]> git.baikalelectronics.ru Git - kernel.git/commitdiff
xen/events: use a common cpu hotplug hook for event channels
authorJuergen Gross <jgross@suse.com>
Sun, 13 Sep 2020 12:23:02 +0000 (14:23 +0200)
committerJuergen Gross <jgross@suse.com>
Tue, 20 Oct 2020 08:22:14 +0000 (10:22 +0200)
Today only fifo event channels have a cpu hotplug callback. In order
to prepare for more percpu (de)init work move that callback into
events_base.c and add percpu_init() and percpu_deinit() hooks to
struct evtchn_ops.

This is part of XSA-332.

Cc: stable@vger.kernel.org
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wl@xen.org>
drivers/xen/events/events_base.c
drivers/xen/events/events_fifo.c
drivers/xen/events/events_internal.h

index 1eba8bc209adda529824b9462ee4b7b35b3d1483..9cbfea5e9a084a9f39e440f4bf9fcfbaaef32295 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/irqnr.h>
 #include <linux/pci.h>
 #include <linux/spinlock.h>
+#include <linux/cpuhotplug.h>
 
 #ifdef CONFIG_X86
 #include <asm/desc.h>
@@ -1830,6 +1831,26 @@ static inline void xen_alloc_callback_vector(void) {}
 static bool fifo_events = true;
 module_param(fifo_events, bool, 0);
 
+static int xen_evtchn_cpu_prepare(unsigned int cpu)
+{
+       int ret = 0;
+
+       if (evtchn_ops->percpu_init)
+               ret = evtchn_ops->percpu_init(cpu);
+
+       return ret;
+}
+
+static int xen_evtchn_cpu_dead(unsigned int cpu)
+{
+       int ret = 0;
+
+       if (evtchn_ops->percpu_deinit)
+               ret = evtchn_ops->percpu_deinit(cpu);
+
+       return ret;
+}
+
 void __init xen_init_IRQ(void)
 {
        int ret = -EINVAL;
@@ -1840,6 +1861,10 @@ void __init xen_init_IRQ(void)
        if (ret < 0)
                xen_evtchn_2l_init();
 
+       cpuhp_setup_state_nocalls(CPUHP_XEN_EVTCHN_PREPARE,
+                                 "xen/evtchn:prepare",
+                                 xen_evtchn_cpu_prepare, xen_evtchn_cpu_dead);
+
        evtchn_to_irq = kcalloc(EVTCHN_ROW(xen_evtchn_max_channels()),
                                sizeof(*evtchn_to_irq), GFP_KERNEL);
        BUG_ON(!evtchn_to_irq);
index 7fd39c64d4b58f8ee6781feaf4ee8cd31aff7760..40e4ca1685aa1be76626229a6241e06bb1ba432d 100644 (file)
@@ -385,21 +385,6 @@ static void evtchn_fifo_resume(void)
        event_array_pages = 0;
 }
 
-static const struct evtchn_ops evtchn_ops_fifo = {
-       .max_channels      = evtchn_fifo_max_channels,
-       .nr_channels       = evtchn_fifo_nr_channels,
-       .setup             = evtchn_fifo_setup,
-       .bind_to_cpu       = evtchn_fifo_bind_to_cpu,
-       .clear_pending     = evtchn_fifo_clear_pending,
-       .set_pending       = evtchn_fifo_set_pending,
-       .is_pending        = evtchn_fifo_is_pending,
-       .test_and_set_mask = evtchn_fifo_test_and_set_mask,
-       .mask              = evtchn_fifo_mask,
-       .unmask            = evtchn_fifo_unmask,
-       .handle_events     = evtchn_fifo_handle_events,
-       .resume            = evtchn_fifo_resume,
-};
-
 static int evtchn_fifo_alloc_control_block(unsigned cpu)
 {
        void *control_block = NULL;
@@ -422,19 +407,36 @@ static int evtchn_fifo_alloc_control_block(unsigned cpu)
        return ret;
 }
 
-static int xen_evtchn_cpu_prepare(unsigned int cpu)
+static int evtchn_fifo_percpu_init(unsigned int cpu)
 {
        if (!per_cpu(cpu_control_block, cpu))
                return evtchn_fifo_alloc_control_block(cpu);
        return 0;
 }
 
-static int xen_evtchn_cpu_dead(unsigned int cpu)
+static int evtchn_fifo_percpu_deinit(unsigned int cpu)
 {
        __evtchn_fifo_handle_events(cpu, true);
        return 0;
 }
 
+static const struct evtchn_ops evtchn_ops_fifo = {
+       .max_channels      = evtchn_fifo_max_channels,
+       .nr_channels       = evtchn_fifo_nr_channels,
+       .setup             = evtchn_fifo_setup,
+       .bind_to_cpu       = evtchn_fifo_bind_to_cpu,
+       .clear_pending     = evtchn_fifo_clear_pending,
+       .set_pending       = evtchn_fifo_set_pending,
+       .is_pending        = evtchn_fifo_is_pending,
+       .test_and_set_mask = evtchn_fifo_test_and_set_mask,
+       .mask              = evtchn_fifo_mask,
+       .unmask            = evtchn_fifo_unmask,
+       .handle_events     = evtchn_fifo_handle_events,
+       .resume            = evtchn_fifo_resume,
+       .percpu_init       = evtchn_fifo_percpu_init,
+       .percpu_deinit     = evtchn_fifo_percpu_deinit,
+};
+
 int __init xen_evtchn_fifo_init(void)
 {
        int cpu = smp_processor_id();
@@ -448,9 +450,5 @@ int __init xen_evtchn_fifo_init(void)
 
        evtchn_ops = &evtchn_ops_fifo;
 
-       cpuhp_setup_state_nocalls(CPUHP_XEN_EVTCHN_PREPARE,
-                                 "xen/evtchn:prepare",
-                                 xen_evtchn_cpu_prepare, xen_evtchn_cpu_dead);
-
        return ret;
 }
index 10684feb094e1a623616ef598b9403e4b3fed857..558abea19d0dd8d7a4e40b8783971d19dc89a9ab 100644 (file)
@@ -69,6 +69,9 @@ struct evtchn_ops {
 
        void (*handle_events)(unsigned cpu);
        void (*resume)(void);
+
+       int (*percpu_init)(unsigned int cpu);
+       int (*percpu_deinit)(unsigned int cpu);
 };
 
 extern const struct evtchn_ops *evtchn_ops;