Re: [PATCH bpf-next v2 5/8] selftests/bpf: Verify xdp_metadata xdp->af_xdp path

Stanislav Fomichev
2022-11-29T18:52:16Z

On Tue, Nov 29, 2022 at 2:06 AM Anton Protopopov <aspsk@isovalent.com> wrote:
>
> On 22/11/21 10:25, Stanislav Fomichev wrote:
> >
> > [...]
> >
> > +
> > + if (bpf_xdp_metadata_rx_timestamp_supported(ctx))
> > + meta->rx_timestamp = bpf_xdp_metadata_rx_timestamp(ctx);
> > +
> > + if (bpf_xdp_metadata_rx_hash_supported(ctx))
> > + meta->rx_hash = bpf_xdp_metadata_rx_hash(ctx);
>
> Is there a case when F_supported and F are not called in a sequence? If not,
> then you can join them:
>
> bool (*ndo_xdp_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
>
> so that a calling XDP program does one indirect call instead of two for one
> field
>
> if (bpf_xdp_metadata_rx_timestamp(ctx, &meta->rx_timestamp)) {
> /* ... couldn't get the timestamp */
> }

The purpose of the original bpf_xdp_metadata_rx_hash_supported was to
allow unrolling and support dropping some dead branches by the
verifier.
Since there is still a chance we might eventually unroll some of
these, maybe it makes sense to keep as is?