public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* When is the page table built for migration destination ?
@ 2013-09-09  5:27 qna
  2013-09-09  8:14 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: qna @ 2013-09-09  5:27 UTC (permalink / raw)
  To: kvm@vger.kernel.org

Hello List,

I am trying to understand kvm memory management code related to VM
migration. From the code, it looks like during guest VM migration, all the
memory of the guest is transferred from source to destination, but does it
copy the source page tables to destination ?

A certain GFN(guest frame/physical number) X can be mapped to to PFN Y in
source but it is not necessary to map that GFN to PFN Y at destination.
Thus it should not make sense to copy page tables. But then, KVM should
build page tables when entire memory is copied(because current
implementation is precopy).

I added prinks in code and looks like at destination it fault, there are no
page tables created. But the memory is. Is this understanding correct ? Can
anyone explain which part of code is doing this page table building ?

--
Sunil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: When is the page table built for migration destination ?
  2013-09-09  5:27 When is the page table built for migration destination ? qna
@ 2013-09-09  8:14 ` Paolo Bonzini
  2013-09-09  9:38   ` Sunil
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2013-09-09  8:14 UTC (permalink / raw)
  To: qna; +Cc: kvm@vger.kernel.org

Il 09/09/2013 07:27, qna ha scritto:
> Hello List,
> 
> I am trying to understand kvm memory management code related to VM
> migration. From the code, it looks like during guest VM migration, all the
> memory of the guest is transferred from source to destination, but does it
> copy the source page tables to destination ?
> 
> A certain GFN(guest frame/physical number) X can be mapped to to PFN Y in
> source but it is not necessary to map that GFN to PFN Y at destination.
> Thus it should not make sense to copy page tables. But then, KVM should
> build page tables when entire memory is copied(because current
> implementation is precopy).
> 
> I added prinks in code and looks like at destination it fault, there are no
> page tables created. But the memory is. Is this understanding correct ? Can
> anyone explain which part of code is doing this page table building ?

The guest's page tables that do the gva->gfn (guest virtual
address->guest frame number) translation are in guest memory, so they
are obviously migrated together with the memory.

As the guest runs, KVM builds page tables that do either gfn->pfn
translation (if nested page tables are in use) or a combined gva->pfn
translation (these are called "shadow page tables").  These page tables
are internal to KVM and they are built lazily as the guest runs.  To do
this, KVM intercepts page faults, then:

* if the entry for the GFN doesn't exist in the KVM page tables, it
builds the entry and retries

* if the entry for the GFN exists, it passes the page fault to the guest.

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: When is the page table built for migration destination ?
  2013-09-09  8:14 ` Paolo Bonzini
@ 2013-09-09  9:38   ` Sunil
  2013-09-09  9:58     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Sunil @ 2013-09-09  9:38 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm@vger.kernel.org

Thanks Paolo.

I am using KVM with EPT support, so I understand this will require
gfn->pfn translation.  Going through the code, looks like function
tdp_page_fault() is responsible for setting up this mapping.

Though the page table is constructed lazily, I understand the page
contents are already transferred during migration. Can you please
explain or point to function names which finds the correct page
contents for given gfn  ? (looks like pte is created in
__direct_map())

--
Sunil

On Mon, Sep 9, 2013 at 1:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 09/09/2013 07:27, qna ha scritto:
>> Hello List,
>>
>> I am trying to understand kvm memory management code related to VM
>> migration. From the code, it looks like during guest VM migration, all the
>> memory of the guest is transferred from source to destination, but does it
>> copy the source page tables to destination ?
>>
>> A certain GFN(guest frame/physical number) X can be mapped to to PFN Y in
>> source but it is not necessary to map that GFN to PFN Y at destination.
>> Thus it should not make sense to copy page tables. But then, KVM should
>> build page tables when entire memory is copied(because current
>> implementation is precopy).
>>
>> I added prinks in code and looks like at destination it fault, there are no
>> page tables created. But the memory is. Is this understanding correct ? Can
>> anyone explain which part of code is doing this page table building ?
>
> The guest's page tables that do the gva->gfn (guest virtual
> address->guest frame number) translation are in guest memory, so they
> are obviously migrated together with the memory.
>
> As the guest runs, KVM builds page tables that do either gfn->pfn
> translation (if nested page tables are in use) or a combined gva->pfn
> translation (these are called "shadow page tables").  These page tables
> are internal to KVM and they are built lazily as the guest runs.  To do
> this, KVM intercepts page faults, then:
>
> * if the entry for the GFN doesn't exist in the KVM page tables, it
> builds the entry and retries
>
> * if the entry for the GFN exists, it passes the page fault to the guest.
>
> Paolo
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: When is the page table built for migration destination ?
  2013-09-09  9:38   ` Sunil
@ 2013-09-09  9:58     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2013-09-09  9:58 UTC (permalink / raw)
  To: Sunil; +Cc: kvm@vger.kernel.org

Il 09/09/2013 11:38, Sunil ha scritto:
> Thanks Paolo.
> 
> I am using KVM with EPT support, so I understand this will require
> gfn->pfn translation.  Going through the code, looks like function
> tdp_page_fault() is responsible for setting up this mapping.
> 
> Though the page table is constructed lazily, I understand the page
> contents are already transferred during migration. Can you please
> explain or point to function names which finds the correct page
> contents for given gfn  ? (looks like pte is created in
> __direct_map())

GFNs are looked up through the memory slots array.  Look at
gfn_to_memslot, gfn_to_hva, and related functions in
virt/kvm/kvm_main.c; also the __gfn_to_memslot and __gfn_to_hva_memslot
inlines in include/linux/kvm_host.h.

Paolo


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-09  9:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09  5:27 When is the page table built for migration destination ? qna
2013-09-09  8:14 ` Paolo Bonzini
2013-09-09  9:38   ` Sunil
2013-09-09  9:58     ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox