Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
@ 2026-10-19 20:12 Ian Rogers
  2026-10-19 20:12 ` [PATCH v1 2/2] tools headers: Update the vdso/unaligned.h copy with the kernel sources Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Ian Rogers @ 2026-10-19 20:12 UTC (permalink / raw)
  To: Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Arnd Bergmann, Stefan Kerkmann, Marc Kleine-Budde,
	Christophe Leroy
  Cc: David Laight, Arnaldo Carvalho de Melo, Namhyung Kim,
	Eric Biggers, Al Viro, Jason A . Donenfeld, Ian Rogers,
	linux-arm-kernel, linux-perf-users, linux-kernel

Commit a339671db64b ("vdso: Switch get/put_unaligned() from packed struct
to memcpy()") switched __get_unaligned_t() and __put_unaligned_t() from
using a __packed struct to __builtin_memcpy() to avoid strict aliasing
undefined behavior.

On ARMv5 with GCC, __builtin_memcpy() may not be inlined and instead emit
a much slower out-of-line memcpy() call. Add CONFIG_VDSO_UNALIGNED_PACKED,
enabled on ARMv5 (CPU_32v5), to use the __packed struct implementation on
ARMv5 while keeping __builtin_memcpy() elsewhere.

Fixes: a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to memcpy()")
Reported-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Closes: https://lore.kernel.org/lkml/47f8c30b-e326-4ff0-a2bc-5683209a9e2d@pengutronix.de/
Signed-off-by: Ian Rogers <irogers@google.com>
---
 include/vdso/unaligned.h | 16 ++++++++++++++++
 lib/vdso/Kconfig         |  8 ++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
index 9076483c9fbb..726fd15efc82 100644
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -4,6 +4,20 @@
 
 #include <linux/compiler_types.h>
 
+#ifdef CONFIG_VDSO_UNALIGNED_PACKED
+
+#define __get_unaligned_t(type, ptr) ({							\
+	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
+	__get_pptr->x;									\
+})
+
+#define __put_unaligned_t(type, val, ptr) do {						\
+	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
+	__put_pptr->x = (val);								\
+} while (0)
+
+#else /* !CONFIG_VDSO_UNALIGNED_PACKED */
+
 /**
  * __get_unaligned_t - read an unaligned value from memory.
  * @type:	the type to load from the pointer.
@@ -41,4 +55,6 @@
 			 sizeof(__put_unaligned_val));			\
 } while (0)
 
+#endif /* CONFIG_VDSO_UNALIGNED_PACKED */
+
 #endif /* __VDSO_UNALIGNED_H */
diff --git a/lib/vdso/Kconfig b/lib/vdso/Kconfig
index 597f5f0f9681..709eb193999f 100644
--- a/lib/vdso/Kconfig
+++ b/lib/vdso/Kconfig
@@ -23,3 +23,11 @@ config VDSO_GETRANDOM
 	select VDSO_DATASTORE
 	help
 	  Selected by architectures that support vDSO getrandom().
+
+config VDSO_UNALIGNED_PACKED
+	bool
+	default CPU_32v5
+	help
+	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
+	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
+	  out-of-line memcpy() calls instead of inlining byte accesses.
-- 
2.56.0.212.g129ede20d9-goog



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

* [PATCH v1 2/2] tools headers: Update the vdso/unaligned.h copy with the kernel sources
  2026-10-19 20:12 [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Ian Rogers
@ 2026-10-19 20:12 ` Ian Rogers
  2026-10-19 22:12 ` [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Arnd Bergmann
  2026-10-20 14:00 ` David Laight
  2 siblings, 0 replies; 11+ messages in thread
From: Ian Rogers @ 2026-10-19 20:12 UTC (permalink / raw)
  To: Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Arnd Bergmann, Stefan Kerkmann, Marc Kleine-Budde,
	Christophe Leroy
  Cc: David Laight, Arnaldo Carvalho de Melo, Namhyung Kim,
	Eric Biggers, Al Viro, Jason A . Donenfeld, Ian Rogers,
	linux-arm-kernel, linux-perf-users, linux-kernel

To pick up the changes in:

  vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/include/vdso/unaligned.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tools/include/vdso/unaligned.h b/tools/include/vdso/unaligned.h
index 9076483c9fbb..726fd15efc82 100644
--- a/tools/include/vdso/unaligned.h
+++ b/tools/include/vdso/unaligned.h
@@ -4,6 +4,20 @@
 
 #include <linux/compiler_types.h>
 
+#ifdef CONFIG_VDSO_UNALIGNED_PACKED
+
+#define __get_unaligned_t(type, ptr) ({							\
+	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
+	__get_pptr->x;									\
+})
+
+#define __put_unaligned_t(type, val, ptr) do {						\
+	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
+	__put_pptr->x = (val);								\
+} while (0)
+
+#else /* !CONFIG_VDSO_UNALIGNED_PACKED */
+
 /**
  * __get_unaligned_t - read an unaligned value from memory.
  * @type:	the type to load from the pointer.
@@ -41,4 +55,6 @@
 			 sizeof(__put_unaligned_val));			\
 } while (0)
 
+#endif /* CONFIG_VDSO_UNALIGNED_PACKED */
+
 #endif /* __VDSO_UNALIGNED_H */
-- 
2.56.0.212.g129ede20d9-goog



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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-19 20:12 [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Ian Rogers
  2026-10-19 20:12 ` [PATCH v1 2/2] tools headers: Update the vdso/unaligned.h copy with the kernel sources Ian Rogers
@ 2026-10-19 22:12 ` Arnd Bergmann
  2026-10-20  6:44   ` Marc Kleine-Budde
  2026-10-20 14:00 ` David Laight
  2 siblings, 1 reply; 11+ messages in thread
From: Arnd Bergmann @ 2026-10-19 22:12 UTC (permalink / raw)
  To: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Marc Kleine-Budde, Christophe Leroy
  Cc: David Laight, Arnaldo Carvalho de Melo, Namhyung Kim,
	Eric Biggers, Alexander Viro, Jason A . Donenfeld,
	linux-arm-kernel, linux-perf-users, linux-kernel

On Mon, Oct 19, 2026, at 22:12, Ian Rogers wrote:
> +
> +config VDSO_UNALIGNED_PACKED
> +	bool
> +	default CPU_32v5
> +	help
> +	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
> +	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
> +	  out-of-line memcpy() calls instead of inlining byte accesses.

As explained, I think this misrepresents the problem as Arm specific and
isn't the correct method for -munaligned-access targets on Arm, which
include CPU_32v3, CPU_32v4 and CPU_32v4T along with CPU_32v5.

I still hope we can use a version that just produces the intended code
on both -munaligned-access and -mno-unaligned-access targets like the
old version did.

     Arnd


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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-19 22:12 ` [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Arnd Bergmann
@ 2026-10-20  6:44   ` Marc Kleine-Budde
  2026-10-20  8:24     ` Arnd Bergmann
  0 siblings, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-10-20  6:44 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]

On 20.10.2026 00:12:57, Arnd Bergmann wrote:
> On Mon, Oct 19, 2026, at 22:12, Ian Rogers wrote:
> > +
> > +config VDSO_UNALIGNED_PACKED
> > +	bool
> > +	default CPU_32v5
> > +	help
> > +	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
> > +	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
> > +	  out-of-line memcpy() calls instead of inlining byte accesses.
>
> As explained, I think this misrepresents the problem as Arm specific and
> isn't the correct method for -munaligned-access targets on Arm, which
> include CPU_32v3, CPU_32v4 and CPU_32v4T along with CPU_32v5.
>
> I still hope we can use a version that just produces the intended code
> on both -munaligned-access and -mno-unaligned-access targets like the
> old version did.

FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
make use of it?

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20  6:44   ` Marc Kleine-Budde
@ 2026-10-20  8:24     ` Arnd Bergmann
  2026-10-20  8:41       ` Marc Kleine-Budde
  2026-10-20 14:56       ` Marc Kleine-Budde
  0 siblings, 2 replies; 11+ messages in thread
From: Arnd Bergmann @ 2026-10-20  8:24 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

On Tue, Oct 20, 2026, at 08:44, Marc Kleine-Budde wrote:
> On 20.10.2026 00:12:57, Arnd Bergmann wrote:
>> On Mon, Oct 19, 2026, at 22:12, Ian Rogers wrote:
>> > +
>> > +config VDSO_UNALIGNED_PACKED
>> > +	bool
>> > +	default CPU_32v5
>> > +	help
>> > +	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
>> > +	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
>> > +	  out-of-line memcpy() calls instead of inlining byte accesses.
>>
>> As explained, I think this misrepresents the problem as Arm specific and
>> isn't the correct method for -munaligned-access targets on Arm, which
>> include CPU_32v3, CPU_32v4 and CPU_32v4T along with CPU_32v5.
>>
>> I still hope we can use a version that just produces the intended code
>> on both -munaligned-access and -mno-unaligned-access targets like the
>> old version did.
>
> FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
> make use of it?

That would be better, but I still hope we can just get back to the
portable code across all architectures for the in-kernel version.

I have one more request for you: can you check /proc/cpu/alignment
on the system that shows the performance regression with and without
the patch? In your original report, you have shown that Ian's patch
caused the drop in performance and that it caused the added function
calls, but I don't see any sufficiently hot code path that would
actually explain the scale of the regression, unless there is now
also a case where get_unaligned() ends up doing the wrong case and
running into a fixup handler. If this happens, you should see a
nontrivial number of fixups listed in /proc/cpu/alignment. On
a working system, the numbers should all be low but likely nonzero
because there tend to be callers that still lack get_unaligned()
wrappers and just access misaligned pointers directly.

      Arnd


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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20  8:24     ` Arnd Bergmann
@ 2026-10-20  8:41       ` Marc Kleine-Budde
  2026-10-20  9:06         ` Arnd Bergmann
  2026-10-20 14:56       ` Marc Kleine-Budde
  1 sibling, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-10-20  8:41 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2701 bytes --]

On 20.10.2026 10:24:51, Arnd Bergmann wrote:
> On Tue, Oct 20, 2026, at 08:44, Marc Kleine-Budde wrote:
> > On 20.10.2026 00:12:57, Arnd Bergmann wrote:
> >> On Mon, Oct 19, 2026, at 22:12, Ian Rogers wrote:
> >> > +
> >> > +config VDSO_UNALIGNED_PACKED
> >> > +	bool
> >> > +	default CPU_32v5
> >> > +	help
> >> > +	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
> >> > +	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
> >> > +	  out-of-line memcpy() calls instead of inlining byte accesses.
> >>
> >> As explained, I think this misrepresents the problem as Arm specific and
> >> isn't the correct method for -munaligned-access targets on Arm, which
> >> include CPU_32v3, CPU_32v4 and CPU_32v4T along with CPU_32v5.
> >>
> >> I still hope we can use a version that just produces the intended code
> >> on both -munaligned-access and -mno-unaligned-access targets like the
> >> old version did.
> >
> > FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
> > make use of it?
>
> That would be better, but I still hope we can just get back to the
> portable code across all architectures for the in-kernel version.
>
> I have one more request for you: can you check /proc/cpu/alignment
> on the system that shows the performance regression with and without
> the patch?

I asked Stefan Kerkmann (who wrote the original regression report) the
same question, but we haven't had time for it yet. We'll get around to
it.

> In your original report, you have shown that Ian's patch
> caused the drop in performance and that it caused the added function
> calls, but I don't see any sufficiently hot code path that would
> actually explain the scale of the regression,

Don't underestimate the overhead of function calls on those old CPUs
with tiny I-caches.

Little side note: IIRC, even on ARMv7 you can measure the performance
overhead of the built-in, but disabled, function tracer.

> unless there is now
> also a case where get_unaligned() ends up doing the wrong case and
> running into a fixup handler. If this happens, you should see a
> nontrivial number of fixups listed in /proc/cpu/alignment. On
> a working system, the numbers should all be low but likely nonzero
> because there tend to be callers that still lack get_unaligned()
> wrappers and just access misaligned pointers directly.

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20  8:41       ` Marc Kleine-Budde
@ 2026-10-20  9:06         ` Arnd Bergmann
  0 siblings, 0 replies; 11+ messages in thread
From: Arnd Bergmann @ 2026-10-20  9:06 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

On Tue, Oct 20, 2026, at 10:41, Marc Kleine-Budde wrote:
> On 20.10.2026 10:24:51, Arnd Bergmann wrote:
>> On Tue, Oct 20, 2026, at 08:44, Marc Kleine-Budde wrote:
>>
>> That would be better, but I still hope we can just get back to the
>> portable code across all architectures for the in-kernel version.
>>
>> I have one more request for you: can you check /proc/cpu/alignment
>> on the system that shows the performance regression with and without
>> the patch?
>
> I asked Stefan Kerkmann (who wrote the original regression report) the
> same question, but we haven't had time for it yet. We'll get around to
> it.

Ok, thanks!

>> In your original report, you have shown that Ian's patch
>> caused the drop in performance and that it caused the added function
>> calls, but I don't see any sufficiently hot code path that would
>> actually explain the scale of the regression,
>
> Don't underestimate the overhead of function calls on those old CPUs
> with tiny I-caches.

What I meant is that I tried to look for calls to get_unaligned()
in the code path you'd hit with UBIFS on nand flash, and I only
found a possible call once per page written
(ebu_nand_write_page_hwecc), which should have a much lower
overhead than what you observe.

While ubifs does use crc32, it uses the lib/crc/ version rather
than the crypto/crc32c.c that you listed, and there is no
get_unaligned() in the lib/ one. If you have NOR flash, the
caller is likely do_write_buffer() calling map_word_load().
That one could explain the problem and could also be
optimized further if it turns out to be the bottleneck.

     Arnd


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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-19 20:12 [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Ian Rogers
  2026-10-19 20:12 ` [PATCH v1 2/2] tools headers: Update the vdso/unaligned.h copy with the kernel sources Ian Rogers
  2026-10-19 22:12 ` [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Arnd Bergmann
@ 2026-10-20 14:00 ` David Laight
  2 siblings, 0 replies; 11+ messages in thread
From: David Laight @ 2026-10-20 14:00 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Arnd Bergmann, Stefan Kerkmann, Marc Kleine-Budde,
	Christophe Leroy, Arnaldo Carvalho de Melo, Namhyung Kim,
	Eric Biggers, Al Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

On Mon, 19 Oct 2026 13:12:56 -0700
Ian Rogers <irogers@google.com> wrote:

> Commit a339671db64b ("vdso: Switch get/put_unaligned() from packed struct
> to memcpy()") switched __get_unaligned_t() and __put_unaligned_t() from
> using a __packed struct to __builtin_memcpy() to avoid strict aliasing
> undefined behavior.

Looking at it the vdso only uses it in the getrandom code for copy+zero.
Even then it only actually uses when misaligned transfers are supported
and the buffer itself is u8[] - so no strict aliasing issues.
So that code could very easily do something else and then the horrid defines
in vdso/unaligned.h could probably go away.

Then the kernel could go back to using packed structs (or something else
since that itself is possibly dubious).

David

> 
> On ARMv5 with GCC, __builtin_memcpy() may not be inlined and instead emit
> a much slower out-of-line memcpy() call. Add CONFIG_VDSO_UNALIGNED_PACKED,
> enabled on ARMv5 (CPU_32v5), to use the __packed struct implementation on
> ARMv5 while keeping __builtin_memcpy() elsewhere.
> 
> Fixes: a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to memcpy()")
> Reported-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
> Closes: https://lore.kernel.org/lkml/47f8c30b-e326-4ff0-a2bc-5683209a9e2d@pengutronix.de/
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  include/vdso/unaligned.h | 16 ++++++++++++++++
>  lib/vdso/Kconfig         |  8 ++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
> index 9076483c9fbb..726fd15efc82 100644
> --- a/include/vdso/unaligned.h
> +++ b/include/vdso/unaligned.h
> @@ -4,6 +4,20 @@
>  
>  #include <linux/compiler_types.h>
>  
> +#ifdef CONFIG_VDSO_UNALIGNED_PACKED
> +
> +#define __get_unaligned_t(type, ptr) ({							\
> +	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
> +	__get_pptr->x;									\
> +})
> +
> +#define __put_unaligned_t(type, val, ptr) do {						\
> +	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
> +	__put_pptr->x = (val);								\
> +} while (0)
> +
> +#else /* !CONFIG_VDSO_UNALIGNED_PACKED */
> +
>  /**
>   * __get_unaligned_t - read an unaligned value from memory.
>   * @type:	the type to load from the pointer.
> @@ -41,4 +55,6 @@
>  			 sizeof(__put_unaligned_val));			\
>  } while (0)
>  
> +#endif /* CONFIG_VDSO_UNALIGNED_PACKED */
> +
>  #endif /* __VDSO_UNALIGNED_H */
> diff --git a/lib/vdso/Kconfig b/lib/vdso/Kconfig
> index 597f5f0f9681..709eb193999f 100644
> --- a/lib/vdso/Kconfig
> +++ b/lib/vdso/Kconfig
> @@ -23,3 +23,11 @@ config VDSO_GETRANDOM
>  	select VDSO_DATASTORE
>  	help
>  	  Selected by architectures that support vDSO getrandom().
> +
> +config VDSO_UNALIGNED_PACKED
> +	bool
> +	default CPU_32v5
> +	help
> +	  Use packed structs rather than memcpy() in include/vdso/unaligned.h
> +	  for unaligned memory accesses. Enabled on ARMv5 where GCC may emit
> +	  out-of-line memcpy() calls instead of inlining byte accesses.



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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20  8:24     ` Arnd Bergmann
  2026-10-20  8:41       ` Marc Kleine-Budde
@ 2026-10-20 14:56       ` Marc Kleine-Budde
  2026-10-20 15:51         ` David Laight
  2026-10-20 15:54         ` Arnd Bergmann
  1 sibling, 2 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-10-20 14:56 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3091 bytes --]

On 20.10.2026 10:24:51, Arnd Bergmann wrote:
> > FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
> > make use of it?

Just noticed that sashiko's review contained the same remark, but the
bot only posts to the linux-perf-users@vger.kernel.org list, where I'm
not subscribed:

https://lore.kernel.org/all/sashiko-outbox-178182@kernel.org/

> That would be better, but I still hope we can just get back to the
> portable code across all architectures for the in-kernel version.
>
> I have one more request for you: can you check /proc/cpu/alignment
> on the system that shows the performance regression with and without
> the patch?

When booted via NFS-root to the login prompt, we have about 570k System
alignment fixups, all in the IP stack: :/

__udp4_lib_rcv+0x78/0xc6c
icmpv6_echo_reply+0x160/0x504
ip_send_unicast_reply+0xf0/0x3f8
ndisc_send_skb+0x15c/0x40c
rawv6_recvmsg+0x114/0x3b4
tcp_rcv_established+0x3ec/0xba0
tcp_v4_fill_cb+0x70/0xec
tcp_validate_incoming+0x540/0x868

Comparing v7.0.12 with mainline "unaligned.h" and reverting commit
a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to
memcpy()") brings no difference with respect to alignment problems. But
I see the increase in I/O performance (measured with "fio" [1]) on a
UBIFS/NAND file system:

- v7.0.12 NFS root
  User:           0
  System:         573956 (tcp_measure_rcv_mss+0xe4/0x1e0)
  Skipped:        0
  Half:           4
  Word:           573940
  DWord:          0
  Multi:          34
  User faults:    0 (ignored)

  WRITE: bw=272KiB/s (278kB/s), 272KiB/s-272KiB/s (278kB/s-278kB/s), io=32.0MiB (33.6MB), run=120532-120532msec

- v7.0.12 NFS root, reverted
  User:           0
  System:         574214 (tcp_measure_rcv_mss+0xe4/0x1e0)
  Skipped:        0
  Half:           4
  Word:           574183
  DWord:          0
  Multi:          27
  User faults:    0 (ignored)

  WRITE: bw=343KiB/s (352kB/s), 343KiB/s-343KiB/s (352kB/s-352kB/s), io=32.0MiB (33.6MB), run=95439-95439msec


Booting from UBIFS, so only the lab background IP noise...

- v7.0.12 UBIFS/NAND root, reverted
  User:           0
  System:         164 (rawv6_recvmsg+0x114/0x3b4)
  Skipped:        0
  Half:           0
  Word:           127
  DWord:          0
  Multi:          37
  User faults:    0 (ignored)

regards,
Marc

[1] fio --name=rw \
    --filename=/var/stat/testfile \
    --size=8M \
    --rw=randwrite \
    --bs=4k \
    --direct=0 \
    --fsync=1 \
    --numjobs=4 \
    --group_reporting

FYI: disabling CONFIG_FTRACE brings +8% compared to v7.0.12, reverted:

- v7.0.12 NFS root, reverted, w/o tracers

  WRITE: bw=371KiB/s (380kB/s), 371KiB/s-371KiB/s (380kB/s-380kB/s), io=32.0MiB (33.6MB), run=88411-88411msec

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20 14:56       ` Marc Kleine-Budde
@ 2026-10-20 15:51         ` David Laight
  2026-10-20 15:54         ` Arnd Bergmann
  1 sibling, 0 replies; 11+ messages in thread
From: David Laight @ 2026-10-20 15:51 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Arnd Bergmann, Ian Rogers, Thomas Gleixner, Andy Lutomirski,
	Vincenzo Frascino, Stefan Kerkmann, Christophe Leroy,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

On Tue, 20 Oct 2026 16:56:40 +0200
Marc Kleine-Budde <mkl@pengutronix.de> wrote:

> On 20.10.2026 10:24:51, Arnd Bergmann wrote:
> > > FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
> > > make use of it?  
> 
> Just noticed that sashiko's review contained the same remark, but the
> bot only posts to the linux-perf-users@vger.kernel.org list, where I'm
> not subscribed:
> 
> https://lore.kernel.org/all/sashiko-outbox-178182@kernel.org/
> 
> > That would be better, but I still hope we can just get back to the
> > portable code across all architectures for the in-kernel version.
> >
> > I have one more request for you: can you check /proc/cpu/alignment
> > on the system that shows the performance regression with and without
> > the patch?  
> 
> When booted via NFS-root to the login prompt, we have about 570k System
> alignment fixups, all in the IP stack: :/
> 
> __udp4_lib_rcv+0x78/0xc6c
> icmpv6_echo_reply+0x160/0x504
> ip_send_unicast_reply+0xf0/0x3f8
> ndisc_send_skb+0x15c/0x40c
> rawv6_recvmsg+0x114/0x3b4
> tcp_rcv_established+0x3ec/0xba0
> tcp_v4_fill_cb+0x70/0xec
> tcp_validate_incoming+0x540/0x868
> 
> Comparing v7.0.12 with mainline "unaligned.h" and reverting commit
> a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to
> memcpy()") brings no difference with respect to alignment problems. But
> I see the increase in I/O performance (measured with "fio" [1]) on a
> UBIFS/NAND file system:

So the nand fs is hit by the memcpy() but there are misaligned transfers
in the network stack.
 
> - v7.0.12 NFS root
>   User:           0
>   System:         573956 (tcp_measure_rcv_mss+0xe4/0x1e0)

I can't find __udp_lib_rcv(), but that looks like it could be from expanding
tcp_flag_word(tcp_hdr(skb)).
Which would rather imply that the network driver isn't correctly aligning
all receive packets (honouring NET_IP_ALIGN).

When I were a lad the kernel just paniced and userspace core dumped :-)

David


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

* Re: [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5
  2026-10-20 14:56       ` Marc Kleine-Budde
  2026-10-20 15:51         ` David Laight
@ 2026-10-20 15:54         ` Arnd Bergmann
  1 sibling, 0 replies; 11+ messages in thread
From: Arnd Bergmann @ 2026-10-20 15:54 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Ian Rogers, Thomas Gleixner, Andy Lutomirski, Vincenzo Frascino,
	Stefan Kerkmann, Christophe Leroy, David Laight,
	Arnaldo Carvalho de Melo, Namhyung Kim, Eric Biggers,
	Alexander Viro, Jason A . Donenfeld, linux-arm-kernel,
	linux-perf-users, linux-kernel

On Tue, Oct 20, 2026, at 16:56, Marc Kleine-Budde wrote:
> On 20.10.2026 10:24:51, Arnd Bergmann wrote:
>> > FYI: there is the kconfig Symbol HAVE_EFFICIENT_UNALIGNED_ACCESS. Can we
>> > make use of it?
>
> Just noticed that sashiko's review contained the same remark, but the
> bot only posts to the linux-perf-users@vger.kernel.org list, where I'm
> not subscribed:
>
> https://lore.kernel.org/all/sashiko-outbox-178182@kernel.org/
>
>> That would be better, but I still hope we can just get back to the
>> portable code across all architectures for the in-kernel version.
>>
>> I have one more request for you: can you check /proc/cpu/alignment
>> on the system that shows the performance regression with and without
>> the patch?
>
> When booted via NFS-root to the login prompt, we have about 570k System
> alignment fixups, all in the IP stack: :/
>
> __udp4_lib_rcv+0x78/0xc6c
> icmpv6_echo_reply+0x160/0x504
> ip_send_unicast_reply+0xf0/0x3f8
> ndisc_send_skb+0x15c/0x40c
> rawv6_recvmsg+0x114/0x3b4
> tcp_rcv_established+0x3ec/0xba0
> tcp_v4_fill_cb+0x70/0xec
> tcp_validate_incoming+0x540/0x868

That is usually a bug in the ethernet driver, which should take care of
aligning the IP header in the rx skb. Many drivers do this using
netdev_alloc_skb_ip_align(), but I see that fec has its own buffer
management, so it may not be that easy to address here but would
boost performance quite a bit if you do.

> Comparing v7.0.12 with mainline "unaligned.h" and reverting commit
> a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to
> memcpy()") brings no difference with respect to alignment problems. But
> I see the increase in I/O performance (measured with "fio" [1]) on a
> UBIFS/NAND file system:
>
> - v7.0.12 NFS root
>   User:           0
>   System:         573956 (tcp_measure_rcv_mss+0xe4/0x1e0)
>   Skipped:        0
>   Half:           4
>   Word:           573940
>   DWord:          0
>   Multi:          34
>   User faults:    0 (ignored)
>
>   WRITE: bw=272KiB/s (278kB/s), 272KiB/s-272KiB/s (278kB/s-278kB/s), 
> io=32.0MiB (33.6MB), run=120532-120532msec
>
> - v7.0.12 NFS root, reverted
>   User:           0
>   System:         574214 (tcp_measure_rcv_mss+0xe4/0x1e0)
>   Skipped:        0
>   Half:           4
>   Word:           574183
>   DWord:          0
>   Multi:          27
>   User faults:    0 (ignored)
>
>   WRITE: bw=343KiB/s (352kB/s), 343KiB/s-343KiB/s (352kB/s-352kB/s), 
> io=32.0MiB (33.6MB), run=95439-95439msec

Ok, so about the same improvement that you saw on ubifs.

> Booting from UBIFS, so only the lab background IP noise...
>
> - v7.0.12 UBIFS/NAND root, reverted
>   User:           0
>   System:         164 (rawv6_recvmsg+0x114/0x3b4)
>   Skipped:        0
>   Half:           0
>   Word:           127
>   DWord:          0
>   Multi:          37
>   User faults:    0 (ignored)

At least it seems fairly safe to assume that your original
finding is correct and my worry about adding more faults is
unfounded.

       Arnd


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

end of thread, other threads:[~2026-10-20 15:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 20:12 [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Ian Rogers
2026-10-19 20:12 ` [PATCH v1 2/2] tools headers: Update the vdso/unaligned.h copy with the kernel sources Ian Rogers
2026-10-19 22:12 ` [PATCH v1 1/2] vdso: Add VDSO_UNALIGNED_PACKED config option for ARMv5 Arnd Bergmann
2026-10-20  6:44   ` Marc Kleine-Budde
2026-10-20  8:24     ` Arnd Bergmann
2026-10-20  8:41       ` Marc Kleine-Budde
2026-10-20  9:06         ` Arnd Bergmann
2026-10-20 14:56       ` Marc Kleine-Budde
2026-10-20 15:51         ` David Laight
2026-10-20 15:54         ` Arnd Bergmann
2026-10-20 14:00 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox