From: Ingo Molnar <mingo@kernel.org>
To: Marco Elver <elver@google.com>
Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org,
linux-kernel@vger.kernel.org, Qian Cai <cai@lca.pw>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] spinlock_debug: Fix various data races
Date: Fri, 29 Nov 2019 08:04:10 +0100 [thread overview]
Message-ID: <20191129070410.GA23979@gmail.com> (raw)
In-Reply-To: <20191121194418.GA239776@google.com>
* Marco Elver <elver@google.com> wrote:
> On Thu, 21 Nov 2019, Ingo Molnar wrote:
>
> >
> > * Marco Elver <elver@google.com> wrote:
> >
> > > static inline void debug_spin_lock_after(raw_spinlock_t *lock)
> > > {
> > > - lock->owner_cpu = raw_smp_processor_id();
> > > - lock->owner = current;
> > > + WRITE_ONCE(lock->owner_cpu, raw_smp_processor_id());
> > > + WRITE_ONCE(lock->owner, current);
> > > }
> >
> > debug_spin_lock_after() runs inside the spinlock itself - why do these
> > writes have to be WRITE_ONCE()?
> >
> > > @@ -197,8 +197,8 @@ static inline void debug_write_unlock(rwlock_t *lock)
> > > RWLOCK_BUG_ON(lock->owner != current, lock, "wrong owner");
> > > RWLOCK_BUG_ON(lock->owner_cpu != raw_smp_processor_id(),
> > > lock, "wrong CPU");
> > > - lock->owner = SPINLOCK_OWNER_INIT;
> > > - lock->owner_cpu = -1;
> > > + WRITE_ONCE(lock->owner, SPINLOCK_OWNER_INIT);
> > > + WRITE_ONCE(lock->owner_cpu, -1);
> > > }
> >
> > This too is running inside the critical section of the spinlock - why are
> > the WRITE_ONCE() calls necessary?
>
> Although the writes are inside the critical section, they are read
> concurrently outside the critical section, e.g. in
> debug_spin_lock_before(). In other words, the WRITE_ONCE pair with the
> READ_ONCE that are *outside* the critical section.
Fair enough!
Thanks,
Ingo
next prev parent reply other threads:[~2019-11-29 7:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 15:57 [PATCH] spinlock_debug: Fix various data races Marco Elver
2019-11-21 18:32 ` Ingo Molnar
2019-11-21 19:44 ` Marco Elver
2019-11-29 7:04 ` Ingo Molnar [this message]
2019-11-29 9:59 ` [tip: locking/core] locking/spinlock/debug: " tip-bot2 for Marco Elver
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=20191129070410.GA23979@gmail.com \
--to=mingo@kernel.org \
--cc=cai@lca.pw \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=will@kernel.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).