kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/fpu/xstate: clear XSAVE features if DISABLED_MASK set
@ 2023-05-30 20:01 Jon Kohler
  2023-05-30 22:22 ` Dave Hansen
  0 siblings, 1 reply; 8+ messages in thread
From: Jon Kohler @ 2023-05-30 20:01 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Chang S. Bae, Kyle Huey, neelnatu, Andrew Cooper,
	Jon Kohler, linux-kernel
  Cc: kvm, Sean Christopherson, Paolo Bonzini

Respect DISABLED_MASK when clearing XSAVE features, such that features
that are disabled do not appear in the xfeatures mask.

This is important for kvm_load_{guest|host}_xsave_state, which look
at host_xcr0 and will do an expensive xsetbv when the guest and host
do not match.

A prime example if CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS is disabled,
the guest OS will not see PKU masked; however, the guest will incur
xsetbv since the host mask will never match the guest, even though
DISABLED_MASK16 has DISABLE_PKU set.

Signed-off-by: Jon Kohler <jon@nutanix.com>
CC: kvm@vger.kernel.org
CC: Sean Christopherson <seanjc@google.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kernel/fpu/xstate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index 0bab497c9436..211ef82b53e3 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -798,7 +798,8 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
 		unsigned short cid = xsave_cpuid_features[i];

 		/* Careful: X86_FEATURE_FPU is 0! */
-		if ((i != XFEATURE_FP && !cid) || !boot_cpu_has(cid))
+		if ((i != XFEATURE_FP && !cid) || !boot_cpu_has(cid) ||
+		    DISABLED_MASK_BIT_SET(cid))
 			fpu_kernel_cfg.max_features &= ~BIT_ULL(i);
 	}

--
2.30.1 (Apple Git-130)


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-06-06 23:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-30 20:01 [PATCH] x86/fpu/xstate: clear XSAVE features if DISABLED_MASK set Jon Kohler
2023-05-30 22:22 ` Dave Hansen
2023-05-31  3:04   ` Jon Kohler
2023-05-31 16:30     ` Sean Christopherson
     [not found]       ` <E17EFDD7-C54A-4532-B1D3-D567557FC54B@nutanix.com>
     [not found]         ` <ZHermsSGQBcDD07R@google.com>
2023-05-31 21:29           ` Borislav Petkov
2023-05-31 22:02             ` Sean Christopherson
     [not found]           ` <CBFC095A-10D1-4925-9F28-DEDEBBB38EF8@nutanix.com>
2023-06-05 13:23             ` Jon Kohler
2023-06-06 23:40               ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).