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=-6.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 883C8C433E7 for ; Fri, 9 Oct 2020 18:01:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EACE2227E for ; Fri, 9 Oct 2020 18:01:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390289AbgJISBV (ORCPT ); Fri, 9 Oct 2020 14:01:21 -0400 Received: from smtprelay0021.hostedemail.com ([216.40.44.21]:33560 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730110AbgJISBV (ORCPT ); Fri, 9 Oct 2020 14:01:21 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 6CA43181D3030; Fri, 9 Oct 2020 18:01:20 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: boys36_610ce33271e2 X-Filterd-Recvd-Size: 3039 Received: from XPS-9350.home (unknown [47.151.133.149]) (Authenticated sender: joe@perches.com) by omf19.hostedemail.com (Postfix) with ESMTPA; Fri, 9 Oct 2020 18:01:19 +0000 (UTC) Message-ID: Subject: Re: [PATCH] checkpatch: Check for .byte-spelled insn opcodes documentation on x86 From: Joe Perches To: Borislav Petkov , X86 ML Cc: Andrew Morton , Andy Whitcroft , LKML , Peter Zijlstra Date: Fri, 09 Oct 2020 11:01:18 -0700 In-Reply-To: <20201009161423.14583-1-bp@alien8.de> References: <20201009161423.14583-1-bp@alien8.de> 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 On Fri, 2020-10-09 at 18:14 +0200, Borislav Petkov wrote: > 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. OK but several notes: > diff --git 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(?:0[xX][0-9a-fA-F]+0-9a-fx,]+)/ && $realfile =~ "^arch/x86/") { Given the location, this only works on .c and .h files. It does not work on .S files. Should it? No need for a capture group. Please use @ not " as all the other $realfile comparisons use that form when expecting a / So it looks like the regex would be more complete as: if ($realfile =~ m@^arch/x86/@ && $rawline =~ /\.byte\s+(?:$Constant|(?:\\)?$Ident|"\s*$Ident)\b/) { etc... > + my $comment = ctx_locate_comment(0, $linenr); A patch can modify any number of files. This should use ctx_locate_comment($file ? 0 : $first_line, $linenr) as checkpatch tests work on patch contexts not the entire file before this line. > + if (! $comment || ($comment !~ /binutils version [0-9.]+/(ms)) { No need for the $!comment test > + WARN("MISSING_BINUTILS_VERSION", > + "Please document which binutils version supports these .byte-spelled\n" . > + "\tinsn opcodes by adding \"binutils version \" in a comment" . > + " above them.\n" . $herecurr); checkpatch uses only a single line output only before $herecurr Output line length doesn't matter.