From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 671FDC27C6E for ; Wed, 16 Aug 2023 22:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347017AbjHPWrC (ORCPT ); Wed, 16 Aug 2023 18:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347013AbjHPWq6 (ORCPT ); Wed, 16 Aug 2023 18:46:58 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F33173F for ; Wed, 16 Aug 2023 15:46:57 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1bb8caf7312so4077785ad.0 for ; Wed, 16 Aug 2023 15:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692226016; x=1692830816; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n7a+uEDA5jWim2WjEe90Wh2lZxzibPYDcHdGrkYhrCo=; b=3rWoeQRrMGgmiQAR59dF+dosUKDEIxpMJHcGetrQmAYhK7t/p+kJTyRyARgg6NFdIM SFj6HTnU3/0HTfd8+Pi25DdHz547vqeGA+sMkVjSFICq45apap82cKChchDfpHsxqiY3 Cq67uWauPB+TPSB6IjaPnJqQCsmSpnVmdcOEsswdT61h1ykcZn/PWvOExXraCT51rvUB Ris6ap9kzZYPhw2d0ojgodh7k26ZB9f6S/JZKn9sb0ph0bf1g4AB0mkykRAyYdH/cX6q 4hIgZFneL3wAUEmB3o5iHkiOy3y7bkTXxFew/qBiP5eM7Sph6BdaRAQ1IL0drcyMelIW +Hug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692226016; x=1692830816; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n7a+uEDA5jWim2WjEe90Wh2lZxzibPYDcHdGrkYhrCo=; b=Gf/AV5L4f/P8upwANgmZqOX6GPDNcChs/3m/CxRn93WI818ROmCXtGuBEpZkAQD9xw fN2u4JrujNiCrcLJQVzo9PKYNl3zdIvYlzQb+tVo/Wj5U7ZrSdxOmYa7An4yJty/Xbm+ MNU2E4TnBEyKLSY3kO6mPaHTGYacBQOFktK3R2NfqQWNc5DkXK+G8wdpSmFyytkDvShL fAJNE2v7vZFITUQzlo6wzl+Ol/EVppNFfCaIV3i2emFd1xSnNf691+ma+dsDPM1g3j78 iStMmP4WImdmbzerbZQV5s6Bhl8xP+V3cQLu2jMbCgcJh7FfkLZV+JlQ4sAO0w4Edt66 14kw== X-Gm-Message-State: AOJu0Yz+up9cY7VvLbWpTEUaRUtaYg/+anuptyedaMwoTy5AWYqq+kvZ N20uAyyOyGdeMVwaaRNHqbtVIxK24pk= X-Google-Smtp-Source: AGHT+IH0EciIyG+E7fGItbQPNlQ+YZpngXRdFj7vCBCg/vY89U8Bdg91XCR3378skcS2onG2JHZ9RKdEjr8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:27cd:b0:1bc:73a6:8be7 with SMTP id km13-20020a17090327cd00b001bc73a68be7mr186093plb.3.1692226016567; Wed, 16 Aug 2023 15:46:56 -0700 (PDT) Date: Wed, 16 Aug 2023 15:46:55 -0700 In-Reply-To: <20230801002127.534020-5-mizhang@google.com> Mime-Version: 1.0 References: <20230801002127.534020-1-mizhang@google.com> <20230801002127.534020-5-mizhang@google.com> Message-ID: Subject: Re: [PATCH v3 4/6] KVM: Documentation: Add the missing description for tdp_mmu_root_count into kvm_mmu_page From: Sean Christopherson To: Mingwei Zhang Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang , Jim Mattson , David Matlack , Ben Gardon , Xu Yilun , Zhi Wang , Randy Dunlap Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Tue, Aug 01, 2023, Mingwei Zhang wrote: > Add the description of tdp_mmu_root_count into kvm_mmu_page description and > combine it with the description of root_count. tdp_mmu_root_count is an > atomic counter used only in TDP MMU. Update the doc. > > Signed-off-by: Mingwei Zhang > Reviewed-by: Kai Huang > --- > Documentation/virt/kvm/x86/mmu.rst | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst > index 17d90974204e..40daf8beb9b1 100644 > --- a/Documentation/virt/kvm/x86/mmu.rst > +++ b/Documentation/virt/kvm/x86/mmu.rst > @@ -229,10 +229,14 @@ Shadow pages contain the following information: > can be calculated from the gfn field when used. In addition, when > role.direct is set, KVM does not track access permission for each of the > gfn. See role.direct and gfn. > - root_count: > - A counter keeping track of how many hardware registers (guest cr3 or > - pdptrs) are now pointing at the page. While this counter is nonzero, the > - page cannot be destroyed. See role.invalid. > + root_count / tdp_mmu_root_count: > + root_count is a reference counter for root shadow pages in Shadow MMU. > + vCPUs elevate the refcount when getting a shadow page that will be used as > + a root page, i.e. page that will be loaded into hardware directly (CR3, > + PDPTRs, nCR3 EPTP). Root pages cannot be destroyed while their refcount is > + non-zero. See role.invalid. tdp_mmu_root_count is similar but exclusively > + used in TDP MMU as an atomic refcount. When the value is non-zero, it > + allows vCPUs acquire references while holding mmu_lock for read. That last sentence is wrong. *vCPUs* can't acquire references while holding mmu_lock for read. And actually, they don't ever put references while holding for read either. vCPUs *must* hold mmu_lock for write to obtain a new root, Not putting references while holding mmu_lock for read is mostly an implementation quirk. Maybe replace it with this? tdp_mmu_root_count is similar but exclusively used in the TDP MMU as an atomic refcount (select TDP MMU flows walk all roots while holding mmu_lock for read, e.g. when clearing dirty bits).