diff mbox

hwmon: (fam15h_power) Disable preemption when reading registers

Message ID 20160602081439.GD10803@pd.tnic (mailing list archive)
State Accepted
Headers show

Commit Message

Borislav Petkov June 2, 2016, 8:14 a.m. UTC
On Thu, Jun 02, 2016 at 09:58:30AM +0200, Borislav Petkov wrote:
> Ha, very nice! Let me try it.

Yap, much better than opencoding on_each_cpu_mask() :-)

---
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
  ...

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
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 | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Guenter Roeck June 3, 2016, 6:18 p.m. UTC | #1
On Thu, Jun 02, 2016 at 10:14:39AM +0200, Borislav Petkov wrote:
> On Thu, Jun 02, 2016 at 09:58:30AM +0200, Borislav Petkov wrote:
> > Ha, very nice! Let me try it.
> 
> Yap, much better than opencoding on_each_cpu_mask() :-)
> 
> ---
> 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
>   ...
> 
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> 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")

I like this version. Applied, though it would be nice to get a Tested-by: or
Acked-by: from someone at AMD. I'll hold back until early next week before
sending it to Linus.

Thanks,
Guenter
--
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 3, 2016, 6:29 p.m. UTC | #2
On Fri, Jun 03, 2016 at 11:18:36AM -0700, Guenter Roeck wrote:
> I like this version. Applied, though it would be nice to get a
> Tested-by: or Acked-by: from someone at AMD. I'll hold back until
> early next week before sending it to Linus.

If it makes you feel any better: I have the affected hardware and am
testing on it too. I wouldnt've caught it otherwise.
Guenter Roeck June 4, 2016, 2:55 p.m. UTC | #3
On 06/03/2016 11:29 AM, Borislav Petkov wrote:
> On Fri, Jun 03, 2016 at 11:18:36AM -0700, Guenter Roeck wrote:
>> I like this version. Applied, though it would be nice to get a
>> Tested-by: or Acked-by: from someone at AMD. I'll hold back until
>> early next week before sending it to Linus.
>
> If it makes you feel any better: I have the affected hardware and am
> testing on it too. I wouldnt've caught it otherwise.
>

I'll send it to Linus next week unless I get an objection.

Guenter

--
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
Huang Rui June 6, 2016, 7:58 a.m. UTC | #4
On Sat, Jun 04, 2016 at 07:55:08AM -0700, Guenter Roeck wrote:
> On 06/03/2016 11:29 AM, Borislav Petkov wrote:
> >On Fri, Jun 03, 2016 at 11:18:36AM -0700, Guenter Roeck wrote:
> >>I like this version. Applied, though it would be nice to get a
> >>Tested-by: or Acked-by: from someone at AMD. I'll hold back until
> >>early next week before sending it to Linus.
> >
> >If it makes you feel any better: I have the affected hardware and am
> >testing on it too. I wouldnt've caught it otherwise.
> >
> 
> I'll send it to Linus next week unless I get an objection.
> 

Guenter, I already verified on AMD CZ(family 15h, model 60h) and model
70h processors.

Acked-and-tested-by: Huang Rui <ray.huang@amd.com>
--
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
diff mbox

Patch

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index eb97a9241d17..15aa49d082c4 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,12 +204,9 @@  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))
-		do_read_registers_on_cu(data);
+	on_each_cpu_mask(mask, do_read_registers_on_cu, data, true);
 
-	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
 	put_online_cpus();
-
 	free_cpumask_var(mask);
 
 	return 0;