Subject: Re: [PATCH net] net: tun: call napi_schedule_prep() to ensure we own a napi

From: Jakub Kicinski <[email-masked]>
Date: Tue, 8 Nov 2022 17:40:57 -0800

On Mon,  7 Nov 2022 18:00:11 +0000 Eric Dumazet wrote:
>  		if (unlikely(headlen > skb_headlen(skb))) {
> +			WARN_ON_ONCE(1);
> +			err = -ENOMEM;
>  			dev_core_stats_rx_dropped_inc(tun->dev);
> +napi_busy:
>  			napi_free_frags(&tfile->napi);
>  			rcu_read_unlock();
>  			mutex_unlock(&tfile->napi_mutex);
> -			WARN_ON(1);
> -			return -ENOMEM;
> +			return err;
>  		}
>  
> -		local_bh_disable();
> -		napi_gro_frags(&tfile->napi);
> -		napi_complete(&tfile->napi);
> -		local_bh_enable();
> +		if (likely(napi_schedule_prep(&tfile->napi))) {
> +			local_bh_disable();
> +			napi_gro_frags(&tfile->napi);
> +			napi_complete(&tfile->napi);
> +			local_bh_enable();
> +		} else {
> +			err = -EBUSY;
> +			goto napi_busy;

This can only hit if someone else is trying to detach / napi_disable()
at the same time?

> +		}