Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH v1] tools/rtla: Fix parse_cpu_set() and add unit test
From: Costa Shulyupin @ 2026-01-12 13:21 UTC (permalink / raw)
  To: Steven Rostedt, Tomas Glozar, Wander Lairson Costa,
	Costa Shulyupin, Ivan Pravdin, Tiezhu Yang, linux-kernel,
	linux-trace-kernel

The patch "Replace atoi() with a robust strtoi()" introduced a bug
in parse_cpu_set(), which relies on partial parsing of the input
string.

Restore the original use of atoi() in parse_cpu_set().

Add a unit test to prevent accidental regressions.

Fixes: 7e9dfccf8f11 ("rtla: Replace atoi() with a robust strtoi()")

Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
---
 tools/tracing/rtla/Makefile           |  3 ++
 tools/tracing/rtla/src/utils.c        | 10 ++--
 tools/tracing/rtla/tests/Makefile     | 12 +++++
 tools/tracing/rtla/tests/test_utils.c | 74 +++++++++++++++++++++++++++
 4 files changed, 93 insertions(+), 6 deletions(-)
 create mode 100644 tools/tracing/rtla/tests/Makefile
 create mode 100644 tools/tracing/rtla/tests/test_utils.c

diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index 2701256abaf3..1805916c7dba 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -109,7 +109,10 @@ clean: doc_clean fixdep-clean
 	$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
 	$(Q)rm -rf feature
 	$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
+
 check: $(RTLA) tests/bpf/bpf_action_map.o
+	make -C tests/ check
 	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f -v tests/
+
 examples: example/timerlat_bpf_action.o
 .PHONY: FORCE clean check
diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index 18986a5aed3c..0da3b2470c31 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -128,18 +128,16 @@ int parse_cpu_set(char *cpu_list, cpu_set_t *set)
 	nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
 
 	for (p = cpu_list; *p; ) {
-		if (strtoi(p, &cpu))
-			goto err;
-		if (cpu < 0 || cpu >= nr_cpus)
+		cpu = atoi(p);
+		if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
 			goto err;
 
 		while (isdigit(*p))
 			p++;
 		if (*p == '-') {
 			p++;
-			if (strtoi(p, &end_cpu))
-				goto err;
-			if (end_cpu < cpu || end_cpu >= nr_cpus)
+			end_cpu = atoi(p);
+			if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
 				goto err;
 			while (isdigit(*p))
 				p++;
diff --git a/tools/tracing/rtla/tests/Makefile b/tools/tracing/rtla/tests/Makefile
new file mode 100644
index 000000000000..fe187306a404
--- /dev/null
+++ b/tools/tracing/rtla/tests/Makefile
@@ -0,0 +1,12 @@
+LIBS := -lcheck
+
+test_utils: test_utils.c ../src/utils.c
+	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
+
+check: test_utils
+	./test_utils
+
+clean:
+	rm -f test_utils
+
+.PHONY: check clean
diff --git a/tools/tracing/rtla/tests/test_utils.c b/tools/tracing/rtla/tests/test_utils.c
new file mode 100644
index 000000000000..92ed49d60d33
--- /dev/null
+++ b/tools/tracing/rtla/tests/test_utils.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Unit tests for src/utils.c parsing functions
+ */
+
+#define _GNU_SOURCE
+#include <check.h>
+#include <unistd.h>
+
+#include "../src/utils.h"
+
+START_TEST(test_parse_cpu_set)
+{
+	cpu_set_t set;
+	int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
+
+	ck_assert_int_eq(parse_cpu_set("0", &set), 0);
+	ck_assert(CPU_ISSET(0, &set));
+	ck_assert(!CPU_ISSET(1, &set));
+
+	if (nr_cpus > 2) {
+		ck_assert_int_eq(parse_cpu_set("0,2", &set), 0);
+		ck_assert(CPU_ISSET(0, &set));
+		ck_assert(CPU_ISSET(2, &set));
+	}
+
+	if (nr_cpus > 3) {
+		ck_assert_int_eq(parse_cpu_set("0-3", &set), 0);
+		ck_assert(CPU_ISSET(0, &set));
+		ck_assert(CPU_ISSET(1, &set));
+		ck_assert(CPU_ISSET(2, &set));
+		ck_assert(CPU_ISSET(3, &set));
+	}
+
+	if (nr_cpus > 5) {
+		ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0);
+		ck_assert(!CPU_ISSET(0, &set));
+		ck_assert(CPU_ISSET(1, &set));
+		ck_assert(CPU_ISSET(2, &set));
+		ck_assert(CPU_ISSET(3, &set));
+		ck_assert(!CPU_ISSET(4, &set));
+		ck_assert(CPU_ISSET(5, &set));
+	}
+
+	ck_assert_int_ne(parse_cpu_set("-1", &set), 0);
+	ck_assert_int_ne(parse_cpu_set("abc", &set), 0);
+	ck_assert_int_ne(parse_cpu_set("9999", &set), 0);
+}
+END_TEST
+
+Suite *utils_suite(void)
+{
+	Suite *s = suite_create("utils");
+	TCase *tc = tcase_create("core");
+
+	tcase_add_test(tc, test_parse_cpu_set);
+
+	suite_add_tcase(s, tc);
+	return s;
+}
+
+int main(void)
+{
+	int num_failed;
+	SRunner *sr;
+
+	sr = srunner_create(utils_suite());
+	srunner_run_all(sr, CK_NORMAL);
+	num_failed = srunner_ntests_failed(sr);
+
+	srunner_free(sr);
+
+	return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
-- 
2.52.0


^ permalink raw reply related

* Re: [PATCH v2 04/18] rtla: Replace atoi() with a robust strtoi()
From: Tomas Glozar @ 2026-01-12 12:39 UTC (permalink / raw)
  To: Costa Shulyupin
  Cc: Wander Lairson Costa, Steven Rostedt, Ivan Pravdin, Crystal Wood,
	John Kacur, Tiezhu Yang,
	open list:Real-time Linux Analysis (RTLA) tools,
	open list:Real-time Linux Analysis (RTLA) tools,
	open list:BPF [MISC]:Keyword:(?:b|_)bpf(?:b|_)
In-Reply-To: <CADDUTFyEJxLHKHiaxya5QxW49kzWdhj=hzTygQYa9JPUOe8Zgw@mail.gmail.com>

po 12. 1. 2026 v 13:28 odesílatel Costa Shulyupin
<costa.shul@redhat.com> napsal:
>
> This commit breaks parse_cpu_set
>
> ./rtla timerlat hist -D -c 1,3
> Error parsing the cpu set 1,3
> Invalid -c cpu list
>
> ./rtla timerlat hist -D -c 1-3
> Error parsing the cpu set 1-3
> Invalid -c cpu list
>

It might not be the worst idea to test more than just "-c 0" in
tests/timerlat.t :)

Tomas


^ permalink raw reply

* Re: [PATCH v2 04/18] rtla: Replace atoi() with a robust strtoi()
From: Costa Shulyupin @ 2026-01-12 12:27 UTC (permalink / raw)
  To: Wander Lairson Costa
  Cc: Steven Rostedt, Tomas Glozar, Ivan Pravdin, Crystal Wood,
	John Kacur, Tiezhu Yang,
	open list:Real-time Linux Analysis (RTLA) tools,
	open list:Real-time Linux Analysis (RTLA) tools,
	open list:BPF [MISC]:Keyword:(?:b|_)bpf(?:b|_)
In-Reply-To: <20260106133655.249887-5-wander@redhat.com>

This commit breaks parse_cpu_set

./rtla timerlat hist -D -c 1,3
Error parsing the cpu set 1,3
Invalid -c cpu list

./rtla timerlat hist -D -c 1-3
Error parsing the cpu set 1-3
Invalid -c cpu list


^ permalink raw reply

* Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
From: Fushuai Wang @ 2026-01-12 12:22 UTC (permalink / raw)
  To: aliceryhl
  Cc: akpm, bp, brauner, cyphar, dave.hansen, fushuai.wang, hpa, jack,
	kees, linux-kernel, linux-trace-kernel, luto, mathieu.desnoyers,
	mhiramat, mingo, peterz, rostedt, tglx, vmalik, wangfushuai, x86,
	yury.norov
In-Reply-To: <CAH5fLgiPdBEN7mjgK64u19VGE_AWghTnCCHYuQQuwnTdvDaYkw@mail.gmail.com>

> strncpy_from_user() succeeds even if userspace data does not contain a
> nul. Then it reads length bytes.

Yes, but if there is no NUL byte in the user buf, whether you use
strncpy_from_user() or copy_from_user(), you need to manually add
a '\0' in the kernel buf to ensure it is properly NUL-terminated.
like:

	ret = strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1);
	if (ret < 0) {
		ret = -EFAULT;
		break;
	}
	buffer[sizeof(buffer) - 1] = '\0';

So I do not think copy_from_user() + '\0' can be instead of strncpy_from_user().
I think strncpy_from_user() can only be used without manually appending '\0'
if someone are certain that the user buf contains a NUL byte.

---
Regards,
WANG

> As far as I can tell, when a nul byte is present, none of these kernel
> use-cases use data after the nul byte. So the behavior is identical
> except that copy_from_user_nul() may result in EFAULT if there are
> unmapped bytes between the first nul byte in `src` and `src+len`.
> 
> Alice


^ permalink raw reply

* [PATCHv3 bpf-next 2/2] selftests/bpf: Add test for bpf_override_return helper
From: Jiri Olsa @ 2026-01-12 12:11 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt, Will Deacon
  Cc: Song Liu, Peter Zijlstra, bpf, linux-trace-kernel,
	linux-arm-kernel, x86, Yonghong Song, Song Liu, Andrii Nakryiko,
	Mark Rutland, Mahe Tardy
In-Reply-To: <20260112121157.854473-1-jolsa@kernel.org>

We do not actually test the bpf_override_return helper functionality
itself at the moment, only the bpf program being able to attach it.

Adding test that override prctl syscall return value on top of
kprobe and kprobe.multi.

Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../bpf/prog_tests/kprobe_multi_test.c        | 44 +++++++++++++++++++
 .../bpf/progs/kprobe_multi_override.c         | 15 +++++++
 tools/testing/selftests/bpf/trace_helpers.h   | 12 +++++
 3 files changed, 71 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 6cfaa978bc9a..9caef222e528 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1,4 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <errno.h>
+#include <sys/prctl.h>
 #include <test_progs.h>
 #include "kprobe_multi.skel.h"
 #include "trace_helpers.h"
@@ -540,6 +542,46 @@ static void test_attach_override(void)
 	kprobe_multi_override__destroy(skel);
 }
 
+static void test_override(void)
+{
+	struct kprobe_multi_override *skel = NULL;
+	int err;
+
+	skel = kprobe_multi_override__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "kprobe_multi_empty__open_and_load"))
+		goto cleanup;
+
+	skel->bss->pid = getpid();
+
+	/* no override */
+	err = prctl(0xffff, 0);
+	ASSERT_EQ(err, -1, "err");
+
+	/* kprobe.multi override */
+	skel->links.test_override = bpf_program__attach_kprobe_multi_opts(skel->progs.test_override,
+						SYS_PREFIX "sys_prctl", NULL);
+	if (!ASSERT_OK_PTR(skel->links.test_override, "bpf_program__attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	err = prctl(0xffff, 0);
+	ASSERT_EQ(err, 123, "err");
+
+	bpf_link__destroy(skel->links.test_override);
+	skel->links.test_override = NULL;
+
+	/* kprobe override */
+	skel->links.test_kprobe_override = bpf_program__attach_kprobe(skel->progs.test_kprobe_override,
+							false, SYS_PREFIX "sys_prctl");
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_override, "bpf_program__attach_kprobe"))
+		goto cleanup;
+
+	err = prctl(0xffff, 0);
+	ASSERT_EQ(err, 123, "err");
+
+cleanup:
+	kprobe_multi_override__destroy(skel);
+}
+
 #ifdef __x86_64__
 static void test_attach_write_ctx(void)
 {
@@ -597,6 +639,8 @@ void test_kprobe_multi_test(void)
 		test_attach_api_fails();
 	if (test__start_subtest("attach_override"))
 		test_attach_override();
+	if (test__start_subtest("override"))
+		test_override();
 	if (test__start_subtest("session"))
 		test_session_skel_api();
 	if (test__start_subtest("session_cookie"))
diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_override.c b/tools/testing/selftests/bpf/progs/kprobe_multi_override.c
index 28f8487c9059..14f39fa6d515 100644
--- a/tools/testing/selftests/bpf/progs/kprobe_multi_override.c
+++ b/tools/testing/selftests/bpf/progs/kprobe_multi_override.c
@@ -5,9 +5,24 @@
 
 char _license[] SEC("license") = "GPL";
 
+int pid = 0;
+
 SEC("kprobe.multi")
 int test_override(struct pt_regs *ctx)
 {
+	if (bpf_get_current_pid_tgid() >> 32 != pid)
+		return 0;
+
+	bpf_override_return(ctx, 123);
+	return 0;
+}
+
+SEC("kprobe")
+int test_kprobe_override(struct pt_regs *ctx)
+{
+	if (bpf_get_current_pid_tgid() >> 32 != pid)
+		return 0;
+
 	bpf_override_return(ctx, 123);
 	return 0;
 }
diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
index 9437bdd4afa5..a5576b2dfc26 100644
--- a/tools/testing/selftests/bpf/trace_helpers.h
+++ b/tools/testing/selftests/bpf/trace_helpers.h
@@ -4,6 +4,18 @@
 
 #include <bpf/libbpf.h>
 
+#ifdef __x86_64__
+#define SYS_PREFIX "__x64_"
+#elif defined(__s390x__)
+#define SYS_PREFIX "__s390x_"
+#elif defined(__aarch64__)
+#define SYS_PREFIX "__arm64_"
+#elif defined(__riscv)
+#define SYS_PREFIX "__riscv_"
+#else
+#define SYS_PREFIX ""
+#endif
+
 #define __ALIGN_MASK(x, mask)	(((x)+(mask))&~(mask))
 #define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a)-1)
 
-- 
2.52.0


^ permalink raw reply related

* [PATCHv3 bpf-next 1/2] arm64/ftrace,bpf: Fix partial regs after bpf_prog_run
From: Jiri Olsa @ 2026-01-12 12:11 UTC (permalink / raw)
  To: Masami Hiramatsu, Steven Rostedt, Will Deacon
  Cc: Mahe Tardy, Peter Zijlstra, bpf, linux-trace-kernel,
	linux-arm-kernel, x86, Yonghong Song, Song Liu, Andrii Nakryiko,
	Mark Rutland

Mahe reported issue with bpf_override_return helper not working when
executed from kprobe.multi bpf program on arm.

The problem is that on arm we use alternate storage for pt_regs object
that is passed to bpf_prog_run and if any register is changed (which
is the case of bpf_override_return) it's not propagated back to actual
pt_regs object.

Fixing this by introducing and calling ftrace_partial_regs_update function
to propagate the values of changed registers (ip and stack).

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Acked-by: Will Deacon <will@kernel.org>
Reported-by: Mahe Tardy <mahe.tardy@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
v3 changes:
- drop const from fregs argument [ci]
- added acks

 include/linux/ftrace_regs.h | 25 +++++++++++++++++++++++++
 kernel/trace/bpf_trace.c    |  1 +
 2 files changed, 26 insertions(+)

diff --git a/include/linux/ftrace_regs.h b/include/linux/ftrace_regs.h
index 15627ceea9bc..386fa48c4a95 100644
--- a/include/linux/ftrace_regs.h
+++ b/include/linux/ftrace_regs.h
@@ -33,6 +33,31 @@ struct ftrace_regs;
 #define ftrace_regs_get_frame_pointer(fregs) \
 	frame_pointer(&arch_ftrace_regs(fregs)->regs)
 
+static __always_inline void
+ftrace_partial_regs_update(struct ftrace_regs *fregs, struct pt_regs *regs) { }
+
+#else
+
+/*
+ * ftrace_partial_regs_update - update the original ftrace_regs from regs
+ * @fregs: The ftrace_regs to update from @regs
+ * @regs: The partial regs from ftrace_partial_regs() that was updated
+ *
+ * Some architectures have the partial regs living in the ftrace_regs
+ * structure, whereas other architectures need to make a different copy
+ * of the @regs. If a partial @regs is retrieved by ftrace_partial_regs() and
+ * if the code using @regs updates a field (like the instruction pointer or
+ * stack pointer) it may need to propagate that change to the original @fregs
+ * it retrieved the partial @regs from. Use this function to guarantee that
+ * update happens.
+ */
+static __always_inline void
+ftrace_partial_regs_update(struct ftrace_regs *fregs, struct pt_regs *regs)
+{
+	ftrace_regs_set_instruction_pointer(fregs, instruction_pointer(regs));
+	ftrace_regs_set_return_value(fregs, regs_return_value(regs));
+}
+
 #endif /* HAVE_ARCH_FTRACE_REGS */
 
 /* This can be overridden by the architectures */
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 6e076485bf70..3a17f79b20c2 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2564,6 +2564,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
 	old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
 	err = bpf_prog_run(link->link.prog, regs);
 	bpf_reset_run_ctx(old_run_ctx);
+	ftrace_partial_regs_update(fregs, bpf_kprobe_multi_pt_regs_ptr());
 	rcu_read_unlock();
 
  out:
-- 
2.52.0


^ permalink raw reply related

* Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
From: Alice Ryhl @ 2026-01-12 11:20 UTC (permalink / raw)
  To: Fushuai Wang
  Cc: akpm, bp, brauner, cyphar, dave.hansen, hpa, jack, kees,
	linux-kernel, linux-trace-kernel, luto, mathieu.desnoyers,
	mhiramat, mingo, peterz, rostedt, tglx, vmalik, wangfushuai, x86,
	yury.norov
In-Reply-To: <20260112100059.12139-1-fushuai.wang@linux.dev>

On Mon, Jan 12, 2026 at 11:01 AM Fushuai Wang <fushuai.wang@linux.dev> wrote:
>
> >> From: Fushuai Wang <wangfushuai@baidu.com>
> >>
> >> Many places call copy_from_user() to copy a buffer from user space,
> >> and then manually add a NULL terminator to the destination buffer,
> >> e.g.:
> >>
> >>      if (copy_from_user(dest, src, len))
> >>              return -EFAULT;
> >>      dest[len] = '\0';
> >>
> >> This is repetitive and error-prone. Add a copy_from_user_nul() helper to
> >> simplify such patterns. It copied n bytes from user space to kernel space,
> >> and NUL-terminates the destination buffer.
> >>
> >> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
> >
> > Hmm, this function is very very similar to strncpy_from_user(). Should
> > they be using that instead?
> >
> > Alice
>
> The strncpy_from_user() is for NUL-terminated strings and stops at the
> first NUL in userspace. But copy_from_user_nul() always copies a fixed length
> and adds a NUL at the end in kernel space, even if userspace data doesn’t
> contain a NUL.
>
> So I think they are for different cases and can’t replace each other.

strncpy_from_user() succeeds even if userspace data does not contain a
nul. Then it reads length bytes.

As far as I can tell, when a nul byte is present, none of these kernel
use-cases use data after the nul byte. So the behavior is identical
except that copy_from_user_nul() may result in EFAULT if there are
unmapped bytes between the first nul byte in `src` and `src+len`.

Alice

^ permalink raw reply

* Re: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
From: kernel test robot @ 2026-01-12 10:15 UTC (permalink / raw)
  To: Shawn Lin, Manivannan Sadhasivam, Bjorn Helgaas
  Cc: llvm, oe-kbuild-all, linux-rockchip, linux-pci,
	linux-trace-kernel, linux-doc, Steven Rostedt, Masami Hiramatsu,
	Shawn Lin
In-Reply-To: <1768180800-63364-4-git-send-email-shawn.lin@rock-chips.com>

Hi Shawn,

kernel test robot noticed the following build errors:

[auto build test ERROR on pci/next]
[also build test ERROR on next-20260109]
[cannot apply to pci/for-linus trace/for-next mani-mhi/mhi-next linus/master v6.19-rc5]
[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/Shawn-Lin/PCI-trace-Add-PCI-controller-LTSSM-transition-tracepoint/20260112-100141
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/1768180800-63364-4-git-send-email-shawn.lin%40rock-chips.com
patch subject: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
config: arm64-randconfig-004-20260112 (https://download.01.org/0day-ci/archive/20260112/202601121712.JbsMAjDZ-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601121712.JbsMAjDZ-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/202601121712.JbsMAjDZ-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:6: error: call to undeclared function 'dw_pcie_ltssm_status_string'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     264 |                                         dw_pcie_ltssm_status_string(state),
         |                                         ^
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:6: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Wint-conversion]
     264 |                                         dw_pcie_ltssm_status_string(state),
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/events/pci_controller.h:20:45: note: passing argument to parameter 'state' here
      20 |         TP_PROTO(const char *dev_name, const char *state, u32 rate),
         |                                                    ^
   2 errors generated.


vim +/dw_pcie_ltssm_status_string +264 drivers/pci/controller/dwc/pcie-dw-rockchip.c

   225	
   226	#ifdef CONFIG_TRACING
   227	static void rockchip_pcie_ltssm_trace_work(struct work_struct *work)
   228	{
   229		struct rockchip_pcie *rockchip = container_of(work, struct rockchip_pcie,
   230							trace_work.work);
   231		struct dw_pcie *pci = &rockchip->pci;
   232		enum dw_pcie_ltssm state;
   233		u32 i, l1ss, prev_val = DW_PCIE_LTSSM_UNKNOWN, rate, val;
   234	
   235		for (i = 0; i < PCIE_DBG_LTSSM_HISTORY_CNT; i++) {
   236			val = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_DBG_FIFO_STATUS);
   237			rate = FIELD_GET(PCIE_DBG_FIFO_RATE_MASK, val);
   238			l1ss = FIELD_GET(PCIE_DBG_FIFO_L1SUB_MASK, val);
   239			val = FIELD_GET(PCIE_LTSSM_STATUS_MASK, val);
   240	
   241			/*
   242			 * Hardware Mechanism: The ring FIFO employs two tracking counters:
   243			 * - 'last-read-point': maintains the user's last read position
   244			 * - 'last-valid-point': tracks the hardware's last state update
   245			 *
   246			 * Software Handling: When two consecutive LTSSM states are identical,
   247			 * it indicates invalid subsequent data in the FIFO. In this case, we
   248			 * skip the remaining entries. The dual-counter design ensures that on
   249			 * the next state transition, reading can resume from the last user
   250			 * position.
   251			 */
   252			if ((i > 0 && val == prev_val) || val > DW_PCIE_LTSSM_RCVRY_EQ3)
   253				break;
   254	
   255			state = prev_val = val;
   256			if (val == DW_PCIE_LTSSM_L1_IDLE) {
   257				if (l1ss == 2)
   258					state = DW_PCIE_LTSSM_L1_2;
   259				else if (l1ss == 1)
   260					state = DW_PCIE_LTSSM_L1_1;
   261			}
   262	
   263			trace_pcie_ltssm_state_transition(dev_name(pci->dev),
 > 264						dw_pcie_ltssm_status_string(state),
   265						((rate + 1) > pci->max_link_speed) ?
   266						PCI_SPEED_UNKNOWN : PCIE_SPEED_2_5GT + rate);
   267		}
   268	
   269		schedule_delayed_work(&rockchip->trace_work, msecs_to_jiffies(5000));
   270	}
   271	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply

* Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
From: Fushuai Wang @ 2026-01-12 10:00 UTC (permalink / raw)
  To: aliceryhl
  Cc: akpm, bp, brauner, cyphar, dave.hansen, fushuai.wang, hpa, jack,
	kees, linux-kernel, linux-trace-kernel, luto, mathieu.desnoyers,
	mhiramat, mingo, peterz, rostedt, tglx, vmalik, wangfushuai, x86,
	yury.norov
In-Reply-To: <aWS9nOj4MAa7pYmS@google.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 999 bytes --]

>> From: Fushuai Wang <wangfushuai@baidu.com>
>> 
>> Many places call copy_from_user() to copy a buffer from user space,
>> and then manually add a NULL terminator to the destination buffer,
>> e.g.:
>> 
>> 	if (copy_from_user(dest, src, len))
>> 		return -EFAULT;
>> 	dest[len] = '\0';
>> 
>> This is repetitive and error-prone. Add a copy_from_user_nul() helper to
>> simplify such patterns. It copied n bytes from user space to kernel space,
>> and NUL-terminates the destination buffer.
>> 
>> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
>
> Hmm, this function is very very similar to strncpy_from_user(). Should
> they be using that instead?
> 
> Alice

The strncpy_from_user() is for NUL-terminated strings and stops at the
first NUL in userspace. But copy_from_user_nul() always copies a fixed length
and adds a NUL at the end in kernel space, even if userspace data doesn’t
contain a NUL.

So I think they are for different cases and can’t replace each other.

---
Regards,
WANG

^ permalink raw reply

* Re: [PATCH] arm64/mm: Fix annotated branch unbootable kernel
From: Breno Leitao @ 2026-01-12  9:42 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Laura Abbott,
	linux-arm-kernel, linux-kernel, linux-trace-kernel,
	Masami Hiramatsu, puranjay, usamaarif642, kernel-team, stable
In-Reply-To: <20260109145022.35da01a3@gandalf.local.home>

Hello Steven,

On Fri, Jan 09, 2026 at 02:50:22PM -0500, Steven Rostedt wrote:
> [ Resending with my kernel.org email, as I received a bunch of messages from gmail saying it's blocking me :-p ]
> 
> On Mon, 5 Jan 2026 21:15:40 +0000
> Will Deacon <will@kernel.org> wrote:
> 
> > > Another approach is to disable profiling on all arch/arm64 code, similarly to
> > > x86, where DISABLE_BRANCH_PROFILING is called for all arch/x86 code. See
> > > commit 2cbb20b008dba ("tracing: Disable branch profiling in noinstr
> > > code").  
> > 
> > Yes, let's start with arch/arm64/. We know that's safe and then if
> > somebody wants to make it finer-grained, it's on them to figure out a
> > way to do it without playing whack-a-mole.
> 
> OK, so by adding -DDISABLE_BRANCH_PROFILING to the Makefile configs and for
> the files that were audited, could be opt-in?

How to do the audit in this case? I suppose we want to disable branch
profiling for files that have any function that would eventually call
noinstr functions, right?

^ permalink raw reply

* Re: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
From: kernel test robot @ 2026-01-12  9:31 UTC (permalink / raw)
  To: Shawn Lin, Manivannan Sadhasivam, Bjorn Helgaas
  Cc: oe-kbuild-all, linux-rockchip, linux-pci, linux-trace-kernel,
	linux-doc, Steven Rostedt, Masami Hiramatsu, Shawn Lin
In-Reply-To: <1768180800-63364-4-git-send-email-shawn.lin@rock-chips.com>

Hi Shawn,

kernel test robot noticed the following build warnings:

[auto build test WARNING on pci/next]
[also build test WARNING on next-20260109]
[cannot apply to pci/for-linus trace/for-next mani-mhi/mhi-next linus/master v6.19-rc5]
[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/Shawn-Lin/PCI-trace-Add-PCI-controller-LTSSM-transition-tracepoint/20260112-100141
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/1768180800-63364-4-git-send-email-shawn.lin%40rock-chips.com
patch subject: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
config: arm64-randconfig-002-20260112 (https://download.01.org/0day-ci/archive/20260112/202601121734.epct0ieX-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601121734.epct0ieX-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/202601121734.epct0ieX-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/pci/controller/dwc/pcie-dw-rockchip.c: In function 'rockchip_pcie_ltssm_trace_work':
   drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:6: error: implicit declaration of function 'dw_pcie_ltssm_status_string'; did you mean 'dw_pcie_start_link'? [-Werror=implicit-function-declaration]
         dw_pcie_ltssm_status_string(state),
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
         dw_pcie_start_link
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:6: warning: passing argument 2 of 'trace_pcie_ltssm_state_transition' makes pointer from integer without a cast [-Wint-conversion]
         dw_pcie_ltssm_status_string(state),
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In file included from include/trace/events/pci_controller.h:9,
                    from drivers/pci/controller/dwc/pcie-dw-rockchip.c:26:
   include/trace/events/pci_controller.h:20:45: note: expected 'const char *' but argument is of type 'int'
     TP_PROTO(const char *dev_name, const char *state, u32 rate),
                                    ~~~~~~~~~~~~^~~~~
   include/linux/tracepoint.h:288:34: note: in definition of macro '__DECLARE_TRACE'
     static inline void trace_##name(proto)    \
                                     ^~~~~
   include/linux/tracepoint.h:494:24: note: in expansion of macro 'PARAMS'
     __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),  \
                           ^~~~~~
   include/linux/tracepoint.h:632:2: note: in expansion of macro 'DECLARE_TRACE_EVENT'
     DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
     ^~~~~~~~~~~~~~~~~~~
   include/linux/tracepoint.h:632:28: note: in expansion of macro 'PARAMS'
     DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
                               ^~~~~~
   include/trace/events/pci_controller.h:19:1: note: in expansion of macro 'TRACE_EVENT'
    TRACE_EVENT(pcie_ltssm_state_transition,
    ^~~~~~~~~~~
   include/trace/events/pci_controller.h:20:2: note: in expansion of macro 'TP_PROTO'
     TP_PROTO(const char *dev_name, const char *state, u32 rate),
     ^~~~~~~~
   cc1: some warnings being treated as errors


vim +/trace_pcie_ltssm_state_transition +264 drivers/pci/controller/dwc/pcie-dw-rockchip.c

   225	
   226	#ifdef CONFIG_TRACING
   227	static void rockchip_pcie_ltssm_trace_work(struct work_struct *work)
   228	{
   229		struct rockchip_pcie *rockchip = container_of(work, struct rockchip_pcie,
   230							trace_work.work);
   231		struct dw_pcie *pci = &rockchip->pci;
   232		enum dw_pcie_ltssm state;
   233		u32 i, l1ss, prev_val = DW_PCIE_LTSSM_UNKNOWN, rate, val;
   234	
   235		for (i = 0; i < PCIE_DBG_LTSSM_HISTORY_CNT; i++) {
   236			val = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_DBG_FIFO_STATUS);
   237			rate = FIELD_GET(PCIE_DBG_FIFO_RATE_MASK, val);
   238			l1ss = FIELD_GET(PCIE_DBG_FIFO_L1SUB_MASK, val);
   239			val = FIELD_GET(PCIE_LTSSM_STATUS_MASK, val);
   240	
   241			/*
   242			 * Hardware Mechanism: The ring FIFO employs two tracking counters:
   243			 * - 'last-read-point': maintains the user's last read position
   244			 * - 'last-valid-point': tracks the hardware's last state update
   245			 *
   246			 * Software Handling: When two consecutive LTSSM states are identical,
   247			 * it indicates invalid subsequent data in the FIFO. In this case, we
   248			 * skip the remaining entries. The dual-counter design ensures that on
   249			 * the next state transition, reading can resume from the last user
   250			 * position.
   251			 */
   252			if ((i > 0 && val == prev_val) || val > DW_PCIE_LTSSM_RCVRY_EQ3)
   253				break;
   254	
   255			state = prev_val = val;
   256			if (val == DW_PCIE_LTSSM_L1_IDLE) {
   257				if (l1ss == 2)
   258					state = DW_PCIE_LTSSM_L1_2;
   259				else if (l1ss == 1)
   260					state = DW_PCIE_LTSSM_L1_1;
   261			}
   262	
   263			trace_pcie_ltssm_state_transition(dev_name(pci->dev),
 > 264						dw_pcie_ltssm_status_string(state),
   265						((rate + 1) > pci->max_link_speed) ?
   266						PCI_SPEED_UNKNOWN : PCIE_SPEED_2_5GT + rate);
   267		}
   268	
   269		schedule_delayed_work(&rockchip->trace_work, msecs_to_jiffies(5000));
   270	}
   271	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply

* Re: [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
From: Alice Ryhl @ 2026-01-12  9:23 UTC (permalink / raw)
  To: Fushuai Wang
  Cc: tglx, peterz, mathieu.desnoyers, akpm, yury.norov, vmalik, kees,
	dave.hansen, luto, mingo, bp, hpa, rostedt, mhiramat, brauner,
	jack, cyphar, linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-2-fushuai.wang@linux.dev>

On Mon, Jan 12, 2026 at 03:30:34PM +0800, Fushuai Wang wrote:
> From: Fushuai Wang <wangfushuai@baidu.com>
> 
> Many places call copy_from_user() to copy a buffer from user space,
> and then manually add a NULL terminator to the destination buffer,
> e.g.:
> 
> 	if (copy_from_user(dest, src, len))
> 		return -EFAULT;
> 	dest[len] = '\0';
> 
> This is repetitive and error-prone. Add a copy_from_user_nul() helper to
> simplify such patterns. It copied n bytes from user space to kernel space,
> and NUL-terminates the destination buffer.
> 
> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>

Hmm, this function is very very similar to strncpy_from_user(). Should
they be using that instead?

Alice

^ permalink raw reply

* Re: [PATCH v13 2/3] mm: Fix OOM killer inaccuracy on large many-core systems
From: Michal Hocko @ 2026-01-12  8:42 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: Andrew Morton, linux-kernel, Paul E. McKenney, Steven Rostedt,
	Masami Hiramatsu, Dennis Zhou, Tejun Heo, Christoph Lameter,
	Martin Liu, David Rientjes, christian.koenig, Shakeel Butt,
	SeongJae Park, Johannes Weiner, Sweet Tea Dorminy,
	Lorenzo Stoakes, Liam R . Howlett, Mike Rapoport,
	Suren Baghdasaryan, Vlastimil Babka, Christian Brauner, Wei Yang,
	David Hildenbrand, Miaohe Lin, Al Viro, linux-mm,
	linux-trace-kernel, Yu Zhao, Roman Gushchin, Mateusz Guzik,
	Matthew Wilcox, Baolin Wang, Aboorva Devarajan
In-Reply-To: <20260111194958.1231477-3-mathieu.desnoyers@efficios.com>

Hi,
sorry to jump in this late but the timing of previous versions didn't
really work well for me.

On Sun 11-01-26 14:49:57, Mathieu Desnoyers wrote:
[...]
> Here is a (possibly incomplete) list of the prior approaches that were
> used or proposed, along with their downside:
> 
> 1) Per-thread rss tracking: large error on many-thread processes.
> 
> 2) Per-CPU counters: up to 12% slower for short-lived processes and 9%
>    increased system time in make test workloads [1]. Moreover, the
>    inaccuracy increases with O(n^2) with the number of CPUs.
> 
> 3) Per-NUMA-node counters: requires atomics on fast-path (overhead),
>    error is high with systems that have lots of NUMA nodes (32 times
>    the number of NUMA nodes).
> 
> The approach proposed here is to replace this by the hierarchical
> per-cpu counters, which bounds the inaccuracy based on the system
> topology with O(N*logN).

The concept of hierarchical pcp counter is interesting and I am
definitely not opposed if there are more users that would benefit.

From the OOM POV, IIUC the primary problem is that get_mm_counter
(percpu_counter_read_positive) is too imprecise on systems when the task
is moving around a large number of cpus. In the list of alternative
solutions I do not see percpu_counter_sum_positive to be mentioned.
oom_badness() is a really slow path and taking the slow path to
calculate a much more precise value seems acceptable. Have you
considered that option?

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply

* Re: [PATCH v2] tracing: Replace use of system_wq with system_dfl_wq
From: Marco Crivellari @ 2026-01-12  8:24 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, linux-trace-kernel, Tejun Heo, Lai Jiangshan,
	Frederic Weisbecker, Sebastian Andrzej Siewior, Michal Hocko,
	Masami Hiramatsu, Mathieu Desnoyers
In-Reply-To: <20260109142758.145f57f8@gandalf.local.home>

On Fri, Jan 9, 2026 at 8:27 PM Steven Rostedt <rostedt@goodmis.org> wrote:
> [...]
> I guess I'll take this through my tree, as I'm pulling in patches now to
> base off of -rc5.

Many thanks Steven!

-- 

Marco Crivellari

L3 Support Engineer

^ permalink raw reply

* Re: [PATCH v12 3/3] mm: Implement precise OOM killer task selection
From: Dan Carpenter @ 2026-01-12  8:06 UTC (permalink / raw)
  To: oe-kbuild, Mathieu Desnoyers, Andrew Morton
  Cc: lkp, oe-kbuild-all, Linux Memory Management List, linux-kernel,
	Mathieu Desnoyers, Paul E. McKenney, Steven Rostedt,
	Masami Hiramatsu, Dennis Zhou, Tejun Heo, Christoph Lameter,
	Martin Liu, David Rientjes, christian.koenig, Shakeel Butt,
	SeongJae Park, Michal Hocko, Johannes Weiner, Sweet Tea Dorminy,
	Lorenzo Stoakes, Liam R . Howlett, Mike Rapoport,
	Suren Baghdasaryan, Vlastimil Babka, Christian Brauner, Wei Yang,
	David Hildenbrand, Miaohe Lin, Al Viro, linux-trace-kernel,
	Yu Zhao
In-Reply-To: <20260111150249.1222944-4-mathieu.desnoyers@efficios.com>

Hi Mathieu,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Desnoyers/lib-Introduce-hierarchical-per-cpu-counters/20260111-231206
base:   next-20260109
patch link:    https://lore.kernel.org/r/20260111150249.1222944-4-mathieu.desnoyers%40efficios.com
patch subject: [PATCH v12 3/3] mm: Implement precise OOM killer task selection
config: s390-randconfig-r071-20260112 (https://download.01.org/0day-ci/archive/20260112/202601120452.VufCnz2j-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 14.3.0
smatch version: v0.5.0-8985-g2614ff1a

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 <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202601120452.VufCnz2j-lkp@intel.com/

smatch warnings:
mm/oom_kill.c:392 oom_evaluate_task() error: uninitialized symbol 'points_min'.

vim +/points_min +392 mm/oom_kill.c

7c5f64f84483bd1 Vladimir Davydov  2016-10-07  322  static int oom_evaluate_task(struct task_struct *task, void *arg)
462607ecc519b19 David Rientjes    2012-07-31  323  {
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  324  	struct oom_control *oc = arg;
72456781289a6ed Mathieu Desnoyers 2026-01-11  325  	unsigned long accuracy_under = 0, accuracy_over = 0;
72456781289a6ed Mathieu Desnoyers 2026-01-11  326  	long points, points_min, points_max;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  327  
ac311a14c682dcd Shakeel Butt      2019-07-11  328  	if (oom_unkillable_task(task))
ac311a14c682dcd Shakeel Butt      2019-07-11  329  		goto next;
ac311a14c682dcd Shakeel Butt      2019-07-11  330  
ac311a14c682dcd Shakeel Butt      2019-07-11  331  	/* p may not have freeable memory in nodemask */
ac311a14c682dcd Shakeel Butt      2019-07-11  332  	if (!is_memcg_oom(oc) && !oom_cpuset_eligible(task, oc))
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  333  		goto next;
462607ecc519b19 David Rientjes    2012-07-31  334  
462607ecc519b19 David Rientjes    2012-07-31  335  	/*
462607ecc519b19 David Rientjes    2012-07-31  336  	 * This task already has access to memory reserves and is being killed.
a373966d1f64c04 Michal Hocko      2016-07-28  337  	 * Don't allow any other task to have access to the reserves unless
862e3073b3eed13 Michal Hocko      2016-10-07  338  	 * the task has MMF_OOM_SKIP because chances that it would release
a373966d1f64c04 Michal Hocko      2016-07-28  339  	 * any memory is quite low.
462607ecc519b19 David Rientjes    2012-07-31  340  	 */
862e3073b3eed13 Michal Hocko      2016-10-07  341  	if (!is_sysrq_oom(oc) && tsk_is_oom_victim(task)) {
12e423ba4eaed7b Lorenzo Stoakes   2025-08-12  342  		if (mm_flags_test(MMF_OOM_SKIP, task->signal->oom_mm))
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  343  			goto next;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  344  		goto abort;
a373966d1f64c04 Michal Hocko      2016-07-28  345  	}
462607ecc519b19 David Rientjes    2012-07-31  346  
e1e12d2f3104be8 David Rientjes    2012-12-11  347  	/*
e1e12d2f3104be8 David Rientjes    2012-12-11  348  	 * If task is allocating a lot of memory and has been marked to be
e1e12d2f3104be8 David Rientjes    2012-12-11  349  	 * killed first if it triggers an oom, then select it.
e1e12d2f3104be8 David Rientjes    2012-12-11  350  	 */
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  351  	if (oom_task_origin(task)) {
9066e5cfb73cdbc Yafang Shao       2020-08-11  352  		points = LONG_MAX;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  353  		goto select;

points_min is uninitialized.

7c5f64f84483bd1 Vladimir Davydov  2016-10-07  354  	}
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  355  
72456781289a6ed Mathieu Desnoyers 2026-01-11  356  	points = oom_badness(task, oc->totalpages, true, &accuracy_under, &accuracy_over);
72456781289a6ed Mathieu Desnoyers 2026-01-11  357  	if (points != LONG_MIN) {
72456781289a6ed Mathieu Desnoyers 2026-01-11  358  		percpu_counter_tree_approximate_min_max_range(points,
72456781289a6ed Mathieu Desnoyers 2026-01-11  359  				accuracy_under, accuracy_over,
72456781289a6ed Mathieu Desnoyers 2026-01-11  360  				&points_min, &points_max);
72456781289a6ed Mathieu Desnoyers 2026-01-11  361  	}
72456781289a6ed Mathieu Desnoyers 2026-01-11  362  	if (oc->approximate) {
72456781289a6ed Mathieu Desnoyers 2026-01-11  363  		/*
72456781289a6ed Mathieu Desnoyers 2026-01-11  364  		 * Keep the process which has the highest minimum
72456781289a6ed Mathieu Desnoyers 2026-01-11  365  		 * possible points value based on approximation.
72456781289a6ed Mathieu Desnoyers 2026-01-11  366  		 */
72456781289a6ed Mathieu Desnoyers 2026-01-11  367  		if (points == LONG_MIN || points_min < oc->chosen_points)
72456781289a6ed Mathieu Desnoyers 2026-01-11  368  			goto next;
72456781289a6ed Mathieu Desnoyers 2026-01-11  369  	} else {
72456781289a6ed Mathieu Desnoyers 2026-01-11  370  		/*
72456781289a6ed Mathieu Desnoyers 2026-01-11  371  		 * Eliminate processes which are certainly below the
72456781289a6ed Mathieu Desnoyers 2026-01-11  372  		 * chosen points minimum possible value with an
72456781289a6ed Mathieu Desnoyers 2026-01-11  373  		 * approximation.
72456781289a6ed Mathieu Desnoyers 2026-01-11  374  		 */
72456781289a6ed Mathieu Desnoyers 2026-01-11  375  		if (points == LONG_MIN || (long)(points_max - oc->chosen_points) < 0)
72456781289a6ed Mathieu Desnoyers 2026-01-11  376  			goto next;
72456781289a6ed Mathieu Desnoyers 2026-01-11  377  
72456781289a6ed Mathieu Desnoyers 2026-01-11  378  		if (oc->nr_precise < max_precise_badness_sums) {
72456781289a6ed Mathieu Desnoyers 2026-01-11  379  			oc->nr_precise++;
72456781289a6ed Mathieu Desnoyers 2026-01-11  380  			/* Precise evaluation. */
72456781289a6ed Mathieu Desnoyers 2026-01-11  381  			points_min = points_max = points = oom_badness(task, oc->totalpages, false, NULL, NULL);
72456781289a6ed Mathieu Desnoyers 2026-01-11  382  			if (points == LONG_MIN || (long)(points - oc->chosen_points) < 0)
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  383  				goto next;
72456781289a6ed Mathieu Desnoyers 2026-01-11  384  		}
72456781289a6ed Mathieu Desnoyers 2026-01-11  385  	}
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  386  
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  387  select:
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  388  	if (oc->chosen)
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  389  		put_task_struct(oc->chosen);
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  390  	get_task_struct(task);
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  391  	oc->chosen = task;
72456781289a6ed Mathieu Desnoyers 2026-01-11 @392  	oc->chosen_points = points_min;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  393  next:
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  394  	return 0;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  395  abort:
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  396  	if (oc->chosen)
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  397  		put_task_struct(oc->chosen);
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  398  	oc->chosen = (void *)-1UL;
7c5f64f84483bd1 Vladimir Davydov  2016-10-07  399  	return 1;
462607ecc519b19 David Rientjes    2012-07-31  400  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply

* [PATCH v2 6/6] kstrtox: Use copy_from_user_nul() instead of copy_from_user()
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 lib/kstrtox.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index bdde40cd69d7..e4ee72b75e09 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -402,9 +402,8 @@ int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
 	char buf[4];
 
 	count = min(count, sizeof(buf) - 1);
-	if (copy_from_user(buf, s, count))
+	if (copy_from_user_nul(buf, s, count))
 		return -EFAULT;
-	buf[count] = '\0';
 	return kstrtobool(buf, res);
 }
 EXPORT_SYMBOL(kstrtobool_from_user);
@@ -416,9 +415,8 @@ int f(const char __user *s, size_t count, unsigned int base, type *res)	\
 	char buf[1 + sizeof(type) * 8 + 1 + 1];				\
 									\
 	count = min(count, sizeof(buf) - 1);				\
-	if (copy_from_user(buf, s, count))				\
+	if (copy_from_user_nul(buf, s, count))				\
 		return -EFAULT;						\
-	buf[count] = '\0';						\
 	return g(buf, base, res);					\
 }									\
 EXPORT_SYMBOL(f)
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 5/6] time: Use copy_from_user_nul() instead of copy_from_user()
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 kernel/time/test_udelay.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c
index 783f2297111b..08ff8fd43471 100644
--- a/kernel/time/test_udelay.c
+++ b/kernel/time/test_udelay.c
@@ -107,9 +107,8 @@ static ssize_t udelay_test_write(struct file *file, const char __user *buf,
 	if (count >= sizeof(lbuf))
 		return -EINVAL;
 
-	if (copy_from_user(lbuf, buf, count))
+	if (copy_from_user_nul(lbuf, buf, count))
 		return -EFAULT;
-	lbuf[count] = '\0';
 
 	ret = sscanf(lbuf, "%d %d", &usecs, &iters);
 	if (ret < 1)
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 4/6] userns: Use copy_from_user_nul() instead of copy_from_user()
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 kernel/user_namespace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 03cb63883d04..881a05a3502c 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -1239,9 +1239,8 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
 
 	/* What was written? */
 	ret = -EFAULT;
-	if (copy_from_user(kbuf, buf, count))
+	if (copy_from_user_nul(kbuf, buf, count))
 		goto out;
-	kbuf[count] = '\0';
 	pos = kbuf;
 
 	/* What is being requested? */
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 3/6] tracing: Use copy_from_user_nul() instead of copy_from_user()
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 kernel/trace/trace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index baec63134ab6..b6ffd006fcf9 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -11266,10 +11266,9 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
 		if (size >= WRITE_BUFSIZE)
 			size = WRITE_BUFSIZE - 1;
 
-		if (copy_from_user(kbuf, buffer + done, size))
+		if (copy_from_user_nul(kbuf, buffer + done, size))
 			return -EFAULT;
 
-		kbuf[size] = '\0';
 		buf = kbuf;
 		do {
 			tmp = strchr(buf, '\n');
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 2/6] x86/tlb: Use copy_from_user_nul() instead of copy_from_user()
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Use copy_from_user_nul() instead of copy_from_user() to simplify
the code.

No functional change.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 arch/x86/mm/tlb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index f5b93e01e347..ae81e5cb510e 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1807,10 +1807,9 @@ static ssize_t tlbflush_write_file(struct file *file,
 	int ceiling;
 
 	len = min(count, sizeof(buf) - 1);
-	if (copy_from_user(buf, user_buf, len))
+	if (copy_from_user_nul(buf, user_buf, len))
 		return -EFAULT;
 
-	buf[len] = '\0';
 	if (kstrtoint(buf, 0, &ceiling))
 		return -EINVAL;
 
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 1/6] uaccess: Add copy_from_user_nul helper
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai
In-Reply-To: <20260112073039.1185-1-fushuai.wang@linux.dev>

From: Fushuai Wang <wangfushuai@baidu.com>

Many places call copy_from_user() to copy a buffer from user space,
and then manually add a NULL terminator to the destination buffer,
e.g.:

	if (copy_from_user(dest, src, len))
		return -EFAULT;
	dest[len] = '\0';

This is repetitive and error-prone. Add a copy_from_user_nul() helper to
simplify such patterns. It copied n bytes from user space to kernel space,
and NUL-terminates the destination buffer.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 include/linux/uaccess.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 1f3804245c06..fe9a1db600c7 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -224,6 +224,25 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
 #endif
 }
 
+/*
+ * copy_from_user_nul - Copy a block of data from user space and NUL-terminate
+ *
+ * @to:   Destination address, in kernel space. This buffer must be at least
+ *        @n+1 bytes long!
+ * @from: Source address, in user space.
+ * @n:    Number of bytes to copy.
+ *
+ * Return: 0 on success, -EFAULT on failure.
+ */
+static __always_inline int __must_check
+copy_from_user_nul(void *to, const void __user *from, unsigned long n)
+{
+	if (copy_from_user(to, from, n))
+		return -EFAULT;
+	((char *)to)[n] = '\0';
+	return 0;
+}
+
 static __always_inline unsigned long __must_check
 copy_to_user(void __user *to, const void *from, unsigned long n)
 {
-- 
2.36.1


^ permalink raw reply related

* [PATCH v2 0/6] uaccess: Introduce copy_from_user_nul helper
From: Fushuai Wang @ 2026-01-12  7:30 UTC (permalink / raw)
  To: tglx, peterz, mathieu.desnoyers, akpm, aliceryhl, yury.norov,
	vmalik, kees, dave.hansen, luto, mingo, bp, hpa, rostedt,
	mhiramat, brauner, jack, cyphar
  Cc: linux-kernel, x86, linux-trace-kernel, wangfushuai

From: Fushuai Wang <wangfushuai@baidu.com>

Hi all,

This patch series introduces a new helper function, copy_from_user_nul,
to simplify cases where a buffer copied from userspace needs to be
NUL-terminated. In many places, after using copy_from_user, we manually
add a NUL byte to the end of the buffer to prevent string overflows and
ensure safe string handling.

The new helper performs both the copy and the NUL-termination in one
step, reducing repetitive code and the chance of errors.

v1 -> v2: Rewrite commit message and add some actual code improvements

--WANG

Fushuai Wang (6):
  uaccess: Add copy_from_user_nul helper
  x86/tlb: Use copy_from_user_nul() instead of copy_from_user()
  tracing: Use copy_from_user_nul() instead of copy_from_user()
  userns: Use copy_from_user_nul() instead of copy_from_user()
  time: Use copy_from_user_nul() instead of copy_from_user()
  kstrtox: Use copy_from_user_nul() instead of copy_from_user()

 arch/x86/mm/tlb.c         |  3 +--
 include/linux/uaccess.h   | 19 +++++++++++++++++++
 kernel/time/test_udelay.c |  3 +--
 kernel/trace/trace.c      |  3 +--
 kernel/user_namespace.c   |  3 +--
 lib/kstrtox.c             |  6 ++----
 6 files changed, 25 insertions(+), 12 deletions(-)

-- 
2.36.1


^ permalink raw reply

* Re: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
From: Shawn Lin @ 2026-01-12  7:19 UTC (permalink / raw)
  To: kernel test robot, Manivannan Sadhasivam, Bjorn Helgaas
  Cc: shawn.lin, oe-kbuild-all, linux-rockchip, linux-pci,
	linux-trace-kernel, linux-doc, Steven Rostedt, Masami Hiramatsu
In-Reply-To: <202601121428.WVvakywZ-lkp@intel.com>


在 2026/01/12 星期一 14:42, kernel test robot 写道:
> Hi Shawn,
> 
> kernel test robot noticed the following build errors:
> 
> [auto build test ERROR on pci/next]
> [also build test ERROR on next-20260109]
> [cannot apply to pci/for-linus trace/for-next mani-mhi/mhi-next linus/master v6.19-rc5]
> [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/Shawn-Lin/PCI-trace-Add-PCI-controller-LTSSM-transition-tracepoint/20260112-100141
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
> patch link:    https://lore.kernel.org/r/1768180800-63364-4-git-send-email-shawn.lin%40rock-chips.com
> patch subject: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
> config: loongarch-randconfig-002-20260112 (https://download.01.org/0day-ci/archive/20260112/202601121428.WVvakywZ-lkp@intel.com/config)
> compiler: loongarch64-linux-gcc (GCC) 15.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601121428.WVvakywZ-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/202601121428.WVvakywZ-lkp@intel.com/
> 
> All errors (new ones prefixed by >>):
> 
>     drivers/pci/controller/dwc/pcie-dw-rockchip.c: In function 'rockchip_pcie_ltssm_trace_work':
>>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:41: error: implicit declaration of function 'dw_pcie_ltssm_status_string' [-Wimplicit-function-declaration]
>       264 |                                         dw_pcie_ltssm_status_string(state),

Hi lkp,

It depends on another patch mentioned in the cover letter. So the
complie error is expected right now.


>           |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:41: error: passing argument 2 of 'trace_pcie_ltssm_state_transition' makes pointer from integer without a cast [-Wint-conversion]
>       264 |                                         dw_pcie_ltssm_status_string(state),
>           |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>           |                                         |
>           |                                         int
>     In file included from include/trace/events/pci_controller.h:9,
>                      from drivers/pci/controller/dwc/pcie-dw-rockchip.c:26:
>     include/trace/events/pci_controller.h:20:52: note: expected 'const char *' but argument is of type 'int'
>        20 |         TP_PROTO(const char *dev_name, const char *state, u32 rate),
>           |                                        ~~~~~~~~~~~~^~~~~
>     include/linux/tracepoint.h:288:41: note: in definition of macro '__DECLARE_TRACE'
>       288 |         static inline void trace_##name(proto)                          \
>           |                                         ^~~~~
>     include/linux/tracepoint.h:494:31: note: in expansion of macro 'PARAMS'
>       494 |         __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),              \
>           |                               ^~~~~~
>     include/linux/tracepoint.h:632:9: note: in expansion of macro 'DECLARE_TRACE_EVENT'
>       632 |         DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
>           |         ^~~~~~~~~~~~~~~~~~~
>     include/linux/tracepoint.h:632:35: note: in expansion of macro 'PARAMS'
>       632 |         DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
>           |                                   ^~~~~~
>     include/trace/events/pci_controller.h:19:1: note: in expansion of macro 'TRACE_EVENT'
>        19 | TRACE_EVENT(pcie_ltssm_state_transition,
>           | ^~~~~~~~~~~
>     include/trace/events/pci_controller.h:20:9: note: in expansion of macro 'TP_PROTO'
>        20 |         TP_PROTO(const char *dev_name, const char *state, u32 rate),
>           |         ^~~~~~~~
> 
> 
> vim +/dw_pcie_ltssm_status_string +264 drivers/pci/controller/dwc/pcie-dw-rockchip.c
> 
>     225	
>     226	#ifdef CONFIG_TRACING
>     227	static void rockchip_pcie_ltssm_trace_work(struct work_struct *work)
>     228	{
>     229		struct rockchip_pcie *rockchip = container_of(work, struct rockchip_pcie,
>     230							trace_work.work);
>     231		struct dw_pcie *pci = &rockchip->pci;
>     232		enum dw_pcie_ltssm state;
>     233		u32 i, l1ss, prev_val = DW_PCIE_LTSSM_UNKNOWN, rate, val;
>     234	
>     235		for (i = 0; i < PCIE_DBG_LTSSM_HISTORY_CNT; i++) {
>     236			val = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_DBG_FIFO_STATUS);
>     237			rate = FIELD_GET(PCIE_DBG_FIFO_RATE_MASK, val);
>     238			l1ss = FIELD_GET(PCIE_DBG_FIFO_L1SUB_MASK, val);
>     239			val = FIELD_GET(PCIE_LTSSM_STATUS_MASK, val);
>     240	
>     241			/*
>     242			 * Hardware Mechanism: The ring FIFO employs two tracking counters:
>     243			 * - 'last-read-point': maintains the user's last read position
>     244			 * - 'last-valid-point': tracks the hardware's last state update
>     245			 *
>     246			 * Software Handling: When two consecutive LTSSM states are identical,
>     247			 * it indicates invalid subsequent data in the FIFO. In this case, we
>     248			 * skip the remaining entries. The dual-counter design ensures that on
>     249			 * the next state transition, reading can resume from the last user
>     250			 * position.
>     251			 */
>     252			if ((i > 0 && val == prev_val) || val > DW_PCIE_LTSSM_RCVRY_EQ3)
>     253				break;
>     254	
>     255			state = prev_val = val;
>     256			if (val == DW_PCIE_LTSSM_L1_IDLE) {
>     257				if (l1ss == 2)
>     258					state = DW_PCIE_LTSSM_L1_2;
>     259				else if (l1ss == 1)
>     260					state = DW_PCIE_LTSSM_L1_1;
>     261			}
>     262	
>     263			trace_pcie_ltssm_state_transition(dev_name(pci->dev),
>   > 264						dw_pcie_ltssm_status_string(state),
>     265						((rate + 1) > pci->max_link_speed) ?
>     266						PCI_SPEED_UNKNOWN : PCIE_SPEED_2_5GT + rate);
>     267		}
>     268	
>     269		schedule_delayed_work(&rockchip->trace_work, msecs_to_jiffies(5000));
>     270	}
>     271	
> 


^ permalink raw reply

* Re: [PATCH v5] tracing: Guard __DECLARE_TRACE() use of __DO_TRACE_CALL() with SRCU-fast
From: Menglong Dong @ 2026-01-12  7:23 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Mathieu Desnoyers, Alexei Starovoitov, LKML, Linux trace kernel,
	bpf, Masami Hiramatsu, Paul E. McKenney,
	Sebastian Andrzej Siewior, Thomas Gleixner, Peter Zijlstra,
	Linus Torvalds
In-Reply-To: <20260109160202.22975aa4@gandalf.local.home>

On 2026/1/10 05:02 Steven Rostedt <rostedt@goodmis.org> write:
> On Fri, 9 Jan 2026 15:21:19 -0500
> Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
> 
> > * preempt disable/enable pair:                                     1.1 ns
> > * srcu-fast lock/unlock:                                           1.5 ns
> > 
> > CONFIG_RCU_REF_SCALE_TEST=y
> > * migrate disable/enable pair:                                     3.0 ns
> > * calls to migrate disable/enable pair within noinline functions: 17.0 ns
> > 
> > CONFIG_RCU_REF_SCALE_TEST=m
> > * migrate disable/enable pair:                                    22.0 ns
> 
> OUCH! So migrate disable/enable has a much larger overhead when executed in
> a module than in the kernel? This means all spin_locks() in modules
> converted to mutexes in PREEMPT_RT are taking this hit!
> 
> It looks like it has to allow access to the rq->nr_pinned. There's a hack to
> expose this part of the rq struct for in-kernel by the following:
> 
> kernel/sched/rq-offsets.c:      DEFINE(RQ_nr_pinned, offsetof(struct rq, nr_pinned));
> 
> Then for the in-kernel code we have:
> 
> #define this_rq_raw() arch_raw_cpu_ptr(&runqueues)
> #else
> #define this_rq_raw() PERCPU_PTR(&runqueues)
> #endif
> #define this_rq_pinned() (*(unsigned int *)((void *)this_rq_raw() + RQ_nr_pinned))
> 
> Looking at the scheduler code, the rq->nr_pinned is referenced by a static
> function with:
> 
> static inline bool rq_has_pinned_tasks(struct rq *rq)
> {
> 	return rq->nr_pinned;
> }
> 
> Which is only referenced in hotplug code and a balance_push() path in load
> balancing. Does this variable really need to be in the runqueue struct?
> 
> Why not just make it a per-cpu variable. Maybe call it cpu_nr_pinned_tasks,
> and export that for all to use?
> 
> It will not only fix the discrepancy between the overhead of
> migrate_disable/enable in modules vs in-kernel. But it also removes the
> hack to expose a portion of the runqueue.

I think it's a good idea to factor out the "nr_pinned" from struct rq.
The current approach that we inline the migrate_disable is a little
obscure. The initial propose of inline migrate_disable is to optimize the
performance of bpf trampoline, so the modules are not considered.

As you said, rq_has_pinned_tasks() is the only place that use the
nr_pinned, except the migrate_disable/migrate_enable. After more
analysis, I think maybe we can do it this way:

DEFINE_PER_CPU_SHARED_ALIGNED(int, cpu_nr_pinned_tasks);

And change rq_has_pinned_tasks() to:
static inline bool rq_has_pinned_tasks(struct rq *rq)
{
	return *per_cpu_ptr(&cpu_nr_pinned_tasks, rq->cpu);
}

The "rq" in rq_has_pinned_tasks() may come from other CPU, so we
can't use "return this_cpu_read(cpu_nr_pinned_tasks)" directly.

Thanks!
Menglong Dong

> 
> -- Steve
> 
> 





^ permalink raw reply

* Re: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
From: kernel test robot @ 2026-01-12  6:42 UTC (permalink / raw)
  To: Shawn Lin, Manivannan Sadhasivam, Bjorn Helgaas
  Cc: oe-kbuild-all, linux-rockchip, linux-pci, linux-trace-kernel,
	linux-doc, Steven Rostedt, Masami Hiramatsu, Shawn Lin
In-Reply-To: <1768180800-63364-4-git-send-email-shawn.lin@rock-chips.com>

Hi Shawn,

kernel test robot noticed the following build errors:

[auto build test ERROR on pci/next]
[also build test ERROR on next-20260109]
[cannot apply to pci/for-linus trace/for-next mani-mhi/mhi-next linus/master v6.19-rc5]
[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/Shawn-Lin/PCI-trace-Add-PCI-controller-LTSSM-transition-tracepoint/20260112-100141
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:    https://lore.kernel.org/r/1768180800-63364-4-git-send-email-shawn.lin%40rock-chips.com
patch subject: [PATCH v3 3/3] PCI: dw-rockchip: Add pcie_ltssm_state_transition trace support
config: loongarch-randconfig-002-20260112 (https://download.01.org/0day-ci/archive/20260112/202601121428.WVvakywZ-lkp@intel.com/config)
compiler: loongarch64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260112/202601121428.WVvakywZ-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/202601121428.WVvakywZ-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/pci/controller/dwc/pcie-dw-rockchip.c: In function 'rockchip_pcie_ltssm_trace_work':
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:41: error: implicit declaration of function 'dw_pcie_ltssm_status_string' [-Wimplicit-function-declaration]
     264 |                                         dw_pcie_ltssm_status_string(state),
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/pci/controller/dwc/pcie-dw-rockchip.c:264:41: error: passing argument 2 of 'trace_pcie_ltssm_state_transition' makes pointer from integer without a cast [-Wint-conversion]
     264 |                                         dw_pcie_ltssm_status_string(state),
         |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                         |
         |                                         int
   In file included from include/trace/events/pci_controller.h:9,
                    from drivers/pci/controller/dwc/pcie-dw-rockchip.c:26:
   include/trace/events/pci_controller.h:20:52: note: expected 'const char *' but argument is of type 'int'
      20 |         TP_PROTO(const char *dev_name, const char *state, u32 rate),
         |                                        ~~~~~~~~~~~~^~~~~
   include/linux/tracepoint.h:288:41: note: in definition of macro '__DECLARE_TRACE'
     288 |         static inline void trace_##name(proto)                          \
         |                                         ^~~~~
   include/linux/tracepoint.h:494:31: note: in expansion of macro 'PARAMS'
     494 |         __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args),              \
         |                               ^~~~~~
   include/linux/tracepoint.h:632:9: note: in expansion of macro 'DECLARE_TRACE_EVENT'
     632 |         DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/tracepoint.h:632:35: note: in expansion of macro 'PARAMS'
     632 |         DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
         |                                   ^~~~~~
   include/trace/events/pci_controller.h:19:1: note: in expansion of macro 'TRACE_EVENT'
      19 | TRACE_EVENT(pcie_ltssm_state_transition,
         | ^~~~~~~~~~~
   include/trace/events/pci_controller.h:20:9: note: in expansion of macro 'TP_PROTO'
      20 |         TP_PROTO(const char *dev_name, const char *state, u32 rate),
         |         ^~~~~~~~


vim +/dw_pcie_ltssm_status_string +264 drivers/pci/controller/dwc/pcie-dw-rockchip.c

   225	
   226	#ifdef CONFIG_TRACING
   227	static void rockchip_pcie_ltssm_trace_work(struct work_struct *work)
   228	{
   229		struct rockchip_pcie *rockchip = container_of(work, struct rockchip_pcie,
   230							trace_work.work);
   231		struct dw_pcie *pci = &rockchip->pci;
   232		enum dw_pcie_ltssm state;
   233		u32 i, l1ss, prev_val = DW_PCIE_LTSSM_UNKNOWN, rate, val;
   234	
   235		for (i = 0; i < PCIE_DBG_LTSSM_HISTORY_CNT; i++) {
   236			val = rockchip_pcie_readl_apb(rockchip, PCIE_CLIENT_DBG_FIFO_STATUS);
   237			rate = FIELD_GET(PCIE_DBG_FIFO_RATE_MASK, val);
   238			l1ss = FIELD_GET(PCIE_DBG_FIFO_L1SUB_MASK, val);
   239			val = FIELD_GET(PCIE_LTSSM_STATUS_MASK, val);
   240	
   241			/*
   242			 * Hardware Mechanism: The ring FIFO employs two tracking counters:
   243			 * - 'last-read-point': maintains the user's last read position
   244			 * - 'last-valid-point': tracks the hardware's last state update
   245			 *
   246			 * Software Handling: When two consecutive LTSSM states are identical,
   247			 * it indicates invalid subsequent data in the FIFO. In this case, we
   248			 * skip the remaining entries. The dual-counter design ensures that on
   249			 * the next state transition, reading can resume from the last user
   250			 * position.
   251			 */
   252			if ((i > 0 && val == prev_val) || val > DW_PCIE_LTSSM_RCVRY_EQ3)
   253				break;
   254	
   255			state = prev_val = val;
   256			if (val == DW_PCIE_LTSSM_L1_IDLE) {
   257				if (l1ss == 2)
   258					state = DW_PCIE_LTSSM_L1_2;
   259				else if (l1ss == 1)
   260					state = DW_PCIE_LTSSM_L1_1;
   261			}
   262	
   263			trace_pcie_ltssm_state_transition(dev_name(pci->dev),
 > 264						dw_pcie_ltssm_status_string(state),
   265						((rate + 1) > pci->max_link_speed) ?
   266						PCI_SPEED_UNKNOWN : PCIE_SPEED_2_5GT + rate);
   267		}
   268	
   269		schedule_delayed_work(&rockchip->trace_work, msecs_to_jiffies(5000));
   270	}
   271	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply


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