Commit b6622798 authored by Juergen Gross's avatar Juergen Gross Committed by Boris Ostrovsky

xen/events: avoid handling the same event on two cpus at the same time

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: default avatarJulien Grall <julien@xen.org>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarJulien Grall <jgrall@amazon.com>
Link: https://lore.kernel.org/r/20210306161833.4552-4-jgross@suse.comSigned-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 25da4618
...@@ -103,6 +103,7 @@ struct irq_info { ...@@ -103,6 +103,7 @@ struct irq_info {
#define EVT_MASK_REASON_EXPLICIT 0x01 #define EVT_MASK_REASON_EXPLICIT 0x01
#define EVT_MASK_REASON_TEMPORARY 0x02 #define EVT_MASK_REASON_TEMPORARY 0x02
#define EVT_MASK_REASON_EOI_PENDING 0x04 #define EVT_MASK_REASON_EOI_PENDING 0x04
u8 is_active; /* Is event just being handled? */
unsigned irq; unsigned irq;
evtchn_port_t evtchn; /* event channel */ evtchn_port_t evtchn; /* event channel */
unsigned short cpu; /* cpu bound */ unsigned short cpu; /* cpu bound */
...@@ -810,6 +811,12 @@ static void xen_evtchn_close(evtchn_port_t port) ...@@ -810,6 +811,12 @@ static void xen_evtchn_close(evtchn_port_t port)
BUG(); BUG();
} }
static void event_handler_exit(struct irq_info *info)
{
smp_store_release(&info->is_active, 0);
clear_evtchn(info->evtchn);
}
static void pirq_query_unmask(int irq) static void pirq_query_unmask(int irq)
{ {
struct physdev_irq_status_query irq_status; struct physdev_irq_status_query irq_status;
...@@ -828,14 +835,15 @@ static void pirq_query_unmask(int irq) ...@@ -828,14 +835,15 @@ static void pirq_query_unmask(int irq)
static void eoi_pirq(struct irq_data *data) static void eoi_pirq(struct irq_data *data)
{ {
evtchn_port_t evtchn = evtchn_from_irq(data->irq); struct irq_info *info = info_for_irq(data->irq);
evtchn_port_t evtchn = info ? info->evtchn : 0;
struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) }; struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) };
int rc = 0; int rc = 0;
if (!VALID_EVTCHN(evtchn)) if (!VALID_EVTCHN(evtchn))
return; return;
clear_evtchn(evtchn); event_handler_exit(info);
if (pirq_needs_eoi(data->irq)) { if (pirq_needs_eoi(data->irq)) {
rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi);
...@@ -1666,6 +1674,8 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl) ...@@ -1666,6 +1674,8 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl)
} }
info = info_for_irq(irq); info = info_for_irq(irq);
if (xchg_acquire(&info->is_active, 1))
return;
dev = (info->type == IRQT_EVTCHN) ? info->u.interdomain : NULL; dev = (info->type == IRQT_EVTCHN) ? info->u.interdomain : NULL;
if (dev) if (dev)
...@@ -1853,12 +1863,11 @@ static void disable_dynirq(struct irq_data *data) ...@@ -1853,12 +1863,11 @@ static void disable_dynirq(struct irq_data *data)
static void ack_dynirq(struct irq_data *data) static void ack_dynirq(struct irq_data *data)
{ {
evtchn_port_t evtchn = evtchn_from_irq(data->irq); struct irq_info *info = info_for_irq(data->irq);
evtchn_port_t evtchn = info ? info->evtchn : 0;
if (!VALID_EVTCHN(evtchn))
return;
clear_evtchn(evtchn); if (VALID_EVTCHN(evtchn))
event_handler_exit(info);
} }
static void mask_ack_dynirq(struct irq_data *data) static void mask_ack_dynirq(struct irq_data *data)
...@@ -1874,7 +1883,7 @@ static void lateeoi_ack_dynirq(struct irq_data *data) ...@@ -1874,7 +1883,7 @@ static void lateeoi_ack_dynirq(struct irq_data *data)
if (VALID_EVTCHN(evtchn)) { if (VALID_EVTCHN(evtchn)) {
do_mask(info, EVT_MASK_REASON_EOI_PENDING); do_mask(info, EVT_MASK_REASON_EOI_PENDING);
clear_evtchn(evtchn); event_handler_exit(info);
} }
} }
...@@ -1885,7 +1894,7 @@ static void lateeoi_mask_ack_dynirq(struct irq_data *data) ...@@ -1885,7 +1894,7 @@ static void lateeoi_mask_ack_dynirq(struct irq_data *data)
if (VALID_EVTCHN(evtchn)) { if (VALID_EVTCHN(evtchn)) {
do_mask(info, EVT_MASK_REASON_EXPLICIT); do_mask(info, EVT_MASK_REASON_EXPLICIT);
clear_evtchn(evtchn); event_handler_exit(info);
} }
} }
...@@ -1998,10 +2007,11 @@ static void restore_cpu_ipis(unsigned int cpu) ...@@ -1998,10 +2007,11 @@ static void restore_cpu_ipis(unsigned int cpu)
/* Clear an irq's pending state, in preparation for polling on it */ /* Clear an irq's pending state, in preparation for polling on it */
void xen_clear_irq_pending(int irq) void xen_clear_irq_pending(int irq)
{ {
evtchn_port_t evtchn = evtchn_from_irq(irq); struct irq_info *info = info_for_irq(irq);
evtchn_port_t evtchn = info ? info->evtchn : 0;
if (VALID_EVTCHN(evtchn)) if (VALID_EVTCHN(evtchn))
clear_evtchn(evtchn); event_handler_exit(info);
} }
EXPORT_SYMBOL(xen_clear_irq_pending); EXPORT_SYMBOL(xen_clear_irq_pending);
void xen_set_irq_pending(int irq) void xen_set_irq_pending(int irq)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment