mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Catalin Marinas <catalin.marinas@arm.com>
Cc: Rich Felker <dalias@libc.org>, Szabolcs Nagy <nsz@port70.net>,
	"musl@lists.openwall.com" <musl@lists.openwall.com>,
	Kees Cook <keescook@chromium.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	Andy Lutomirski <luto@amacapital.net>
Subject: Re: ARM atomics overhaul for musl
Date: Mon, 17 Nov 2014 15:47:39 +0000	[thread overview]
Message-ID: <20141117154739.GT4042@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20141117152624.GF20652@localhost>

On Mon, Nov 17, 2014 at 03:26:25PM +0000, Catalin Marinas wrote:
> On Mon, Nov 17, 2014 at 02:39:05PM +0000, Russell King - ARM Linux wrote:
> > Given that even cocked these up (just as what happened with the cache
> > type register) decoding of the feature type registers depends on the
> > underlying CPU architecture.
> > 
> > So, even _if_ we exported the feature registers to userspace, you still
> > need to know the CPU architecture to decode them properly, so you still
> > need to parse the AT_PLATFORM string to get that information.
> 
> >From ARMv7 and many recent ARMv6, you can rely on the MIDR to tell you
> whether you have the extended CPUID or not. Prior to that, MIDR contains
> the architecture number.

That is not what I'm referring to.  Where the feature registers are
implemented, there are at least two different interpretations of these
feature registers.  They do not comprise of a single coherent set of
definitions - the meaning of some nibbles were changed between different
architectures.

> So what would you like to set it to? "v7l"? Even for pre-ARMv8 CPUs,
> such value doesn't give enough information and user space should rely on
> hwcap (yes, we missed a HWCAP_DMB because we relied on kuser helpers;
> another big thing we missed is Thumb-2 in hwcap).

Shall we look at the entire code fragment again, and this time use our
heads to *think* about it first?

        const char *ptr;
        int architecture;

        ptr = (const char *)(uintptr_t)getauxval(AT_PLATFORM);
        assert(ptr);

        if (!strncmp(ptr, "aarch64", 7))
                architecture = 8;
        else
                assert(sscanf(ptr, "v%d", &architecture) == 1);

        switch (architecture) {
        case 4:
        case 5:
                no_mcr_dmb;
                break;
        case 6:
                use_mcr;
                break;
        default:
                use_dmb;
                break;
        }

Now, if 32-bit ARMv8 returns "v8l" from the AT_PLATFORM auxval, then
it is not equal to "aarch64".  So, we fall through th sscanf().  sscanf()
parses the "v8l" string, and sets "architecture" to 8.

We now enter the switch() statement.  8 isn't 4.  8 also isn't 5.  Nor is
it 6.  So, we fall through to the "default" section, which uses "use_dmb".

That's the correct answer for ARMv8 CPUs, because we don't want to use
the MCR instruction there, nor do we want to do nothing.  That is not
coincidence - it was /specifically/ designed to select that outcome for
any architecture value it didn't explicitly know.  The assumption there
is that ARM are not going to deprecate and remove the dmb instruction.

So it doesn't matter if there's a v9, v10, v11, v12 etc.  It'll continue
to select the dmb method until the code is modified to do otherwise.

So, maybe I'm not as stupid as you first thought, and maybe I /did/ think
about this carefully about the possible scenarios before suggesting this
code fragment as a solution.

-- 
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.


  reply	other threads:[~2014-11-17 15:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-16  5:56 Rich Felker
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 [this message]
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=20141117154739.GT4042@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=catalin.marinas@arm.com \
    --cc=dalias@libc.org \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --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).