mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse
@ 2026-06-01 23:58 Jeremy Linton
  2026-06-02 18:32 ` Jarred White
  2026-06-05 16:33 ` Easwar Hariharan
  0 siblings, 2 replies; 4+ messages in thread
From: Jeremy Linton @ 2026-06-01 23:58 UTC (permalink / raw)
  To: linux-acpi
  Cc: jarredwhite, easwar.hariharan, lenb, rafael, linux-kernel, Jeremy Linton

The definition of reg->access_width changes depending on the
reg->space_id type.  Type ACPI_ADR_SPACE_PLATFORM_COMM uses
access_width to indicate the PCC region, which can result in a UBSAN
if the value is greater than 4.

For example:

 UBSAN: shift-out-of-bounds in drivers/acpi/cppc_acpi.c:1090:9
 shift exponent 32 is too large for 32-bit type 'int'
 CPU: 61 UID: 0 PID: 1220 Comm: (udev-worker) Not tainted 7.0.10-201.fc44.aarch64 #1 PREEMPT(lazy)
 Hardware name: To be filled by O.E.M.
 Call trace:
  ...(trimming)
  ubsan_epilogue+0x10/0x48
  __ubsan_handle_shift_out_of_bounds+0xdc/0x1e0
  cpc_write+0x4d0/0x670
  cppc_set_perf+0x18c/0x490
  cppc_cpufreq_cpu_init+0x1c8/0x380 [cppc_cpufreq]
  ... (trimming)

Lets fix this by validating the region type, as well as whether
access_width has a value. Then since we are returning bit_width
directly for ACPI_ADR_SPACE_PLATFORM_COMM, drop the code correcting
the size.

Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 drivers/acpi/cppc_acpi.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index f370be8715ae..34edec0f2bde 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -185,8 +185,13 @@ show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_freq);
 
 show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
 
-/* Check for valid access_width, otherwise, fallback to using bit_width */
-#define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
+/*
+ * PCC reuses the access_width field as the subspace id, so only decode access
+ * size for non-PCC registers. Otherwise, use the bit_width.
+ */
+#define GET_BIT_WIDTH(reg) (((reg)->access_width &&				\
+			     (reg)->space_id != ACPI_ADR_SPACE_PLATFORM_COMM) ? \
+			    (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
 
 /* Shift and apply the mask for CPC reads/writes */
 #define MASK_VAL_READ(reg, val) (((val) >> (reg)->bit_offset) &				\
@@ -1045,7 +1050,6 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
 		 * by the bit width field; the access size is used to indicate
 		 * the PCC subspace id.
 		 */
-		size = reg->bit_width;
 		vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
 	}
 	else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
@@ -1118,7 +1122,6 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
 		 * by the bit width field; the access size is used to indicate
 		 * the PCC subspace id.
 		 */
-		size = reg->bit_width;
 		vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
 	}
 	else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
-- 
2.54.0


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

* Re: [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse
  2026-06-01 23:58 [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse Jeremy Linton
@ 2026-06-02 18:32 ` Jarred White
  2026-06-05 16:33 ` Easwar Hariharan
  1 sibling, 0 replies; 4+ messages in thread
From: Jarred White @ 2026-06-02 18:32 UTC (permalink / raw)
  To: Jeremy Linton, linux-acpi; +Cc: easwar.hariharan, lenb, rafael, linux-kernel

On 6/1/2026 4:58 PM, Jeremy Linton wrote:
> The definition of reg->access_width changes depending on the
> reg->space_id type.  Type ACPI_ADR_SPACE_PLATFORM_COMM uses
> access_width to indicate the PCC region, which can result in a UBSAN
> if the value is greater than 4.
> 
> For example:
> 
>   UBSAN: shift-out-of-bounds in drivers/acpi/cppc_acpi.c:1090:9
>   shift exponent 32 is too large for 32-bit type 'int'
>   CPU: 61 UID: 0 PID: 1220 Comm: (udev-worker) Not tainted 7.0.10-201.fc44.aarch64 #1 PREEMPT(lazy)
>   Hardware name: To be filled by O.E.M.
>   Call trace:
>    ...(trimming)
>    ubsan_epilogue+0x10/0x48
>    __ubsan_handle_shift_out_of_bounds+0xdc/0x1e0
>    cpc_write+0x4d0/0x670
>    cppc_set_perf+0x18c/0x490
>    cppc_cpufreq_cpu_init+0x1c8/0x380 [cppc_cpufreq]
>    ... (trimming)
> 
> Lets fix this by validating the region type, as well as whether
> access_width has a value. Then since we are returning bit_width
> directly for ACPI_ADR_SPACE_PLATFORM_COMM, drop the code correcting
> the size.
> 
> Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> ---
>   drivers/acpi/cppc_acpi.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 

This change looks good!
Tested-by: Jarred White <jarredwhite@linux.microsoft.com>
Reviewed-by: Jarred White <jarredwhite@linux.microsoft.com>

> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index f370be8715ae..34edec0f2bde 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -185,8 +185,13 @@ show_cppc_data(cppc_get_perf_caps, cppc_perf_caps, nominal_freq);
>   
>   show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
>   
> -/* Check for valid access_width, otherwise, fallback to using bit_width */
> -#define GET_BIT_WIDTH(reg) ((reg)->access_width ? (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
> +/*
> + * PCC reuses the access_width field as the subspace id, so only decode access
> + * size for non-PCC registers. Otherwise, use the bit_width.
> + */
> +#define GET_BIT_WIDTH(reg) (((reg)->access_width &&				\
> +			     (reg)->space_id != ACPI_ADR_SPACE_PLATFORM_COMM) ? \
> +			    (8 << ((reg)->access_width - 1)) : (reg)->bit_width)
>   
>   /* Shift and apply the mask for CPC reads/writes */
>   #define MASK_VAL_READ(reg, val) (((val) >> (reg)->bit_offset) &				\
> @@ -1045,7 +1050,6 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
>   		 * by the bit width field; the access size is used to indicate
>   		 * the PCC subspace id.
>   		 */
> -		size = reg->bit_width;
>   		vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
>   	}
>   	else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
> @@ -1118,7 +1122,6 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
>   		 * by the bit width field; the access size is used to indicate
>   		 * the PCC subspace id.
>   		 */
> -		size = reg->bit_width;
>   		vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
>   	}
>   	else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)


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

* Re: [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse
  2026-06-01 23:58 [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse Jeremy Linton
  2026-06-02 18:32 ` Jarred White
@ 2026-06-05 16:33 ` Easwar Hariharan
  2026-06-08 12:25   ` Rafael J. Wysocki
  1 sibling, 1 reply; 4+ messages in thread
From: Easwar Hariharan @ 2026-06-05 16:33 UTC (permalink / raw)
  To: Jeremy Linton
  Cc: linux-acpi, easwar.hariharan, jarredwhite, lenb, rafael, linux-kernel

On 6/1/2026 16:58, Jeremy Linton wrote:
> The definition of reg->access_width changes depending on the
> reg->space_id type.  Type ACPI_ADR_SPACE_PLATFORM_COMM uses
> access_width to indicate the PCC region, which can result in a UBSAN
> if the value is greater than 4.
> 
> For example:
> 
>  UBSAN: shift-out-of-bounds in drivers/acpi/cppc_acpi.c:1090:9
>  shift exponent 32 is too large for 32-bit type 'int'
>  CPU: 61 UID: 0 PID: 1220 Comm: (udev-worker) Not tainted 7.0.10-201.fc44.aarch64 #1 PREEMPT(lazy)
>  Hardware name: To be filled by O.E.M.
>  Call trace:
>   ...(trimming)
>   ubsan_epilogue+0x10/0x48
>   __ubsan_handle_shift_out_of_bounds+0xdc/0x1e0
>   cpc_write+0x4d0/0x670
>   cppc_set_perf+0x18c/0x490
>   cppc_cpufreq_cpu_init+0x1c8/0x380 [cppc_cpufreq]
>   ... (trimming)
> 
> Lets fix this by validating the region type, as well as whether
> access_width has a value. Then since we are returning bit_width
> directly for ACPI_ADR_SPACE_PLATFORM_COMM, drop the code correcting
> the size.
> 
> Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> ---
>  drivers/acpi/cppc_acpi.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
Reviewed-by: Easwar Hariharan <easwar.hariharan@linux.microsoft.com>

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

* Re: [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse
  2026-06-05 16:33 ` Easwar Hariharan
@ 2026-06-08 12:25   ` Rafael J. Wysocki
  0 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2026-06-08 12:25 UTC (permalink / raw)
  To: Easwar Hariharan, Jeremy Linton; +Cc: linux-acpi, jarredwhite, linux-kernel

On Fri, Jun 5, 2026 at 6:33 PM Easwar Hariharan
<easwar.hariharan@linux.microsoft.com> wrote:
>
> On 6/1/2026 16:58, Jeremy Linton wrote:
> > The definition of reg->access_width changes depending on the
> > reg->space_id type.  Type ACPI_ADR_SPACE_PLATFORM_COMM uses
> > access_width to indicate the PCC region, which can result in a UBSAN
> > if the value is greater than 4.
> >
> > For example:
> >
> >  UBSAN: shift-out-of-bounds in drivers/acpi/cppc_acpi.c:1090:9
> >  shift exponent 32 is too large for 32-bit type 'int'
> >  CPU: 61 UID: 0 PID: 1220 Comm: (udev-worker) Not tainted 7.0.10-201.fc44.aarch64 #1 PREEMPT(lazy)
> >  Hardware name: To be filled by O.E.M.
> >  Call trace:
> >   ...(trimming)
> >   ubsan_epilogue+0x10/0x48
> >   __ubsan_handle_shift_out_of_bounds+0xdc/0x1e0
> >   cpc_write+0x4d0/0x670
> >   cppc_set_perf+0x18c/0x490
> >   cppc_cpufreq_cpu_init+0x1c8/0x380 [cppc_cpufreq]
> >   ... (trimming)
> >
> > Lets fix this by validating the region type, as well as whether
> > access_width has a value. Then since we are returning bit_width
> > directly for ACPI_ADR_SPACE_PLATFORM_COMM, drop the code correcting
> > the size.
> >
> > Fixes: 2f4a4d63a193 ("ACPI: CPPC: Use access_width over bit_width for system memory accesses")
> > Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> > ---
> >  drivers/acpi/cppc_acpi.c | 11 +++++++----
> >  1 file changed, 7 insertions(+), 4 deletions(-)
> >
> Reviewed-by: Easwar Hariharan <easwar.hariharan@linux.microsoft.com>

Applied as 7.2 material, thanks!

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

end of thread, other threads:[~2026-06-08 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-01 23:58 [PATCH] ACPI: CPPC: Suppress UBSAN warning caused by field misuse Jeremy Linton
2026-06-02 18:32 ` Jarred White
2026-06-05 16:33 ` Easwar Hariharan
2026-06-08 12:25   ` 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