Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3368406rdh; Thu, 28 Sep 2023 09:34:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+ViSqzQ4y8Ny72Xd2iHCumpoHdt3anWc2uzNYtTkVPMzJA9g4Z6XLYBAlzV/eTAe3UNP3 X-Received: by 2002:a17:902:d2c5:b0:1c6:c90:2aeb with SMTP id n5-20020a170902d2c500b001c60c902aebmr1885871plc.51.1695918893207; Thu, 28 Sep 2023 09:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695918893; cv=none; d=google.com; s=arc-20160816; b=LJEwOZmrsxPt4l6m3Ms8vi8cuGd2SRClkla1LwpUDCRf9wB+EKdrZt7rfSJtklakqE R5pVfBjky+iJaHntCb/V0kY2LML8Cs+U52O4rPwVnUzrT6JPWSgAYAz0B36KVc5NCG2Q HyC5vQlcZqamKbRZsNw4TnX5EgcomazJahN1yahd3rw+6xpzTExZs6W2G9Bh4py+Ruzh /LAIYR5GY1hu6NulXagMZeGdlWhUqfapCtYPK4texlNmeYrt1XDdGrROPrjsUT8nM4Kg tzqgWyJsKBc0scBZmtPbplw7z4ngbGHrES8LHpsTtrbp7fDvCwpckCwCcmXaHEOPT0gE 1j+Q== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=D9/RV6Hb0/JilJv3mz6TN4Le2K6hQ3WCfVt/3YM6beE=; fh=4N0ilCeWNPUMy3p+fwQEcpDcSktLq8IMxbqwLAweA1k=; b=hBzUBTXGoXoEXHQQHug8NROyoU/KwdG3F8MHjl+q7TCtMbQzE4pj1s4izm3a5aEu0+ vgMPgSY0mkX1X504YUPhKiKBFrULazUMt6trUsIPc+g45HIbL7bQNayJxGOqLeuEKK+Q y54kpXY1tQ+6RBfe1lzunNsOu14q2rjG16uIEZCMF0Y8EbRRfWfrBUctfHKlMnHzlOil v8AjvlO4iTXNSVGjhUbv95ZVmoegWKKvdIxhqWcSaZi/iioWQcJJcal80JyFcfcwuXR8 fK1g9v6T2fF/TueOhO2PNDjI406PSc7/jttODX4D5SI3z3QyeIjQVYMYwa7Oqo+4oqI2 Ay5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C0rs+wK3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b5-20020a170902d50500b001c611f28597si13786139plg.539.2023.09.28.09.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 09:34:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C0rs+wK3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 017428097A72; Thu, 28 Sep 2023 09:31:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231704AbjI1QbH (ORCPT + 99 others); Thu, 28 Sep 2023 12:31:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231696AbjI1QbD (ORCPT ); Thu, 28 Sep 2023 12:31:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 134231AD for ; Thu, 28 Sep 2023 09:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695918612; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D9/RV6Hb0/JilJv3mz6TN4Le2K6hQ3WCfVt/3YM6beE=; b=C0rs+wK3kJNX0cfHh2/rNwBwj3KADNRmuR+HyLEZld7iZYv7+ablLpXOJruc5HuzymaYAH gTP2t0hIjLHxYKUrsGk0tGf6LCMxolmsvx/yvd93tVdsMMaQie5KLk15afAtRozDmHNWub II2FDRXRbM+/8O3EB4HVePrvqHcL+Vc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-204-jWNZzshsOFiCkpO4G53Aiw-1; Thu, 28 Sep 2023 12:30:02 -0400 X-MC-Unique: jWNZzshsOFiCkpO4G53Aiw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F17B858293; Thu, 28 Sep 2023 16:30:00 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26BEE140E969; Thu, 28 Sep 2023 16:30:00 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 1/3] KVM: x86/mmu: remove unnecessary "bool shared" argument from functions Date: Thu, 28 Sep 2023 12:29:57 -0400 Message-Id: <20230928162959.1514661-2-pbonzini@redhat.com> In-Reply-To: <20230928162959.1514661-1-pbonzini@redhat.com> References: <20230928162959.1514661-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 28 Sep 2023 09:31:45 -0700 (PDT) Neither tdp_mmu_next_root nor kvm_tdp_mmu_put_root need to know if the lock is taken for read or write. Either way, protection is achieved via RCU and tdp_mmu_pages_lock. Remove the argument and just assert that the lock is taken. Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 34 +++++++++++++++++++++------------- arch/x86/kvm/mmu/tdp_mmu.h | 3 +-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index f7901cb4d2fa..64b1bdba943e 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -3548,7 +3548,7 @@ static void mmu_free_root_page(struct kvm *kvm, hpa_t *root_hpa, return; if (is_tdp_mmu_page(sp)) - kvm_tdp_mmu_put_root(kvm, sp, false); + kvm_tdp_mmu_put_root(kvm, sp); else if (!--sp->root_count && sp->role.invalid) kvm_mmu_prepare_zap_page(kvm, sp, invalid_list); diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 6cd4dd631a2f..ab0876015be7 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -73,10 +73,13 @@ static void tdp_mmu_free_sp_rcu_callback(struct rcu_head *head) tdp_mmu_free_sp(sp); } -void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root, - bool shared) +void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root) { - kvm_lockdep_assert_mmu_lock_held(kvm, shared); + /* + * Either read or write is okay, but the lock is needed because + * writers might not take tdp_mmu_pages_lock. + */ + lockdep_assert_held(&kvm->mmu_lock); if (!refcount_dec_and_test(&root->tdp_mmu_root_count)) return; @@ -106,10 +109,16 @@ void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root, */ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, struct kvm_mmu_page *prev_root, - bool shared, bool only_valid) + bool only_valid) { struct kvm_mmu_page *next_root; + /* + * While the roots themselves are RCU-protected, fields such as + * role.invalid are protected by mmu_lock. + */ + lockdep_assert_held(&kvm->mmu_lock); + rcu_read_lock(); if (prev_root) @@ -132,7 +141,7 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, rcu_read_unlock(); if (prev_root) - kvm_tdp_mmu_put_root(kvm, prev_root, shared); + kvm_tdp_mmu_put_root(kvm, prev_root); return next_root; } @@ -144,13 +153,12 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, * recent root. (Unless keeping a live reference is desirable.) * * If shared is set, this function is operating under the MMU lock in read - * mode. In the unlikely event that this thread must free a root, the lock - * will be temporarily dropped and reacquired in write mode. + * mode. */ #define __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _shared, _only_valid)\ - for (_root = tdp_mmu_next_root(_kvm, NULL, _shared, _only_valid); \ - _root; \ - _root = tdp_mmu_next_root(_kvm, _root, _shared, _only_valid)) \ + for (_root = tdp_mmu_next_root(_kvm, NULL, _only_valid); \ + _root; \ + _root = tdp_mmu_next_root(_kvm, _root, _only_valid)) \ if (kvm_lockdep_assert_mmu_lock_held(_kvm, _shared) && \ kvm_mmu_page_as_id(_root) != _as_id) { \ } else @@ -159,9 +167,9 @@ static struct kvm_mmu_page *tdp_mmu_next_root(struct kvm *kvm, __for_each_tdp_mmu_root_yield_safe(_kvm, _root, _as_id, _shared, true) #define for_each_tdp_mmu_root_yield_safe(_kvm, _root, _shared) \ - for (_root = tdp_mmu_next_root(_kvm, NULL, _shared, false); \ - _root; \ - _root = tdp_mmu_next_root(_kvm, _root, _shared, false)) \ + for (_root = tdp_mmu_next_root(_kvm, NULL, false); \ + _root; \ + _root = tdp_mmu_next_root(_kvm, _root, false)) if (!kvm_lockdep_assert_mmu_lock_held(_kvm, _shared)) { \ } else diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h index 733a3aef3a96..20d97aa46c49 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.h +++ b/arch/x86/kvm/mmu/tdp_mmu.h @@ -17,8 +17,7 @@ __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm_mmu_page *root) return refcount_inc_not_zero(&root->tdp_mmu_root_count); } -void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root, - bool shared); +void kvm_tdp_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *root); bool kvm_tdp_mmu_zap_leafs(struct kvm *kvm, gfn_t start, gfn_t end, bool flush); bool kvm_tdp_mmu_zap_sp(struct kvm *kvm, struct kvm_mmu_page *sp); -- 2.39.1