All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] KVM: x86: fix kvm_has_noapic_vcpu updates when fail to create vcpu
@ 2023-11-23  1:04 Li RongQing
  2023-12-01 16:57 ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Li RongQing @ 2023-11-23  1:04 UTC (permalink / raw)
  To: x86, kvm, mlevitsk, yilun.xu

Static key kvm_has_noapic_vcpu should be reduced when fail to create
vcpu, opportunistically change to call kvm_free_lapic only when LAPIC
is in kernel in kvm_arch_vcpu_destroy

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
diff v1: call kvm_free_lapic conditionally in kvm_arch_vcpu_destroy

 arch/x86/kvm/x86.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2c92407..3cadf28 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12079,7 +12079,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 	kfree(vcpu->arch.mci_ctl2_banks);
 	free_page((unsigned long)vcpu->arch.pio_data);
 fail_free_lapic:
-	kvm_free_lapic(vcpu);
+	if (lapic_in_kernel(vcpu))
+		kvm_free_lapic(vcpu);
+	else
+		static_branch_dec(&kvm_has_noapic_vcpu);
 fail_mmu_destroy:
 	kvm_mmu_destroy(vcpu);
 	return r;
@@ -12122,14 +12125,17 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 	kvm_pmu_destroy(vcpu);
 	kfree(vcpu->arch.mce_banks);
 	kfree(vcpu->arch.mci_ctl2_banks);
-	kvm_free_lapic(vcpu);
+
+	if (lapic_in_kernel(vcpu))
+		kvm_free_lapic(vcpu);
+	else
+		static_branch_dec(&kvm_has_noapic_vcpu);
+
 	idx = srcu_read_lock(&vcpu->kvm->srcu);
 	kvm_mmu_destroy(vcpu);
 	srcu_read_unlock(&vcpu->kvm->srcu, idx);
 	free_page((unsigned long)vcpu->arch.pio_data);
 	kvfree(vcpu->arch.cpuid_entries);
-	if (!lapic_in_kernel(vcpu))
-		static_branch_dec(&kvm_has_noapic_vcpu);
 }
 
 void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-14 15:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-23  1:04 [PATCH v2] KVM: x86: fix kvm_has_noapic_vcpu updates when fail to create vcpu Li RongQing
2023-12-01 16:57 ` Sean Christopherson
2023-12-04  9:13   ` Li,Rongqing
2023-12-14 15:04   ` Xu Yilun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.