提交 a3e339e1 编写于 作者: P Paolo Bonzini

KVM: compute correct map even if all APICs are software disabled

Logical destination mode can be used to send NMI IPIs even when all
APICs are software disabled, so if all APICs are software disabled we
should still look at the DFRs.

So the DFRs should all be the same, even if some or all APICs are
software disabled.  However, the SDM does not say this, so tweak
the logic as follows:

- if one APIC is enabled and has LDR != 0, use that one to build the map.
This picks the right DFR in case an OS is only setting it for the
software-enabled APICs, or in case an OS is using logical addressing
on some APICs while leaving the rest in reset state (using LDR was
suggested by Radim).

- if all APICs are disabled, pick a random one to build the map.
We use the last one with LDR != 0 for simplicity.
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 173beedc
...@@ -160,29 +160,34 @@ static void recalculate_apic_map(struct kvm *kvm) ...@@ -160,29 +160,34 @@ static void recalculate_apic_map(struct kvm *kvm)
if (!kvm_apic_present(vcpu)) if (!kvm_apic_present(vcpu))
continue; continue;
/*
* All APICs have to be configured in the same mode by an OS.
* We take advatage of this while building logical id loockup
* table. After reset APICs are in xapic/flat mode, so if we
* find apic with different setting we assume this is the mode
* OS wants all apics to be in; build lookup table accordingly.
*/
if (apic_x2apic_mode(apic)) { if (apic_x2apic_mode(apic)) {
new->ldr_bits = 32; new->ldr_bits = 32;
new->cid_shift = 16; new->cid_shift = 16;
new->cid_mask = (1 << KVM_X2APIC_CID_BITS) - 1; new->cid_mask = (1 << KVM_X2APIC_CID_BITS) - 1;
new->lid_mask = 0xffff; new->lid_mask = 0xffff;
new->broadcast = X2APIC_BROADCAST; new->broadcast = X2APIC_BROADCAST;
break; } else if (kvm_apic_get_reg(apic, APIC_LDR)) {
} else if (kvm_apic_sw_enabled(apic)) {
if (kvm_apic_get_reg(apic, APIC_DFR) == if (kvm_apic_get_reg(apic, APIC_DFR) ==
APIC_DFR_CLUSTER) { APIC_DFR_CLUSTER) {
new->cid_shift = 4; new->cid_shift = 4;
new->cid_mask = 0xf; new->cid_mask = 0xf;
new->lid_mask = 0xf; new->lid_mask = 0xf;
} else {
new->cid_shift = 8;
new->cid_mask = 0;
new->lid_mask = 0xff;
} }
break;
} }
/*
* All APICs have to be configured in the same mode by an OS.
* We take advatage of this while building logical id loockup
* table. After reset APICs are in software disabled mode, so if
* we find apic with different setting we assume this is the mode
* OS wants all apics to be in; build lookup table accordingly.
*/
if (kvm_apic_sw_enabled(apic))
break;
} }
kvm_for_each_vcpu(i, vcpu, kvm) { kvm_for_each_vcpu(i, vcpu, kvm) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册