[PATCH v4] bpf: support new commands BPF_MAP_*_BATCH

Dmitry V. Levin ldv at altlinux.org
Sat Apr 4 17:53:15 UTC 2020


On Sat, Apr 04, 2020 at 07:39:18PM +0200, Paul Chaignon wrote:
> On Sat, Apr 04, 2020 at 08:30:34PM +0300, Dmitry V. Levin wrote:
> > On Sat, Apr 04, 2020 at 07:03:17PM +0200, Paul Chaignon wrote:
> > > * xlat/bpf_commands.in (BPF_MAP_LOOKUP_BATCH): New constant introduced
> > > by Linux commit v5.6-rc1~151^2~46^2~23^2~7.
> > > (BPF_MAP_LOOKUP_AND_DELETE_BATCH): New constant introduced by Linux
> > > commit v5.6-rc1~151^2~46^2~23^2~4.
> > > (BPF_MAP_UPDATE_BATCH, BPF_MAP_DELETE_BATCH): New constants introduced
> > > by Linux commit v5.6-rc1~151^2~46^2~23^2~6.
> > > * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH),
> > > BEGIN_BPF_CMD_DECODER(BPF_MAP_UPDATE_BATCH),
> > > BEGIN_BPF_CMD_DECODER(BPF_MAP_DELETE_BATCH)): Decode the new commands.
> > > (decode_BPF_MAP_LOOKUP_AND_DELETE_BATCH): New macro.
> > > (SYS_FUNC(bpf)): Decode the new commands.
> > > * bpf_attr.h (BPF_MAP_LOOKUP_BATCH_struct,
> > > BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct, BPF_MAP_UPDATE_BATCH_struct,
> > > BPF_MAP_DELETE_BATCH_struct): New structs introduced by Linux commit
> > > v5.6-rc1~151^2~46^2~23^2~7.
> > > (BPF_MAP_LOOKUP_BATCH_struct_size,
> > > BPF_MAP_LOOKUP_AND_DELETE_BATCH_struct_size,
> > > BPF_MAP_UPDATE_BATCH_struct_size, BPF_MAP_DELETE_BATCH_struct_size): New
> > > macros.
> > > * NEWS: Mention this.
> > > * tests/bpf.c (BPF_MAP_LOOKUP_BATCH_checks, BPF_MAP_UPDATE_BATCH_checks,
> > > BPF_MAP_DELETE_BATCH_checks): Tests for the new commands.
> > > 
> > > Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
> > > ---
> 
> [...]
> 
> > > diff --git a/bpf.c b/bpf.c
> > > index d666a423..97d102c6 100644
> > > --- a/bpf.c
> > > +++ b/bpf.c
> > > @@ -954,6 +954,90 @@ BEGIN_BPF_CMD_DECODER(BPF_TASK_FD_QUERY)
> > >  }
> > >  END_BPF_CMD_DECODER(RVAL_DECODED)
> > >  
> > > +BEGIN_BPF_CMD_DECODER(BPF_MAP_LOOKUP_BATCH)
> > > +{
> > > +	unsigned long count;
> > > +
> > > +	if (entering(tcp)) {
> > > +		set_tcb_priv_ulong(tcp, attr.count);
> > > +
> > > +		PRINT_FIELD_ADDR64("{batch={", attr, in_batch);
> > > +		PRINT_FIELD_ADDR64(", ", attr, out_batch);
> > > +		PRINT_FIELD_ADDR64(", ", attr, keys);
> > > +		PRINT_FIELD_ADDR64(", ", attr, values);
> > > +		PRINT_FIELD_U(", ", attr, count);
> > > +		PRINT_FIELD_FD(", ", attr, map_fd, tcp);
> > > +		PRINT_FIELD_FLAGS(", ", attr, elem_flags,
> > > +				  bpf_map_lookup_elem_flags, "BPF_???");
> > > +		PRINT_FIELD_X(", ", attr, flags);
> > > +
> > > +		tprintf("}");
> > > +	} else {
> > > +		count = get_tcb_priv_ulong(tcp);
> > > +		if (count != attr.count) {
> > > +			PRINT_FIELD_U("=> {", attr, count);
> > > +			tprintf("}");
> > > +		}
> > > +		return RVAL_DECODED;
> > > +	}
> > > +}
> > > +END_BPF_CMD_DECODER(0)
> > 
> > Shouldn't the name "batch" be printed on exiting as well?
> 
> Ugh, of course :(
> Should I resent?

Yes, please.


-- 
ldv


More information about the Strace-devel mailing list