linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@ozlabs.org, kvm list <kvm@vger.kernel.org>,
	kvm-ppc@vger.kernel.org, Avi Kivity <avi@redhat.com>
Subject: Re: [PATCH v3 12/14] KVM: Add barriers to allow mmu_notifier_retry to be used locklessly
Date: Mon, 19 Dec 2011 18:18:58 +0100	[thread overview]
Message-ID: <29064998-0526-435B-A8BA-DB6BF9CDED46@suse.de> (raw)
In-Reply-To: <20111212223720.GM18868@bloggs.ozlabs.ibm.com>


On 12.12.2011, at 23:37, Paul Mackerras wrote:

> This adds an smp_wmb in kvm_mmu_notifier_invalidate_range_end() and an
> smp_rmb in mmu_notifier_retry() so that mmu_notifier_retry() will give
> the correct answer when called without kvm->mmu_lock being held.
> PowerPC Book3S HV KVM wants to use a bitlock per guest page rather =
than
> a single global spinlock in order to improve the scalability of =
updates
> to the guest MMU hashed page table, and so needs this.
>=20
> Signed-off-by: Paul Mackerras <paulus@samba.org>

Avi, mind to ack?


Alex

> ---
> include/linux/kvm_host.h |   14 +++++++++-----
> virt/kvm/kvm_main.c      |    6 +++---
> 2 files changed, 12 insertions(+), 8 deletions(-)
>=20
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 8c5c303..ec79a45 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -700,12 +700,16 @@ static inline int mmu_notifier_retry(struct =
kvm_vcpu *vcpu, unsigned long mmu_se
> 	if (unlikely(vcpu->kvm->mmu_notifier_count))
> 		return 1;
> 	/*
> -	 * Both reads happen under the mmu_lock and both values are
> -	 * modified under mmu_lock, so there's no need of smb_rmb()
> -	 * here in between, otherwise mmu_notifier_count should be
> -	 * read before mmu_notifier_seq, see
> -	 * mmu_notifier_invalidate_range_end write side.
> +	 * Ensure the read of mmu_notifier_count happens before the read
> +	 * of mmu_notifier_seq.  This interacts with the smp_wmb() in
> +	 * mmu_notifier_invalidate_range_end to make sure that the =
caller
> +	 * either sees the old (non-zero) value of mmu_notifier_count or
> +	 * the new (incremented) value of mmu_notifier_seq.
> +	 * PowerPC Book3s HV KVM calls this under a per-page lock
> +	 * rather than under kvm->mmu_lock, for scalability, so
> +	 * can't rely on kvm->mmu_lock to keep things ordered.
> 	 */
> +	smp_rmb();
> 	if (vcpu->kvm->mmu_notifier_seq !=3D mmu_seq)
> 		return 1;
> 	return 0;
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index e289486..c144132 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -357,11 +357,11 @@ static void =
kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn,
> 	 * been freed.
> 	 */
> 	kvm->mmu_notifier_seq++;
> +	smp_wmb();
> 	/*
> 	 * The above sequence increase must be visible before the
> -	 * below count decrease but both values are read by the kvm
> -	 * page fault under mmu_lock spinlock so we don't need to add
> -	 * a smb_wmb() here in between the two.
> +	 * below count decrease, which is ensured by the smp_wmb above
> +	 * in conjunction with the smp_rmb in mmu_notifier_retry().
> 	 */
> 	kvm->mmu_notifier_count--;
> 	spin_unlock(&kvm->mmu_lock);
> --=20
> 1.7.7.3
>=20

  reply	other threads:[~2011-12-19 17:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12 22:23 [PATCH v3 00/14] KVM: PPC: Update Book3S HV memory handling Paul Mackerras
2011-12-12 22:24 ` [PATCH v3 01/14] KVM: PPC: Make wakeups work again for Book3S HV guests Paul Mackerras
2011-12-12 22:26 ` [PATCH v3 02/14] KVM: PPC: Move kvm_vcpu_ioctl_[gs]et_one_reg down to platform-specific code Paul Mackerras
2011-12-12 22:27 ` [PATCH v3 03/14] KVM: PPC: Keep a record of HV guest view of hashed page table entries Paul Mackerras
2011-12-12 22:28 ` [PATCH v3 04/14] KVM: PPC: Keep page physical addresses in per-slot arrays Paul Mackerras
2011-12-19 15:10   ` Alexander Graf
2011-12-12 22:28 ` [PATCH v3 05/14] KVM: PPC: Add an interface for pinning guest pages in Book3s HV guests Paul Mackerras
2011-12-12 22:30 ` [PATCH v3 06/14] KVM: PPC: Make the H_ENTER hcall more reliable Paul Mackerras
2011-12-12 22:31 ` [PATCH v3 07/14] KVM: PPC: Only get pages when actually needed, not in prepare_memory_region() Paul Mackerras
2011-12-12 22:31 ` [PATCH v3 08/14] KVM: PPC: Allow use of small pages to back Book3S HV guests Paul Mackerras
2011-12-12 22:32 ` [PATCH v3 09/14] KVM: PPC: Allow I/O mappings in memory slots Paul Mackerras
2011-12-12 22:33 ` [PATCH v3 10/14] KVM: PPC: Maintain a doubly-linked list of guest HPTEs for each gfn Paul Mackerras
2011-12-12 22:36 ` [PATCH v3 11/14] KVM: PPC: Implement MMIO emulation support for Book3S HV guests Paul Mackerras
2011-12-12 22:37 ` [PATCH v3 12/14] KVM: Add barriers to allow mmu_notifier_retry to be used locklessly Paul Mackerras
2011-12-19 17:18   ` Alexander Graf [this message]
2011-12-19 17:21     ` Avi Kivity
2011-12-12 22:38 ` [PATCH v3 13/14] KVM: PPC: Implement MMU notifiers for Book3S HV guests Paul Mackerras
2011-12-12 22:38 ` [PATCH v3 14/14] KVM: PPC: Allow for read-only pages backing a Book3S HV guest Paul Mackerras
2011-12-19 17:39 ` [PATCH v3 00/14] KVM: PPC: Update Book3S HV memory handling 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=29064998-0526-435B-A8BA-DB6BF9CDED46@suse.de \
    --to=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).