Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1020410pxb; Wed, 6 Apr 2022 06:55:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyFULgpAbTz7zQxcBigQyCmiyCp7kj4cFA3XW84Zl8sIxYnp5lO4AAp3fL5mVXnMHV8VVE X-Received: by 2002:a17:903:1252:b0:154:ca85:59a0 with SMTP id u18-20020a170903125200b00154ca8559a0mr8952086plh.169.1649253299980; Wed, 06 Apr 2022 06:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649253299; cv=none; d=google.com; s=arc-20160816; b=eeqLPgHi18YYq9GVtV9k0lPC0zYNuT/X8I7mstdoRD8lVLMuh7dwzaXwb0zLObRgy6 9hM8Jg3RXMz9UYKLiFteh44+5zV1uzeEz91qcykabi+Q1xjtXPBioYZGgmUZIAU6BIiU i1getWsAYSjmMClk2u7WsKngQcn/2rwGndVkIvri+LOi1ojjNJ1OKhiqGgLy4D7qB2nU SZHUU1g1BKUFlnmkuwcWA1FBuF2cldZp2vAEtxjNmzYc3LfIJszf9uiPHOjLqERUZ8GO jbzdCHue9lyonN1D7PbdctBquXNvd533PuUQVN2BoXyT1iR7ldCBvyo6F7q40ZhJl80K tk9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1hsJkr9UXrzSngeeWLSa9xhNQuw6M20YfSZxEN2SPwE=; b=mNfEG+HcZoy8yjf0oGyiAGt3P217kmhqHwh+jBeDRfDijALTaKEn66djZ4GrlUVYs4 Z58Db/6a8+R+5vQoxt2Gx/cCUj0h4OszGPm2p5wPC9GkfihkNqv6LQhxSCUlK0e9fXC6 4Aj2tsVyAVnmp5sMDvu7rj+amaYnC3PQ/d3lsGItm8N2z88dQWN2JQSu7NLsktDll8VH 68cXTOGImKaGmLOQBh8K6q5u5uYc09CGmW2WvnwdnDNTv0J0cBJaB2ap0wmVvGe6XbR2 arv44tsH/xZ+TWwfV7Yg5eGIoQMYa1rzpqcwCd9OLo9B9rsVPT2KGeATSSALeD6hhBD3 ZZVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aAvkQP7U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u7-20020a170903124700b00153be6474c2si16542258plh.531.2022.04.06.06.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:54:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aAvkQP7U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C314FBF033; Wed, 6 Apr 2022 04:48:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573054AbiDEWsJ (ORCPT + 99 others); Tue, 5 Apr 2022 18:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352739AbiDEKFC (ORCPT ); Tue, 5 Apr 2022 06:05:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF47A49FA4; Tue, 5 Apr 2022 02:53:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D868616DC; Tue, 5 Apr 2022 09:53:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B3CCC385A3; Tue, 5 Apr 2022 09:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152425; bh=LHcQxs7YDYUfU/67ZI4UyYI/EQF43ch4sKzahqrifew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aAvkQP7UZuLM0fKuERgYwqUPtWFv1Bwa5uaq/uPxRbF+eO1p/xrLOrQR4SJA6wVXS eb5W7DKcpSVmoQHVMDnydZUAtjyD3WpQGUMiGswauQMeDqR/FfY+ztuXfDL1GWBs/p HJjixok4DfQtXfBY267/TcmL8XEswL1rlzst9JzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.15 771/913] KVM: x86/mmu: Move "invalid" check out of kvm_tdp_mmu_get_root() Date: Tue, 5 Apr 2022 09:30:33 +0200 Message-Id: <20220405070402.943010262@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Sean Christopherson commit 04dc4e6ce274fa729feda32aa957b27388a3870c upstream. Move the check for an invalid root out of kvm_tdp_mmu_get_root() and into the one place it actually matters, tdp_mmu_next_root(), as the other user already has an implicit validity check. A future bug fix will need to get references to invalid roots to honor mmu_notifier requests; there's no point in forcing what will be a common path to open code getting a reference to a root. No functional change intended. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson Message-Id: <20211215011557.399940-3-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/tdp_mmu.c | 12 ++++++++++-- arch/x86/kvm/mmu/tdp_mmu.h | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -121,9 +121,14 @@ static struct kvm_mmu_page *tdp_mmu_next next_root = list_first_or_null_rcu(&kvm->arch.tdp_mmu_roots, typeof(*next_root), link); - while (next_root && !kvm_tdp_mmu_get_root(kvm, next_root)) + while (next_root) { + if (!next_root->role.invalid && + kvm_tdp_mmu_get_root(kvm, next_root)) + break; + next_root = list_next_or_null_rcu(&kvm->arch.tdp_mmu_roots, &next_root->link, typeof(*next_root), link); + } rcu_read_unlock(); @@ -199,7 +204,10 @@ hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(stru role = page_role_for_level(vcpu, vcpu->arch.mmu->shadow_root_level); - /* Check for an existing root before allocating a new one. */ + /* + * Check for an existing root before allocating a new one. Note, the + * role check prevents consuming an invalid root. + */ for_each_tdp_mmu_root(kvm, root, kvm_mmu_role_as_id(role)) { if (root->role.word == role.word && kvm_tdp_mmu_get_root(kvm, root)) --- a/arch/x86/kvm/mmu/tdp_mmu.h +++ b/arch/x86/kvm/mmu/tdp_mmu.h @@ -10,9 +10,6 @@ hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(stru __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm *kvm, struct kvm_mmu_page *root) { - if (root->role.invalid) - return false; - return refcount_inc_not_zero(&root->tdp_mmu_root_count); }