From: Alexander Graf <agraf@suse.de>
To: kvm-ppc <kvm-ppc@vger.kernel.org>
Cc: KVM <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
Paul Mackerras <paulus@samba.org>
Subject: [PULL 07/12] KVM: PPC: Book3S HV: Fix race in reading change bit when removing HPTE
Date: Sat, 22 Aug 2015 09:21:30 +0000 [thread overview]
Message-ID: <1440235295-244203-8-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1440235295-244203-1-git-send-email-agraf@suse.de>
From: Paul Mackerras <paulus@samba.org>
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
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
arch/powerpc/kvm/book3s_hv_rm_mmu.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_hv_rm_mmu.c b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
index b027a89..c6d601c 100644
--- a/arch/powerpc/kvm/book3s_hv_rm_mmu.c
+++ b/arch/powerpc/kvm/book3s_hv_rm_mmu.c
@@ -421,14 +421,20 @@ 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);
+ /*
+ * 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 re-read the HPTE after
+ * the invalidation sequence has completed in order to
+ * obtain reliable values of R and C.
+ */
+ remove_revmap_chain(kvm, pte_index, rev, v,
+ be64_to_cpu(hpte[1]));
}
r = rev->guest_rpte & ~HPTE_GR_RESERVED;
note_hpte_modification(kvm, rev);
--
1.8.1.4
next prev parent reply other threads:[~2015-08-22 9:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-22 9:21 [PULL 00/12] ppc patch queue 2015-08-22 Alexander Graf
2015-08-22 9:21 ` [PULL 01/12] KVM: PPC: fix suspicious use of conditional operator Alexander Graf
2015-08-22 9:21 ` [PULL 02/12] KVM: PPC: Remove PPC970 from KVM_BOOK3S_64_HV text in Kconfig Alexander Graf
2015-08-22 9:21 ` [PULL 03/12] KVM: PPC: Fix warnings from sparse Alexander Graf
2015-08-22 9:21 ` [PULL 04/12] KVM: PPC: add missing pt_regs initialization Alexander Graf
2015-08-22 9:21 ` [PULL 05/12] KVM: PPC: Book3S HV: Make use of unused threads when running guests Alexander Graf
2015-08-22 9:21 ` [PULL 06/12] KVM: PPC: Book3S HV: Implement dynamic micro-threading on POWER8 Alexander Graf
2015-08-22 9:21 ` Alexander Graf [this message]
2015-08-22 9:21 ` [PULL 08/12] KVM: PPC: Book3S HV: Fix bug in dirty page tracking Alexander Graf
2015-08-22 9:21 ` [PULL 09/12] KVM: PPC: Book3S HV: Implement H_CLEAR_REF and H_CLEAR_MOD Alexander Graf
2015-08-22 9:21 ` [PULL 10/12] KVM: PPC: Book3S HV: Fix preempted vcore list locking Alexander Graf
2015-08-22 9:21 ` [PULL 11/12] KVM: PPC: Book3S HV: Fix preempted vcore stolen time calculation Alexander Graf
2015-08-22 9:21 ` [PULL 12/12] KVM: PPC: Book3S: correct width in XER handling Alexander Graf
2015-08-22 22:32 ` [PULL 00/12] ppc patch queue 2015-08-22 Paolo Bonzini
2015-08-24 4:49 ` Alexander Graf
2015-08-24 8:52 ` Paolo Bonzini
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=1440235295-244203-8-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=paulus@samba.org \
--cc=pbonzini@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox