From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EED53C433EF for ; Mon, 11 Apr 2022 09:38:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343785AbiDKJkI (ORCPT ); Mon, 11 Apr 2022 05:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344633AbiDKJjt (ORCPT ); Mon, 11 Apr 2022 05:39:49 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBCE740923; Mon, 11 Apr 2022 02:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649669853; x=1681205853; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=wVjlORT4Ee/YTCdDKrpjhYEEMJhlDlPVyc5jVtqX37o=; b=IZ6jW7MC2e6S7MLlR1l0KJdC0Xt1PCVweohDP7hW9dBMBhdLRxOGgO2A KPBHdd+qgPIW8CJR+kIbul2s0zQ1kl5/sodNbATZ60PVgTEBqvp6+CiyA JG6v6sEf9Ba8YtdYpGLMWgkob5bIXP28QUYt/w/U89P3EolvULwCxJ3F7 Y2prGcHNRohyVTx24LpqomfQ/zpxrBHJuMVgs51ZgknS4PBCNsAyx6u+P ARNSjWCcuf2CtyWXoUaCC6cNTnVWy4j7gWvt3X4oY638GrAE8Qre2RNJW 80WaRV9v9wHKNVInnSGRlQsUF7LU5JpWuUZyQf+7G6cn0LO9sfUv3uJEc w==; X-IronPort-AV: E=McAfee;i="6400,9594,10313"; a="259671479" X-IronPort-AV: E=Sophos;i="5.90,251,1643702400"; d="scan'208";a="259671479" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2022 02:37:09 -0700 X-IronPort-AV: E=Sophos;i="5.90,251,1643702400"; d="scan'208";a="572050567" Received: from arthur-vostro-3668.sh.intel.com ([10.239.13.120]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2022 02:37:03 -0700 From: Zeng Guang To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, Dave Hansen , Tony Luck , Kan Liang , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Kim Phillips , Jarkko Sakkinen , Jethro Beekman , Kai Huang Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Robert Hu , Gao Chao , Zeng Guang Subject: [PATCH v8 7/9] KVM: Move kvm_arch_vcpu_precreate() under kvm->lock Date: Mon, 11 Apr 2022 17:04:45 +0800 Message-Id: <20220411090447.5928-8-guang.zeng@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220411090447.5928-1-guang.zeng@intel.com> References: <20220411090447.5928-1-guang.zeng@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arch specific KVM common data may require pre-allocation or other preprocess ready before vCPU creation at runtime. It's safe to invoke kvm_arch_vcpu_precreate() within the protection of kvm->lock directly rather than take into account in the implementation for each architecture. Suggested-by: Sean Christopherson Signed-off-by: Zeng Guang --- arch/s390/kvm/kvm-s390.c | 2 -- virt/kvm/kvm_main.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 156d1c25a3c1..5c795bbcf1ea 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -3042,9 +3042,7 @@ static int sca_can_add_vcpu(struct kvm *kvm, unsigned int id) if (!sclp.has_esca || !sclp.has_64bscao) return false; - mutex_lock(&kvm->lock); rc = kvm->arch.use_esca ? 0 : sca_switch_to_extended(kvm); - mutex_unlock(&kvm->lock); return rc == 0 && id < KVM_S390_ESCA_CPU_SLOTS; } diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 70e05af5ebea..a452e678a015 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3732,9 +3732,9 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) } kvm->created_vcpus++; + r = kvm_arch_vcpu_precreate(kvm, id); mutex_unlock(&kvm->lock); - r = kvm_arch_vcpu_precreate(kvm, id); if (r) goto vcpu_decrement; -- 2.27.0