From: Robert Hancock <hancockr@shaw.ca>
To: Roger Larsson <roger.larsson@e-gatan.se>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
Robert Love <rml@tech9.net>, Pavel Machek <pavel@ucw.cz>
Subject: Re: PROBLEM: in_atomic() misuse all over the place
Date: Tue, 27 Jan 2009 18:12:00 -0600 [thread overview]
Message-ID: <497FA2D0.1090605@shaw.ca> (raw)
In-Reply-To: <200901280010.37633.roger.larsson@e-gatan.se>
Roger Larsson wrote:
> (resent, non html)
>
> [1.] One line summary of the problem:
> in_atomic() is used to select path of execution, most likely to suppress
> warning logs when running a preemptive kernel.
>
> [2.] Full description of the problem/report:
>
> The problem is that in_atomic() only works on preemptive kernels...
>
> Result: preemptive kernel warns about a potential deadlock in all kernels,
> developer silence with the help of in_atomic()
> bug remains in SMP/UP kernels...
>
> [3.] Keywords (i.e., modules, networking, kernel):
> in_atomic(), preemptive, sleeping
>
> [4.] Kernel version (from /proc/version):
> 2.6.28.2 (review)
>
> [5.] Output of Oops..
>
> "sleeping function called from invalid context"
>
> [6.] A small shell script or example program which triggers the
> problem (if possible)
>
> Small example of the strange code I found is this
>
> file: include/net/sock.h
>
> static inline gfp_t gfp_any(void)
> {
> return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
> }
>
> // I can find no comment on why this strange code would be OK.
> // An it is in its turn used in several drivers...
>
> If the processor can get to this function while atomic in a preemptive kernel
> it will likely be able to get there in other kernels as well, especially SMP.
>
> It returns GFP_ATOMIC when being atomic in a preemptive kernel, allocating
> with that flag will not sleep. But calling this with another kernel will
> ALWAYS return GFP_KERNEL, and it may cause a sleeping allocate...
>
> Other places that I think misuse of in_atomic is Arch code, USB code, ...
>
> There are 77 uses of in_atomic directly (grep | wc)
> 36 in ./arch
> 23 in ./drivers
> 2 in ./sound/core/seq/seq_virmidi.c
> 1 in ./include/net/sock.h
> The remaining 15 are probably OK (kernel, mm/filemap)
>
> But the sock.h gfp_any() spreads further...
> 1 in ./Documentation
> 2 in ./drivers
> 9 in ./net
>
>
> Suggestion: should in_atomic() that by default return the safer 1 instead of
> the unsafe 0. And add an in_atomic_warn() with default of 0 to use where it is
> OK - like when deciding to log a warning.
I would think that the code that's using it for this purpose should be
changed to do things differently, such as by changing the functions
using it to make their caller pass in the proper GFP mask. I don't think
it was ever intended to be used to select allocation behavior like this,
only for debug warning checks and such.. Getting rid of in_atomic() and
creating a in_atomic_warn() that just raises a warning if called
atomically, might be the best long-term solution.
next prev parent reply other threads:[~2009-01-28 0:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-27 23:10 PROBLEM: in_atomic() misuse all over the place Roger Larsson
2009-01-28 0:12 ` Robert Hancock [this message]
2009-01-31 11:45 ` Joerg Roedel
2009-01-28 12:18 ` Andi Kleen
2009-01-31 0:03 ` Andrew Morton
2009-01-31 5:55 ` Andi Kleen
2009-01-31 5:49 ` Andrew Morton
2009-01-31 8:48 ` David Miller
2009-01-31 8:58 ` Andrew Morton
2009-02-04 16:17 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=497FA2D0.1090605@shaw.ca \
--to=hancockr@shaw.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pavel@ucw.cz \
--cc=rml@tech9.net \
--cc=roger.larsson@e-gatan.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox