Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/fpu: Add fpu_state_config::legacy_features

The upcoming prctl() which is required to request the permission for a
dynamically enabled feature will also provide an option to retrieve the
supported features. If the CPU does not support XSAVE, the supported
features would be 0 even when the CPU supports FP and SSE.

Provide separate storage for the legacy feature set to avoid that and fill
in the bits in the legacy init function.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211021225527.10184-6-chang.seok.bae@intel.com

authored by

Thomas Gleixner and committed by
Borislav Petkov
c33f0a81 6f6a7c09

+13 -3
+7
arch/x86/include/asm/fpu/types.h
··· 503 503 * be requested by user space before usage. 504 504 */ 505 505 u64 default_features; 506 + /* 507 + * @legacy_features: 508 + * 509 + * Features which can be reported back to user space 510 + * even without XSAVE support, i.e. legacy features FP + SSE 511 + */ 512 + u64 legacy_features; 506 513 }; 507 514 508 515 /* FPU state configuration information */
+6 -3
arch/x86/kernel/fpu/init.c
··· 193 193 * Note that the size configuration might be overwritten later 194 194 * during fpu__init_system_xstate(). 195 195 */ 196 - if (!cpu_feature_enabled(X86_FEATURE_FPU)) 196 + if (!cpu_feature_enabled(X86_FEATURE_FPU)) { 197 197 size = sizeof(struct swregs_state); 198 - else if (cpu_feature_enabled(X86_FEATURE_FXSR)) 198 + } else if (cpu_feature_enabled(X86_FEATURE_FXSR)) { 199 199 size = sizeof(struct fxregs_state); 200 - else 200 + fpu_user_cfg.legacy_features = XFEATURE_MASK_FPSSE; 201 + } else { 201 202 size = sizeof(struct fregs_state); 203 + fpu_user_cfg.legacy_features = XFEATURE_MASK_FP; 204 + } 202 205 203 206 fpu_kernel_cfg.max_size = size; 204 207 fpu_kernel_cfg.default_size = size;