Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp233036pxb; Tue, 12 Apr 2022 00:05:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8cSCxgbwfCQPmEedmlCJUzDrgQDpO2uA2JcjYI2Zfwo9w/mXeMPvQkW73LZc9cvnlzswE X-Received: by 2002:a63:6645:0:b0:382:65eb:1215 with SMTP id a66-20020a636645000000b0038265eb1215mr29479446pgc.337.1649747130750; Tue, 12 Apr 2022 00:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649747130; cv=none; d=google.com; s=arc-20160816; b=ByhNHp+7oos0vG0AU8xfFCzNYeoXI9sOJtCku9K5QuB0e+TXtnn3YfY0cRPZt+coO7 RcP8o24B0iduySzB7zFM+3RVxTYttWeBUKquhR7UJIjvH0YWgIfHwQhkuM15yCrYljWH 8N/N2erfWmZqOSrqtpSGsROoHt2DWfaz7wsLmhfeE7GD8I70HjeChP4s+brTMwx8VP72 0b/54rhU34TIkNVXTeZiDNQVE6gnI9yABNrmfrblX3KUa59gO+hXfRt2zZNgRW0idFPd ZLWMvhU+qCrIlKrEHf/Mt0NzZpJvJ4FwkiZFFY3R/ZHAmox+9nIyuxC+/o54XfSEtEum MJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=lHGKrBd6spPi3Qu0/ie/DAPEXmOkL5QVBRj5P2EvhCY=; b=LzHtkhPT5QMy3fIebKKtQHLorWreTs3b/WTjG9yZaMrlvM6Fgj2XxRMLiHDAVcGK0J CVb42B9Px8OuWWAELxSDR5NnRKZVEggISi/QtBLpMnO62mpjELHDYOZ4GBsTSILXhEPx dinvINrp2C/3g/NB2PAZYadZb5ipLUTEUx611FjpCv4fY0eWsvVxFhYc7X7+5z2pp36d Ouc+fv2sqMDcSytCMMdqVqVpfC/wBRQBlqL1UIn7Bx90vS2eiskKIMFsY5jjfdMv0ApK LStXrwuiX+GU50nBFDAvMlaCCsiD20bFDahI3U0jMfdwk2p+f26cf4qSsGywpWIYGpF3 qT0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IZ6jW7MC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a170902e85200b0015874dc3247si3674046plg.170.2022.04.12.00.05.06; Tue, 12 Apr 2022 00:05:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IZ6jW7MC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242868AbiDKJkI (ORCPT + 99 others); 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> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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