Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests
@ 2026-07-23  7:13 Shung-Hsi Yu
  2026-07-23  7:13 ` [PATCH stable 6.12 6.6 2/2] selftests/bpf: Add simple strscpy() implementation Shung-Hsi Yu
  2026-07-23 10:19 ` [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Shung-Hsi Yu @ 2026-07-23  7:13 UTC (permalink / raw)
  To: stable
  Cc: Shung-Hsi Yu, Lorenzo Stoakes, Jann Horn, John Hubbard,
	Liam Howlett, Sidhartha Kumar, Vlastimil Babka, Dan Williams,
	Peter Zijlstra, Andrew Morton

From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

commit 9a6a6a3191574a01dcf7a7d9385246d7bc8736bc upstream.

Commit 857d18f23ab1 ("cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for
conditional locks") accidentally broke the radix tree, VMA userland tests
by including linux/args.h which is not present in the tools/include
directory.

This patch copies this over and adds an #ifdef block to avoid duplicate
__CONCAT declaration in conflict with system headers when we ultimately
include this.

Link: https://lkml.kernel.org/r/20250811052654.33286-1-lorenzo.stoakes@oracle.com
Fixes: 857d18f23ab1 ("cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks")
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 63c49efc987a ("selftests/bpf: Add simple strscpy() implementation")
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
 tools/include/linux/args.h       | 28 ++++++++++++++++++++++++++++
 tools/testing/shared/linux/idr.h |  4 ++++
 2 files changed, 32 insertions(+)
 create mode 100644 tools/include/linux/args.h

diff --git a/tools/include/linux/args.h b/tools/include/linux/args.h
new file mode 100644
index 000000000000..2e8e65d975c7
--- /dev/null
+++ b/tools/include/linux/args.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _LINUX_ARGS_H
+#define _LINUX_ARGS_H
+
+/*
+ * How do these macros work?
+ *
+ * In __COUNT_ARGS() _0 to _12 are just placeholders from the start
+ * in order to make sure _n is positioned over the correct number
+ * from 12 to 0 (depending on X, which is a variadic argument list).
+ * They serve no purpose other than occupying a position. Since each
+ * macro parameter must have a distinct identifier, those identifiers
+ * are as good as any.
+ *
+ * In COUNT_ARGS() we use actual integers, so __COUNT_ARGS() returns
+ * that as _n.
+ */
+
+/* This counts to 15. Any more, it will return 16th argument. */
+#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _n, X...) _n
+#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+/* Concatenate two parameters, but allow them to be expanded beforehand. */
+#define __CONCAT(a, b) a ## b
+#define CONCATENATE(a, b) __CONCAT(a, b)
+
+#endif	/* _LINUX_ARGS_H */
diff --git a/tools/testing/shared/linux/idr.h b/tools/testing/shared/linux/idr.h
index 4e342f2e37cf..676c5564e33f 100644
--- a/tools/testing/shared/linux/idr.h
+++ b/tools/testing/shared/linux/idr.h
@@ -1 +1,5 @@
+/* Avoid duplicate definitions due to system headers. */
+#ifdef __CONCAT
+#undef __CONCAT
+#endif
 #include "../../../../include/linux/idr.h"
-- 
2.55.0


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

* [PATCH stable 6.12 6.6 2/2] selftests/bpf: Add simple strscpy() implementation
  2026-07-23  7:13 [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Shung-Hsi Yu
@ 2026-07-23  7:13 ` Shung-Hsi Yu
  2026-07-23 10:19 ` [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Shung-Hsi Yu @ 2026-07-23  7:13 UTC (permalink / raw)
  To: stable
  Cc: Shung-Hsi Yu, Lorenzo Stoakes, Jann Horn, John Hubbard,
	Liam Howlett, Sidhartha Kumar, Vlastimil Babka, Dan Williams,
	Peter Zijlstra, Andrew Morton, Ihor Solodrai, Alexei Starovoitov

From: Ihor Solodrai <ihor.solodrai@linux.dev>

commit 63c49efc987afefc6b9bb7de083eb8748e0b1789 upstream.

Replace bpf_strlcpy() in bpf_util.h with a sized_strscpy(), which is a
simplified sized_strscpy() from the kernel (lib/string.c [1]). It:
  * takes a count (destination size) parameter
  * guarantees NULL-termination
  * returns the number of characters copied or -E2BIG

Re-define strscpy macro similar to in-kernel implementation [2]: allow
the count parameter to be optional.

Add #ifdef-s to tools/include/linux/args.h, as they may be defined in
other system headers (for example, __CONCAT in sys/cdefs.h).

Fixup the single existing bpf_strlcpy() call in cgroup_helpers.c

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/string.c?h=v6.19#n113
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/string.h?h=v6.19#n91

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223190736.649171-2-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Stable-dep-of: 55ffbe8a15b1 ("selftests/bpf: Initialize operation name before use")
Closes: https://lore.kernel.org/stable/al8dSv_OvhwxFCar@u94a
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
Confirmed that BPF selftests successfully builds on 6.12[1] and 6.6[2]
after this patchset is applied.

1: https://github.com/kernel-patches/linux-stable/actions/runs/29986297264
2: https://github.com/kernel-patches/linux-stable/actions/runs/29987147891/
---
 tools/include/linux/args.h                   |  4 ++
 tools/testing/selftests/bpf/bpf_util.h       | 45 ++++++++++++++------
 tools/testing/selftests/bpf/cgroup_helpers.c |  2 +-
 3 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/tools/include/linux/args.h b/tools/include/linux/args.h
index 2e8e65d975c7..14b268f2389a 100644
--- a/tools/include/linux/args.h
+++ b/tools/include/linux/args.h
@@ -22,7 +22,11 @@
 #define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
 
 /* Concatenate two parameters, but allow them to be expanded beforehand. */
+#ifndef __CONCAT
 #define __CONCAT(a, b) a ## b
+#endif
+#ifndef CONCATENATE
 #define CONCATENATE(a, b) __CONCAT(a, b)
+#endif
 
 #endif	/* _LINUX_ARGS_H */
diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h
index feff92219e21..33486c460913 100644
--- a/tools/testing/selftests/bpf/bpf_util.h
+++ b/tools/testing/selftests/bpf/bpf_util.h
@@ -8,6 +8,7 @@
 #include <errno.h>
 #include <syscall.h>
 #include <bpf/libbpf.h> /* libbpf_num_possible_cpus */
+#include <linux/args.h>
 
 static inline unsigned int bpf_num_possible_cpus(void)
 {
@@ -21,25 +22,43 @@ static inline unsigned int bpf_num_possible_cpus(void)
 	return possible_cpus;
 }
 
-/* Copy up to sz - 1 bytes from zero-terminated src string and ensure that dst
- * is zero-terminated string no matter what (unless sz == 0, in which case
- * it's a no-op). It's conceptually close to FreeBSD's strlcpy(), but differs
- * in what is returned. Given this is internal helper, it's trivial to extend
- * this, when necessary. Use this instead of strncpy inside libbpf source code.
+/*
+ * Simplified strscpy() implementation. The kernel one is in lib/string.c
  */
-static inline void bpf_strlcpy(char *dst, const char *src, size_t sz)
+static inline ssize_t sized_strscpy(char *dest, const char *src, size_t count)
 {
-	size_t i;
+	long res = 0;
 
-	if (sz == 0)
-		return;
+	if (count == 0)
+		return -E2BIG;
 
-	sz--;
-	for (i = 0; i < sz && src[i]; i++)
-		dst[i] = src[i];
-	dst[i] = '\0';
+	while (count > 1) {
+		char c;
+
+		c = src[res];
+		dest[res] = c;
+		if (!c)
+			return res;
+		res++;
+		count--;
+	}
+
+	/* Force NUL-termination. */
+	dest[res] = '\0';
+
+	/* Return E2BIG if the source didn't stop */
+	return src[res] ? -E2BIG : res;
 }
 
+#define __strscpy0(dst, src, ...)	\
+	sized_strscpy(dst, src, sizeof(dst))
+#define __strscpy1(dst, src, size)	\
+	sized_strscpy(dst, src, size)
+
+#undef strscpy /* Redefine the placeholder from tools/include/linux/string.h */
+#define strscpy(dst, src, ...)	\
+	CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
+
 #define __bpf_percpu_val_align	__attribute__((__aligned__(8)))
 
 #define BPF_DECLARE_PERCPU(type, name)				\
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index e4535451322e..23bcf1aca76f 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -85,7 +85,7 @@ static int __enable_controllers(const char *cgroup_path, const char *controllers
 		enable[len] = 0;
 		close(fd);
 	} else {
-		bpf_strlcpy(enable, controllers, sizeof(enable));
+		strscpy(enable, controllers);
 	}
 
 	snprintf(path, sizeof(path), "%s/cgroup.subtree_control", cgroup_path);
-- 
2.55.0


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

* Re: [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests
  2026-07-23  7:13 [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Shung-Hsi Yu
  2026-07-23  7:13 ` [PATCH stable 6.12 6.6 2/2] selftests/bpf: Add simple strscpy() implementation Shung-Hsi Yu
@ 2026-07-23 10:19 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-07-23 10:19 UTC (permalink / raw)
  To: Shung-Hsi Yu
  Cc: stable, Lorenzo Stoakes, Jann Horn, John Hubbard, Liam Howlett,
	Sidhartha Kumar, Vlastimil Babka, Dan Williams, Peter Zijlstra,
	Andrew Morton

On Thu, Jul 23, 2026 at 03:13:31PM +0800, Shung-Hsi Yu wrote:
> From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> 
> commit 9a6a6a3191574a01dcf7a7d9385246d7bc8736bc upstream.
> 
> Commit 857d18f23ab1 ("cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for
> conditional locks") accidentally broke the radix tree, VMA userland tests
> by including linux/args.h which is not present in the tools/include
> directory.
> 
> This patch copies this over and adds an #ifdef block to avoid duplicate
> __CONCAT declaration in conflict with system headers when we ultimately
> include this.
> 
> Link: https://lkml.kernel.org/r/20250811052654.33286-1-lorenzo.stoakes@oracle.com
> Fixes: 857d18f23ab1 ("cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() for conditional locks")
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Cc: Jann Horn <jannh@google.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Liam Howlett <liam.howlett@oracle.com>
> Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Stable-dep-of: 63c49efc987a ("selftests/bpf: Add simple strscpy() implementation")
> Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
> ---
>  tools/include/linux/args.h       | 28 ++++++++++++++++++++++++++++
>  tools/testing/shared/linux/idr.h |  4 ++++
>  2 files changed, 32 insertions(+)
>  create mode 100644 tools/include/linux/args.h
> 
> diff --git a/tools/include/linux/args.h b/tools/include/linux/args.h
> new file mode 100644
> index 000000000000..2e8e65d975c7
> --- /dev/null
> +++ b/tools/include/linux/args.h
> @@ -0,0 +1,28 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef _LINUX_ARGS_H
> +#define _LINUX_ARGS_H
> +
> +/*
> + * How do these macros work?
> + *
> + * In __COUNT_ARGS() _0 to _12 are just placeholders from the start
> + * in order to make sure _n is positioned over the correct number
> + * from 12 to 0 (depending on X, which is a variadic argument list).
> + * They serve no purpose other than occupying a position. Since each
> + * macro parameter must have a distinct identifier, those identifiers
> + * are as good as any.
> + *
> + * In COUNT_ARGS() we use actual integers, so __COUNT_ARGS() returns
> + * that as _n.
> + */
> +
> +/* This counts to 15. Any more, it will return 16th argument. */
> +#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _n, X...) _n
> +#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
> +
> +/* Concatenate two parameters, but allow them to be expanded beforehand. */
> +#define __CONCAT(a, b) a ## b
> +#define CONCATENATE(a, b) __CONCAT(a, b)
> +
> +#endif	/* _LINUX_ARGS_H */
> diff --git a/tools/testing/shared/linux/idr.h b/tools/testing/shared/linux/idr.h
> index 4e342f2e37cf..676c5564e33f 100644
> --- a/tools/testing/shared/linux/idr.h
> +++ b/tools/testing/shared/linux/idr.h
> @@ -1 +1,5 @@
> +/* Avoid duplicate definitions due to system headers. */
> +#ifdef __CONCAT
> +#undef __CONCAT
> +#endif
>  #include "../../../../include/linux/idr.h"
> -- 
> 2.55.0
> 
> 

Does not apply to 6.6.y at all :(


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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23  7:13 [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Shung-Hsi Yu
2026-07-23  7:13 ` [PATCH stable 6.12 6.6 2/2] selftests/bpf: Add simple strscpy() implementation Shung-Hsi Yu
2026-07-23 10:19 ` [PATCH stable 6.12 6.6 1/2] tools/testing: add linux/args.h header and fix radix, VMA tests Greg KH

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