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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD62AC00140 for ; Wed, 24 Aug 2022 16:52:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55E13940007; Wed, 24 Aug 2022 12:52:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50D916B0078; Wed, 24 Aug 2022 12:52:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FCA0940007; Wed, 24 Aug 2022 12:52:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 303F66B0075 for ; Wed, 24 Aug 2022 12:52:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F2C771A0C6E for ; Wed, 24 Aug 2022 16:52:11 +0000 (UTC) X-FDA: 79835078862.11.C01720C Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by imf28.hostedemail.com (Postfix) with ESMTP id 9F786C006A for ; Wed, 24 Aug 2022 16:52:11 +0000 (UTC) Received: from omf07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C3D66C024E; Wed, 24 Aug 2022 16:52:09 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf07.hostedemail.com (Postfix) with ESMTPA id 696E12002C; Wed, 24 Aug 2022 16:52:06 +0000 (UTC) Message-ID: <3c250aa26020b2f336fd575a58d06ba26faf1f14.camel@perches.com> Subject: Re: [PATCH RFC 2/2] checkpatch: warn on usage of VM_BUG_ON() and friends From: Joe Perches To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kexec@lists.infradead.org, Linus Torvalds , Andrew Morton , Ingo Molnar , David Laight , Jonathan Corbet , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young Date: Wed, 24 Aug 2022 12:52:05 -0400 In-Reply-To: <20220824163100.224449-3-david@redhat.com> References: <20220824163100.224449-1-david@redhat.com> <20220824163100.224449-3-david@redhat.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-1.fc36) MIME-Version: 1.0 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/ObFLiNI+vpAgQqKNzyIkOlEeiH6U5Lr8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661359931; a=rsa-sha256; cv=none; b=YzvPg9ZxJGsP6zKkj8CT3xaqQyZLJ8RBmP1HDSibbO8JkM/WsbofxQ6Ze3UeCLYLEZ8r3M nSolFSS+ISODgWPlbnxBZ917NwpaY7ADdlUK3YShxgKWriY1fKRKBLmH6iWdP9xizvAupA SUPjfAEjxVlrdkgqsA+WUt7OT5tbRvo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.11) smtp.mailfrom=joe@perches.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661359931; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QJ/U+pjAKNgqd3+ssHMZkS9NzwuUfa0/0f0ROS3HABA=; b=Vz8CshTptgajizzS/sIjGvnoXiTTjlSxmAyZ+B9Cz7cTHYdwCKggvBp3N3xbIvtg/6MbLo LlgmF3+iguhCvta9FZLGFywHwioWrbcONplYWLMW4lNrnWWCojNlq0jvdNIxKOrAAZEVoo Ob7UDFR41wasD80MPZJ0Sg7L/0Jds8g= X-Stat-Signature: xdfsywp4ynu35rhcbtmcxspfkg319mk7 X-Rspamd-Queue-Id: 9F786C006A X-HE-Tag-Orig: 1661359926-188978 Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=none (imf28.hostedemail.com: domain of joe@perches.com has no SPF policy when checking 216.40.44.11) smtp.mailfrom=joe@perches.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1661359931-658215 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 2022-08-24 at 18:31 +0200, David Hildenbrand wrote: > checkpatch does not point out that VM_BUG_ON() and friends should be > avoided, however, Linus notes: >=20 > 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] >=20 > So let's warn on VM_BUG_ON() and friends as well. While at it, make it > clearer that the kernel really shouldn't be crashed. >=20 > Note that there are some other *_BUG_ON flavors, but they are not all > bad: for example, KVM_BUG_ON() only triggers a WARN_ON_ONCE and then > flags KVM as being buggy, so we'll not care about them for now here. [] > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > @@ -4695,12 +4695,12 @@ sub process { > } > } > =20 > -# avoid BUG() or BUG_ON() > - if ($line =3D~ /\b(?:BUG|BUG_ON)\b/) { > +# do not use BUG(), BUG_ON(), VM_BUG_ON() and friends. > + if ($line =3D~ /\b(?:BUG|BUG_ON|VM_BUG_ON|VM_BUG_ON_[A-Z]+)\b/) { Perhaps better as something like the below to pick up more variants if ($line =3D~ /\b(?!KVM_|BUILD_)(?:[A-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*= \(/ > my $msg_level =3D \&WARN; > $msg_level =3D \&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); and maybe: "Do not crash the kernel unless it is unavoidable - use WARN_ON_O= NCE & recovery code (if reasonable) rather than BUG() or variants\n" . $her= ecurr);