Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp978049iob; Fri, 13 May 2022 18:21:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2MpEp1bPQskMSSRjSsoRRBhR0U2Y83U7SpB/Rr7v6wr7gmde8Hiihv4v47gmBa+Q2gxzO X-Received: by 2002:a5d:4312:0:b0:20c:af5f:bdcf with SMTP id h18-20020a5d4312000000b0020caf5fbdcfmr6064816wrq.498.1652491311867; Fri, 13 May 2022 18:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652491311; cv=none; d=google.com; s=arc-20160816; b=bP55tpKHbaG8awxWBa2dt3qGXDPinSNYl5ME3k2NNFIbVKPdWydWI4rtZSI8wEszEG Cpjfs9kvuNB2XlxCuiU7WyPcCzv5xkffYGKbv9D4jRmnI/k3QFgDVFY1gHs+qTwbqnvt E3AOjxuS78aHTsnOLxh0EGFIin2y7H/BZXjrY4jcE8ciFUkorrJE2uBsolcSByyVHVLE noIamYvRsDBB6K/9brfIU/vV4DCTfmIZd/VgPSbpXl0dwWNJtmzToy9z0uk7rgQnkjiN IQTRlcORu8zSnpobvImS1/Z/NJWGK/Nm8qesW6Zpp7BzDTJYT8Efe3cmoWDBG9dHtkgn IqWg== 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=GQcrUD+iS10OWB2IhvHVYLyHQumXXSUypBIwcEyZKqA=; b=RE/v5XKR1N6XE7XBn8dk8Vxgqc3N4l60S+SS4ZnZKYElu0v3CsL/BCSOACW5NoC6Xl ei/F28JRKUW1WQm7ZGcDX0B8zsnzjkKNAgLMTV+84iPSKNqQ/6A1i2hGyxGaw25mx2VY 7iwNo7Z5KGkps45wLQyQw/FiIhyWWgjUcm/uZ3dBLW8ot2rc7nFEdBwGwVaZ+aWzik2X xtcOpHJN6B8RGOp7/D9Lawq8h0OgEl0doJBChLh7J0atigriokMeXZq97YvRGrQD6N17 rjVD6Xe7ehM9MmMBPW2d0qaog7WdkL2LOAcl50uBLnOwcpt8j+eZGYCx6l8U9ydOCv0n a/xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=hmGpvhMr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v16-20020adfe4d0000000b0020c7684a879si3147942wrm.298.2022.05.13.18.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:21:51 -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=@google.com header.s=20210112 header.b=hmGpvhMr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9FEC03CC5B2; Fri, 13 May 2022 16:51:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384898AbiEMWxN (ORCPT + 99 others); Fri, 13 May 2022 18:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233036AbiEMWxL (ORCPT ); Fri, 13 May 2022 18:53:11 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09CBB179080 for ; Fri, 13 May 2022 15:53:11 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id m12so9287581plb.4 for ; Fri, 13 May 2022 15:53:11 -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=GQcrUD+iS10OWB2IhvHVYLyHQumXXSUypBIwcEyZKqA=; b=hmGpvhMrmjZTe82jZGMH34s8ZMK8DhjPEZsAWOIQX9kjLF/JR9LLibbajKK2uSWBAV k7MAl1nQC1idFIml998Iqf/rm2g6m3cQEgWR5E+KPYi2/g0ady2z994cjhEJpIx1iGPR QpLYejtbBl7CTS1JQ0bl8F9YrlzAuGqHis3QNjm7uvX+78r1dB2QgxAxASqWX0gyfQLa qID4GVM+faLlv94xLNqQwFa20TwYQT2zjodjB00qnsZqgczQHzdNKQzpY96X/w4VEOQI hgxRO+mMyd9/kFJmj55nYOkqvt2QpcTsJ77Hyw8yOBRTdD0kKorFtKGmmtnbZD4NW2kc 12wQ== 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=GQcrUD+iS10OWB2IhvHVYLyHQumXXSUypBIwcEyZKqA=; b=4B4cpH/X2x6GizZbGt8eWTbg0Zg9cYfPh/rK91Wni7owkoFYEVRudZD9vEnAsAg5Iy JDFoY+2zpw1bFDZouUhf0L3KCSbDz500fox/Wfykq+0t8BbrAlSr0O48ySo7GlM+Cq2I /cHWP5lThl2LrDoN6NZW82T+BVn3VnrKxr4ZCmtGcuvm8zUR6pIuegJT/Egi23Dwis8d 6SZovbNLXuHweSc1BMbm9MS+eT4/0LcUaVTssJSm6tZqKHIu+bRlfoIH9PGmT0lC+hK9 XVLwj7DXbOUbK4mbYONfwrdM4ozLMFtGQMgrLdF+RffF5+T8WZFmLfSvnmH66XjPeIk4 G9rg== X-Gm-Message-State: AOAM531HdLZBMOq9DBXht/bzMmWNH9JjZre1tg2JemHqjyMiodeoUp0J qRib7OSTqE2s36ITon4SMdDfWw== X-Received: by 2002:a17:90b:3445:b0:1d6:91a5:29fe with SMTP id lj5-20020a17090b344500b001d691a529femr18230208pjb.138.1652482390246; Fri, 13 May 2022 15:53:10 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id b10-20020a170902650a00b0015e8d4eb269sm2289156plk.179.2022.05.13.15.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 15:53:09 -0700 (PDT) Date: Fri, 13 May 2022 22:53:05 +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 1/7] KVM: X86/MMU: Add using_special_root_page() Message-ID: References: <20220503150735.32723-1-jiangshanlai@gmail.com> <20220503150735.32723-2-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220503150735.32723-2-jiangshanlai@gmail.com> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 On Tue, May 03, 2022 at 11:07:29PM +0800, Lai Jiangshan wrote: > From: Lai Jiangshan > > In some case, special roots are used in mmu. It is often using > to_shadow_page(mmu->root.hpa) to check if special roots are used. > > Add using_special_root_page() to directly check if special roots are > used or needed to be used even mmu->root.hpa is not set. > > Prepare for making to_shadow_page(mmu->root.hpa) return non-NULL via > using special shadow pages. > > Signed-off-by: Lai Jiangshan > --- > arch/x86/kvm/mmu/mmu.c | 14 +++++++++++--- > 1 file changed, 11 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 909372762363..7f20796af351 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -1711,6 +1711,14 @@ static void drop_parent_pte(struct kvm_mmu_page *sp, > mmu_spte_clear_no_track(parent_pte); > } > > +static bool using_special_root_page(struct kvm_mmu *mmu) Could you enumerate all the scenarios that use special roots and which roots are the special ones? I think that would help a lot with reviewing this series and would be useful to encode in a comment, probably above this function here, for future readers. Also the term "special" is really vague. Maybe once you enumerate all the scenarios a common theme will arise and we can pick a better name, unless you have any ideas off the top of your head. > +{ > + if (mmu->root_role.direct) > + return mmu->root_role.level == PT32E_ROOT_LEVEL; > + else > + return mmu->cpu_role.base.level <= PT32E_ROOT_LEVEL; > +} > + > static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, int direct) > { > struct kvm_mmu_page *sp; > @@ -4241,10 +4249,10 @@ static bool fast_pgd_switch(struct kvm *kvm, struct kvm_mmu *mmu, > { > /* > * For now, limit the caching to 64-bit hosts+VMs in order to avoid > - * having to deal with PDPTEs. We may add support for 32-bit hosts/VMs > - * later if necessary. > + * having to deal with PDPTEs. Special roots can not be put into > + * mmu->prev_roots[]. > */ > - if (VALID_PAGE(mmu->root.hpa) && !to_shadow_page(mmu->root.hpa)) > + if (VALID_PAGE(mmu->root.hpa) && using_special_root_page(mmu)) > kvm_mmu_free_roots(kvm, mmu, KVM_MMU_ROOT_CURRENT); > > if (VALID_PAGE(mmu->root.hpa)) > -- > 2.19.1.6.gb485710b >