Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4885299imw; Tue, 19 Jul 2022 15:28:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7b+o8kj378bC0s935Ieua+C3JsEwDDJBYPDnlGhBIqVz5dci5hAWIdmOtalvu6cjbNFgy X-Received: by 2002:a17:90b:4f41:b0:1f0:4785:b9a8 with SMTP id pj1-20020a17090b4f4100b001f04785b9a8mr1727738pjb.224.1658269730247; Tue, 19 Jul 2022 15:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658269730; cv=none; d=google.com; s=arc-20160816; b=buwK/zUQWnKIdmWZlEyoEUiV+uWOX7mKzkeYL222FXFJAB+nRp9BjK3cA1S3SW70aX i7b3T7lMN2PZuWYVmUI07BJ4D/US+Echul1kkSFh14+wfbz/ppzEmHb2Mb5p0noHdBPW 4ir/uG34J8amO6XziL+G8s8wE6QA9KmPOnz+6Essrw/ezCmS3nb3++SlLqLUPh5LU/P0 FGVUAxGXlU9pAzIAtH0Kv0d7U3RP1f7iCpUmYaP4fHhj2+1JX5e32h55PRyV7R6j56t6 w3LodAlVJQs1Wles/u3zwya2zl2fNGX7A3ClQrFUf76k6SVjywOCa4CCWmU6CETnIFk5 AUOQ== 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=jwz2xPBcsSUvi6UQz2aVRRre7pThVfHLQu+ABQPNNpM=; b=sdyQMdUQfxVCQpzwMQcrPKYHTLtxOyUlejptegBZZtGVDlbBYj/S7HWURmyZTL1XRx 4+CNSYileigDBWUl2V5NLSih1Dg2vUtdx4CXS0UWl6nwvXXeADjgDIuKu0MKsftL+nxO Ge8PqE1PCQnLugv1OrqSVKgZnZbPPAibrvmAhZ/OnUKrdhze/vYavHMvpMr2p1xDghDE K+bE/gL05WZVftFVWFzlly6IaEgbq5nd87wZ9wM+01TfuGaWVGkjrvZU8abDehl7pIHv QMGJqEsPAlTNsEpH4JdJk+8zAN3sNPiqP0TmFUc4AetT4eFH4mb0IHFzprFKGMHBIuzP 1Jjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bvlVC+TD; 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 j17-20020a170902da9100b0016a3b4745c2si22198758plx.93.2022.07.19.15.28.35; Tue, 19 Jul 2022 15:28:50 -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=bvlVC+TD; 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 S239296AbiGSWVq (ORCPT + 99 others); Tue, 19 Jul 2022 18:21:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231495AbiGSWVn (ORCPT ); Tue, 19 Jul 2022 18:21:43 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B83BF57214 for ; Tue, 19 Jul 2022 15:21:42 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id c3so13980265pfb.13 for ; Tue, 19 Jul 2022 15:21:42 -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=jwz2xPBcsSUvi6UQz2aVRRre7pThVfHLQu+ABQPNNpM=; b=bvlVC+TDi6T2/b4/pLOrdrFYGLJavot6uN0VC38WaAa3VaW3zaRwWf0gdFGQMpJbak 96TWnRjxQnbhbdZlSvBUqo1Byt+wnG1f6xVDoOZ5jTxnFgGC7/goofWz7QxxpE9MrUUu 3MAD4vePMasYcKhPf5CPGxQPtS1ADhXACzf7vdnce4deuyM0ovvPojN5om6EIQiwq8FM TR/MkL13E92UYGG6nzxdVQjK7E6SC7efPQhO+iuziOnyMscb7rDTFklxqekPF3oq8pqA TocrVBZ8BAH2zcKnPrAWu4zilccRa0VfLpgkpuu8lVGwSTv7DDaJ+Pli6amJ5E+71iXP N8Tw== 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=jwz2xPBcsSUvi6UQz2aVRRre7pThVfHLQu+ABQPNNpM=; b=6RA5sZ1pFzXbR4O8pBF8IBIF5SX93TFZDKPxx7kN8lxSSMOuuItIFa+yh4+nyMIDto QEsx3Bwmjx0/0UpkG0PyK5iMGvAau82hny5BDHusujl7viFMybZ0k/34Hcu4PD6Cy7R8 qU4imDeTcMtSkT+2fKlVf6XcEvhRxbHcS8m0IQq3oLm6Dz7jmIiSMc4bpwsrzcZfWSvm yK8tvk3DvV9dYdOw9zWQTyxJl84cbBObnfpBwdBsNlE8sN4ISHpnnoPF8zFKLBSdTRy7 GznIrbc1MqqzcprHFyAAnZMn/f1QL5DIlAQxYf25a8BGrx+U1wHl6IUMoLmAv0RfquWB yXJQ== X-Gm-Message-State: AJIora/5CEyejed6KO5Yor9oK/rVSinivusOrEYL73rxD6DqNM+xf4kS RZwvOxj9eZ65i+83rG2OC8VWRjUD7xutrg== X-Received: by 2002:a05:6a00:e8f:b0:528:a1c7:3d00 with SMTP id bo15-20020a056a000e8f00b00528a1c73d00mr34920341pfb.25.1658269302103; Tue, 19 Jul 2022 15:21:42 -0700 (PDT) Received: from google.com (123.65.230.35.bc.googleusercontent.com. [35.230.65.123]) by smtp.gmail.com with ESMTPSA id f15-20020aa7968f000000b00528c22fbb45sm12215669pfk.141.2022.07.19.15.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 15:21:41 -0700 (PDT) Date: Tue, 19 Jul 2022 22:21:38 +0000 From: Sean Christopherson To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Maxim Levitsky , David Matlack , Lai Jiangshan Subject: Re: [PATCH V3 05/12] KVM: X86/MMU: Link PAE root pagetable with its children Message-ID: References: <20220521131700.3661-1-jiangshanlai@gmail.com> <20220521131700.3661-6-jiangshanlai@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220521131700.3661-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, 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 The shortlog is very misleading. This patch doesn't "Link PAE root pagetable with its children", it adds support for creating PAE PDPTEs in order to link them into shadow pages, but it doesn't do the actual linking. KVM: x86/mmu: Add support for linking PAE PDPTE shadow pages On Sat, May 21, 2022, Lai Jiangshan wrote: > From: Lai Jiangshan > > When local shadow pages are activated, link_shadow_page() might link > a local 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 local shadow pages are not activated > yet. And though it's redudnant with other context, IMO it's helpful to again reiterate why this will be used for per-vCPU (local) shadow pages, i.e. why it's _not_ used right now. Add support for installing PDPTEs via link_shadow_page(), PDPTEs have different layouts than every other entry type and so need a dedicated helper to make them. This code will become active when a future patch activates per-vCPU shadow pages and stops using so called "special" roots (which are installed at root allocation, not via link_shadow_page()). > 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 c941a5931bc3..e1a059dd9621 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -2340,7 +2340,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 b5960bbde7f7..5c31fa1d2b61 100644 > --- a/arch/x86/kvm/mmu/spte.c > +++ b/arch/x86/kvm/mmu/spte.c > @@ -279,6 +279,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. */ s/ignore/ignored, though it might be worth calling out that unlike 64-bit paging, the upper bits bits are reserved (I always forget this). /* * Only PDPTE bits 11:9 are ignored by hardware. Unlike 64-bit paging, * bits above the PA bits are reserved. */ > + BUILD_BUG_ON(!(GENMASK(11,9) & SPTE_MMU_PRESENT_MASK)); > + return __pa(child_pt) | PT_PRESENT_MASK | SPTE_MMU_PRESENT_MASK | > + shadow_me_value; > +} > > 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 0127bb6e3c7d..2408ba1361d5 100644 > --- a/arch/x86/kvm/mmu/spte.h > +++ b/arch/x86/kvm/mmu/spte.h > @@ -426,6 +426,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 >