diff mbox

hwmon: (fam15h_power) Disable preemption when reading registers

Message ID 20160602072619.GB10803@pd.tnic (mailing list archive)
State Superseded
Headers show

Commit Message

Borislav Petkov June 2, 2016, 7:26 a.m. UTC
On Wed, Jun 01, 2016 at 11:15:09AM -0700, Guenter Roeck wrote:
> It would be great if you can add at least part of the BUG message as well
> as a Fixes: tag into the patch description.

How's that:

---
From: Borislav Petkov <bp@suse.de>
Date: Wed, 1 Jun 2016 11:36:13 +0200
Subject: [PATCH] hwmon: (fam15h_power) Disable preemption when reading registers

We need to read a bunch of registers on each compute unit and possibly
on the current CPU too. Disable preemption around it. Otherwise, you
get:

  BUG: using smp_processor_id() in preemptible [00000000] code: systemd-udevd/327
  caller is read_registers+0x6a/0x110 [fam15h_power]
  CPU: 3 PID: 327 Comm: systemd-udevd Not tainted 4.7.0-rc1+ #4
  Hardware name: HP HP EliteBook 745 G3/807E, BIOS N73 Ver. 01.08 01/28/2016
  ...

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Rui Huang <ray.huang@amd.com>
Cc: Sherry Hurwitz <sherry.hurwitz@amd.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Fixes: fa7943449943 ("hwmon: (fam15h_power) Add compute unit accumulated power")
---
 drivers/hwmon/fam15h_power.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Thomas Gleixner June 2, 2016, 7:47 a.m. UTC | #1
On Thu, 2 Jun 2016, Borislav Petkov wrote:
>  static int read_registers(struct fam15h_power_data *data)
>  {
> -	int this_cpu, ret, cpu;
>  	int core, this_core;
>  	cpumask_var_t mask;
> +	int ret, cpu;
>  
>  	ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
>  	if (!ret)
> @@ -183,7 +183,6 @@ static int read_registers(struct fam15h_power_data *data)
>  	memset(data->cu_on, 0, sizeof(int) * MAX_CUS);
>  
>  	get_online_cpus();
> -	this_cpu = smp_processor_id();
>  
>  	/*
>  	 * Choose the first online core of each compute unit, and then
> @@ -205,10 +204,13 @@ static int read_registers(struct fam15h_power_data *data)
>  		cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(cpu)), mask);
>  	}
>  
> -	if (cpumask_test_cpu(this_cpu, mask))
> +	preempt_disable();
> +	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
> +
> +	if (cpumask_test_cpu(smp_processor_id(), mask))
>  		do_read_registers_on_cu(data);
>  
> -	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
> +	preempt_enable();
>  	put_online_cpus();

What's wrong with using:

       on_each_cpu_mask()

Which does all that magic for you?

Thanks,

	tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Borislav Petkov June 2, 2016, 7:58 a.m. UTC | #2
On Thu, Jun 02, 2016 at 09:47:54AM +0200, Thomas Gleixner wrote:
> What's wrong with using:
> 
>        on_each_cpu_mask()
> 
> Which does all that magic for you?

Ha, very nice! Let me try it.

Thanks!
diff mbox

Patch

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index eb97a9241d17..69bb810f528b 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -172,9 +172,9 @@  static void do_read_registers_on_cu(void *_data)
  */
 static int read_registers(struct fam15h_power_data *data)
 {
-	int this_cpu, ret, cpu;
 	int core, this_core;
 	cpumask_var_t mask;
+	int ret, cpu;
 
 	ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
 	if (!ret)
@@ -183,7 +183,6 @@  static int read_registers(struct fam15h_power_data *data)
 	memset(data->cu_on, 0, sizeof(int) * MAX_CUS);
 
 	get_online_cpus();
-	this_cpu = smp_processor_id();
 
 	/*
 	 * Choose the first online core of each compute unit, and then
@@ -205,10 +204,13 @@  static int read_registers(struct fam15h_power_data *data)
 		cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(cpu)), mask);
 	}
 
-	if (cpumask_test_cpu(this_cpu, mask))
+	preempt_disable();
+	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
+
+	if (cpumask_test_cpu(smp_processor_id(), mask))
 		do_read_registers_on_cu(data);
 
-	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
+	preempt_enable();
 	put_online_cpus();
 
 	free_cpumask_var(mask);