From: Jason Low <jason.low2@hpe.com>
To: Waiman Long <waiman.long@hpe.com>
Cc: jason.low2@hp.com, Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Terry Rudd <terry.rudd@hpe.com>,
Scott J Norton <scott.norton@hpe.com>
Subject: Re: [PATCH] locking/mutex: Set and clear owner using WRITE_ONCE()
Date: Fri, 20 May 2016 15:09:45 -0700 [thread overview]
Message-ID: <1463782185.2479.6.camel@j-VirtualBox> (raw)
In-Reply-To: <573F734C.7050708@hpe.com>
On Fri, 2016-05-20 at 16:27 -0400, Waiman Long wrote:
> On 05/19/2016 06:23 PM, Jason Low wrote:
> > The mutex owner can get read and written to without the wait_lock.
> > Use WRITE_ONCE when setting and clearing the owner field in order
> > to avoid optimizations such as store tearing. This avoids
> > situations where the owner field gets written to with multiple
> > stores and another thread could concurrently read and use a
> > partially written owner value.
> >
> > Signed-off-by: Jason Low<jason.low2@hpe.com>
> > ---
> > kernel/locking/mutex.h | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/locking/mutex.h b/kernel/locking/mutex.h
> > index 5cda397..469b61e 100644
> > --- a/kernel/locking/mutex.h
> > +++ b/kernel/locking/mutex.h
> > @@ -17,14 +17,20 @@
> > __list_del((waiter)->list.prev, (waiter)->list.next)
> >
> > #ifdef CONFIG_MUTEX_SPIN_ON_OWNER
> > +/*
> > + * The mutex owner can get read and written to locklessly.
> > + * We should use WRITE_ONCE() when writing the owner value to
> > + * avoid store tearing, otherwise, a thread could potentially
> > + * read a partially written and incomplete owner value.
> > + */
> > static inline void mutex_set_owner(struct mutex *lock)
> > {
> > - lock->owner = current;
> > + WRITE_ONCE(lock->owner, current);
> > }
> >
> > static inline void mutex_clear_owner(struct mutex *lock)
> > {
> > - lock->owner = NULL;
> > + WRITE_ONCE(lock->owner, NULL);
> > }
> > #else
> > static inline void mutex_set_owner(struct mutex *lock)
>
> I think mutex-debug.h also needs similar changes for completeness.
Good point, I will add the changes to those functions in the debug case
to this patch.
Thanks,
Jason
next prev parent reply other threads:[~2016-05-20 22:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-19 22:23 [PATCH] locking/mutex: Set and clear owner using WRITE_ONCE() Jason Low
2016-05-20 1:19 ` Davidlohr Bueso
2016-05-20 20:27 ` Waiman Long
2016-05-20 22:09 ` Jason Low [this message]
2016-05-21 1:00 ` Davidlohr Bueso
2016-05-21 4:09 ` Waiman Long
2016-05-23 20:40 ` Jason Low
2016-05-23 21:31 ` Davidlohr Bueso
2016-05-23 21:49 ` Jason Low
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=1463782185.2479.6.camel@j-VirtualBox \
--to=jason.low2@hpe.com \
--cc=dave@stgolabs.net \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=scott.norton@hpe.com \
--cc=terry.rudd@hpe.com \
--cc=waiman.long@hpe.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 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.