[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <qvnda66iujv53bhjnhdtnkb2w6aq5fh4shmqmrxq7aaqjmdcx4@yav323c4bcns>
Date: Tue, 22 Jul 2025 17:31:04 +0200
From: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
To: Xin Li <xin@...or.com>
CC: Gleixner Thomas <tglx@...utronix.de>, Molnar Ingo <mingo@...hat.com>,
Petkov Borislav <bp@...en8.de>, Hansen Dave <dave.hansen@...ux.intel.com>,
<x86@...nel.org>, "Anvin H. Peter" <hpa@...or.com>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] x86: Clear LAM and FRED feature bits
On 2025-07-22 at 02:08:28 -0700, Xin Li wrote:
>
>> On Jul 22, 2025, at 12:54 AM, Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com> wrote:
>>
>> If LAM (CONFIG_ADDRESS_MASKING) or FRED (CONFIG_X86_FRED) are disabled
>> during compile time, they still are enumerated in macros such as
>> cpu_has() or this_cpu_has() that use the x86_capability bitmask. The
>> features are also visible in /proc/cpuinfo even though they are not
>> enabled - which is contrary to what the documentation states about the
>> file.
>
>I'm curious how this bug is introduced with my patch set that adds the
>AWK script which automatically generates the CPU feature mask header.
While your patch works great in setting up the DISABLED_MASKs, there is no place
that would read that mask and clear x86_capability bitmask. Most other features
seem to have a call to setup_clear_cpu_cap() somewhere, or they're in the
required bitmask. LAM doesn't have one at all, and FRED only has a kernel
command line check - so no compile-time support is checked anywhere.
>
>>
>> The documentation for x86/cpuinfo.rst also states how to handle features
>> disabled at compile time:
>>
>> The kernel disabled support for it at compile-time
>> --------------------------------------------------
>>
>> For example, if Linear Address Masking (LAM) is not enabled when
>> building (i.e., CONFIG_ADDRESS_MASKING is not selected) the flag
>> "lam" will not show up. Even though the feature will still be
>> detected via CPUID, the kernel disables it by clearing via
>> setup_clear_cpu_cap(X86_FEATURE_LAM).
>>
>> Clear feature bits if they are present in the DISABLED_MASK.
>>
>> Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
>
>And we need a Fixes tag and CC stable.
Ah, thank you for reminding me :)
>
>> ---
>> arch/x86/kernel/cpu/common.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
>> index 77afca95cced..1c5af795cedc 100644
>> --- a/arch/x86/kernel/cpu/common.c
>> +++ b/arch/x86/kernel/cpu/common.c
>> @@ -1782,6 +1782,16 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)
>> if (!pgtable_l5_enabled())
>> setup_clear_cpu_cap(X86_FEATURE_LA57);
>>
>> + /*
>> + * If a feature is disabled during compile time clear its feature
>> + * bit to prevent it from showing up in the x86_capability bitmask.
>> + */
>> + if (!cpu_feature_enabled(X86_FEATURE_LAM))
>> + setup_clear_cpu_cap(X86_FEATURE_LAM);
>> +
>> + if (!cpu_feature_enabled(X86_FEATURE_FRED))
>> + setup_clear_cpu_cap(X86_FEATURE_FRED);
>> +
>
>The following code will work as a generic fix:
>
> c->x86_capability[i] &= ~DISABLED_MASK(i);
>
>And DISABLED_MASK(x) needs to be defined like DISABLED_MASK_BIT_SET(x).
Thanks, I'll add a helper for that and put the call in the same place this patch
changes are. Seems like a good place with a lot of other setup_clear_cpu_cap()
calls.
>
>Thanks!
> Xin
--
Kind regards
Maciej Wieczór-Retman
Powered by blists - more mailing lists