Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-20 Thread Paolo Bonzini
Il 20/08/2014 03:03, David Matlack ha scritto: > On Tue, Aug 19, 2014 at 5:29 PM, Xiao Guangrong > wrote: >> On 08/19/2014 05:03 PM, Paolo Bonzini wrote: >>> Il 19/08/2014 10:50, Xiao Guangrong ha scritto: Okay, what confused me it that it seems that the single line patch is ok to you. :

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-19 Thread David Matlack
On Tue, Aug 19, 2014 at 5:29 PM, Xiao Guangrong wrote: > On 08/19/2014 05:03 PM, Paolo Bonzini wrote: >> Il 19/08/2014 10:50, Xiao Guangrong ha scritto: >>> Okay, what confused me it that it seems that the single line patch >>> is ok to you. :) >> >> No, it was late and I was confused. :) >> >>> N

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-19 Thread Xiao Guangrong
On 08/19/2014 05:03 PM, Paolo Bonzini wrote: > Il 19/08/2014 10:50, Xiao Guangrong ha scritto: >> Okay, what confused me it that it seems that the single line patch >> is ok to you. :) > > No, it was late and I was confused. :) > >> Now, do we really need to care the case 2? like David said: >> "

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-19 Thread Paolo Bonzini
Il 19/08/2014 10:50, Xiao Guangrong ha scritto: > Okay, what confused me it that it seems that the single line patch > is ok to you. :) No, it was late and I was confused. :) > Now, do we really need to care the case 2? like David said: > "Sorry I didn't explain myself very well: Since we can get

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-19 Thread Xiao Guangrong
On 08/19/2014 04:28 PM, Paolo Bonzini wrote: > Il 19/08/2014 05:50, Xiao Guangrong ha scritto: >> >> Note in the step *, my approach detects the invalid generation-number which >> will invalidate the mmio spte properly . > > You are right, in fact my mail included another part: "Another > alterna

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-19 Thread Paolo Bonzini
Il 19/08/2014 05:50, Xiao Guangrong ha scritto: > > Note in the step *, my approach detects the invalid generation-number which > will invalidate the mmio spte properly . You are right, in fact my mail included another part: "Another alternative could be to use the low bit to mark an in-progress

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
On 08/19/2014 01:40 PM, David Matlack wrote: > On Mon, Aug 18, 2014 at 10:19 PM, Xiao Guangrong > wrote: >> On 08/19/2014 01:00 PM, David Matlack wrote: >>> On Mon, Aug 18, 2014 at 9:41 PM, Xiao Guangrong >>> wrote: On 08/19/2014 12:31 PM, David Matlack wrote: > The single line patch I s

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 10:19 PM, Xiao Guangrong wrote: > On 08/19/2014 01:00 PM, David Matlack wrote: >> On Mon, Aug 18, 2014 at 9:41 PM, Xiao Guangrong >> wrote: >>> On 08/19/2014 12:31 PM, David Matlack wrote: The single line patch I suggested was only intended to fix the "forever in

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
On 08/19/2014 01:00 PM, David Matlack wrote: > On Mon, Aug 18, 2014 at 9:41 PM, Xiao Guangrong > wrote: >> On 08/19/2014 12:31 PM, David Matlack wrote: >>> But it looks like you basically said the same thing earlier, so I think >>> we're on the same page. >>> >> >> Yes, that is what i try to expla

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 9:41 PM, Xiao Guangrong wrote: > On 08/19/2014 12:31 PM, David Matlack wrote: >> But it looks like you basically said the same thing earlier, so I think >> we're on the same page. >> > > Yes, that is what i try to explain in previous mails. :( I'm glad we understand each o

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
On 08/19/2014 12:31 PM, David Matlack wrote: > On Mon, Aug 18, 2014 at 8:50 PM, Xiao Guangrong > wrote: >> On 08/19/2014 05:15 AM, David Matlack wrote: >>> On Mon, Aug 18, 2014 at 12:56 PM, Xiao Guangrong >>> wrote: @@ -287,9 +293,15 @@ static bool set_mmio_spte(struct kvm *kvm, u64 *s

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 8:50 PM, Xiao Guangrong wrote: > On 08/19/2014 05:15 AM, David Matlack wrote: >> On Mon, Aug 18, 2014 at 12:56 PM, Xiao Guangrong >> wrote: >>> @@ -287,9 +293,15 @@ static bool set_mmio_spte(struct kvm *kvm, u64 *sptep, >>> gfn_t gfn, >>> >>> static bool check_mmio_spte(

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
On 08/19/2014 05:15 AM, David Matlack wrote: > On Mon, Aug 18, 2014 at 12:56 PM, Xiao Guangrong > wrote: >> @@ -287,9 +293,15 @@ static bool set_mmio_spte(struct kvm *kvm, u64 *sptep, >> gfn_t gfn, >> >> static bool check_mmio_spte(struct kvm *kvm, u64 spte) >> { >> + struct kvm_memslots

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 2:24 PM, Paolo Bonzini wrote: > Il 18/08/2014 23:15, David Matlack ha scritto: >> I just realized how simple Paolo's idea is. I think it can be a one line >> patch (without comments): >> >> [...] >> update_memslots(slots, new, kvm->memslots->generation); >>

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Paolo Bonzini
Il 18/08/2014 23:15, David Matlack ha scritto: > I just realized how simple Paolo's idea is. I think it can be a one line > patch (without comments): > > [...] > update_memslots(slots, new, kvm->memslots->generation); > rcu_assign_pointer(kvm->memslots, slots); > synchroniz

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 12:56 PM, Xiao Guangrong wrote: > @@ -287,9 +293,15 @@ static bool set_mmio_spte(struct kvm *kvm, u64 *sptep, > gfn_t gfn, > > static bool check_mmio_spte(struct kvm *kvm, u64 spte) > { > + struct kvm_memslots *slots = kvm_memslots(kvm); > unsigned int kvm_

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
On Aug 19, 2014, at 2:47 AM, Paolo Bonzini wrote: > >> I think this patch is auditable, page-fault is always called by holding >> srcu-lock so that a page fault can’t go across synchronize_srcu_expedited. >> Only these cases can happen: >> >> 1) page fault occurs before synchronize_srcu_exped

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Paolo Bonzini
Il 18/08/2014 18:35, Xiao Guangrong ha scritto: > > Hi Paolo, > > Thank you to review the patch! > > On Aug 18, 2014, at 9:57 PM, Paolo Bonzini wrote: > >> Il 14/08/2014 09:01, Xiao Guangrong ha scritto: >>> - update_memslots(slots, new, kvm->memslots->generation); >>> + /* ensure generati

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread David Matlack
On Mon, Aug 18, 2014 at 9:35 AM, Xiao Guangrong wrote: > > Hi Paolo, > > Thank you to review the patch! > > On Aug 18, 2014, at 9:57 PM, Paolo Bonzini wrote: > >> Il 14/08/2014 09:01, Xiao Guangrong ha scritto: >>> -update_memslots(slots, new, kvm->memslots->generation); >>> +/* ensure ge

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Xiao Guangrong
Hi Paolo, Thank you to review the patch! On Aug 18, 2014, at 9:57 PM, Paolo Bonzini wrote: > Il 14/08/2014 09:01, Xiao Guangrong ha scritto: >> -update_memslots(slots, new, kvm->memslots->generation); >> +/* ensure generation number is always increased. */ >> +slots->generation = o

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-18 Thread Paolo Bonzini
Il 14/08/2014 09:01, Xiao Guangrong ha scritto: > - update_memslots(slots, new, kvm->memslots->generation); > + /* ensure generation number is always increased. */ > + slots->generation = old_memslots->generation; > + update_memslots(slots, new); > rcu_assign_pointer(kvm->mems

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-14 Thread Xiao Guangrong
Sorry, the title is not clear enough. This is the v2 which fixes the issue pointed out by David: " the generation number actually decreases." Please review. On 08/14/2014 03:01 PM, Xiao Guangrong wrote: > We may cache the current mmio generation number and stale memslot info > into spte, like t

[PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-14 Thread Xiao Guangrong
We may cache the current mmio generation number and stale memslot info into spte, like this scenario: CPU 0 CPU 1 page fault:add a new memslot read memslot and detecting its a mmio access

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-13 Thread Xiao Guangrong
On 08/13/2014 05:18 AM, David Matlack wrote: > On Mon, Aug 11, 2014 at 10:02 PM, Xiao Guangrong > wrote: >> @@ -722,9 +719,10 @@ static struct kvm_memslots *install_new_memslots(struct >> kvm *kvm, >> { >> struct kvm_memslots *old_memslots = kvm->memslots; >> > > I think you want > >

Re: [PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-12 Thread David Matlack
On Mon, Aug 11, 2014 at 10:02 PM, Xiao Guangrong wrote: > @@ -722,9 +719,10 @@ static struct kvm_memslots *install_new_memslots(struct > kvm *kvm, > { > struct kvm_memslots *old_memslots = kvm->memslots; > I think you want slots->generation = old_memslots->generation; here. On the

[PATCH 1/2] KVM: fix cache stale memslot info with correct mmio generation number

2014-08-11 Thread Xiao Guangrong
We may cache the current mmio generation number and stale memslot info into spte, like this scenario: CPU 0 CPU 1 page fault:add a new memslot read memslot and detecting its a mmio access