From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bh-25.webhostbox.net ([208.91.199.152]:53627 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752901AbcFANXK (ORCPT ); Wed, 1 Jun 2016 09:23:10 -0400 Subject: Re: [PATCH] hwmon: (fam15h_power) Disable preemption when reading registers To: Borislav Petkov , linux-hwmon@vger.kernel.org References: <1464775486-23446-1-git-send-email-bp@alien8.de> Cc: X86 ML , LKML , Rui Huang , Sherry Hurwitz From: Guenter Roeck Message-ID: <574EE1B3.9010704@roeck-us.net> Date: Wed, 1 Jun 2016 06:22:59 -0700 MIME-Version: 1.0 In-Reply-To: <1464775486-23446-1-git-send-email-bp@alien8.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-hwmon-owner@vger.kernel.org List-Id: linux-hwmon@vger.kernel.org On 06/01/2016 03:04 AM, Borislav Petkov wrote: > From: Borislav Petkov > > 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 > Signed-off-by: Borislav Petkov > Cc: Rui Huang > Cc: Sherry Hurwitz > Cc: Guenter Roeck > --- > drivers/hwmon/fam15h_power.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > 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); >