* [PATCH 2/6] [-mm] epoll: don't use current in irq context
@ 2009-02-24 17:28 Tony Battersby
2009-02-27 22:08 ` Davide Libenzi
0 siblings, 1 reply; 2+ messages in thread
From: Tony Battersby @ 2009-02-24 17:28 UTC (permalink / raw)
To: Andrew Morton, Davide Libenzi; +Cc: Jonathan Corbet, linux-kernel
ep_call_nested() (formerly 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 <tonyb@cybernetics.com>
---
This patch is against the current -mm tree, and might not apply
to 2.6.29. Since this patch probably won't go into 2.6.29, you may
apply this version of the patch after the other patches in -mm.
--- a/fs/eventpoll.c 2009-02-23 13:13:33.000000000 -0500
+++ b/fs/eventpoll.c 2009-02-23 13:17:46.000000000 -0500
@@ -97,8 +97,8 @@ struct epoll_filefd {
*/
struct nested_call_node {
struct list_head llink;
- struct task_struct *task;
void *cookie;
+ int cpu;
};
/*
@@ -327,7 +327,7 @@ static int ep_call_nested(struct nested_
{
int error, call_nests = 0;
unsigned long flags;
- struct task_struct *this_task = current;
+ int this_cpu = get_cpu();
struct list_head *lsthead = &ncalls->tasks_call_list;
struct nested_call_node *tncur;
struct nested_call_node tnode;
@@ -340,20 +340,19 @@ static int ep_call_nested(struct nested_
* very much limited.
*/
list_for_each_entry(tncur, lsthead, llink) {
- if (tncur->task == this_task &&
+ if (tncur->cpu == this_cpu &&
(tncur->cookie == cookie || ++call_nests > max_nests)) {
/*
* Ops ... loop detected or maximum nest level reached.
* We abort this wake by breaking the cycle itself.
*/
- spin_unlock_irqrestore(&ncalls->lock, flags);
-
- return -1;
+ error = -1;
+ goto out_unlock;
}
}
/* Add the current task and cookie to the list */
- tnode.task = this_task;
+ tnode.cpu = this_cpu;
tnode.cookie = cookie;
list_add(&tnode.llink, lsthead);
@@ -365,8 +364,10 @@ static int ep_call_nested(struct nested_
/* Remove the current task from the list */
spin_lock_irqsave(&ncalls->lock, flags);
list_del(&tnode.llink);
+ out_unlock:
spin_unlock_irqrestore(&ncalls->lock, flags);
+ put_cpu();
return error;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/6] [-mm] epoll: don't use current in irq context
2009-02-24 17:28 [PATCH 2/6] [-mm] epoll: don't use current in irq context Tony Battersby
@ 2009-02-27 22:08 ` Davide Libenzi
0 siblings, 0 replies; 2+ messages in thread
From: Davide Libenzi @ 2009-02-27 22:08 UTC (permalink / raw)
To: Tony Battersby; +Cc: Andrew Morton, Jonathan Corbet, Linux Kernel Mailing List
On Tue, 24 Feb 2009, Tony Battersby wrote:
> ep_call_nested() (formerly 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.
Oh, I forgot about this one ...
We're not actually dereferencing anything in current, by using it as a
cookie. But yes, getting the CPU is better, even at preemption expenses.
Thank you for your report Tony.
Acked-by: Davide Libenzi <davidel@xmailserver.org>
- Davide
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-27 22:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-24 17:28 [PATCH 2/6] [-mm] epoll: don't use current in irq context Tony Battersby
2009-02-27 22:08 ` Davide Libenzi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®