From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86/mmu: Expose number of shadow MMU shadow pages as a stat
Date: Mon, 15 Jun 2026 17:20:12 -0700 [thread overview]
Message-ID: <ajCWvIiTDcYyjC-c@google.com> (raw)
In-Reply-To: <CAO9r8zNqhUHCs=Q-jWUhQr8VJF7SgL-Kh4Ztji0E5vWpSB2UOg@mail.gmail.com>
On Mon, Jun 15, 2026, Yosry Ahmed wrote:
> On Mon, Jun 15, 2026 at 4:46 PM Sean Christopherson <seanjc@google.com> wrote:
> > > I guess for most cases, mmu_shadow_pages will represent either the MMU
> > > pages used to shadow the VM's x86 page tables (with TDP off) or nested
> > > TDP MMU pages (with TDP on and nested used) -- but I do remember some
> > > interesting case about direct mappings in the shadow MMU or sth?
> >
> > Yes, there can direct shadow pages in an indirect mmu (guest is using a page size
> > that is larger than the host, in which case there are no gPTEs to shadow and thus
> > the gva=>gpa / l2_gpa=>l1_gpa translations in KVM's shadow pages are "direct").
>
> I never understood why these are "direct" tho. Sure, they do not
> directly correspond gPTEs, but they still are shadowing guest
> mappings.
No, the *parent* is shadowing a gPTE, the child is not. Overall, KVM is shadowing
a mapping, but individual shadow pages are shadowing a specific gPTE in a specific
context, not a full mapping.
> IOW, if the guest has a PMD mapping and KVM has some PTE mappings, aren't
> those PTE mappings still shadowing the PMD mapping,
Nope, as above, there is an indirect shadow page with a base GFN that corresponds
to the guest PMD entry, i.e. that is shadowing the huge gPMD. And so if that
gPMD is modified, KVM needs to adjust that parent shadow page.
But for the PG_LEVEL_4K shadow pages, i.e. the children, there is no corresponding
page table, no gPTEs to shadow, no gfn that needs write-protection, no protection
bits to account for, and no additional lookup to do when getting from the base GFN
to the final GFN.
See the use of sp->shadowed_translation, e.g. in kvm_mmu_page_get_gfn() and
kvm_mmu_page_get_access(), and also commit 9ecc1c119b28 ("KVM: x86/mmu: Only
allocate shadowed translation cache for sp->role.level <= KVM_MAX_HUGEPAGE_LEVEL"),
which optimized KVM to avoid allocating unused metadata (KVM only ever needs to
query the gfn and access protections for leaf SPTEs).
> and still need to be sync'd in the same way they would if they were shadowing
> PTEs?
Ignoring for the moment that KVM never unsyncs PMD+ gPTEs, "yes", but only the
parents.
next prev parent reply other threads:[~2026-06-16 0:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 13:37 [PATCH v2] KVM: x86/mmu: Expose number of shadow MMU shadow pages as a stat Sean Christopherson
2026-06-15 20:57 ` Yosry Ahmed
2026-06-15 23:46 ` Sean Christopherson
2026-06-15 23:57 ` Yosry Ahmed
2026-06-16 0:20 ` Sean Christopherson [this message]
2026-06-16 0:29 ` Yosry Ahmed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajCWvIiTDcYyjC-c@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.