[v2,4/6] KVM: Documentation: Add the missing description for tdp_mmu_root_count into kvm_mmu_page
Message ID | 20230626182016.4127366-5-mizhang@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7705374vqr; Mon, 26 Jun 2023 12:25:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6YexCCGwSf4/qOqML/NiZ4t+nPSjG5S4UX4/vgcj00gpz9tJ070rzm24hJETIi8wFF0yQv X-Received: by 2002:a17:907:7ea1:b0:98e:886:f27f with SMTP id qb33-20020a1709077ea100b0098e0886f27fmr6415947ejc.20.1687807557775; Mon, 26 Jun 2023 12:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687807557; cv=none; d=google.com; s=arc-20160816; b=dedHQRFclMBRtM3l/zRIEWZWm734exl9QsQBkuMYmuJz/ozG9rZmLQOKhQ5qLkGo9T QVjRAxTg8mkFr0xvJcU3jLFF3g6/uStw4AtxvZXL3/SxXH/q5d3I2FmdkQQreEXmTFBL MBzVnX3z80Ckdb/NcYJrkFgyuGcK8IT3JCASOLPRcpORnSMOTSqElAz1F7v0ZQoggkBA ZFaPkLSp4XNnpwxbYgxrDTC64ePA5PBYChdBb7B9fPTtrKW+ySAIkJzrRZ8DpFj9hKfi 6vhdzZ6W9+0a610CUPysxKG9lybnGPX8Cp6n3IP2oOWpnQ745U/KUfqhDsavGfYE4fXI aYlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=DC1JUUoeIHOkdglYQmr1DfzfpGQE2uWlWtSL5MUhKa8=; fh=4e3puReJ7DjwMG6rJqHJp2nX/a/7QqKKhs1FjQcufg4=; b=XF+98XBJvnIB6ClCPb3VOgQqqqejhs09FzFPRzV3nAvDwVOERYfZU+zsalhoD2b8Cg +ixtWc3K8+N0pzBG0Kkxqt6ZUlRElz48DsAQwLFaDbsMTuP1RhHGsmeu0caZiRQWEX1M NaXqTGPw9636fUr84YiBKBOlmhmK0oZ7zJYQG/NC3cAbsEhmf+Vh0wjDXuTvG3uU2nk4 RUHO89TbivYazruj7RqfvkzhSnm6jqHt1fBIWXq1OjyLw7LOcWk42jSzVC5X6ujwF6Js qIQwzy540JDM1EiMgswWKHBvPROw/D6+h9gSBH9gik9juWvEEzuA/+6y9j7p3LQntr9W qDwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xYtXcmWx; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a1709061d1100b00991bd84725asi1454672ejh.227.2023.06.26.12.25.32; Mon, 26 Jun 2023 12:25:57 -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=20221208 header.b=xYtXcmWx; 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 S231824AbjFZSUy (ORCPT <rfc822;filip.gregor98@gmail.com> + 99 others); Mon, 26 Jun 2023 14:20:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231679AbjFZSUe (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 26 Jun 2023 14:20:34 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89BD510D7 for <linux-kernel@vger.kernel.org>; Mon, 26 Jun 2023 11:20:28 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bd6df68105cso5081392276.2 for <linux-kernel@vger.kernel.org>; Mon, 26 Jun 2023 11:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687803627; x=1690395627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=DC1JUUoeIHOkdglYQmr1DfzfpGQE2uWlWtSL5MUhKa8=; b=xYtXcmWxk0P1fCDcWTRmRHQ213fqB4rQuiXjexvxKc69fWrbx+jG1hAwG0llCkpycZ vIxsx2SNm225hbYaBdJVqoTck9XSOJKHlXh8DXvyqKg1GDw5gd8l+hSpY9QBLAiV12RY rv75429GaSsLG1+mV89FXylyGQezn4c2bMvPj3UN87MBkxdRUBLLYdkdL6DAdn3RGg72 VAUFRTosn8/60fdz9qwFv3TJRj28bLsYQui4hfKh76McyD8vBN0+at6FZ+BkOw316Td+ oESmYoDPXCHZZNA1rzDVevcOJ+5+8ZFPleApgNlncNDFxrTYp6OUsyfuI65KKgKe+AdK ayrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687803627; x=1690395627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DC1JUUoeIHOkdglYQmr1DfzfpGQE2uWlWtSL5MUhKa8=; b=jRPxCKFmkeKJ9T65hqU8oVDhCDo5RBP2DIdfzK0j+oAUnKYQn2IYw1Rd5fsuO2czeZ iO+lGRilTmHGR9GjOe7gVhnBg+dIM/FDyTrUcnKrMxBhVeyo9KDhbKNNCAfUXL3NU2FY 5luJzfWj7R2sSEzP33WwhzAd7o9/g9eYm6T+sfMqf3A0oxOuOFanC4PkLLRh4uZtlNGg zIQLe2IzCVi4j2h+LLwEVAzSnCHZJ3u4cdYY4YsnXPQNttatlKV2hDgftGmsZL04NDb2 Y5KBcZ2VpmtM4790j7Wrn1eVbBz1Xt8LjsSec1i10EkwJWgyRZX95oldW9Z7AXj9ERK4 Xdag== X-Gm-Message-State: AC+VfDw2Z4coUMeP7K/Iur1lg9M14ThdOcGg66rPEwLo+LYlHrRgBZsD ofNALnBH+FRELaoGc8rpVQ3dtC0ukfPu X-Received: from mizhang-super.c.googlers.com ([35.247.89.60]) (user=mizhang job=sendgmr) by 2002:a05:6902:18c4:b0:c1c:e037:136c with SMTP id ck4-20020a05690218c400b00c1ce037136cmr3172718ybb.0.1687803627815; Mon, 26 Jun 2023 11:20:27 -0700 (PDT) Reply-To: Mingwei Zhang <mizhang@google.com> Date: Mon, 26 Jun 2023 18:20:14 +0000 In-Reply-To: <20230626182016.4127366-1-mizhang@google.com> Mime-Version: 1.0 References: <20230626182016.4127366-1-mizhang@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230626182016.4127366-5-mizhang@google.com> Subject: [PATCH v2 4/6] KVM: Documentation: Add the missing description for tdp_mmu_root_count into kvm_mmu_page From: Mingwei Zhang <mizhang@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang <mizhang@google.com>, Kai Huang <kai.huang@intel.com>, Jim Mattson <jmattson@google.com>, David Matlack <dmatlack@google.com>, Ben Gardon <bgardon@google.com>, Xu Yilun <yilun.xu@intel.com>, Zhi Wang <zhi.wang.linux@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769794497895411978?= X-GMAIL-MSGID: =?utf-8?q?1769794497895411978?= |
Series |
Update document description for kvm_mmu_page and kvm_mmu_page_role
|
|
Commit Message
Mingwei Zhang
June 26, 2023, 6:20 p.m. UTC
Add the description of tdp_mmu_root_count into kvm_mmu_page description.
tdp_mmu_root_count is an atomic counter used only in TDP MMU. Its usage and
meaning is slightly different with root_counter in shadow MMU. Update the
doc.
Signed-off-by: Mingwei Zhang <mizhang@google.com>
---
Documentation/virt/kvm/x86/mmu.rst | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Mon, 2023-06-26 at 18:20 +0000, Mingwei Zhang wrote: > Add the description of tdp_mmu_root_count into kvm_mmu_page description. > tdp_mmu_root_count is an atomic counter used only in TDP MMU. Its usage and > meaning is slightly different with root_counter in shadow MMU. Update the > doc. > > Signed-off-by: Mingwei Zhang <mizhang@google.com> > --- > Documentation/virt/kvm/x86/mmu.rst | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst > index 5cd6cd5e8926..97d695207e11 100644 > --- a/Documentation/virt/kvm/x86/mmu.rst > +++ b/Documentation/virt/kvm/x86/mmu.rst > @@ -231,6 +231,11 @@ Shadow pages contain the following information: > 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. > + tdp_mmu_root_count: > + An atomic reference counter in TDP MMU root page that allows for parallel > + accesses. Accessing the page requires lifting the counter value. The > + initial value is set to 2 indicating one reference from vCPU and one > + from TDP MMU itself. Note this field is a union with root_count. > parent_ptes: > The reverse mapping for the pte/ptes pointing at this page's spt. If > parent_ptes bit 0 is zero, only one spte points at this page and > -- > 2.41.0.162.gfafddb0af9-goog > Reviewed-by: Kai Huang <kai.huang@intel.com>
On Mon, Jun 26, 2023, Mingwei Zhang wrote: > Add the description of tdp_mmu_root_count into kvm_mmu_page description. > tdp_mmu_root_count is an atomic counter used only in TDP MMU. Its usage and > meaning is slightly different with root_counter in shadow MMU. Update the > doc. > > Signed-off-by: Mingwei Zhang <mizhang@google.com> > --- > Documentation/virt/kvm/x86/mmu.rst | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst > index 5cd6cd5e8926..97d695207e11 100644 > --- a/Documentation/virt/kvm/x86/mmu.rst > +++ b/Documentation/virt/kvm/x86/mmu.rst > @@ -231,6 +231,11 @@ Shadow pages contain the following information: > 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. > + tdp_mmu_root_count: > + An atomic reference counter in TDP MMU root page that allows for parallel > + accesses. I find the "parallel accesses" simultaneously redundant and confusing. The fact that's it's an atomic implies that there are concurrent accesses. And need for an atomic is really just a minor note, i.e. shouldn't be the focus of the documentation. On a related topic, the description for "root_count" is stale now that KVM keeps references to roots. What if we take this opportunity to unify the documentation? root_count / tdp_mmu_rount_count: A reference counter for root shadow pages. vCPUs elevate the refcount when getting a shadow page that will be used as a root, i.e. will be loaded into hardware directly (CR3, PDPTRs, nCR3 EPTP). Root pages cannnot be freed while their refcount is non-zero. The TDP MMU uses an atomic refcount as vCPUs can acquire references while holding mmu_lock for read. See role.invalid and Root Pages. And then add a section specifically for root pages? I think trying to cram everything important about root pages into the description for their refcount will be difficult and kludgy. E.g. this doc should also provide an explanation of previous roots. Root Pages ========== Key talking points: - Definition of a root page - Lifecycle of roots for both the shadow MMU and TDP MMU - Previous root tracking, and why only KVM doesn'y track previous roots when using PAE paging - The importance of preserving roots that are currently not referenced by any vCPU, i.e. why TDP MMU roots are initialized with a refcount of '2' - Why shadow MMU roots don't gift a reference to the MMU itself, i.e. why they naturally survive their refcount going to zero > Accessing the page requires lifting the counter value. The > + initial value is set to 2 indicating one reference from vCPU and one > + from TDP MMU itself. Note this field is a union with root_count. > parent_ptes: > The reverse mapping for the pte/ptes pointing at this page's spt. If > parent_ptes bit 0 is zero, only one spte points at this page and > -- > 2.41.0.162.gfafddb0af9-goog >
On Tue, Jun 27, 2023, Sean Christopherson wrote: > On Mon, Jun 26, 2023, Mingwei Zhang wrote: > > Add the description of tdp_mmu_root_count into kvm_mmu_page description. > > tdp_mmu_root_count is an atomic counter used only in TDP MMU. Its usage and > > meaning is slightly different with root_counter in shadow MMU. Update the > > doc. > > > > Signed-off-by: Mingwei Zhang <mizhang@google.com> > > --- > > Documentation/virt/kvm/x86/mmu.rst | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst > > index 5cd6cd5e8926..97d695207e11 100644 > > --- a/Documentation/virt/kvm/x86/mmu.rst > > +++ b/Documentation/virt/kvm/x86/mmu.rst > > @@ -231,6 +231,11 @@ Shadow pages contain the following information: > > 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. > > + tdp_mmu_root_count: > > + An atomic reference counter in TDP MMU root page that allows for parallel > > + accesses. > > I find the "parallel accesses" simultaneously redundant and confusing. The fact > that's it's an atomic implies that there are concurrent accesses. And need for > an atomic is really just a minor note, i.e. shouldn't be the focus of the > documentation. > > On a related topic, the description for "root_count" is stale now that KVM keeps > references to roots. > > What if we take this opportunity to unify the documentation? > > root_count / tdp_mmu_rount_count: > > A reference counter for root shadow pages. vCPUs elevate the refcount when > getting a shadow page that will be used as a root, i.e. will be loaded into > hardware directly (CR3, PDPTRs, nCR3 EPTP). Root pages cannnot be freed > while their refcount is non-zero. The TDP MMU uses an atomic refcount as > vCPUs can acquire references while holding mmu_lock for read. See > role.invalid and Root Pages. Ok, I think this one is reasonable and this clarifies that this field only works for root pages. > > And then add a section specifically for root pages? I think trying to cram > everything important about root pages into the description for their refcount > will be difficult and kludgy. E.g. this doc should also provide an explanation of > previous roots. > > Root Pages > ========== > > Key talking points: > > - Definition of a root page > - Lifecycle of roots for both the shadow MMU and TDP MMU > - Previous root tracking, and why only KVM doesn'y track previous roots when > using PAE paging > - The importance of preserving roots that are currently not referenced by any > vCPU, i.e. why TDP MMU roots are initialized with a refcount of '2' > - Why shadow MMU roots don't gift a reference to the MMU itself, i.e. why they > naturally survive their refcount going to zero > I am not sure if I can add the whole section in this commit. Maybe I can push it back separately into a different series. For root_count, a brief introduction of root pages should be good enough, which is explain in your suggestion: page that "will be loaded into hardware directly (CR3, PDPTRs, nCR3 EPTP)". > > > Accessing the page requires lifting the counter value. The > > + initial value is set to 2 indicating one reference from vCPU and one > > + from TDP MMU itself. Note this field is a union with root_count. > > parent_ptes: > > The reverse mapping for the pte/ptes pointing at this page's spt. If > > parent_ptes bit 0 is zero, only one spte points at this page and > > -- > > 2.41.0.162.gfafddb0af9-goog > >
diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst index 5cd6cd5e8926..97d695207e11 100644 --- a/Documentation/virt/kvm/x86/mmu.rst +++ b/Documentation/virt/kvm/x86/mmu.rst @@ -231,6 +231,11 @@ Shadow pages contain the following information: 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. + tdp_mmu_root_count: + An atomic reference counter in TDP MMU root page that allows for parallel + accesses. Accessing the page requires lifting the counter value. The + initial value is set to 2 indicating one reference from vCPU and one + from TDP MMU itself. Note this field is a union with root_count. parent_ptes: The reverse mapping for the pte/ptes pointing at this page's spt. If parent_ptes bit 0 is zero, only one spte points at this page and