Re: [PATCH v5 02/10] x86/resctrl: Protect against bad shift
From: Borislav Petkov
Date: Mon Jul 20 2026 - 22:01:34 EST
On Tue, Jun 30, 2026 at 09:27:02PM -0700, Reinette Chatre wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index bca782050198..9b9495174041 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -247,7 +247,11 @@ 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 (BITS_PER_TYPE(r->membw.max_bw) <= eax) {
> + pr_warn("Unable to support hardware's maximum bandwidth\n");
> + return false;
> + }
> + r->membw.max_bw = BIT(eax);
Why?
Why go all the effort if the field can be 64 bits?
Why not make max_bw u64 and handle *all* possible values naturally?
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette