Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp605744pxb; Tue, 5 Apr 2022 15:43:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw71SMy6TOWNHVVHoCUoKqa7xkgb7SFtw/o+YZ0nINjUlU6tOpamq5HsHOhuNvuzq5CJVAD X-Received: by 2002:a17:902:a98a:b0:155:fc0b:f1a with SMTP id bh10-20020a170902a98a00b00155fc0b0f1amr5520040plb.21.1649198626056; Tue, 05 Apr 2022 15:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649198626; cv=none; d=google.com; s=arc-20160816; b=CPfcXPZJr7I0v2qyc3UJW8qfmpXtw6K0cZDS9YjiqZX7JBD3sYfmvG3iYBoQPgvnJH eIQbbQ8g3aUPh8pMNI0VQeUZ1bWqcYVkggOmt7fCXPZ48C6ksIjlJWGaZlzMipBNfCCN hWm3tVPXFfyZNLE8ZD0qBj4GspX8KsaCrHUZNKvAAWERZAuWdQ2AkPi3iWAqT2W0Q8cU 6FxC7AH2RxCUfCDq76BOX9CYrbHCjMRkvLgkSMiptXfAoEz69ClHEXdJ6ORmFLphdbb+ f6ZKuWdbvcdnEGJq+O3iiyDBvaZ4ofv6+GLKS696q/c2G7J8NlWQWAA6nBfrR6DOAd4k RTVQ== 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=iZoEvjyTCh2jJacY6QzEncD/HhiKdKQ9dJik1nlCgLI=; b=aD1gWYcdx3Vy7ESe4ISyLvzaPBPl8X0A1YW92l052OhnfoSmTYHvSKMmCiMmraAvf8 MYFknyc7Q4bC9mQMOnrut2qRXIQ/zDGgUImqaA8DLgD3s7qgwe1fgzKXNI9oU8RXDzp8 H49G9LbXng1DbzeSeUTQipz5bLz9seJAzYPYZoaVjfJqFBpPSRjkYbsmAGezEHGZCcZP +RseEW0tkuo1yCiZpM4QCTFn+L8ZMc/EAis1C5Kx9nML+VPl36a6s/fWOWyAdHIwEQmS Xi2UG6Kp96l3x/TWj6VkHa9/Sn908g7RTLtWHUJtGi4871E0pYYqUzE2JnQf4HmFFYn6 VZtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uBZX53MT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id t23-20020a1709028c9700b00153b2d164f5si13216850plo.253.2022.04.05.15.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:43:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uBZX53MT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 735676FA16; Tue, 5 Apr 2022 15:24:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383280AbiDENac (ORCPT + 99 others); Tue, 5 Apr 2022 09:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345347AbiDEJW3 (ORCPT ); Tue, 5 Apr 2022 05:22:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A0F47AE4; Tue, 5 Apr 2022 02:10:38 -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 7DEF161527; Tue, 5 Apr 2022 09:10:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FCE4C385A0; Tue, 5 Apr 2022 09:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149837; bh=FwQBUKInjP4jnvxbqXA+7tsKrzdHs2KgsX0dQYJAh1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uBZX53MTpIwJ0bqRbcnr43MgQHs8bygVwgjJXLIK5sSb89rzi/Zq7nZGYHYEMHhuH 7k5B3Ol+msfWkOwW9LfjJA2F6GMp0xVVjrTwmt4nUYHi8edTYhw1egAuBv0737DFrE /knp4++mCbQqedZyC2Wz/jGiNwYRjydc96GePiEQ= 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.16 0859/1017] KVM: x86/mmu: Move "invalid" check out of kvm_tdp_mmu_get_root() Date: Tue, 5 Apr 2022 09:29:32 +0200 Message-Id: <20220405070419.732710256@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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(); @@ -200,7 +205,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); }