Skip to content

Switch get/put unaligned to use memcpy

Ian Rogers linux-parisc lkml oe-kbuild-all 5 versions – Applied

Status from this message: The following commit has been merged into the timers/vdso branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest4 patches 23 repliesApplied
  2. v43 patches 0 repliesApplied
  3. v33 patches 5 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches4 repliesSuperseded
v13 patches3 repliesSuperseded

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/4parisc: Inline a type punning version of get_unaligned_le32arch/parisc/boot/compressed/misc.c+14 -10 replies
2/4vdso: Switch get/put unaligned from packed struct to memcpyinclude/vdso/unaligned.h+35 -623 replies
3/4tools headers: Update the linux/unaligned.h copy with the kernel sourcestools/include/linux/compiler_types.h tools/include/vdso/unaligned.h+57 -60 replies
4/4tools headers: Remove unneeded ignoring of warnings in unaligned.htools/include/linux/unaligned.h+0 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/4] Switch get/put unaligned to use memcpy

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 was not true in the tools directory until this patch from Eric Biggers <[email protected]>:
https://lore.kernel.org/lkml/[email protected]/

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

v5: add a patch to make parisc still use a punned version of
get_unaligned_le32 for an unusual boot case they have. This is untested but suggested as necessary by:
https://lore.kernel.org/lkml/[email protected]/
I wasn't clear if this work was picked up, but I don't see it in v6.18-rc1 and so I'm resending rebased as v5.

v4: switch the type/expression variable __get_unaligned_ctrl_type that
is used by _Generic to be a pointer to avoid 0 vs NULL usage warnings - always use NULL and dereference the type. This should also hopefully address analysis bots complaints.

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 <[email protected]>:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (4):
parisc: Inline a type punning version of get_unaligned_le32
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

 arch/parisc/boot/compressed/misc.c   | 15 +++++++++-
 include/vdso/unaligned.h             | 41 ++++++++++++++++++++++++----
 tools/include/linux/compiler_types.h | 22 +++++++++++++++
 tools/include/linux/unaligned.h      |  4 ---
 tools/include/vdso/unaligned.h       | 41 ++++++++++++++++++++++++----
 5 files changed, 106 insertions(+), 17 deletions(-)
Signature · 1 line
2.51.0.858.gf9c4a03a3a-goog