Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>
Acked-by: Huang Rui <ray.huang@amd.com>
Tested-by: Huang Rui <ray.huang@amd.com>
Fixes: fa7943449943 ("hwmon: (fam15h_power) Add compute unit accumulated power")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Borislav Petkov and committed by
Guenter Roeck
7be48818 af8c34ce

+2 -6
+2 -6
drivers/hwmon/fam15h_power.c
··· 172 172 */ 173 173 static int read_registers(struct fam15h_power_data *data) 174 174 { 175 - int this_cpu, ret, cpu; 176 175 int core, this_core; 177 176 cpumask_var_t mask; 177 + int ret, cpu; 178 178 179 179 ret = zalloc_cpumask_var(&mask, GFP_KERNEL); 180 180 if (!ret) ··· 183 183 memset(data->cu_on, 0, sizeof(int) * MAX_CUS); 184 184 185 185 get_online_cpus(); 186 - this_cpu = smp_processor_id(); 187 186 188 187 /* 189 188 * Choose the first online core of each compute unit, and then ··· 204 205 cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(cpu)), mask); 205 206 } 206 207 207 - if (cpumask_test_cpu(this_cpu, mask)) 208 - do_read_registers_on_cu(data); 208 + on_each_cpu_mask(mask, do_read_registers_on_cu, data, true); 209 209 210 - smp_call_function_many(mask, do_read_registers_on_cu, data, true); 211 210 put_online_cpus(); 212 - 213 211 free_cpumask_var(mask); 214 212 215 213 return 0;