Skip to content

Commit ef40757

Browse files
Yuan ZhaoXiongbonzini
authored andcommitted
KVM: x86: fix APICv/x2AVIC disabled when vm reboot by itself
When a VM reboots itself, the reset process will result in an ioctl(KVM_SET_LAPIC, ...) to disable x2APIC mode and set the xAPIC id of the vCPU to its default value, which is the vCPU id. That will be handled in KVM as follows: kvm_vcpu_ioctl_set_lapic kvm_apic_set_state kvm_lapic_set_base => disable X2APIC mode kvm_apic_state_fixup kvm_lapic_xapic_id_updated kvm_xapic_id(apic) != apic->vcpu->vcpu_id kvm_set_apicv_inhibit(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) memcpy(vcpu->arch.apic->regs, s->regs, sizeof(*s)) => update APIC_ID When kvm_apic_set_state invokes kvm_lapic_set_base to disable x2APIC mode, the old 32-bit x2APIC id is still present rather than the 8-bit xAPIC id. kvm_lapic_xapic_id_updated will set the APICV_INHIBIT_REASON_APIC_ID_MODIFIED bit and disable APICv/x2AVIC. Instead, kvm_lapic_xapic_id_updated must be called after APIC_ID is changed. In fact, this fixes another small issue in the code in that potential changes to a vCPU's xAPIC ID need not be tracked for KVM_GET_LAPIC. Fixes: 3743c2f ("KVM: x86: inhibit APICv/AVIC on changes to APIC ID or APIC base") Signed-off-by: Yuan ZhaoXiong <[email protected]> Message-Id: <[email protected]> Cc: [email protected] Reported-by: Alejandro Jimenez <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent dd03cc9 commit ef40757

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/x86/kvm/lapic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,8 +2724,6 @@ static int kvm_apic_state_fixup(struct kvm_vcpu *vcpu,
27242724
icr = __kvm_lapic_get_reg64(s->regs, APIC_ICR);
27252725
__kvm_lapic_set_reg(s->regs, APIC_ICR2, icr >> 32);
27262726
}
2727-
} else {
2728-
kvm_lapic_xapic_id_updated(vcpu->arch.apic);
27292727
}
27302728

27312729
return 0;
@@ -2761,6 +2759,9 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s)
27612759
}
27622760
memcpy(vcpu->arch.apic->regs, s->regs, sizeof(*s));
27632761

2762+
if (!apic_x2apic_mode(apic))
2763+
kvm_lapic_xapic_id_updated(apic);
2764+
27642765
atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
27652766
kvm_recalculate_apic_map(vcpu->kvm);
27662767
kvm_apic_set_version(vcpu);

0 commit comments

Comments
 (0)