Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp285574imn; Mon, 25 Jul 2022 16:36:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tzefNQJvBp288ow7w+IafUCs+62pR0Q3/Vo7G3L3uvEOihWz8hi1p8YeWHEldcI4vxt3xC X-Received: by 2002:a17:902:b593:b0:16c:4d8a:c8b0 with SMTP id a19-20020a170902b59300b0016c4d8ac8b0mr14983775pls.9.1658792176488; Mon, 25 Jul 2022 16:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658792176; cv=none; d=google.com; s=arc-20160816; b=FBVxO4jtjWU7KzN8a1mhmJnUlon7I21trwQYObFqPvyjQxXJ9nI/jQW30OvJgxZaV1 XkWJF7GpWeMo/zLqeq3KLSRgjJxRS49eWj/HvFRPUH8ZPz4AMS5Jg8umtt2HDF3PTImS 6POFglxg7jf61NLC+GJbHVWnLC3m4pRqM1pEs/L9wWbXYzK1rFuq95/glxpxSJhNfgE/ igD4Heu6k8Mxbkah3RpHRez494Da4Bz+29Vy5EmNLMBYb9jBc6d9mIpDeSSFXtmbq0sn hVBANKrVr48UGJ0rqB8c6XJVccDQ43S5bBfeTbVMP750TPCVp5H3jhKkwXLdsslhBpXS wefA== 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=ZQyRxqGM1W/LS0ssRps7WJXXzo4kRUKS7bNZtUe51CI=; b=dAULzZAjROY4Hp929P4flk7ig0E66ha8tXQCm2IxOrDrAE9krWaIdANv6ibIcBjBx0 8bBUWJUEXng7l4XBPhOmK7M76+1YF6CRgrwWdj1RllKpio6OY8MUKw8iAqe/90TGEszq SJkdW2ho4EfGSv96P/pgxI2Tna02lHFMP51qSYuWKL11DHgVzR3AtQrfxJXFLiSkS9DM 0XwK1mVYnkMUIwdIXTg1ppVFTPiBKZY5zcUzI3vHj8P40/QAt1CXMQAhWJUfD9JY4a7o KuNiqOn8DNllfksVKNPJK8K13eW44vIbwJaSL9Ej1VoxkNeru/Iw9QdpR2Nb1fpJ3e/E IuIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nD1BmdVc; 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 mq11-20020a17090b380b00b001e4dad046dcsi22791061pjb.179.2022.07.25.16.36.00; Mon, 25 Jul 2022 16:36:16 -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=nD1BmdVc; 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 S231801AbiGYXfM (ORCPT + 99 others); Mon, 25 Jul 2022 19:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237424AbiGYXdT (ORCPT ); Mon, 25 Jul 2022 19:33:19 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7943926AF9 for ; Mon, 25 Jul 2022 16:33:17 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 6so11662663pgb.13 for ; Mon, 25 Jul 2022 16:33:17 -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=ZQyRxqGM1W/LS0ssRps7WJXXzo4kRUKS7bNZtUe51CI=; b=nD1BmdVcHA3I/t+9230v3W5nFsOePTrhYHGv1QgVncGS6DjjdzdUlg0mB28F2w17he wLIwFt2t1dozuJkNbrYtPWRQKfBx2GA6EQRPMLVO5IBGIyYkvHpjqIa6DwjXaLl15cks o1vVz7YidMp46YVb/IJoMUHFevN7f18woJ3vqb1msw37nMZ1WMQDEUfiCZekJKT2B3g+ /V4sFLBnFXPB7bJpDxO1U8rWzwNquDh13PZXl2rPZVcUBUgi5Vp7svlCGze6dANvD2Ow eZI6QTIWPbeTOhqOGkng55MBfyQiuvBtWJwJA4h6yEK8FAfmGad8EtpVPzP9xiMtjFmc JcSQ== 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=ZQyRxqGM1W/LS0ssRps7WJXXzo4kRUKS7bNZtUe51CI=; b=Ph2DzjlOQ1PNdJpAQkcTUIm7+gfrYm1/4RXGL492qU+SnY6kSf1cLFNboyobXREdqW kA/6LLtisYCDI7agh6qRwD4nuz0JSm92PqeN8352q9SLm61AD4DtMakdTEznDN0GIjRe vS0Ghl8bbgQa9R8EoSYhRV/JY/CF1Y8ARc30xZRNuR6Cr4TeKU6HzQWuN+OUwngq3I49 JVZn5y1JwHLyfrTjopZFdNorE1jR71znLdCNdh6xI/fUDKiZ1DgKcQ2dLe08266fv3uq PE3YrzEGMpPEcOXYZE2MHf+mtOHAfDF5U3nbX25FR0CCNHFPCyoSIdZsGG53MEQIE4p1 PUYw== X-Gm-Message-State: AJIora+xLsH0jaakgKE3KuAwalFNRoG9BC6frk5MYCWQHRtYROmY2wsn sDo52+UmMq/qDGAj07ZFveUQHA== X-Received: by 2002:a05:6a00:134e:b0:52a:d5b4:19bb with SMTP id k14-20020a056a00134e00b0052ad5b419bbmr14826941pfu.45.1658791996740; Mon, 25 Jul 2022 16:33:16 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id a8-20020a17090a6d8800b001f24c08c3fesm7573683pjk.1.2022.07.25.16.33.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 16:33:16 -0700 (PDT) Date: Mon, 25 Jul 2022 23:33:12 +0000 From: Sean Christopherson To: David Matlack 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: 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=unavailable 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 Mon, Jul 25, 2022, David Matlack wrote: > 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. Yeah, I balked a bit when making the change, but couldn't come up with a better alternative. > Maybe spte_to_child_sp() or to_child_sp()? I like to_child_sp(). Apparently I have a mental block when it comes to parent vs. child pages and never realized that sptep_to_sp() gets the "parent" but spte_to_sp() gets the "child". That indeed makes spte_to_sp() a bad name.