Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 287907
b: refs/heads/master
c: 971316f
h: refs/heads/master
i:
  287905: 69eed9b
  287903: 2193b1e
v: v3
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Feb 24, 2012
1 parent 7871c28 commit b84abdf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d80e731ecab420ddcb79ee9d0ac427acbc187b4b
refs/heads/master: 971316f0503a5c50633d07b83b6db2f15a3a5b00
30 changes: 27 additions & 3 deletions trunk/fs/eventpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ static inline int ep_is_linked(struct list_head *p)
return !list_empty(p);
}

static inline struct eppoll_entry *ep_pwq_from_wait(wait_queue_t *p)
{
return container_of(p, struct eppoll_entry, wait);
}

/* Get the "struct epitem" from a wait queue pointer */
static inline struct epitem *ep_item_from_wait(wait_queue_t *p)
{
Expand Down Expand Up @@ -467,6 +472,18 @@ static void ep_poll_safewake(wait_queue_head_t *wq)
put_cpu();
}

static void ep_remove_wait_queue(struct eppoll_entry *pwq)
{
wait_queue_head_t *whead;

rcu_read_lock();
/* If it is cleared by POLLFREE, it should be rcu-safe */
whead = rcu_dereference(pwq->whead);
if (whead)
remove_wait_queue(whead, &pwq->wait);
rcu_read_unlock();
}

/*
* This function unregisters poll callbacks from the associated file
* descriptor. Must be called with "mtx" held (or "epmutex" if called from
Expand All @@ -481,7 +498,7 @@ static void ep_unregister_pollwait(struct eventpoll *ep, struct epitem *epi)
pwq = list_first_entry(lsthead, struct eppoll_entry, llink);

list_del(&pwq->llink);
remove_wait_queue(pwq->whead, &pwq->wait);
ep_remove_wait_queue(pwq);
kmem_cache_free(pwq_cache, pwq);
}
}
Expand Down Expand Up @@ -842,9 +859,16 @@ static int ep_poll_callback(wait_queue_t *wait, unsigned mode, int sync, void *k
struct epitem *epi = ep_item_from_wait(wait);
struct eventpoll *ep = epi->ep;

/* the caller holds eppoll_entry->whead->lock */
if ((unsigned long)key & POLLFREE)
if ((unsigned long)key & POLLFREE) {
ep_pwq_from_wait(wait)->whead = NULL;
/*
* whead = NULL above can race with ep_remove_wait_queue()
* which can do another remove_wait_queue() after us, so we
* can't use __remove_wait_queue(). whead->lock is held by
* the caller.
*/
list_del_init(&wait->task_list);
}

spin_lock_irqsave(&ep->lock, flags);

Expand Down
6 changes: 5 additions & 1 deletion trunk/fs/signalfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
void signalfd_cleanup(struct sighand_struct *sighand)
{
wait_queue_head_t *wqh = &sighand->signalfd_wqh;

/*
* The lockless check can race with remove_wait_queue() in progress,
* but in this case its caller should run under rcu_read_lock() and
* sighand_cachep is SLAB_DESTROY_BY_RCU, we can safely return.
*/
if (likely(!waitqueue_active(wqh)))
return;

Expand Down

0 comments on commit b84abdf

Please sign in to comment.