Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371213

[PATCH v4 5/6] dcdbas: make use of smp_call_on_cpu()

From Juergen Gross <jgross@suse.com>
Newsgroups linux.kernel
Subject [PATCH v4 5/6] dcdbas: make use of smp_call_on_cpu()
Date 2016-04-05 07:20 +0200
Message-ID <rkrzc-6vm-15@gated-at.bofh.it> (permalink)
References <rkrzc-6vm-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Use smp_call_on_cpu() to raise SMI on cpu 0.
Make call secure by adding get_online_cpus() to avoid e.g. suspend
resume cycles in between.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V4: add call to get_online_cpus()
---
 drivers/firmware/dcdbas.c | 51 ++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 829eec8..68e1d38 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -23,6 +23,7 @@
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/errno.h>
+#include <linux/cpu.h>
 #include <linux/gfp.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -238,33 +239,14 @@ static ssize_t host_control_on_shutdown_store(struct device *dev,
 	return count;
 }
 
-/**
- * dcdbas_smi_request: generate SMI request
- *
- * Called with smi_data_lock.
- */
-int dcdbas_smi_request(struct smi_cmd *smi_cmd)
+static int raise_smi(void *par)
 {
-	cpumask_var_t old_mask;
-	int ret = 0;
+	struct smi_cmd *smi_cmd = par;
 
-	if (smi_cmd->magic != SMI_CMD_MAGIC) {
-		dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
-			 __func__);
-		return -EBADR;
-	}
-
-	/* SMI requires CPU 0 */
-	if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
-		return -ENOMEM;
-
-	cpumask_copy(old_mask, &current->cpus_allowed);
-	set_cpus_allowed_ptr(current, cpumask_of(0));
 	if (smp_processor_id() != 0) {
 		dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
 			__func__);
-		ret = -EBUSY;
-		goto out;
+		return -EBUSY;
 	}
 
 	/* generate SMI */
@@ -280,9 +262,28 @@ int dcdbas_smi_request(struct smi_cmd *smi_cmd)
 		: "memory"
 	);
 
-out:
-	set_cpus_allowed_ptr(current, old_mask);
-	free_cpumask_var(old_mask);
+	return 0;
+}
+/**
+ * dcdbas_smi_request: generate SMI request
+ *
+ * Called with smi_data_lock.
+ */
+int dcdbas_smi_request(struct smi_cmd *smi_cmd)
+{
+	int ret;
+
+	if (smi_cmd->magic != SMI_CMD_MAGIC) {
+		dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
+			 __func__);
+		return -EBADR;
+	}
+
+	/* SMI requires CPU 0 */
+	get_online_cpus();
+	ret = smp_call_on_cpu(0, true, raise_smi, smi_cmd);
+	put_online_cpus();
+
 	return ret;
 }
 
-- 
2.6.2

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/6] Support calling functions on dedicated physical cpu Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
  [PATCH v4 1/6] xen: sync xen header Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
    Re: [Xen-devel] [PATCH v4 1/6] xen: sync xen header David Vrabel <david.vrabel@citrix.com> - 2016-04-05 11:40 +0200
  [PATCH v4 4/6] xen: add xen_pin_vcpu() to support calling functions on a dedicated pcpu Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
    Re: [Xen-devel] [PATCH v4 4/6] xen: add xen_pin_vcpu() to support  calling functions on a dedicated pcpu David Vrabel <david.vrabel@citrix.com> - 2016-04-05 11:50 +0200
      Re: [Xen-devel] [PATCH v4 4/6] xen: add xen_pin_vcpu() to support  calling functions on a dedicated pcpu David Vrabel <david.vrabel@citrix.com> - 2016-04-05 12:10 +0200
      Re: [Xen-devel] [PATCH v4 4/6] xen: add xen_pin_vcpu() to support  calling functions on a dedicated pcpu Juergen Gross <jgross@suse.com> - 2016-04-05 12:10 +0200
  [PATCH v4 3/6] smp: add function to execute a function synchronously on a cpu Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
    Re: [PATCH v4 3/6] smp: add function to execute a function  synchronously on a cpu Peter Zijlstra <peterz@infradead.org> - 2016-04-05 10:20 +0200
      Re: [PATCH v4 3/6] smp: add function to execute a function  synchronously on a cpu Juergen Gross <jgross@suse.com> - 2016-04-05 12:10 +0200
  [PATCH v4 6/6] hwmon: use smp_call_on_cpu() for dell-smm i8k Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
    Re: [PATCH v4 6/6] hwmon: use smp_call_on_cpu() for dell-smm i8k Guenter Roeck <linux@roeck-us.net> - 2016-04-05 17:00 +0200
      Re: [PATCH v4 6/6] hwmon: use smp_call_on_cpu() for dell-smm i8k Pali Rohár <pali.rohar@gmail.com> - 2016-04-05 21:40 +0200
  [PATCH v4 2/6] virt, sched: add generic vcpu pinning support Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200
  [PATCH v4 5/6] dcdbas: make use of smp_call_on_cpu() Juergen Gross <jgross@suse.com> - 2016-04-05 07:20 +0200

csiph-web