Commit aad3a0d0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull ftrace updates from Steven Rostedt:

 - Restructure the function graph shadow stack to prepare it for use
   with kretprobes

   With the goal of merging the shadow stack logic of function graph and
   kretprobes, some more restructuring of the function shadow stack is
   required.

   Move out function graph specific fields from the fgraph
   infrastructure and store it on the new stack variables that can pass
   data from the entry callback to the exit callback.

   Hopefully, with this change, the merge of kretprobes to use fgraph
   shadow stacks will be ready by the next merge window.

 - Make shadow stack 4k instead of using PAGE_SIZE.

   Some architectures have very large PAGE_SIZE values which make its
   use for shadow stacks waste a lot of memory.

 - Give shadow stacks its own kmem cache.

   When function graph is started, every task on the system gets a
   shadow stack. In the future, shadow stacks may not be 4K in size.
   Have it have its own kmem cache so that whatever size it becomes will
   still be efficient in allocations.

 - Initialize profiler graph ops as it will be needed for new updates to
   fgraph

 - Convert to use guard(mutex) for several ftrace and fgraph functions

 - Add more comments and documentation

 - Show function return address in function graph tracer

   Add an option to show the caller of a function at each entry of the
   function graph tracer, similar to what the function tracer does.

 - Abstract out ftrace_regs from being used directly like pt_regs

   ftrace_regs was created to store a partial pt_regs. It holds only the
   registers and stack information to get to the function arguments and
   return values. On several archs, it is simply a wrapper around
   pt_regs. But some users would access ftrace_regs directly to get the
   pt_regs which will not work on all archs. Make ftrace_regs an
   abstract structure that requires all access to its fields be through
   accessor functions.

 - Show how long it takes to do function code modifications

   When code modification for function hooks happen, it always had the
   time recorded in how long it took to do the conversion. But this
   value was never exported. Recently the code was touched due to new
   ROX modification handling that caused a large slow down in doing the
   modifications and had a significant impact on boot times.

   Expose the timings in the dyn_ftrace_total_info file. This file was
   created a while ago to show information about memory usage and such
   to implement dynamic function tracing. It's also an appropriate file
   to store the timings of this modification as well. This will make it
   easier to see the impact of changes to code modification on boot up
   timings.

 - Other clean ups and small fixes

* tag 'ftrace-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: (22 commits)
  ftrace: Show timings of how long nop patching took
  ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash()
  ftrace: Use guard to take the ftrace_lock in release_probe()
  ftrace: Use guard to lock ftrace_lock in cache_mod()
  ftrace: Use guard for match_records()
  fgraph: Use guard(mutex)(&ftrace_lock) for unregister_ftrace_graph()
  fgraph: Give ret_stack its own kmem cache
  fgraph: Separate size of ret_stack from PAGE_SIZE
  ftrace: Rename ftrace_regs_return_value to ftrace_regs_get_return_value
  selftests/ftrace: Fix check of return value in fgraph-retval.tc test
  ftrace: Use arch_ftrace_regs() for ftrace_regs_*() macros
  ftrace: Consolidate ftrace_regs accessor functions for archs using pt_regs
  ftrace: Make ftrace_regs abstract from direct use
  fgragh: No need to invoke the function call_filter_check_discard()
  fgraph: Simplify return address printing in function graph tracer
  function_graph: Remove unnecessary initialization in ftrace_graph_ret_addr()
  function_graph: Support recording and printing the function return address
  ftrace: Have calltime be saved in the fgraph storage
  ftrace: Use a running sleeptime instead of saving on shadow stack
  fgraph: Use fgraph data to store subtime for profiler
  ...
parents 8f7c8b88 36a367b8
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -54,8 +54,11 @@ extern void return_to_handler(void);
unsigned long ftrace_call_adjust(unsigned long addr);

#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
#define HAVE_ARCH_FTRACE_REGS
struct dyn_ftrace;
struct ftrace_ops;
struct ftrace_regs;
#define arch_ftrace_regs(fregs) ((struct __arch_ftrace_regs *)(fregs))

#define arch_ftrace_get_regs(regs) NULL

@@ -63,7 +66,7 @@ struct ftrace_ops;
 * Note: sizeof(struct ftrace_regs) must be a multiple of 16 to ensure correct
 * stack alignment
 */
struct ftrace_regs {
struct __arch_ftrace_regs {
	/* x0 - x8 */
	unsigned long regs[9];

@@ -83,47 +86,47 @@ struct ftrace_regs {
static __always_inline unsigned long
ftrace_regs_get_instruction_pointer(const struct ftrace_regs *fregs)
{
	return fregs->pc;
	return arch_ftrace_regs(fregs)->pc;
}

static __always_inline void
ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
				    unsigned long pc)
{
	fregs->pc = pc;
	arch_ftrace_regs(fregs)->pc = pc;
}

static __always_inline unsigned long
ftrace_regs_get_stack_pointer(const struct ftrace_regs *fregs)
{
	return fregs->sp;
	return arch_ftrace_regs(fregs)->sp;
}

static __always_inline unsigned long
ftrace_regs_get_argument(struct ftrace_regs *fregs, unsigned int n)
{
	if (n < 8)
		return fregs->regs[n];
		return arch_ftrace_regs(fregs)->regs[n];
	return 0;
}

static __always_inline unsigned long
ftrace_regs_get_return_value(const struct ftrace_regs *fregs)
{
	return fregs->regs[0];
	return arch_ftrace_regs(fregs)->regs[0];
}

static __always_inline void
ftrace_regs_set_return_value(struct ftrace_regs *fregs,
			     unsigned long ret)
{
	fregs->regs[0] = ret;
	arch_ftrace_regs(fregs)->regs[0] = ret;
}

static __always_inline void
ftrace_override_function_with_return(struct ftrace_regs *fregs)
{
	fregs->pc = fregs->lr;
	arch_ftrace_regs(fregs)->pc = arch_ftrace_regs(fregs)->lr;
}

int ftrace_regs_query_register_offset(const char *name);
@@ -143,7 +146,7 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs,
	 * The ftrace trampoline will return to this address instead of the
	 * instrumented function.
	 */
	fregs->direct_tramp = addr;
	arch_ftrace_regs(fregs)->direct_tramp = addr;
}
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */

+11 −11
Original line number Diff line number Diff line
@@ -80,19 +80,19 @@ int main(void)
  DEFINE(PT_REGS_SIZE,		sizeof(struct pt_regs));
  BLANK();
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_ARGS
  DEFINE(FREGS_X0,		offsetof(struct ftrace_regs, regs[0]));
  DEFINE(FREGS_X2,		offsetof(struct ftrace_regs, regs[2]));
  DEFINE(FREGS_X4,		offsetof(struct ftrace_regs, regs[4]));
  DEFINE(FREGS_X6,		offsetof(struct ftrace_regs, regs[6]));
  DEFINE(FREGS_X8,		offsetof(struct ftrace_regs, regs[8]));
  DEFINE(FREGS_FP,		offsetof(struct ftrace_regs, fp));
  DEFINE(FREGS_LR,		offsetof(struct ftrace_regs, lr));
  DEFINE(FREGS_SP,		offsetof(struct ftrace_regs, sp));
  DEFINE(FREGS_PC,		offsetof(struct ftrace_regs, pc));
  DEFINE(FREGS_X0,		offsetof(struct __arch_ftrace_regs, regs[0]));
  DEFINE(FREGS_X2,		offsetof(struct __arch_ftrace_regs, regs[2]));
  DEFINE(FREGS_X4,		offsetof(struct __arch_ftrace_regs, regs[4]));
  DEFINE(FREGS_X6,		offsetof(struct __arch_ftrace_regs, regs[6]));
  DEFINE(FREGS_X8,		offsetof(struct __arch_ftrace_regs, regs[8]));
  DEFINE(FREGS_FP,		offsetof(struct __arch_ftrace_regs, fp));
  DEFINE(FREGS_LR,		offsetof(struct __arch_ftrace_regs, lr));
  DEFINE(FREGS_SP,		offsetof(struct __arch_ftrace_regs, sp));
  DEFINE(FREGS_PC,		offsetof(struct __arch_ftrace_regs, pc));
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
  DEFINE(FREGS_DIRECT_TRAMP,	offsetof(struct ftrace_regs, direct_tramp));
  DEFINE(FREGS_DIRECT_TRAMP,	offsetof(struct __arch_ftrace_regs, direct_tramp));
#endif
  DEFINE(FREGS_SIZE,		sizeof(struct ftrace_regs));
  DEFINE(FREGS_SIZE,		sizeof(struct __arch_ftrace_regs));
  BLANK();
#endif
  DEFINE(CPU_BOOT_TASK,		offsetof(struct secondary_data, task));
+5 −5
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ struct fregs_offset {
#define FREGS_OFFSET(n, field)					\
{								\
	.name = n,						\
	.offset = offsetof(struct ftrace_regs, field),	\
	.offset = offsetof(struct __arch_ftrace_regs, field),	\
}

static const struct fregs_offset fregs_offsets[] = {
@@ -481,7 +481,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
		       struct ftrace_ops *op, struct ftrace_regs *fregs)
{
	prepare_ftrace_return(ip, &fregs->lr, fregs->fp);
	prepare_ftrace_return(ip, &arch_ftrace_regs(fregs)->lr, arch_ftrace_regs(fregs)->fp);
}
#else
/*
+4 −25
Original line number Diff line number Diff line
@@ -44,40 +44,19 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent);
#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
struct ftrace_ops;

struct ftrace_regs {
	struct pt_regs regs;
};
#include <linux/ftrace_regs.h>

static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
{
	return &fregs->regs;
}

static __always_inline unsigned long
ftrace_regs_get_instruction_pointer(struct ftrace_regs *fregs)
{
	return instruction_pointer(&fregs->regs);
	return &arch_ftrace_regs(fregs)->regs;
}

static __always_inline void
ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, unsigned long ip)
{
	instruction_pointer_set(&fregs->regs, ip);
	instruction_pointer_set(&arch_ftrace_regs(fregs)->regs, ip);
}

#define ftrace_regs_get_argument(fregs, n) \
	regs_get_kernel_argument(&(fregs)->regs, n)
#define ftrace_regs_get_stack_pointer(fregs) \
	kernel_stack_pointer(&(fregs)->regs)
#define ftrace_regs_return_value(fregs) \
	regs_return_value(&(fregs)->regs)
#define ftrace_regs_set_return_value(fregs, ret) \
	regs_set_return_value(&(fregs)->regs, ret)
#define ftrace_override_function_with_return(fregs) \
	override_function_with_return(&(fregs)->regs)
#define ftrace_regs_query_register_offset(name) \
	regs_query_register_offset(name)

#define ftrace_graph_func ftrace_graph_func
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
		       struct ftrace_ops *op, struct ftrace_regs *fregs);
@@ -90,7 +69,7 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
}

#define arch_ftrace_set_direct_caller(fregs, addr) \
	__arch_ftrace_set_direct_caller(&(fregs)->regs, addr)
	__arch_ftrace_set_direct_caller(&arch_ftrace_regs(fregs)->regs, addr)
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */

#endif
+1 −1
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent)
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
		       struct ftrace_ops *op, struct ftrace_regs *fregs)
{
	struct pt_regs *regs = &fregs->regs;
	struct pt_regs *regs = &arch_ftrace_regs(fregs)->regs;
	unsigned long *parent = (unsigned long *)&regs->regs[1];

	prepare_ftrace_return(ip, (unsigned long *)parent);
Loading