[2.6.29] epoll: don't use current in irq context
PATCH 2/6 [2.6.29] epoll: don't use current in irq context
ep_poll_safewake() uses "current" to detect callback recursion, but it may be called from irq context where the use of current is generally frowned upon. It would be better to use get_cpu() and put_cpu() to detect the callback recursion.
Signed-off-by Tony Battersby <[email protected]>
---
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.
fs/eventpoll.c +10 -8
@@ -118,8 +118,8 @@ struct epoll_filefd {*/ struct wake_task_node {struct list_head llink; -struct task_struct *task;wait_queue_head_t *wq; +int cpu; };/*
@@ -335,7 +335,7 @@ static void ep_poll_safewake(struct poll {int wake_nests =0 ;unsigned long flags; -struct task_struct *this_task = current; +int this_cpu =get_cpu ();struct list_head *lsthead = &psw->wake_task_list;struct wake_task_node *tncur;struct wake_task_node tnode;
@@ -346,18 +346,18 @@ static void ep_poll_safewake(struct polllist_for_each_entry (tncur, lsthead, llink) {if (tncur->wq == wq || - (tncur->task == this_task && ++wake_nests >EP_MAX_POLLWAKE_NESTS )) { + (tncur->cpu == this_cpu && + ++wake_nests >EP_MAX_POLLWAKE_NESTS )) {/* * Ops ... loop detected or maximum nest level reached. * We abort this wake by breaking the cycle itself. */ -spin_unlock_irqrestore (&psw->lock, flags); -return ; + goto out_unlock; } }/* Add the current task to the list */ - tnode.task = this_task; + tnode.cpu = this_cpu; tnode.wq = wq;list_add (&tnode.llink, lsthead);
@@ -369,7 +369,9 @@ static void ep_poll_safewake(struct poll/* Remove the current task from the list */ spin_lock_irqsave (&psw->lock, flags);list_del (&tnode.llink); +out_unlock:spin_unlock_irqrestore (&psw->lock, flags); +put_cpu (); }/*
@@ -652,8 +654,8 @@ static int ep_poll_callback(wait_queue_tstruct epitem *epi =ep_item_from_wait (wait);struct eventpoll *ep = epi->ep; -DNPRINTK (3 , (KERN_INFO "[%p] eventpoll: poll_callback(%p) epi=%p ep=%p\n" , - current, epi->ffd.file, epi, ep)); +DNPRINTK (3 , (KERN_INFO "eventpoll: poll_callback(%p) epi=%p ep=%p\n" , + epi->ffd.file, epi, ep));spin_lock_irqsave (&ep->lock, flags);