Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+8
+8
tools/testing/selftests/kvm/x86/userspace_msr_exit_test.c
··· 343 343 data = test_rdmsr(MSR_GS_BASE); 344 344 GUEST_ASSERT(data == MSR_GS_BASE); 345 345 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 + 346 352 GUEST_DONE(); 347 353 } 348 354 ··· 688 682 "Expected ucall state to be UCALL_SYNC."); 689 683 vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_gs); 690 684 run_guest_then_process_rdmsr(vcpu, MSR_GS_BASE); 685 + 686 + vm_ioctl(vm, KVM_X86_SET_MSR_FILTER, &filter_allow); 691 687 run_guest_then_process_ucall_done(vcpu); 692 688 } 693 689