Skip to content

Commit 44dd0f5

Browse files
committed
KVM: x86: Suppress userspace access failures on unsupported, "emulated" MSRs
Extend KVM's suppression of userspace MSR access failures to MSRs that KVM reports as emulated, but are ultimately unsupported, e.g. if the VMX MSRs are emulated by KVM, but are unsupported given the vCPU model. Suggested-by: Weijiang Yang <[email protected]> Reviewed-by: Weijiang Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 64a5d7a commit 44dd0f5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

arch/x86/kvm/x86.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static bool kvm_is_immutable_feature_msr(u32 msr)
476476
return false;
477477
}
478478

479-
static bool kvm_is_msr_to_save(u32 msr_index)
479+
static bool kvm_is_advertised_msr(u32 msr_index)
480480
{
481481
unsigned int i;
482482

@@ -485,6 +485,11 @@ static bool kvm_is_msr_to_save(u32 msr_index)
485485
return true;
486486
}
487487

488+
for (i = 0; i < num_emulated_msrs; i++) {
489+
if (emulated_msrs[i] == msr_index)
490+
return true;
491+
}
492+
488493
return false;
489494
}
490495

@@ -514,11 +519,11 @@ static __always_inline int kvm_do_msr_access(struct kvm_vcpu *vcpu, u32 msr,
514519

515520
/*
516521
* Userspace is allowed to read MSRs, and write '0' to MSRs, that KVM
517-
* reports as to-be-saved, even if an MSR isn't fully supported.
522+
* advertises to userspace, even if an MSR isn't fully supported.
518523
* Simply check that @data is '0', which covers both the write '0' case
519524
* and all reads (in which case @data is zeroed on failure; see above).
520525
*/
521-
if (host_initiated && !*data && kvm_is_msr_to_save(msr))
526+
if (host_initiated && !*data && kvm_is_advertised_msr(msr))
522527
return 0;
523528

524529
if (!ignore_msrs) {

0 commit comments

Comments
 (0)