[dpdk-dev] [PATCH] bpf: fix to allow ptr stack program type

Ananyev, Konstantin konstantin.ananyev at intel.com
Tue Aug 13 08:50:34 CEST 2019


Hi Jerin,

> > > > >
> > > > > bpf_validate does not allow to execute RTE_BPF_ARG_PTR_STACK for
> > > > > no reason.
> > > >
> > > > I believe there is a reason,
> > > > ARG_PTR_STACK is reserved for memory within BPF program internal
> > > > stack only.
> > > > User that calls BPF program should never pass parameter with that type.
> > >
> > > OK.
> > > Shouldn't we remove that from public header file
> > > (lib/librte_bpf/rte_bpf.h) then ?
> >
> > Probably... or might be just put extra comments to mark it as internal?
> > The reason I left it here, so we can add new public values for enum here,
> > before RTE_BPF_ARG_PTR_STACK.
> > Of course in theory we can use for RTE_BPF_ARG_PTR_STACK some
> > reserved value instead.
> >
> > >
> > > > If the user allocates parameter for bpf function on the stack, he
> > > > can still use RTE_BPF_ARG_PTR for it.
> > >
> > > I see the _stack_ is only allocated under RTE_BPF_ARG_PTR_STACK checks
> > in bpf_validate.c.
> > > Can you check? I agree that stack should be allocated for
> > RTE_BPF_ARG_PTR as well.
> >
> > Not sure I understand your query here...
> > Each BPF program can use up to MAX_BPF_STACK_SIZE bytes for stack.
> > Though to avoid JIT to allocate unused space for the stack, in bpf_validate.c
> > we figure out does given BPF program really allocate things on the stack and
> > if yes, how many bytes is needed.
> > This info is stored in rte_bpf.stack_sz and can be used later by the JIT.
> > Let say for x86 jit is used in  emit_prolog().
> 
> I thought, stack will be allocated only when user gives
> RTE_BPF_ARG_PTR_STACK.
> I tested following program with RTE_BPF_ARG_PTR. It allocates stacks
> Properly. So everything is good.
> 
> stdw [r10-64], 0xab
> mov r0, 0
> exit
> 
> I will modify this patch to following to avoid any confusion to user:
> 1) Change RTE_BPF_ARG_PTR_STACK to RTE_BPF_ARG_RESERVED in public header file
> 2) In the implementation #define RTE_BPF_ARG_RESERVED BPF_ARG_PTR_STACK
> 
> Is it OK?

Yes, sounds like a good approach to me.
Thanks
Konstantin



More information about the dev mailing list