* Can request_irq be called under spinlock?
@ 2009-02-12 20:08 Jeremy Fitzhardinge
2009-02-12 22:28 ` Thomas Gleixner
0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Fitzhardinge @ 2009-02-12 20:08 UTC (permalink / raw)
To: Yinghai Lu
Cc: Ingo Molnar, the arch/x86 maintainers, Linux Kernel Mailing List
Relatively recently, I've started seeing this report from my code:
BUG: sleeping function called from invalid context at /home/jeremy/git/linux-2.6/mm/slab.c:2982
in_atomic(): 1, irqs_disabled(): 1, pid: 2249, name: xenstored
Pid: 2249, comm: xenstored Not tainted 2.6.29-rc4-tip #22
Call Trace:
[<ffffffff80233e5d>] __might_sleep+0x113/0x115
[<ffffffff802a6f8c>] __kmalloc+0x67/0xe2
[<ffffffff802ebc85>] __proc_create+0x89/0x127
[<ffffffff803f1c5f>] ? bind_evtchn_to_cpu+0x4f/0xa0
[<ffffffff802ec0ad>] proc_mkdir_mode+0x2e/0x57
[<ffffffff802ec0ec>] proc_mkdir+0x16/0x18
[<ffffffff80270d99>] register_irq_proc+0x74/0xcf
[<ffffffff8026f5ab>] __setup_irq+0x19b/0x200
[<ffffffff8026f6e7>] request_irq+0xd7/0x100
[<ffffffff803f7d8e>] ? evtchn_interrupt+0x0/0xc1
[<ffffffff803f7d8e>] ? evtchn_interrupt+0x0/0xc1
[<ffffffff803f2856>] bind_evtchn_to_irqhandler+0x3d/0x5f
[<ffffffff803f7c8b>] evtchn_bind_to_user+0x54/0x72
[<ffffffff803f81cc>] evtchn_ioctl+0x180/0x39c
[<ffffffff802a8592>] ? __dentry_open+0x1a4/0x2a2
[<ffffffff802a9513>] ? nameidata_to_filp+0x46/0x57
[<ffffffff803f02ed>] ? pnpacpi_parse_allocated_resource+0x94/0x9b
[<ffffffff8020e6d9>] ? xen_force_evtchn_callback+0xd/0xf
[<ffffffff802b5f06>] vfs_ioctl+0x2f/0x7c
[<ffffffff802b63fe>] do_vfs_ioctl+0x4ab/0x503
[<ffffffff802aad0e>] ? __fput+0x1a1/0x1ae
[<ffffffff802b649d>] sys_ioctl+0x47/0x6a
[<ffffffff80212522>] system_call_fastpath+0x16/0x1b
because I'm calling request_irq() while holding a spinlock.
request_irq() itself looks like its OK with that (it allocates with
GFP_ATOMIC, for example), but __setup_irq -> register_irq_proc ->
proc_mkdir ends up doing a GFP_KERNEL allocation, which leads to this
message.
I can rearrange this code to not do the call under lock, but it seems
like there was an unintentional change in API here.
Thanks,
J
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can request_irq be called under spinlock?
2009-02-12 20:08 Can request_irq be called under spinlock? Jeremy Fitzhardinge
@ 2009-02-12 22:28 ` Thomas Gleixner
2009-02-12 23:35 ` Jeremy Fitzhardinge
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Gleixner @ 2009-02-12 22:28 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Yinghai Lu, Ingo Molnar, the arch/x86 maintainers,
Linux Kernel Mailing List
On Thu, 12 Feb 2009, Jeremy Fitzhardinge wrote:
> Relatively recently, I've started seeing this report from my code:
>
> BUG: sleeping function called from invalid context at
> /home/jeremy/git/linux-2.6/mm/slab.c:2982
> in_atomic(): 1, irqs_disabled(): 1, pid: 2249, name: xenstored
> Pid: 2249, comm: xenstored Not tainted 2.6.29-rc4-tip #22
> Call Trace:
> [<ffffffff80233e5d>] __might_sleep+0x113/0x115
> [<ffffffff802a6f8c>] __kmalloc+0x67/0xe2
> [<ffffffff802ebc85>] __proc_create+0x89/0x127
> [<ffffffff803f1c5f>] ? bind_evtchn_to_cpu+0x4f/0xa0
> [<ffffffff802ec0ad>] proc_mkdir_mode+0x2e/0x57
> [<ffffffff802ec0ec>] proc_mkdir+0x16/0x18
> [<ffffffff80270d99>] register_irq_proc+0x74/0xcf
> [<ffffffff8026f5ab>] __setup_irq+0x19b/0x200
> [<ffffffff8026f6e7>] request_irq+0xd7/0x100
> [<ffffffff803f7d8e>] ? evtchn_interrupt+0x0/0xc1
> [<ffffffff803f7d8e>] ? evtchn_interrupt+0x0/0xc1
> [<ffffffff803f2856>] bind_evtchn_to_irqhandler+0x3d/0x5f
> [<ffffffff803f7c8b>] evtchn_bind_to_user+0x54/0x72
> [<ffffffff803f81cc>] evtchn_ioctl+0x180/0x39c
> [<ffffffff802a8592>] ? __dentry_open+0x1a4/0x2a2
> [<ffffffff802a9513>] ? nameidata_to_filp+0x46/0x57
> [<ffffffff803f02ed>] ? pnpacpi_parse_allocated_resource+0x94/0x9b
> [<ffffffff8020e6d9>] ? xen_force_evtchn_callback+0xd/0xf
> [<ffffffff802b5f06>] vfs_ioctl+0x2f/0x7c
> [<ffffffff802b63fe>] do_vfs_ioctl+0x4ab/0x503
> [<ffffffff802aad0e>] ? __fput+0x1a1/0x1ae
> [<ffffffff802b649d>] sys_ioctl+0x47/0x6a
> [<ffffffff80212522>] system_call_fastpath+0x16/0x1b
>
> because I'm calling request_irq() while holding a spinlock.
>
> request_irq() itself looks like its OK with that (it allocates with
> GFP_ATOMIC, for example), but __setup_irq -> register_irq_proc -> proc_mkdir
> ends up doing a GFP_KERNEL allocation, which leads to this message.
>
> I can rearrange this code to not do the call under lock, but it seems like
> there was an unintentional change in API here.
I dont think that proc_mkdir conventions have changed
recently. According to git blame fs/proc/generic.c:
^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 580) ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
Thanks,
tglx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can request_irq be called under spinlock?
2009-02-12 22:28 ` Thomas Gleixner
@ 2009-02-12 23:35 ` Jeremy Fitzhardinge
2009-02-13 3:38 ` Johannes Weiner
2009-02-13 9:23 ` Thomas Gleixner
0 siblings, 2 replies; 6+ messages in thread
From: Jeremy Fitzhardinge @ 2009-02-12 23:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Yinghai Lu, Ingo Molnar, the arch/x86 maintainers,
Linux Kernel Mailing List
Thomas Gleixner wrote:
> I dont think that proc_mkdir conventions have changed
> recently. According to git blame fs/proc/generic.c:
>
> ^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 580) ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
>
>
I think its new that request_irq ends up calling proc_mkdir though. But
its moot now anyway; I cleaned up that code, and don't call request_irq
under spinlock any more.
J
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can request_irq be called under spinlock?
2009-02-12 23:35 ` Jeremy Fitzhardinge
@ 2009-02-13 3:38 ` Johannes Weiner
2009-02-13 9:52 ` Ingo Molnar
2009-02-13 9:23 ` Thomas Gleixner
1 sibling, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2009-02-13 3:38 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Thomas Gleixner, Yinghai Lu, Ingo Molnar,
the arch/x86 maintainers, Linux Kernel Mailing List
On Thu, Feb 12, 2009 at 03:35:25PM -0800, Jeremy Fitzhardinge wrote:
> Thomas Gleixner wrote:
> >I dont think that proc_mkdir conventions have changed
> >recently. According to git blame fs/proc/generic.c:
> >
> >^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 580) ent =
> >kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
> >
> >
>
> I think its new that request_irq ends up calling proc_mkdir though. But
> its moot now anyway; I cleaned up that code, and don't call request_irq
> under spinlock any more.
Still, the attached could be of use, no?
Hannes
---
From: Johannes Weiner <hannes@cmpxchg.org>
Subject: irq: use GFP_KERNEL for action allocation in request_irq()
request_irq() calls into proc code via __setup_irq() which is not safe
in an atomic context, so request_irq() can itself use the more
reliable GFP_KERNEL allocation for the action descriptor.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 291f036..0f2b3b6 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -709,7 +709,7 @@ int request_irq(unsigned int irq, irq_handler_t handler,
if (!handler)
return -EINVAL;
- action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
+ action = kmalloc(sizeof(struct irqaction), GFP_KERNEL);
if (!action)
return -ENOMEM;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: Can request_irq be called under spinlock?
2009-02-12 23:35 ` Jeremy Fitzhardinge
2009-02-13 3:38 ` Johannes Weiner
@ 2009-02-13 9:23 ` Thomas Gleixner
1 sibling, 0 replies; 6+ messages in thread
From: Thomas Gleixner @ 2009-02-13 9:23 UTC (permalink / raw)
To: Jeremy Fitzhardinge
Cc: Yinghai Lu, Ingo Molnar, the arch/x86 maintainers,
Linux Kernel Mailing List
On Thu, 12 Feb 2009, Jeremy Fitzhardinge wrote:
> Thomas Gleixner wrote:
> > I dont think that proc_mkdir conventions have changed
> > recently. According to git blame fs/proc/generic.c:
> >
> > ^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 580) ent =
> > kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
> >
> >
>
> I think its new that request_irq ends up calling proc_mkdir though. But its
> moot now anyway; I cleaned up that code, and don't call request_irq under
> spinlock any more.
Just checked. The register_irq_proc() and register_handler_proc()
calls in request/setup_irq() have the same time stamp in git :)
Thanks,
tglx
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can request_irq be called under spinlock?
2009-02-13 3:38 ` Johannes Weiner
@ 2009-02-13 9:52 ` Ingo Molnar
0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-02-13 9:52 UTC (permalink / raw)
To: Johannes Weiner
Cc: Jeremy Fitzhardinge, Thomas Gleixner, Yinghai Lu,
the arch/x86 maintainers, Linux Kernel Mailing List
* Johannes Weiner <hannes@cmpxchg.org> wrote:
> From: Johannes Weiner <hannes@cmpxchg.org>
> Subject: irq: use GFP_KERNEL for action allocation in request_irq()
>
> request_irq() calls into proc code via __setup_irq() which is not safe
> in an atomic context, so request_irq() can itself use the more
> reliable GFP_KERNEL allocation for the action descriptor.
>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>
> diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
> index 291f036..0f2b3b6 100644
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -709,7 +709,7 @@ int request_irq(unsigned int irq, irq_handler_t handler,
> if (!handler)
> return -EINVAL;
>
> - action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
> + action = kmalloc(sizeof(struct irqaction), GFP_KERNEL);
> if (!action)
> return -ENOMEM;
Good catch - applied to tip:irq/genirq, thanks Johannes!
Ingo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-02-13 9:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-12 20:08 Can request_irq be called under spinlock? Jeremy Fitzhardinge
2009-02-12 22:28 ` Thomas Gleixner
2009-02-12 23:35 ` Jeremy Fitzhardinge
2009-02-13 3:38 ` Johannes Weiner
2009-02-13 9:52 ` Ingo Molnar
2009-02-13 9:23 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox