From: Mark Rutland <mark.rutland@arm.com>
To: bdegraaf@codeaurora.org
Cc: Will Deacon <will.deacon@arm.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Timur Tabi <timur@codeaurora.org>,
Nathan Lynch <nathan_lynch@mentor.com>,
linux-kernel@vger.kernel.org,
Christopher Covington <cov@codeaurora.org>,
linux-arm-kernel@lists.infradead.org, abooker@qti.qualcomm.com
Subject: Re: [RFC] arm64: Enforce observed order for spinlock and data
Date: Fri, 14 Oct 2016 01:24:12 +0100 [thread overview]
Message-ID: <20161014002412.GC24167@remoulade> (raw)
In-Reply-To: <f35bbb7a559933abfc559548e860d641@codeaurora.org>
On Thu, Oct 13, 2016 at 04:00:47PM -0400, bdegraaf@codeaurora.org wrote:
> On 2016-10-13 07:02, Will Deacon wrote:
> >Brent,
> >
> >On Wed, Oct 12, 2016 at 04:01:06PM -0400, bdegraaf@codeaurora.org wrote:
> >
> >Everything from this point down needs clarification.
> >
> >>All arm64 lockref accesses that occur without taking the spinlock must
> >>behave like true atomics, ensuring successive operations are all done
> >>sequentially.
> >
> >What is a "true atomic"? What do you mean by "successive"? What do you
> >mean by "done sequentially"?
>
> Despite the use case in dentry, lockref itself is a generic locking API, and
> any problems I describe here are with the generic API itself, not necessarily
> the dentry use case. I'm not patching dentry--I'm fixing lockref.
Having spent the best part of a week looking at this myself, my view is that if
there is any problem it's simply that the semantics of lockref are unclear; we
can fix that by clarifying the imprecise wording in the lockref documentation
(i.e. the comment block in <linux/lockref.h>).
As far as I can tell, the only fundamental requirement is that an agent holding
the lock won't see the count change under its feet. Ordering requirements for
agents performing updates without holding the lock were never strictly defined,
and the de-facto ordering requirements of existing users (e.g. none in the case
of the dentry cache) appear to be met.
[...]
> At the time lockref was introduced, The Linux Foundation gave a presentation
> at LinuxCon 2014 that can be found at the following link:
>
> https://events.linuxfoundation.org/sites/events/files/slides/linuxcon-2014-locking-final.pdf
>
> On page 46, it outlines the lockref API. The first lines of the slide give
> the
> relevant details.
>
> Lockref
> • *Generic* mechanism to *atomically* update a reference count that is
> protected by a spinlock without actually acquiring the spinlock itself.
... which is exactly what lockref does today. The count is updated atomically
(i.e. there are no intervening stores between the load and store to the count)
it's just that this atomic update has no enforced ordering against other memory
accesses.
This is a generically useful primitive, as-is.
> >Again, why is this a problem? It's exactly the same as if you did:
> >
> > spin_lock(lock);
> > inc_ref_cnt();
> > spin_unlock(lock);
> >
> >Accesses outside of the critical section can still be reordered. Big deal.
>
> Since the current code resembles but actually has *fewer* ordering effects
> compared to the example used by your atomic.h commit, even though A->B->C is
> in program order, it could access out of order according to your own commit
> text on commit 8e86f0b409a44193f1587e87b69c5dcf8f65be67.
This case is not comparable. The atomic_* API has a documented requirement that
the atomic operations in question operate as full barriers, as is called out in
the commit message. Lockref has no such documented requirement.
[...]
> Again, this is a generic API, not an API married to dentry. If it were for
> dentry's sole use, it should not be accessible outside of the dentry code.
> While the cmpxchg64_relaxed case may be OK for dentry, it is not OK for the
> generic case.
Again, you are assuming a specific set of semantics that lockref is not
documented as having (and which contemporary code does not require).
If you have a use-case for which you want stronger semantics, that is a
different story entirely.
Thanks,
Mark.
next prev parent reply other threads:[~2016-10-14 0:25 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 17:40 [RFC] arm64: Enforce observed order for spinlock and data Brent DeGraaf
2016-09-30 18:43 ` Robin Murphy
2016-10-01 15:45 ` bdegraaf
2016-09-30 18:52 ` Peter Zijlstra
2016-09-30 19:05 ` Peter Zijlstra
2016-10-01 15:59 ` bdegraaf
2016-09-30 19:32 ` Mark Rutland
2016-10-01 16:11 ` bdegraaf
2016-10-01 18:11 ` Mark Rutland
2016-10-03 19:20 ` bdegraaf
2016-10-04 6:50 ` Peter Zijlstra
2016-10-04 10:12 ` Mark Rutland
2016-10-04 17:53 ` bdegraaf
2016-10-04 18:28 ` bdegraaf
2016-10-04 19:12 ` Mark Rutland
2016-10-05 14:55 ` bdegraaf
2016-10-05 15:10 ` Peter Zijlstra
2016-10-05 15:30 ` bdegraaf
2016-10-12 20:01 ` bdegraaf
2016-10-13 11:02 ` Will Deacon
2016-10-13 20:00 ` bdegraaf
2016-10-14 0:24 ` Mark Rutland [this message]
2016-10-05 15:11 ` bdegraaf
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=20161014002412.GC24167@remoulade \
--to=mark.rutland@arm.com \
--cc=abooker@qti.qualcomm.com \
--cc=bdegraaf@codeaurora.org \
--cc=catalin.marinas@arm.com \
--cc=cov@codeaurora.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nathan_lynch@mentor.com \
--cc=peterz@infradead.org \
--cc=timur@codeaurora.org \
--cc=will.deacon@arm.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 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).