From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from merlin.infradead.org ([205.233.59.134]:48228 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbeCLWBo (ORCPT ); Mon, 12 Mar 2018 18:01:44 -0400 Date: Mon, 12 Mar 2018 23:01:32 +0100 From: Peter Zijlstra To: Song Liu 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 Message-ID: <20180312220132.GH4043@hirez.programming.kicks-ass.net> References: <20180312203957.2025833-1-songliubraving@fb.com> <20180312203957.2025833-2-songliubraving@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180312203957.2025833-2-songliubraving@fb.com> Sender: netdev-owner@vger.kernel.org List-ID: 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(¤t->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(¤t->mm->mmap_sem); > +}