mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: Andy Lutomirski <luto@amacapital.net>,
	Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Szabolcs Nagy <nsz@port70.net>, Kees Cook <keescook@chromium.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: ARM atomics overhaul for musl
Date: Sun, 16 Nov 2014 00:56:56 -0500	[thread overview]
Message-ID: <20141116055656.GA13940@brightrain.aerifal.cx> (raw)

One item on the agenda for this release cycle is overhauling the way
atomics are done on ARM. I'm cc'ing people who have been involved in
this discussion in the past in case anyone's not on the musl list and
has opinions about what should be done.

The current situation looks like the following:

Pre-v6: Hard-coded to use cas from kuser_helper page (0xffff0fc0)

v6: Hard-coded to use ldrex/strex with mcr-based barrier

v7+: Hard-coded to use ldrex/strex with dmb-based barrier

In the cases where ldrex/strex are used directly, they're still not
used optimally; all the non-cas primitives like atomic inc/dec are
built on top of cas and thus have more loop complexity and probably
more barriers than they should.

Aside from that, the only case among the above that's "right" already
is v7+. Hard-coding the mcr-based barrier on v6 is wrong because it's
deprecated (future models may not support the instruction, and
although the kernel could trap and emulate it this would be horribly
slow) and hard-coding kuser helper on pre-v6 is wrong because pre-v6
binaries might run on v6+ hardware and kernel where the kernel has
been built with the kuser_helper page removed for security.

My main goals for this overhaul are:

1. Make baseline (pre-v6) binaries truely universal so they run even
   on kernels with kuser_helper removed.

2. Make v7+ perform competitively. This means optimal code sequences
   for a_cas, a_swap, a_fetch_add, a_store, etc. rather than just
   doing everything with a_cas.

What's still not entirely clear is what to do with v6, and how goal #1
should be achieved. The options are basically:

A. Prefer using ldrex/strex and an appropriate barrier directly, but
   fall back to kuser_helper (assuming it's present) if the hwcap or
   similar does not indicate availability of atomics.

B. Prefer kuser_helper and and only fallback to using atomics and an
   appropriate barrier directly if kuser_helper page is missing.

Of these two approaches, A seems easier, because it's easier to know
that atomics are available (via HWCAP_TLS) than that kuser_helper is
(which requires some sort of probe for the mapping if we want to
support grsec kernels where the mapping is completely missing; if not,
we can just check the kuser version number at a fixed address).
However neither is really very easy because it seems impossible to
detect whether the mcr-based barrier or the dmb-based barrier should
be used -- there's no hwcap flag to indicate support for the latter.
This also complicates what to do in builds for v6.

Before proceeding, I think we need some sort of proposed way to detect
the availability of dmb. If there really is none, we probably need to
go with option B (prefer kuser_helper) for both pre-v6 and v6 (i.e.
only use atomics directly on v7+) and choose what to do when
kuser_helper is missing: either assume v7+ and use dmb, or assume that
the mcr barrier is still working and use it. I think I would lean
towards the latter.

Rich


             reply	other threads:[~2014-11-16  5:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-16  5:56 Rich Felker [this message]
2014-11-16 16:33 ` Russell King - ARM Linux
2014-11-16 16:50   ` Rich Felker
2014-11-16 17:10     ` Russell King - ARM Linux
2014-11-16 18:27       ` Andy Lutomirski
2014-11-16 18:56         ` Rich Felker
2014-11-16 19:02       ` Rich Felker
2014-11-17 13:54       ` Catalin Marinas
2014-11-17 14:11         ` Szabolcs Nagy
2014-11-17 14:47           ` Catalin Marinas
2014-11-17 14:39         ` Russell King - ARM Linux
2014-11-17 15:26           ` Catalin Marinas
2014-11-17 15:47             ` Russell King - ARM Linux
2014-11-17 16:19               ` Catalin Marinas
2014-11-17 16:53                 ` Russell King - ARM Linux
2014-11-17 17:48                   ` Catalin Marinas
2014-11-17 17:38           ` Andy Lutomirski
2014-11-18 10:56             ` Catalin Marinas
2014-11-18 18:14               ` Will Deacon
2014-11-18 18:24                 ` Andy Lutomirski
2014-11-18 19:19                 ` Russell King - ARM Linux
2014-11-19 18:32                 ` Catalin Marinas
2014-11-17 11:48   ` Catalin Marinas
2014-11-17 12:21     ` Arnd Bergmann
2014-11-17 13:30       ` Szabolcs Nagy
2014-11-17 14:34         ` Catalin Marinas
2014-11-16 22:33 ` Jens Gustedt
2014-11-16 23:23   ` Rich Felker

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=20141116055656.GA13940@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@arm.linux.org.uk \
    --cc=luto@amacapital.net \
    --cc=musl@lists.openwall.com \
    --cc=nsz@port70.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).