Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17924511rwd; Tue, 27 Jun 2023 09:11:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57VMQwBIf7E5dJPrAidOpna2NGS0KfKZEkJsKe+caNAkgEb6RI7mLqi2HFNg04s0nnJny5 X-Received: by 2002:a05:6512:10d1:b0:4f8:7494:17d7 with SMTP id k17-20020a05651210d100b004f8749417d7mr11762781lfg.59.1687882263148; Tue, 27 Jun 2023 09:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687882263; cv=none; d=google.com; s=arc-20160816; b=ZsXLjLRInIG5IpLXWtBIPat48PU7EYME9vZ9FiIoICxnN59gHRuUoT3x6RcuUmzocN 9MpngjRdgpK7Fc5ZSBDKc4K/Sw3ckVu3lAkmJo7tJP3s0EN5/dFxgamNADEmAHWiNSSN aVJAIFkob0PiJCRn9hryMy5iVCCyILQmnWO4D1t08RCXkt9O0bPuFydOK+ptSudicqB2 /l62ZdYdl0qzyUuGg02Dxj3OPdw1AiqvcR7jCfsY4ZZHZ5ha5YM5yyWrbb5j7MJJ0L4F 07EfanVvqMarkN/qKdRtVGN/plLZS+1U1oD+lUDpIqSGF7Ei5HdGPi8luwTKjRVO5Rf7 fDDQ== 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:dkim-signature; bh=f5n5wbc65BkLjffQxci9ddtPIGz5YKpcfVhEyMlRoQY=; fh=ZsnesNvhcFaQMCtnzlSbqLHGfUt7yoi0dxAC9t/q8bU=; b=FnhtlfnhnI/Txe7XZEft0Z4AEXq5u1+H1wlYAw9NHGrLKQ0zKzDIQ588KYG7NnV+v7 D4x+p85/rZGilP5anAP9fVFPssX68C0AfKTRu8MXMW4XDM8vJdvg4j8h+wMTOvKe3dI4 cWLtsc436iYLLvb5aKWDYa48bDM33iDxgHuhKErt9Tt8vzs3J4nFiRMZ/q+4MuuVMDHX 66UJ/vytm2rQ2I3R+5MaZfxwhaEH7z+zgqSXkQ6OVlzhyMv02QcH+Nz/K6PR0iuyQyyJ K41IMzbW1mfwEeYLTBlbxQmZITTf/Ka8TZ0BC9LKiGzw1G+TTSDDeefLjgccJ8JWbyD1 M3IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=VhMOUNxS; 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 w23-20020aa7dcd7000000b0051d55d6eadcsi4330131edu.8.2023.06.27.09.10.36; Tue, 27 Jun 2023 09:11:03 -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=VhMOUNxS; 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 S231825AbjF0PuI (ORCPT + 99 others); Tue, 27 Jun 2023 11:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231786AbjF0PuH (ORCPT ); Tue, 27 Jun 2023 11:50:07 -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 A2B852D50 for ; Tue, 27 Jun 2023 08:50:04 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bb2fae9b286so6059479276.3 for ; Tue, 27 Jun 2023 08:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687881004; x=1690473004; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=f5n5wbc65BkLjffQxci9ddtPIGz5YKpcfVhEyMlRoQY=; b=VhMOUNxSGhmfeN6tDKv9taNLgMcr5boht1EBjABUS4HraFOok8xpcso7YrzEuAs2yD +fXKHztOwJwongchscymI1+wRS4M3XnZg0imwW+LEL1Hv5vvZCq8a/kpbVE1NEVPIbck NtWyVbZchEPzOXDvF5DoXEYD4gk8bg457Fd2/ZxwwwmhwaRjmW/QLlWLhp98MkO1F19g /w9WdiEarwnv76xb0+YaLD7LCHKppXsN2A51pOz0/OtHAq1Zh51CBnotWzXtZuchE1X5 t22fV9gTuCA0jsyRpGHAumZ4XgtJwNa9sROwT27nws9Ck11caUxgch3giXyO0GTvhZsR svWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687881004; x=1690473004; 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=f5n5wbc65BkLjffQxci9ddtPIGz5YKpcfVhEyMlRoQY=; b=BQRM09r9PnUc8SxSvMzbEm0uIdFFfob21wX7sfN0jJJt7YBG6QepwLu8auPOPnzOJY Ua2+YCZjDXEU92YZNAjLWvfbJudetKw//0vGg+6rXtcS9K/Ig4SeNZPukXwb0ctmELte YfOsGEPPKAczuRxxpHJov2Q6yIduZfVI+TjDNy9ymf3JtSXfXBFxGS6xA6umZCnllTUr JOd8FWif97yPQFr717duSj9lf7OQYjsLHQSF/DJCfY0Ee4i/GRUzUNHTgE/dZ8/OAu0M Wug43G+Sg9a51DhYpNpoFMtCk36j18rhX/GTYrWHHmC+w8lAbiaByGjjQf0eqogJ7GEe bFng== X-Gm-Message-State: AC+VfDzc5zrerg7IDrFVVyg11E9Xz/gK5YGeAoWvXDSZ/ldsrFYHlMDF XZ/g7uO8ShUYRAA3xTlilrR9la/VRRw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:c514:0:b0:ba8:b828:c8ff with SMTP id v20-20020a25c514000000b00ba8b828c8ffmr7185326ybe.10.1687881003834; Tue, 27 Jun 2023 08:50:03 -0700 (PDT) Date: Tue, 27 Jun 2023 08:50:02 -0700 In-Reply-To: <20230626182016.4127366-5-mizhang@google.com> Mime-Version: 1.0 References: <20230626182016.4127366-1-mizhang@google.com> <20230626182016.4127366-5-mizhang@google.com> Message-ID: Subject: Re: [PATCH v2 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 Content-Type: text/plain; charset="us-ascii" 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 >