linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Joe Perches <joe@perches.com>
Cc: X86 ML <x86@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH -v3] checkpatch: Check for .byte-spelled insn opcodes documentation on x86
Date: Mon, 12 Oct 2020 16:23:06 +0200	[thread overview]
Message-ID: <20201012142306.GB22829@zn.tnic> (raw)
In-Reply-To: <20201012142148.GA22829@zn.tnic>

From: Borislav Petkov <bp@suse.de>

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 <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 504d2e431c60..e9ead600d685 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -408,6 +408,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}};
 our $Int	= qr{[0-9]+$Int_type?};
 our $Octal	= qr{0[0-7]+$Int_type?};
 our $String	= qr{"[X\t]*"};
@@ -6858,6 +6859,18 @@ 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 ($realfile =~ m@^arch/x86/@ &&
+		    $rawline =~ /\s*\.byte\s+(?:$Hex_byte[,\s]*){1,15}/) {
+
+			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 <num>\" in a comment above them.\n" . $herecurr);
+			}
+		}
 	}
 
 	# If we have no input at all, then there is nothing to report on
-- 
2.21.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2020-10-12 14:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-09 16:14 [PATCH] checkpatch: Check for .byte-spelled insn opcodes documentation on x86 Borislav Petkov
2020-10-09 18:01 ` Joe Perches
2020-10-10 10:54   ` Borislav Petkov
2020-10-10 10:55     ` [PATCH -v2] " Borislav Petkov
2020-10-10 15:27     ` [PATCH] " Joe Perches
2020-10-10 16:11       ` Borislav Petkov
2020-10-10 16:47         ` Joe Perches
2020-10-12 14:21           ` Borislav Petkov
2020-10-12 14:23             ` Borislav Petkov [this message]
2020-10-12 15:04               ` [PATCH -v3] " Joe Perches
2020-10-12 15:02             ` [PATCH] " Joe Perches
2020-10-12 17:09             ` [PATCH -v4] " Joe Perches
2020-10-12 17:15               ` Borislav Petkov
2020-10-12 17:17                 ` Joe Perches
2020-10-12 17:31                   ` Borislav Petkov
2020-10-12 17:40                     ` Joe Perches
2020-10-12 17:55                       ` Borislav Petkov
2020-10-12 18:03                         ` Joe Perches
2020-10-10 15:38     ` [PATCH] " Joe Perches

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=20201012142306.GB22829@zn.tnic \
    --to=bp@alien8.de \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).