[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b3f96eb9-25c7-eeaf-3e0d-7c055939168b@intel.com>
Date: Wed, 14 Jun 2023 15:25:15 +0200
From: Alexander Lobakin <aleksander.lobakin@...el.com>
To: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
CC: Toke Høiland-Jørgensen <toke@...nel.org>,
<netdev@...r.kernel.org>, <anthony.l.nguyen@...el.com>,
<intel-wired-lan@...ts.osuosl.org>, <magnus.karlsson@...el.com>,
<fred@...udflare.com>
Subject: Re: [Intel-wired-lan] [PATCH iwl-next] ice: allow hot-swapping XDP
programs
From: Maciej Fijalkowski <maciej.fijalkowski@...el.com>
Date: Wed, 14 Jun 2023 14:50:28 +0200
> On Wed, Jun 14, 2023 at 02:40:07PM +0200, Alexander Lobakin wrote:
>> From: Toke Høiland-Jørgensen <toke@...nel.org>
>> Date: Tue, 13 Jun 2023 19:59:37 +0200
[...]
>> What if a NAPI polling cycle is being run on one core while at the very
>> same moment I'm replacing the XDP prog on another core? Not in terms of
>> pointer tearing, I see now that this is handled correctly, but in terms
>> of refcounts? Can't bpf_prog_put() free it while the polling is still
>> active?
>
> Hmm you mean we should do bpf_prog_put() *after* we update bpf_prog on
> ice_rx_ring? I think this is a fair point as we don't bump the refcount
> per each Rx ring that holds the ptr to bpf_prog, we just rely on the main
> one from VSI.
Not even after we update it there. I believe we should synchronize NAPI
cycles with BPF prog update (have synchronize_rcu() before put or so to
make the config path wait until there's no polling and onstack pointers,
would that be enough?).
NAPI polling starts
|<--- XDP prog pointer is placed on the stack and used from there
|
| <--- here you do xchg() and bpf_prog_put()
| <--- here you update XDP progs on the rings
|
|<--- polling loop is still using the [now invalid] onstack pointer
|
NAPI polling ends
>
>>
>>>
>>> It *would* be nice to add an __rcu annotation to ice_vsi->xdp_prog and
>>> ice_rx_ring->xdp_prog (and move to using rcu_dereference(),
>>> rcu_assign_pointer() etc), but this is more a documentation/static
>>> checker thing than it's a "correctness of the generated code" thing :)
>
> Agree but I would rather address the rest of Intel drivers in the series.
>
>>>
>>> -Toke
>>
>> [0]
>> https://elixir.bootlin.com/linux/v6.4-rc6/source/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c#L141
>> [1]
>> https://github.com/alobakin/linux/commit/9c25a22dfb00270372224721fed646965420323a
>>
>> Thanks,
>> Olek
Thanks,
Olek
Powered by blists - more mailing lists