Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp63057iob; Tue, 17 May 2022 18:50:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzswmLnR8df32b3XHehkLpfbQBenBiDKA1XcvqxEkk6S6dE3EN3bTSSqKEoS+Ff5YUp3ciK X-Received: by 2002:a05:6402:90e:b0:425:a4bc:db86 with SMTP id g14-20020a056402090e00b00425a4bcdb86mr21560074edz.98.1652838656570; Tue, 17 May 2022 18:50:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652838656; cv=none; d=google.com; s=arc-20160816; b=DuDChfQyOHdru3Sz9Ma4ZgitfQV+CAmhpqjtqOk4N9S6u37B/EDYws4Qlr1VcfH1g6 cKGaDocec9TOzVHYnIflxMJLQcYxLfY9IUgAy1OrRwHjtDWLWYoi47WKOeRo1sG4E6C7 rXrf3zM4LdOjXLh7b+fUt8H3s16OJVNmqxNf6gpjkizxr/DczHfobDJfkkwEvlmMYvnZ 2H+pgzNpVLpo4TYqlM999wl6nfbeAoY5RmuYueprbtocUHkES9SX6KF1ekQJbGljt4O4 LkRy3fut7KN99moynibZXFVrbQcS8YSCAE4q1kjN7N0AUkGTOlWNU788TK+zNRe+bbRz XnXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EBasZC6YLIGG+8ebkH1QLdEFicqNV7dhlVlz53XQa0g=; b=OQn1aDKiNi9pVEjpPejLX0oKaiQXqPqzgeMiKN9snwn9ULb/zpe1i3hR0mkytSO+t6 aSBnQFK2hPcOt50cj2wMpifuubDp+0aSwwV4tYDV6k0C7wkgvemRGii7XPESj1NWhiSU QYdtM49y70qvvqU0e3W0h2UKzS/p9NVJxIEhiFb5qSIo3mO0vl3bBsenwogaei8FL55W BEOJTBs/KrFAwdKrcIB3EslhBx9JEXcfKyLOSfXBLGT/U8KzHwfzt89q7otfJ19lpZvV JAVBumuNSHvzj8KZnsfD7iA7lsYPcPgC8qEbUhc8EE2q/S+tvPkcEfh/c4jyJrqXMWps SHOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Lmv+/OSh"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020aa7d749000000b00425b4f69f0asi809401eds.101.2022.05.17.18.50.31; Tue, 17 May 2022 18:50:56 -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=@google.com header.s=20210112 header.b="Lmv+/OSh"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351171AbiEQQsC (ORCPT + 99 others); Tue, 17 May 2022 12:48:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351176AbiEQQsA (ORCPT ); Tue, 17 May 2022 12:48:00 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD5E14EF4D for ; Tue, 17 May 2022 09:47:59 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id i17so17824276pla.10 for ; Tue, 17 May 2022 09:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EBasZC6YLIGG+8ebkH1QLdEFicqNV7dhlVlz53XQa0g=; b=Lmv+/OShourHoBUs+tURSbEj9Ks1XGiGMRM1OA2iE9dUBahc5HLA478PsXXz7goCEk oWj8FTCW5ak98bLmlPS8M39fBTM6883huUiR2o2OTG0IUprf+o9MMW58JrB8kaJhjwBB rSmIX/EVnANSjwuReBISK8mk29tv18UFf44sovifAskP6YHXlmF7KPRbh6pOTYI3exrD nChhxdff6K0M4caV4KluMckdE/abpp0X3Y5PpHytyh1u/znF1JO4NbwVQG18nDDFWr+6 Lo85CQkuRy3rfW59Lh92dLP/q808AX5DHZAhfG+S4d3Dm5HvzM5xKlInnAIrtCEosfpt Gg5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EBasZC6YLIGG+8ebkH1QLdEFicqNV7dhlVlz53XQa0g=; b=m0sqEVtaL40WREaJLAnnSlOyo3lqX6ZyQ5ZbS998bukiaBjBYniU8tII/ZuOsf+NCG tkBS7m0bsRP4z+ed8oAzIh8xBBIZdhz4UGaabHJ7Knv1i5e7G7xLkAEaHStX+s8cMX55 6d7lHA8z4uo26JEfbTdeMkXRSCB2TdIPng/MaGn9bRNhSdUstSl/iVCq+30Pm2bMJzcu PrYN7rhDET6knJfGWIlsLueyaGomEauuyC0ogqiH+YXMCZZAcyhomCC+CBiNaPaaG0Za 5gaZvFavtKXhLTiYjdmJdTvKP4kShZBXiDfVycQe7NeNKhNFacGhcy7rjdG2GKdaxlT5 +klw== X-Gm-Message-State: AOAM53072suKadVpgNR2uJofMUazpe8Ppe/o9PZKLMz3/L52QLYSQUTd sF0wKDJ2M2dNuSOghniRYVEoKQ== X-Received: by 2002:a17:903:124b:b0:15e:84d0:ded6 with SMTP id u11-20020a170903124b00b0015e84d0ded6mr22605889plh.141.1652806078925; Tue, 17 May 2022 09:47:58 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id i7-20020a63cd07000000b003c14af5063esm8853588pgg.86.2022.05.17.09.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 09:47:58 -0700 (PDT) Date: Tue, 17 May 2022 16:47:54 +0000 From: David Matlack To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Lai Jiangshan , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH V2 5/7] KVM: X86/MMU: Remove the check of the return value of to_shadow_page() Message-ID: References: <20220503150735.32723-1-jiangshanlai@gmail.com> <20220503150735.32723-6-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220503150735.32723-6-jiangshanlai@gmail.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Tue, May 03, 2022 at 11:07:33PM +0800, Lai Jiangshan wrote: > From: Lai Jiangshan > > Remove the check of the return value of to_shadow_page() in > mmu_free_root_page(), kvm_mmu_free_guest_mode_roots(), is_unsync_root() > and is_tdp_mmu() because it can not return NULL. > > Remove the check of the return value of to_shadow_page() in > is_page_fault_stale() and is_obsolete_root() because it can not return > NULL and the obsoleting for special shadow page is already handled by > a different way. > > When the obsoleting process is done, all the obsoleted shadow pages are > already unlinked from the special pages by the help of the parent rmap > of the children and the special pages become theoretically valid again. > The special shadow page can be freed if is_obsolete_sp() return true, > or be reused if is_obsolete_sp() return false. > > Signed-off-by: Lai Jiangshan Reviewed-by: David Matlack > --- > arch/x86/kvm/mmu/mmu.c | 44 +++----------------------------------- > arch/x86/kvm/mmu/tdp_mmu.h | 7 +----- > 2 files changed, 4 insertions(+), 47 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 6f626d7e8ebb..bcb3e2730277 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -3318,8 +3318,6 @@ static void mmu_free_root_page(struct kvm *kvm, hpa_t *root_hpa, > return; > > sp = to_shadow_page(*root_hpa & PT64_BASE_ADDR_MASK); > - if (WARN_ON(!sp)) > - return; > > if (is_tdp_mmu_page(sp)) > kvm_tdp_mmu_put_root(kvm, sp, false); > @@ -3422,8 +3420,7 @@ void kvm_mmu_free_guest_mode_roots(struct kvm *kvm, struct kvm_mmu *mmu) > if (!VALID_PAGE(root_hpa)) > continue; > > - if (!to_shadow_page(root_hpa) || > - to_shadow_page(root_hpa)->role.guest_mode) > + if (to_shadow_page(root_hpa)->role.guest_mode) > roots_to_free |= KVM_MMU_ROOT_PREVIOUS(i); > } > > @@ -3673,13 +3670,6 @@ static bool is_unsync_root(hpa_t root) > smp_rmb(); > sp = to_shadow_page(root); > > - /* > - * PAE roots (somewhat arbitrarily) aren't backed by shadow pages, the > - * PDPTEs for a given PAE root need to be synchronized individually. > - */ > - if (WARN_ON_ONCE(!sp)) > - return false; > - > if (sp->unsync || sp->unsync_children) > return true; > > @@ -3975,21 +3965,7 @@ static bool kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, > static bool is_page_fault_stale(struct kvm_vcpu *vcpu, > struct kvm_page_fault *fault, int mmu_seq) > { > - struct kvm_mmu_page *sp = to_shadow_page(vcpu->arch.mmu->root.hpa); > - > - /* Special roots, e.g. pae_root, are not backed by shadow pages. */ > - if (sp && is_obsolete_sp(vcpu->kvm, sp)) > - return true; > - > - /* > - * Roots without an associated shadow page are considered invalid if > - * there is a pending request to free obsolete roots. The request is > - * only a hint that the current root _may_ be obsolete and needs to be > - * reloaded, e.g. if the guest frees a PGD that KVM is tracking as a > - * previous root, then __kvm_mmu_prepare_zap_page() signals all vCPUs > - * to reload even if no vCPU is actively using the root. > - */ > - if (!sp && kvm_test_request(KVM_REQ_MMU_FREE_OBSOLETE_ROOTS, vcpu)) > + if (is_obsolete_sp(vcpu->kvm, to_shadow_page(vcpu->arch.mmu->root.hpa))) > return true; > > return fault->slot && > @@ -5094,24 +5070,10 @@ void kvm_mmu_unload(struct kvm_vcpu *vcpu) > > static bool is_obsolete_root(struct kvm *kvm, hpa_t root_hpa) > { > - struct kvm_mmu_page *sp; > - > if (!VALID_PAGE(root_hpa)) > return false; > > - /* > - * When freeing obsolete roots, treat roots as obsolete if they don't > - * have an associated shadow page. This does mean KVM will get false > - * positives and free roots that don't strictly need to be freed, but > - * such false positives are relatively rare: > - * > - * (a) only PAE paging and nested NPT has roots without shadow pages > - * (b) remote reloads due to a memslot update obsoletes _all_ roots > - * (c) KVM doesn't track previous roots for PAE paging, and the guest > - * is unlikely to zap an in-use PGD. > - */ > - sp = to_shadow_page(root_hpa); > - return !sp || is_obsolete_sp(kvm, sp); > + return is_obsolete_sp(kvm, to_shadow_page(root_hpa)); > } > > static void __kvm_mmu_free_obsolete_roots(struct kvm *kvm, struct kvm_mmu *mmu) > diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h > index c163f7cc23ca..5779a2a7161e 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.h > +++ b/arch/x86/kvm/mmu/tdp_mmu.h > @@ -78,13 +78,8 @@ static inline bool is_tdp_mmu(struct kvm_mmu *mmu) > if (WARN_ON(!VALID_PAGE(hpa))) > return false; > > - /* > - * A NULL shadow page is legal when shadowing a non-paging guest with > - * PAE paging, as the MMU will be direct with root_hpa pointing at the > - * pae_root page, not a shadow page. > - */ > sp = to_shadow_page(hpa); > - return sp && is_tdp_mmu_page(sp) && sp->root_count; > + return is_tdp_mmu_page(sp) && sp->root_count; > } > #else > static inline int kvm_mmu_init_tdp_mmu(struct kvm *kvm) { return 0; } > -- > 2.19.1.6.gb485710b >