Commit 27046a3f authored by Juergen Gross's avatar Juergen Gross Committed by Ingo Molnar

hwmon: Use smp_call_on_cpu() for dell-smm i8k

Use the smp_call_on_cpu() function to call system management
mode on CPU 0.
Make call secure by adding get_online_cpus() to avoid e.g. suspend
resume cycles in between.
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Douglas_Warzecha@dell.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: akataria@vmware.com
Cc: boris.ostrovsky@oracle.com
Cc: chrisw@sous-sol.org
Cc: david.vrabel@citrix.com
Cc: hpa@zytor.com
Cc: jdelvare@suse.com
Cc: jeremy@goop.org
Cc: linux@roeck-us.net
Cc: pali.rohar@gmail.com
Cc: rusty@rustcorp.com.au
Cc: virtualization@lists.linux-foundation.org
Cc: xen-devel@lists.xenproject.org
Link: http://lkml.kernel.org/r/1472453327-19050-7-git-send-email-jgross@suse.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent e23f22b5
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/cpu.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/types.h> #include <linux/types.h>
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/smp.h>
#include <linux/i8k.h> #include <linux/i8k.h>
...@@ -134,11 +136,11 @@ static inline const char *i8k_get_dmi_data(int field) ...@@ -134,11 +136,11 @@ static inline const char *i8k_get_dmi_data(int field)
/* /*
* Call the System Management Mode BIOS. Code provided by Jonathan Buzzard. * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
*/ */
static int i8k_smm(struct smm_regs *regs) static int i8k_smm_func(void *par)
{ {
int rc; int rc;
struct smm_regs *regs = par;
int eax = regs->eax; int eax = regs->eax;
cpumask_var_t old_mask;
#ifdef DEBUG #ifdef DEBUG
int ebx = regs->ebx; int ebx = regs->ebx;
...@@ -149,16 +151,8 @@ static int i8k_smm(struct smm_regs *regs) ...@@ -149,16 +151,8 @@ static int i8k_smm(struct smm_regs *regs)
#endif #endif
/* SMM requires CPU 0 */ /* SMM requires CPU 0 */
if (!alloc_cpumask_var(&old_mask, GFP_KERNEL)) if (smp_processor_id() != 0)
return -ENOMEM; return -EBUSY;
cpumask_copy(old_mask, &current->cpus_allowed);
rc = set_cpus_allowed_ptr(current, cpumask_of(0));
if (rc)
goto out;
if (smp_processor_id() != 0) {
rc = -EBUSY;
goto out;
}
#if defined(CONFIG_X86_64) #if defined(CONFIG_X86_64)
asm volatile("pushq %%rax\n\t" asm volatile("pushq %%rax\n\t"
...@@ -216,10 +210,6 @@ static int i8k_smm(struct smm_regs *regs) ...@@ -216,10 +210,6 @@ static int i8k_smm(struct smm_regs *regs)
if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax) if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
rc = -EINVAL; rc = -EINVAL;
out:
set_cpus_allowed_ptr(current, old_mask);
free_cpumask_var(old_mask);
#ifdef DEBUG #ifdef DEBUG
rettime = ktime_get(); rettime = ktime_get();
delta = ktime_sub(rettime, calltime); delta = ktime_sub(rettime, calltime);
...@@ -231,6 +221,20 @@ static int i8k_smm(struct smm_regs *regs) ...@@ -231,6 +221,20 @@ static int i8k_smm(struct smm_regs *regs)
return rc; return rc;
} }
/*
* Call the System Management Mode BIOS.
*/
static int i8k_smm(struct smm_regs *regs)
{
int ret;
get_online_cpus();
ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
put_online_cpus();
return ret;
}
/* /*
* Read the fan status. * Read the fan status.
*/ */
......
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