hwmon: (fam15h_power) Disable preemption when reading registers
PATCH 1/1 hwmon: (fam15h_power) Disable preemption when reading registers
From: Borislav Petkov <[email protected]>
We need to read a bunch of registers on each compute unit and possibly on the current CPU too. Disable preemption around it.
--- drivers/hwmon/fam15h_power.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwmon/fam15h_power.c +6 -4
@@ -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);
Signature · 1 line
2.7.3
Guenter Roeck
maintainerQuoted 5 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
We need to read a bunch of registers on each compute unit and possibly on the current CPU too. Disable preemption around it.
An explanation would be helpful. Is this a bug fix ? I would like to get a confirmation from someone at AMD that this is really necessary.
Thanks,
Guenter
Quoted 48 lines
Signed-off-by Borislav Petkov <[email protected]>Cc Rui Huang <[email protected]>Cc Sherry Hurwitz <[email protected]>Cc Guenter Roeck <[email protected]>--- drivers/hwmon/fam15h_power.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/hwmon/fam15h_power.c +6
-4@@ -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);
Quoted 1 line · Guenter Roeck
An explanation would be helpful. Is this a bug fix ?
That's a good point - yes, it is necessary. Both smp_processor_id() *and* smp_call_function_many() need to be called with preemption disabled.
It did fire the BUG thing in check_preemption_disabled() with 4.7-rc1 here without those fixes.
But, we need the other patch too -
"[PATCH] x86/cpu/AMD: Extend X86_FEATURE_TOPOEXT workaround to newer models"
because the cpumask generation in read_registers() doesn't work on those Carrizo CPUs.
IINM, the breakage came in during this merge window so we don't have to CC:stable but both should be sent to Linus as fixes for 4.7.
You could sync with Ingo who takes/acks what... but they could go through tip and hwmon tree too, I don't see a hard dependency between the two - they'd only need to be in 4.7-final.
Thanks.
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Huang, Ray
maintainerQuoted 13 lines · Guenter Roeck
Quoted 6 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
We need to read a bunch of registers on each compute unit and possibly on the current CPU too. Disable preemption around it.
An explanation would be helpful. Is this a bug fix ? I would like to get a confirmation from someone at AMD that this is really necessary.
This change looks good for me. But I am in office this week, I will test it on CZ platform next week. :-)
Thanks,
Rui
Quoted 51 lines
Thanks,
GuenterQuoted 47 lines
Signed-off-by Borislav Petkov <[email protected]>Cc Rui Huang <[email protected]>Cc Sherry Hurwitz <[email protected]>Cc Guenter Roeck <[email protected]>--- drivers/hwmon/fam15h_power.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/hwmon/fam15h_power.c +6
-4@@ -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);
Huang, Ray
maintainerSent from my iPad
Quoted 9 lines · Ray
Quoted 8 lines
Quoted 8 lines · Guenter Roeck
On 06/01/2016 03:04 AM, Borislav Petkov wrote:
From: Borislav Petkov <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
We need to read a bunch of registers on each compute unit and possibly on the current CPU too. Disable preemption around it.
An explanation would be helpful. Is this a bug fix ? I would like to get a confirmation from someone at AMD that this is really necessary.
This change looks good for me. But I am in office this week, I will test it on CZ platform next week. :-)
Sorry, fix typo. I am *not* in office this week.
Rui
Guenter Roeck
maintainerQuoted 10 lines · Borislav Petkov
Quoted 1 line · Guenter Roeck
An explanation would be helpful. Is this a bug fix ?
That's a good point - yes, it is necessary. Both
smp_processor_id()*and*smp_call_function_many()need to be called with preemption disabled.It did fire the BUG thing in
check_preemption_disabled()with 4.7-rc1 here without those fixes.
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. If you had, I would not have asked, saving both of us time ;-).
Quoted 7 lines
But, we need the other patch too -
"[PATCH] x86/cpu/AMD: Extend
X86_FEATURE_TOPOEXTworkaround to newer models"because the cpumask generation in
read_registers()doesn't work on those Carrizo CPUs.
Quoted 7 lines
IINM, the breakage came in during this merge window so we don't have to CC:stable but both should be sent to Linus as fixes for 4.7.
You could sync with Ingo who takes/acks what... but they could go through tip and hwmon tree too, I don't see a hard dependency between the two - they'd only need to be in 4.7-final.
Sounds like separate trees should be fine then.
Thanks,
Guenter
Quoted 2 lines · Guenter Roeck
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 <[email protected]>
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 ...
--- drivers/hwmon/fam15h_power.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/hwmon/fam15h_power.c +6 -4
@@ -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);
Signature · 7 lines
2.7.3
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Quoted 21 lines · Borislav Petkov
static int
read_registers(struct fam15h_power_data *data){drivers/hwmon/fam15h_power.c +1
-2-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); }
drivers/hwmon/fam15h_power.c static int read_registers(struct fam15h_power_data *data) · line 214
Quoted 10 lines
drivers/hwmon/fam15h_power.c +5
-2-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
Quoted 5 lines · Thomas Gleixner
What's wrong with using:
on_each_cpu_mask()Which does all that magic for you?
Ha, very nice! Let me try it.
Thanks!
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Quoted 1 line · Borislav Petkov
Ha, very nice! Let me try it.
Yap, much better than opencoding on_each_cpu_mask() :-)
---
From: Borislav Petkov <[email protected]>
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 ...
--- drivers/hwmon/fam15h_power.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/hwmon/fam15h_power.c +2 -6
@@ -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 ;
Signature · 8 lines
2.7.3
--
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Guenter Roeck
maintainerQuoted 21 lines · Borislav Petkov
Quoted 1 line · Borislav Petkov
Ha, very nice! Let me try it.
Yap, much better than opencoding
on_each_cpu_mask():-)---
From: Borislav Petkov <[email protected]>
Date: Wed, 1 Jun 2016 11:36:13 +0200
Subject: [PATCH] hwmon: (fam15h_power) Disable preemption when reading
registersWe 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 ...
Quoted 6 lines
Suggested-by Thomas Gleixner <[email protected]>Signed-off-by Borislav Petkov <[email protected]>Cc Rui Huang <[email protected]>Cc Sherry Hurwitz <[email protected]>Cc Guenter Roeck <[email protected]>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
Quoted 3 lines · Guenter Roeck
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.
Signature · 4 lines
Regards/Gruss,
Boris.
ECO tip #101: Trim your mails when you reply.Guenter Roeck
maintainerQuoted 8 lines · Borislav Petkov
Quoted 3 lines · Guenter Roeck
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
Huang Rui
maintainerQuoted 6 lines · Guenter Roeck
Quoted 5 lines · Borislav Petkov
Quoted 3 lines · Guenter Roeck
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.
Quoted 6 lines
Quoted 3 lines
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.