> powerpc: Mark helpers called from noinstr code notrace TL;DR: - wrtee() and mtmsr_isync() may be left traceable out of line in noinstr paths; unverified in a build - commit message has wrong riscv irqflags and soft_nmi_interrupt() claims
> powerpc: Mark helpers called from noinstr code notrace > > Much of the powerpc code that must not be traced uses plain inline > helpers from headers: the atomic, bitops and barrier helpers, the > irqflags and hard irq helpers in <asm/hw_irq.h>, the interrupt entry > and exit helpers in <asm/entry-common.h>, and the MMIO accessors. > noinstr code calls them at points where tracing is not safe, for > example: > [ ... ] > - soft_nmi_interrupt() calls wd_smp_lock(). > With clang, a ppc64le_defconfig build has out-of-line copies of many of > these helpers, called from the functions above. The copies are > untraced only because inline implies notrace. > Mark them notrace explicitly, like the irq_soft_mask_*() helpers in > <asm/hw_irq.h> already are. On x86, arm64 and riscv, the atomic, bitops > and irqflags helpers are __always_inline. No functional change. > Assisted-by: Claude:claude-opus-5 > Signed-off-by: Song Liu <[email protected]> The commit message says that on riscv the irqflags helpers are __always_inline. Is that accurate? In arch/riscv/include/asm/irqflags.h they are plain inline: static inline unsigned long arch_local_save_flags(void) static inline void arch_local_irq_enable(void) static inline void arch_local_irq_disable(void) The riscv patch later in this series, 0c13f314b0bd ("riscv: Mark helpers called from noinstr code notrace"), says "On riscv, the arch_local_irq_*() helpers behind these are plain inline functions. On x86 and arm64 they are __always_inline." That patch adds notrace and leaves them plain inline, so the sentence stays wrong after the series. The riscv atomic and bitops helpers are __always_inline, so only the irqflags part is off. Could the sentence name only x86 and arm64 for the irqflags helpers? The commit message also gives soft_nmi_interrupt() calling wd_smp_lock() as an example of noinstr code calling a helper where tracing is not safe. Is that accurate? powerpc interrupt handlers are deliberately not noinstr; interrupt.h says "Don't use noinstr here like x86, but rather add NOKPROBE_SYMBOL". soft_nmi_interrupt() is entered with IVEC=0x900 in virtual mode, so DEFINE_INTERRUPT_HANDLER_NMI calls irqentry_nmi_enter() before the body runs and RCU is watching when wd_smp_lock() is called. In addition, nmi_disables_ftrace() has: /* Allow DEC and PMI to be traced when they are soft-NMI */ and returns false for INTERRUPT_DECREMENTER on BOOK3S_64, so ftrace is left enabled on purpose. The same handler body also calls wd_try_report(), set_cpu_stuck() and pr_emerg(), which are all traceable. Marking wd_smp_lock() and wd_smp_unlock() notrace looks harmless, but could this example be dropped or reworded to give the real reason? > diff --git a/arch/powerpc/include/asm/hw_irq.h > b/arch/powerpc/include/asm/hw_irq.h > --- a/arch/powerpc/include/asm/hw_irq.h > +++ b/arch/powerpc/include/asm/hw_irq.h [ ... ] > -static inline unsigned long mtmsr_isync_irqsafe(unsigned long msr) > +static inline notrace unsigned long mtmsr_isync_irqsafe(unsigned long msr) > { > #ifdef CONFIG_PPC64 > if (arch_irqs_disabled()) { mtmsr_isync_irqsafe() and the BookE irqflags helpers call two leaf helpers from arch/powerpc/include/asm/reg.h that stay plain inline and are not marked anywhere in the series: static inline void mtmsr_isync(unsigned long val) static inline void wrtee(unsigned long val) On Book3S-64 mtmsr_isync() is reached from code that is notrace on purpose: arch_exit_to_user_mode_prepare() (notrace) -> restore_math() (notrace) -> msr_check_and_set() (notrace) -> mtmsr_isync_irqsafe() -> mtmsr_isync() On 32-bit BookE, ct_idle_exit() (noinstr) calls raw_local_irq_save() and raw_local_irq_restore(), which reach arch_local_irq_save() -> wrtee(0) and arch_local_irq_restore() -> wrtee(flags) before RCU is watching. Once a833438864c3 ("compiler_types: Move notrace from inline to __always_inline") is applied, an out-of-line copy of either function would get an ftrace call site. Should wrtee() and mtmsr_isync() (and possibly msr_check_and_clear(), which restore_math() also calls) be marked notrace here? This was not seen in a build. --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46577721107
