]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/fpu/apx: Disallow conflicting MPX presence
authorChang S. Bae <chang.seok.bae@intel.com>
Wed, 16 Apr 2025 02:16:53 +0000 (19:16 -0700)
committerIngo Molnar <mingo@kernel.org>
Wed, 16 Apr 2025 07:44:14 +0000 (09:44 +0200)
XSTATE components are architecturally independent. There is no rule
requiring their offsets in the non-compacted format to be strictly
ascending or mutually non-overlapping. However, in practice, such
overlaps have not occurred -- until now.

APX is introduced as xstate component 19, following AMX. In the
non-compacted XSAVE format, its offset overlaps with the space previously
occupied by the now-deprecated MPX feature:

    45fc24e89b7c ("x86/mpx: remove MPX from arch/x86")

To prevent conflicts, the kernel must ensure the CPU never expose both
features at the same time. If so, it indicates unreliable hardware. In
such cases, XSAVE should be disabled entirely as a precautionary measure.

Add a sanity check to detect this condition and disable XSAVE if an
invalid hardware configuration is identified.

Note: MPX state components remain enabled on legacy systems solely for
KVM guest support.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20250416021720.12305-4-chang.seok.bae@intel.com
arch/x86/kernel/fpu/xstate.c

index dfd07af1003742fa0aaee5308be94a96daf229df..14f5c1bb208003f86cacc8bdf859009067c5d607 100644 (file)
@@ -814,6 +814,17 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
                goto out_disable;
        }
 
+       if (fpu_kernel_cfg.max_features & XFEATURE_MASK_APX &&
+           fpu_kernel_cfg.max_features & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) {
+               /*
+                * This is a problematic CPU configuration where two
+                * conflicting state components are both enumerated.
+                */
+               pr_err("x86/fpu: Both APX/MPX present in the CPU's xstate features: 0x%llx, disabling XSAVE.\n",
+                      fpu_kernel_cfg.max_features);
+               goto out_disable;
+       }
+
        fpu_kernel_cfg.independent_features = fpu_kernel_cfg.max_features &
                                              XFEATURE_MASK_INDEPENDENT;