* [PATCH v2 0/3] Switch get/put unaligned to use memcpy
@ 2025-06-17 20:53 Ian Rogers
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-17 20:53 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/20250614044133.660848-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.
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 | 48 ++++++++++++++++++++++++++++-----
tools/include/linux/unaligned.h | 4 ---
tools/include/vdso/unaligned.h | 48 ++++++++++++++++++++++++++++-----
3 files changed, 84 insertions(+), 16 deletions(-)
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
2025-06-17 20:53 [PATCH v2 0/3] Switch get/put unaligned to use memcpy Ian Rogers
@ 2025-06-17 20:53 ` Ian Rogers
2025-06-18 11:40 ` Christophe Leroy
` (2 more replies)
2025-06-17 20:53 ` [PATCH v2 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
` (2 subsequent siblings)
3 siblings, 3 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-17 20:53 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
Type punning is necessary for get/put unaligned but the use of a
packed struct violates strict aliasing rules, requiring
-fno-strict-aliasing to be passed to the C compiler. Switch to using
memcpy so that -fno-strict-aliasing isn't necessary.
Signed-off-by: Ian Rogers <irogers@google.com>
---
include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 6 deletions(-)
diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
index ff0c06b6513e..f33c1eefbf68 100644
--- a/include/vdso/unaligned.h
+++ b/include/vdso/unaligned.h
@@ -2,14 +2,50 @@
#ifndef __VDSO_UNALIGNED_H
#define __VDSO_UNALIGNED_H
-#define __get_unaligned_t(type, ptr) ({ \
- const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
- __get_pptr->x; \
+#define ____get_unaligned_type(type) type: (type)0
+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @ptr: the pointer to load from.
+ * @type: the type to load from the pointer.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use _Generic to map to a non-const type
+ * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
+ */
+#define __get_unaligned_t(type, ptr) ({ \
+ type __get_unaligned_map_ctrl = 0; \
+ typeof(_Generic(__get_unaligned_map_ctrl, \
+ ____get_unaligned_type(short int), \
+ ____get_unaligned_type(unsigned short int), \
+ ____get_unaligned_type(int), \
+ ____get_unaligned_type(unsigned int), \
+ ____get_unaligned_type(long), \
+ ____get_unaligned_type(unsigned long), \
+ ____get_unaligned_type(long long), \
+ ____get_unaligned_type(unsigned long long), \
+ default: (type)0 \
+ )) __get_unaligned_val; \
+ (void)__get_unaligned_map_ctrl; \
+ __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
+ sizeof(__get_unaligned_val)); \
+ __get_unaligned_val; \
})
-#define __put_unaligned_t(type, val, ptr) do { \
- struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
- __put_pptr->x = (val); \
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type: the type of the value to store.
+ * @val: the value to store.
+ * @ptr: the pointer to store to.
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do { \
+ type __put_unaligned_val = (val); \
+ __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \
+ sizeof(__put_unaligned_val)); \
} while (0)
#endif /* __VDSO_UNALIGNED_H */
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources
2025-06-17 20:53 [PATCH v2 0/3] Switch get/put unaligned to use memcpy Ian Rogers
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
@ 2025-06-17 20:53 ` Ian Rogers
2025-06-17 20:53 ` [PATCH v2 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers
2025-06-18 11:42 ` [PATCH v2 0/3] Switch get/put unaligned to use memcpy Christophe Leroy
3 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-17 20:53 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
To pick up the changes in:
fe9b2b7b3583 vdso: Switch get/put unaligned from packed struct to memcpy
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 6 deletions(-)
diff --git a/tools/include/vdso/unaligned.h b/tools/include/vdso/unaligned.h
index ff0c06b6513e..f33c1eefbf68 100644
--- a/tools/include/vdso/unaligned.h
+++ b/tools/include/vdso/unaligned.h
@@ -2,14 +2,50 @@
#ifndef __VDSO_UNALIGNED_H
#define __VDSO_UNALIGNED_H
-#define __get_unaligned_t(type, ptr) ({ \
- const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
- __get_pptr->x; \
+#define ____get_unaligned_type(type) type: (type)0
+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @ptr: the pointer to load from.
+ * @type: the type to load from the pointer.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use _Generic to map to a non-const type
+ * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
+ */
+#define __get_unaligned_t(type, ptr) ({ \
+ type __get_unaligned_map_ctrl = 0; \
+ typeof(_Generic(__get_unaligned_map_ctrl, \
+ ____get_unaligned_type(short int), \
+ ____get_unaligned_type(unsigned short int), \
+ ____get_unaligned_type(int), \
+ ____get_unaligned_type(unsigned int), \
+ ____get_unaligned_type(long), \
+ ____get_unaligned_type(unsigned long), \
+ ____get_unaligned_type(long long), \
+ ____get_unaligned_type(unsigned long long), \
+ default: (type)0 \
+ )) __get_unaligned_val; \
+ (void)__get_unaligned_map_ctrl; \
+ __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
+ sizeof(__get_unaligned_val)); \
+ __get_unaligned_val; \
})
-#define __put_unaligned_t(type, val, ptr) do { \
- struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
- __put_pptr->x = (val); \
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type: the type of the value to store.
+ * @val: the value to store.
+ * @ptr: the pointer to store to.
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do { \
+ type __put_unaligned_val = (val); \
+ __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \
+ sizeof(__put_unaligned_val)); \
} while (0)
#endif /* __VDSO_UNALIGNED_H */
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h
2025-06-17 20:53 [PATCH v2 0/3] Switch get/put unaligned to use memcpy Ian Rogers
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-17 20:53 ` [PATCH v2 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
@ 2025-06-17 20:53 ` Ian Rogers
2025-06-18 11:42 ` [PATCH v2 0/3] Switch get/put unaligned to use memcpy Christophe Leroy
3 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-17 20:53 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
Now the get/put unaligned use memcpy the -Wpacked and -Wattributes
warnings don't need disabling.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/include/linux/unaligned.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/tools/include/linux/unaligned.h b/tools/include/linux/unaligned.h
index 395a4464fe73..d51ddafed138 100644
--- a/tools/include/linux/unaligned.h
+++ b/tools/include/linux/unaligned.h
@@ -6,9 +6,6 @@
* This is the most generic implementation of unaligned accesses
* and should work almost anywhere.
*/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wpacked"
-#pragma GCC diagnostic ignored "-Wattributes"
#include <vdso/unaligned.h>
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
@@ -143,6 +140,5 @@ static inline u64 get_unaligned_be48(const void *p)
{
return __get_unaligned_be48(p);
}
-#pragma GCC diagnostic pop
#endif /* __LINUX_UNALIGNED_H */
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
@ 2025-06-18 11:40 ` Christophe Leroy
2025-06-18 13:14 ` kernel test robot
2025-06-20 13:34 ` David Laight
2 siblings, 0 replies; 10+ messages in thread
From: Christophe Leroy @ 2025-06-18 11:40 UTC (permalink / raw)
To: Ian Rogers, Eric Biggers, Yuzhuo Jing, Andy Lutomirski,
Thomas Gleixner, Vincenzo Frascino, Arnaldo Carvalho de Melo,
Al Viro, Jason A. Donenfeld, linux-kernel, linux-perf-users
Le 17/06/2025 à 22:53, Ian Rogers a écrit :
> Type punning is necessary for get/put unaligned but the use of a
> packed struct violates strict aliasing rules, requiring
> -fno-strict-aliasing to be passed to the C compiler. Switch to using
> memcpy so that -fno-strict-aliasing isn't necessary.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++++++++-----
> 1 file changed, 42 insertions(+), 6 deletions(-)
>
> diff --git a/include/vdso/unaligned.h b/include/vdso/unaligned.h
> index ff0c06b6513e..f33c1eefbf68 100644
> --- a/include/vdso/unaligned.h
> +++ b/include/vdso/unaligned.h
> @@ -2,14 +2,50 @@
> #ifndef __VDSO_UNALIGNED_H
> #define __VDSO_UNALIGNED_H
>
> -#define __get_unaligned_t(type, ptr) ({ \
> - const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr); \
> - __get_pptr->x; \
> +#define ____get_unaligned_type(type) type: (type)0
> +/**
> + * __get_unaligned_t - read an unaligned value from memory.
> + * @ptr: the pointer to load from.
> + * @type: the type to load from the pointer.
> + *
> + * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
> + * from approaches like type punning that require -fno-strict-aliasing in order
> + * to be correct. As type may be const, use _Generic to map to a non-const type
> + * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
> + */
> +#define __get_unaligned_t(type, ptr) ({ \
> + type __get_unaligned_map_ctrl = 0; \
> + typeof(_Generic(__get_unaligned_map_ctrl, \
> + ____get_unaligned_type(short int), \
> + ____get_unaligned_type(unsigned short int), \
> + ____get_unaligned_type(int), \
> + ____get_unaligned_type(unsigned int), \
> + ____get_unaligned_type(long), \
> + ____get_unaligned_type(unsigned long), \
> + ____get_unaligned_type(long long), \
> + ____get_unaligned_type(unsigned long long), \
> + default: (type)0 \
> + )) __get_unaligned_val; \
> + (void)__get_unaligned_map_ctrl; \
> + __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
> + sizeof(__get_unaligned_val)); \
> + __get_unaligned_val; \
> })
>
> -#define __put_unaligned_t(type, val, ptr) do { \
> - struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr); \
> - __put_pptr->x = (val); \
> +/**
> + * __put_unaligned_t - write an unaligned value to memory.
> + * @type: the type of the value to store.
> + * @val: the value to store.
> + * @ptr: the pointer to store to.
> + *
> + * Use memcpy to affect an unaligned type sized store avoiding undefined
> + * behavior from approaches like type punning that require -fno-strict-aliasing
> + * in order to be correct. The void* cast silences ubsan warnings.
> + */
> +#define __put_unaligned_t(type, val, ptr) do { \
> + type __put_unaligned_val = (val); \
> + __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \
> + sizeof(__put_unaligned_val)); \
> } while (0)
>
> #endif /* __VDSO_UNALIGNED_H */
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/3] Switch get/put unaligned to use memcpy
2025-06-17 20:53 [PATCH v2 0/3] Switch get/put unaligned to use memcpy Ian Rogers
` (2 preceding siblings ...)
2025-06-17 20:53 ` [PATCH v2 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers
@ 2025-06-18 11:42 ` Christophe Leroy
2025-06-25 18:06 ` Ian Rogers
3 siblings, 1 reply; 10+ messages in thread
From: Christophe Leroy @ 2025-06-18 11:42 UTC (permalink / raw)
To: Ian Rogers, Eric Biggers, Yuzhuo Jing, Andy Lutomirski,
Thomas Gleixner, Vincenzo Frascino, Arnaldo Carvalho de Melo,
Al Viro, Jason A. Donenfeld, linux-kernel, linux-perf-users
Le 17/06/2025 à 22:53, Ian Rogers a écrit :
> 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2F20250614044133.660848-2-ebiggers%40kernel.org%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894967529%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=29QUBLnUowncZiTH4z74Ec1olUlX0OTYnUNGDvWxX1o%3D&reserved=0
>
> 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.
>
> 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2Fc57de5bf-d55c-48c5-9dfa-e2fb844dafe9%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894985987%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=l1LJP3XPKVuhDpiHxxkfWBiNPMYaBT9YXGBFzs6wLpY%3D&reserved=0
>
Does this new version also fixes the failures reported by the robots:
- arm64-randconfig with clang 21
- i386-randconfig with gcc 12
Christophe
> 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 | 48 ++++++++++++++++++++++++++++-----
> tools/include/linux/unaligned.h | 4 ---
> tools/include/vdso/unaligned.h | 48 ++++++++++++++++++++++++++++-----
> 3 files changed, 84 insertions(+), 16 deletions(-)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-18 11:40 ` Christophe Leroy
@ 2025-06-18 13:14 ` kernel test robot
2025-06-20 13:34 ` David Laight
2 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2025-06-18 13:14 UTC (permalink / raw)
To: Ian Rogers, 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: oe-kbuild-all, Ian Rogers
Hi Ian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.16-rc2 next-20250618]
[cannot apply to tip/timers/vdso acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ian-Rogers/vdso-Switch-get-put-unaligned-from-packed-struct-to-memcpy/20250618-045610
base: linus/master
patch link: https://lore.kernel.org/r/20250617205320.1580946-2-irogers%40google.com
patch subject: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
config: parisc-allnoconfig (https://download.01.org/0day-ci/archive/20250618/202506182044.OhyWGCSm-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250618/202506182044.OhyWGCSm-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506182044.OhyWGCSm-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/linux/swab.h:5,
from include/uapi/linux/byteorder/big_endian.h:14,
from include/linux/byteorder/big_endian.h:5,
from arch/parisc/include/uapi/asm/byteorder.h:5,
from arch/parisc/include/asm/bitops.h:11,
from include/linux/bitops.h:67,
from include/linux/kernel.h:23,
from arch/parisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/thread_info.h:13,
from include/linux/sched.h:14,
from include/linux/uaccess.h:9,
from arch/parisc/boot/compressed/misc.c:7:
In function 'get_unaligned_le32',
inlined from 'decompress_kernel' at arch/parisc/boot/compressed/misc.c:312:16:
>> include/vdso/unaligned.h:30:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 1 [-Wstringop-overread]
30 | __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 | sizeof(__get_unaligned_val)); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/uapi/linux/swab.h:120:19: note: in definition of macro '__swab32'
120 | __fswab32(x))
| ^
include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
89 | #define le32_to_cpu __le32_to_cpu
| ^~~~~~~~~~~~~
include/linux/unaligned.h:23:28: note: in expansion of macro '__get_unaligned_t'
23 | return le32_to_cpu(__get_unaligned_t(__le32, p));
| ^~~~~~~~~~~~~~~~~
arch/parisc/boot/compressed/misc.c: In function 'decompress_kernel':
arch/parisc/boot/compressed/misc.c:29:13: note: source object 'output_len' of size 1
29 | extern char output_len;
| ^~~~~~~~~~
vim +/__builtin_memcpy +30 include/vdso/unaligned.h
4
5 #define ____get_unaligned_type(type) type: (type)0
6 /**
7 * __get_unaligned_t - read an unaligned value from memory.
8 * @ptr: the pointer to load from.
9 * @type: the type to load from the pointer.
10 *
11 * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
12 * from approaches like type punning that require -fno-strict-aliasing in order
13 * to be correct. As type may be const, use _Generic to map to a non-const type
14 * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
15 */
16 #define __get_unaligned_t(type, ptr) ({ \
17 type __get_unaligned_map_ctrl = 0; \
18 typeof(_Generic(__get_unaligned_map_ctrl, \
19 ____get_unaligned_type(short int), \
20 ____get_unaligned_type(unsigned short int), \
21 ____get_unaligned_type(int), \
22 ____get_unaligned_type(unsigned int), \
23 ____get_unaligned_type(long), \
24 ____get_unaligned_type(unsigned long), \
25 ____get_unaligned_type(long long), \
26 ____get_unaligned_type(unsigned long long), \
27 default: (type)0 \
28 )) __get_unaligned_val; \
29 (void)__get_unaligned_map_ctrl; \
> 30 __builtin_memcpy(&__get_unaligned_val, (void *)(ptr), \
31 sizeof(__get_unaligned_val)); \
32 __get_unaligned_val; \
33 })
34
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
@ 2025-06-18 16:32 kernel test robot
0 siblings, 0 replies; 10+ messages in thread
From: kernel test robot @ 2025-06-18 16:32 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp, Dan Carpenter
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20250617205320.1580946-2-irogers@google.com>
References: <20250617205320.1580946-2-irogers@google.com>
TO: Ian Rogers <irogers@google.com>
TO: Eric Biggers <ebiggers@google.com>
TO: Yuzhuo Jing <yuzhuo@google.com>
TO: Andy Lutomirski <luto@kernel.org>
TO: Thomas Gleixner <tglx@linutronix.de>
TO: Vincenzo Frascino <vincenzo.frascino@arm.com>
TO: Arnaldo Carvalho de Melo <acme@redhat.com>
TO: Al Viro <viro@zeniv.linux.org.uk>
TO: Christophe Leroy <christophe.leroy@csgroup.eu>
TO: "Jason A. Donenfeld" <Jason@zx2c4.com>
TO: linux-kernel@vger.kernel.org
TO: linux-perf-users@vger.kernel.org
CC: Ian Rogers <irogers@google.com>
Hi Ian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.16-rc2 next-20250618]
[cannot apply to tip/timers/vdso acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ian-Rogers/vdso-Switch-get-put-unaligned-from-packed-struct-to-memcpy/20250618-045610
base: linus/master
patch link: https://lore.kernel.org/r/20250617205320.1580946-2-irogers%40google.com
patch subject: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
:::::: branch date: 20 hours ago
:::::: commit date: 20 hours ago
config: i386-randconfig-141-20250618 (https://download.01.org/0day-ci/archive/20250619/202506190009.DyDpM6gF-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202506190009.DyDpM6gF-lkp@intel.com/
smatch warnings:
drivers/iio/magnetometer/yamaha-yas530.c:1101 yas537_get_calibration_data() warn: ' - 256' 4294967040 can't fit into 32767 'c->Cx'
drivers/iio/magnetometer/yamaha-yas530.c:1102 yas537_get_calibration_data() warn: ' - 256' 4294967040 can't fit into 32767 'c->Cy1'
drivers/iio/magnetometer/yamaha-yas530.c:1104 yas537_get_calibration_data() warn: ' - 64' 4294967232 can't fit into 127 'c->a2'
drivers/iio/magnetometer/yamaha-yas530.c:1105 yas537_get_calibration_data() warn: ' - 64' 4294967232 can't fit into 127 'c->a3'
drivers/iio/magnetometer/yamaha-yas530.c:1107 yas537_get_calibration_data() warn: ' - 112' 4294967184 can't fit into 32767 'c->a5'
drivers/iio/magnetometer/yamaha-yas530.c:1108 yas537_get_calibration_data() warn: ' - 64' 4294967232 can't fit into 127 'c->a6'
drivers/iio/magnetometer/yamaha-yas530.c:1110 yas537_get_calibration_data() warn: ' - 64' 4294967232 can't fit into 127 'c->a8'
drivers/iio/magnetometer/yamaha-yas530.c:1111 yas537_get_calibration_data() warn: ' - 112' 4294967184 can't fit into 32767 'c->a9'
vim +1101 drivers/iio/magnetometer/yamaha-yas530.c
de8860b1ed4701 Linus Walleij 2020-12-24 925
65f79b50103067 Jakob Hauser 2022-08-13 926 static int yas537_get_calibration_data(struct yas5xx *yas5xx)
65f79b50103067 Jakob Hauser 2022-08-13 927 {
65f79b50103067 Jakob Hauser 2022-08-13 928 struct yas5xx_calibration *c = &yas5xx->calibration;
65f79b50103067 Jakob Hauser 2022-08-13 929 u8 data[17];
65f79b50103067 Jakob Hauser 2022-08-13 930 u32 val1, val2, val3, val4;
65f79b50103067 Jakob Hauser 2022-08-13 931 int i, ret;
65f79b50103067 Jakob Hauser 2022-08-13 932
65f79b50103067 Jakob Hauser 2022-08-13 933 /* Writing SRST register */
65f79b50103067 Jakob Hauser 2022-08-13 934 ret = regmap_write(yas5xx->map, YAS537_SRST, BIT(1));
65f79b50103067 Jakob Hauser 2022-08-13 935 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 936 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 937
65f79b50103067 Jakob Hauser 2022-08-13 938 /* Calibration readout, YAS537 needs one readout only */
65f79b50103067 Jakob Hauser 2022-08-13 939 ret = regmap_bulk_read(yas5xx->map, YAS537_CAL, data, sizeof(data));
65f79b50103067 Jakob Hauser 2022-08-13 940 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 941 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 942 dev_dbg(yas5xx->dev, "calibration data: %17ph\n", data);
65f79b50103067 Jakob Hauser 2022-08-13 943
65f79b50103067 Jakob Hauser 2022-08-13 944 /* Sanity check, is this all zeroes? */
65f79b50103067 Jakob Hauser 2022-08-13 945 if (!memchr_inv(data, 0x00, 16) && !FIELD_GET(GENMASK(5, 0), data[16]))
65f79b50103067 Jakob Hauser 2022-08-13 946 dev_warn(yas5xx->dev, "calibration is blank!\n");
65f79b50103067 Jakob Hauser 2022-08-13 947
65f79b50103067 Jakob Hauser 2022-08-13 948 /* Contribute calibration data to the input pool for kernel entropy */
65f79b50103067 Jakob Hauser 2022-08-13 949 add_device_randomness(data, sizeof(data));
65f79b50103067 Jakob Hauser 2022-08-13 950
65f79b50103067 Jakob Hauser 2022-08-13 951 /* Extract version information */
65f79b50103067 Jakob Hauser 2022-08-13 952 yas5xx->version = FIELD_GET(GENMASK(7, 6), data[16]);
65f79b50103067 Jakob Hauser 2022-08-13 953
65f79b50103067 Jakob Hauser 2022-08-13 954 /* There are two versions of YAS537 behaving differently */
65f79b50103067 Jakob Hauser 2022-08-13 955 switch (yas5xx->version) {
65f79b50103067 Jakob Hauser 2022-08-13 956 case YAS537_VERSION_0:
65f79b50103067 Jakob Hauser 2022-08-13 957 /*
65f79b50103067 Jakob Hauser 2022-08-13 958 * The first version simply writes data back into registers:
65f79b50103067 Jakob Hauser 2022-08-13 959 *
65f79b50103067 Jakob Hauser 2022-08-13 960 * data[0] YAS537_MTC 0x93
65f79b50103067 Jakob Hauser 2022-08-13 961 * data[1] 0x94
65f79b50103067 Jakob Hauser 2022-08-13 962 * data[2] 0x95
65f79b50103067 Jakob Hauser 2022-08-13 963 * data[3] 0x96
65f79b50103067 Jakob Hauser 2022-08-13 964 * data[4] 0x97
65f79b50103067 Jakob Hauser 2022-08-13 965 * data[5] 0x98
65f79b50103067 Jakob Hauser 2022-08-13 966 * data[6] 0x99
65f79b50103067 Jakob Hauser 2022-08-13 967 * data[7] 0x9a
65f79b50103067 Jakob Hauser 2022-08-13 968 * data[8] 0x9b
65f79b50103067 Jakob Hauser 2022-08-13 969 * data[9] 0x9c
65f79b50103067 Jakob Hauser 2022-08-13 970 * data[10] 0x9d
65f79b50103067 Jakob Hauser 2022-08-13 971 * data[11] YAS537_OC 0x9e
65f79b50103067 Jakob Hauser 2022-08-13 972 *
65f79b50103067 Jakob Hauser 2022-08-13 973 * data[12] YAS537_OFFSET_X 0x84
65f79b50103067 Jakob Hauser 2022-08-13 974 * data[13] YAS537_OFFSET_Y1 0x85
65f79b50103067 Jakob Hauser 2022-08-13 975 * data[14] YAS537_OFFSET_Y2 0x86
65f79b50103067 Jakob Hauser 2022-08-13 976 *
65f79b50103067 Jakob Hauser 2022-08-13 977 * data[15] YAS537_HCK 0x88
65f79b50103067 Jakob Hauser 2022-08-13 978 * data[16] YAS537_LCK 0x89
65f79b50103067 Jakob Hauser 2022-08-13 979 */
65f79b50103067 Jakob Hauser 2022-08-13 980 for (i = 0; i < 12; i++) {
65f79b50103067 Jakob Hauser 2022-08-13 981 ret = regmap_write(yas5xx->map, YAS537_MTC + i,
65f79b50103067 Jakob Hauser 2022-08-13 982 data[i]);
65f79b50103067 Jakob Hauser 2022-08-13 983 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 984 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 985 }
65f79b50103067 Jakob Hauser 2022-08-13 986 for (i = 0; i < 3; i++) {
65f79b50103067 Jakob Hauser 2022-08-13 987 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i,
65f79b50103067 Jakob Hauser 2022-08-13 988 data[i + 12]);
65f79b50103067 Jakob Hauser 2022-08-13 989 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 990 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 991 yas5xx->hard_offsets[i] = data[i + 12];
65f79b50103067 Jakob Hauser 2022-08-13 992 }
65f79b50103067 Jakob Hauser 2022-08-13 993 for (i = 0; i < 2; i++) {
65f79b50103067 Jakob Hauser 2022-08-13 994 ret = regmap_write(yas5xx->map, YAS537_HCK + i,
65f79b50103067 Jakob Hauser 2022-08-13 995 data[i + 15]);
65f79b50103067 Jakob Hauser 2022-08-13 996 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 997 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 998 }
65f79b50103067 Jakob Hauser 2022-08-13 999 break;
65f79b50103067 Jakob Hauser 2022-08-13 1000 case YAS537_VERSION_1:
65f79b50103067 Jakob Hauser 2022-08-13 1001 /*
65f79b50103067 Jakob Hauser 2022-08-13 1002 * The second version writes some data into registers but also
65f79b50103067 Jakob Hauser 2022-08-13 1003 * extracts calibration coefficients.
65f79b50103067 Jakob Hauser 2022-08-13 1004 *
65f79b50103067 Jakob Hauser 2022-08-13 1005 * Registers being written:
65f79b50103067 Jakob Hauser 2022-08-13 1006 *
65f79b50103067 Jakob Hauser 2022-08-13 1007 * data[0] YAS537_MTC 0x93
65f79b50103067 Jakob Hauser 2022-08-13 1008 * data[1] YAS537_MTC+1 0x94
65f79b50103067 Jakob Hauser 2022-08-13 1009 * data[2] YAS537_MTC+2 0x95
65f79b50103067 Jakob Hauser 2022-08-13 1010 * data[3] YAS537_MTC+3 (partially) 0x96
65f79b50103067 Jakob Hauser 2022-08-13 1011 *
65f79b50103067 Jakob Hauser 2022-08-13 1012 * data[12] YAS537_OFFSET_X 0x84
65f79b50103067 Jakob Hauser 2022-08-13 1013 * data[13] YAS537_OFFSET_Y1 0x85
65f79b50103067 Jakob Hauser 2022-08-13 1014 * data[14] YAS537_OFFSET_Y2 0x86
65f79b50103067 Jakob Hauser 2022-08-13 1015 *
65f79b50103067 Jakob Hauser 2022-08-13 1016 * data[15] YAS537_HCK (partially) 0x88
65f79b50103067 Jakob Hauser 2022-08-13 1017 * YAS537_LCK (partially) 0x89
65f79b50103067 Jakob Hauser 2022-08-13 1018 * data[16] YAS537_OC (partially) 0x9e
65f79b50103067 Jakob Hauser 2022-08-13 1019 */
65f79b50103067 Jakob Hauser 2022-08-13 1020 for (i = 0; i < 3; i++) {
65f79b50103067 Jakob Hauser 2022-08-13 1021 ret = regmap_write(yas5xx->map, YAS537_MTC + i,
65f79b50103067 Jakob Hauser 2022-08-13 1022 data[i]);
65f79b50103067 Jakob Hauser 2022-08-13 1023 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1024 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1025 }
65f79b50103067 Jakob Hauser 2022-08-13 1026 for (i = 0; i < 3; i++) {
65f79b50103067 Jakob Hauser 2022-08-13 1027 ret = regmap_write(yas5xx->map, YAS537_OFFSET_X + i,
65f79b50103067 Jakob Hauser 2022-08-13 1028 data[i + 12]);
65f79b50103067 Jakob Hauser 2022-08-13 1029 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1030 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1031 yas5xx->hard_offsets[i] = data[i + 12];
65f79b50103067 Jakob Hauser 2022-08-13 1032 }
65f79b50103067 Jakob Hauser 2022-08-13 1033 /*
65f79b50103067 Jakob Hauser 2022-08-13 1034 * Visualization of partially taken data:
65f79b50103067 Jakob Hauser 2022-08-13 1035 *
65f79b50103067 Jakob Hauser 2022-08-13 1036 * data[3] n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1037 * YAS537_MTC+3 x x x 1 0 0 0 0
65f79b50103067 Jakob Hauser 2022-08-13 1038 *
65f79b50103067 Jakob Hauser 2022-08-13 1039 * data[15] n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1040 * YAS537_HCK x x x x 0
65f79b50103067 Jakob Hauser 2022-08-13 1041 *
65f79b50103067 Jakob Hauser 2022-08-13 1042 * data[15] n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1043 * YAS537_LCK x x x x 0
65f79b50103067 Jakob Hauser 2022-08-13 1044 *
65f79b50103067 Jakob Hauser 2022-08-13 1045 * data[16] n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1046 * YAS537_OC x x x x x x
65f79b50103067 Jakob Hauser 2022-08-13 1047 */
65f79b50103067 Jakob Hauser 2022-08-13 1048 ret = regmap_write(yas5xx->map, YAS537_MTC + 3,
65f79b50103067 Jakob Hauser 2022-08-13 1049 FIELD_PREP(YAS537_MTC3_MASK_PREP,
65f79b50103067 Jakob Hauser 2022-08-13 1050 FIELD_GET(YAS537_MTC3_MASK_GET, data[3])) |
65f79b50103067 Jakob Hauser 2022-08-13 1051 YAS537_MTC3_ADD_BIT);
65f79b50103067 Jakob Hauser 2022-08-13 1052 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1053 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1054 ret = regmap_write(yas5xx->map, YAS537_HCK,
65f79b50103067 Jakob Hauser 2022-08-13 1055 FIELD_PREP(YAS537_HCK_MASK_PREP,
65f79b50103067 Jakob Hauser 2022-08-13 1056 FIELD_GET(YAS537_HCK_MASK_GET, data[15])));
65f79b50103067 Jakob Hauser 2022-08-13 1057 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1058 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1059 ret = regmap_write(yas5xx->map, YAS537_LCK,
65f79b50103067 Jakob Hauser 2022-08-13 1060 FIELD_PREP(YAS537_LCK_MASK_PREP,
65f79b50103067 Jakob Hauser 2022-08-13 1061 FIELD_GET(YAS537_LCK_MASK_GET, data[15])));
65f79b50103067 Jakob Hauser 2022-08-13 1062 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1063 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1064 ret = regmap_write(yas5xx->map, YAS537_OC,
65f79b50103067 Jakob Hauser 2022-08-13 1065 FIELD_GET(YAS537_OC_MASK_GET, data[16]));
65f79b50103067 Jakob Hauser 2022-08-13 1066 if (ret)
65f79b50103067 Jakob Hauser 2022-08-13 1067 return ret;
65f79b50103067 Jakob Hauser 2022-08-13 1068 /*
65f79b50103067 Jakob Hauser 2022-08-13 1069 * For data extraction, build some blocks. Four 32-bit blocks
65f79b50103067 Jakob Hauser 2022-08-13 1070 * look appropriate.
65f79b50103067 Jakob Hauser 2022-08-13 1071 *
65f79b50103067 Jakob Hauser 2022-08-13 1072 * n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1073 * data[0] 0 [ Cx Cx Cx Cx Cx Cx Cx Cx ] bits 31 .. 24
65f79b50103067 Jakob Hauser 2022-08-13 1074 * data[1] 1 [ Cx C1 C1 C1 C1 C1 C1 C1 ] bits 23 .. 16
65f79b50103067 Jakob Hauser 2022-08-13 1075 * data[2] 2 [ C1 C1 C2 C2 C2 C2 C2 C2 ] bits 15 .. 8
65f79b50103067 Jakob Hauser 2022-08-13 1076 * data[3] 3 [ C2 C2 C2 ] bits 7 .. 0
65f79b50103067 Jakob Hauser 2022-08-13 1077 *
65f79b50103067 Jakob Hauser 2022-08-13 1078 * n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1079 * data[3] 0 [ a2 a2 a2 a2 a2 ] bits 31 .. 24
65f79b50103067 Jakob Hauser 2022-08-13 1080 * data[4] 1 [ a2 a2 a3 a3 a3 a3 a3 a3 ] bits 23 .. 16
65f79b50103067 Jakob Hauser 2022-08-13 1081 * data[5] 2 [ a3 a4 a4 a4 a4 a4 a4 a4 ] bits 15 .. 8
65f79b50103067 Jakob Hauser 2022-08-13 1082 * data[6] 3 [ a4 ] bits 7 .. 0
65f79b50103067 Jakob Hauser 2022-08-13 1083 *
65f79b50103067 Jakob Hauser 2022-08-13 1084 * n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1085 * data[6] 0 [ a5 a5 a5 a5 a5 a5 a5 ] bits 31 .. 24
65f79b50103067 Jakob Hauser 2022-08-13 1086 * data[7] 1 [ a5 a5 a6 a6 a6 a6 a6 a6 ] bits 23 .. 16
65f79b50103067 Jakob Hauser 2022-08-13 1087 * data[8] 2 [ a6 a7 a7 a7 a7 a7 a7 a7 ] bits 15 .. 8
65f79b50103067 Jakob Hauser 2022-08-13 1088 * data[9] 3 [ a7 ] bits 7 .. 0
65f79b50103067 Jakob Hauser 2022-08-13 1089 *
65f79b50103067 Jakob Hauser 2022-08-13 1090 * n 7 6 5 4 3 2 1 0
65f79b50103067 Jakob Hauser 2022-08-13 1091 * data[9] 0 [ a8 a8 a8 a8 a8 a8 a8 ] bits 31 .. 24
65f79b50103067 Jakob Hauser 2022-08-13 1092 * data[10] 1 [ a9 a9 a9 a9 a9 a9 a9 a9 ] bits 23 .. 16
65f79b50103067 Jakob Hauser 2022-08-13 1093 * data[11] 2 [ a9 k k k k k k k ] bits 15 .. 8
65f79b50103067 Jakob Hauser 2022-08-13 1094 * data[12] 3 [ ] bits 7 .. 0
65f79b50103067 Jakob Hauser 2022-08-13 1095 */
65f79b50103067 Jakob Hauser 2022-08-13 1096 val1 = get_unaligned_be32(&data[0]);
65f79b50103067 Jakob Hauser 2022-08-13 1097 val2 = get_unaligned_be32(&data[3]);
65f79b50103067 Jakob Hauser 2022-08-13 1098 val3 = get_unaligned_be32(&data[6]);
65f79b50103067 Jakob Hauser 2022-08-13 1099 val4 = get_unaligned_be32(&data[9]);
65f79b50103067 Jakob Hauser 2022-08-13 1100 /* Extract calibration coefficients and modify */
65f79b50103067 Jakob Hauser 2022-08-13 @1101 c->Cx = FIELD_GET(GENMASK(31, 23), val1) - 256;
65f79b50103067 Jakob Hauser 2022-08-13 @1102 c->Cy1 = FIELD_GET(GENMASK(22, 14), val1) - 256;
65f79b50103067 Jakob Hauser 2022-08-13 1103 c->Cy2 = FIELD_GET(GENMASK(13, 5), val1) - 256;
65f79b50103067 Jakob Hauser 2022-08-13 @1104 c->a2 = FIELD_GET(GENMASK(28, 22), val2) - 64;
65f79b50103067 Jakob Hauser 2022-08-13 @1105 c->a3 = FIELD_GET(GENMASK(21, 15), val2) - 64;
65f79b50103067 Jakob Hauser 2022-08-13 1106 c->a4 = FIELD_GET(GENMASK(14, 7), val2) - 128;
65f79b50103067 Jakob Hauser 2022-08-13 @1107 c->a5 = FIELD_GET(GENMASK(30, 22), val3) - 112;
65f79b50103067 Jakob Hauser 2022-08-13 @1108 c->a6 = FIELD_GET(GENMASK(21, 15), val3) - 64;
65f79b50103067 Jakob Hauser 2022-08-13 1109 c->a7 = FIELD_GET(GENMASK(14, 7), val3) - 128;
65f79b50103067 Jakob Hauser 2022-08-13 @1110 c->a8 = FIELD_GET(GENMASK(30, 24), val4) - 64;
65f79b50103067 Jakob Hauser 2022-08-13 @1111 c->a9 = FIELD_GET(GENMASK(23, 15), val4) - 112;
65f79b50103067 Jakob Hauser 2022-08-13 1112 c->k = FIELD_GET(GENMASK(14, 8), val4);
65f79b50103067 Jakob Hauser 2022-08-13 1113 break;
65f79b50103067 Jakob Hauser 2022-08-13 1114 default:
65f79b50103067 Jakob Hauser 2022-08-13 1115 dev_err(yas5xx->dev, "unknown version of YAS537\n");
65f79b50103067 Jakob Hauser 2022-08-13 1116 return -EINVAL;
65f79b50103067 Jakob Hauser 2022-08-13 1117 }
65f79b50103067 Jakob Hauser 2022-08-13 1118
65f79b50103067 Jakob Hauser 2022-08-13 1119 return 0;
65f79b50103067 Jakob Hauser 2022-08-13 1120 }
65f79b50103067 Jakob Hauser 2022-08-13 1121
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-18 11:40 ` Christophe Leroy
2025-06-18 13:14 ` kernel test robot
@ 2025-06-20 13:34 ` David Laight
2 siblings, 0 replies; 10+ messages in thread
From: David Laight @ 2025-06-20 13:34 UTC (permalink / raw)
To: Ian Rogers
Cc: 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
On Tue, 17 Jun 2025 13:53:18 -0700
Ian Rogers <irogers@google.com> wrote:
> Type punning is necessary for get/put unaligned but the use of a
> packed struct violates strict aliasing rules, requiring
> -fno-strict-aliasing to be passed to the C compiler. Switch to using
> memcpy so that -fno-strict-aliasing isn't necessary.
>.... \
> +/**
> + * __put_unaligned_t - write an unaligned value to memory.
> + * @type: the type of the value to store.
> + * @val: the value to store.
> + * @ptr: the pointer to store to.
> + *
> + * Use memcpy to affect an unaligned type sized store avoiding undefined
> + * behavior from approaches like type punning that require -fno-strict-aliasing
> + * in order to be correct. The void* cast silences ubsan warnings.
> + */
> +#define __put_unaligned_t(type, val, ptr) do { \
> + type __put_unaligned_val = (val); \
> + __builtin_memcpy((void *)(ptr), &__put_unaligned_val, \
> + sizeof(__put_unaligned_val)); \
> } while (0)
Does that actually work?
If 'ptr' has type 'long *' gcc will (validly according to C) assume
it is aligned and will generate a misaligned memory write.
The (void *) cast make no difference.
Using (void *)(long)(ptr) might lose the alignment.
Otherwise you may need to use OPTIMISER_HIDE_VAR() and live
with the extra register-register move it tends to generate.
David
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/3] Switch get/put unaligned to use memcpy
2025-06-18 11:42 ` [PATCH v2 0/3] Switch get/put unaligned to use memcpy Christophe Leroy
@ 2025-06-25 18:06 ` Ian Rogers
0 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2025-06-25 18:06 UTC (permalink / raw)
To: Christophe Leroy
Cc: Eric Biggers, Yuzhuo Jing, Andy Lutomirski, Thomas Gleixner,
Vincenzo Frascino, Arnaldo Carvalho de Melo, Al Viro,
Jason A. Donenfeld, linux-kernel, linux-perf-users
On Wed, Jun 18, 2025 at 4:42 AM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
>
>
> Le 17/06/2025 à 22:53, Ian Rogers a écrit :
> > 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2F20250614044133.660848-2-ebiggers%40kernel.org%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894967529%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=29QUBLnUowncZiTH4z74Ec1olUlX0OTYnUNGDvWxX1o%3D&reserved=0
> >
> > 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.
> >
> > 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://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2Fc57de5bf-d55c-48c5-9dfa-e2fb844dafe9%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894985987%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=l1LJP3XPKVuhDpiHxxkfWBiNPMYaBT9YXGBFzs6wLpY%3D&reserved=0
> >
So I think I can remove the _Generic block in unaligned.h by depending
on the equivalent __unqual_scalar_typeof from
include/linux/compiler_types.h. I think this is preferable and so I'll
post a v3.
> Does this new version also fixes the failures reported by the robots:
> - arm64-randconfig with clang 21
The issue here was:
llvm-readelf: warning: 'arch/arm64/kernel/vdso/vdso.so.dbg': invalid
PT_DYNAMIC size (0x118)
llvm-readelf: warning: 'arch/arm64/kernel/vdso/vdso.so.dbg':
PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
which the switch to __builtin_memcpy should have resolved.
> - i386-randconfig with gcc 12
The reported error is in the unaligned code from sparse:
drivers/scsi/megaraid/megaraid_sas_base.c:8438:32: sparse: sparse:
Using plain integer as NULL pointer
I believe this is because of the _Generic block with a pointer type,
and so the use of __unqual_scalar_typeof in the next/v3 patch set
should hopefully resolve it - or else we'll need to special case
pointer types to assign NULL rather than 0, but I'd prefer not to
special case every potential pointer type.
Thanks,
Ian
> Christophe
>
> > 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 | 48 ++++++++++++++++++++++++++++-----
> > tools/include/linux/unaligned.h | 4 ---
> > tools/include/vdso/unaligned.h | 48 ++++++++++++++++++++++++++++-----
> > 3 files changed, 84 insertions(+), 16 deletions(-)
> >
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-06-25 18:06 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 20:53 [PATCH v2 0/3] Switch get/put unaligned to use memcpy Ian Rogers
2025-06-17 20:53 ` [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy Ian Rogers
2025-06-18 11:40 ` Christophe Leroy
2025-06-18 13:14 ` kernel test robot
2025-06-20 13:34 ` David Laight
2025-06-17 20:53 ` [PATCH v2 2/3] tools headers: Update the linux/unaligned.h copy with the kernel sources Ian Rogers
2025-06-17 20:53 ` [PATCH v2 3/3] tools headers: Remove unneeded ignoring of warnings in unaligned.h Ian Rogers
2025-06-18 11:42 ` [PATCH v2 0/3] Switch get/put unaligned to use memcpy Christophe Leroy
2025-06-25 18:06 ` Ian Rogers
-- strict thread matches above, loose matches on Subject: below --
2025-06-18 16:32 [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy kernel test robot
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.