From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73D05C433E7 for ; Mon, 12 Oct 2020 17:09:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4596520878 for ; Mon, 12 Oct 2020 17:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404051AbgJLRJs (ORCPT ); Mon, 12 Oct 2020 13:09:48 -0400 Received: from smtprelay0032.hostedemail.com ([216.40.44.32]:49330 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403963AbgJLRJs (ORCPT ); Mon, 12 Oct 2020 13:09:48 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id B9225182251AE; Mon, 12 Oct 2020 17:09:46 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: wish49_450c7ef271fc X-Filterd-Recvd-Size: 4228 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Mon, 12 Oct 2020 17:09:45 +0000 (UTC) Message-ID: Subject: [PATCH -v4] checkpatch: Check for .byte-spelled insn opcodes documentation on x86 From: Joe Perches To: Andrew Morton Cc: X86 ML , Andy Whitcroft , LKML , Peter Zijlstra , Borislav Petkov Date: Mon, 12 Oct 2020 10:09:44 -0700 References: <20201009161423.14583-1-bp@alien8.de> <20201010105421.GA24674@zn.tnic> <4147e49c0b1251343181b5580d946c2273247927.camel@perches.com> <20201010161112.GC24674@zn.tnic> <20201012142148.GA22829@zn.tnic> In-Reply-To: <20201012142148.GA22829@zn.tnic> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.36.4-0ubuntu1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov Instruction opcode bytes spelled using the gas directive .byte should carry a comment above them stating which binutils version has added support for the instruction mnemonic so that they can be replaced with the mnemonic when that binutils version is equal or less than the minimum-supported version by the kernel. Add a check for that. Requested-by: Peter Zijlstra Signed-off-by: Borislav Petkov Signed-off-by: Joe Perches --- v4: trivial neatening of $Hex_byte and adding a mechanism to only emit the message once per patched file (Joe) scripts/checkpatch.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index fab38b493cef..7568f583701c 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -414,6 +414,7 @@ our $Lval = qr{$Ident(?:$Member)*}; our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; our $Binary = qr{(?i)0b[01]+$Int_type?}; our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; +our $Hex_byte = qr{(?i)0x[0-9a-f]{1,2}\b}; our $Int = qr{[0-9]+$Int_type?}; our $Octal = qr{0[0-7]+$Int_type?}; our $String = qr{"[X\t]*"}; @@ -2408,6 +2409,7 @@ sub process { my $comment_edge = 0; my $first_line = 0; my $p1_prefix = ''; + my $warned_binutils = 0; my $prev_values = 'E'; @@ -2589,6 +2591,7 @@ sub process { $realfile =~ s@^([^/]*)/@@ if (!$file); $in_commit_log = 0; $found_file = 1; + $warned_binutils = 0; } elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@ if (!$file); @@ -2606,6 +2609,7 @@ sub process { "do not modify files in include/asm, change architecture specific files in include/asm-\n" . "$here$rawline\n"); } $found_file = 1; + $warned_binutils = 0; } #make up the handle for any error we report on this line @@ -6954,6 +6958,20 @@ sub process { WARN("DUPLICATED_SYSCTL_CONST", "duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr); } + +# document which binutils version supports the actual insn mnemonic so that the naked opcode bytes can be replaced. +# x86-only. Upper limit is rather arbitrary (max insn length on x86) but imposed so as to avoid perl aborts. + if (!$warned_binutils && + $realfile =~ m@^arch/x86/@ && + $rawline =~ /\s*\.byte\s+$Hex_byte(?:\s*,\s*$Hex_byte){0,14}/) { + + my $comment = ctx_locate_comment($file ? 0 : $first_line, $linenr); + if ($comment !~ /binutils (?:version )*[0-9.]+/ms) { + WARN("MISSING_BINUTILS_VERSION", + "Please consider documenting which binutils version supports these .byte-spelled insn opcodes by adding \"binutils version \" in a comment above them\n" . $herecurr); + $warned_binutils = 1; + } + } } # If we have no input at all, then there is nothing to report on