* [PATCH 4/6] [2.6.29] epoll: remove unnecessary xchg
@ 2009-02-24 17:27 Tony Battersby
0 siblings, 0 replies; only message in thread
From: Tony Battersby @ 2009-02-24 17:27 UTC (permalink / raw)
To: Andrew Morton, Davide Libenzi; +Cc: Jonathan Corbet, linux-kernel
xchg in ep_unregister_pollwait() is unnecessary because it is protected
by either epmutex or ep->mtx (the same protection as ep_remove()).
If xchg wasn't unnecessary, it would be insufficient to protect against
problems. If multiple concurrent calls to ep_unregister_pollwait()
were possible, then a second caller that returns without doing anything
because nwait == 0 could return before the waitqueues are removed
by the first caller, which looks like it could lead to problematic
races with ep_poll_callback(). So remove xchg and add comments about
the locking.
Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
---
This patch is against 2.6.29-rc6; however, it doesn't need to go
into 2.6.29. Use the -mm version instead if applying after the other
patches in -mm.
--- a/fs/eventpoll.c 2009-02-20 16:50:16.000000000 -0500
+++ b/fs/eventpoll.c 2009-02-20 16:53:26.000000000 -0500
@@ -375,27 +375,21 @@ out_unlock:
}
/*
- * This function unregister poll callbacks from the associated file descriptor.
- * Since this must be called without holding "ep->lock" the atomic exchange trick
- * will protect us from multiple unregister.
+ * This function unregisters poll callbacks from the associated file
+ * descriptor. Must be called with "mtx" held (or "epmutex" if called from
+ * ep_free).
*/
static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *epi)
{
- int nwait;
struct list_head *lsthead = &epi->pwqlist;
struct eppoll_entry *pwq;
- /* This is called without locks, so we need the atomic exchange */
- nwait = xchg(&epi->nwait, 0);
+ while (!list_empty(lsthead)) {
+ pwq = list_first_entry(lsthead, struct eppoll_entry, llink);
- if (nwait) {
- while (!list_empty(lsthead)) {
- pwq = list_first_entry(lsthead, struct eppoll_entry, llink);
-
- list_del_init(&pwq->llink);
- remove_wait_queue(pwq->whead, &pwq->wait);
- kmem_cache_free(pwq_cache, pwq);
- }
+ list_del(&pwq->llink);
+ remove_wait_queue(pwq->whead, &pwq->wait);
+ kmem_cache_free(pwq_cache, pwq);
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-02-24 17:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-24 17:27 [PATCH 4/6] [2.6.29] epoll: remove unnecessary xchg Tony Battersby
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox