Hi Masami, On Thu, Dec 3, 2026 at 6:28 PM Masami Hiramatsu (Google) <[email protected]> wrote: [...] > > > > Does this make sense? > > Yes, I understand the livepatch issue you are describing: when a function > is marked `inline` without `__always_inline` and the compiler generates > an instance, the implicit `notrace` on `inline` prevents ftrace (and > thus ftrace-based livepatching) from patching that copy, so you have to > convert it to `__always_inline` or drop `inline` for such cases. > > My concern is that modifying inline macros globally could lead to the > exclusion of inline function calls, including those within the internal > execution paths of ftrace and call-graph tracing, from tracing (via > `notrace`), thus there is a risk of the loss of protection against > recursive calls. > > ----- > For example, `tracing_gen_ctx()` / `tracing_gen_ctx_flags()` (called in > `function_test_events_call()` before `preempt_disable_notrace()` and the > recursion counter check) call `arch_local_save_flags()` and > `arch_irqs_disabled_flags()`, `trace_test_and_set_recursion()` reads > `current` via `current_thread_info()` before setting > `current->trace_recursion`, and `is_kernel_text()` (called by > `core_kernel_text()` in MIPS `prepare_ftrace_return()` before > `function_graph_enter()`) calls `in_gate_area_no_mm()`. Across > architectures without an objtool-like static check for `notrace`, any > remaining or future plain `static inline` helper on those paths can > break silently. > ----- > > Also, regarding your earlier question about `__switch_to()`: > > > Hmm.. Do we really have the protection today? For example, on x86, > > __switch_to is marked with __notrace_funcgraph. But __switch_to > > calls switch_to_extra, which calls __switch_to_xtra, and __switch_to_xtra > > is actually traceable. Is this a problem? > > That is actually fine, because __notrace_funcgraph on __switch_to() > is specifically for function_graph's current->ret_stack tracking across > the current task switch, not general ftrace recursion. > > In __switch_to(), raw_cpu_write(current_task, next_p) updates `current`: > if __switch_to() itself were graph-traced, entry would push the return > address onto prev_p->ret_stack while return would pop from > next_p->ret_stack. On the other hand, switch_to_extra() is called after > current_task has already switched to next_p, so `current` remains > next_p across both entry and exit of __switch_to_xtra(). > This consistency is important for function graph tracer.
Thanks for the explanation! I can understand the concern here. > On the other hand, if notrace is removed from inline macro without static > verification, an un-inlined "inline" helper called from notrace or > ftrace pre-recursion paths has no such safeguard. That is why I believe > we need compile-time validation (similar to noinstr checks) before > changing inline globally. However, it appears that we are using "inline" as "notrace", which seems wrong. IIUC, recursion avoidance is the requirement for the tracing subsystem, but "inline means notrace" applies to the whole kernel. Shall we review all the "inline" uses in the tracing subsystem, and add "notrace" to functions that cannot be traced. Then, we can remove notrace from "inline". Would this work? AFAICT, we may or may not need a static analysis tool for this. Thanks, Song
