Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-16 Thread Marcelo Tosatti
On Wed, Oct 16, 2013 at 12:12:11PM +0300, Gleb Natapov wrote: > On Tue, Oct 15, 2013 at 07:21:19PM -0300, Marcelo Tosatti wrote: > > On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: > > > > > > > > Why is it safe to allow access, by the lockless page write protect > > > > side, to

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-16 Thread Gleb Natapov
On Tue, Oct 15, 2013 at 07:21:19PM -0300, Marcelo Tosatti wrote: > On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: > > > > > > Why is it safe to allow access, by the lockless page write protect > > > side, to spt pointer for shadow page A that can change to a shadow page > > >

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-16 Thread Gleb Natapov
On Tue, Oct 15, 2013 at 07:21:19PM -0300, Marcelo Tosatti wrote: On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: Why is it safe to allow access, by the lockless page write protect side, to spt pointer for shadow page A that can change to a shadow page pointer of shadow

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-16 Thread Marcelo Tosatti
On Wed, Oct 16, 2013 at 12:12:11PM +0300, Gleb Natapov wrote: On Tue, Oct 15, 2013 at 07:21:19PM -0300, Marcelo Tosatti wrote: On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: Why is it safe to allow access, by the lockless page write protect side, to spt pointer for

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-15 Thread Xiao Guangrong
On Oct 16, 2013, at 6:21 AM, Marcelo Tosatti wrote: > On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: >>> >>> Why is it safe to allow access, by the lockless page write protect >>> side, to spt pointer for shadow page A that can change to a shadow page >>> pointer of shadow page

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-15 Thread Marcelo Tosatti
On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: > > > > Why is it safe to allow access, by the lockless page write protect > > side, to spt pointer for shadow page A that can change to a shadow page > > pointer of shadow page B? > > > > Write protect spte of any page at will? Or

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-15 Thread Xiao Guangrong
On Oct 16, 2013, at 6:21 AM, Marcelo Tosatti mtosa...@redhat.com wrote: On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: Why is it safe to allow access, by the lockless page write protect side, to spt pointer for shadow page A that can change to a shadow page pointer of

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-15 Thread Marcelo Tosatti
On Tue, Oct 15, 2013 at 06:57:05AM +0300, Gleb Natapov wrote: Why is it safe to allow access, by the lockless page write protect side, to spt pointer for shadow page A that can change to a shadow page pointer of shadow page B? Write protect spte of any page at will? Or verify that

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-14 Thread Gleb Natapov
On Mon, Oct 14, 2013 at 04:29:45PM -0300, Marcelo Tosatti wrote: > On Sat, Oct 12, 2013 at 08:53:56AM +0300, Gleb Natapov wrote: > > On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: > > > On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: > > > > > n_max_mmu_pages is not

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-14 Thread Marcelo Tosatti
On Sat, Oct 12, 2013 at 08:53:56AM +0300, Gleb Natapov wrote: > On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: > > On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: > > > > n_max_mmu_pages is not a suitable limit to throttle freeing of pages via > > > > RCU (its too

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-14 Thread Marcelo Tosatti
On Sat, Oct 12, 2013 at 08:53:56AM +0300, Gleb Natapov wrote: On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: n_max_mmu_pages is not a suitable limit to throttle freeing of pages via RCU (its too large). If

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-14 Thread Gleb Natapov
On Mon, Oct 14, 2013 at 04:29:45PM -0300, Marcelo Tosatti wrote: On Sat, Oct 12, 2013 at 08:53:56AM +0300, Gleb Natapov wrote: On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: n_max_mmu_pages is not a suitable

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-11 Thread Gleb Natapov
On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: > On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: > > > n_max_mmu_pages is not a suitable limit to throttle freeing of pages via > > > RCU (its too large). If the free memory watermarks are smaller than > > >

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-11 Thread Marcelo Tosatti
On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: > > n_max_mmu_pages is not a suitable limit to throttle freeing of pages via > > RCU (its too large). If the free memory watermarks are smaller than > > n_max_mmu_pages for all guests, OOM is possible. > > > Ah, yes. I am not saying

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-11 Thread Marcelo Tosatti
On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: n_max_mmu_pages is not a suitable limit to throttle freeing of pages via RCU (its too large). If the free memory watermarks are smaller than n_max_mmu_pages for all guests, OOM is possible. Ah, yes. I am not saying

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-11 Thread Gleb Natapov
On Fri, Oct 11, 2013 at 05:30:17PM -0300, Marcelo Tosatti wrote: On Fri, Oct 11, 2013 at 08:38:31AM +0300, Gleb Natapov wrote: n_max_mmu_pages is not a suitable limit to throttle freeing of pages via RCU (its too large). If the free memory watermarks are smaller than n_max_mmu_pages for

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Thu, Oct 10, 2013 at 06:03:01PM -0300, Marcelo Tosatti wrote: > On Thu, Oct 10, 2013 at 10:16:46PM +0300, Gleb Natapov wrote: > > On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: > > > On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: > > > > On Wed, Oct 09, 2013 at

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Marcelo Tosatti
On Thu, Oct 10, 2013 at 10:16:46PM +0300, Gleb Natapov wrote: > On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: > > On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: > > > On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: > > > > > >> Gleb has a idea

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: > On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: > > On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: > > > > >> Gleb has a idea that uses RCU_DESTORY to protect the shadow page > > > > >> table > > >

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Marcelo Tosatti
On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: > On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: > > > >> Gleb has a idea that uses RCU_DESTORY to protect the shadow page table > > > >> and encodes the page-level into the spte (since we need to check if > > > >>

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: > > >> Gleb has a idea that uses RCU_DESTORY to protect the shadow page table > > >> and encodes the page-level into the spte (since we need to check if the > > >> spte > > >> is the last-spte. ). How about this? > > > > > >

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: Gleb has a idea that uses RCU_DESTORY to protect the shadow page table and encodes the page-level into the spte (since we need to check if the spte is the last-spte. ). How about this? Pointer please? Why is

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Marcelo Tosatti
On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: Gleb has a idea that uses RCU_DESTORY to protect the shadow page table and encodes the page-level into the spte (since we need to check if the spte is

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: Gleb has a idea that uses RCU_DESTORY to protect the shadow page table and encodes the

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Marcelo Tosatti
On Thu, Oct 10, 2013 at 10:16:46PM +0300, Gleb Natapov wrote: On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: On Wed, Oct 09, 2013 at 10:47:10PM -0300, Marcelo Tosatti wrote: Gleb has a idea that uses

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-10 Thread Gleb Natapov
On Thu, Oct 10, 2013 at 06:03:01PM -0300, Marcelo Tosatti wrote: On Thu, Oct 10, 2013 at 10:16:46PM +0300, Gleb Natapov wrote: On Thu, Oct 10, 2013 at 01:42:22PM -0300, Marcelo Tosatti wrote: On Thu, Oct 10, 2013 at 03:08:45PM +0300, Gleb Natapov wrote: On Wed, Oct 09, 2013 at 10:47:10PM

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-09 Thread Marcelo Tosatti
On Wed, Oct 09, 2013 at 06:45:47PM +0800, Xiao Guangrong wrote: > On 10/09/2013 09:56 AM, Marcelo Tosatti wrote: > > On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: > >> > >> Hi Marcelo, > >> > >> On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti wrote: > >> > > +if

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-09 Thread Xiao Guangrong
On 10/09/2013 09:56 AM, Marcelo Tosatti wrote: > On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: >> >> Hi Marcelo, >> >> On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti wrote: >> + if (kvm->arch.rcu_free_shadow_page) { + kvm_mmu_isolate_pages(invalid_list);

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-09 Thread Xiao Guangrong
On 10/09/2013 09:56 AM, Marcelo Tosatti wrote: On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: Hi Marcelo, On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti mtosa...@redhat.com wrote: + if (kvm-arch.rcu_free_shadow_page) { + kvm_mmu_isolate_pages(invalid_list); +

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-09 Thread Marcelo Tosatti
On Wed, Oct 09, 2013 at 06:45:47PM +0800, Xiao Guangrong wrote: On 10/09/2013 09:56 AM, Marcelo Tosatti wrote: On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: Hi Marcelo, On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti mtosa...@redhat.com wrote: +if

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-08 Thread Marcelo Tosatti
On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: > > Hi Marcelo, > > On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti wrote: > > >> > >> + if (kvm->arch.rcu_free_shadow_page) { > >> + kvm_mmu_isolate_pages(invalid_list); > >> + sp = list_first_entry(invalid_list,

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-08 Thread Marcelo Tosatti
On Tue, Oct 08, 2013 at 12:02:32PM +0800, Xiao Guangrong wrote: Hi Marcelo, On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti mtosa...@redhat.com wrote: + if (kvm-arch.rcu_free_shadow_page) { + kvm_mmu_isolate_pages(invalid_list); + sp = list_first_entry(invalid_list,

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-07 Thread Xiao Guangrong
Hi Marcelo, On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti wrote: >> >> +if (kvm->arch.rcu_free_shadow_page) { >> +kvm_mmu_isolate_pages(invalid_list); >> +sp = list_first_entry(invalid_list, struct kvm_mmu_page, link); >> +list_del_init(invalid_list); >>

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-07 Thread Marcelo Tosatti
On Thu, Sep 05, 2013 at 06:29:15PM +0800, Xiao Guangrong wrote: > It is easy if the handler is in the vcpu context, in that case we can use > walk_shadow_page_lockless_begin() and walk_shadow_page_lockless_end() that > disable interrupt to stop shadow page being freed. But we are on the ioctl >

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-07 Thread Marcelo Tosatti
On Thu, Sep 05, 2013 at 06:29:15PM +0800, Xiao Guangrong wrote: It is easy if the handler is in the vcpu context, in that case we can use walk_shadow_page_lockless_begin() and walk_shadow_page_lockless_end() that disable interrupt to stop shadow page being freed. But we are on the ioctl

Re: [PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-10-07 Thread Xiao Guangrong
Hi Marcelo, On Oct 8, 2013, at 9:23 AM, Marcelo Tosatti mtosa...@redhat.com wrote: +if (kvm-arch.rcu_free_shadow_page) { +kvm_mmu_isolate_pages(invalid_list); +sp = list_first_entry(invalid_list, struct kvm_mmu_page, link); +

[PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-09-05 Thread Xiao Guangrong
It is easy if the handler is in the vcpu context, in that case we can use walk_shadow_page_lockless_begin() and walk_shadow_page_lockless_end() that disable interrupt to stop shadow page being freed. But we are on the ioctl context and the paths we are optimizing for have heavy workload, disabling

[PATCH v2 12/15] KVM: MMU: allow locklessly access shadow page table out of vcpu thread

2013-09-05 Thread Xiao Guangrong
It is easy if the handler is in the vcpu context, in that case we can use walk_shadow_page_lockless_begin() and walk_shadow_page_lockless_end() that disable interrupt to stop shadow page being freed. But we are on the ioctl context and the paths we are optimizing for have heavy workload, disabling