diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-06-13 00:27:02 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-06-12 08:57:02 -0400 |
commit | abd41f037e1a64543000ed73b42f616d04d92700 (patch) | |
tree | d9013e66f4d8fc66fc92ce0587f8d126e156b253 /drivers/lguest/core.c | |
parent | ebf9a5a99c1a464afe0b4dfa64416fc8b273bc5c (diff) |
lguest: fix race in halt code
When the Guest does the LHCALL_HALT hypercall, we go to sleep, expecting
that a timer or the Waker will wake_up_process() us.
But we do it in a stupid way, leaving a classic missing wakeup race.
So split maybe_do_interrupt() into interrupt_pending() and
try_deliver_interrupt(), and check maybe_do_interrupt() and the
"break_out" flag before calling schedule.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/lguest/core.c')
-rw-r--r-- | drivers/lguest/core.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c index 4845fb3cf74b..8ca1def5b142 100644 --- a/drivers/lguest/core.c +++ b/drivers/lguest/core.c | |||
@@ -188,6 +188,8 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user) | |||
188 | { | 188 | { |
189 | /* We stop running once the Guest is dead. */ | 189 | /* We stop running once the Guest is dead. */ |
190 | while (!cpu->lg->dead) { | 190 | while (!cpu->lg->dead) { |
191 | unsigned int irq; | ||
192 | |||
191 | /* First we run any hypercalls the Guest wants done. */ | 193 | /* First we run any hypercalls the Guest wants done. */ |
192 | if (cpu->hcall) | 194 | if (cpu->hcall) |
193 | do_hypercalls(cpu); | 195 | do_hypercalls(cpu); |
@@ -211,7 +213,9 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user) | |||
211 | /* Check if there are any interrupts which can be delivered now: | 213 | /* Check if there are any interrupts which can be delivered now: |
212 | * if so, this sets up the hander to be executed when we next | 214 | * if so, this sets up the hander to be executed when we next |
213 | * run the Guest. */ | 215 | * run the Guest. */ |
214 | maybe_do_interrupt(cpu); | 216 | irq = interrupt_pending(cpu); |
217 | if (irq < LGUEST_IRQS) | ||
218 | try_deliver_interrupt(cpu, irq); | ||
215 | 219 | ||
216 | /* All long-lived kernel loops need to check with this horrible | 220 | /* All long-lived kernel loops need to check with this horrible |
217 | * thing called the freezer. If the Host is trying to suspend, | 221 | * thing called the freezer. If the Host is trying to suspend, |
@@ -227,7 +231,13 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user) | |||
227 | * clock timer or LHREQ_BREAK from the Waker will wake us. */ | 231 | * clock timer or LHREQ_BREAK from the Waker will wake us. */ |
228 | if (cpu->halted) { | 232 | if (cpu->halted) { |
229 | set_current_state(TASK_INTERRUPTIBLE); | 233 | set_current_state(TASK_INTERRUPTIBLE); |
230 | schedule(); | 234 | /* Just before we sleep, make sure nothing snuck in |
235 | * which we should be doing. */ | ||
236 | if (interrupt_pending(cpu) < LGUEST_IRQS | ||
237 | || cpu->break_out) | ||
238 | set_current_state(TASK_RUNNING); | ||
239 | else | ||
240 | schedule(); | ||
231 | continue; | 241 | continue; |
232 | } | 242 | } |
233 | 243 | ||