virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: David Vrabel <dvrabel@cantab.net>
To: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	peterz@infradead.org, torvalds@linux-foundation.org,
	konrad.wilk@oracle.com, pbonzini@redhat.com
Cc: waiman.long@hp.com, jeremy@goop.org, ak@linux.intel.com,
	kvm@vger.kernel.org, paul.gortmaker@windriver.com,
	a.ryabinin@samsung.com, x86@kernel.org, oleg@redhat.com,
	linux-kernel@vger.kernel.org, borntraeger@de.ibm.com,
	dave@stgolabs.net, davej@redhat.com,
	xen-devel@lists.xenproject.org, akpm@linux-foundation.org,
	paulmck@linux.vnet.ibm.com,
	virtualization@lists.linux-foundation.org,
	sasha.levin@oracle.com
Subject: Re: [Xen-devel] [PATCH V5] x86 spinlock: Fix memory corruption on completing completions
Date: Mon, 16 Feb 2015 16:47:12 +0000	[thread overview]
Message-ID: <54E21F10.1040402@cantab.net> (raw)
In-Reply-To: <20150215173043.GA7471@linux.vnet.ibm.com>

On 15/02/15 17:30, Raghavendra K T wrote:
> --- a/arch/x86/xen/spinlock.c
> +++ b/arch/x86/xen/spinlock.c
> @@ -41,7 +41,7 @@ static u8 zero_stats;
>  static inline void check_zero(void)
>  {
>  	u8 ret;
> -	u8 old = ACCESS_ONCE(zero_stats);
> +	u8 old = READ_ONCE(zero_stats);
>  	if (unlikely(old)) {
>  		ret = cmpxchg(&zero_stats, old, 0);
>  		/* This ensures only one fellow resets the stat */
> @@ -112,6 +112,7 @@ __visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want)
>  	struct xen_lock_waiting *w = this_cpu_ptr(&lock_waiting);
>  	int cpu = smp_processor_id();
>  	u64 start;
> +	__ticket_t head;
>  	unsigned long flags;
>  
>  	/* If kicker interrupts not initialized yet, just spin */
> @@ -159,11 +160,15 @@ __visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want)
>  	 */
>  	__ticket_enter_slowpath(lock);
>  
> +	/* make sure enter_slowpath, which is atomic does not cross the read */
> +	smp_mb__after_atomic();
> +
>  	/*
>  	 * check again make sure it didn't become free while
>  	 * we weren't looking
>  	 */
> -	if (ACCESS_ONCE(lock->tickets.head) == want) {
> +	head = READ_ONCE(lock->tickets.head);
> +	if (__tickets_equal(head, want)) {
>  		add_stats(TAKEN_SLOW_PICKUP, 1);
>  		goto out;
>  	}
> @@ -204,8 +209,8 @@ static void xen_unlock_kick(struct arch_spinlock *lock, __ticket_t next)
>  		const struct xen_lock_waiting *w = &per_cpu(lock_waiting, cpu);
>  
>  		/* Make sure we read lock before want */
> -		if (ACCESS_ONCE(w->lock) == lock &&
> -		    ACCESS_ONCE(w->want) == next) {
> +		if (READ_ONCE(w->lock) == lock &&
> +		    READ_ONCE(w->want) == next) {
>  			add_stats(RELEASED_SLOW_KICKED, 1);
>  			xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
>  			break;

Acked-by: David Vrabel <david.vrabel@citrix.com>

Although some of the ACCESS_ONCE to READ_ONCE changes are cosmetic and
are perhaps best left out of a patch destined for stable.

David

  parent reply	other threads:[~2015-02-16 16:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-15  5:55 [PATCH V5] x86 spinlock: Fix memory corruption on completing completions Raghavendra K T
2015-02-15  6:01 ` Raghavendra K T
2015-02-17 18:26   ` Sasha Levin
2015-02-15 16:17 ` Oleg Nesterov
2015-02-15 17:34   ` Raghavendra K T
2015-02-15 17:30 ` Raghavendra K T
2015-02-15 20:31   ` Oleg Nesterov
2015-02-16 16:47   ` David Vrabel [this message]
2015-02-17 10:03     ` [Xen-devel] " Raghavendra K T

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=54E21F10.1040402@cantab.net \
    --to=dvrabel@cantab.net \
    --cc=a.ryabinin@samsung.com \
    --cc=ak@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=borntraeger@de.ibm.com \
    --cc=dave@stgolabs.net \
    --cc=davej@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=konrad.wilk@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=raghavendra.kt@linux.vnet.ibm.com \
    --cc=sasha.levin@oracle.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=waiman.long@hp.com \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.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).