From patchwork Fri Nov 17 12:26:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li RongQing X-Patchwork-Id: 13458922 Authentication-Results: smtp.subspace.kernel.org; dkim=none X-Greylist: delayed 617 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 17 Nov 2023 04:36:53 PST Received: from njjs-sys-mailin01.njjs.baidu.com (mx316.baidu.com [180.101.52.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E7E49B3 for ; Fri, 17 Nov 2023 04:36:53 -0800 (PST) Received: from localhost (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by njjs-sys-mailin01.njjs.baidu.com (Postfix) with ESMTP id 85A787F00067; Fri, 17 Nov 2023 20:26:33 +0800 (CST) From: Li RongQing To: x86@kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: x86: fix kvm_has_noapic_vcpu updates when fail to create vcpu Date: Fri, 17 Nov 2023 20:26:33 +0800 Message-Id: <20231117122633.47028-1-lirongqing@baidu.com> X-Mailer: git-send-email 2.9.4 X-Spam-Level: * Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Static key kvm_has_noapic_vcpu should be reduced when fail to create vcpu, this patch fixes it Signed-off-by: Li RongQing Reviewed-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 41cce50..2a22e66 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11957,7 +11957,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)) + static_branch_dec(&kvm_has_noapic_vcpu); + else + kvm_free_lapic(vcpu); fail_mmu_destroy: kvm_mmu_destroy(vcpu); return r;