From: "Arnd Bergmann" <arnd@arndb.de>
To: "Ian Rogers" <irogers@google.com>,
"Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Thomas Gleixner" <tglx@linutronix.de>,
"Stefan Kerkmann" <s.kerkmann@pengutronix.de>,
"James E . J . Bottomley" <James.Bottomley@hansenpartnership.com>,
"Helge Deller" <deller@gmx.de>,
"Andy Lutomirski" <luto@kernel.org>,
"Vincenzo Frascino" <vincenzo.frascino@arm.com>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Eric Biggers" <ebiggers@google.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Jason A . Donenfeld" <Jason@zx2c4.com>
Subject: Re: [Regression] [PATCH v5 2/4] vdso: Switch get/put unaligned from packed struct to memcpy
Date: Mon, 19 Oct 2026 18:27:24 +0200 [thread overview]
Message-ID: <18c92ae1-deaa-4c09-adca-157819cf005b@app.fastmail.com> (raw)
In-Reply-To: <CAP-5=fUwDOv9k1Ptz22h9kKYFJowg9UPa+LzWnnswJ72ptF8tA@mail.gmail.com>
On Mon, Oct 19, 2026, at 17:10, Ian Rogers wrote:
> On Mon, Oct 19, 2026 at 5:37 AM Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>> On 10.10.2026 08:04:42, Ian Rogers wrote:
>
> It is a little more manual than automagic :-) When perf builds there
> is a script that complains if the tools' version of files is
> out-of-sync with the kernel's:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/check-headers.sh#n28
> It doesn't break the perf build, it just adds noise to it.
I see that the include/linux/unaligned.h and tools/include/linux/unaligned.h
headers have not been in sync for a long time, so maybe it's just not
a big deal there.
> My understanding, biased by my opinions, is that the preferred option
> is to add a config variable controlling whether to use memcpy or a
> packed struct. My preference, to avoid undefined behavior, is to
> default to memcpy but set it to use packed structs for ARMv5. I will
> vibe code this up, and apologize in advance for any offense such a
> patch series may cause (ie I'm sure someone on LKML will want to
> complain at me for using memcpy at all and give me a lecture about
> strict aliasing being nonsense, etc.). Arnd or someone else may have a
> different preferred solution, to which I'm more than happy to defer.
As I wrote, we need the packed struct version at least on mips32,
mips64, openrisc, riscv32, riscv64, sh4, sparc32, and sparc64 to avoid
the external library calls the same as on armv5, but I would prefer
to just always use that in the kernel. My guess is that this list
is actually the same as the architectures that lack unaligned word
access instructions in hardware, and armv5 is certainly not
a special case.
For 7.4 (and stable kernels) reverting the in-kernel header seems
best to me, and then we can think about what to use for the tools.
Looking at the uses of get_unaligned() in the tools directory,
I notice that at least some of them should just not exist, e.g.
struct debug_entry in tools/perf/util/jitdump.h is just
needs a __packed attribute to correctly describe what it does,
and tools/testing/cxl/test/mem.c does not need the unaligned
helpers at all because the structs are all packed already.
I'm also a bit suspicious of the usage in
tools/testing/selftests/bpf/test_kmods/bpf_testmod.c, which
looks like it may run into a corner case:
__bpf_kfunc int bpf_kfunc_test_uninit_alias(int *out__uninit, const int *in)
{
int value = get_unaligned(in);
put_unaligned(42, out__uninit);
return value;
}
The current version of get_unaligned() turns into __builtin_memcpy(),
and the function prototype defines both arguments as pointers
to naturally aligned objects. Do you see anything that would
stop the compiler from replacing the __builtin_memcpy() with
an invalid pointer dereference? This bit is probably fine
because of the way gcc handles __builtin_memcpy() optimization,
but I'm not sure if that's an implementation detail or required
by the C standard, especially if strict aliasing rules say
that the int* argument cannot overlap a misaligned int*.
Arnd
next prev parent reply other threads:[~2026-10-19 16:28 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 20:51 [PATCH v5 0/4] Switch get/put unaligned to use memcpy Ian Rogers
2025-10-16 20:51 ` [PATCH v5 1/4] parisc: Inline a type punning version of get_unaligned_le32 Ian Rogers
2026-01-13 13:47 ` [tip: timers/vdso] parisc: Inline a type punning version of get_unaligned_le32() tip-bot2 for Ian Rogers
2026-01-14 8:01 ` tip-bot2 for Ian Rogers
2025-10-16 20:51 ` [PATCH v5 2/4] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-10-19 17:24 ` David Laight
2026-01-13 13:47 ` [tip: timers/vdso] vdso: Switch get/put_unaligned() from packed struct to memcpy() tip-bot2 for Ian Rogers
2026-01-14 8:01 ` tip-bot2 for Ian Rogers
2026-09-28 15:39 ` [Regression] [PATCH v5 2/4] vdso: Switch get/put unaligned from packed struct to memcpy Stefan Kerkmann
2026-09-28 15:58 ` Ian Rogers
2026-10-06 12:31 ` Marc Kleine-Budde
2026-10-07 10:59 ` Arnd Bergmann
2026-10-09 21:28 ` Ian Rogers
2026-10-10 10:26 ` Christophe Leroy (CS GROUP)
2026-10-10 12:20 ` Ian Rogers
2026-10-10 14:06 ` Arnd Bergmann
2026-10-10 15:04 ` Ian Rogers
2026-10-19 12:37 ` Marc Kleine-Budde
2026-10-19 15:10 ` Ian Rogers
2026-10-19 16:27 ` Arnd Bergmann [this message]
2026-10-19 17:04 ` Ian Rogers
2026-10-19 21:00 ` Arnd Bergmann
2026-10-19 21:14 ` Ian Rogers
2026-10-19 22:05 ` Arnd Bergmann
2025-10-16 20:51 ` [PATCH v5 3/4] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
2026-01-13 13:47 ` [tip: timers/vdso] " tip-bot2 for Ian Rogers
2026-01-14 8:01 ` tip-bot2 for Ian Rogers
2025-10-16 20:51 ` [PATCH v5 4/4] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers
2026-01-13 13:47 ` [tip: timers/vdso] " tip-bot2 for Ian Rogers
2026-01-14 8:01 ` tip-bot2 for Ian Rogers
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=18c92ae1-deaa-4c09-adca-157819cf005b@app.fastmail.com \
--to=arnd@arndb.de \
--cc=James.Bottomley@hansenpartnership.com \
--cc=Jason@zx2c4.com \
--cc=acme@redhat.com \
--cc=christophe.leroy@csgroup.eu \
--cc=deller@gmx.de \
--cc=ebiggers@google.com \
--cc=irogers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mkl@pengutronix.de \
--cc=s.kerkmann@pengutronix.de \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®