On Tue, 23 Feb 2021 15:41:30 -0800 Wei Wang wrote: > Currently, napi_thread_wait() checks for NAPI_STATE_SCHED bit to > determine if the kthread owns this napi and could call napi->poll() on > it. However, if socket busy poll is enabled, it is possible that the > busy poll thread grabs this SCHED bit (after the previous napi->poll() > invokes napi_complete_done() and clears SCHED bit) and tries to poll > on the same napi. > This patch tries to fix this race by adding a new bit > NAPI_STATE_SCHED_BUSY_POLL in napi->state. This bit gets set in > napi_busy_loop() togther with NAPI_STATE_SCHED, and gets cleared in > napi_complete_done() together with NAPI_STATE_SCHED. This helps > distinguish the ownership of the napi between kthread and the busy poll > thread, and prevents the kthread from polling on the napi when this napi > is still owned by the busy poll thread. > > Fixes: 29863d41bb6e ("net: implement threaded-able napi poll loop support") > Reported-by: Martin Zaharinov <micro...@gmail.com> > Suggested-by: Alexander Duyck <alexanderdu...@fb.com> > Reviewed-by: Alexander Duyck <alexanderdu...@fb.com> > Reviewed-by: Eric Dumazet <eduma...@google.come>
AFAIU sched bit controls the ownership of the poll_list. Can we please add a poll_list for the thread and make sure the thread polls based on the list? IMO that's far clearer than defining a forest of ownership state bits. I think with just the right (wrong?) timing this patch will still not protect against disabling the NAPI.