Netdev List
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: netdev@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	kernel-team@fb.com, hannes@cmpxchg.org, qinteng@fb.com
Subject: Re: [PATCH bpf-next v4 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address
Date: Mon, 12 Mar 2018 23:01:32 +0100	[thread overview]
Message-ID: <20180312220132.GH4043@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180312203957.2025833-2-songliubraving@fb.com>

On Mon, Mar 12, 2018 at 01:39:56PM -0700, Song Liu wrote:
> +static void stack_map_get_build_id_offset(struct bpf_map *map,
> +					  struct stack_map_bucket *bucket,
> +					  u64 *ips, u32 trace_nr)
> +{
> +	int i;
> +	struct vm_area_struct *vma;
> +	struct bpf_stack_build_id *id_offs;
> +
> +	bucket->nr = trace_nr;
> +	id_offs = (struct bpf_stack_build_id *)bucket->data;
> +
> +	if (!current || !current->mm ||
> +	    down_read_trylock(&current->mm->mmap_sem) == 0) {

You probably want an in_nmi() before the down_read_trylock(). Doing
up_read() is an absolute no-no from NMI context.

And IIUC its 'trivial' to use this stuff with hardware counters.

> +		/* cannot access current->mm, fall back to ips */
> +		for (i = 0; i < trace_nr; i++) {
> +			id_offs[i].status = BPF_STACK_BUILD_ID_IP;
> +			id_offs[i].ip = ips[i];
> +		}
> +		return;
> +	}
> +
> +	for (i = 0; i < trace_nr; i++) {
> +		vma = find_vma(current->mm, ips[i]);
> +		if (!vma || stack_map_get_build_id(vma, id_offs[i].build_id)) {
> +			/* per entry fall back to ips */
> +			id_offs[i].status = BPF_STACK_BUILD_ID_IP;
> +			id_offs[i].ip = ips[i];
> +			continue;
> +		}
> +		id_offs[i].offset = (vma->vm_pgoff << PAGE_SHIFT) + ips[i]
> +			- vma->vm_start;
> +		id_offs[i].status = BPF_STACK_BUILD_ID_VALID;
> +	}
> +	up_read(&current->mm->mmap_sem);
> +}

  parent reply	other threads:[~2018-03-12 22:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12 20:39 [PATCH bpf-next v4 0/2] bpf stackmap with build_id+offset Song Liu
2018-03-12 20:39 ` [PATCH bpf-next v4 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address Song Liu
2018-03-12 21:00   ` Alexei Starovoitov
2018-03-12 21:12     ` Song Liu
2018-03-12 21:31       ` Alexei Starovoitov
2018-03-12 22:47         ` Song Liu
2018-03-13 21:31           ` Song Liu
2018-03-12 22:01   ` Peter Zijlstra [this message]
2018-04-24  0:06     ` Yonghong Song
2018-03-13  9:53   ` [PATCH] bpf: fix semicolon.cocci warnings kbuild test robot
2018-03-13  9:53   ` [PATCH bpf-next v4 1/2] bpf: extend stackmap to save binary_build_id+offset instead of address kbuild test robot
2018-03-12 20:39 ` [PATCH bpf-next v4 2/2] bpf: add selftest for stackmap with BPF_F_STACK_BUILD_ID Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180312220132.GH4043@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=qinteng@fb.com \
    --cc=songliubraving@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox