All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org,
	Nathan Whitehorn <nwhitehorn@freebsd.org>
Subject: Re: [PATCH 1/3] KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE
Date: Tue, 28 Apr 2015 09:10:45 +0000	[thread overview]
Message-ID: <20150428091045.GA10461@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <87fv7k96z7.fsf@linux.vnet.ibm.com>

On Tue, Apr 28, 2015 at 10:36:52AM +0530, Aneesh Kumar K.V wrote:
> Paul Mackerras <paulus@samba.org> writes:
> 
> > The reference (R) and change (C) bits in a HPT entry can be set by
> > hardware at any time up until the HPTE is invalidated and the TLB
> > invalidation sequence has completed.  This means that when removing
> > a HPTE, we need to read the HPTE after the invalidation sequence has
> > completed in order to obtain reliable values of R and C.  The code
> > in kvmppc_do_h_remove() used to do this.  However, commit 6f22bd3265fb
> > ("KVM: PPC: Book3S HV: Make HTAB code LE host aware") removed the
> > read after invalidation as a side effect of other changes.  This
> > restores the read of the HPTE after invalidation.
> >
> > The user-visible effect of this bug would be that when migrating a
> > guest, there is a small probability that a page modified by the guest
> > and then unmapped by the guest might not get re-transmitted and thus
> > the destination might end up with a stale copy of the page.
> >
> > Fixes: 6f22bd3265fb
> > Cc: stable@vger.kernel.org # v3.17+
> > Signed-off-by: Paul Mackerras <paulus@samba.org>
> > ---
> >  arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > index f6bf0b1..5c1737f 100644
> > --- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > +++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > @@ -413,14 +413,12 @@ long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
> >  	rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]);
> >  	v = pte & ~HPTE_V_HVLOCK;
> >  	if (v & HPTE_V_VALID) {
> > -		u64 pte1;
> > -
> > -		pte1 = be64_to_cpu(hpte[1]);
> >  		hpte[0] &= ~cpu_to_be64(HPTE_V_VALID);
> > -		rb = compute_tlbie_rb(v, pte1, pte_index);
> > +		rb = compute_tlbie_rb(v, be64_to_cpu(hpte[1]), pte_index);
> >  		do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true);
> >  		/* Read PTE low word after tlbie to get final R/C values */
> > -		remove_revmap_chain(kvm, pte_index, rev, v, pte1);
> > +		remove_revmap_chain(kvm, pte_index, rev, v,
> > +				    be64_to_cpu(hpte[1]));
> >  	}
> 
> May be add the above commit message as a code comment ?

Well, that's what "/* Read PTE low word after tlbie to get final R/C
values */" was trying to be, originally, but maybe it would be helpful
to expand on it.

Paul.

WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org,
	Nathan Whitehorn <nwhitehorn@freebsd.org>
Subject: Re: [PATCH 1/3] KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE
Date: Tue, 28 Apr 2015 19:10:45 +1000	[thread overview]
Message-ID: <20150428091045.GA10461@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <87fv7k96z7.fsf@linux.vnet.ibm.com>

On Tue, Apr 28, 2015 at 10:36:52AM +0530, Aneesh Kumar K.V wrote:
> Paul Mackerras <paulus@samba.org> writes:
> 
> > The reference (R) and change (C) bits in a HPT entry can be set by
> > hardware at any time up until the HPTE is invalidated and the TLB
> > invalidation sequence has completed.  This means that when removing
> > a HPTE, we need to read the HPTE after the invalidation sequence has
> > completed in order to obtain reliable values of R and C.  The code
> > in kvmppc_do_h_remove() used to do this.  However, commit 6f22bd3265fb
> > ("KVM: PPC: Book3S HV: Make HTAB code LE host aware") removed the
> > read after invalidation as a side effect of other changes.  This
> > restores the read of the HPTE after invalidation.
> >
> > The user-visible effect of this bug would be that when migrating a
> > guest, there is a small probability that a page modified by the guest
> > and then unmapped by the guest might not get re-transmitted and thus
> > the destination might end up with a stale copy of the page.
> >
> > Fixes: 6f22bd3265fb
> > Cc: stable@vger.kernel.org # v3.17+
> > Signed-off-by: Paul Mackerras <paulus@samba.org>
> > ---
> >  arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > index f6bf0b1..5c1737f 100644
> > --- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > +++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
> > @@ -413,14 +413,12 @@ long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
> >  	rev = real_vmalloc_addr(&kvm->arch.revmap[pte_index]);
> >  	v = pte & ~HPTE_V_HVLOCK;
> >  	if (v & HPTE_V_VALID) {
> > -		u64 pte1;
> > -
> > -		pte1 = be64_to_cpu(hpte[1]);
> >  		hpte[0] &= ~cpu_to_be64(HPTE_V_VALID);
> > -		rb = compute_tlbie_rb(v, pte1, pte_index);
> > +		rb = compute_tlbie_rb(v, be64_to_cpu(hpte[1]), pte_index);
> >  		do_tlbies(kvm, &rb, 1, global_invalidates(kvm, flags), true);
> >  		/* Read PTE low word after tlbie to get final R/C values */
> > -		remove_revmap_chain(kvm, pte_index, rev, v, pte1);
> > +		remove_revmap_chain(kvm, pte_index, rev, v,
> > +				    be64_to_cpu(hpte[1]));
> >  	}
> 
> May be add the above commit message as a code comment ?

Well, that's what "/* Read PTE low word after tlbie to get final R/C
values */" was trying to be, originally, but maybe it would be helpful
to expand on it.

Paul.

  reply	other threads:[~2015-04-28  9:10 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-24  5:39 [PATCH 0/3] PPC HV bug fixes + hcalls for FreeBSD Paul Mackerras
2015-04-24  5:39 ` Paul Mackerras
2015-04-24  5:39 ` [PATCH 1/3] KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE Paul Mackerras
2015-04-24  5:39   ` Paul Mackerras
2015-04-28  5:06   ` Aneesh Kumar K.V
2015-04-28  5:18     ` Aneesh Kumar K.V
2015-04-28  9:10     ` Paul Mackerras [this message]
2015-04-28  9:10       ` Paul Mackerras
2015-04-24  5:39 ` [PATCH 2/3] KVM: PPC: Book3S HV: Fix bug in dirty page tracking Paul Mackerras
2015-04-24  5:39   ` Paul Mackerras
2015-04-24  5:39 ` [PATCH 3/3] KVM: PPC: Book3S HV: Implement H_CLEAR_REF and H_CLEAR_MOD Paul Mackerras
2015-04-24  5:39   ` Paul Mackerras
2015-07-27 17:31   ` Nathan Whitehorn
2015-07-27 17:31     ` Nathan Whitehorn
2015-09-06 19:47     ` Nathan Whitehorn
2015-09-06 19:47       ` Nathan Whitehorn
2015-09-06 23:52       ` Paul Mackerras
2015-09-06 23:52         ` Paul Mackerras
2015-09-07  0:46         ` Nathan Whitehorn
2015-09-07  0:46           ` Nathan Whitehorn
2015-09-12 16:47         ` Nathan Whitehorn
2015-09-12 16:47           ` Nathan Whitehorn
2015-09-12 16:51           ` Alexander Graf
2015-09-12 16:51             ` Alexander Graf

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=20150428091045.GA10461@iris.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=nwhitehorn@freebsd.org \
    /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 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.