]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86: Add helper to retrieve current value of user return MSR
authorHou Wenlong <houwenlong.hwl@antgroup.com>
Tue, 23 Sep 2025 15:37:37 +0000 (08:37 -0700)
committerSean Christopherson <seanjc@google.com>
Tue, 23 Sep 2025 15:55:20 +0000 (08:55 -0700)
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.

Cc: stable@vger.kernel.org
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
[sean: drop "cache" from the name, make it a one-liner, tag for stable]
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250923153738.1875174-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c

index 822a5596a4a09b3db46a34e97937d7b03370fb9c..0d6a4af79b781aa3f7c34da4ac097754e5c66655 100644 (file)
@@ -2357,6 +2357,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(unsigned int slot);
 
 static inline bool kvm_is_supported_user_return_msr(u32 msr)
 {
index 1d7faf8bc78554f69a10977ae13d0550c60615e9..5ac2183b9993258bb032de35de71946a1ce69e94 100644 (file)
@@ -677,6 +677,12 @@ 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(unsigned int slot)
+{
+       return this_cpu_ptr(user_return_msrs)->values[slot].curr;
+}
+EXPORT_SYMBOL_GPL(kvm_get_user_return_msr);
+
 static void drop_user_return_notifiers(void)
 {
        struct kvm_user_return_msrs *msrs = this_cpu_ptr(user_return_msrs);