[PATCH] checkpatch: Check for .byte-spelled insn opcodes documentation on x86

From: Borislav Petkov
Date: Fri Oct 09 2020 - 12:15:14 EST


From: Borislav Petkov <bp@xxxxxxx>

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@xxxxxxxxxxxxx>
Signed-off-by: Borislav Petkov <bp@xxxxxxx>
---
scripts/checkpatch.pl | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 504d2e431c60..cfa81f1640cd 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6858,6 +6858,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.
+ if ($rawline =~ /(\.byte[\s0-9a-fx,]+)/ && $realfile =~ "^arch/x86/") {
+ my $comment = ctx_locate_comment(0, $linenr);
+ if (! $comment || ($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
--
2.21.0