lkml.org 
[lkml]   [2022]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH net 7/9] rxrpc: Fix I/O thread stop
Date
Hillf Danton <hdanton@sina.com> wrote:

> > @@ -478,13 +479,14 @@ int rxrpc_io_thread(void *data)
> > }
> >
> > set_current_state(TASK_INTERRUPTIBLE);
> > + should_stop = kthread_should_stop();
> > if (!skb_queue_empty(&local->rx_queue) ||
> > !list_empty(&local->call_attend_q)) {
> > __set_current_state(TASK_RUNNING);
> > continue;
> > }
> >
> > - if (kthread_should_stop())
> > + if (should_stop)
> > break;
> > schedule();
> > }
>
> At the second glance still fail to see the difference this change can
> make.

There is a window here:

if (!skb_queue_empty(&local->rx_queue) ...)
continue;
--->
if (kthread_should_stop())
break;

in which an event can happen that should be attended to. For instance the
AF_RXRPC socket being closed, aborting all its calls and stopping the kthread
by doing the final unuse on its rxrpc_local struct - in that order. The
window can be expanded by an interrupt or softirq handler running.

So once we've observed that we've been asked to stop, we need to check if
there's more work to be done and, if so, do that work first.

So by doing:

should_stop = kthread_should_stop();
if (!skb_queue_empty(&local->rx_queue) ...)
continue;
if (should_stop)
break;

we do all outstanding cleanup work before exiting the loop to stop the thread.

David

\
 
 \ /
  Last update: 2022-12-16 07:47    [W:0.136 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site