• Steven Rostedt (Google)'s avatar
    function_graph: Fix up ftrace_graph_ret_addr() · 29c1c24a
    Steven Rostedt (Google) authored
    Yang Li sent a patch to fix the kerneldoc of ftrace_graph_ret_addr().
    While reviewing it, I realized that the comments in the entire function
    header needed a rewrite. When doing that, I realized that @idx parameter
    was being ignored. Every time this was called by the unwinder, it would
    start the loop at the top of the shadow stack and look for the matching
    stack pointer. When it found it, it would return it. When the unwinder
    asked for the next function, it would search from the beginning again.
    
    In reality, it should start from where it left off. That was the reason
    for the @idx parameter in the first place. The first time the unwinder
    calls this function, the @idx pointer would contain zero. That would mean
    to start from the top of the stack. The function was supposed to update
    the @idx with the index where it found the return address, so that the
    next time the unwinder calls this function it doesn't have to search
    through the previous addresses it found (making it O(n^2)!).
    
    This speeds up the unwinder's use of ftrace_graph_ret_addr() by an order
    of magnitude.
    
    Link: https://lore.kernel.org/linux-trace-kernel/20240610181746.656e3759@gandalf.local.home/
    Link: https://lore.kernel.org/linux-trace-kernel/20240611031737.821995106@goodmis.org
    
    Cc: Masami Hiramatsu <mhiramat@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Guo Ren <guoren@kernel.org>
    Cc: Huacai Chen <chenhuacai@kernel.org>
    Cc: WANG Xuerui <kernel@xen0n.name>
    Cc: Michael Ellerman <mpe@ellerman.id.au>
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
    Cc: "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>
    Cc: Paul Walmsley <paul.walmsley@sifive.com>
    Cc: Palmer Dabbelt <palmer@dabbelt.com>
    Cc: Albert Ou <aou@eecs.berkeley.edu>
    Cc: Heiko Carstens <hca@linux.ibm.com>
    Cc: Vasily Gorbik <gor@linux.ibm.com>
    Cc: Alexander Gordeev <agordeev@linux.ibm.com>
    Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: "H. Peter Anvin" <hpa@zytor.com>
    Reported-by: default avatarYang Li <yang.lee@linux.alibaba.com>
    Fixes: 7aa1eaef ("function_graph: Allow multiple users to attach to function graph")
    Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
    29c1c24a
fgraph.c 38.1 KB