Add support for yet another page to hang from the VMCS12 for nested VMX testing: the virtual APIC page. This page is necessary for a VMCS12 to be launched with the "use TPR shadow" VM-execution control set (except in some oddball circumstances permitted by KVM). Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx> Reviewed-by: Oliver Upton <oupton@xxxxxxxxxx> --- tools/testing/selftests/kvm/include/x86_64/vmx.h | 5 +++++ tools/testing/selftests/kvm/lib/x86_64/vmx.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testing/selftests/kvm/include/x86_64/vmx.h index 516c81d86353..83ccb096b966 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -574,6 +574,10 @@ struct vmx_pages { void *apic_access_hva; uint64_t apic_access_gpa; void *apic_access; + + void *virtual_apic_hva; + uint64_t virtual_apic_gpa; + void *virtual_apic; }; union vmx_basic { @@ -618,5 +622,6 @@ void prepare_eptp(struct vmx_pages *vmx, struct kvm_vm *vm, uint32_t eptp_memslot); void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm, uint32_t eptp_memslot); +void prepare_tpr_shadow(struct vmx_pages *vmx, struct kvm_vm *vm); #endif /* SELFTEST_KVM_VMX_H */ diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/selftests/kvm/lib/x86_64/vmx.c index 2448b30e8efa..1023760d1bf7 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -551,3 +551,11 @@ void prepare_virtualize_apic_accesses(struct vmx_pages *vmx, struct kvm_vm *vm, vmx->apic_access_hva = addr_gva2hva(vm, (uintptr_t)vmx->apic_access); vmx->apic_access_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->apic_access); } + +void prepare_tpr_shadow(struct vmx_pages *vmx, struct kvm_vm *vm) +{ + vmx->virtual_apic = (void *)vm_vaddr_alloc(vm, getpagesize(), + 0x10000, 0, 0); + vmx->virtual_apic_hva = addr_gva2hva(vm, (uintptr_t)vmx->virtual_apic); + vmx->virtual_apic_gpa = addr_gva2gpa(vm, (uintptr_t)vmx->virtual_apic); +} -- 2.31.1.818.g46aad6cb9e-goog