linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: nSVM: Enter guest mode before initializing nested NPT MMU
Date: Thu, 30 Jan 2025 08:13:10 -0800	[thread overview]
Message-ID: <Z5ulFoNRWGg3LOzA@google.com> (raw)
In-Reply-To: <Z5rhH342Jghl2tgL@google.com>

On Thu, Jan 30, 2025, Yosry Ahmed wrote:
> On Wed, Jan 29, 2025 at 05:08:25PM -0800, Sean Christopherson wrote:
> > When preparing vmcb02 for nested VMRUN (or state restore), "enter" guest
> > mode prior to initializing the MMU for nested NPT so that guest_mode is
> > set in the MMU's role.  KVM's model is that all L2 MMUs are tagged with
> > guest_mode, as the behavior of hypervisor MMUs tends to be significantly
> > different than kernel MMUs.
> > 
> > Practically speaking, the bug is relatively benign, as KVM only directly
> > queries role.guest_mode in kvm_mmu_free_guest_mode_roots(), which SVM
> > doesn't use, and in paths that are optimizations (mmu_page_zap_pte() and
> > shadow_mmu_try_split_huge_pages()).
> 
> Just curious, what about kvm_mmu_page_ad_need_write_protect()?

Doh, I missed that usage.

> Is it also bengin?

Yes.  Better to be lucky than good :-)

That path forces KVM to use write-protection instead of dirty-bit based Page
Modification Logging (PML) when L2 is active, because the GPAs captured by the
CPU would be L2 GPAs, not L1 GPAs, and there's no guarantee that the L2=>L1
translation would be valid when KVM processes the PML buffer.  To ensure the
correct page gets marked dirty, KVM uses it's standard write-protect scheme when
running L2, even if KVM is using PML to dirty log L1 accesses.

Lucky for me, PML isn't supported on any AMD CPUs.

  reply	other threads:[~2025-01-30 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30  1:08 [PATCH] KVM: nSVM: Enter guest mode before initializing nested NPT MMU Sean Christopherson
2025-01-30  2:17 ` Yosry Ahmed
2025-01-30 16:13   ` Sean Christopherson [this message]
2025-01-30 16:36     ` Yosry Ahmed
2025-02-15  0:50 ` Sean Christopherson

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=Z5ulFoNRWGg3LOzA@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=yosry.ahmed@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).