Skip to content

Commit

Permalink
1. Fixing page offset check in funcslower
Browse files Browse the repository at this point in the history
2. Not using BPF_F_REUSE_STACKID in funcslower stack traces
3. Combining an ifdef check
  • Loading branch information
dpayne committed Jun 6, 2018
1 parent f99769d commit 00ac6d6
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tools/funcslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@
BPF_HASH(entryinfo, u64, struct entry_t);
BPF_PERF_OUTPUT(events);
#ifdef USER_STACKS
BPF_STACK_TRACE(stacks, 2048);
#else
#ifdef KERNEL_STACKS
#if defined(USER_STACKS) || defined(KERNEL_STACKS)
BPF_STACK_TRACE(stacks, 2048);
#endif
#endif
static int trace_entry(struct pt_regs *ctx, int id)
{
Expand Down Expand Up @@ -167,21 +163,34 @@
data.retval = PT_REGS_RC(ctx);
#ifdef USER_STACKS
data.user_stack_id = stacks.get_stackid(ctx, BPF_F_REUSE_STACKID | BPF_F_USER_STACK);
data.user_stack_id = stacks.get_stackid(ctx, BPF_F_USER_STACK);
#endif
#ifdef KERNEL_STACKS
data.kernel_stack_id = stacks.get_stackid(ctx, 0 | BPF_F_REUSE_STACKID);
data.kernel_stack_id = stacks.get_stackid(ctx, 0);
if (data.kernel_stack_id >= 0) {
u64 ip = PT_REGS_IP(ctx);
u64 page_offset;
// if ip isn't sane, leave key ips as zero for later checking
#ifdef CONFIG_RANDOMIZE_MEMORY
if (ip > __PAGE_OFFSET_BASE) {
#if defined(CONFIG_X86_64) && defined(__PAGE_OFFSET_BASE)
// x64, 4.16, ..., 4.11, etc., but some earlier kernel didn't have it
page_offset = __PAGE_OFFSET_BASE;
#elif defined(CONFIG_X86_64) && defined(__PAGE_OFFSET_BASE_L4)
// x64, 4.17, and later
#if defined(CONFIG_DYNAMIC_MEMORY_LAYOUT) && defined(CONFIG_X86_5LEVEL)
page_offset = __PAGE_OFFSET_BASE_L5;
#else
page_offset = __PAGE_OFFSET_BASE_L4;
#endif
#else
if (ip > PAGE_OFFSET) {
// earlier x86_64 kernels, e.g., 4.6, comes here
// arm64, s390, powerpc, x86_32
page_offset = PAGE_OFFSET;
#endif
if (ip > page_offset) {
data.kernel_ip = ip;
}
}
Expand Down

0 comments on commit 00ac6d6

Please sign in to comment.