Re: [PATCH net-net] tun: Assign missing bpf_net_context.

From: Breno Leitao
Date: Thu Sep 12 2024 - 10:41:09 EST


On Thu, Sep 12, 2024 at 04:30:29PM +0200, Sebastian Andrzej Siewior wrote:
> On 2024-09-12 07:19:54 [-0700], Breno Leitao wrote:
> > Hello Vadim,
> >
> > On Thu, Sep 12, 2024 at 02:32:55PM +0100, Vadim Fedorenko wrote:
> > > On 12/09/2024 14:17, Breno Leitao wrote:
> > > > @@ -72,6 +73,7 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev)
> > > > struct net_device *peer;
> > > > int len = skb->len;
> > > > + bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx);
> > > > rcu_read_lock();
> > >
> > > Hi Breno,
> > >
> > > looks like bpf_net_ctx should be set under rcu read lock...
> >
> > Why exactly?
> >
> > I saw in some examples where bpf_net_ctx_set() was set inside the
> > rcu_read_lock(), but, I was not able to come up with justification to do
> > the same. Would you mind elaborating why this might be needed inside the
> > lock?
>
> It might have been done due to simpler nesting or other reasons but
> there is no requirement to do this under RCU protection. The assignment
> and cleanup is always performed task-local.

Thanks. I will keep it out of the RCU lock then, as in the patch above.

--breno