public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro
@ 2024-04-09  5:23 Jarred White
  2024-04-16 17:24 ` Jarred White
  2024-04-17 17:36 ` Vanshidhar Konda
  0 siblings, 2 replies; 4+ messages in thread
From: Jarred White @ 2024-04-09  5:23 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Jarred White, Easwar Hariharan,
	open list:ACPI, open list
  Cc: Vanshidhar Konda, stable

Commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for
system memory accesses") neglected to properly wrap the bit_offset shift
when it comes to applying the mask. This may cause incorrect values to be
read and may cause the cpufreq module not be loaded.

[   11.059751] cpu_capacity: CPU0 missing/invalid highest performance.
[   11.066005] cpu_capacity: partial information: fallback to 1024 for all CPUs

Also, corrected the bitmask generation in GENMASK (extra bit being added).

Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
CC: Vanshidhar Konda <vanshikonda@os.amperecomputing.com> 
CC: stable@vger.kernel.org #5.15+
---
 drivers/acpi/cppc_acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 4bfbe55553f4..00a30ca35e78 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -170,8 +170,8 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
 #define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
 
 /* Shift and apply the mask for CPC reads/writes */
-#define MASK_VAL(reg, val) ((val) >> ((reg)->bit_offset & 			\
-					GENMASK(((reg)->bit_width), 0)))
+#define MASK_VAL(reg, val) (((val) >> (reg)->bit_offset) & 			\
+					GENMASK(((reg)->bit_width) - 1, 0))
 
 static ssize_t show_feedback_ctrs(struct kobject *kobj,
 		struct kobj_attribute *attr, char *buf)
-- 
2.33.8


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro
  2024-04-09  5:23 [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro Jarred White
@ 2024-04-16 17:24 ` Jarred White
  2024-04-17 17:36 ` Vanshidhar Konda
  1 sibling, 0 replies; 4+ messages in thread
From: Jarred White @ 2024-04-16 17:24 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Easwar Hariharan, open list:ACPI,
	open list
  Cc: Vanshidhar Konda, stable

On 4/8/2024 10:23 PM, Jarred White wrote:
> Commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for
> system memory accesses") neglected to properly wrap the bit_offset shift
> when it comes to applying the mask. This may cause incorrect values to be
> read and may cause the cpufreq module not be loaded.
> 
> [   11.059751] cpu_capacity: CPU0 missing/invalid highest performance.
> [   11.066005] cpu_capacity: partial information: fallback to 1024 for all CPUs
> 
> Also, corrected the bitmask generation in GENMASK (extra bit being added).
> 
> Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
> Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
> CC: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
> CC: stable@vger.kernel.org #5.15+
> ---
>   drivers/acpi/cppc_acpi.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index 4bfbe55553f4..00a30ca35e78 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -170,8 +170,8 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
>   #define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
>   
>   /* Shift and apply the mask for CPC reads/writes */
> -#define MASK_VAL(reg, val) ((val) >> ((reg)->bit_offset & 			\
> -					GENMASK(((reg)->bit_width), 0)))
> +#define MASK_VAL(reg, val) (((val) >> (reg)->bit_offset) & 			\
> +					GENMASK(((reg)->bit_width) - 1, 0))
>   
>   static ssize_t show_feedback_ctrs(struct kobject *kobj,
>   		struct kobj_attribute *attr, char *buf)

Hi Vanshi,

Could you review please?


Thanks,
Jarred

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro
  2024-04-09  5:23 [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro Jarred White
  2024-04-16 17:24 ` Jarred White
@ 2024-04-17 17:36 ` Vanshidhar Konda
  2024-04-22 16:43   ` Rafael J. Wysocki
  1 sibling, 1 reply; 4+ messages in thread
From: Vanshidhar Konda @ 2024-04-17 17:36 UTC (permalink / raw)
  To: Jarred White
  Cc: Rafael J. Wysocki, Len Brown, Easwar Hariharan, open list:ACPI,
	open list, stable

Looks good to me.

Reviewed-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>

On Mon, Apr 08, 2024 at 10:23:09PM -0700, Jarred White wrote:
>Commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for
>system memory accesses") neglected to properly wrap the bit_offset shift
>when it comes to applying the mask. This may cause incorrect values to be
>read and may cause the cpufreq module not be loaded.
>
>[   11.059751] cpu_capacity: CPU0 missing/invalid highest performance.
>[   11.066005] cpu_capacity: partial information: fallback to 1024 for all CPUs
>
>Also, corrected the bitmask generation in GENMASK (extra bit being added).
>
>Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
>Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
>CC: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
>CC: stable@vger.kernel.org #5.15+
>---
> drivers/acpi/cppc_acpi.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
>index 4bfbe55553f4..00a30ca35e78 100644
>--- a/drivers/acpi/cppc_acpi.c
>+++ b/drivers/acpi/cppc_acpi.c
>@@ -170,8 +170,8 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
> #define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
>
> /* Shift and apply the mask for CPC reads/writes */
>-#define MASK_VAL(reg, val) ((val) >> ((reg)->bit_offset & 			\
>-					GENMASK(((reg)->bit_width), 0)))
>+#define MASK_VAL(reg, val) (((val) >> (reg)->bit_offset) & 			\
>+					GENMASK(((reg)->bit_width) - 1, 0))
>
> static ssize_t show_feedback_ctrs(struct kobject *kobj,
> 		struct kobj_attribute *attr, char *buf)
>-- 
>2.33.8
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro
  2024-04-17 17:36 ` Vanshidhar Konda
@ 2024-04-22 16:43   ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2024-04-22 16:43 UTC (permalink / raw)
  To: Vanshidhar Konda, Jarred White
  Cc: Rafael J. Wysocki, Len Brown, Easwar Hariharan, open list:ACPI,
	open list, stable

On Wed, Apr 17, 2024 at 7:37 PM Vanshidhar Konda
<vanshikonda@os.amperecomputing.com> wrote:
>
> Looks good to me.
>
> Reviewed-by: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
>
> On Mon, Apr 08, 2024 at 10:23:09PM -0700, Jarred White wrote:
> >Commit 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for
> >system memory accesses") neglected to properly wrap the bit_offset shift
> >when it comes to applying the mask. This may cause incorrect values to be
> >read and may cause the cpufreq module not be loaded.
> >
> >[   11.059751] cpu_capacity: CPU0 missing/invalid highest performance.
> >[   11.066005] cpu_capacity: partial information: fallback to 1024 for all CPUs
> >
> >Also, corrected the bitmask generation in GENMASK (extra bit being added).
> >
> >Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
> >Signed-off-by: Jarred White <jarredwhite@linux.microsoft.com>
> >CC: Vanshidhar Konda <vanshikonda@os.amperecomputing.com>
> >CC: stable@vger.kernel.org #5.15+
> >---
> > drivers/acpi/cppc_acpi.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> >diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> >index 4bfbe55553f4..00a30ca35e78 100644
> >--- a/drivers/acpi/cppc_acpi.c
> >+++ b/drivers/acpi/cppc_acpi.c
> >@@ -170,8 +170,8 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
> > #define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
> >
> > /* Shift and apply the mask for CPC reads/writes */
> >-#define MASK_VAL(reg, val) ((val) >> ((reg)->bit_offset &                     \
> >-                                      GENMASK(((reg)->bit_width), 0)))
> >+#define MASK_VAL(reg, val) (((val) >> (reg)->bit_offset) &                    \
> >+                                      GENMASK(((reg)->bit_width) - 1, 0))
> >
> > static ssize_t show_feedback_ctrs(struct kobject *kobj,
> >               struct kobj_attribute *attr, char *buf)
> >--

Applied as 6.9-rc material, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-22 16:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09  5:23 [PATCH] ACPI: CPPC: Fix bit_offset shift in MASK_VAL macro Jarred White
2024-04-16 17:24 ` Jarred White
2024-04-17 17:36 ` Vanshidhar Konda
2024-04-22 16:43   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox