]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: nVMX: Update vmcs01 TPR_THRESHOLD if L2 changed L1 TPR
authorLiran Alon <liran.alon@oracle.com>
Mon, 11 Nov 2019 12:30:55 +0000 (14:30 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 15 Nov 2019 10:44:05 +0000 (11:44 +0100)
When L1 don't use TPR-Shadow to run L2, L0 configures vmcs02 without
TPR-Shadow and install intercepts on CR8 access (load and store).

If L1 do not intercept L2 CR8 access, L0 intercepts on those accesses
will emulate load/store on L1's LAPIC TPR. If in this case L2 lowers
TPR such that there is now an injectable interrupt to L1,
apic_update_ppr() will request a KVM_REQ_EVENT which will trigger a call
to update_cr8_intercept() to update TPR-Threshold to highest pending IRR
priority.

However, this update to TPR-Threshold is done while active vmcs is
vmcs02 instead of vmcs01. Thus, when later at some point L0 will
emulate an exit from L2 to L1, L1 will still run with high
TPR-Threshold. This will result in every VMEntry to L1 to immediately
exit on TPR_BELOW_THRESHOLD and continue to do so infinitely until
some condition will cause KVM_REQ_EVENT to be set.
(Note that TPR_BELOW_THRESHOLD exit handler do not set KVM_REQ_EVENT
until apic_update_ppr() will notice a new injectable interrupt for PPR)

To fix this issue, change update_cr8_intercept() such that if L2 lowers
L1's TPR in a way that requires to lower L1's TPR-Threshold, save update
to TPR-Threshold and apply it to vmcs01 when L0 emulates an exit from
L2 to L1.

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index cd8d0b040daa813915395b3e727a6ebc1cfec846..bdb9b302825073d5e946c8fc9bf84096dee8c7a7 100644 (file)
@@ -2073,6 +2073,7 @@ static void prepare_vmcs02_early(struct vcpu_vmx *vmx, struct vmcs12 *vmcs12)
        exec_control &= ~CPU_BASED_TPR_SHADOW;
        exec_control |= vmcs12->cpu_based_vm_exec_control;
 
+       vmx->nested.l1_tpr_threshold = -1;
        if (exec_control & CPU_BASED_TPR_SHADOW)
                vmcs_write32(TPR_THRESHOLD, vmcs12->tpr_threshold);
 #ifdef CONFIG_X86_64
@@ -4115,6 +4116,8 @@ void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
        vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.host.nr);
        vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, vmx->msr_autoload.guest.nr);
        vmcs_write64(TSC_OFFSET, vcpu->arch.tsc_offset);
+       if (vmx->nested.l1_tpr_threshold != -1)
+               vmcs_write32(TPR_THRESHOLD, vmx->nested.l1_tpr_threshold);
 
        if (kvm_has_tsc_control)
                decache_tsc_multiplier(vmx);
index 2a64bf3c62b9fbffc4a14ecaadd49c754ee92a4b..765086756177518241d980712326abd4e243d5dc 100644 (file)
@@ -5988,7 +5988,10 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
                return;
 
        tpr_threshold = (irr == -1 || tpr < irr) ? 0 : irr;
-       vmcs_write32(TPR_THRESHOLD, tpr_threshold);
+       if (is_guest_mode(vcpu))
+               to_vmx(vcpu)->nested.l1_tpr_threshold = tpr_threshold;
+       else
+               vmcs_write32(TPR_THRESHOLD, tpr_threshold);
 }
 
 void vmx_set_virtual_apic_mode(struct kvm_vcpu *vcpu)
index bee16687dc0bf054957273d520306cfcbbd178dc..43331dfafffe6f91007c1e701bb343a91afee41c 100644 (file)
@@ -167,6 +167,9 @@ struct nested_vmx {
        u64 vmcs01_debugctl;
        u64 vmcs01_guest_bndcfgs;
 
+       /* to migrate it to L1 if L2 writes to L1's CR8 directly */
+       int l1_tpr_threshold;
+
        u16 vpid02;
        u16 last_vpid;