public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: x86: Add helper to retrieve cached value of user return MSR
@ 2025-09-18  3:38 Hou Wenlong
  2025-09-18  3:38 ` [PATCH 2/2] KVM: SVM: Use cached value as restore value of TSC_AUX for SEV-ES guest Hou Wenlong
  2025-09-19 16:28 ` [PATCH 1/2] KVM: x86: Add helper to retrieve cached value of user return MSR Sean Christopherson
  0 siblings, 2 replies; 9+ messages in thread
From: Hou Wenlong @ 2025-09-18  3:38 UTC (permalink / raw)
  To: kvm
  Cc: Lai Jiangshan, Sean Christopherson, Paolo Bonzini,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, linux-kernel

In the user return MSR support, the cached value is always the hardware
value of the specific MSR. Therefore, add a helper to retrieve the
cached value, which can replace the need for RDMSR, for example, to
allow SEV-ES guests to restore the correct host hardware value without
using RDMSR.

Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
---
 arch/x86/include/asm/kvm_host.h | 1 +
 arch/x86/kvm/x86.c              | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index cb86f3cca3e9..2cbb0f446a9b 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2376,6 +2376,7 @@ int kvm_add_user_return_msr(u32 msr);
 int kvm_find_user_return_msr(u32 msr);
 int kvm_set_user_return_msr(unsigned index, u64 val, u64 mask);
 void kvm_user_return_msr_update_cache(unsigned int index, u64 val);
+u64 kvm_get_user_return_msr_cache(unsigned int index);
 
 static inline bool kvm_is_supported_user_return_msr(u32 msr)
 {
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6d85fbafc679..88d26c86c3b2 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -675,6 +675,14 @@ void kvm_user_return_msr_update_cache(unsigned int slot, u64 value)
 }
 EXPORT_SYMBOL_GPL(kvm_user_return_msr_update_cache);
 
+u64 kvm_get_user_return_msr_cache(unsigned int slot)
+{
+	struct kvm_user_return_msrs *msrs = this_cpu_ptr(user_return_msrs);
+
+	return msrs->values[slot].curr;
+}
+EXPORT_SYMBOL_GPL(kvm_get_user_return_msr_cache);
+
 static void drop_user_return_notifiers(void)
 {
 	struct kvm_user_return_msrs *msrs = this_cpu_ptr(user_return_msrs);

base-commit: 603c090664d350b7fdaffbe8e6a6e43829938458
-- 
2.31.1


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

end of thread, other threads:[~2025-09-20  6:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18  3:38 [PATCH 1/2] KVM: x86: Add helper to retrieve cached value of user return MSR Hou Wenlong
2025-09-18  3:38 ` [PATCH 2/2] KVM: SVM: Use cached value as restore value of TSC_AUX for SEV-ES guest Hou Wenlong
2025-09-18 18:47   ` Tom Lendacky
2025-09-19 13:15     ` Hou Wenlong
2025-09-19 16:23       ` Sean Christopherson
2025-09-19 16:30         ` Sean Christopherson
2025-09-19 16:45           ` Sean Christopherson
2025-09-20  6:52         ` Hou Wenlong
2025-09-19 16:28 ` [PATCH 1/2] KVM: x86: Add helper to retrieve cached value of user return MSR Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox