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: Thu, 21 Nov 2019 19:32:57 +0100 [thread overview]
Message-ID: <20191121183257.GA124760@gmail.com> (raw)
In-Reply-To: <20191120155715.28089-1-elver@google.com>
* 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?
Thanks,
Ingo
next prev parent reply other threads:[~2019-11-21 18:33 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 [this message]
2019-11-21 19:44 ` Marco Elver
2019-11-29 7:04 ` Ingo Molnar
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=20191121183257.GA124760@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).