Skip to content

Commit 6982b34

Browse files
aljimenezbsean-jc
authored andcommitted
KVM: x86: Only set APICV_INHIBIT_REASON_ABSENT if APICv is enabled
Use the APICv enablement status to determine if APICV_INHIBIT_REASON_ABSENT needs to be set, instead of unconditionally setting the reason during initialization. Specifically, in cases where AVIC is disabled via module parameter or lack of hardware support, unconditionally setting an inhibit reason due to the absence of an in-kernel local APIC can lead to a scenario where the reason incorrectly remains set after a local APIC has been created by either KVM_CREATE_IRQCHIP or the enabling of KVM_CAP_IRQCHIP_SPLIT. This is because the helpers in charge of removing the inhibit return early if enable_apicv is not true, and therefore the bit remains set. This leads to confusion as to the cause why APICv is not active, since an incorrect reason will be reported by tracepoints and/or a debugging tool that examines the currently set inhibit reasons. Fixes: ef8b4b7 ("KVM: ensure APICv is considered inactive if there is no APIC") Signed-off-by: Alejandro Jimenez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 1d294df commit 6982b34

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

arch/x86/kvm/x86.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,15 +9992,12 @@ static void set_or_clear_apicv_inhibit(unsigned long *inhibits,
99929992

99939993
static void kvm_apicv_init(struct kvm *kvm)
99949994
{
9995-
unsigned long *inhibits = &kvm->arch.apicv_inhibit_reasons;
9995+
enum kvm_apicv_inhibit reason = enable_apicv ? APICV_INHIBIT_REASON_ABSENT :
9996+
APICV_INHIBIT_REASON_DISABLE;
99969997

9997-
init_rwsem(&kvm->arch.apicv_update_lock);
9998-
9999-
set_or_clear_apicv_inhibit(inhibits, APICV_INHIBIT_REASON_ABSENT, true);
9998+
set_or_clear_apicv_inhibit(&kvm->arch.apicv_inhibit_reasons, reason, true);
100009999

10001-
if (!enable_apicv)
10002-
set_or_clear_apicv_inhibit(inhibits,
10003-
APICV_INHIBIT_REASON_DISABLE, true);
10000+
init_rwsem(&kvm->arch.apicv_update_lock);
1000410001
}
1000510002

1000610003
static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)

0 commit comments

Comments
 (0)