Re: [PATCH v2 1/8] x86/fpu: Check for missing AVX and AVX-512 xstate bits
Thomas Gleixner <[email protected]> Wed, 29 Jul 2026 00:35:22 +0200
| Newsgroups | org.infradead.lists.linux-um,org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel,org.kernel.vger.linux-raid |
|---|---|
| Message-ID | <87fr12hhed.ffs@fw13> |
On Mon, Jul 27 2026 at 19:15, Eric Biggers wrote: > If the CPU declares AVX or AVX-512 support, verify that the > corresponding xstate bits are also set. If not, warn and clear them. That's clearly a firmware bug which has to be treated as all other inconsistencies of that sort. > This eliminates the perceived need for AVX and AVX-512 optimized code in > the kernel to call cpu_has_xfeatures(). That has never been universally > done, which strongly suggests that it has never really been needed in > practice, but this should remove any remaining doubt. Indeed it is inconsistent all over the place. While looking at the follow up patches I wondered how many of these remaining nested conditions are redundant. Most of them should be covered by the dependency checks. If they are not, then we should add them. > Signed-off-by: Eric Biggers <[email protected]> > --- > arch/x86/kernel/fpu/xstate.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c > index a7b6524a9dea2..904ff933c0d88 100644 > --- a/arch/x86/kernel/fpu/xstate.c > +++ b/arch/x86/kernel/fpu/xstate.c > @@ -799,6 +799,23 @@ static u64 __init guest_default_mask(void) > return ~(u64)XFEATURE_MASK_USER_DYNAMIC; > } > > +/* Clear any X86_FEATURE_* used by the kernel whose xfeatures are missing. */ > +static void __init clear_cpu_caps_with_missing_xfeatures(u64 xfeatures) > +{ > + u64 mask; > + > + mask = XFEATURE_MASK_FPSSE | XFEATURE_MASK_YMM; > + if (boot_cpu_has(X86_FEATURE_AVX) && (xfeatures & mask) != mask) { > + pr_err("x86/fpu: Disabling AVX support due to missing xstate features\n"); Please make these pr_err(FW_BUG "...") As that's what it is. Thanks, tglx