[-v2] checkpatch: Check for .byte-spelled insn opcodes documentation on x86
diff mbox series

Message ID 20201010105547.GB24674@zn.tnic
State New, archived
Headers show
Series
  • [-v2] checkpatch: Check for .byte-spelled insn opcodes documentation on x86
Related show

Commit Message

Borislav Petkov Oct. 10, 2020, 10:55 a.m. UTC
--
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 | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Patch
diff mbox series

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 504d2e431c60..d9065ef5d4fe 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6858,6 +6858,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.
+		if ($realfile =~ m@^arch/x86/@ &&
+		    $rawline =~ /\.byte[\s0-9a-fx,]+/) {
+
+			my $comment = ctx_locate_comment($file ? 0 : $first_line, $linenr);
+			if ($comment !~ /binutils version [0-9.]+/ms) {
+				WARN("MISSING_BINUTILS_VERSION",
+				     "Please document which binutils version supports these .byte-spelled\n" .
+				     "\tinsn 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