[PATCH] epoll: use RCU protect wakeup_source in epitem

From: Eric Wong
Date: Sun Mar 10 2013 - 07:50:34 EST


Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote:
> On Sun, 2013-03-10 at 01:11 +0000, Eric Wong wrote:
> >
> > static void ep_destroy_wakeup_source(struct epitem *epi)
> > {
> > - wakeup_source_unregister(epi->ws);
> > - epi->ws = NULL;
> > + struct wakeup_source *ws = epi->ws;
> > +
> > + rcu_assign_pointer(epi->ws, NULL);
>
> There is no need to use a memory barrier before setting epi->ws to NULL
>
> You should use RCU_POINTER_INIT()

Thanks for looking at this patch. Using RCU_POINTER_INIT in my
updated patch below.

> > + synchronize_rcu(); /* wait for ep_pm_stay_awake to finish */
>
> Wont this add a significant slowdown ?

Maybe, but this is a very rare code path (using EPOLL_CTL_MOD to remove
a wakeup source), and synchronize_rcu gets called later, too:

wakeup_source_unregister
wakeup_source_remove
synchronize_rcu

> > + wakeup_source_unregister(ws);
> > }
>
> Please add the following in your .config
>
> CONFIG_SPARSE_RCU_POINTER=y
>
> and try :
>
> make C=2 fs/eventpoll.o
>
> And fix all warnings ;)

Done.

---------------------------------8<------------------------------