diff mbox series

[v2,15/23] KVM: x86: Explicitly skip adding vCPU to optimized logical map if LDR==0

Message ID 20220903002254.2411750-16-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: AVIC and local APIC fixes+cleanups | expand

Commit Message

Sean Christopherson Sept. 3, 2022, 12:22 a.m. UTC
Explicitly skip adding a vCPU to the optimized map of logical IDs if the
the vCPU's LDR is '0', i.e. if the vCPU will never response to logical
mode interrupts.  KVM already skips the vCPU in this case, but relies on
kvm_apic_map_get_logical_dest() to generate mask==0.  KVM still needs the
mask=0 check as a non-zero LDR can yield mask==0 depending on the mode,
but explicitly handling the LDR will make it simpler to clean up the
logical mode tracking in the future.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/lapic.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 4c5f49c4d4f1..80528d86f010 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -318,10 +318,12 @@  void kvm_recalculate_apic_map(struct kvm *kvm)
 			continue;
 
 		ldr = kvm_lapic_get_reg(apic, APIC_LDR);
+		if (!ldr)
+			continue;
 
 		if (apic_x2apic_mode(apic)) {
 			new->mode |= KVM_APIC_MODE_X2APIC;
-		} else if (ldr) {
+		} else {
 			ldr = GET_APIC_LOGICAL_ID(ldr);
 			if (kvm_lapic_get_reg(apic, APIC_DFR) == APIC_DFR_FLAT)
 				new->mode |= KVM_APIC_MODE_XAPIC_FLAT;