Skip to content

Commit 6909081

Browse files
committed
KVM: nVMX: allow tests to use bad virtual-APIC page address
As mentioned in the comment, there are some special cases where we can simply clear the TPR shadow bit from the CPU-based execution controls in the vmcs02. Handle them so that we can remove some XFAILs from vmx.flat. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent cfd32ac commit 6909081

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎arch/x86/kvm/vmx/nested.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,20 +2873,27 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu)
28732873
/*
28742874
* If translation failed, VM entry will fail because
28752875
* prepare_vmcs02 set VIRTUAL_APIC_PAGE_ADDR to -1ull.
2876-
* Failing the vm entry is _not_ what the processor
2877-
* does but it's basically the only possibility we
2878-
* have. We could still enter the guest if CR8 load
2879-
* exits are enabled, CR8 store exits are enabled, and
2880-
* virtualize APIC access is disabled; in this case
2881-
* the processor would never use the TPR shadow and we
2882-
* could simply clear the bit from the execution
2883-
* control. But such a configuration is useless, so
2884-
* let's keep the code simple.
28852876
*/
28862877
if (!is_error_page(page)) {
28872878
vmx->nested.virtual_apic_page = page;
28882879
hpa = page_to_phys(vmx->nested.virtual_apic_page);
28892880
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, hpa);
2881+
} else if (nested_cpu_has(vmcs12, CPU_BASED_CR8_LOAD_EXITING) &&
2882+
nested_cpu_has(vmcs12, CPU_BASED_CR8_STORE_EXITING) &&
2883+
!nested_cpu_has2(vmcs12, SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) {
2884+
/*
2885+
* The processor will never use the TPR shadow, simply
2886+
* clear the bit from the execution control. Such a
2887+
* configuration is useless, but it happens in tests.
2888+
* For any other configuration, failing the vm entry is
2889+
* _not_ what the processor does but it's basically the
2890+
* only possibility we have.
2891+
*/
2892+
vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL,
2893+
CPU_BASED_TPR_SHADOW);
2894+
} else {
2895+
printk("bad virtual-APIC page address\n");
2896+
dump_vmcs();
28902897
}
28912898
}
28922899

‎arch/x86/kvm/vmx/vmx.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5603,7 +5603,7 @@ static void vmx_dump_dtsel(char *name, uint32_t limit)
56035603
vmcs_readl(limit + GUEST_GDTR_BASE - GUEST_GDTR_LIMIT));
56045604
}
56055605

5606-
static void dump_vmcs(void)
5606+
void dump_vmcs(void)
56075607
{
56085608
u32 vmentry_ctl = vmcs_read32(VM_ENTRY_CONTROLS);
56095609
u32 vmexit_ctl = vmcs_read32(VM_EXIT_CONTROLS);

‎arch/x86/kvm/vmx/vmx.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,4 +517,6 @@ static inline void decache_tsc_multiplier(struct vcpu_vmx *vmx)
517517
vmcs_write64(TSC_MULTIPLIER, vmx->current_tsc_ratio);
518518
}
519519

520+
void dump_vmcs(void);
521+
520522
#endif /* __KVM_X86_VMX_H */

0 commit comments

Comments
 (0)