Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Eric Biggers <ebiggers@kernel.org>
Cc: x86@kernel.org, linux-um@lists.infradead.org,
	linux-raid@vger.kernel.org, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v2 1/8] x86/fpu: Check for missing AVX and AVX-512 xstate bits
Date: Wed, 12 Aug 2026 10:48:26 -0700	[thread overview]
Message-ID: <20260812174826.GAanyx6vUWv5GLX2AZ@fat_crate.local> (raw)
In-Reply-To: <20260728234726.GCamk_jnl3LtfGbxoC@fat_crate.local>

On Tue, Jul 28, 2026 at 04:47:26PM -0700, Borislav Petkov wrote:
> On Tue, Jul 28, 2026 at 04:34:30PM -0700, Eric Biggers wrote:
> > I don't know what your suggestion is.  Are you still asking for the
> > function to be renamed to clear_cpu_caps_xft()?  Note that the
> > abbreviation "xft" doesn't appear anywhere else in arch/x86/.  Maybe you
> > want the argument inverted?  I don't know what you want, sorry.
> 
> That's fine - I'll take a look at the final version after having gone through
> the whole pile and then holler if I still see a need.

Ok, here's something ontop of yours. It is tested only in a guest but it
should show the intention.

The first call in:

	if (!boot_cpu_has(X86_FEATURE_FPU)) {

is not needed because that is caught earlier:

[    0.553199] x86/fpu: Giving up, no FPU found and no math emulation present

and we stop there.

The second one can then simply do:

                /* Disable all dependent flags too */
                setup_clear_cpu_cap(X86_FEATURE_XSAVE);

because that'll clear all dependent flags and we should be good there:

[    0.560698] do_clear_cpu_cap: clearing 10:0 (xsaveopt)
[    0.561697] do_clear_cpu_cap: clearing 10:1 (xsavec)
[    0.562697] do_clear_cpu_cap: clearing 10:3 (xsaves)
[    0.563697] do_clear_cpu_cap: clearing 4:28 (avx)
[    0.564697] do_clear_cpu_cap: clearing 16:3 (pku)
[    0.565697] do_clear_cpu_cap: clearing 9:14 (mpx)
[    0.566697] do_clear_cpu_cap: clearing 10:2 (xgetbv1)
[    0.567697] do_clear_cpu_cap: clearing 21:9 ((null))
[    0.568698] do_clear_cpu_cap: clearing 12:4 (avx_vnni)
[    0.569697] do_clear_cpu_cap: clearing 4:12 (fma)
[    0.570697] do_clear_cpu_cap: clearing 16:9 (vaes)
[    0.571697] do_clear_cpu_cap: clearing 16:10 (vpclmulqdq)
[    0.572697] do_clear_cpu_cap: clearing 9:5 (avx2)
[    0.573697] do_clear_cpu_cap: clearing 9:16 (avx512f)
[    0.574697] do_clear_cpu_cap: clearing 9:21 (avx512ifma)
[    0.575698] do_clear_cpu_cap: clearing 9:26 (avx512pf)
[    0.576697] do_clear_cpu_cap: clearing 9:27 (avx512er)
[    0.577697] do_clear_cpu_cap: clearing 9:28 (avx512cd)
[    0.578697] do_clear_cpu_cap: clearing 9:17 (avx512dq)
[    0.579697] do_clear_cpu_cap: clearing 9:30 (avx512bw)
[    0.580697] do_clear_cpu_cap: clearing 9:31 (avx512vl)
[    0.581697] do_clear_cpu_cap: clearing 16:1 (avx512vbmi)
[    0.582697] do_clear_cpu_cap: clearing 16:6 (avx512_vbmi2)
[    0.583697] do_clear_cpu_cap: clearing 16:11 (avx512_vnni)
[    0.584697] do_clear_cpu_cap: clearing 16:12 (avx512_bitalg)
[    0.585697] do_clear_cpu_cap: clearing 18:2 (avx512_4vnniw)
[    0.586697] do_clear_cpu_cap: clearing 18:3 (avx512_4fmaps)
[    0.587697] do_clear_cpu_cap: clearing 16:14 (avx512_vpopcntdq)
[    0.588698] do_clear_cpu_cap: clearing 18:8 (avx512_vp2intersect)
[    0.589698] do_clear_cpu_cap: clearing 12:5 (avx512_bf16)
[    0.590697] do_clear_cpu_cap: clearing 18:23 (avx512_fp16)
[    0.592697] do_clear_cpu_cap: clearing 16:29 (enqcmd)
[    0.593697] do_clear_cpu_cap: clearing 10:4 ((null))
[    0.594697] do_clear_cpu_cap: clearing 18:24 (amx_tile)
[    0.595697] do_clear_cpu_cap: clearing 12:21 ((null))
[    0.596697] do_clear_cpu_cap: clearing 18:22 (amx_bf16)
[    0.597697] do_clear_cpu_cap: clearing 18:25 (amx_int8)
[    0.598697] do_clear_cpu_cap: clearing 16:7 ((null))

and then the rest is streamlined into fpu__init_system_xstate() where all
sanity checking should be performed, as I mentioned intially.

Full diff ontop:

diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index 99801e844b30..96c43ec164f7 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -142,6 +142,8 @@ static void do_clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int feature)
 				continue;
 
 			changed = true;
+			pr_info("%s: clearing %d:%d (%s)\n",
+				__func__, d->feature >> 5, d->feature & 31, x86_cap_flags[d->feature]);
 			clear_feature(c, d->feature);
 		}
 	} while (changed);
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 3c185b2828c7..406ae0841b5f 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -761,23 +761,6 @@ 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");
-		setup_clear_cpu_cap(X86_FEATURE_AVX);
-	}
-	mask = XFEATURE_MASK_FPSSE | XFEATURE_MASK_YMM | XFEATURE_MASK_AVX512;
-	if (boot_cpu_has(X86_FEATURE_AVX512F) && (xfeatures & mask) != mask) {
-		pr_err("x86/fpu: Disabling AVX-512 support due to missing xstate features\n");
-		setup_clear_cpu_cap(X86_FEATURE_AVX512F);
-	}
-}
-
 /*
  * Enable and initialize the xsave feature.
  * Called once per system bootup.
@@ -785,20 +768,20 @@ static void __init clear_cpu_caps_with_missing_xfeatures(u64 xfeatures)
 void __init fpu__init_system_xstate(unsigned int legacy_size)
 {
 	unsigned int eax, ebx, ecx, edx;
-	u64 xfeatures;
+	u64 xfeatures, mask;
 	int err;
 	int i;
 
 	if (!boot_cpu_has(X86_FEATURE_FPU)) {
 		pr_info("x86/fpu: No FPU detected\n");
-		clear_cpu_caps_with_missing_xfeatures(0);
 		return;
 	}
 
 	if (!boot_cpu_has(X86_FEATURE_XSAVE)) {
 		pr_info("x86/fpu: x87 FPU will use %s\n",
 			boot_cpu_has(X86_FEATURE_FXSR) ? "FXSAVE" : "FSAVE");
-		clear_cpu_caps_with_missing_xfeatures(0);
+		/* Disable all dependent flags too */
+		setup_clear_cpu_cap(X86_FEATURE_XSAVE);
 		return;
 	}
 
@@ -814,7 +797,8 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
 	cpuid_count(CPUID_LEAF_XSTATE, 1, &eax, &ebx, &ecx, &edx);
 	fpu_kernel_cfg.max_features |= ecx + ((u64)edx << 32);
 
-	if ((fpu_kernel_cfg.max_features & XFEATURE_MASK_FPSSE) != XFEATURE_MASK_FPSSE) {
+	mask = XFEATURE_MASK_FPSSE;
+	if ((fpu_kernel_cfg.max_features & mask) != mask) {
 		/*
 		 * This indicates that something really unexpected happened
 		 * with the enumeration.  Disable XSAVE and try to continue
@@ -825,6 +809,22 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
 		goto out_disable;
 	}
 
+	mask |= XFEATURE_MASK_YMM;
+	if (boot_cpu_has(X86_FEATURE_AVX)) {
+		if ((fpu_kernel_cfg.max_features & mask) != mask) {
+			pr_err("x86/fpu: Disabling AVX support due to missing xstate features\n");
+			setup_clear_cpu_cap(X86_FEATURE_AVX);
+		}
+	}
+
+	mask |= XFEATURE_MASK_AVX512;
+	if (boot_cpu_has(X86_FEATURE_AVX512F)) {
+		if ((fpu_kernel_cfg.max_features & mask) != mask) {
+			pr_err("x86/fpu: Disabling AVX-512 support due to missing xstate features\n");
+			setup_clear_cpu_cap(X86_FEATURE_AVX512F);
+		}
+	}
+
 	if (fpu_kernel_cfg.max_features & XFEATURE_MASK_APX &&
 	    fpu_kernel_cfg.max_features & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) {
 		/*
@@ -836,8 +836,6 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
 		goto out_disable;
 	}
 
-	clear_cpu_caps_with_missing_xfeatures(fpu_kernel_cfg.max_features);
-
 	fpu_kernel_cfg.independent_features = fpu_kernel_cfg.max_features &
 					      XFEATURE_MASK_INDEPENDENT;
 

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2026-08-12 17:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  2:15 [PATCH v2 0/8] x86: Remove cpu_has_xfeatures() and add AVX-512 xor_gen() Eric Biggers
2026-07-28  2:15 ` [PATCH v2 1/8] x86/fpu: Check for missing AVX and AVX-512 xstate bits Eric Biggers
2026-07-28  5:27   ` Borislav Petkov
2026-07-28  5:45     ` Eric Biggers
2026-07-28 18:20       ` Borislav Petkov
2026-07-28 18:34         ` Eric Biggers
2026-07-28 22:59           ` Borislav Petkov
2026-07-28 23:34             ` Eric Biggers
2026-07-28 23:47               ` Borislav Petkov
2026-08-12 17:48                 ` Borislav Petkov [this message]
2026-08-12 19:40                   ` Eric Biggers
2026-08-12 20:04                     ` Borislav Petkov
2026-07-28  9:23     ` David Laight
2026-07-28 22:35   ` Thomas Gleixner
2026-07-28  2:15 ` [PATCH v2 2/8] um: " Eric Biggers
2026-07-30 23:06   ` Borislav Petkov
2026-07-28  2:15 ` [PATCH v2 3/8] crypto: x86 - Stop using cpu_has_xfeatures() Eric Biggers
2026-07-28  9:30   ` David Laight
2026-07-28 23:40     ` Eric Biggers
2026-07-28  2:15 ` [PATCH v2 4/8] lib/crypto: x86: " Eric Biggers
2026-07-30 23:19   ` Borislav Petkov
2026-07-30 23:47     ` Eric Biggers
2026-07-31  4:26       ` Borislav Petkov
2026-07-28  2:16 ` [PATCH v2 5/8] lib/crc: " Eric Biggers
2026-07-28  2:16 ` [PATCH v2 6/8] x86/fpu: Remove cpu_has_xfeatures() Eric Biggers
2026-07-28  2:16 ` [PATCH v2 7/8] lib/raid/xor: x86: Remove redundant X86_FEATURE_OSXSAVE check Eric Biggers
2026-07-28  3:41   ` Christoph Hellwig
2026-07-28  2:16 ` [PATCH v2 8/8] lib/raid/xor: x86: Add AVX-512 optimized xor_gen() Eric Biggers
2026-07-28  3:44   ` Christoph Hellwig
2026-07-28  3:44 ` [PATCH v2 0/8] x86: Remove cpu_has_xfeatures() and add AVX-512 xor_gen() Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260812174826.GAanyx6vUWv5GLX2AZ@fat_crate.local \
    --to=bp@alien8.de \
    --cc=akpm@linux-foundation.org \
    --cc=ebiggers@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox