All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] Switch get/put unaligned to use memcpy
@ 2025-06-26  5:48 Ian Rogers
  2025-06-26  5:48 ` [PATCH v3 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Ian Rogers @ 2025-06-26  5:48 UTC (permalink / raw)
  To: Eric Biggers, Yuzhuo Jing, Andy Lutomirski, Thomas Gleixner,
	Vincenzo Frascino, Arnaldo Carvalho de Melo, Al Viro,
	Christophe Leroy, Jason A. Donenfeld, linux-kernel,
	linux-perf-users
  Cc: Ian Rogers

The existing type punning approach with packed structs requires
 -fno-strict-aliasing to be passed to the compiler for
correctness. This is true in the kernel tree but not in the tools
directory resulting in this suggested patch from Eric Biggers
 <ebiggers@google.com>:
https://lore.kernel.org/lkml/20250625202311.23244-2-ebiggers@kernel.org/

Requiring -fno-strict-aliasing seems unfortunate and so this patch
makes the unaligned code work via memcpy for type punning rather than
the packed attribute.

v3: switch to __unqual_scalar_typeof, reducing the code, and use an
    uninitialized variable rather than a cast of 0 to try to avoid a
    sparse warning about not using NULL. The code is trying to
    navigate a minefield of uninitialized and casting warnings,
    hopefully the best balance has been struck, but the code will fail
    for cases like:
    const void *val = get_unaligned((const void * const *)ptr);
    due to __unqual_scalar_typeof leaving the 2nd const of the cast in
    place. Thankfully no code does this - tested with an
    allyesconfig. Support would be achievable by using void* as a
    default case in __unqual_scalar_typeof, it just doesn't seem worth
    it for a fairly unusual const case.

v2: switch memcpy to __builtin_memcpy to avoid potential/disallowed
    memcpy calls in vdso caused by -fno-builtin. Reported by
    Christophe Leroy <christophe.leroy@csgroup.eu>:
    https://lore.kernel.org/lkml/c57de5bf-d55c-48c5-9dfa-e2fb844dafe9@csgroup.eu/

Ian Rogers (3):
  vdso: Switch get/put unaligned from packed struct to memcpy
  tools headers: Update the linux/unaligned.h copy with the kernel
    sources
  tools headers: Remove unneeded ignoring of warnings in unaligned.h

 include/vdso/unaligned.h             | 39 +++++++++++++++++++++++-----
 tools/include/linux/compiler_types.h | 22 ++++++++++++++++
 tools/include/linux/unaligned.h      |  4 ---
 tools/include/vdso/unaligned.h       | 39 +++++++++++++++++++++++-----
 4 files changed, 88 insertions(+), 16 deletions(-)

-- 
2.50.0.727.gbf7dc18ff4-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-08-18 16:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26  5:48 [PATCH v3 0/3] Switch get/put unaligned to use memcpy Ian Rogers
2025-06-26  5:48 ` [PATCH v3 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-27  7:58   ` kernel test robot
2025-07-05  0:05   ` kernel test robot
2025-07-22 15:56     ` Thomas Gleixner
2025-07-22 16:44       ` Ian Rogers
2025-07-22 17:00         ` Ian Rogers
2025-07-23 22:14           ` David Laight
2025-08-18 16:03           ` Ian Rogers
2025-06-26  5:48 ` [PATCH v3 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
2025-06-26  5:48 ` [PATCH v3 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.