Skip to content

Commit 0792c71

Browse files
committed
KVM: selftests: Verify KVM disable interception (for userspace) on filter change
Re-read MSR_{FS,GS}_BASE after restoring the "allow everything" userspace MSR filter to verify that KVM stops forwarding exits to userspace. This can also be used in conjunction with manual verification (e.g. printk) to ensure KVM is correctly updating the MSR bitmaps consumed by hardware. Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Tested-by: Manali Shukla <Manali.Shukla@amd.com> Link: https://lore.kernel.org/r/20250610225737.156318-33-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent bea44d1 commit 0792c71

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tools/testing/selftests/kvm/x86/userspace_msr_exit_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ static void guest_code_permission_bitmap(void)
343343
data = test_rdmsr(MSR_GS_BASE);
344344
GUEST_ASSERT(data == MSR_GS_BASE);
345345

346+
/* Access the MSRs again to ensure KVM has disabled interception.*/
347+
data = test_rdmsr(MSR_FS_BASE);
348+
GUEST_ASSERT(data != MSR_FS_BASE);
349+
data = test_rdmsr(MSR_GS_BASE);
350+
GUEST_ASSERT(data != MSR_GS_BASE);
351+
346352
GUEST_DONE();
347353
}
348354

@@ -682,6 +688,8 @@ KVM_ONE_VCPU_TEST(user_msr, msr_permission_bitmap, guest_code_permission_bitmap)
682688
"Expected ucall state to be UCALL_SYNC.");
683689
vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_gs);
684690
run_guest_then_process_rdmsr(vcpu, MSR_GS_BASE);
691+
692+
vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_allow);
685693
run_guest_then_process_ucall_done(vcpu);
686694
}
687695

0 commit comments

Comments
 (0)