Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp142432iob; Tue, 17 May 2022 21:40:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbeIAWUVfQqM1k8gFZzkIug5hTuVSw0T2rGmzfvZCMiuL9YA/oerhM8Q6KdyLn3UuFx6MU X-Received: by 2002:aa7:949c:0:b0:518:16a3:6a26 with SMTP id z28-20020aa7949c000000b0051816a36a26mr2567125pfk.13.1652848853254; Tue, 17 May 2022 21:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652848853; cv=none; d=google.com; s=arc-20160816; b=H27a6ae9ylbDl6W73B0bK7TrjVbMWfPP3GVujtfT5zsJ7E6idkTYBLbUXjFEwQz+O+ Ft0Ieu9SSliDRJ0CtUKUEaxiLPOCApftMnNlyMSOXfYtJBTR3RXrP4swo+5gup5M7CTB HDjMSoECu43nVfDod5MnYky+uhaQ+WiK7u/eVwmCiJ28cq7TKOxBlTrvPoKij4awriXq g5KaacnofFwdyMDBqzB6VnUPmOY3Dslgq1xrwahphKJ4haIOPfLQkAdch8t63CdMSi8P iwUFbmWytiAKF4zZNNxu/TPBaNorn38/sJAbbopcdZ3Tmrc67xB9DWP8RF/tGxF3H5ZJ K0Kw== 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=UAaK0aU2k1qQWWA1NGAVdax/L+mO0Yx8sa53VfFr0E0=; b=XOFAOsbIyQoF6VGm49PAWBLEvi9eG7XTWo0WXcw/nYDh0IceROEuGRlkOiV3nvRfgD iSZ7iKElMVGrQNxwcrdFM6hkM4joUDVolvKATqXIWODL69mrcuLCsqdJmm1mYf6uQLMm XXARjH3fjvTJbod3fBf2hrD4dtW5OheW2LUJRFbCDHrGOl5F7SEksBAaKpa0hRTILcxE vcC/dWVtmykYsO0yRHlRk2gxdVvBtHbevPwCFsInQ5/lFSm8qsPM0L7S/EDHCrGrkPQS hElSrdNUmrMHYIRb/L3ksXpr5Rht77J/XwFEZ9nPhE6XnqNTTN1Xm/44tI0s2VrRcEbA 8oQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FAg0TouX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 67-20020a630746000000b003f5e581cd89si1060703pgh.833.2022.05.17.21.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 21:40:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FAg0TouX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 B43CA3A9; Tue, 17 May 2022 20:56:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351034AbiEQQmJ (ORCPT + 99 others); Tue, 17 May 2022 12:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242619AbiEQQmG (ORCPT ); Tue, 17 May 2022 12:42:06 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A1B3FD93 for ; Tue, 17 May 2022 09:42:05 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id s68so882962pgb.13 for ; Tue, 17 May 2022 09:42:05 -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=UAaK0aU2k1qQWWA1NGAVdax/L+mO0Yx8sa53VfFr0E0=; b=FAg0TouXgjpk19jvVBTpS2yi0HzoIqR5b71b+PMKbwpZMPO1LZuzVCe6EPm3a5bf2v fbkXVBiZV3TOhPvfJAuAFYvSLRndrHQfQ5j9leSEEt+ykDBiFbuwbZuYBNdSvm/WCtcV 4NJAmUPPZEXXatIF9oal5vnGZW+3qSjbzPslrTO2NwswDDhykcQ5dAZg9vq5LUgqdna8 Ic4mhJj3ws2m0H7Mg85/Nqf/7UzLcn7QcqxrwY6Z8TZ1yC0mCWalS7N/mUyc02Aaf5MN EonoD/leoWhq/NP4bLZK5VS360YZhsvG9+qln6ggH/W9TTnTg/Jfbwmzr0ea1XnjG8ez /AAQ== 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=UAaK0aU2k1qQWWA1NGAVdax/L+mO0Yx8sa53VfFr0E0=; b=2a2FGU8S8CifOCpEuPqXRnBIxMCGmcWTyMnqonONkTO3ZMqegvYWOQlst3QKHugDmE q2/TzHGZvwri4s5xgTazFORjNHYiXorQ3Mqeb6UW2q1P9muUNV/42xCpwBHDS9YYQ9Pe Cun9lVaPY/Pp6HnEg0Lno3hsrSVRRUALAnZmBv4MV2Ve3iLqJr9sPpl+tezLNRzl9BvE a12IZdAnRwZbu5Zl1pC7yhuj61KIgttegOq7kR4makFmupmNsLmQzUDe/kgdLbfTRHWL 3nrBxgxbm76RPFiIuRgoudq2XGV3d+TbqThX2G6gbQjEr3EBvEfV2lhc50Tk92hz7L80 fnpQ== X-Gm-Message-State: AOAM532YoaHYwHWt23TLmV/WgjXQSzSMQviTD/ryMJ0GF62FB5zYfBwb Pp002+QrDnW3w1fUW0aC/qL65A== X-Received: by 2002:a63:43c2:0:b0:3c1:829a:5602 with SMTP id q185-20020a6343c2000000b003c1829a5602mr20449743pga.252.1652805724330; Tue, 17 May 2022 09:42:04 -0700 (PDT) Received: from google.com (254.80.82.34.bc.googleusercontent.com. [34.82.80.254]) by smtp.gmail.com with ESMTPSA id j15-20020a170903024f00b0015eee3ab203sm9562937plh.49.2022.05.17.09.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 09:42:03 -0700 (PDT) Date: Tue, 17 May 2022 16:41:59 +0000 From: David Matlack To: Lai Jiangshan Cc: LKML , "open list:KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips)" , Paolo Bonzini , Sean Christopherson , Lai Jiangshan , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "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: 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 17, 2022 at 09:13:54AM +0800, Lai Jiangshan wrote: > On Tue, May 17, 2022 at 8:01 AM David Matlack wrote: > > > > 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? > > Because it has a struct kvm_mmu_page associated with it now. > > sp->spt[i] requires SPTE_MMU_PRESENT_MASK if it is present. Ah of course. e.g. FNAME(fetch) will call is_shadow_present_pte() on PAE PDPTEs. Could you also update the comment above SPTE_MMU_PRESENT_MASK? Right now it says: "Use bit 11, as it is ignored by all flavors of SPTEs and checking a low bit often generates better code than for a high bit, e.g. 56+." I think it would be helpful to also meniton that SPTE_MMU_PRESENT_MASK is also used in PDPTEs which only ignore bits 11:9. > > > > > > +} > > > > > > 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 > > >