Skip to content

Commit f67e524

Browse files
jgross1gregkh
authored andcommitted
xen/events: avoid handling the same event on two cpus at the same time
commit b662279 upstream. When changing the cpu affinity of an event it can happen today that (with some unlucky timing) the same event will be handled on the old and the new cpu at the same time. Avoid that by adding an "event active" flag to the per-event data and call the handler only if this flag isn't set. Cc: stable@vger.kernel.org Reported-by: Julien Grall <julien@xen.org> Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Julien Grall <jgrall@amazon.com> Link: https://lore.kernel.org/r/20210306161833.4552-4-jgross@suse.com Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 30cdb86 commit f67e524

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

‎drivers/xen/events/events_base.c‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct irq_info {
101101
#define EVT_MASK_REASON_EXPLICIT 0x01
102102
#define EVT_MASK_REASON_TEMPORARY 0x02
103103
#define EVT_MASK_REASON_EOI_PENDING 0x04
104+
u8 is_active; /* Is event just being handled? */
104105
unsigned irq;
105106
evtchn_port_t evtchn; /* event channel */
106107
unsigned short cpu; /* cpu bound */
@@ -751,6 +752,12 @@ static void xen_evtchn_close(evtchn_port_t port)
751752
BUG();
752753
}
753754

755+
static void event_handler_exit(struct irq_info *info)
756+
{
757+
smp_store_release(&info->is_active, 0);
758+
clear_evtchn(info->evtchn);
759+
}
760+
754761
static void pirq_query_unmask(int irq)
755762
{
756763
struct physdev_irq_status_query irq_status;
@@ -781,13 +788,13 @@ static void eoi_pirq(struct irq_data *data)
781788
likely(!irqd_irq_disabled(data))) {
782789
do_mask(info, EVT_MASK_REASON_TEMPORARY);
783790

784-
clear_evtchn(evtchn);
791+
event_handler_exit(info);
785792

786793
irq_move_masked_irq(data);
787794

788795
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
789796
} else
790-
clear_evtchn(evtchn);
797+
event_handler_exit(info);
791798

792799
if (pirq_needs_eoi(data->irq)) {
793800
rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
@@ -1603,6 +1610,8 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
16031610
}
16041611

16051612
info = info_for_irq(irq);
1613+
if (xchg_acquire(&info->is_active, 1))
1614+
return;
16061615

16071616
if (ctrl->defer_eoi) {
16081617
info->eoi_cpu = smp_processor_id();
@@ -1778,13 +1787,13 @@ static void ack_dynirq(struct irq_data *data)
17781787
likely(!irqd_irq_disabled(data))) {
17791788
do_mask(info, EVT_MASK_REASON_TEMPORARY);
17801789

1781-
clear_evtchn(evtchn);
1790+
event_handler_exit(info);
17821791

17831792
irq_move_masked_irq(data);
17841793

17851794
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
17861795
} else
1787-
clear_evtchn(evtchn);
1796+
event_handler_exit(info);
17881797
}
17891798

17901799
static void mask_ack_dynirq(struct irq_data *data)
@@ -1800,7 +1809,7 @@ static void lateeoi_ack_dynirq(struct irq_data *data)
18001809

18011810
if (VALID_EVTCHN(evtchn)) {
18021811
do_mask(info, EVT_MASK_REASON_EOI_PENDING);
1803-
clear_evtchn(evtchn);
1812+
event_handler_exit(info);
18041813
}
18051814
}
18061815

@@ -1811,7 +1820,7 @@ static void lateeoi_mask_ack_dynirq(struct irq_data *data)
18111820

18121821
if (VALID_EVTCHN(evtchn)) {
18131822
do_mask(info, EVT_MASK_REASON_EXPLICIT);
1814-
clear_evtchn(evtchn);
1823+
event_handler_exit(info);
18151824
}
18161825
}
18171826

@@ -1922,10 +1931,11 @@ static void restore_cpu_ipis(unsigned int cpu)
19221931
/* Clear an irq's pending state, in preparation for polling on it */
19231932
void xen_clear_irq_pending(int irq)
19241933
{
1925-
evtchn_port_t evtchn = evtchn_from_irq(irq);
1934+
struct irq_info *info = info_for_irq(irq);
1935+
evtchn_port_t evtchn = info ? info->evtchn : 0;
19261936

19271937
if (VALID_EVTCHN(evtchn))
1928-
clear_evtchn(evtchn);
1938+
event_handler_exit(info);
19291939
}
19301940
EXPORT_SYMBOL(xen_clear_irq_pending);
19311941
void xen_set_irq_pending(int irq)

0 commit comments

Comments
 (0)