Skip to contentSkip to conversation

tracing: More updates for 6.13

GIT PULL Merged Steven Rostedt 6 participants 11 messages Nov 27, 2024 – Nov 29, 2024

Subsystems (5)
Documentation Tracing Rust RCU +1 more subsystems
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

[ Resend to include LKML ]

Linus,

Tracing updates for 6.13:

- Add trace flag for NEED_RESCHED_LAZY

Now that NEED_RESCHED_LAZY is upstream, add it to the status bits of the common_flags. This will now show when the NEED_RESCHED_LAZY flag is set that is used for debugging latency issues in the kernel via a trace.

- Remove leftover "__idx" variable when SRCU was removed from the tracepoint code

- Add rcu_tasks_trace guard

To add a guard() around the tracepoint code, a rcu_tasks_trace guard needs to be created first.

- Remove __DO_TRACE() macro and just call __DO_TRACE_CALL() directly

The DO_TRACE() macro has conditional locking depending on what was passed into the macro parameters. As the guts of the macro has been moved to __DO_TRACE_CALL() to handle static call logic, there's no reason to keep the __DO_TRACE() macro around. It is better to just do the locking in place without the conditionals and call __DO_TRACE_CALL() from those locations. The "cond" passed in can also be moved out of that macro. This simplifies the code.

- Remove the "cond" from the system call tracepoint macros

The "cond" variable was added to allow some tracepoints to check a condition within the static_branch (jump/nop) logic. The system calls do not need this. Removing it simplifies the code.

- Replace scoped_guard() with just guard() in the tracepoint logic

guard() works just as well as scoped_guard() in the tracepoint logic and the scoped_guard() causes some issues.

[
NOTE: The rust tracepoint code added hooks to the same macros that were modified in this pull request. The merge has non-trivial conflicts. I fixed it up in my "for-next" branch in the same repository. That branch was a merge of this branch into the commit where you pulled the rust tracepoint code.

To be consistent, I kept the rust hooks in the system call macros even though there are currently no Rust system calls. But if one day there is, then this could be useful.

The rust folks may want to look at that merge too. I ran my normal tests but I don't yet have anything that tests Rust tracepoints.
]

Please pull the latest trace-v6.13-2 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace-v6.13-2

Tag SHA1: 6a46d81b2c10dc4fefcc063d9cc5478a66e9e7a2 Head SHA1: 2bd9b57d04df417f31ef54448477c212fcdd14fc

Mathieu Desnoyers (6):
tracing: Move it_func[0] comment to the relevant context
tracing: Remove __idx variable from __DO_TRACE
rcupdate_trace: Define rcu_tasks_trace lock guard
tracing: Remove conditional locking from __DO_TRACE()
tracing: Remove cond argument from __DECLARE_TRACE_SYSCALL
tracing: Use guard() rather than scoped_guard()

Thomas Gleixner (1):
tracing: Record task flag NEED_RESCHED_LAZY.

----

 Documentation/trace/ftrace.rst |  4 +++
 include/linux/rcupdate_trace.h |  5 +++
 include/linux/trace_events.h   |  1 +
 include/linux/tracepoint.h     | 70 +++++++++++++++---------------------------
 kernel/trace/trace.c           |  2 ++
 kernel/trace/trace_output.c    | 14 ++++++++-
 6 files changed, 49 insertions(+), 47 deletions(-)

---------------------------

Documentation/trace/ftrace.rst +4 -0
index 74d5bd801b1a..272464bb7c60 100644
@@ -1033,9 +1033,13 @@ explains which is which.
   irqs-off: 'd' interrupts are disabled. '.' otherwise.
 
   need-resched:
+	- 'B' all, TIF_NEED_RESCHED, PREEMPT_NEED_RESCHED and TIF_RESCHED_LAZY is set,
 	- 'N' both TIF_NEED_RESCHED and PREEMPT_NEED_RESCHED is set,
 	- 'n' only TIF_NEED_RESCHED is set,
 	- 'p' only PREEMPT_NEED_RESCHED is set,
+	- 'L' both PREEMPT_NEED_RESCHED and TIF_RESCHED_LAZY is set,
+	- 'b' both TIF_NEED_RESCHED and TIF_RESCHED_LAZY is set,
+	- 'l' only TIF_RESCHED_LAZY is set
 	- '.' otherwise.
 
   hardirq/softirq:
include/linux/rcupdate_trace.h +5 -0
index eda493200663..e6c44eb428ab 100644
@@ -10,6 +10,7 @@
 
 #include <linux/sched.h>
 #include <linux/rcupdate.h>
+#include <linux/cleanup.h>
 
 extern struct lockdep_map rcu_trace_lock_map;
 
@@ -98,4 +99,8 @@ static inline void rcu_read_lock_trace(void) { BUG(); }
 static inline void rcu_read_unlock_trace(void) { BUG(); }
 #endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
 
+DEFINE_LOCK_GUARD_0(rcu_tasks_trace,
+	rcu_read_lock_trace(),
+	rcu_read_unlock_trace())
+
 #endif /* __LINUX_RCUPDATE_TRACE_H */
include/linux/trace_events.h +1 -0
index 016b29a56c87..2a5df5b62cfc 100644
@@ -184,6 +184,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status);
 
 enum trace_flag_type {
 	TRACE_FLAG_IRQS_OFF		= 0x01,
+	TRACE_FLAG_NEED_RESCHED_LAZY	= 0x02,
 	TRACE_FLAG_NEED_RESCHED		= 0x04,
 	TRACE_FLAG_HARDIRQ		= 0x08,
 	TRACE_FLAG_SOFTIRQ		= 0x10,
include/linux/tracepoint.h +24 -46

123 lines not on this page · raw message

kernel/trace/trace.c +2 -0
index 3ef047ed9705..be62f0ea1814 100644
@@ -2552,6 +2552,8 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
 		trace_flags |= TRACE_FLAG_NEED_RESCHED;
 	if (test_preempt_need_resched())
 		trace_flags |= TRACE_FLAG_PREEMPT_RESCHED;
+	if (IS_ENABLED(CONFIG_ARCH_HAS_PREEMPT_LAZY) && tif_test_bit(TIF_NEED_RESCHED_LAZY))
+		trace_flags |= TRACE_FLAG_NEED_RESCHED_LAZY;
 	return (trace_flags << 16) | (min_t(unsigned int, pc & 0xff, 0xf)) |
 		(min_t(unsigned int, migration_disable_value(), 0xf)) << 4;
 }
kernel/trace/trace_output.c +13 -1
index e08aee34ef63..da748b7cbc4d 100644
@@ -462,17 +462,29 @@ int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
 		bh_off ? 'b' :
 		'.';
 
-	switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
+	switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY |
 				TRACE_FLAG_PREEMPT_RESCHED)) {
+	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
+		need_resched = 'B';
+		break;
 	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
 		need_resched = 'N';
 		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY | TRACE_FLAG_PREEMPT_RESCHED:
+		need_resched = 'L';
+		break;
+	case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'b';
+		break;
 	case TRACE_FLAG_NEED_RESCHED:
 		need_resched = 'n';
 		break;
 	case TRACE_FLAG_PREEMPT_RESCHED:
 		need_resched = 'p';
 		break;
+	case TRACE_FLAG_NEED_RESCHED_LAZY:
+		need_resched = 'l';
+		break;
 	default:
 		need_resched = '.';
 		break;
merge bot Merged
#1 lore raw
The pull request you sent on Wed, 27 Nov 2024 13:19:41 -0500:

The pull request you sent on Wed, 27 Nov 2024 13:19:41 -0500:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git trace-v6.13-2

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/7af08b57bcb9ebf78675c50069c54125c0a8b795

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html
#2 lore raw
In reply to Steven Rostedt
Quoted 7 lines · Steven Rostedt

[
NOTE: The rust tracepoint code added hooks to the same macros that were modified in this pull request. The merge has non-trivial conflicts. I fixed it up in my "for-next" branch in the same repository. That branch was a merge of this branch into the commit where you pulled the rust tracepoint code.

I checked my resolution against yours, and I don't think your resolution is right.

You didn't check 'cond' on regular rust tracepoints, and you didn't do any locking on either kind.

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

That said, I also think that the "__rust_do_trace_##name" inline helper should just be renamed to "__trace_##name", and then the regular trace_##name() helper could use that inside the static_branch_unlikely() check. Because that seems to be the only real thing the "rust" version wants - avoiding the static branch infrastructure in favor of whatever rust infrastructure.

But hey, I do basic sanity build testing of the rust code, I don't actually _know_ it. Again, I might be missing something.

Linus

author maintainer
#3 lore raw
Quoted 5 lines · On Thu, 28 Nov 2024 11:55:34 -0800 Linus Torvalds…

I checked my resolution against yours, and I don't think your resolution is right.

You didn't check 'cond' on regular rust tracepoints, and you didn't do any locking on either kind.

Bah, you're right. The cond is only needed if they utilize it, which I'm not sure they do, but the locking is definitely needed. My brain was off when doing the merge conflict. I was thinking more of "what makes this compile" than how it actually works.

Quoted 3 lines

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

Looks better than what I had. I'll kick my tests on it just as a sanity check.

Quoted 7 lines

That said, I also think that the "__rust_do_trace_##name" inline helper should just be renamed to "__trace_##name", and then the regular trace_##name() helper could use that inside the static_branch_unlikely() check. Because that seems to be the only real thing the "rust" version wants - avoiding the static branch infrastructure in favor of whatever rust infrastructure.

Hmm, I think that could be done.

Quoted 3 lines

But hey, I do basic sanity build testing of the rust code, I don't actually _know_ it. Again, I might be missing something.

I need to spend some time understanding the rust code, so I can at least review it better.

-- Steve

author maintainer
#4 lore raw
Quoted 6 lines · On Thu, 28 Nov 2024 15:51:20 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

Looks better than what I had. I'll kick my tests on it just as a sanity check.

And my tests failed. But not for this change. The build failed. Config attached:

CC kernel/time/tick-broadcast.o
In file included from /work/build/trace/nobackup/linux-test.git/include/linux/string.h:390,
from /work/build/trace/nobackup/linux-test.git/include/linux/bitmap.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/cpumask.h:12,
from /work/build/trace/nobackup/linux-test.git/include/linux/smp.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/lockdep.h:14,
from /work/build/trace/nobackup/linux-test.git/include/linux/spinlock.h:63,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait.h:9,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait_bit.h:8,
from /work/build/trace/nobackup/linux-test.git/include/linux/fs.h:6,
from /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:37:
In function ‘sized_strscpy’,
inlined from ‘__audit_ptrace’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2732:2:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)

  293 |                 __write_overflow();
      |                 ^~~~~~~~~~~~~~~~~~

CC arch/x86/kernel/tracepoint.o
In function ‘sized_strscpy’,
inlined from ‘audit_signal_info_syscall’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2759:3:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)

  293 |                 __write_overflow();
      |                 ^~~~~~~~~~~~~~~~~~

AR drivers/nvmem/built-in.a
make[4]: *** [/work/build/trace/nobackup/linux-test.git/scripts/Makefile.build:229: kernel/auditsc.o] Error 1

I'm currently too busy eating turkey, so I'll let someone else figure this out.

-- Steve

#5 lore raw
Quoted 33 lines · Steven Rostedt
Quoted 6 lines · On Thu, 28 Nov 2024 15:51:20 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

Looks better than what I had. I'll kick my tests on it just as a sanity check.

And my tests failed. But not for this change. The build failed. Config attached:

CC kernel/time/tick-broadcast.o
In file included from /work/build/trace/nobackup/linux-test.git/include/linux/string.h:390,
from /work/build/trace/nobackup/linux-test.git/include/linux/bitmap.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/cpumask.h:12,
from /work/build/trace/nobackup/linux-test.git/include/linux/smp.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/lockdep.h:14,
from /work/build/trace/nobackup/linux-test.git/include/linux/spinlock.h:63,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait.h:9,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait_bit.h:8,
from /work/build/trace/nobackup/linux-test.git/include/linux/fs.h:6,
from /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:37:
In function ‘sized_strscpy’,
inlined from ‘__audit_ptrace’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2732:2:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)

  293 |                 __write_overflow();
      |                 ^~~~~~~~~~~~~~~~~~

CC arch/x86/kernel/tracepoint.o
In function ‘sized_strscpy’,
inlined from ‘audit_signal_info_syscall’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2759:3:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)

Quoted 6 lines
  293 |                 __write_overflow();
      |                 ^~~~~~~~~~~~~~~~~~

AR drivers/nvmem/built-in.a
make[4]: *** [/work/build/trace/nobackup/linux-test.git/scripts/Makefile.build:229: kernel/auditsc.o] Error 1

I'm currently too busy eating turkey, so I'll let someone else figure this out.

The issue appears to be a known GCC bug, though the root cause remains unclear at this time.

A potential workaround has been proposed, which you can find here:
https://lore.kernel.org/linux-hardening/202410171059.C2C395030@keescook/

However, it seems that the patch has not yet been accepted into the mainline.

--
Regards
Yafang

author maintainer
#6 lore raw
Quoted 7 lines · On Fri, 29 Nov 2024 10:16:54 +0800 Yafang Shao <[email protected]> wrote:

The issue appears to be a known GCC bug, though the root cause remains unclear at this time.

A potential workaround has been proposed, which you can find here:
https://lore.kernel.org/linux-hardening/202410171059.C2C395030@keescook/

However, it seems that the patch has not yet been accepted into the mainline.

Thanks, I applied that to my "fixes" patch that is used to fix other issues that are not related to my code so that I can continue testing.

I just kicked off my tests again with that applied.

-- Steve

#7 lore raw
In reply to Yafang Shao
Quoted 41 lines · Yafang Shao
Quoted 38 lines · Steven Rostedt
Quoted 6 lines · On Thu, 28 Nov 2024 15:51:20 -0500 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

Looks better than what I had. I'll kick my tests on it just as a sanity check.

And my tests failed. But not for this change. The build failed. Config attached:

CC kernel/time/tick-broadcast.o
In file included from /work/build/trace/nobackup/linux-test.git/include/linux/string.h:390,
from /work/build/trace/nobackup/linux-test.git/include/linux/bitmap.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/cpumask.h:12,
from /work/build/trace/nobackup/linux-test.git/include/linux/smp.h:13,
from /work/build/trace/nobackup/linux-test.git/include/linux/lockdep.h:14,
from /work/build/trace/nobackup/linux-test.git/include/linux/spinlock.h:63,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait.h:9,
from /work/build/trace/nobackup/linux-test.git/include/linux/wait_bit.h:8,
from /work/build/trace/nobackup/linux-test.git/include/linux/fs.h:6,
from /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:37:
In function ‘sized_strscpy’,
inlined from ‘__audit_ptrace’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2732:2:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)
293 | __write_overflow();
| ^~~~~~~~~~~~~~~~~~
CC arch/x86/kernel/tracepoint.o
In function ‘sized_strscpy’,
inlined from ‘audit_signal_info_syscall’ at /work/build/trace/nobackup/linux-test.git/kernel/auditsc.c:2759:3:
/work/build/trace/nobackup/linux-test.git/include/linux/fortify-string.h:293:17: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object (1st parameter)
293 | __write_overflow();
| ^~~~~~~~~~~~~~~~~~
AR drivers/nvmem/built-in.a
make[4]: *** [/work/build/trace/nobackup/linux-test.git/scripts/Makefile.build:229: kernel/auditsc.o] Error 1

Quoted 1 line

I'm currently too busy eating turkey, so I'll let someone else figure this out.

Quoted 7 lines

The issue appears to be a known GCC bug, though the root cause remains unclear at this time.

A potential workaround has been proposed, which you can find here:
https://lore.kernel.org/linux-hardening/202410171059.C2C395030@keescook/

However, it seems that the patch has not yet been accepted into the mainline.

I didn't pull that into the audit tree because it isn't a real patch. Looking at it again on my phone before today's holiday stuff kicks off, I don't have a problem with the workaround, but i do need to see it as a proper patch with a commit description, sign off, etc. before I can merge it.

For anyone who is going to put together a patch, please make it clear that it is a compiler bug and provide the associated bug report links.

--
paul-moore.com

author maintainer Tested-by
#8 lore raw
Quoted 6 lines · On Fri, 29 Nov 2024 08:14:56 -0500 Paul Moore <[email protected]> wrote:
Quoted 6 lines

The issue appears to be a known GCC bug, though the root cause remains unclear at this time.

A potential workaround has been proposed, which you can find here:
https://lore.kernel.org/linux-hardening/202410171059.C2C395030@keescook/

Quoted 6 lines
Quoted 1 line

However, it seems that the patch has not yet been accepted into the mainline.

I didn't pull that into the audit tree because it isn't a real patch. Looking at it again on my phone before today's holiday stuff kicks off, I don't have a problem with the workaround, but i do need to see it as a proper patch with a commit description, sign off, etc. before I can merge it.

Yeah, from the comment I was expecting to see a proper patch.

Quoted 3 lines

For anyone who is going to put together a patch, please make it clear that it is a compiler bug and provide the associated bug report links.

If it matters, with that patch applied, all my tests were able to complete with success.

-- Steve

#9 lore raw
Quoted 9 lines · Steven Rostedt
Quoted 6 lines · On Fri, 29 Nov 2024 08:14:56 -0500 Paul Moore <[email protected]> wrote:
Quoted 6 lines

The issue appears to be a known GCC bug, though the root cause remains unclear at this time.

A potential workaround has been proposed, which you can find here:
https://lore.kernel.org/linux-hardening/202410171059.C2C395030@keescook/

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

However, it seems that the patch has not yet been accepted into the mainline.

I didn't pull that into the audit tree because it isn't a real patch. Looking at it again on my phone before today's holiday stuff kicks off, I don't have a problem with the workaround, but i do need to see it as a proper patch with a commit description, sign off, etc. before I can merge it.

Yeah, from the comment I was expecting to see a proper patch.

So was I :). To be perfectly honest I was really expecting this to get sorted with some compiler flag, workaround, etc. If we have to fix it by hacking around it in the audit code that's okay (the hack looks pretty minor) but it's not still a kludge.

Quoted 8 lines
Quoted 3 lines

For anyone who is going to put together a patch, please make it clear that it is a compiler bug and provide the associated bug report links.

If it matters, with that patch applied, all my tests were able to complete with success.

Thanks.

--
paul-moore.com

reviewer
#10 lore raw
In reply to Linus Torvalds
Quoted 19 lines · Linus Torvalds
Quoted 7 lines · Steven Rostedt

[
NOTE: The rust tracepoint code added hooks to the same macros that were modified in this pull request. The merge has non-trivial conflicts. I fixed it up in my "for-next" branch in the same repository. That branch was a merge of this branch into the commit where you pulled the rust tracepoint code.

I checked my resolution against yours, and I don't think your resolution is right.

You didn't check 'cond' on regular rust tracepoints, and you didn't do any locking on either kind.

I've pushed out my resolution, and hopefully rust people can actually test it. I might just be full of it.

Quoted 6 lines

That said, I also think that the "__rust_do_trace_##name" inline helper should just be renamed to "__trace_##name", and then the regular trace_##name() helper could use that inside the static_branch_unlikely() check. Because that seems to be the only real thing the "rust" version wants - avoiding the static branch infrastructure in favor of whatever rust infrastructure.

The Rust parts look reasonable to me, thanks!

Alice