Skip to contentSkip to conversation

xen/events/fifo: Handle linked events when closing a port

PATCH Applied Ross Lagerwall 2 participants 3 messages Jul 31, 2015 – Aug 4, 2015 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xen/events/fifo: Handle linked events when closing a port

When a channel is closed and the event is still linked into a queue, ensure that it is unlinked before completing. If it is not unlinked and the port is subsequently reused, events may be missed.

If the CPU to which the event channel bound is online, spin until the event is handled by that CPU. If that CPU is offline, it can't handle the event, so clear the event queue during the close, dropping the events.

This fixes missing interrupts (and subsequent disk stalls) when offlining a CPU.

---
 drivers/xen/events/events_base.c     | 10 ++++----
 drivers/xen/events/events_fifo.c     | 45 ++++++++++++++++++++++++++++++++----
 drivers/xen/events/events_internal.h |  7 ++++++
 3 files changed, 53 insertions(+), 9 deletions(-)
drivers/xen/events/events_base.c +6 -4
index 96093ae..1495ecc 100644
@@ -452,10 +452,12 @@ static void xen_free_irq(unsigned irq)
 	irq_free_desc(irq);
 }
 
-static void xen_evtchn_close(unsigned int port)
+static void xen_evtchn_close(unsigned int port, unsigned int cpu)
 {
 	struct evtchn_close close;
 
+	xen_evtchn_op_close(port, cpu);
+
 	close.port = port;
 	if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
 		BUG();
@@ -544,7 +546,7 @@ out:
 
 err:
 	pr_err("irq%d: Failed to set port to irq mapping (%d)\n", irq, rc);
-	xen_evtchn_close(evtchn);
+	xen_evtchn_close(evtchn, NR_CPUS);
 	return 0;
 }
 
@@ -565,7 +567,7 @@ static void shutdown_pirq(struct irq_data *data)
 		return;
 
 	mask_evtchn(evtchn);
-	xen_evtchn_close(evtchn);
+	xen_evtchn_close(evtchn, cpu_from_evtchn(evtchn));
 	xen_irq_info_cleanup(info);
 }
 
@@ -609,7 +611,7 @@ static void __unbind_from_irq(unsigned int irq)
 	if (VALID_EVTCHN(evtchn)) {
 		unsigned int cpu = cpu_from_irq(irq);
 
-		xen_evtchn_close(evtchn);
+		xen_evtchn_close(evtchn, cpu);
 
 		switch (type_from_irq(irq)) {
 		case IRQT_VIRQ:
drivers/xen/events/events_fifo.c +40 -5

89 lines not on this page · raw message

drivers/xen/events/events_internal.h +7 -0
index 50c2050a..d18e123 100644
@@ -68,6 +68,7 @@ struct evtchn_ops {
 	bool (*test_and_set_mask)(unsigned port);
 	void (*mask)(unsigned port);
 	void (*unmask)(unsigned port);
+	void (*close)(unsigned port, unsigned cpu);
 
 	void (*handle_events)(unsigned cpu);
 	void (*resume)(void);
@@ -145,6 +146,12 @@ static inline void xen_evtchn_resume(void)
 		evtchn_ops->resume();
 }
 
+static inline void xen_evtchn_op_close(unsigned port, unsigned cpu)
+{
+	if (evtchn_ops->close)
+		return evtchn_ops->close(port, cpu);
+}
+
 void xen_evtchn_2l_init(void);
 int xen_evtchn_fifo_init(void);
 
Signature · 1 line
2.1.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Ross Lagerwall

When a channel is closed and the event is still linked into a queue, ensure that it is unlinked before completing. If it is not unlinked and the port is subsequently reused, events may be missed.

If the CPU to which the event channel bound is online, spin until the event is handled by that CPU. If that CPU is offline, it can't handle the event, so clear the event queue during the close, dropping the events.

This fixes missing interrupts (and subsequent disk stalls) when offlining a CPU.

The last paragraph should be expanded I think. How about:

An event channel bound to a CPU that was offlined may still be linked on that CPU's queue. If this event channel is closed and reused, subsequent events will be lost because the event channel is never unlinked.

Otherwise,

David

Applied
#2 lore raw
In reply to Ross Lagerwall
Quoted 11 lines · Ross Lagerwall

When a channel is closed and the event is still linked into a queue, ensure that it is unlinked before completing. If it is not unlinked and the port is subsequently reused, events may be missed.

If the CPU to which the event channel bound is online, spin until the event is handled by that CPU. If that CPU is offline, it can't handle the event, so clear the event queue during the close, dropping the events.

This fixes missing interrupts (and subsequent disk stalls) when offlining a CPU.

Applied to for-linus-4.2 and tagged for stable, thanks.

David