All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: harry harry <hiharryharryharry@gmail.com>
Cc: Maxim Levitsky <mlevitsk@redhat.com>,
	kvm@vger.kernel.org, qemu-devel@nongnu.org,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	stefanha@redhat.com, mathieu.tarral@protonmail.com
Subject: Re: About two-dimensional page translation (e.g., Intel EPT) and shadow page table in Linux QEMU/KVM
Date: Wed, 28 Jul 2021 20:01:18 +0000	[thread overview]
Message-ID: <YQG3jg9kSqfzmbPB@google.com> (raw)
In-Reply-To: <CA+-xGqP7=m47cLD65DhTumOF8+sWZvc81gh+04aKMS56WWkVtA@mail.gmail.com>

On Wed, Jul 28, 2021, harry harry wrote:
> Sean, sorry for the late reply. Thanks for your careful explanations.
> 
> > For emulation of any instruction/flow that starts with a guest virtual address.
> > On Intel CPUs, that includes quite literally any "full" instruction emulation,
> > since KVM needs to translate CS:RIP to a guest physical address in order to fetch
> > the guest's code stream.  KVM can't avoid "full" emulation unless the guest is
> > heavily enlightened, e.g. to avoid string I/O, among many other things.
> 
> Do you mean the emulated MMU is needed when it *only* wants to
> translate GVAs to GPAs in the guest level?

Not quite, though gva_to_gpa() is the main use.  The emulated MMU is also used to
inject guest #PF and to load/store guest PDTPRs.  

> In such cases, the hardware MMU cannot be used because hardware MMU
> can only translate GVAs to HPAs, right?

Sort of.  The hardware MMU does translate GVA to GPA, but the GPA value is not
visible to software (unless the GPA->HPA translation faults).  That's also true
for VA to PA (and GVA to HPA).  Irrespective of virtualization, x86 ISA doesn't
provide an instruction to retrive the PA for a given VA.

If such an instruction did exist, and it was to be usable for a VMM to do a
GVA->GPA translation, the magic instruction would need to take all MMU params as
operands, e.g. CR0, CR3, CR4, and EFER.  When KVM is active (not the guest), the
hardware MMU is loaded with the host MMU configuration, not the guest.  In both
VMX and SVM, vCPU state is mostly ephemeral in the sense that it ceases to exist
in hardware when the vCPU exits to the host.  Some state is retained in hardware,
e.g. TLB and cache entries, but those are associated with select properties of
the vCPU, e.g. EPTP, CR3, etc..., not with the vCPU itself, i.e. not with the
VMCS (VMX) / VMCB (SVM).

  reply	other threads:[~2021-07-28 20:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-11 20:13 About two-dimensional page translation (e.g., Intel EPT) and shadow page table in Linux QEMU/KVM harry harry
2021-07-11 20:13 ` harry harry
2021-07-12  9:49 ` Maxim Levitsky
2021-07-12  9:49   ` Maxim Levitsky
2021-07-12 13:02   ` harry harry
2021-07-12 13:02     ` harry harry
2021-07-12 13:11     ` Maxim Levitsky
2021-07-12 13:11       ` Maxim Levitsky
2021-07-12 14:56       ` Sean Christopherson
2021-07-14  5:30         ` harry harry
2021-07-14  5:30           ` harry harry
2021-07-14 17:47           ` Sean Christopherson
2021-07-15  5:49             ` harry harry
2021-07-15  5:49               ` harry harry
2021-07-15 22:24               ` Sean Christopherson
2021-07-16  3:20                 ` harry harry
2021-07-16  3:20                   ` harry harry
2021-07-21 21:00                   ` Sean Christopherson
2021-07-28 19:00                     ` harry harry
2021-07-28 19:00                       ` harry harry
2021-07-28 20:01                       ` Sean Christopherson [this message]
2021-08-05 19:42                         ` harry harry
2021-08-05 19:42                           ` harry harry
2021-07-14  5:22       ` harry harry
2021-07-14  5:22         ` harry harry

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=YQG3jg9kSqfzmbPB@google.com \
    --to=seanjc@google.com \
    --cc=hiharryharryharry@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=mathieu.tarral@protonmail.com \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=stefanha@redhat.com \
    /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.