kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Arthur Chunqi Li <yzt356@gmail.com>
Cc: kvm <kvm@vger.kernel.org>, Jan Kiszka <jan.kiszka@web.de>
Subject: Re: Calling to kvm_mmu_load
Date: Fri, 25 Oct 2013 01:43:24 +0100	[thread overview]
Message-ID: <5269BEAC.90809@redhat.com> (raw)
In-Reply-To: <CABpY8MJAnxWqZNWt-+B_=r6kf3fHRx13HNLpkTFvTME4ufx0Bw@mail.gmail.com>

Il 24/10/2013 08:55, Arthur Chunqi Li ha scritto:
> Hi Paolo,
> 
> Thanks for your reply.
> 
> On Wed, Oct 23, 2013 at 2:21 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>> Il 21/10/2013 08:56, Arthur Chunqi Li ha scritto:
>>> Hi there,
>>>
>>> I noticed that kvm_mmu_reload() is called every time in vcpu enter,
>>> and kvm_mmu_load() is called in this function when root_hpa is
>>> INVALID_PAGE. I get confused why and when root_hpa can be set to
>>> INVALID_PAGE? I find one condition that if vcpu get request
>>> KVM_REQ_MMU_RELOAD, kvm_mmu_unload() is called to invalid root_hpa,
>>> but this condition cannot cover all occasions.
>>
>> Look also at mmu_free_roots, kvm_mmu_unload and kvm_mmu_reset_context.
>> In "normal" cases and without EPT, it should be called when CR3 changes
>> or when the paging mode changes (32-bit, PAE, 64-bit, no paging).  With
>> EPT, this kind of change won't reset the MMU (CR3 changes won't cause a
>> vmexit at all, in fact).
> 
> When EPT is enabled, why will root_hpa be set to INVALID_PAGE when a
> VM boots?

Because EPT page tables are only built lazily.  The EPT page tables
start all-invalid, and are built as the guest accesses pages at new
guest physical addresses (instead, shadow page tables are built as the
guest accesses pages at new guest virtual addresses).

> I find that Qemu reset root_hpa with KVM_REQ_MMU_RELOAD
> request several time when booting a VM, why?

This happens when the memory map changes.  A previously-valid guest
physical address might become invalid now, and the EPT page tables have
to be "emptied".

> And will VM use EPT from the very beginning when booting?

Yes.  But it's not the VM.  It's KVM that uses EPT.

The VM only uses EPT if you're using nested virtualization, and EPT is
enabled.  L1's KVM uses EPT, L2 doesn't (because it doesn't run KVM).

>> With nested virtualization, roots are invalidated whenever kvm->arch.mmu
>> changes meaning from L1->L0 or L2->L0 or vice versa (in the special case
>> where EPT is disabled on L0, this is trivially because vmentry loads CR3
>> from the vmcs02).
> 
> Besides, in function tdp_page_fault(), I find two different execution
> flow which may not reach __direct_map() (which I think is the normal
> path to handle PF), they are fast_page_fault() and try_async_pf().
> When will these two paths called when handling EPT page fault?

fast_page_fault() is called if you're using dirty page tracking.  It
checks if we have a read-only page that is in a writeable memory slot
(SPTE_HOST_WRITEABLE) and whose PTE allows writes (SPTE_MMU_WRITEABLE).
 If these conditions are satisfied, the page was read-only because of
dirty page tracking; it is made read-write with a single cmpxchg and
sets the bit for the page in the dirty bitmap.

try_async_pf will inject a "dummy" pagefault instead of creating the EPT
page table, and create the page table in the background.  The guest will
do something else (run another task) until the EPT page table has been
created; then a second "dummy" pagefault is injected.
kvm_arch_async_page_not_present signals the first page fault,
kvm_arch_async_page_present signals the second.  For this to happen, the
guest must have enabled the asynchronous page fault feature with a write
to a KVM-specific MSR.

Paolo

  reply	other threads:[~2013-10-25  0:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21  7:56 Calling to kvm_mmu_load Arthur Chunqi Li
2013-10-23  6:21 ` Paolo Bonzini
2013-10-24  7:55   ` Arthur Chunqi Li
2013-10-25  0:43     ` Paolo Bonzini [this message]
2013-10-29  5:39       ` Arthur Chunqi Li
2013-10-29 12:55         ` Paolo Bonzini
2013-10-30 11:39           ` Arthur Chunqi Li
2013-10-30 11:44             ` Paolo Bonzini
2013-10-31  8:05           ` Arthur Chunqi Li
2013-10-31  9:52             ` Paolo Bonzini

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=5269BEAC.90809@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=kvm@vger.kernel.org \
    --cc=yzt356@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 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).