]> git.ipfire.org Git - thirdparty/linux.git/commit
KVM: selftests: Add a selftests for nested VMLOAD/VMSAVE
authorYosry Ahmed <yosry.ahmed@linux.dev>
Sat, 10 Jan 2026 00:48:20 +0000 (00:48 +0000)
committerSean Christopherson <seanjc@google.com>
Wed, 14 Jan 2026 22:09:10 +0000 (14:09 -0800)
commit55058e32151f95dc5badd62381d184e89f15de99
treef7ac26f980150e5e4e6f389030f173a13fe32ff3
parentf756ed82c62aa2725757ac011710492d4cc8c7d8
KVM: selftests: Add a selftests for nested VMLOAD/VMSAVE

Add a test for VMLOAD/VMSAVE in an L2 guest. The test verifies that L1
intercepts for VMSAVE/VMLOAD always work regardless of
VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK.

Then, more interestingly, it makes sure that when L1 does not intercept
VMLOAD/VMSAVE, they work as intended in L2. When
VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK is enabled by L1, VMSAVE/VMLOAD from
L2 should interpret the GPA as an L2 GPA and translate it through the
NPT. When VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK is disabled by L1,
VMSAVE/VMLOAD from L2 should interpret the GPA as an L1 GPA.

To test this, put two VMCBs (0 and 1) in L1's physical address space,
and have a single L2 GPA where:
- L2 VMCB GPA == L1 VMCB(0) GPA
- L2 VMCB GPA maps to L1 VMCB(1) via the NPT in L1.

This setup allows detecting how the GPA is interpreted based on which L1
VMCB is actually accessed.

In both cases, L2 sets KERNEL_GS_BASE (one of the fields handled by
VMSAVE/VMLOAD), and executes VMSAVE to write its value to the VMCB. The
test userspace code then checks that the write was made to the correct
VMCB (based on whether VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK is set by L1),
and writes a new value to that VMCB. L2 then executes VMLOAD to load the
new value and makes sure it's reflected correctly in KERNERL_GS_BASE.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Link: https://patch.msgid.link/20260110004821.3411245-4-yosry.ahmed@linux.dev
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/Makefile.kvm
tools/testing/selftests/kvm/include/x86/processor.h
tools/testing/selftests/kvm/x86/nested_vmsave_vmload_test.c [new file with mode: 0644]