Commit 8fba38c9 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Thomas Gleixner

x86/msr: Convert to hotplug state machine

Install the callbacks via the state machine and let the core invoke
the callbacks on the already online CPUs.

Move the callbacks to online/offline as there is no point in having the
files around before the cpu is online and until its completely gone.

[ tglx: Move the callbacks to online/offline ]
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: rt@linuxtronix.de
Link: http://lkml.kernel.org/r/20161117183541.8588-4-bigeasy@linutronix.deSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent ee92be9b
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <asm/msr.h> #include <asm/msr.h>
static struct class *msr_class; static struct class *msr_class;
static enum cpuhp_state cpuhp_msr_state;
static ssize_t msr_read(struct file *file, char __user *buf, static ssize_t msr_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
...@@ -180,7 +181,7 @@ static const struct file_operations msr_fops = { ...@@ -180,7 +181,7 @@ static const struct file_operations msr_fops = {
.compat_ioctl = msr_ioctl, .compat_ioctl = msr_ioctl,
}; };
static int msr_device_create(int cpu) static int msr_device_create(unsigned int cpu)
{ {
struct device *dev; struct device *dev;
...@@ -189,34 +190,12 @@ static int msr_device_create(int cpu) ...@@ -189,34 +190,12 @@ static int msr_device_create(int cpu)
return PTR_ERR_OR_ZERO(dev); return PTR_ERR_OR_ZERO(dev);
} }
static void msr_device_destroy(int cpu) static int msr_device_destroy(unsigned int cpu)
{ {
device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu)); device_destroy(msr_class, MKDEV(MSR_MAJOR, cpu));
return 0;
} }
static int msr_class_cpu_callback(struct notifier_block *nfb,
unsigned long action, void *hcpu)
{
unsigned int cpu = (unsigned long)hcpu;
int err = 0;
switch (action) {
case CPU_UP_PREPARE:
err = msr_device_create(cpu);
break;
case CPU_UP_CANCELED:
case CPU_UP_CANCELED_FROZEN:
case CPU_DEAD:
msr_device_destroy(cpu);
break;
}
return notifier_from_errno(err);
}
static struct notifier_block __refdata msr_class_cpu_notifier = {
.notifier_call = msr_class_cpu_callback,
};
static char *msr_devnode(struct device *dev, umode_t *mode) static char *msr_devnode(struct device *dev, umode_t *mode)
{ {
return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt)); return kasprintf(GFP_KERNEL, "cpu/%u/msr", MINOR(dev->devt));
...@@ -224,13 +203,11 @@ static char *msr_devnode(struct device *dev, umode_t *mode) ...@@ -224,13 +203,11 @@ static char *msr_devnode(struct device *dev, umode_t *mode)
static int __init msr_init(void) static int __init msr_init(void)
{ {
int i, err = 0; int err;
i = 0;
if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) { if (__register_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr", &msr_fops)) {
pr_err("unable to get major %d for msr\n", MSR_MAJOR); pr_err("unable to get major %d for msr\n", MSR_MAJOR);
err = -EBUSY; return -EBUSY;
goto out;
} }
msr_class = class_create(THIS_MODULE, "msr"); msr_class = class_create(THIS_MODULE, "msr");
if (IS_ERR(msr_class)) { if (IS_ERR(msr_class)) {
...@@ -239,44 +216,28 @@ static int __init msr_init(void) ...@@ -239,44 +216,28 @@ static int __init msr_init(void)
} }
msr_class->devnode = msr_devnode; msr_class->devnode = msr_devnode;
cpu_notifier_register_begin(); err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/msr:online",
for_each_online_cpu(i) { msr_device_create, msr_device_destroy);
err = msr_device_create(i); if (err < 0)
if (err != 0)
goto out_class; goto out_class;
} cpuhp_msr_state = err;
__register_hotcpu_notifier(&msr_class_cpu_notifier); return 0;
cpu_notifier_register_done();
err = 0;
goto out;
out_class: out_class:
i = 0; cpuhp_remove_state(cpuhp_msr_state);
for_each_online_cpu(i)
msr_device_destroy(i);
cpu_notifier_register_done();
class_destroy(msr_class); class_destroy(msr_class);
out_chrdev: out_chrdev:
__unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
out:
return err; return err;
} }
module_init(msr_init);
static void __exit msr_exit(void) static void __exit msr_exit(void)
{ {
int cpu = 0; cpuhp_remove_state(cpuhp_msr_state);
cpu_notifier_register_begin();
for_each_online_cpu(cpu)
msr_device_destroy(cpu);
class_destroy(msr_class); class_destroy(msr_class);
__unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr"); __unregister_chrdev(MSR_MAJOR, 0, NR_CPUS, "cpu/msr");
__unregister_hotcpu_notifier(&msr_class_cpu_notifier);
cpu_notifier_register_done();
} }
module_init(msr_init);
module_exit(msr_exit) module_exit(msr_exit)
MODULE_AUTHOR("H. Peter Anvin <hpa@zytor.com>"); MODULE_AUTHOR("H. Peter Anvin <hpa@zytor.com>");
......
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