diff options
author | David Vrabel <david.vrabel@citrix.com> | 2013-08-15 08:21:04 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2013-08-20 10:02:03 -0400 |
commit | fb58e30091c74967f6b8e98b3c1f292782f92b41 (patch) | |
tree | 089af5ce298915f3825545319ec58a185ca2ab90 /arch/x86/xen/irq.c | |
parent | 781575cd8127c30a0444953bcd0b6d1e882df13e (diff) |
x86/xen: disable premption when enabling local irqs
If CONFIG_PREEMPT is enabled then xen_enable_irq() (and
xen_restore_fl()) could be preempted and rescheduled on a different
VCPU in between the clear of the mask and the check for pending
events. This may result in events being lost as the upcall will check
for pending events on the wrong VCPU.
Fix this by disabling preemption around the unmask and check for
events.
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'arch/x86/xen/irq.c')
-rw-r--r-- | arch/x86/xen/irq.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c index 01a4dc015ae1..0da7f863056f 100644 --- a/arch/x86/xen/irq.c +++ b/arch/x86/xen/irq.c | |||
@@ -47,23 +47,18 @@ static void xen_restore_fl(unsigned long flags) | |||
47 | /* convert from IF type flag */ | 47 | /* convert from IF type flag */ |
48 | flags = !(flags & X86_EFLAGS_IF); | 48 | flags = !(flags & X86_EFLAGS_IF); |
49 | 49 | ||
50 | /* There's a one instruction preempt window here. We need to | 50 | /* See xen_irq_enable() for why preemption must be disabled. */ |
51 | make sure we're don't switch CPUs between getting the vcpu | ||
52 | pointer and updating the mask. */ | ||
53 | preempt_disable(); | 51 | preempt_disable(); |
54 | vcpu = this_cpu_read(xen_vcpu); | 52 | vcpu = this_cpu_read(xen_vcpu); |
55 | vcpu->evtchn_upcall_mask = flags; | 53 | vcpu->evtchn_upcall_mask = flags; |
56 | preempt_enable_no_resched(); | ||
57 | |||
58 | /* Doesn't matter if we get preempted here, because any | ||
59 | pending event will get dealt with anyway. */ | ||
60 | 54 | ||
61 | if (flags == 0) { | 55 | if (flags == 0) { |
62 | preempt_check_resched(); | ||
63 | barrier(); /* unmask then check (avoid races) */ | 56 | barrier(); /* unmask then check (avoid races) */ |
64 | if (unlikely(vcpu->evtchn_upcall_pending)) | 57 | if (unlikely(vcpu->evtchn_upcall_pending)) |
65 | xen_force_evtchn_callback(); | 58 | xen_force_evtchn_callback(); |
66 | } | 59 | preempt_enable(); |
60 | } else | ||
61 | preempt_enable_no_resched(); | ||
67 | } | 62 | } |
68 | PV_CALLEE_SAVE_REGS_THUNK(xen_restore_fl); | 63 | PV_CALLEE_SAVE_REGS_THUNK(xen_restore_fl); |
69 | 64 | ||
@@ -82,10 +77,12 @@ static void xen_irq_enable(void) | |||
82 | { | 77 | { |
83 | struct vcpu_info *vcpu; | 78 | struct vcpu_info *vcpu; |
84 | 79 | ||
85 | /* We don't need to worry about being preempted here, since | 80 | /* |
86 | either a) interrupts are disabled, so no preemption, or b) | 81 | * We may be preempted as soon as vcpu->evtchn_upcall_mask is |
87 | the caller is confused and is trying to re-enable interrupts | 82 | * cleared, so disable preemption to ensure we check for |
88 | on an indeterminate processor. */ | 83 | * events on the VCPU we are still running on. |
84 | */ | ||
85 | preempt_disable(); | ||
89 | 86 | ||
90 | vcpu = this_cpu_read(xen_vcpu); | 87 | vcpu = this_cpu_read(xen_vcpu); |
91 | vcpu->evtchn_upcall_mask = 0; | 88 | vcpu->evtchn_upcall_mask = 0; |
@@ -96,6 +93,8 @@ static void xen_irq_enable(void) | |||
96 | barrier(); /* unmask then check (avoid races) */ | 93 | barrier(); /* unmask then check (avoid races) */ |
97 | if (unlikely(vcpu->evtchn_upcall_pending)) | 94 | if (unlikely(vcpu->evtchn_upcall_pending)) |
98 | xen_force_evtchn_callback(); | 95 | xen_force_evtchn_callback(); |
96 | |||
97 | preempt_enable(); | ||
99 | } | 98 | } |
100 | PV_CALLEE_SAVE_REGS_THUNK(xen_irq_enable); | 99 | PV_CALLEE_SAVE_REGS_THUNK(xen_irq_enable); |
101 | 100 | ||