* inappropriate use of in_atomic()
@ 2005-03-11 4:40 Andrew Morton
2005-03-11 6:25 ` Stephen Rothwell
[not found] ` <20050310204006.48286d17.akpm-3NddpPZAyC0@public.gmane.org>
0 siblings, 2 replies; 7+ messages in thread
From: Andrew Morton @ 2005-03-11 4:40 UTC (permalink / raw)
To: Paul Mackerras, Jean Tourrilhes, javier, linux-fbdev-devel,
acpi-devel, linux1394-devel, Roland Dreier
Cc: linux-kernel
in_atomic() is not a reliable indication of whether it is currently safe
to call schedule().
This is because the lockdepth beancounting which in_atomic() uses is only
accumulated if CONFIG_PREEMPT=y. in_atomic() will return false inside
spinlocks if CONFIG_PREEMPT=n.
Consequently the use of in_atomic() in the below files is probably
deadlocky if CONFIG_PREEMPT=n:
arch/ppc64/kernel/viopath.c
drivers/net/irda/sir_kthread.c
drivers/net/wireless/airo.c
drivers/video/amba-clcd.c
drivers/acpi/osl.c
drivers/ieee1394/ieee1394_transactions.c
drivers/infiniband/core/mad.c
Note that the same beancounting is used for the "scheduling while atomic"
warning, so if the code calls schedule with locks held, we won't get a
warning. Both are tied to CONFIG_PREEMPT=y.
The kernel provides no reliable runtime way of detecting whether or not it
is safe to call schedule().
Can we please find ways to change the above code to not use in_atomic()?
Then we can whack #ifndef MODULE around its definition to reduce
reoccurrences. Will probably rename it to something more scary as well.
Thanks.
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: inappropriate use of in_atomic() 2005-03-11 4:40 inappropriate use of in_atomic() Andrew Morton @ 2005-03-11 6:25 ` Stephen Rothwell [not found] ` <20050310204006.48286d17.akpm-3NddpPZAyC0@public.gmane.org> 1 sibling, 0 replies; 7+ messages in thread From: Stephen Rothwell @ 2005-03-11 6:25 UTC (permalink / raw) To: Andrew Morton Cc: jt, javier, roland, linux-kernel, acpi-devel, paulus, linuxppc64-dev, linux-fbdev-devel, linux1394-devel [-- Attachment #1.1: Type: text/plain, Size: 1932 bytes --] Hi Andrew, On Thu, 10 Mar 2005 20:40:06 -0800 Andrew Morton <akpm@osdl.org> wrote: > > in_atomic() is not a reliable indication of whether it is currently safe > to call schedule(). > > arch/ppc64/kernel/viopath.c in_atomic() in viopath.c was just used to determine if we had initialised enough to be able to wait in a semaphore (i.e. schedule). Thus it can be replaced now with checking system_state for SYSTEM_RUNNING. Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Test booted on iSeries (which is the only place it is used). -- Cheers, Stephen Rothwell sfr@canb.auug.org.au http://www.canb.auug.org.au/~sfr/ diff -ruNp linus/arch/ppc64/kernel/viopath.c linus-in_atomic/arch/ppc64/kernel/viopath.c --- linus/arch/ppc64/kernel/viopath.c 2005-01-22 06:09:01.000000000 +1100 +++ linus-in_atomic/arch/ppc64/kernel/viopath.c 2005-03-11 17:19:45.000000000 +1100 @@ -79,7 +79,7 @@ static void handleMonitorEvent(struct Hv /* * We use this structure to handle asynchronous responses. The caller * blocks on the semaphore and the handler posts the semaphore. However, - * if in_atomic() is true in the caller, then wait_atomic is used ... + * if system_state is not SYSTEM_RUNNING, then wait_atomic is used ... */ struct doneAllocParms_t { struct semaphore *sem; @@ -465,7 +465,7 @@ static int allocateEvents(HvLpIndex remo DECLARE_MUTEX_LOCKED(Semaphore); atomic_t wait_atomic; - if (in_atomic()) { + if (system_state != SYSTEM_RUNNING) { parms.used_wait_atomic = 1; atomic_set(&wait_atomic, 1); parms.wait_atomic = &wait_atomic; @@ -475,7 +475,7 @@ static int allocateEvents(HvLpIndex remo } mf_allocate_lp_events(remoteLp, HvLpEvent_Type_VirtualIo, 250, /* It would be nice to put a real number here! */ numEvents, &viopath_donealloc, &parms); - if (in_atomic()) { + if (system_state != SYSTEM_RUNNING) { while (atomic_read(&wait_atomic)) mb(); } else [-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --] [-- Attachment #2: Type: text/plain, Size: 161 bytes --] _______________________________________________ Linuxppc64-dev mailing list Linuxppc64-dev@ozlabs.org https://ozlabs.org/cgi-bin/mailman/listinfo/linuxppc64-dev ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20050310204006.48286d17.akpm-3NddpPZAyC0@public.gmane.org>]
* Re: inappropriate use of in_atomic() [not found] ` <20050310204006.48286d17.akpm-3NddpPZAyC0@public.gmane.org> @ 2005-03-11 9:11 ` Jan Kasprzak 2005-03-11 9:46 ` [ACPI] " Andrew Morton 0 siblings, 1 reply; 7+ messages in thread From: Jan Kasprzak @ 2005-03-11 9:11 UTC (permalink / raw) To: Andrew Morton Cc: Paul Mackerras, Jean Tourrilhes, javier-UOFnMJzu7Pp1eVVWpSVkNqxOck334EZe, linux-fbdev-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, linux1394-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Roland Dreier, linux-kernel-u79uwXL29TY76Z2rM5mHXA Andrew Morton wrote: : : in_atomic() is not a reliable indication of whether it is currently safe : to call schedule(). : : This is because the lockdepth beancounting which in_atomic() uses is only : accumulated if CONFIG_PREEMPT=y. in_atomic() will return false inside : spinlocks if CONFIG_PREEMPT=n. : : Consequently the use of in_atomic() in the below files is probably : deadlocky if CONFIG_PREEMPT=n: [...] : drivers/acpi/osl.c [...] This may be the cause of http://bugme.osdl.org/show_bug.cgi?id=4150 - I have recently verified that the problem described in bug #4150 disappears when CONFIG_PREEMPT=y is used. -Yenya -- | Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> | | GPG: ID 1024/D3498839 Fingerprint 0D99A7FB206605D7 8B35FCDE05B18A5E | | http://www.fi.muni.cz/~kas/ Czech Linux Homepage: http://www.linux.cz/ | > Whatever the Java applications and desktop dances may lead to, Unix will < > still be pushing the packets around for a quite a while. --Rob Pike < ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ACPI] inappropriate use of in_atomic() 2005-03-11 9:11 ` Jan Kasprzak @ 2005-03-11 9:46 ` Andrew Morton [not found] ` <20050311014601.166ae43d.akpm-3NddpPZAyC0@public.gmane.org> 0 siblings, 1 reply; 7+ messages in thread From: Andrew Morton @ 2005-03-11 9:46 UTC (permalink / raw) To: Jan Kasprzak Cc: paulus, jt, javier, linux-fbdev-devel, acpi-devel, linux1394-devel, roland, linux-kernel Jan Kasprzak <kas@fi.muni.cz> wrote: > > This may be the cause of > > http://bugme.osdl.org/show_bug.cgi?id=4150 Looks that way, yes. ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <20050311014601.166ae43d.akpm-3NddpPZAyC0@public.gmane.org>]
* Re: [Linux-fbdev-devel] Re: inappropriate use of in_atomic() [not found] ` <20050311014601.166ae43d.akpm-3NddpPZAyC0@public.gmane.org> @ 2005-03-11 12:26 ` Benjamin Herrenschmidt 2005-03-12 0:13 ` [Linux-fbdev-devel] Re: [ACPI] " Andrew Morton 0 siblings, 1 reply; 7+ messages in thread From: Benjamin Herrenschmidt @ 2005-03-11 12:26 UTC (permalink / raw) To: Linux Fbdev development list Cc: Jan Kasprzak, Paul Mackerras, jt-yAE0UhLNZJawPNPzzlOzwdBPR1lH4CV8, javier-UOFnMJzu7Pp1eVVWpSVkNqxOck334EZe, acpi-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, linux1394-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, roland-nF87da4h5whBDgjK7y7TUQ, Linux Kernel list On Fri, 2005-03-11 at 01:46 -0800, Andrew Morton wrote: > Jan Kasprzak <kas-0hYGf3jDe+XrBKCeMvbIDA@public.gmane.org> wrote: > > > > This may be the cause of > > > > http://bugme.osdl.org/show_bug.cgi?id=4150 > > Looks that way, yes. Note that it would be interesting to fix that (I mean the reliability of is_atomic() or an alternative). I agree it's quite bad to rely on that in practice, but there are a few corner cases where it's useful (like oops handling in fbdev's etc...) Ben. ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Linux-fbdev-devel] Re: [ACPI] inappropriate use of in_atomic() 2005-03-11 12:26 ` [Linux-fbdev-devel] " Benjamin Herrenschmidt @ 2005-03-12 0:13 ` Andrew Morton 2005-03-12 0:22 ` Benjamin Herrenschmidt 0 siblings, 1 reply; 7+ messages in thread From: Andrew Morton @ 2005-03-12 0:13 UTC (permalink / raw) To: Benjamin Herrenschmidt Cc: linux-fbdev-devel, kas, paulus, jt, javier, acpi-devel, linux1394-devel, roland, linux-kernel (where'd my cc go?) Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote: > > On Fri, 2005-03-11 at 01:46 -0800, Andrew Morton wrote: > > Jan Kasprzak <kas@fi.muni.cz> wrote: > > > > > > This may be the cause of > > > > > > http://bugme.osdl.org/show_bug.cgi?id=4150 > > > > Looks that way, yes. > > Note that it would be interesting to fix that (I mean the reliability of > is_atomic() or an alternative). I agree it's quite bad to rely on that > in practice, but there are a few corner cases where it's useful (like > oops handling in fbdev's etc...) > That would require that we increment current->something on every spin/read/write_lock and decrement it in unlock, even with !CONFIG_PREEMPT. iirc, Anton added an option to do that to the ppc64 build, decoupled from CONFIG_PREEMPT (which ppc64 doesn't support). But it's an appreciable amount of overhead. ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Re: [ACPI] inappropriate use of in_atomic() 2005-03-12 0:13 ` [Linux-fbdev-devel] Re: [ACPI] " Andrew Morton @ 2005-03-12 0:22 ` Benjamin Herrenschmidt 0 siblings, 0 replies; 7+ messages in thread From: Benjamin Herrenschmidt @ 2005-03-12 0:22 UTC (permalink / raw) To: Andrew Morton Cc: Linux Fbdev development list, kas, Paul Mackerras, jt, javier, acpi-devel, linux1394-devel, roland, Linux Kernel list On Fri, 2005-03-11 at 16:13 -0800, Andrew Morton wrote: > (where'd my cc go?) > > Benjamin Herrenschmidt <benh@kernel.crashing.org> wrote: > > > > On Fri, 2005-03-11 at 01:46 -0800, Andrew Morton wrote: > > > Jan Kasprzak <kas@fi.muni.cz> wrote: > > > > > > > > This may be the cause of > > > > > > > > http://bugme.osdl.org/show_bug.cgi?id=4150 > > > > > > Looks that way, yes. > > > > Note that it would be interesting to fix that (I mean the reliability of > > is_atomic() or an alternative). I agree it's quite bad to rely on that > > in practice, but there are a few corner cases where it's useful (like > > oops handling in fbdev's etc...) > > > > That would require that we increment current->something on every > spin/read/write_lock and decrement it in unlock, even with !CONFIG_PREEMPT. > > iirc, Anton added an option to do that to the ppc64 build, decoupled from > CONFIG_PREEMPT (which ppc64 doesn't support). ppc64 _does_ support PREEMPT nowadays :) > But it's an appreciable amount of overhead. -- Benjamin Herrenschmidt <benh@kernel.crashing.org> ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-03-12 0:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-11 4:40 inappropriate use of in_atomic() Andrew Morton
2005-03-11 6:25 ` Stephen Rothwell
[not found] ` <20050310204006.48286d17.akpm-3NddpPZAyC0@public.gmane.org>
2005-03-11 9:11 ` Jan Kasprzak
2005-03-11 9:46 ` [ACPI] " Andrew Morton
[not found] ` <20050311014601.166ae43d.akpm-3NddpPZAyC0@public.gmane.org>
2005-03-11 12:26 ` [Linux-fbdev-devel] " Benjamin Herrenschmidt
2005-03-12 0:13 ` [Linux-fbdev-devel] Re: [ACPI] " Andrew Morton
2005-03-12 0:22 ` Benjamin Herrenschmidt
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).