[PATCH 2/3] arm64: Optimize __READ_ONCE() with CONFIG_LTO=y

David Laight david.laight.linux at gmail.com
Tue Jan 27 10:54:24 PST 2026


On Tue, 27 Jan 2026 16:04:45 +0100
Marco Elver <elver at google.com> wrote:

...
> I think the bigger issue was 'volatile': "Passing a volatile-qualified
> pointer to READ_ONCE() is an absolute
> trainwreck for code generation [...]" per dee081bf8f82.
> 
> While the above with the temporary is gone for the asm-generic
> version, the arm64 LTO still has the temporary and we need some
> qualifier-stripping helper.

I've done some real experiments, see https://www.godbolt.org/z/n9f91dGe3

If you don't strip the volatile you get a 'trainwreck'.
Visible on godbolt for the short sub-structure function f_v_s().
Fixable using __unqual_typeof__().

But the code for anything over 8 bytes is also a trainwreck.
eg: for an int[4] in a sub-structure:
	return __READ_ONCE(s->s_i).i[2];
f_s_i:
        sub     sp, sp, #16
        ldr     x8, [x0, #56]
        str     x8, [sp, #8]
        ldr     w8, [x0, #64]
        str     w8, [sp, #4]
        ldr     w9, [x0, #68]
        mov     w0, w8
        str     w9, [sp], #16
        ret
(The same code for a char[4] is fine...)

For integral types you can get a variable of the unqualified
type with:
	auto v = (typeof(x))0;
but that doesn't help here because the code needs to read short structures.

For long structures member by member access will give better code.
I'm not sure they should be allowed.
(and there may not be any.)

	David



More information about the linux-arm-kernel mailing list