All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Tony Roberts <mrthaggar14@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: KVM EPT implementation
Date: Fri, 29 Mar 2013 10:20:28 +0100	[thread overview]
Message-ID: <51555CDC.6070605@redhat.com> (raw)
In-Reply-To: <CAPCXfDse4qVGEC-y4P+1SAOSCVwAUPfpUhAiU6M_Udep02hYfA@mail.gmail.com>

Il 28/03/2013 17:06, Tony Roberts ha scritto:
> 
> I was hoping somebody might be able to point me to the correct
> location within the KVM source code to track when EPT entries are
> actually written to the various tables in the 4 level hierarchy.  The
> function pte_list_add seems to do nothing more than change the value
> of a pointer, but only the first address passed to it is page aligned
> (the PML4 base) and the rest of the addresses appear to be pointers
> into existing pages, often seeming to be outside of the PML4 page
> range.

The EPT tables are built lazily, as if they were shadow page tables.
There is "only" one difference in how they're built; namely, the tables
do not include the gva->gpa (guest virtual address->guest physical
address) translation.

This is very similar to how KVM builds shadow page tables when the guest
is running without pages.  In both cases we have to build a page table
for gpa->hpa translation ("standard" OS page tables are hva->hpa).  In
fact, many callbacks are shared between the two cases, and even when
they're not there are similarities.  You can see that both
nonpaging_page_fault and tdp_page_fault invoke __direct_map, for example.

What makes the difference, of course, is that EPT tables are hardly ever
invalidated:

1) nonpaging_invlpg and nonpaging_sync_page are no-ops; this is also the
case with shadow page tables in nonpaging mode, as the names suggest.

2) neither invlpg nor CR3 loads and stores cause a vmexit in EPT mode.
kvm_set_cr3, and hence (via nonpaging_new_cr3) mmu_free_roots, are
hardly ever called.  You could get a call from the emulator in rare
cases, which would cause a spurious flush, but that never happens in
practice.

(This doesn't include nested virtualization, which uses the MMU in
another mode with its own callbacks---see init_kvm_nested_mmu.  I think
this is beyond what you currently care about, though).

Paolo

      parent reply	other threads:[~2013-03-29  9:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 16:06 KVM EPT implementation Tony Roberts
2013-03-29  2:03 ` Zhang, Yang Z
2013-03-29  9:20 ` Paolo Bonzini [this message]

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=51555CDC.6070605@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mrthaggar14@gmail.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.