Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp359493rwb; Thu, 22 Sep 2022 19:52:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kewmikU1O8n2XFbzBDKMyt/MaWDLHOf89UaiGOYMqydDzfH0LM83QzuVRFkz0fkMN8LRw X-Received: by 2002:a17:907:3e90:b0:781:cfa5:18a with SMTP id hs16-20020a1709073e9000b00781cfa5018amr5162099ejc.511.1663901531416; Thu, 22 Sep 2022 19:52:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663901531; cv=none; d=google.com; s=arc-20160816; b=uTN3LMEWwslp2zuqeuTWjleMCj2SurrQYBEOVTxDi84t3zUPdcS33f0XN9oiBTT0rS YEdUhTQsya4GHt7wjXTJrhh28pJyt0cA/bLRAPG2iWwCnFaxeq22yPUFwIOkgggUffBY 60zI2yZH6H5Sdq5hmrYXC4RZADnTljYcG/UubudPiixKTw3lNjNMVWmaze7yyrDbCRXF kRWPN1B/WjtUSVghp4sU8OYWDzryoeIavkS9ZBcc7caM+evo6wzSN8mZo4Z+7zDfkTA2 eOlWXaKQin8v12LWz/4JU1Zdf4vwb56MWY+QbFYcn4R+I2rPHHBU2QXfOGym57hoTFtf hqDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=JgRyJ6y0pthKyyaMNynM5xviBUzFO8J38XiFgiFxGVY=; b=B+Xp4QPXV7IvQdD5bQ+S3AzbbeLu5c/2Aw4JFGgrJEi/8BcIxShV3DcYtoWpTCsGE5 WXAVm9pJI22af7BT31FMGHSK9HLwiyfVj4Gm1SVOV87iRMb5x444lPeJPhktpO0TYPLV goEt5EcU4t0O0OdzYN6UggZ755V8141g8Q+3ENcQqCPfNKp7r6xec48DjY8XSRQNdzB7 z6kb4Aiw4yZcZQzZv1uCR07ATttdQIjOV3UqZAKnu+w6nM0LMqONNqc2Zb9OF7hvBbXB fpxHKKS6HtrWxaew9KQIgfK2dumXFbablfUTE2Dx41MPop+odGO6v36g5CatFbdbhbJ3 JV4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a056402271000b00450bda7e40bsi7577108edd.29.2022.09.22.19.51.45; Thu, 22 Sep 2022 19:52:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbiIWCL7 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 22 Sep 2022 22:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231491AbiIWCL5 (ORCPT ); Thu, 22 Sep 2022 22:11:57 -0400 Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 031CA105D78; Thu, 22 Sep 2022 19:11:55 -0700 (PDT) Received: from omf12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C9E20160333; Fri, 23 Sep 2022 02:11:51 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA id 7D8BE19; Fri, 23 Sep 2022 02:11:41 +0000 (UTC) Message-ID: <3179f4545d3f71358da3e6c6ee18085af601b2eb.camel@perches.com> Subject: Re: [PATCH v1 3/3] checkpatch: warn on usage of VM_BUG_ON() and other BUG variants From: Joe Perches To: John Hubbard , David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Linus Torvalds , Andrew Morton , Ingo Molnar , David Laight , Jonathan Corbet , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young , Jani Nikula , Michael Ellerman , Nicholas Piggin , Christophe Leroy Date: Thu, 22 Sep 2022 19:11:44 -0700 In-Reply-To: References: <20220920122302.99195-1-david@redhat.com> <20220920122302.99195-4-david@redhat.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Stat-Signature: me7gijswwjx78bt11de9ttdkeerub4ce X-Rspamd-Server: rspamout04 X-Rspamd-Queue-Id: 7D8BE19 X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,FORGED_SPF_HELO, KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+TmJmbnGkm+LNw6VlDjRWiozpu+WDNQbw= X-HE-Tag: 1663899101-987245 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-09-22 at 19:05 -0700, John Hubbard wrote: > On 9/20/22 05:23, David Hildenbrand wrote: > > checkpatch does not point out that VM_BUG_ON() and friends should be > > avoided, however, Linus notes: > > > > VM_BUG_ON() has the exact same semantics as BUG_ON. It is literally > > no different, the only difference is "we can make the code smaller > > because these are less important". [1] > > > > So let's warn on VM_BUG_ON() and other BUG variants as well. While at it, > > make it clearer that the kernel really shouldn't be crashed. > > > > As there are some subsystem BUG macros that actually don't end up crashing > > the kernel -- for example, KVM_BUG_ON() -- exclude these manually. > > > > [1] https://lore.kernel.org/r/CAHk-=wg40EAZofO16Eviaj7mfqDhZ2gVEbvfsMf6gYzspRjYvw@mail.gmail.com [] > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > > @@ -4695,12 +4695,12 @@ sub process { > > } > > } > > > > -# avoid BUG() or BUG_ON() > > - if ($line =~ /\b(?:BUG|BUG_ON)\b/) { > > +# do not use BUG() or variants > > + if ($line =~ /\b(?!AA_|BUILD_|DCCP_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*\(/) { > > Should this be a separate patch? Adding a bunch of exceptions to the BUG() rules is > a separate and distinct thing from adding VM_BUG_ON() and other *BUG*() variants to > the mix. Not in my opinion. > > my $msg_level = \&WARN; > > $msg_level = \&CHK if ($file); > > &{$msg_level}("AVOID_BUG", > > - "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr); > > + "Do not crash the kernel unless it is unavoidable - use WARN_ON_ONCE & recovery code (if reasonable) rather than BUG() or variants.\n" . $herecurr); > > Here's a requested tweak, to clean up the output and fix punctuation: > > "Avoid crashing the kernel--use WARN_ON_ONCE() plus recovery code (if feasible) instead of BUG() or variants.\n" . $herecurr); Fixing punctuation here would be removing the trailing period as checkpatch only has periods for multi-sentence output messages. And I think that "Do not crash" is a stronger statement than "Avoid crashing" so I prefer the original suggestion but it's not a big deal either way.