Skip to contentSkip to conversation

checkpatch: handling of memory barriers

PATCH In review Michael S. Tsirkin 3 participants 35 messages Jan 4, 2016 – Jan 10, 2016

Subsystems (7)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

cover checkpatch: handling of memory barriers

As part of memory barrier cleanup, this patchset
extends checkpatch to make it easier to stop
incorrect memory barrier usage.

This applies on top of my series
arch: barrier cleanup + barriers for virt
and will be included in the next version of the series.

Michael S. Tsirkin (3):
checkpatch.pl: add missing memory barriers
checkpatch: check for __smp outside barrier.h
checkpatch: add virt barriers

 scripts/checkpatch.pl | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
Signature · 1 line
MST
author maintainer
#1 lore raw

PATCH 1/3 checkpatch.pl: add missing memory barriers

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +8 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
 			}
 		}
 # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
 				WARN("MEMORY_BARRIER",
 				     "memory barrier without comment\n" . $herecurr);
Signature · 1 line
MST
maintainer
#2 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

Quoted 14 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 2b3c228..0245bbe 100755

scripts/checkpatch.pl sub process { · line 5123

Quoted 9 lines
scripts/checkpatch.pl +5 -1
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

Quoted 3 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
#3 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#4 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

Quoted 8 lines

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

right, thanks.

maintainer
#5 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Russell King - ARM Linux
Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

Quoted 8 lines

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

right, thanks.

maintainer
#6 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Russell King - ARM Linux
Quoted 17 lines · Russell King - ARM Linux
Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

Quoted 8 lines

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

right, thanks.

#7 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#8 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 9 lines · Joe Perches

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines · Michael S. Tsirkin
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/
as there's no reason for the capture and there
could be a space between the function and the
open parenthesis.

I think you mean

	/\b(?:$all_barriers)\s*\(/

as 'all_barriers' will be:

mb|wmb|rmb|smp_mb|smp_wmb|smp_rmb

and putting that into your suggestion results in:

	/\bmb|wmb|rmb|smp_mb|smp_wmb|smp_rmb\s*\(/

which is clearly wrong - the \b only applies to 'mb' and the \s*\( only applies to smp_rmb.

Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#9 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Okay - I'll rewrite using foreach.

Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

That's the way it was - space before ( will trigger other warnings. But sure, ok.

Quoted 4 lines
Quoted 4 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
maintainer
#10 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

Quoted 30 lines · Michael S. Tsirkin
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Quoted 2 lines

Okay - I'll rewrite using foreach.

I think using the qr form (like 'our $Attribute' and a bunch of others) is the general style that should be used for checkpatch.

author maintainer
#11 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

Quoted 31 lines · Joe Perches
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Joe Perches
Quoted 14 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 2b3c228..0245bbe 100755

scripts/checkpatch.pl sub process { · line 5123

Quoted 9 lines
scripts/checkpatch.pl +5 -1
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Quoted 6 lines
Quoted 2 lines

Okay - I'll rewrite using foreach.

I think using the qr form (like 'our $Attribute' and a bunch of others) is the general style that should be used for checkpatch.

Thanks - that's what I did in the new version (included in v3 of the arch cleanup patchset now).

author maintainer
#12 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 31 lines · Joe Perches
Quoted 30 lines · Michael S. Tsirkin
Quoted 28 lines · Joe Perches
Quoted 14 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 2b3c228..0245bbe 100755

scripts/checkpatch.pl sub process { · line 5123

Quoted 9 lines
scripts/checkpatch.pl +5 -1
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Quoted 6 lines
Quoted 2 lines

Okay - I'll rewrite using foreach.

I think using the qr form (like 'our $Attribute' and a bunch of others) is the general style that should be used for checkpatch.

Thanks - that's what I did in the new version (included in v3 of the arch cleanup patchset now).

maintainer
#13 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Quoted 2 lines

Okay - I'll rewrite using foreach.

I think using the qr form (like 'our $Attribute' and a bunch of others) is the general style that should be used for checkpatch.

maintainer
#14 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Michael S. Tsirkin
Quoted 30 lines · Michael S. Tsirkin
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Quoted 2 lines

Okay - I'll rewrite using foreach.

I think using the qr form (like 'our $Attribute' and a bunch of others) is the general style that should be used for checkpatch.

author maintainer
#15 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Okay - I'll rewrite using foreach.

Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

That's the way it was - space before ( will trigger other warnings. But sure, ok.

Quoted 4 lines
Quoted 4 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
author maintainer
#16 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Joe Perches
Quoted 20 lines · Joe Perches
Quoted 19 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5123

Quoted 4 lines
scripts/checkpatch.pl +4 -0
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

Okay - I'll rewrite using foreach.

Quoted 8 lines

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

That's the way it was - space before ( will trigger other warnings. But sure, ok.

Quoted 4 lines
Quoted 4 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
maintainer
#17 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Michael S. Tsirkin
Quoted 14 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 2b3c228..0245bbe 100755

scripts/checkpatch.pl sub process { · line 5123

Quoted 9 lines
scripts/checkpatch.pl +5 -1
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

Quoted 3 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
maintainer
#18 lore raw

Re: [PATCH 1/3] checkpatch.pl: add missing memory barriers

In reply to Michael S. Tsirkin
Quoted 14 lines · Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +0 -0
index 2b3c228..0245bbe 100755

scripts/checkpatch.pl sub process { · line 5123

Quoted 9 lines
scripts/checkpatch.pl +5 -1
@@ -5116,7 +5116,14 @@ sub process {
  			}
  		}
  # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);

I think using map, which so far checkpatch doesn't use, makes smp_barriers harder to understand and it'd be better to enumerate them.

scripts/checkpatch.pl sub process { · line 5126

Quoted 3 lines
scripts/checkpatch.pl +3 -0
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {

It would be better to use /\b$all_barriers\s*\(/ as there's no reason for the capture and there could be a space between the function and the open parenthesis.

Quoted 3 lines
scripts/checkpatch.pl +0 -0
  			if (!ctx_has_comment($first_line, $linenr)) {
  				WARN("MEMORY_BARRIER",
  				     "memory barrier without comment\n" . $herecurr);
author maintainer
#19 lore raw

PATCH 1/3 checkpatch.pl: add missing memory barriers

In reply to Michael S. Tsirkin

SMP-only barriers were missing in checkpatch.pl

Refactor code slightly to make adding more variants easier.

---
 scripts/checkpatch.pl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +8 -1
index 2b3c228..0245bbe 100755
@@ -5116,7 +5116,14 @@ sub process {
 			}
 		}
 # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+
+		my @barriers = ('mb', 'rmb', 'wmb', 'read_barrier_depends');
+		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
+
+		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);
+		my $all_barriers = join('|', (@barriers, @smp_barriers));
+
+		if ($line =~ /\b($all_barriers)\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
 				WARN("MEMORY_BARRIER",
 				     "memory barrier without comment\n" . $herecurr);
Signature · 1 line
MST
author maintainer
#20 lore raw

PATCH 2/3 checkpatch: check for __smp outside barrier.h

In reply to Michael S. Tsirkin

Introduction of __smp barriers cleans up a bunch of duplicate code, but it gives people an additional handle onto a "new" set of barriers - just because they're prefixed with __* unfortunately doesn't stop anyone from using it (as happened with other arch stuff before.)

Add a checkpatch test so it will trigger a warning.

---
 scripts/checkpatch.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/checkpatch.pl +11 -0
index 0245bbe..e3f9ad9 100755
@@ -5130,6 +5130,17 @@ sub process {
 			}
 		}
 
+		my @underscore_smp_barriers = map {"__" . $_} @smp_barriers;
+		my $underscore_all_barriers = join('|', @underscore_smp_barriers);
+
+		if ($realfile !~ m@^include/asm-generic/@ &&
+		    $realfile !~ m@/barrier\.h$@ &&
+		    $line =~ m/\b($underscore_all_barriers)\(/ &&
+		    $line !~ m/^.\s*\#\s*define\s+($underscore_all_barriers)\(/) {
+			WARN("MEMORY_BARRIER",
+			     "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
+		}
+
 # check for waitqueue_active without a comment.
 		if ($line =~ /\bwaitqueue_active\s*\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
Signature · 1 line
MST
author maintainer
#21 lore raw

PATCH 2/3 checkpatch: check for __smp outside barrier.h

In reply to Michael S. Tsirkin

Introduction of __smp barriers cleans up a bunch of duplicate code, but it gives people an additional handle onto a "new" set of barriers - just because they're prefixed with __* unfortunately doesn't stop anyone from using it (as happened with other arch stuff before.)

Add a checkpatch test so it will trigger a warning.

---
 scripts/checkpatch.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/checkpatch.pl +11 -0
index 0245bbe..e3f9ad9 100755
@@ -5130,6 +5130,17 @@ sub process {
 			}
 		}
 
+		my @underscore_smp_barriers = map {"__" . $_} @smp_barriers;
+		my $underscore_all_barriers = join('|', @underscore_smp_barriers);
+
+		if ($realfile !~ m@^include/asm-generic/@ &&
+		    $realfile !~ m@/barrier\.h$@ &&
+		    $line =~ m/\b($underscore_all_barriers)\(/ &&
+		    $line !~ m/^.\s*\#\s*define\s+($underscore_all_barriers)\(/) {
+			WARN("MEMORY_BARRIER",
+			     "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
+		}
+
 # check for waitqueue_active without a comment.
 		if ($line =~ /\bwaitqueue_active\s*\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
Signature · 1 line
MST
author maintainer
#22 lore raw

PATCH 3/3 checkpatch: add virt barriers

In reply to Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index e3f9ad9..5fb6ef7 100755
@@ -5121,7 +5121,8 @@ sub process {
 		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
 
 		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);
-		my $all_barriers = join('|', (@barriers, @smp_barriers));
+		my @virt_barriers = map {my $l = $_; $l =~ s/smp_/virt_/; $l} @smp_barriers;
+		my $all_barriers = join('|', (@barriers, @smp_barriers, @virt_barriers));
 
 		if ($line =~ /\b($all_barriers)\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
Signature · 1 line
MST
maintainer
#23 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

author maintainer
#24 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

Quoted 7 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Signature · 1 line
MST
maintainer
#25 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

Quoted 7 lines
Quoted 1 line

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
        arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Ah, OK, thanks.

Are the virtio_ barriers going away?
If not, maybe those should be added too.

author maintainer
#26 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

Quoted 13 lines · Joe Perches
Quoted 12 lines · Michael S. Tsirkin
Quoted 7 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
        arch: barrier cleanup + barriers for virt

Quoted 7 lines
Quoted 2 lines

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Ah, OK, thanks.

Are the virtio_ barriers going away?
If not, maybe those should be added too.

I don't mind. I'll queue a patch like that.

Signature · 1 line
MST
author maintainer
#27 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Joe Perches
Quoted 13 lines · Joe Perches
Quoted 12 lines · Michael S. Tsirkin
Quoted 7 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
        arch: barrier cleanup + barriers for virt

Quoted 7 lines
Quoted 2 lines

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Ah, OK, thanks.

Are the virtio_ barriers going away?
If not, maybe those should be added too.

I don't mind. I'll queue a patch like that.

Signature · 1 line
MST
maintainer
#28 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

Quoted 7 lines
Quoted 1 line

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
        arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Ah, OK, thanks.

Are the virtio_ barriers going away?
If not, maybe those should be added too.

maintainer
#29 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

Quoted 7 lines
Quoted 1 line

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
        arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Ah, OK, thanks.

Are the virtio_ barriers going away?
If not, maybe those should be added too.

author maintainer
#30 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Joe Perches
Quoted 7 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Signature · 1 line
MST
author maintainer
#31 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Joe Perches
Quoted 7 lines · Joe Perches
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

They will be :) They are added and used by patchset
arch: barrier cleanup + barriers for virt

See
http://article.gmane.org/gmane.linux.kernel.virtualization/26555

Signature · 1 line
MST
maintainer
#32 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Michael S. Tsirkin
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

maintainer
#33 lore raw

Re: [PATCH 3/3] checkpatch: add virt barriers

In reply to Michael S. Tsirkin
Quoted 2 lines · Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

Are these virt_ barriers used anywhere?

I see some virtio_ barrier like uses.

author maintainer
#34 lore raw

PATCH 3/3 checkpatch: add virt barriers

In reply to Michael S. Tsirkin

Add virt_ barriers to list of barriers to check for presence of a comment.

---
 scripts/checkpatch.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +2 -1
index e3f9ad9..5fb6ef7 100755
@@ -5121,7 +5121,8 @@ sub process {
 		my @smp_barriers = ('smp_store_release', 'smp_load_acquire', 'smp_store_mb');
 
 		@smp_barriers = (@smp_barriers, map {"smp_" . $_} @barriers);
-		my $all_barriers = join('|', (@barriers, @smp_barriers));
+		my @virt_barriers = map {my $l = $_; $l =~ s/smp_/virt_/; $l} @smp_barriers;
+		my $all_barriers = join('|', (@barriers, @smp_barriers, @virt_barriers));
 
 		if ($line =~ /\b($all_barriers)\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
Signature · 1 line
MST