Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26a6cbe3 authored by Juergen Gross's avatar Juergen Gross Committed by Greg Kroah-Hartman
Browse files

xen/events: use a common cpu hotplug hook for event channels



commit 7beb290caa2adb0a399e735a1e175db9aae0523a upstream.

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: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarJan Beulich <jbeulich@suse.com>
Reviewed-by: default avatarWei Liu <wl@xen.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 957a6b5f
Loading
Loading
Loading
Loading
+47 −0
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@
#include <linux/irqnr.h>
#include <linux/irqnr.h>
#include <linux/pci.h>
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/spinlock.h>
#include <linux/cpu.h>


#ifdef CONFIG_X86
#ifdef CONFIG_X86
#include <asm/desc.h>
#include <asm/desc.h>
@@ -1832,6 +1833,50 @@ void xen_callback_vector(void) {}
static bool fifo_events = true;
static bool fifo_events = true;
module_param(fifo_events, bool, 0);
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;
}

static int evtchn_cpu_notification(struct notifier_block *self,
				   unsigned long action, void *hcpu)
{
	int cpu = (long)hcpu;
	int ret = 0;

	switch (action) {
	case CPU_UP_PREPARE:
		ret = xen_evtchn_cpu_prepare(cpu);
		break;
	case CPU_DEAD:
		ret = xen_evtchn_cpu_dead(cpu);
		break;
	default:
		break;
	}

	return ret < 0 ? NOTIFY_BAD : NOTIFY_OK;
}

static struct notifier_block evtchn_cpu_notifier = {
	.notifier_call  = evtchn_cpu_notification,
};

void __init xen_init_IRQ(void)
void __init xen_init_IRQ(void)
{
{
	int ret = -EINVAL;
	int ret = -EINVAL;
@@ -1841,6 +1886,8 @@ void __init xen_init_IRQ(void)
	if (ret < 0)
	if (ret < 0)
		xen_evtchn_2l_init();
		xen_evtchn_2l_init();


	register_cpu_notifier(&evtchn_cpu_notifier);

	evtchn_to_irq = kcalloc(EVTCHN_ROW(xen_evtchn_max_channels()),
	evtchn_to_irq = kcalloc(EVTCHN_ROW(xen_evtchn_max_channels()),
				sizeof(*evtchn_to_irq), GFP_KERNEL);
				sizeof(*evtchn_to_irq), GFP_KERNEL);
	BUG_ON(!evtchn_to_irq);
	BUG_ON(!evtchn_to_irq);
+25 −36
Original line number Original line Diff line number Diff line
@@ -386,21 +386,6 @@ static void evtchn_fifo_resume(void)
	event_array_pages = 0;
	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)
static int evtchn_fifo_alloc_control_block(unsigned cpu)
{
{
	void *control_block = NULL;
	void *control_block = NULL;
@@ -423,29 +408,34 @@ static int evtchn_fifo_alloc_control_block(unsigned cpu)
	return ret;
	return ret;
}
}


static int evtchn_fifo_cpu_notification(struct notifier_block *self,
static int evtchn_fifo_percpu_init(unsigned int cpu)
						  unsigned long action,
						  void *hcpu)
{
{
	int cpu = (long)hcpu;
	int ret = 0;

	switch (action) {
	case CPU_UP_PREPARE:
	if (!per_cpu(cpu_control_block, cpu))
	if (!per_cpu(cpu_control_block, cpu))
			ret = evtchn_fifo_alloc_control_block(cpu);
		return evtchn_fifo_alloc_control_block(cpu);
		break;
	return 0;
	case CPU_DEAD:
		__evtchn_fifo_handle_events(cpu, true);
		break;
	default:
		break;
}
}
	return ret < 0 ? NOTIFY_BAD : NOTIFY_OK;

static int evtchn_fifo_percpu_deinit(unsigned int cpu)
{
	__evtchn_fifo_handle_events(cpu, true);
	return 0;
}
}


static struct notifier_block evtchn_fifo_cpu_notifier = {
static const struct evtchn_ops evtchn_ops_fifo = {
	.notifier_call	= evtchn_fifo_cpu_notification,
	.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 __init xen_evtchn_fifo_init(void)
@@ -461,7 +451,6 @@ int __init xen_evtchn_fifo_init(void)


	evtchn_ops = &evtchn_ops_fifo;
	evtchn_ops = &evtchn_ops_fifo;


	register_cpu_notifier(&evtchn_fifo_cpu_notifier);
out:
out:
	put_cpu();
	put_cpu();
	return ret;
	return ret;
+3 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,9 @@ struct evtchn_ops {


	void (*handle_events)(unsigned cpu);
	void (*handle_events)(unsigned cpu);
	void (*resume)(void);
	void (*resume)(void);

	int (*percpu_init)(unsigned int cpu);
	int (*percpu_deinit)(unsigned int cpu);
};
};


extern const struct evtchn_ops *evtchn_ops;
extern const struct evtchn_ops *evtchn_ops;