Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp283786imn; Mon, 25 Jul 2022 16:32:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vk0bBlMzDse0fdx/wq/lBOzvPKdEXDWtLU5ue2vW9UPaTds5Ez/HqKcU/Tqs4sMypLSykn X-Received: by 2002:a17:902:7285:b0:16c:ce55:9dba with SMTP id d5-20020a170902728500b0016cce559dbamr14129469pll.156.1658791935302; Mon, 25 Jul 2022 16:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658791935; cv=none; d=google.com; s=arc-20160816; b=oGLoHHDnwsNnrca2l/zhJjm//f0R4bbM4hRIV88gmiWa6sXdZcEsTtGPY+czYP52gE BAIKbbkgL0oR90fpc1OSkWJ4tMMQnuk+KyW4RMFoRhBjFYMBbZNDMCt08ckGd6e/+7j3 iVlUxgPMHTxzppbF6lT8pPOASKsj+apUWiSrZPmYN2+110ZJlbrrL7jsN3cbDiJKK/ij 6K8u9UF5eMuyKZlx907yAEuMu2KMVpsuS46yYTrGUWfqOEQneYvvywS9U5Tx1Eja8oqM 8J12z4splYNsz5pCqPgdt9iWTDgnGgyqAmu0mClWn3aoRjr9psGhbE1Z/hQeeD5Aa1ib In/Q== 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=QOC9FutRXycysZcNDNb8yY3ROXU2xsC5EASisQKUw28=; b=WTY1DkyMk5PdVTw+lgWZkvSEFZLyW14sVsWhenEjZ/XWvut4tAMxC9l8womnES4qht jFSehp+HIGi6BSueAsIwz+U2PA8fAb+EHCCb7gxAs4SghFhrFRDHd4Bty0uWC+qNZCAR C84HaTsz7dkexO4H4rD2JJqgo6B/D5Kq1tihWj+SEXqCYx+f9iY9dNOni1AQhtWJ6C9m oux1QNzNxn67KneDr5eNZpF3Vg9PR2xPuNyScuWnanzIvd3pppiTU9k+0KlDlrPun3mR rGWMOLkhZve3xG5642BnakcXhNb1NZAJok+UunTwvgETCMSWnXm3xxsDE9izF6eYHD3O r+gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HX26puFi; 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 y5-20020a056a00180500b0052592bbcb5bsi18917060pfa.13.2022.07.25.16.32.00; Mon, 25 Jul 2022 16:32:15 -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=HX26puFi; 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 S237624AbiGYXYB (ORCPT + 99 others); Mon, 25 Jul 2022 19:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237355AbiGYXX7 (ORCPT ); Mon, 25 Jul 2022 19:23:59 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7E4320BD5 for ; Mon, 25 Jul 2022 16:23:58 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id y24so11773245plh.7 for ; Mon, 25 Jul 2022 16:23:58 -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=QOC9FutRXycysZcNDNb8yY3ROXU2xsC5EASisQKUw28=; b=HX26puFihhU88Ii05Usra+lh8D0UTysdNaR016h0JmdhviKtRUcH2ZCbfwgZQC7APZ Oaw2Noa92Rxqw+hu5YDDjSd1cKFw7ajbEThpmAiNxkFcN2jHTDNXCSxdFfjGVQjc4yKn /jxb66jnsbAFiNlGoirxA0xEuxN3FKRSpvcFWG2XxXJFj+BoFgGaA7G97js7GpqoBf8Q twoCn5V/917VYazyO1nsxlqvkuct5ktRz9TPcu122uAo7dLFWh+kt6tj9DWxyh7UTNAf bXmXdDDQ34NxBh9G/mY5dx04+3EklNmmVN4dw99oIYy/27CJ4POG/hcRJy3ASOX5eItO /3jg== 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=QOC9FutRXycysZcNDNb8yY3ROXU2xsC5EASisQKUw28=; b=C9Y8/HtYDbxsHfVjPmuo+dq20IP1HTj6eFMXbAxDaM+au9KzjGxpRI9B761QpicB6d 3EIPzNjzLcbJsUqoIbEOlqMkVHQMaS8svNzVSqPAsjzuloC1jUK3nuzCevCeDSBGvd0v di5A/R5S17qf4qwYkb1Bd6rRTFdh3wVSxTn/63mZpFxOHLaFeSI1Y4NVOBHFY1dFm+IU kltBXwYRS8MgbT3h82HrHdjlPNLIrKX6ffKK7o/DKuG5zC6NE/9WlSTxoBLjQBfiXy2u LTA7r7r/paWyBd2cvVLjBccRf+h3bHqT09oVu+T66WuG0n9jGA57fR7/sB8JTvDJi7N3 aAog== X-Gm-Message-State: AJIora8fjAoSxOZ31TpcXkW+Twt5zrb18onn/pKbiZzg62qdNPaDSidy yAMDnx17pDsj57/4FWwfS9HrWA== X-Received: by 2002:a17:90a:4291:b0:1f2:2a19:fc95 with SMTP id p17-20020a17090a429100b001f22a19fc95mr27990421pjg.29.1658791437974; Mon, 25 Jul 2022 16:23:57 -0700 (PDT) Received: from google.com (223.103.125.34.bc.googleusercontent.com. [34.125.103.223]) by smtp.gmail.com with ESMTPSA id y20-20020a170902e19400b0016c35b21901sm9669785pla.195.2022.07.25.16.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 16:23:57 -0700 (PDT) Date: Mon, 25 Jul 2022 16:23:52 -0700 From: David Matlack To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , Mingwei Zhang , Ben Gardon Subject: Re: [PATCH v2 5/6] KVM: x86/mmu: Add helper to convert SPTE value to its shadow page Message-ID: References: <20220723012325.1715714-1-seanjc@google.com> <20220723012325.1715714-6-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220723012325.1715714-6-seanjc@google.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 On Sat, Jul 23, 2022 at 01:23:24AM +0000, Sean Christopherson wrote: > Add a helper to convert a SPTE to its shadow page to deduplicate a > variety of flows and hopefully avoid future bugs, e.g. if KVM attempts to > get the shadow page for a SPTE without dropping high bits. > > Opportunistically add a comment in mmu_free_root_page() documenting why > it treats the root HPA as a SPTE. > > No functional change intended. > > Signed-off-by: Sean Christopherson > --- [...] > --- a/arch/x86/kvm/mmu/spte.h > +++ b/arch/x86/kvm/mmu/spte.h > @@ -207,6 +207,23 @@ static inline int spte_index(u64 *sptep) > */ > extern u64 __read_mostly shadow_nonpresent_or_rsvd_lower_gfn_mask; > > +static inline struct kvm_mmu_page *to_shadow_page(hpa_t shadow_page) > +{ > + struct page *page = pfn_to_page((shadow_page) >> PAGE_SHIFT); > + > + return (struct kvm_mmu_page *)page_private(page); > +} > + > +static inline struct kvm_mmu_page *spte_to_sp(u64 spte) > +{ > + return to_shadow_page(spte & SPTE_BASE_ADDR_MASK); > +} spte_to_sp() and sptep_to_sp() are a bit hard to differentiate visually. Maybe spte_to_child_sp() or to_child_sp()? > + > +static inline struct kvm_mmu_page *sptep_to_sp(u64 *sptep) > +{ > + return to_shadow_page(__pa(sptep)); > +} > + > static inline bool is_mmio_spte(u64 spte) > { > return (spte & shadow_mmio_mask) == shadow_mmio_value && > diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h > index c163f7cc23ca..d3714200b932 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.h > +++ b/arch/x86/kvm/mmu/tdp_mmu.h > @@ -5,6 +5,8 @@ > > #include > > +#include "spte.h" > + > hpa_t kvm_tdp_mmu_get_vcpu_root_hpa(struct kvm_vcpu *vcpu); > > __must_check static inline bool kvm_tdp_mmu_get_root(struct kvm_mmu_page *root) > -- > 2.37.1.359.gd136c6c3e2-goog >