* [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule
@ 2017-11-03 19:08 Yang Shi
2017-11-03 19:41 ` Joe Perches
2017-11-06 13:52 ` Michal Hocko
0 siblings, 2 replies; 5+ messages in thread
From: Yang Shi @ 2017-11-03 19:08 UTC (permalink / raw)
To: apw, joe; +Cc: akpm, Yang Shi, linux-kernel
checkpatch.pl still reports the below in_atomic warning:
WARNING: use of in_atomic() is incorrect outside core kernel code
+ if (in_atomic())
But, in_atomic() has been used outside kernel dir for a long time, and
even drivers. So, remove the obsolete rule even though they can be
ignored.
Signed-off-by: Yang Shi <yang.s@alibaba-inc.com>
CC: Andrew Morton <akpm@linux-foundation.org>
---
Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway
it sounds not make sense to keep invalid rule.
scripts/checkpatch.pl | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8b80bac..e8cf94f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6231,17 +6231,6 @@ sub process {
"Using $1 should generally have parentheses around the comparison\n" . $herecurr);
}
-# whine mightly about in_atomic
- if ($line =~ /\bin_atomic\s*\(/) {
- if ($realfile =~ m@^drivers/@) {
- ERROR("IN_ATOMIC",
- "do not use in_atomic in drivers\n" . $herecurr);
- } elsif ($realfile !~ m@^kernel/@) {
- WARN("IN_ATOMIC",
- "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
- }
- }
-
# whine about ACCESS_ONCE
if ($^V && $^V ge 5.10.0 &&
$line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule
2017-11-03 19:08 [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule Yang Shi
@ 2017-11-03 19:41 ` Joe Perches
2017-11-03 22:41 ` Yang Shi
2017-11-06 13:52 ` Michal Hocko
1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2017-11-03 19:41 UTC (permalink / raw)
To: Yang Shi, apw, Jonathan Corbet; +Cc: akpm, linux-kernel
On Sat, 2017-11-04 at 03:08 +0800, Yang Shi wrote:
> checkpatch.pl still reports the below in_atomic warning:
>
> WARNING: use of in_atomic() is incorrect outside core kernel code
> + if (in_atomic())
>
> But, in_atomic() has been used outside kernel dir for a long time, and
> even drivers. So, remove the obsolete rule even though they can be
> ignored.
Removing in_atomic() from checkpatch does not make sense
without also updating include/linux/preempt.h
Jonathon Corbet added this comment in
commit 8c703d35fa91911dd92a18c31a718853f483ad80
Author: Jonathan Corbet <corbet@lwn.net>
Date: Fri Mar 28 14:15:49 2008 -0700
in_atomic(): document why it is unsuitable for general use
Discourage people from inappropriately using in_atomic()
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
include/linux/hardirq.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index 49829988bfa0..897f723bd222 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -72,6 +72,13 @@
#define in_softirq() (softirq_count())
#define in_interrupt() (irq_count())
+/*
+ * Are we running in atomic context? WARNING: this macro cannot
+ * always detect atomic context; in particular, it cannot know about
+ * held spinlocks in non-preemptible kernels. Thus it should not be
+ * used in the general case to determine whether sleeping is possible.
+ * Do not use in_atomic() in driver code.
+ */
Maybe he remembers why...
> Signed-off-by: Yang Shi <yang.s@alibaba-inc.com>
> CC: Andrew Morton <akpm@linux-foundation.org>
> ---
> Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway
> it sounds not make sense to keep invalid rule.
>
> scripts/checkpatch.pl | 11 -----------
> 1 file changed, 11 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8b80bac..e8cf94f 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6231,17 +6231,6 @@ sub process {
> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
> }
>
> -# whine mightly about in_atomic
> - if ($line =~ /\bin_atomic\s*\(/) {
> - if ($realfile =~ m@^drivers/@) {
> - ERROR("IN_ATOMIC",
> - "do not use in_atomic in drivers\n" . $herecurr);
> - } elsif ($realfile !~ m@^kernel/@) {
> - WARN("IN_ATOMIC",
> - "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
> - }
> - }
> -
> # whine about ACCESS_ONCE
> if ($^V && $^V ge 5.10.0 &&
> $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule
2017-11-03 19:41 ` Joe Perches
@ 2017-11-03 22:41 ` Yang Shi
0 siblings, 0 replies; 5+ messages in thread
From: Yang Shi @ 2017-11-03 22:41 UTC (permalink / raw)
To: Joe Perches, apw, Jonathan Corbet; +Cc: akpm, linux-kernel
On 11/3/17 12:41 PM, Joe Perches wrote:
> On Sat, 2017-11-04 at 03:08 +0800, Yang Shi wrote:
>> checkpatch.pl still reports the below in_atomic warning:
>>
>> WARNING: use of in_atomic() is incorrect outside core kernel code
>> + if (in_atomic())
>>
>> But, in_atomic() has been used outside kernel dir for a long time, and
>> even drivers. So, remove the obsolete rule even though they can be
>> ignored.
>
> Removing in_atomic() from checkpatch does not make sense
> without also updating include/linux/preempt.h
>
> Jonathon Corbet added this comment in
>
> commit 8c703d35fa91911dd92a18c31a718853f483ad80
> Author: Jonathan Corbet <corbet@lwn.net>
> Date: Fri Mar 28 14:15:49 2008 -0700
>
> in_atomic(): document why it is unsuitable for general use
>
> Discourage people from inappropriately using in_atomic()
>
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> ---
> include/linux/hardirq.h | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
> index 49829988bfa0..897f723bd222 100644
> --- a/include/linux/hardirq.h
> +++ b/include/linux/hardirq.h
> @@ -72,6 +72,13 @@
> #define in_softirq() (softirq_count())
> #define in_interrupt() (irq_count())
>
> +/*
> + * Are we running in atomic context? WARNING: this macro cannot
> + * always detect atomic context; in particular, it cannot know about
> + * held spinlocks in non-preemptible kernels. Thus it should not be
This part looks changed. CONFIG_PREEMPT_COUNT might be enabled with
non-preemptible kernel, so that in_atomic() could know if kernel held
spinlocks or not.
Yang
> + * used in the general case to determine whether sleeping is possible.
> + * Do not use in_atomic() in driver code.
> + */
>
> Maybe he remembers why...
>
>> Signed-off-by: Yang Shi <yang.s@alibaba-inc.com>
>> CC: Andrew Morton <akpm@linux-foundation.org>
>> ---
>> Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway
>> it sounds not make sense to keep invalid rule.
>>
>> scripts/checkpatch.pl | 11 -----------
>> 1 file changed, 11 deletions(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 8b80bac..e8cf94f 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -6231,17 +6231,6 @@ sub process {
>> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
>> }
>>
>> -# whine mightly about in_atomic
>> - if ($line =~ /\bin_atomic\s*\(/) {
>> - if ($realfile =~ m@^drivers/@) {
>> - ERROR("IN_ATOMIC",
>> - "do not use in_atomic in drivers\n" . $herecurr);
>> - } elsif ($realfile !~ m@^kernel/@) {
>> - WARN("IN_ATOMIC",
>> - "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
>> - }
>> - }
>> -
>> # whine about ACCESS_ONCE
>> if ($^V && $^V ge 5.10.0 &&
>> $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule
2017-11-03 19:08 [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule Yang Shi
2017-11-03 19:41 ` Joe Perches
@ 2017-11-06 13:52 ` Michal Hocko
2017-11-06 16:08 ` Yang Shi
1 sibling, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2017-11-06 13:52 UTC (permalink / raw)
To: Yang Shi; +Cc: apw, joe, akpm, linux-kernel
On Sat 04-11-17 03:08:06, Yang Shi wrote:
> checkpatch.pl still reports the below in_atomic warning:
>
> WARNING: use of in_atomic() is incorrect outside core kernel code
> + if (in_atomic())
>
> But, in_atomic() has been used outside kernel dir for a long time, and
> even drivers. So, remove the obsolete rule even though they can be
> ignored.
NAK. in_atomic is tricky and shouldn't be used. I would bet most of the
usage is simply broken. See more http://lkml.kernel.org/r/20171106100558.GD3165@worktop.lehotels.local
> Signed-off-by: Yang Shi <yang.s@alibaba-inc.com>
> CC: Andrew Morton <akpm@linux-foundation.org>
> ---
> Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway
> it sounds not make sense to keep invalid rule.
>
> scripts/checkpatch.pl | 11 -----------
> 1 file changed, 11 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8b80bac..e8cf94f 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6231,17 +6231,6 @@ sub process {
> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
> }
>
> -# whine mightly about in_atomic
> - if ($line =~ /\bin_atomic\s*\(/) {
> - if ($realfile =~ m@^drivers/@) {
> - ERROR("IN_ATOMIC",
> - "do not use in_atomic in drivers\n" . $herecurr);
> - } elsif ($realfile !~ m@^kernel/@) {
> - WARN("IN_ATOMIC",
> - "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
> - }
> - }
> -
> # whine about ACCESS_ONCE
> if ($^V && $^V ge 5.10.0 &&
> $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
> --
> 1.8.3.1
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule
2017-11-06 13:52 ` Michal Hocko
@ 2017-11-06 16:08 ` Yang Shi
0 siblings, 0 replies; 5+ messages in thread
From: Yang Shi @ 2017-11-06 16:08 UTC (permalink / raw)
To: Michal Hocko; +Cc: apw, joe, akpm, linux-kernel
On 11/6/17 5:52 AM, Michal Hocko wrote:
> On Sat 04-11-17 03:08:06, Yang Shi wrote:
>> checkpatch.pl still reports the below in_atomic warning:
>>
>> WARNING: use of in_atomic() is incorrect outside core kernel code
>> + if (in_atomic())
>>
>> But, in_atomic() has been used outside kernel dir for a long time, and
>> even drivers. So, remove the obsolete rule even though they can be
>> ignored.
>
> NAK. in_atomic is tricky and shouldn't be used. I would bet most of the
> usage is simply broken. See more http://lkml.kernel.org/r/20171106100558.GD3165@worktop.lehotels.local
Thanks for following up. Yes, it sounds so. However, there is not a
reliable and effective approach to check atomic context for both PREEMPT
and !PREEMPT.
Yang
>
>> Signed-off-by: Yang Shi <yang.s@alibaba-inc.com>
>> CC: Andrew Morton <akpm@linux-foundation.org>
>> ---
>> Not sure if removing the obsolete rule is preferred by checkpatch.pl, anyway
>> it sounds not make sense to keep invalid rule.
>>
>> scripts/checkpatch.pl | 11 -----------
>> 1 file changed, 11 deletions(-)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 8b80bac..e8cf94f 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -6231,17 +6231,6 @@ sub process {
>> "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
>> }
>>
>> -# whine mightly about in_atomic
>> - if ($line =~ /\bin_atomic\s*\(/) {
>> - if ($realfile =~ m@^drivers/@) {
>> - ERROR("IN_ATOMIC",
>> - "do not use in_atomic in drivers\n" . $herecurr);
>> - } elsif ($realfile !~ m@^kernel/@) {
>> - WARN("IN_ATOMIC",
>> - "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
>> - }
>> - }
>> -
>> # whine about ACCESS_ONCE
>> if ($^V && $^V ge 5.10.0 &&
>> $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) {
>> --
>> 1.8.3.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-11-06 16:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03 19:08 [RFC PATCH] scripts: checkpatch.pl: remove obsolete in_atomic rule Yang Shi
2017-11-03 19:41 ` Joe Perches
2017-11-03 22:41 ` Yang Shi
2017-11-06 13:52 ` Michal Hocko
2017-11-06 16:08 ` Yang Shi
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).