bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: "Björn Töpel" <bjorn.topel@intel.com>,
	"Björn Töpel" <bjorn.topel@gmail.com>,
	ast@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: maciej.fijalkowski@intel.com, hawk@kernel.org, toke@redhat.com,
	magnus.karlsson@intel.com, john.fastabend@gmail.com,
	kuba@kernel.org, davem@davemloft.net,
	Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: [PATCH bpf-next v5 2/2] bpf, xdp: restructure redirect actions
Date: Fri, 5 Mar 2021 23:56:20 +0100	[thread overview]
Message-ID: <f285c8c8-2640-8c34-804c-48928adbe0ff@iogearbox.net> (raw)
In-Reply-To: <222735a9-0cbe-7131-7fd8-f638ddecbedc@intel.com>

On 3/5/21 6:11 PM, Björn Töpel wrote:
> On 2021-03-05 16:44, Daniel Borkmann wrote:
>> On 2/27/21 1:21 PM, Björn Töpel wrote:
>> [...]
>>> diff --git a/include/linux/filter.h b/include/linux/filter.h
>>> index 008691fd3b58..a7752badc2ec 100644
>>> --- a/include/linux/filter.h
>>> +++ b/include/linux/filter.h
>>> @@ -646,11 +646,20 @@ struct bpf_redirect_info {
>>>       u32 flags;
>>>       u32 tgt_index;
>>>       void *tgt_value;
>>> -    struct bpf_map *map;
>>> +    u32 map_id;
>>> +    u32 tgt_type;
>>>       u32 kern_flags;
>>>       struct bpf_nh_params nh;
>>>   };
>>> +enum xdp_redirect_type {
>>> +    XDP_REDIR_UNSET,
>>> +    XDP_REDIR_DEV_IFINDEX,
>>
>> [...]
>>
>>> +    XDP_REDIR_DEV_MAP,
>>> +    XDP_REDIR_CPU_MAP,
>>> +    XDP_REDIR_XSK_MAP,
>>
>> Did you eval whether for these maps we can avoid the redundant def above by just
>> passing in map->map_type as ri->tgt_type and inferring the XDP_REDIR_UNSET from
>> invalid map_id of 0 (given the idr will never allocate such)?
>>
> 
> I'll take a stab at it!

Sounds good, thanks! If it doesn't simplify or gets worse, we can always stick to
the one here.

>> [...]
>>> @@ -4068,10 +4039,9 @@ BPF_CALL_2(bpf_xdp_redirect, u32, ifindex, u64, flags)
>>>       if (unlikely(flags))
>>>           return XDP_ABORTED;
>>> -    ri->flags = flags;
>>> -    ri->tgt_index = ifindex;
>>> -    ri->tgt_value = NULL;
>>> -    WRITE_ONCE(ri->map, NULL);
>>> +    ri->tgt_type = XDP_REDIR_DEV_IFINDEX;
>>> +    ri->tgt_index = 0;
>>> +    ri->tgt_value = (void *)(long)ifindex;
>>
>> nit: Bit ugly to pass this in /read out this way, maybe union if we cannot use
>> tgt_index?
>>
> 
> Dito!
> 
> 
> Thanks for the input! I'll get back with a v6!
> 
> 
> Björn
> 
> 
>>>       return XDP_REDIRECT;
>>>   }
>>> diff --git a/net/xdp/xskmap.c b/net/xdp/xskmap.c
>>> index 711acb3636b3..2c58d88aa69d 100644
>>> --- a/net/xdp/xskmap.c
>>> +++ b/net/xdp/xskmap.c
>>> @@ -87,7 +87,6 @@ static void xsk_map_free(struct bpf_map *map)
>>>   {
>>>       struct xsk_map *m = container_of(map, struct xsk_map, map);
>>> -    bpf_clear_redirect_map(map);
>>>       synchronize_net();
>>>       bpf_map_area_free(m);
>>>   }
>>> @@ -229,7 +228,8 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key)
>>>   static int xsk_map_redirect(struct bpf_map *map, u32 ifindex, u64 flags)
>>>   {
>>> -    return __bpf_xdp_redirect_map(map, ifindex, flags, __xsk_map_lookup_elem);
>>> +    return __bpf_xdp_redirect_map(map, ifindex, flags, __xsk_map_lookup_elem,
>>> +                      XDP_REDIR_XSK_MAP);
>>>   }
>>>   void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
>>>
>>


      reply	other threads:[~2021-03-05 22:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-27 12:21 [PATCH bpf-next v5 0/2] Optimize bpf_redirect_map()/xdp_do_redirect() Björn Töpel
2021-02-27 12:21 ` [PATCH bpf-next v5 1/2] bpf, xdp: make bpf_redirect_map() a map operation Björn Töpel
2021-03-05 15:55   ` Daniel Borkmann
2021-03-05 17:11     ` Björn Töpel
2021-02-27 12:21 ` [PATCH bpf-next v5 2/2] bpf, xdp: restructure redirect actions Björn Töpel
2021-03-05 15:44   ` Daniel Borkmann
2021-03-05 17:11     ` Björn Töpel
2021-03-05 22:56       ` Daniel Borkmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f285c8c8-2640-8c34-804c-48928adbe0ff@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@gmail.com \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.com \
    --subject='Re: [PATCH bpf-next v5 2/2] bpf, xdp: restructure redirect actions' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).