Skip to content

Commit 9bc3663

Browse files
bysuisean-jc
authored andcommitted
KVM: x86: Add helper to retrieve current value of user return MSR
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>
1 parent 5b66e33 commit 9bc3663

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,7 @@ int kvm_add_user_return_msr(u32 msr);
23572357
int kvm_find_user_return_msr(u32 msr);
23582358
int kvm_set_user_return_msr(unsigned index, u64 val, u64 mask);
23592359
void kvm_user_return_msr_update_cache(unsigned int index, u64 val);
2360+
u64 kvm_get_user_return_msr(unsigned int slot);
23602361

23612362
static inline bool kvm_is_supported_user_return_msr(u32 msr)
23622363
{

arch/x86/kvm/x86.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,12 @@ void kvm_user_return_msr_update_cache(unsigned int slot, u64 value)
677677
}
678678
EXPORT_SYMBOL_GPL(kvm_user_return_msr_update_cache);
679679

680+
u64 kvm_get_user_return_msr(unsigned int slot)
681+
{
682+
return this_cpu_ptr(user_return_msrs)->values[slot].curr;
683+
}
684+
EXPORT_SYMBOL_GPL(kvm_get_user_return_msr);
685+
680686
static void drop_user_return_notifiers(void)
681687
{
682688
struct kvm_user_return_msrs *msrs = this_cpu_ptr(user_return_msrs);

0 commit comments

Comments
 (0)