Re: [PATCH v3 05/13] x86/resctrl: Protect against bad shift

From: Reinette Chatre

Date: Wed Apr 08 2026 - 12:44:25 EST




On 4/7/26 9:02 AM, Reinette Chatre wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 7667cf7c4e94..db787c4dee61 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -246,7 +246,9 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
>
> cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx);
> hw_res->num_closid = edx + 1;
> - r->membw.max_bw = 1 << eax;
> + if (WARN_ON(BITS_PER_TYPE(r->membw.max_bw) <= eax))

sashiko [1] reminded me about not using WARN_ON().
I'll switch this to pr_warn().

> + return false;
> + r->membw.max_bw = BIT(eax);
>

Reinette

[1] https://sashiko.dev/#/patchset/cover.1775576382.git.reinette.chatre%40intel.com