mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32
@ 2026-10-29  9:17 Julian Vetter
  2026-10-29  9:17 ` [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers Julian Vetter
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Julian Vetter @ 2026-10-29  9:17 UTC (permalink / raw)
  To: Andrew Morton, Arnaldo Carvalho de Melo, Namhyung Kim
  Cc: Arnd Bergmann, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	James Clark, linux-perf-users, linux-kernel, Julian Vetter

This is the remainder of my series removing the deprecated
__get_unaligned_cpuX() helpers. Patch 1/5 of the previous version was
already applied as commit 50b4233a22b1 ("include/linux/jhash.h: replace
__get_unaligned_cpu32 in jhash function"), so this version only contains
the remaining patches, rebased onto current master.

There are no users of the helpers left in the tree, so patch 1 removes
include/linux/unaligned/packed_struct.h. Patch 2 does the same for the
tools copy.

Signed-off-by: Julian Vetter <julian@outer-limits.org>
---
Changes in v2:
- Drop patch 1/5 -> already applied
- Squash the three tools patches (3/5, 4/5, 5/5) into one
- Include linux/kernel.h explicitly. It was previously pulled in through
  packed_struct.h
- Also drop the "#pragma GCC diagnostic" in check-headers.sh. The
  pragmas were removed in commit 10a62a0611f5 ("tools headers: Remove
  unneeded ignoring of warnings in unaligned.h")

v1 (RESEND): https://lore.kernel.org/lkml/20250707122500.724699-1-julian@outer-limits.org/
---
Julian Vetter (2):
  include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX()
    helpers
  tools/include/linux/jhash.h: replace __get_unaligned_cpu32 in jhash
    function

 include/linux/unaligned.h                     |  1 -
 include/linux/unaligned/packed_struct.h       | 46 ------------------
 tools/include/linux/jhash.h                   |  9 ++--
 tools/include/linux/unaligned/packed_struct.h | 47 -------------------
 tools/perf/check-headers.sh                   |  2 +-
 5 files changed, 6 insertions(+), 99 deletions(-)
 delete mode 100644 include/linux/unaligned/packed_struct.h
 delete mode 100644 tools/include/linux/unaligned/packed_struct.h


base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
-- 
2.53.0


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

* [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers
  2026-10-29  9:17 [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Julian Vetter
@ 2026-10-29  9:17 ` Julian Vetter
  2026-10-29 11:11   ` David Laight
  2026-10-29  9:17 ` [PATCH v2 2/2] tools/include/linux/jhash.h: replace __get_unaligned_cpu32 in jhash function Julian Vetter
  2026-10-29 12:43 ` [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Arnd Bergmann
  2 siblings, 1 reply; 5+ messages in thread
From: Julian Vetter @ 2026-10-29  9:17 UTC (permalink / raw)
  To: Andrew Morton, Arnaldo Carvalho de Melo, Namhyung Kim
  Cc: Arnd Bergmann, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	James Clark, linux-perf-users, linux-kernel, Julian Vetter

The __get_unaligned_cpu16/32/64() and __put_unaligned_cpu16/32/64()
helpers are deprecated and all users have been converted to the more
generic get_unaligned() and put_unaligned(). So, remove
linux/unaligned/packed_struct.h, and drop its inclusion from
linux/unaligned.h.

Signed-off-by: Julian Vetter <julian@outer-limits.org>
---
 include/linux/unaligned.h               |  1 -
 include/linux/unaligned/packed_struct.h | 46 -------------------------
 2 files changed, 47 deletions(-)
 delete mode 100644 include/linux/unaligned/packed_struct.h

diff --git a/include/linux/unaligned.h b/include/linux/unaligned.h
index 4a9651017e3c..18c4b0c00e2a 100644
--- a/include/linux/unaligned.h
+++ b/include/linux/unaligned.h
@@ -6,7 +6,6 @@
  * This is the most generic implementation of unaligned accesses
  * and should work almost anywhere.
  */
-#include <linux/unaligned/packed_struct.h>
 #include <asm/byteorder.h>
 #include <vdso/unaligned.h>
 
diff --git a/include/linux/unaligned/packed_struct.h b/include/linux/unaligned/packed_struct.h
deleted file mode 100644
index f4c8eaf4d012..000000000000
--- a/include/linux/unaligned/packed_struct.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
-#define _LINUX_UNALIGNED_PACKED_STRUCT_H
-
-#include <linux/types.h>
-
-struct __una_u16 { u16 x; } __packed;
-struct __una_u32 { u32 x; } __packed;
-struct __una_u64 { u64 x; } __packed;
-
-static inline u16 __get_unaligned_cpu16(const void *p)
-{
-	const struct __una_u16 *ptr = (const struct __una_u16 *)p;
-	return ptr->x;
-}
-
-static inline u32 __get_unaligned_cpu32(const void *p)
-{
-	const struct __una_u32 *ptr = (const struct __una_u32 *)p;
-	return ptr->x;
-}
-
-static inline u64 __get_unaligned_cpu64(const void *p)
-{
-	const struct __una_u64 *ptr = (const struct __una_u64 *)p;
-	return ptr->x;
-}
-
-static inline void __put_unaligned_cpu16(u16 val, void *p)
-{
-	struct __una_u16 *ptr = (struct __una_u16 *)p;
-	ptr->x = val;
-}
-
-static inline void __put_unaligned_cpu32(u32 val, void *p)
-{
-	struct __una_u32 *ptr = (struct __una_u32 *)p;
-	ptr->x = val;
-}
-
-static inline void __put_unaligned_cpu64(u64 val, void *p)
-{
-	struct __una_u64 *ptr = (struct __una_u64 *)p;
-	ptr->x = val;
-}
-
-#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */
-- 
2.53.0


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

* [PATCH v2 2/2] tools/include/linux/jhash.h: replace __get_unaligned_cpu32 in jhash function
  2026-10-29  9:17 [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Julian Vetter
  2026-10-29  9:17 ` [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers Julian Vetter
@ 2026-10-29  9:17 ` Julian Vetter
  2026-10-29 12:43 ` [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Arnd Bergmann
  2 siblings, 0 replies; 5+ messages in thread
From: Julian Vetter @ 2026-10-29  9:17 UTC (permalink / raw)
  To: Andrew Morton, Arnaldo Carvalho de Melo, Namhyung Kim
  Cc: Arnd Bergmann, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	James Clark, linux-perf-users, linux-kernel, Julian Vetter

__get_unaligned_cpu32() is deprecated. So, replace it with the more
generic get_unaligned() and just cast the input parameter, like it was
done for the kernel copy of jhash.h.

linux/unaligned/packed_struct.h used to pull in linux/kernel.h, which
provides the byte order helpers needed by linux/unaligned.h, so include
it explicitly.

With jhash.h converted, the tools copy of packed_struct.h has no users
left, so remove it. Also drop the packed_struct.h and "#pragma GCC
diagnostic" in check-headers.sh.

Signed-off-by: Julian Vetter <julian@outer-limits.org>
---
 tools/include/linux/jhash.h                   |  9 ++--
 tools/include/linux/unaligned/packed_struct.h | 47 -------------------
 tools/perf/check-headers.sh                   |  2 +-
 3 files changed, 6 insertions(+), 52 deletions(-)
 delete mode 100644 tools/include/linux/unaligned/packed_struct.h

diff --git a/tools/include/linux/jhash.h b/tools/include/linux/jhash.h
index af8d0fe1c6ce..df524ee14bcd 100644
--- a/tools/include/linux/jhash.h
+++ b/tools/include/linux/jhash.h
@@ -24,7 +24,8 @@
  * Jozsef
  */
 #include <linux/bitops.h>
-#include <linux/unaligned/packed_struct.h>
+#include <linux/kernel.h>
+#include <linux/unaligned.h>
 
 /* Best hash sizes are of power of two */
 #define jhash_size(n)   ((u32)1<<(n))
@@ -77,9 +78,9 @@ static inline u32 jhash(const void *key, u32 length, u32 initval)
 
 	/* All but the last block: affect some 32 bits of (a,b,c) */
 	while (length > 12) {
-		a += __get_unaligned_cpu32(k);
-		b += __get_unaligned_cpu32(k + 4);
-		c += __get_unaligned_cpu32(k + 8);
+		a += get_unaligned((u32 *)k);
+		b += get_unaligned((u32 *)(k + 4));
+		c += get_unaligned((u32 *)(k + 8));
 		__jhash_mix(a, b, c);
 		length -= 12;
 		k += 12;
diff --git a/tools/include/linux/unaligned/packed_struct.h b/tools/include/linux/unaligned/packed_struct.h
deleted file mode 100644
index dbd93c7df2e1..000000000000
--- a/tools/include/linux/unaligned/packed_struct.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
-#define _LINUX_UNALIGNED_PACKED_STRUCT_H
-
-#include <linux/kernel.h>
-
-struct __una_u16 { u16 x; } __packed;
-struct __una_u32 { u32 x; } __packed;
-struct __una_u64 { u64 x; } __packed;
-
-static inline u16 __get_unaligned_cpu16(const void *p)
-{
-	const struct __una_u16 *ptr = (const struct __una_u16 *)p;
-	return ptr->x;
-}
-
-static inline u32 __get_unaligned_cpu32(const void *p)
-{
-	const struct __una_u32 *ptr = (const struct __una_u32 *)p;
-	return ptr->x;
-}
-
-static inline u64 __get_unaligned_cpu64(const void *p)
-{
-	const struct __una_u64 *ptr = (const struct __una_u64 *)p;
-	return ptr->x;
-}
-
-static inline void __put_unaligned_cpu16(u16 val, void *p)
-{
-	struct __una_u16 *ptr = (struct __una_u16 *)p;
-	ptr->x = val;
-}
-
-static inline void __put_unaligned_cpu32(u32 val, void *p)
-{
-	struct __una_u32 *ptr = (struct __una_u32 *)p;
-	ptr->x = val;
-}
-
-static inline void __put_unaligned_cpu64(u64 val, void *p)
-{
-	struct __una_u64 *ptr = (struct __una_u64 *)p;
-	ptr->x = val;
-}
-
-#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 531c0e0e84df..39d9c7182f9b 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -187,7 +187,7 @@ done
 check arch/x86/lib/memcpy_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memcpy_\(erms\|orig\))" -I"^#include <linux/cfi_types.h>"'
 check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
 check arch/x86/include/asm/amd/ibs.h  '-I "^#include .*/msr-index.h"'
-check include/linux/unaligned.h '-I "^#include <linux/unaligned/packed_struct.h>" -I "^#include <asm/byteorder.h>" -I "^#pragma GCC diagnostic"'
+check include/linux/unaligned.h '-I "^#include <asm/byteorder.h>"'
 check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
 check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
 check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
-- 
2.53.0


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

* Re: [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers
  2026-10-29  9:17 ` [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers Julian Vetter
@ 2026-10-29 11:11   ` David Laight
  0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2026-10-29 11:11 UTC (permalink / raw)
  To: Julian Vetter
  Cc: Andrew Morton, Arnaldo Carvalho de Melo, Namhyung Kim,
	Arnd Bergmann, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	James Clark, linux-perf-users, linux-kernel

On Thu, 29 Oct 2026 10:17:35 +0100
Julian Vetter <julian@outer-limits.org> wrote:

> The __get_unaligned_cpu16/32/64() and __put_unaligned_cpu16/32/64()
> helpers are deprecated and all users have been converted to the more
> generic get_unaligned() and put_unaligned().

Ugg...

get_unaligned() relies on you having a pointer that is misaligned for its
type.
IIUC that is UB and the compiler can (at least sometimes) remember the
alignment use memory accesses that fault.

In reality it is get_unaligned() that should be deprecated, leaving only
the 16/32/64 le/be/cpu functions that operate on a 'u8 *' parameter for
accessing generic buffers.
Every thing else should be using packed structures.

David

> So, remove
> linux/unaligned/packed_struct.h, and drop its inclusion from
> linux/unaligned.h.
> 
> Signed-off-by: Julian Vetter <julian@outer-limits.org>
> ---
>  include/linux/unaligned.h               |  1 -
>  include/linux/unaligned/packed_struct.h | 46 -------------------------
>  2 files changed, 47 deletions(-)
>  delete mode 100644 include/linux/unaligned/packed_struct.h
> 
> diff --git a/include/linux/unaligned.h b/include/linux/unaligned.h
> index 4a9651017e3c..18c4b0c00e2a 100644
> --- a/include/linux/unaligned.h
> +++ b/include/linux/unaligned.h
> @@ -6,7 +6,6 @@
>   * This is the most generic implementation of unaligned accesses
>   * and should work almost anywhere.
>   */
> -#include <linux/unaligned/packed_struct.h>
>  #include <asm/byteorder.h>
>  #include <vdso/unaligned.h>
>  
> diff --git a/include/linux/unaligned/packed_struct.h b/include/linux/unaligned/packed_struct.h
> deleted file mode 100644
> index f4c8eaf4d012..000000000000
> --- a/include/linux/unaligned/packed_struct.h
> +++ /dev/null
> @@ -1,46 +0,0 @@
> -#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H
> -#define _LINUX_UNALIGNED_PACKED_STRUCT_H
> -
> -#include <linux/types.h>
> -
> -struct __una_u16 { u16 x; } __packed;
> -struct __una_u32 { u32 x; } __packed;
> -struct __una_u64 { u64 x; } __packed;
> -
> -static inline u16 __get_unaligned_cpu16(const void *p)
> -{
> -	const struct __una_u16 *ptr = (const struct __una_u16 *)p;
> -	return ptr->x;
> -}
> -
> -static inline u32 __get_unaligned_cpu32(const void *p)
> -{
> -	const struct __una_u32 *ptr = (const struct __una_u32 *)p;
> -	return ptr->x;
> -}
> -
> -static inline u64 __get_unaligned_cpu64(const void *p)
> -{
> -	const struct __una_u64 *ptr = (const struct __una_u64 *)p;
> -	return ptr->x;
> -}
> -
> -static inline void __put_unaligned_cpu16(u16 val, void *p)
> -{
> -	struct __una_u16 *ptr = (struct __una_u16 *)p;
> -	ptr->x = val;
> -}
> -
> -static inline void __put_unaligned_cpu32(u32 val, void *p)
> -{
> -	struct __una_u32 *ptr = (struct __una_u32 *)p;
> -	ptr->x = val;
> -}
> -
> -static inline void __put_unaligned_cpu64(u64 val, void *p)
> -{
> -	struct __una_u64 *ptr = (struct __una_u64 *)p;
> -	ptr->x = val;
> -}
> -
> -#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */


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

* Re: [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32
  2026-10-29  9:17 [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Julian Vetter
  2026-10-29  9:17 ` [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers Julian Vetter
  2026-10-29  9:17 ` [PATCH v2 2/2] tools/include/linux/jhash.h: replace __get_unaligned_cpu32 in jhash function Julian Vetter
@ 2026-10-29 12:43 ` Arnd Bergmann
  2 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2026-10-29 12:43 UTC (permalink / raw)
  To: Julian Vetter, Andrew Morton, Arnaldo Carvalho de Melo, Namhyung Kim
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
	linux-perf-users, linux-kernel

On Thu, Oct 29, 2026, at 10:17, Julian Vetter wrote:
> This is the remainder of my series removing the deprecated
> __get_unaligned_cpuX() helpers. Patch 1/5 of the previous version was
> already applied as commit 50b4233a22b1 ("include/linux/jhash.h: replace
> __get_unaligned_cpu32 in jhash function"), so this version only contains
> the remaining patches, rebased onto current master.
>
> There are no users of the helpers left in the tree, so patch 1 removes
> include/linux/unaligned/packed_struct.h. Patch 2 does the same for the
> tools copy.
>
> Signed-off-by: Julian Vetter <julian@outer-limits.org>
> ---
> Changes in v2:
> - Drop patch 1/5 -> already applied
> - Squash the three tools patches (3/5, 4/5, 5/5) into one
> - Include linux/kernel.h explicitly. It was previously pulled in through
>   packed_struct.h
> - Also drop the "#pragma GCC diagnostic" in check-headers.sh. The
>   pragmas were removed in commit 10a62a0611f5 ("tools headers: Remove
>   unneeded ignoring of warnings in unaligned.h")

Looks good, I've applied this to my preliminary asm-generic tree so I
don't forget about it. I'll rebase this next week for integration
into linux-next and 7.5.

Thanks for finishing this work!

      Arnd

[1] https://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic.git/log/?h=asm-generic

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

end of thread, other threads:[~2026-10-29 12:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29  9:17 [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Julian Vetter
2026-10-29  9:17 ` [PATCH v2 1/2] include/linux/unaligned.h: remove deprecated __get_unaligned_cpuX() helpers Julian Vetter
2026-10-29 11:11   ` David Laight
2026-10-29  9:17 ` [PATCH v2 2/2] tools/include/linux/jhash.h: replace __get_unaligned_cpu32 in jhash function Julian Vetter
2026-10-29 12:43 ` [PATCH v2 0/2] Remove remaining __get_unaligned_cpu32 Arnd Bergmann

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®