Subject: Re: [PATCH bpf-next 2/3] bpf: emit RECORD_MMAP events for bpf prog load/unload

From: Arnaldo Carvalho de Melo <[email-masked]>
Date: Thu, 20 Sep 2018 10:25:45 -0300

Em Thu, Sep 20, 2018 at 10:44:24AM +0200, Peter Zijlstra escreveu:
> On Wed, Sep 19, 2018 at 03:39:34PM -0700, Alexei Starovoitov wrote:
> >  void bpf_prog_kallsyms_del(struct bpf_prog *fp)
> >  {
> > +	unsigned long symbol_start, symbol_end;
> > +	/* mmap_record.filename cannot be NULL and has to be u64 aligned */
> > +	char buf[sizeof(u64)] = {};
> > +
> >  	if (!bpf_prog_kallsyms_candidate(fp))
> >  		return;
> >  
> >  	spin_lock_bh(&bpf_lock);
> >  	bpf_prog_ksym_node_del(fp->aux);
> >  	spin_unlock_bh(&bpf_lock);
> > +	bpf_get_prog_addr_region(fp, &symbol_start, &symbol_end);
> > +	perf_event_mmap_bpf_prog(symbol_start, symbol_end - symbol_start,
> > +				 buf, sizeof(buf));
> >  }
> 
> So perf doesn't normally issue unmap events.. We've talked about doing
> that, but so far it's never really need needed I think.
 
> I feels a bit weird to start issuing unmap events for this.

For reference, this surfaced here:

https://lkml.org/lkml/2017/1/27/452

Start of the thread, that involves postgresql, JIT, LLVM, perf is here:

https://lkml.org/lkml/2016/12/10/1

PeterZ provided a patch introducing PERF_RECORD_MUNMAP, went nowhere due
to having to cope with munmapping parts of existing mmaps, etc.

I'm still more in favour of introduce PERF_RECORD_MUNMAP, even if for
now it would be used just in this clean case for undoing a
PERF_RECORD_MMAP for a BPF program.

The ABI is already complicated, starting to use something called
PERF_RECORD_MMAP for unmmaping by just using a NULL name... too clever,
I think.

- Arnaldo