2015-12-08 18:33:29

by Prarit Bhargava

[permalink] [raw]
Subject: [PATCH] powercap, intel_rapl.c, fix BIOS lock check

Intel RAPL initialized on several systems where the BIOS lock bit (msr
0x610, bit 63) was set. This occured because the return value of
rapl_read_data_raw() was being checked, rather than the value of the variable
passed in, locked.

This patch properly implments the rapl_read_data_raw() call to check the
variable locked, and now the Intel RAPL driver outputs the warning:

intel_rapl: RAPL package 0 domain package locked by BIOS

and does not initialize for the package.

Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Jacob Pan <[email protected]>
Cc: Radivoje Jovanovic <[email protected]>
Cc: Seiichi Ikarashi <[email protected]>
Cc: Mathias Krause <[email protected]>
Cc: Ajay Thomas <[email protected]>
Signed-off-by: Prarit Bhargava <[email protected]>
---
drivers/powercap/intel_rapl.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index cc97f08..0b0d09d 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -1341,11 +1341,13 @@ static int rapl_detect_domains(struct rapl_package *rp, int cpu)

for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
/* check if the domain is locked by BIOS */
- if (rapl_read_data_raw(rd, FW_LOCK, false, &locked)) {
+ ret = rapl_read_data_raw(rd, FW_LOCK, false, &locked);
+ if (ret)
+ return ret;
+ if (locked)
pr_info("RAPL package %d domain %s locked by BIOS\n",
rp->id, rd->name);
rd->state |= DOMAIN_STATE_BIOS_LOCKED;
- }
}


--
1.7.9.3


2015-12-08 23:31:13

by Jacob Pan

[permalink] [raw]
Subject: Re: [PATCH] powercap, intel_rapl.c, fix BIOS lock check

On Tue, 8 Dec 2015 13:33:22 -0500
Prarit Bhargava <[email protected]> wrote:

> Intel RAPL initialized on several systems where the BIOS lock bit (msr
> 0x610, bit 63) was set. This occured because the return value of
> rapl_read_data_raw() was being checked, rather than the value of the
> variable passed in, locked.
>
> This patch properly implments the rapl_read_data_raw() call to check
> the variable locked, and now the Intel RAPL driver outputs the
> warning:
>
> intel_rapl: RAPL package 0 domain package locked by BIOS
>
> and does not initialize for the package.
Looks good to me.

2015-12-09 00:24:27

by Seiichi Ikarashi

[permalink] [raw]
Subject: Re: [PATCH] powercap, intel_rapl.c, fix BIOS lock check

On 2015-12-09 03:33, Prarit Bhargava wrote:
> Intel RAPL initialized on several systems where the BIOS lock bit (msr
> 0x610, bit 63) was set. This occured because the return value of
> rapl_read_data_raw() was being checked, rather than the value of the variable
> passed in, locked.
>
> This patch properly implments the rapl_read_data_raw() call to check the
> variable locked, and now the Intel RAPL driver outputs the warning:
>
> intel_rapl: RAPL package 0 domain package locked by BIOS
>
> and does not initialize for the package.
>
> Cc: "Rafael J. Wysocki" <[email protected]>
> Cc: Jacob Pan <[email protected]>
> Cc: Radivoje Jovanovic <[email protected]>
> Cc: Seiichi Ikarashi <[email protected]>
> Cc: Mathias Krause <[email protected]>
> Cc: Ajay Thomas <[email protected]>
> Signed-off-by: Prarit Bhargava <[email protected]>
> ---
> drivers/powercap/intel_rapl.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
> index cc97f08..0b0d09d 100644
> --- a/drivers/powercap/intel_rapl.c
> +++ b/drivers/powercap/intel_rapl.c
> @@ -1341,11 +1341,13 @@ static int rapl_detect_domains(struct rapl_package *rp, int cpu)
>
> for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
> /* check if the domain is locked by BIOS */
> - if (rapl_read_data_raw(rd, FW_LOCK, false, &locked)) {
> + ret = rapl_read_data_raw(rd, FW_LOCK, false, &locked);
> + if (ret)
> + return ret;
> + if (locked)
> pr_info("RAPL package %d domain %s locked by BIOS\n",
> rp->id, rd->name);
> rd->state |= DOMAIN_STATE_BIOS_LOCKED;
> - }
> }

A good spot!
But this patch looks setting DOMAIN_STATE_BIOS_LOCKED bit to all package domains.
I suppose what you are going to do is like below.

--- a/drivers/powercap/intel_rapl.c 2015-11-02 09:05:25.000000000 +0900
+++ b/drivers/powercap/intel_rapl.c 2015-12-09 09:05:33.386142840 +0900
@@ -1340,10 +1340,13 @@ static int rapl_detect_domains(struct ra

for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
/* check if the domain is locked by BIOS */
- if (rapl_read_data_raw(rd, FW_LOCK, false, &locked)) {
+ ret = rapl_read_data_raw(rd, FW_LOCK, false, &locked);
+ if (ret)
+ return ret;
+ if (locked) {
pr_info("RAPL package %d domain %s locked by BIOS\n",
rp->id, rd->name);
- rd->state |= DOMAIN_STATE_BIOS_LOCKED;
+ rd->state |= DOMAIN_STATE_BIOS_LOCKED;
}
}

2015-12-09 13:27:09

by Prarit Bhargava

[permalink] [raw]
Subject: Re: [PATCH] powercap, intel_rapl.c, fix BIOS lock check



On 12/08/2015 07:12 PM, Seiichi Ikarashi wrote:
> On 2015-12-09 03:33, Prarit Bhargava wrote:
>> Intel RAPL initialized on several systems where the BIOS lock bit (msr
>> 0x610, bit 63) was set. This occured because the return value of
>> rapl_read_data_raw() was being checked, rather than the value of the variable
>> passed in, locked.
>>
>> This patch properly implments the rapl_read_data_raw() call to check the
>> variable locked, and now the Intel RAPL driver outputs the warning:
>>
>> intel_rapl: RAPL package 0 domain package locked by BIOS
>>
>> and does not initialize for the package.
>>
>> Cc: "Rafael J. Wysocki" <[email protected]>
>> Cc: Jacob Pan <[email protected]>
>> Cc: Radivoje Jovanovic <[email protected]>
>> Cc: Seiichi Ikarashi <[email protected]>
>> Cc: Mathias Krause <[email protected]>
>> Cc: Ajay Thomas <[email protected]>
>> Signed-off-by: Prarit Bhargava <[email protected]>
>> ---
>> drivers/powercap/intel_rapl.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
>> index cc97f08..0b0d09d 100644
>> --- a/drivers/powercap/intel_rapl.c
>> +++ b/drivers/powercap/intel_rapl.c
>> @@ -1341,11 +1341,13 @@ static int rapl_detect_domains(struct rapl_package *rp, int cpu)
>>
>> for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
>> /* check if the domain is locked by BIOS */
>> - if (rapl_read_data_raw(rd, FW_LOCK, false, &locked)) {
>> + ret = rapl_read_data_raw(rd, FW_LOCK, false, &locked);
>> + if (ret)
>> + return ret;
>> + if (locked)
>> pr_info("RAPL package %d domain %s locked by BIOS\n",
>> rp->id, rd->name);
>> rd->state |= DOMAIN_STATE_BIOS_LOCKED;
>> - }
>> }
>
> A good spot!
> But this patch looks setting DOMAIN_STATE_BIOS_LOCKED bit to all package domains.
> I suppose what you are going to do is like below.
>
> --- a/drivers/powercap/intel_rapl.c 2015-11-02 09:05:25.000000000 +0900
> +++ b/drivers/powercap/intel_rapl.c 2015-12-09 09:05:33.386142840 +0900
> @@ -1340,10 +1340,13 @@ static int rapl_detect_domains(struct ra
>
> for (rd = rp->domains; rd < rp->domains + rp->nr_domains; rd++) {
> /* check if the domain is locked by BIOS */
> - if (rapl_read_data_raw(rd, FW_LOCK, false, &locked)) {
> + ret = rapl_read_data_raw(rd, FW_LOCK, false, &locked);
> + if (ret)
> + return ret;
> + if (locked) {
> pr_info("RAPL package %d domain %s locked by BIOS\n",
> rp->id, rd->name);
> - rd->state |= DOMAIN_STATE_BIOS_LOCKED;
> + rd->state |= DOMAIN_STATE_BIOS_LOCKED;
> }
> }

Oh geez :) Of course ... I'll resubmit shortly.

P.

>
>