Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2771073rdh; Mon, 30 Oct 2023 07:17:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGjglXhEZmX9wjtkYVdvbD+ej8Ilfc29kgC0p96ts1q68P7q4ItBuAlwF4LQWw2zq+eNuT X-Received: by 2002:a05:6a00:148c:b0:6ba:8478:b99f with SMTP id v12-20020a056a00148c00b006ba8478b99fmr12806367pfu.28.1698675465908; Mon, 30 Oct 2023 07:17:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698675465; cv=none; d=google.com; s=arc-20160816; b=IFmR2iGygRLblQ0CM5BuFxn4043hzQSGUmlp7qTTbFlf4tz59UFxofB9CshE6x57B/ gsrt3otD4U6o1fMtdEPS3jKrlQPWZb06PXjFt+cNa3dyTW3uDZZyb7RjRnA6n8en26dd 4EE+yj5opR3TRvyX48rvnU1iQEZgdqfwauUEoKzI7JkHSSYXMvu+O9WQvco6n87GWAH4 UbG0UPWmFJubmrXIIldOpG1S63Ft09I6lYWHIUBUi41/BxKCcwWEZI+82HTvlWirrL4M L8d57ZAhDFo82TOEmxeELr5wJSx/0nBe6NB8RTkLttLpZ16VrZcGle1ch6aTETwXjb1/ URyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=JL0o6ejOmiqyX7RlEJrZ7RAI8Gjvf0EzzlogCece80k=; fh=LkO7p7q30BFfSoovj2Eo8otZDk7Xt7A9HoE19DR418E=; b=XRQcezlPYZrfK1OF40GBpZfY+lcjpl6m9yEVl9jtmi7p746dLnGHL727OWjvLMnqWl hWmrFrKb7HbYnLICWSm77XxcCn6UISaosF5ci0yBtLxFy6kS65qX1rfvUcTAzRIl2Veg d9biDRlczeu9yuy1od7/I7vQDpZTAM/uCXJv7a3IaTDb1Nov8znuHRfQsKd2Go9c5fAO NHiPWwJIIXPJeUA/09EHfmOmlAJw5+LyPci6xYI3yFpK1oe/FQFhpvOPy+WF7bbFills 74DLjLpgwmHhzLjrHPaRHjEZ4oSgpMN7vVVgBWKWkSB3A9H7ILeRmNiE1uiI/kVMcDZ4 sJvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Wjl2lgZq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id fh9-20020a056a00390900b006bdaa24308fsi5026400pfb.105.2023.10.30.07.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 07:17:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Wjl2lgZq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4D3C4808207D; Mon, 30 Oct 2023 07:17:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233092AbjJ3ORh (ORCPT + 99 others); Mon, 30 Oct 2023 10:17:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbjJ3ORf (ORCPT ); Mon, 30 Oct 2023 10:17:35 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C9BC0; Mon, 30 Oct 2023 07:17:33 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B59E521906; Mon, 30 Oct 2023 14:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1698675451; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=JL0o6ejOmiqyX7RlEJrZ7RAI8Gjvf0EzzlogCece80k=; b=Wjl2lgZqWUg/a9AE3QuJHK6+NDQzHMDQTy31U33Llwff6vIw9Uw3qZJEK6BBLQK7obO/sZ t2Mtq/tO6UUvCOg2E8yhcLo1TzdTXF2lTFc0SzApsN+9MC+1pLb4PGPjwQK+Xh8b3RevrF dn4G3KmXXo2GEKtZOC/O72raxnLbkZw= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 66803138F8; Mon, 30 Oct 2023 14:17:31 +0000 (UTC) Received: from dovecot-director1.suse.de ([192.168.254.64]) by imap2.suse-dmz.suse.de with ESMTPSA id jifVFvu6P2VsOgAAMHmgww (envelope-from ); Mon, 30 Oct 2023 14:17:31 +0000 From: Nikolay Borisov To: seanjc@google.com Cc: pbonzini@redhat.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Nikolay Borisov Subject: [PATCH] KVM: x86: User mutex guards to eliminate __kvm_x86_vendor_init() Date: Mon, 30 Oct 2023 16:17:28 +0200 Message-Id: <20231030141728.1406118-1-nik.borisov@suse.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 30 Oct 2023 07:17:43 -0700 (PDT) Current separation between (__){0,1}kvm_x86_vendor_init() is superfluos as the the underscore version doesn't have any other callers. Instead, use the newly added cleanup infrastructure to ensure that kvm_x86_vendor_init() holds the vendor_module_lock throughout its exectuion and that in case of error in the middle it's released. No functional changes. Signed-off-by: Nikolay Borisov --- arch/x86/kvm/x86.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 41cce5031126..cd7c2d0f88cb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9446,11 +9446,13 @@ static void kvm_x86_check_cpu_compat(void *ret) *(int *)ret = kvm_x86_check_processor_compatibility(); } -static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) +int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) { u64 host_pat; int r, cpu; + guard(mutex)(&vendor_module_lock); + if (kvm_x86_ops.hardware_enable) { pr_err("already loaded vendor module '%s'\n", kvm_x86_ops.name); return -EEXIST; @@ -9580,17 +9582,6 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) kmem_cache_destroy(x86_emulator_cache); return r; } - -int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) -{ - int r; - - mutex_lock(&vendor_module_lock); - r = __kvm_x86_vendor_init(ops); - mutex_unlock(&vendor_module_lock); - - return r; -} EXPORT_SYMBOL_GPL(kvm_x86_vendor_init); void kvm_x86_vendor_exit(void) -- 2.34.1