Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3506269iob; Tue, 17 May 2022 01:15:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyG0sS8bcvxfc/ZeedlEOXQWDiqwITFvelsIuj0TTxz4q+oP0KIaA7021EGvNN0MvbHS9Ie X-Received: by 2002:a17:903:2411:b0:161:39ef:57f7 with SMTP id e17-20020a170903241100b0016139ef57f7mr18209208plo.136.1652775300175; Tue, 17 May 2022 01:15:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652775300; cv=none; d=google.com; s=arc-20160816; b=DB+PDCDRRTgE6ycxINqog4oHsUMbeoJEvTXCzgi9+w/hECfSXftgXWe3WOuU73fSd/ 76XNJSgduNNy/72zoQ5kvdNclJLdmYA6M3RqNDfnta+o2uIIH63QwDJR7yImF5PflifG 4US5Clkgnb3uwVH2Yr+SiNKxZszvgZTWlklTIGRblWHZdVAcbRspcRvUNzEYVNK3lnQp ncU9a/YuA1ENbIXxmvfMZIlW/YeNu5EzT6LKzLjfaALlEDZp+ah/ecdbyeSChD7w7zRN ADQiHmw1F/7OXrAv1QddpEInbSX5zyND97YS68zWvObUSh60pCbSJyn1m6Jc6x0MJpwM ekMw== 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=IX2wmwvaDyZMh7ib5ZKuwhVkKDHyhdCDkN7AoejMd14=; b=G3o6Md5nTMfumm6wbMSPyujrrMN/Xp9z6+aEaoNNpvKTUEM+My+/bKqV9TOqBqZkZu nF4BMCitVkjrrjCyUqvnFC5NmVhd9fuY/Y0ybSlI2BybYnVtuOKw468FUU3NGUuiPAuj qhEtXqV+gDcFVDcvgrVH7kp2NWX7XmDcqqG+R0y3xRS3onhDwb90+C9xsc+8sf/uQyYC CQgdgAfae7ouBSmXkIavblTF5J+i2Ue7zkOv4ONcX7A57jNjDakhZR/sbs52wWaIDaI6 ugC2dOdejUZ4jMw85TXzsjwvVx8kOw5ilt0DhhtXixV2TuSifbOhDnugkwFQJC5PugXf xi7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QO4M1yV2; 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 x36-20020a056a0018a400b0050cfb4ff72dsi18242695pfh.52.2022.05.17.01.14.48; Tue, 17 May 2022 01:15:00 -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=QO4M1yV2; 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 S1350503AbiEQABb (ORCPT + 99 others); Mon, 16 May 2022 20:01:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238584AbiEQABX (ORCPT ); Mon, 16 May 2022 20:01:23 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B70A3FBC1 for ; Mon, 16 May 2022 17:01:22 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id p8so15439724pfh.8 for ; Mon, 16 May 2022 17:01:22 -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=IX2wmwvaDyZMh7ib5ZKuwhVkKDHyhdCDkN7AoejMd14=; b=QO4M1yV2IkKeIohfCfSn9H3sUzERCQ1hJGTky+xBqF2Rgc4HUQud/A0HZ5mhCRjOC9 X9PJy3n49zrIzWH5CF1gyUvkBMCgbhctRGm/yJl1gIn2Z9Nib3jcV5NaP4iSz9XhATB/ lUnlNNq5VqtrQ7JBDpM9kerEriKcO1fQSh6nNcaNjZaFoKMG0/4d1q6sPxPy6MqgLGFp K/xv4+vuwxaUGTBLDO3AjcPw0k5uMJxmdbA40w0uaCdxttoP35ebrshjn4E7LQPGsJ8I uqkXOlz+jnD1NMvb95PKCI0MDx/uY/+LaOTkepYltMJWWdcD7FOj6IeB14TRA0Bs9m6i NUZw== 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=IX2wmwvaDyZMh7ib5ZKuwhVkKDHyhdCDkN7AoejMd14=; b=4mZ9wVq7x81RWWx/5TzErvDTcO6u2W/w2f1ksnl1KumcCua6q1Ybj20o08J0DD2xM/ R0oc5oWQwsFFzAq2CEh7E/A9j7zn/riwBtfrbO3nH9XlQ8AnTPShuXI/BTHGDFo7eVFj YknKd7DEm4WDE1wTAa8/M5Ix0KiQKtr1ugu2QzzSO+6irmrbr0cG5A+ocV0rqFIVAC0f u6VJC+XD/Qz21UyO28YuSxCqhKA+09UqRFNvkYTl/4TC1GzQQuKl4YXyOq6JDmiTEuj8 phbws4U7LE73qYqidqGbbD7B3ANHPlnnqswhqXj0otLic/ggddrO3dNDwO0ikKCO6ZDr rwKA== X-Gm-Message-State: AOAM530BZP2KhJJnbbFwBhA6300rm188wuDnQKcaBBjYC/wTf/mlKw6P 0CKf2jsqk4qRhKEX/t0H5Gbx9w== X-Received: by 2002:a05:6a00:23c6:b0:50f:f570:7ea7 with SMTP id g6-20020a056a0023c600b0050ff5707ea7mr19962149pfc.76.1652745681364; Mon, 16 May 2022 17:01:21 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id i13-20020a170902eb4d00b0015e8d4eb1b9sm7781773pli.3.2022.05.16.17.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 17:01:20 -0700 (PDT) Date: Tue, 17 May 2022 00:01:17 +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 3/7] KVM: X86/MMU: Link PAE root pagetable with its children Message-ID: References: <20220503150735.32723-1-jiangshanlai@gmail.com> <20220503150735.32723-4-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220503150735.32723-4-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=ham 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:31PM +0800, Lai Jiangshan wrote: > From: Lai Jiangshan > > When special shadow pages are activated, link_shadow_page() might link > a special shadow pages which is the PAE root for PAE paging with its > children. > > Add make_pae_pdpte() to handle it. > > The code is not activated since special shadow pages are not activated > yet. > > Signed-off-by: Lai Jiangshan > --- > arch/x86/kvm/mmu/mmu.c | 6 +++++- > arch/x86/kvm/mmu/spte.c | 7 +++++++ > arch/x86/kvm/mmu/spte.h | 1 + > 3 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 126f0cd07f98..3fe70ad3bda2 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2277,7 +2277,11 @@ static void link_shadow_page(struct kvm_vcpu *vcpu, u64 *sptep, > > BUILD_BUG_ON(VMX_EPT_WRITABLE_MASK != PT_WRITABLE_MASK); > > - spte = make_nonleaf_spte(sp->spt, sp_ad_disabled(sp)); > + if (unlikely(sp->role.level == PT32_ROOT_LEVEL && > + vcpu->arch.mmu->root_role.level == PT32E_ROOT_LEVEL)) > + spte = make_pae_pdpte(sp->spt); > + else > + spte = make_nonleaf_spte(sp->spt, sp_ad_disabled(sp)); > > mmu_spte_set(sptep, spte); > > diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c > index 75c9e87d446a..ccd9267a58ca 100644 > --- a/arch/x86/kvm/mmu/spte.c > +++ b/arch/x86/kvm/mmu/spte.c > @@ -251,6 +251,13 @@ u64 make_huge_page_split_spte(u64 huge_spte, int huge_level, int index) > return child_spte; > } > > +u64 make_pae_pdpte(u64 *child_pt) > +{ > + /* The only ignore bits in PDPTE are 11:9. */ > + BUILD_BUG_ON(!(GENMASK(11,9) & SPTE_MMU_PRESENT_MASK)); > + return __pa(child_pt) | PT_PRESENT_MASK | SPTE_MMU_PRESENT_MASK | > + shadow_me_value; If I'm reading mmu_alloc_{direct,shadow}_roots() correctly, PAE page directories just get: root | PT_PRESENT_MASK | shadow_me_value. Is there a reason to add SPTE_MMU_PRESENT_MASK or am I misreading the code? > +} > > u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled) > { > diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h > index fbbab180395e..09a7e4ba017a 100644 > --- a/arch/x86/kvm/mmu/spte.h > +++ b/arch/x86/kvm/mmu/spte.h > @@ -413,6 +413,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, > u64 old_spte, bool prefetch, bool can_unsync, > bool host_writable, u64 *new_spte); > u64 make_huge_page_split_spte(u64 huge_spte, int huge_level, int index); > +u64 make_pae_pdpte(u64 *child_pt); > u64 make_nonleaf_spte(u64 *child_pt, bool ad_disabled); > u64 make_mmio_spte(struct kvm_vcpu *vcpu, u64 gfn, unsigned int access); > u64 mark_spte_for_access_track(u64 spte); > -- > 2.19.1.6.gb485710b >