All of lore.kernel.org
 help / color / mirror / Atom feed
* Does KVM use one EPT table per Guest CR3?
@ 2010-12-07 21:47 Lok Kwong Yan
  2010-12-07 21:57 ` Anthony Liguori
  0 siblings, 1 reply; 11+ messages in thread
From: Lok Kwong Yan @ 2010-12-07 21:47 UTC (permalink / raw)
  To: kvm

After some testing and digging around the 2.6.32-26 Kernel, Ubuntu port, , it seems to me that KVM creates a separate EPT table for each separate guest CR3 value. So, if there are 100 guest processes, there are essentially 100 EPT tables. Is this correct? If so, can someone please tell me where these tables are actually being created? Is this design decision a historical artifact from how QEMU/KVM (without EPT/NPT) created multiple shadow page tables so that each guest/virtual CR3 value has a corresponding real CR3 value so that memory based separation for the guest is enforced?

Thanks!

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

* Re: Does KVM use one EPT table per Guest CR3?
  2010-12-07 21:47 Does KVM use one EPT table per Guest CR3? Lok Kwong Yan
@ 2010-12-07 21:57 ` Anthony Liguori
  2010-12-07 22:00   ` Lok Kwong Yan
  0 siblings, 1 reply; 11+ messages in thread
From: Anthony Liguori @ 2010-12-07 21:57 UTC (permalink / raw)
  To: Lok Kwong Yan; +Cc: kvm

On 12/07/2010 03:47 PM, Lok Kwong Yan wrote:
> After some testing and digging around the 2.6.32-26 Kernel, Ubuntu port, , it seems to me that KVM creates a separate EPT table for each separate guest CR3 value. So, if there are 100 guest processes, there are essentially 100 EPT tables. Is this correct?

No, it's not correct.

Regards,

Anthony Liguori

>   If so, can someone please tell me where these tables are actually being created? Is this design decision a historical artifact from how QEMU/KVM (without EPT/NPT) created multiple shadow page tables so that each guest/virtual CR3 value has a corresponding real CR3 value so that memory based separation for the guest is enforced?
>
> Thanks!--
> 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] 11+ messages in thread

* RE: Does KVM use one EPT table per Guest CR3?
  2010-12-07 21:57 ` Anthony Liguori
@ 2010-12-07 22:00   ` Lok Kwong Yan
  2010-12-07 22:11     ` Anthony Liguori
  0 siblings, 1 reply; 11+ messages in thread
From: Lok Kwong Yan @ 2010-12-07 22:00 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: kvm

Thanks for the quick response. It is greatly appreciated. 

Can you please point me in the right direction on finding out why the EPTP (EPT_POINTER & mmu.root_hpa) have so many different values? 

Thanks again.

________________________________________
From: Anthony Liguori [anthony@codemonkey.ws]
Sent: Tuesday, December 07, 2010 4:57 PM
To: Lok Kwong Yan
Cc: kvm@vger.kernel.org
Subject: Re: Does KVM use one EPT table per Guest CR3?

On 12/07/2010 03:47 PM, Lok Kwong Yan wrote:
> After some testing and digging around the 2.6.32-26 Kernel, Ubuntu port, , it seems to me that KVM creates a separate EPT table for each separate guest CR3 value. So, if there are 100 guest processes, there are essentially 100 EPT tables. Is this correct?

No, it's not correct.

Regards,

Anthony Liguori

>   If so, can someone please tell me where these tables are actually being created? Is this design decision a historical artifact from how QEMU/KVM (without EPT/NPT) created multiple shadow page tables so that each guest/virtual CR3 value has a corresponding real CR3 value so that memory based separation for the guest is enforced?
>
> Thanks!--
> 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] 11+ messages in thread

* Re: Does KVM use one EPT table per Guest CR3?
  2010-12-07 22:00   ` Lok Kwong Yan
@ 2010-12-07 22:11     ` Anthony Liguori
  2010-12-10  7:44       ` Lok Kwong Yan
  0 siblings, 1 reply; 11+ messages in thread
From: Anthony Liguori @ 2010-12-07 22:11 UTC (permalink / raw)
  To: Lok Kwong Yan; +Cc: kvm

On 12/07/2010 04:00 PM, Lok Kwong Yan wrote:
> Thanks for the quick response. It is greatly appreciated.
>
> Can you please point me in the right direction on finding out why the EPTP (EPT_POINTER&  mmu.root_hpa) have so many different values?
>    

The table is built dynamically as memory is faulted in so it changes 
over time.  But the rate is significantly less than the rate you'd see 
with shadow paging.

Unlike Xen, KVM doesn't just built an EPT table all at once and leave it 
alone.  The has to be updated as the guest is swapped in and out of memory.

Regards,

Anthony Liguori

> Thanks again.
>
> ________________________________________
> From: Anthony Liguori [anthony@codemonkey.ws]
> Sent: Tuesday, December 07, 2010 4:57 PM
> To: Lok Kwong Yan
> Cc: kvm@vger.kernel.org
> Subject: Re: Does KVM use one EPT table per Guest CR3?
>
> On 12/07/2010 03:47 PM, Lok Kwong Yan wrote:
>    
>> After some testing and digging around the 2.6.32-26 Kernel, Ubuntu port, , it seems to me that KVM creates a separate EPT table for each separate guest CR3 value. So, if there are 100 guest processes, there are essentially 100 EPT tables. Is this correct?
>>      
> No, it's not correct.
>
> Regards,
>
> Anthony Liguori
>
>    
>>    If so, can someone please tell me where these tables are actually being created? Is this design decision a historical artifact from how QEMU/KVM (without EPT/NPT) created multiple shadow page tables so that each guest/virtual CR3 value has a corresponding real CR3 value so that memory based separation for the guest is enforced?
>>
>> Thanks!--
>> 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] 11+ messages in thread

* RE: Does KVM use one EPT table per Guest CR3?
  2010-12-07 22:11     ` Anthony Liguori
@ 2010-12-10  7:44       ` Lok Kwong Yan
  2010-12-12 10:47         ` Avi Kivity
  0 siblings, 1 reply; 11+ messages in thread
From: Lok Kwong Yan @ 2010-12-10  7:44 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: kvm

Thanks again. 

I understand that the table can change over time, but it doesn't explain why the top-most table gets zapped and seemingly recreated with a different page frame (and thus the different EPTP values) so frequently. Why isn't the table being updated instead of being destroyed and then recreated? Which piece of the puzzle and I missing?

Thanks.


________________________________________
From: Anthony Liguori [anthony@codemonkey.ws]
Sent: Tuesday, December 07, 2010 5:11 PM
To: Lok Kwong Yan
Cc: kvm@vger.kernel.org
Subject: Re: Does KVM use one EPT table per Guest CR3?

On 12/07/2010 04:00 PM, Lok Kwong Yan wrote:
> Thanks for the quick response. It is greatly appreciated.
>
> Can you please point me in the right direction on finding out why the EPTP (EPT_POINTER&  mmu.root_hpa) have so many different values?
>

The table is built dynamically as memory is faulted in so it changes
over time.  But the rate is significantly less than the rate you'd see
with shadow paging.

Unlike Xen, KVM doesn't just built an EPT table all at once and leave it
alone.  The has to be updated as the guest is swapped in and out of memory.

Regards,

Anthony Liguori

> Thanks again.
>
> ________________________________________
> From: Anthony Liguori [anthony@codemonkey.ws]
> Sent: Tuesday, December 07, 2010 4:57 PM
> To: Lok Kwong Yan
> Cc: kvm@vger.kernel.org
> Subject: Re: Does KVM use one EPT table per Guest CR3?
>
> On 12/07/2010 03:47 PM, Lok Kwong Yan wrote:
>
>> After some testing and digging around the 2.6.32-26 Kernel, Ubuntu port, , it seems to me that KVM creates a separate EPT table for each separate guest CR3 value. So, if there are 100 guest processes, there are essentially 100 EPT tables. Is this correct?
>>
> No, it's not correct.
>
> Regards,
>
> Anthony Liguori
>
>
>>    If so, can someone please tell me where these tables are actually being created? Is this design decision a historical artifact from how QEMU/KVM (without EPT/NPT) created multiple shadow page tables so that each guest/virtual CR3 value has a corresponding real CR3 value so that memory based separation for the guest is enforced?
>>
>> Thanks!--
>> 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] 11+ messages in thread

* Re: Does KVM use one EPT table per Guest CR3?
  2010-12-10  7:44       ` Lok Kwong Yan
@ 2010-12-12 10:47         ` Avi Kivity
  2010-12-16 22:14           ` Lok Kwong Yan
  0 siblings, 1 reply; 11+ messages in thread
From: Avi Kivity @ 2010-12-12 10:47 UTC (permalink / raw)
  To: Lok Kwong Yan; +Cc: Anthony Liguori, kvm

On 12/10/2010 09:44 AM, Lok Kwong Yan wrote:
> Thanks again.
>
> I understand that the table can change over time, but it doesn't explain why the top-most table gets zapped and seemingly recreated with a different page frame (and thus the different EPTP values) so frequently. Why isn't the table being updated instead of being destroyed and then recreated? Which piece of the puzzle and I missing?

When the physical memory map changes the EPT tables are zapped.  This 
happens when PCI BARs are remapped, or when VGA remaps the framebuffer 
windows at 0xa0000-0xc0000.  Both of these happen during boot.  Do you 
see zaps happening after boot is complete?

-- 
error compiling committee.c: too many arguments to function


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

* RE: Does KVM use one EPT table per Guest CR3?
  2010-12-12 10:47         ` Avi Kivity
@ 2010-12-16 22:14           ` Lok Kwong Yan
  2010-12-17 15:24             ` Avi Kivity
  0 siblings, 1 reply; 11+ messages in thread
From: Lok Kwong Yan @ 2010-12-16 22:14 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, kvm

Thanks for the reply and it makes a lot of sense.

I am not seeing any EPT tables being zapped after the guest has fully started up although the value of EPTP continuously changes as the guest is running. 

________________________________________
From: Avi Kivity [avi@redhat.com]
Sent: Sunday, December 12, 2010 5:47 AM
To: Lok Kwong Yan
Cc: Anthony Liguori; kvm@vger.kernel.org
Subject: Re: Does KVM use one EPT table per Guest CR3?

On 12/10/2010 09:44 AM, Lok Kwong Yan wrote:
> Thanks again.
>
> I understand that the table can change over time, but it doesn't explain why the top-most table gets zapped and seemingly recreated with a different page frame (and thus the different EPTP values) so frequently. Why isn't the table being updated instead of being destroyed and then recreated? Which piece of the puzzle and I missing?

When the physical memory map changes the EPT tables are zapped.  This
happens when PCI BARs are remapped, or when VGA remaps the framebuffer
windows at 0xa0000-0xc0000.  Both of these happen during boot.  Do you
see zaps happening after boot is complete?

--
error compiling committee.c: too many arguments to function


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

* Re: Does KVM use one EPT table per Guest CR3?
  2010-12-16 22:14           ` Lok Kwong Yan
@ 2010-12-17 15:24             ` Avi Kivity
  2010-12-19 14:31               ` Avi Kivity
  0 siblings, 1 reply; 11+ messages in thread
From: Avi Kivity @ 2010-12-17 15:24 UTC (permalink / raw)
  To: Lok Kwong Yan; +Cc: Anthony Liguori, kvm

On 12/17/2010 12:14 AM, Lok Kwong Yan wrote:
> Thanks for the reply and it makes a lot of sense.
>
> I am not seeing any EPT tables being zapped after the guest has fully started up although the value of EPTP continuously changes as the guest is running.

Really strange, this is likely a bug.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


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

* Re: Does KVM use one EPT table per Guest CR3?
  2010-12-17 15:24             ` Avi Kivity
@ 2010-12-19 14:31               ` Avi Kivity
  2010-12-22 21:56                 ` Lok Kwong Yan
  2011-02-10 20:47                 ` Lok Kwong Yan
  0 siblings, 2 replies; 11+ messages in thread
From: Avi Kivity @ 2010-12-19 14:31 UTC (permalink / raw)
  To: Lok Kwong Yan; +Cc: Anthony Liguori, kvm

On 12/17/2010 05:24 PM, Avi Kivity wrote:
> On 12/17/2010 12:14 AM, Lok Kwong Yan wrote:
>> Thanks for the reply and it makes a lot of sense.
>>
>> I am not seeing any EPT tables being zapped after the guest has fully 
>> started up although the value of EPTP continuously changes as the 
>> guest is running.
>
> Really strange, this is likely a bug.
>

I tried to reproduce, the only times I see eptp changes are when the 
guest reprograms the vga adapter:

  qemu-system-x86-20944 [033]  1327.151819: kvm_pio:              
pio_write at 0x3ce size 2 count 1
  qemu-system-x86-20944 [033]  1327.151819: kvm_userspace_exit:   reason 
KVM_EXIT_IO (2)
  qemu-system-x86-20944 [033]  1327.152405: kvm_mmu_prepare_zap_page: 
[FAILED TO PARSE] gfn=237568 role=122881 root_count=0 unsync=0
...
  qemu-system-x86-20944 [033]  1327.153230: kvm_mmu_prepare_zap_page: 
[FAILED TO PARSE] gfn=0 role=253956 root_count=2 unsync=0
  qemu-system-x86-20944 [033]  1327.153339: kvm_mmu_get_page:     sp gfn 
0 0/4 q0 direct --- !pge !nxe root 0sync
  qemu-system-x86-20944 [033]  1327.153344: print:                
a0265cde vmx_set_cr3: eptp fef14101

Under what scenario do you see eptp changing?

-- 
error compiling committee.c: too many arguments to function


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

* RE: Does KVM use one EPT table per Guest CR3?
  2010-12-19 14:31               ` Avi Kivity
@ 2010-12-22 21:56                 ` Lok Kwong Yan
  2011-02-10 20:47                 ` Lok Kwong Yan
  1 sibling, 0 replies; 11+ messages in thread
From: Lok Kwong Yan @ 2010-12-22 21:56 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, kvm

Thanks for the reply. I haven't traced the source of eptp changing and won't have a chance to do that for a couple of weeks. I will do that and respond. Thanks again.

Lok

________________________________________
From: Avi Kivity [avi@redhat.com]
Sent: Sunday, December 19, 2010 9:31 AM
To: Lok Kwong Yan
Cc: Anthony Liguori; kvm@vger.kernel.org
Subject: Re: Does KVM use one EPT table per Guest CR3?

On 12/17/2010 05:24 PM, Avi Kivity wrote:
> On 12/17/2010 12:14 AM, Lok Kwong Yan wrote:
>> Thanks for the reply and it makes a lot of sense.
>>
>> I am not seeing any EPT tables being zapped after the guest has fully
>> started up although the value of EPTP continuously changes as the
>> guest is running.
>
> Really strange, this is likely a bug.
>

I tried to reproduce, the only times I see eptp changes are when the
guest reprograms the vga adapter:

  qemu-system-x86-20944 [033]  1327.151819: kvm_pio:
pio_write at 0x3ce size 2 count 1
  qemu-system-x86-20944 [033]  1327.151819: kvm_userspace_exit:   reason
KVM_EXIT_IO (2)
  qemu-system-x86-20944 [033]  1327.152405: kvm_mmu_prepare_zap_page:
[FAILED TO PARSE] gfn=237568 role=122881 root_count=0 unsync=0
...
  qemu-system-x86-20944 [033]  1327.153230: kvm_mmu_prepare_zap_page:
[FAILED TO PARSE] gfn=0 role=253956 root_count=2 unsync=0
  qemu-system-x86-20944 [033]  1327.153339: kvm_mmu_get_page:     sp gfn
0 0/4 q0 direct --- !pge !nxe root 0sync
  qemu-system-x86-20944 [033]  1327.153344: print:
a0265cde vmx_set_cr3: eptp fef14101

Under what scenario do you see eptp changing?

--
error compiling committee.c: too many arguments to function


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

* RE: Does KVM use one EPT table per Guest CR3?
  2010-12-19 14:31               ` Avi Kivity
  2010-12-22 21:56                 ` Lok Kwong Yan
@ 2011-02-10 20:47                 ` Lok Kwong Yan
  1 sibling, 0 replies; 11+ messages in thread
From: Lok Kwong Yan @ 2011-02-10 20:47 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Anthony Liguori, kvm

Sorry for the late reply.

Seems to me that the EPTP pointer is changing because of kvm_set_cr0.

Here is what I did and please correct me if I am doing the trace incorrectly:

- Added a trace entry in vmx_set_cr3 where a trace message is outputted whenever vmcs_read64(EPT_POINTER) != eptp after construct_eptp(cr3).

I then looked at the trace log and seems to show up with 

kvm_exit: reason cr_access rip 0xc0122003
kvm_cr: cr_write 0 = 0x8005003b

I also noticed that kvm_mmu_reset_context(vcpu) is being called at the end of kvm_set_cr0. 

The CR0 value of 0x8005003b doesn't seem to trigger any of the if cases which would indicate that kvm_mmu_reset_context(vcpu) is being called and could be the reason why eptp is changing.

Thanks for your help again.

Enjoy,

Lok




________________________________________
From: Avi Kivity [avi@redhat.com]
Sent: Sunday, December 19, 2010 9:31 AM
To: Lok Kwong Yan
Cc: Anthony Liguori; kvm@vger.kernel.org
Subject: Re: Does KVM use one EPT table per Guest CR3?

On 12/17/2010 05:24 PM, Avi Kivity wrote:
> On 12/17/2010 12:14 AM, Lok Kwong Yan wrote:
>> Thanks for the reply and it makes a lot of sense.
>>
>> I am not seeing any EPT tables being zapped after the guest has fully
>> started up although the value of EPTP continuously changes as the
>> guest is running.
>
> Really strange, this is likely a bug.
>

I tried to reproduce, the only times I see eptp changes are when the
guest reprograms the vga adapter:

  qemu-system-x86-20944 [033]  1327.151819: kvm_pio:
pio_write at 0x3ce size 2 count 1
  qemu-system-x86-20944 [033]  1327.151819: kvm_userspace_exit:   reason
KVM_EXIT_IO (2)
  qemu-system-x86-20944 [033]  1327.152405: kvm_mmu_prepare_zap_page:
[FAILED TO PARSE] gfn=237568 role=122881 root_count=0 unsync=0
...
  qemu-system-x86-20944 [033]  1327.153230: kvm_mmu_prepare_zap_page:
[FAILED TO PARSE] gfn=0 role=253956 root_count=2 unsync=0
  qemu-system-x86-20944 [033]  1327.153339: kvm_mmu_get_page:     sp gfn
0 0/4 q0 direct --- !pge !nxe root 0sync
  qemu-system-x86-20944 [033]  1327.153344: print:
a0265cde vmx_set_cr3: eptp fef14101

Under what scenario do you see eptp changing?

--
error compiling committee.c: too many arguments to function


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

end of thread, other threads:[~2011-02-10 20:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07 21:47 Does KVM use one EPT table per Guest CR3? Lok Kwong Yan
2010-12-07 21:57 ` Anthony Liguori
2010-12-07 22:00   ` Lok Kwong Yan
2010-12-07 22:11     ` Anthony Liguori
2010-12-10  7:44       ` Lok Kwong Yan
2010-12-12 10:47         ` Avi Kivity
2010-12-16 22:14           ` Lok Kwong Yan
2010-12-17 15:24             ` Avi Kivity
2010-12-19 14:31               ` Avi Kivity
2010-12-22 21:56                 ` Lok Kwong Yan
2011-02-10 20:47                 ` Lok Kwong Yan

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.