Re: arm64 mrs and system registers

From: Andrew Turner <andrew_at_fubar.geek.nz>
Date: Tue, 09 Apr 2024 08:20:43 UTC

> On 8 Apr 2024, at 22:03, Paul Floyd <pjfloyd@wanadoo.fr> wrote:
> 
> 
> 
>> On 8 Apr 2024, at 22:31, Warner Losh <imp@bsdimp.com> wrote:
>> 
>> 
>> 
>> On Mon, Apr 8, 2024 at 9:03 PM Paul Floyd <pjfloyd@wanadoo.fr> wrote:
>> Hi
>> 
>> I've been looking at this bugzilla item
>> 
>> https://bugs.kde.org/show_bug.cgi?id=392146
>> 
>> Is there any difference between Linux and FreeBSD when it comes to what 
>> registers and fields are exposed by the kernel (see comment 17 in the 
>> link above).
>> 
>> I don't think so. We've not seen issues with other drivers on aarch64 except
>> when they were written on x86 and didn't have the synchronization needed
>> for the weaker memory models in aarch64 systems.
>>  I did have a poke around the kernel code but it's a bit hard to tell 
>> exactly which of the access macros are being used, without exhaustively 
>> grepping for them one by one.
>> 
>> Yea, I think that there's missing atomics on the state transitions and/or
>> some missing locking that "magically" provides barriers that make it work
>> on x86.
>> 
> 
> Hi
> 
> There aren’t any memory issues.
> 
> The problem is that the opcodes aren’t fully covered. There are 3 aspects to that
> 1. What the kernel exposes
> 2. What Valgrind implements (usually a subset of point 1 but it should claim things that the kernel doesn’t support).
> 3. Actually handling the opcode.
> 
> If Linux and FreeBSD expose the same things then I can go ahead with looking at a common solution.

The list of registers FreeBSD handles are in user_mrs_handler [1]. They are midr_el1, mpidr_el1, revid_el1, and anything that looks like it should be an id_aa64 register. See the comment there for the exact list.

When adding support I wrote a tool to read the Arm special registers [2]. It should run on both FreeBSD and Linux, although the register order may not be identical.

Andrew

[1] https://cgit.freebsd.org/src/tree/sys/arm64/arm64/identcpu.c?id=da2b732288c72b347b128e1fa9a169c7bba3beb8#n1907
[2] https://github.com/zxombie/arm64id