Michael S. Tsirkin
2016-Jan-04 11:36 UTC
[PATCH 0/3] 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(-) -- MST
Michael S. Tsirkin
2016-Jan-04 11:36 UTC
[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. Signed-off-by: Michael S. Tsirkin <mst at redhat.com> --- scripts/checkpatch.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2b3c228..0245bbe 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -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); -- MST
Michael S. Tsirkin
2016-Jan-04 11:37 UTC
[PATCH 2/3] checkpatch: check for __smp outside barrier.h
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. Reported-by: Russell King <linux at arm.linux.org.uk> Signed-off-by: Michael S. Tsirkin <mst at redhat.com> --- scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0245bbe..e3f9ad9 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -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)) { -- MST
Add virt_ barriers to list of barriers to check for presence of a comment. Signed-off-by: Michael S. Tsirkin <mst at redhat.com> --- scripts/checkpatch.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e3f9ad9..5fb6ef7 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -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)) { -- MST
On Mon, 2016-01-04 at 13:36 +0200, Michael S. Tsirkin wrote:> SMP-only barriers were missing in checkpatch.pl > > Refactor code slightly to make adding more variants easier. > > Signed-off-by: Michael S. Tsirkin <mst at redhat.com> > --- > ?scripts/checkpatch.pl | 9 ++++++++- > ?1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 2b3c228..0245bbe 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -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.> + 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.> ? if (!ctx_has_comment($first_line, $linenr)) { > ? WARN("MEMORY_BARRIER", > ? ?????"memory barrier without comment\n" . $herecurr);
On Mon, 2016-01-04 at 13:37 +0200, Michael S. Tsirkin wrote:> 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.
Apparently Analagous Threads
- [PATCH 0/3] checkpatch: handling of memory barriers
- [PATCH v2 0/3] checkpatch: handling of memory barriers
- [PATCH v2 0/3] checkpatch: handling of memory barriers
- [PATCH 1/3] checkpatch.pl: add missing memory barriers
- [PATCH 1/3] checkpatch.pl: add missing memory barriers