Commit d141b8bc authored by Song Liu's avatar Song Liu Committed by Alexei Starovoitov
Browse files

perf: Expose get/put_callchain_entry()



Sanitize and expose get/put_callchain_entry(). This would be used by bpf
stack map.

Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200630062846.664389-2-songliubraving@fb.com
parent bba1dc0b
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -1244,6 +1244,8 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
extern struct perf_callchain_entry *perf_callchain(struct perf_event *event, struct pt_regs *regs);
extern struct perf_callchain_entry *perf_callchain(struct perf_event *event, struct pt_regs *regs);
extern int get_callchain_buffers(int max_stack);
extern int get_callchain_buffers(int max_stack);
extern void put_callchain_buffers(void);
extern void put_callchain_buffers(void);
extern struct perf_callchain_entry *get_callchain_entry(int *rctx);
extern void put_callchain_entry(int rctx);


extern int sysctl_perf_event_max_stack;
extern int sysctl_perf_event_max_stack;
extern int sysctl_perf_event_max_contexts_per_stack;
extern int sysctl_perf_event_max_contexts_per_stack;
+6 −7
Original line number Original line Diff line number Diff line
@@ -149,7 +149,7 @@ void put_callchain_buffers(void)
	}
	}
}
}


static struct perf_callchain_entry *get_callchain_entry(int *rctx)
struct perf_callchain_entry *get_callchain_entry(int *rctx)
{
{
	int cpu;
	int cpu;
	struct callchain_cpus_entries *entries;
	struct callchain_cpus_entries *entries;
@@ -159,8 +159,10 @@ static struct perf_callchain_entry *get_callchain_entry(int *rctx)
		return NULL;
		return NULL;


	entries = rcu_dereference(callchain_cpus_entries);
	entries = rcu_dereference(callchain_cpus_entries);
	if (!entries)
	if (!entries) {
		put_recursion_context(this_cpu_ptr(callchain_recursion), *rctx);
		return NULL;
		return NULL;
	}


	cpu = smp_processor_id();
	cpu = smp_processor_id();


@@ -168,7 +170,7 @@ static struct perf_callchain_entry *get_callchain_entry(int *rctx)
		(*rctx * perf_callchain_entry__sizeof()));
		(*rctx * perf_callchain_entry__sizeof()));
}
}


static void
void
put_callchain_entry(int rctx)
put_callchain_entry(int rctx)
{
{
	put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
	put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
@@ -183,11 +185,8 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
	int rctx;
	int rctx;


	entry = get_callchain_entry(&rctx);
	entry = get_callchain_entry(&rctx);
	if (rctx == -1)
		return NULL;

	if (!entry)
	if (!entry)
		goto exit_put;
		return NULL;


	ctx.entry     = entry;
	ctx.entry     = entry;
	ctx.max_stack = max_stack;
	ctx.max_stack = max_stack;