Skip to contentSkip to conversation

xen: event handling cleanup

PATCH Superseded Juergen Gross 2 participants 11 messages Oct 22, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author maintainer
#3 lore raw

PATCH 3/5 xen/events: only register debug interrupt for 2-level events

In reply to Juergen Gross

xen_debug_interrupt() is specific to 2-level event handling. So don't register it with fifo event handling being active.

---
 arch/x86/xen/smp.c               | 19 +++++++++++--------
 arch/x86/xen/xen-ops.h           |  2 ++
 drivers/xen/events/events_base.c |  6 ++++--
 3 files changed, 17 insertions(+), 10 deletions(-)
arch/x86/xen/smp.c +11 -8
index 2097fa0ebdb5..b544e511b3c2 100644
@@ -88,14 +88,17 @@ int xen_smp_intr_init(unsigned int cpu)
 	per_cpu(xen_callfunc_irq, cpu).irq = rc;
 	per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
 
-	debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
-	rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt,
-				     IRQF_PERCPU | IRQF_NOBALANCING,
-				     debug_name, NULL);
-	if (rc < 0)
-		goto fail;
-	per_cpu(xen_debug_irq, cpu).irq = rc;
-	per_cpu(xen_debug_irq, cpu).name = debug_name;
+	if (!fifo_events) {
+		debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
+		rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu,
+					     xen_debug_interrupt,
+					     IRQF_PERCPU | IRQF_NOBALANCING,
+					     debug_name, NULL);
+		if (rc < 0)
+			goto fail;
+		per_cpu(xen_debug_irq, cpu).irq = rc;
+		per_cpu(xen_debug_irq, cpu).name = debug_name;
+	}
 
 	callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
 	rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
arch/x86/xen/xen-ops.h +2 -0
index 45d556f71858..e444c78b6e2b 100644
@@ -29,6 +29,8 @@ extern struct start_info *xen_start_info;
 extern struct shared_info xen_dummy_shared_info;
 extern struct shared_info *HYPERVISOR_shared_info;
 
+extern bool fifo_events;
+
 void xen_setup_mfn_list_list(void);
 void xen_build_mfn_list_list(void);
 void xen_setup_machphys_mapping(void);
drivers/xen/events/events_base.c +4 -2
index 1c25580c7691..bb18cce4db06 100644
@@ -2050,7 +2050,7 @@ void xen_setup_callback_vector(void) {}
 static inline void xen_alloc_callback_vector(void) {}
 #endif
 
-static bool fifo_events = true;
+bool fifo_events = true;
 module_param(fifo_events, bool, 0);
 
 static int xen_evtchn_cpu_prepare(unsigned int cpu)
@@ -2082,8 +2082,10 @@ void __init xen_init_IRQ(void)
 
 	if (fifo_events)
 		ret = xen_evtchn_fifo_init();
-	if (ret < 0)
+	if (ret < 0) {
 		xen_evtchn_2l_init();
+		fifo_events = false;
+	}
 
 	xen_cpu_init_eoi(smp_processor_id());
 
Signature · 1 line
2.26.2

Juergen Gross

author maintainer
#0 lore raw

cover xen: event handling cleanup

Do some cleanups in Xen event handling code.

Juergen Gross (5):
xen: remove no longer used functions
xen/events: make struct irq_info private to events_base.c xen/events: only register debug interrupt for 2-level events xen/events: unmask a fifo event channel only if it was masked
Documentation: add xen.fifo_events kernel parameter description

 .../admin-guide/kernel-parameters.txt         |  7 ++
 arch/x86/xen/smp.c                            | 19 ++--
 arch/x86/xen/xen-ops.h                        |  2 +
 drivers/xen/events/events_2l.c                |  7 +-
 drivers/xen/events/events_base.c              | 90 +++++++++++++------
 drivers/xen/events/events_fifo.c              |  9 +-
 drivers/xen/events/events_internal.h          | 70 ++-------------
 include/xen/events.h                          |  8 --
 8 files changed, 100 insertions(+), 112 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#9 lore raw

PATCH 5/5 Documentation: add xen.fifo_events kernel parameter description

The kernel boot parameter xen.fifo_events isn't listed in Documentation/admin-guide/kernel-parameters.txt. Add it.

---
 Documentation/admin-guide/kernel-parameters.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index 02d4adbf98d2..526d65d8573a 100644
@@ -5978,6 +5978,13 @@
 			After which time (jiffies) the event handling loop
 			should start to delay EOI handling. Default is 2.
 
+	xen.fifo_events=	[XEN]
+			Boolean parameter to disable using fifo event handling
+			even if available. Normally fifo event handling is
+			preferred over the 2-level event handling, as it is
+			fairer and the number of possible event channels is
+			much higher. Default is on (use fifo events).
+
 	nopv=		[X86,XEN,KVM,HYPER_V,VMWARE]
 			Disables the PV optimizations forcing the guest to run
 			as generic guest with no PV drivers. Currently support
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH 1/5 xen: remove no longer used functions

In reply to Juergen Gross

With the switch to the lateeoi model for interdomain event channels some functions are no longer in use. Remove them.

---
 drivers/xen/events/events_base.c | 21 ---------------------
 include/xen/events.h             |  8 --------
 2 files changed, 29 deletions(-)
drivers/xen/events/events_base.c +0 -21
index cc317739e786..436682db41c5 100644
@@ -1145,14 +1145,6 @@ static int bind_interdomain_evtchn_to_irq_chip(unsigned int remote_domain,
 					       chip);
 }
 
-int bind_interdomain_evtchn_to_irq(unsigned int remote_domain,
-				   evtchn_port_t remote_port)
-{
-	return bind_interdomain_evtchn_to_irq_chip(remote_domain, remote_port,
-						   &xen_dynamic_chip);
-}
-EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irq);
-
 int bind_interdomain_evtchn_to_irq_lateeoi(unsigned int remote_domain,
 					   evtchn_port_t remote_port)
 {
@@ -1320,19 +1312,6 @@ static int bind_interdomain_evtchn_to_irqhandler_chip(
 	return irq;
 }
 
-int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
-					  evtchn_port_t remote_port,
-					  irq_handler_t handler,
-					  unsigned long irqflags,
-					  const char *devname,
-					  void *dev_id)
-{
-	return bind_interdomain_evtchn_to_irqhandler_chip(remote_domain,
-				remote_port, handler, irqflags, devname,
-				dev_id, &xen_dynamic_chip);
-}
-EXPORT_SYMBOL_GPL(bind_interdomain_evtchn_to_irqhandler);
-
 int bind_interdomain_evtchn_to_irqhandler_lateeoi(unsigned int remote_domain,
 						  evtchn_port_t remote_port,
 						  irq_handler_t handler,
include/xen/events.h +0 -8
index 3b8155c2ea03..8ec418e30c7f 100644
@@ -35,16 +35,8 @@ int bind_ipi_to_irqhandler(enum ipi_vector ipi,
 			   unsigned long irqflags,
 			   const char *devname,
 			   void *dev_id);
-int bind_interdomain_evtchn_to_irq(unsigned int remote_domain,
-				   evtchn_port_t remote_port);
 int bind_interdomain_evtchn_to_irq_lateeoi(unsigned int remote_domain,
 					   evtchn_port_t remote_port);
-int bind_interdomain_evtchn_to_irqhandler(unsigned int remote_domain,
-					  evtchn_port_t remote_port,
-					  irq_handler_t handler,
-					  unsigned long irqflags,
-					  const char *devname,
-					  void *dev_id);
 int bind_interdomain_evtchn_to_irqhandler_lateeoi(unsigned int remote_domain,
 						  evtchn_port_t remote_port,
 						  irq_handler_t handler,
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

PATCH 2/5 xen/events: make struct irq_info private to events_base.c

In reply to Juergen Gross

The struct irq_info of Xen's event handling is used only for two evtchn_ops functions outside of events_base.c. Those two functions can easily be switched to avoid that usage.

This allows to make struct irq_info and its related access functions private to events_base.c.

---
 drivers/xen/events/events_2l.c       |  7 +--
 drivers/xen/events/events_base.c     | 63 ++++++++++++++++++++++---
 drivers/xen/events/events_fifo.c     |  6 +--
 drivers/xen/events/events_internal.h | 70 ++++------------------------
 4 files changed, 73 insertions(+), 73 deletions(-)
drivers/xen/events/events_2l.c +4 -3
index fe5ad0e89cd8..da87f3a1e351 100644
@@ -47,10 +47,11 @@ static unsigned evtchn_2l_max_channels(void)
 	return EVTCHN_2L_NR_CHANNELS;
 }
 
-static void evtchn_2l_bind_to_cpu(struct irq_info *info, unsigned cpu)
+static void evtchn_2l_bind_to_cpu(evtchn_port_t evtchn, unsigned int cpu,
+				  unsigned int old_cpu)
 {
-	clear_bit(info->evtchn, BM(per_cpu(cpu_evtchn_mask, info->cpu)));
-	set_bit(info->evtchn, BM(per_cpu(cpu_evtchn_mask, cpu)));
+	clear_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, old_cpu)));
+	set_bit(evtchn, BM(per_cpu(cpu_evtchn_mask, cpu)));
 }
 
 static void evtchn_2l_clear_pending(evtchn_port_t port)
drivers/xen/events/events_base.c +57 -6

105 lines not on this page · raw message

drivers/xen/events/events_fifo.c +3 -3
index 6085a808da95..243e7b6d7b96 100644
@@ -138,9 +138,8 @@ static void init_array_page(event_word_t *array_page)
 		array_page[i] = 1 << EVTCHN_FIFO_MASKED;
 }
 
-static int evtchn_fifo_setup(struct irq_info *info)
+static int evtchn_fifo_setup(evtchn_port_t port)
 {
-	evtchn_port_t port = info->evtchn;
 	unsigned new_array_pages;
 	int ret;
 
@@ -186,7 +185,8 @@ static int evtchn_fifo_setup(struct irq_info *info)
 	return ret;
 }
 
-static void evtchn_fifo_bind_to_cpu(struct irq_info *info, unsigned cpu)
+static void evtchn_fifo_bind_to_cpu(evtchn_port_t evtchn, unsigned int cpu, 
+				    unsigned int old_cpu)
 {
 	/* no-op */
 }
drivers/xen/events/events_internal.h +9 -61

103 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#6 lore raw

PATCH 4/5 xen/events: unmask a fifo event channel only if it was masked

In reply to Juergen Gross

Unmasking an event channel with fifo events channels being used can require a hypercall to be made, so try to avoid that by checking whether the event channel was really masked.

---
 drivers/xen/events/events_fifo.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/xen/events/events_fifo.c +3 -0
index 243e7b6d7b96..f60c5a9ec833 100644
@@ -236,6 +236,9 @@ static bool clear_masked_cond(volatile event_word_t *word)
 
 	w = *word;
 
+	if (!(w & (1 << EVTCHN_FIFO_MASKED)))
+		return true;
+
 	do {
 		if (w & (1 << EVTCHN_FIFO_PENDING))
 			return false;
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 3/5] xen/events: only register debug interrupt for 2-level events

In reply to Juergen Gross

drivers/xen/events/events_base.c void xen_setup_callback_vector(void) {} · line 2053

Quoted 8 lines · Juergen Gross
drivers/xen/events/events_base.c +1 -1
@@ -2050,7 +2050,7 @@ void xen_setup_callback_vector(void) {}
 static inline void xen_alloc_callback_vector(void) {}
 #endif
 
-static bool fifo_events = true;
+bool fifo_events = true;

When making this non-static, perhaps better to also prefix it with xen_?

Jan

#7 lore raw

Re: [PATCH 4/5] xen/events: unmask a fifo event channel only if it was masked

In reply to Juergen Gross

drivers/xen/events/events_fifo.c static bool clear_masked_cond(volatile event_word_t *word) · line 240

Quoted 8 lines · Juergen Gross
drivers/xen/events/events_fifo.c +2 -0
@@ -236,6 +236,9 @@ static bool clear_masked_cond(volatile event_word_t *word)
 
 	w = *word;
 
+	if (!(w & (1 << EVTCHN_FIFO_MASKED)))
+		return true;

Maybe better move this ...

drivers/xen/events/events_fifo.c static bool clear_masked_cond(volatile event_word_t *word) · line 244

Quoted 4 lines
drivers/xen/events/events_fifo.c +0 -0
 	do {
 		if (w & (1 << EVTCHN_FIFO_PENDING))
 			return false;

... into the loop, above this check?

Jan

Reviewed-by on the v1 series
#10 lore raw
In reply to Juergen Gross
Quoted 8 lines · Juergen Gross

Do some cleanups in Xen event handling code.

Juergen Gross (5):
xen: remove no longer used functions
xen/events: make struct irq_info private to events_base.c xen/events: only register debug interrupt for 2-level events xen/events: unmask a fifo event channel only if it was masked
Documentation: add xen.fifo_events kernel parameter description

With the two remarks to individual patches suitably taken care of one way or another

Jan

author maintainer
#5 lore raw

Re: [PATCH 3/5] xen/events: only register debug interrupt for 2-level events

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Juergen Gross
drivers/xen/events/events_base.c +0 -0
@@ -2050,7 +2050,7 @@ void xen_setup_callback_vector(void) {}
  static inline void xen_alloc_callback_vector(void) {}
  #endif
 
Quoted 5 lines

drivers/xen/events/events_base.c void xen_setup_callback_vector(void) {} · line 2053

Quoted 2 lines
drivers/xen/events/events_base.c +1 -1
-static bool fifo_events = true;
+bool fifo_events = true;

When making this non-static, perhaps better to also prefix it with xen_?

Fine with me.

Juergen

author maintainer
#8 lore raw

Re: [PATCH 4/5] xen/events: unmask a fifo event channel only if it was masked

In reply to Jan Beulich
Quoted 12 lines · Jan Beulich

drivers/xen/events/events_fifo.c static bool clear_masked_cond(volatile event_word_t *word) · line 240

Quoted 8 lines · Juergen Gross
drivers/xen/events/events_fifo.c +2 -0
@@ -236,6 +236,9 @@ static bool clear_masked_cond(volatile event_word_t *word)
 
  	w = *word;
 
+	if (!(w & (1 << EVTCHN_FIFO_MASKED)))
+		return true;

Maybe better move this ...

Quoted 6 lines

drivers/xen/events/events_fifo.c static bool clear_masked_cond(volatile event_word_t *word) · line 244

Quoted 4 lines
drivers/xen/events/events_fifo.c +0 -0
  	do {
  		if (w & (1 << EVTCHN_FIFO_PENDING))
  			return false;

... into the loop, above this check?

Yes, that should be better.

Juergen