]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: selftests: Add a test for gPAT handling in L2
authorYosry Ahmed <yosry@kernel.org>
Thu, 28 May 2026 23:10:52 +0000 (16:10 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 3 Jun 2026 12:42:35 +0000 (05:42 -0700)
commitadeb462cecae964ae4525512e31d54e545539476
tree77db16eac88daab3507cb1028ad0e0b8ce9e0cea
parentf4805dcf2d2107b83329b56f62204e3a846ff7d2
KVM: selftests: Add a test for gPAT handling in L2

When KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT is disabled, verify that KVM
correctly virtualizes the host PAT MSR and the guest PAT register for
nested SVM guests.

With nested NPT disabled:
 * L1 and L2 share the same PAT
 * The vmcb12.g_pat is ignored

With nested NPT enabled:
 * An invalid g_pat in vmcb12 causes VMEXIT_INVALID
 * RDMSR(IA32_PAT) from L2 returns the value of the guest PAT register
 * WRMSR(IA32_PAT) from L2 is reflected in vmcb12's g_pat on VMEXIT
 * RDMSR(IA32_PAT) from L1 returns the value of the host PAT MSR

Verify that save/restore with the vCPU in guest mode behaves as expected in
both cases, e.g. preserves both hPAT and gPAT when NPT is enabled.

Originally-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
[sean: use even fancier macro shenanigans]
Link: https://patch.msgid.link/20260528231052.404737-1-seanjc@google.com
[sean: avoid use of goto, print skips]
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/Makefile.kvm
tools/testing/selftests/kvm/x86/svm_nested_pat_test.c [new file with mode: 0644]