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 0B7BFECAAA2 for ; Mon, 29 Aug 2022 03:08:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FCA294000B; Sun, 28 Aug 2022 23:08:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AC9A940007; Sun, 28 Aug 2022 23:08:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69B1F94000B; Sun, 28 Aug 2022 23:08:19 -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 5B49D940007 for ; Sun, 28 Aug 2022 23:08:19 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1E6FA1C61EF for ; Mon, 29 Aug 2022 03:08:19 +0000 (UTC) X-FDA: 79851146718.09.4560E89 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by imf10.hostedemail.com (Postfix) with ESMTP id BD51FC0032 for ; Mon, 29 Aug 2022 03:08:18 +0000 (UTC) Received: by mail-ej1-f48.google.com with SMTP id u9so13111250ejy.5 for ; Sun, 28 Aug 2022 20:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=czsEz3uMSDGtuN3iX+1gBJ3GgnTp4SI1Njv08bLGbUU=; b=cPVVHSrIrAu2fehaiXFO0NP7AV/D8IKrlaMiQe+6eE9t8kVdLLqit3Ns43ao5yryMU bM3fOL+yiO5KsBC9cVh11Rmxm0oDVgV9e8FV3PDtt1F3rBjNB5Hi9jvvZ95lMWPmJgHo BzpLC+c2RDhxf774/fKbqWzoqlAZzsnK+vWK4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=czsEz3uMSDGtuN3iX+1gBJ3GgnTp4SI1Njv08bLGbUU=; b=G+E7YoCCCloZ3hY1nYD+4gCVLs+zKcZ7+oOUcEfhXTMvzKRtwSBEKRRpNq9byr+eIo JZQXVKEZ83lAufsbHig/sXq+SUh38cPu9mWp9/Clyw3QgGOx7p+/Yhggu/k/ECnfu9A3 Wlg6Xm5pBj2s7J1qOMACJSmYYler8s6rlFYowXIncwppC+qVGbDdDdz8lUzwsJGwsSS5 UJuebs/G7h8zPcMfSK5+/w3SH1WcrT2gW1wEMnJHKE6vvs7ego/p4yCw9wva+OZq9wVA vNTqKt3gMX9ldpd7qFJLu/nAYqf9ac9KVWPOcMP4WmySQHD4FML3zK5d8T+eSJ+0EQNR 7g4w== X-Gm-Message-State: ACgBeo3bbjm7T8hxx2bK28yZsltw/LZjbRjBzESTH0iaj4ObvvYcIEpr GLh+cLoJgdezeq7cvU7MHM4Aw6X9X3Rq395A X-Google-Smtp-Source: AA6agR44HgVLmST1z1sP7znwKFznc0swpBVuMsXRVCC34hJ3Wzyg1tAMLMJTb43+7pBWmLfiRRHciQ== X-Received: by 2002:a17:907:284a:b0:73d:a818:5a2a with SMTP id el10-20020a170907284a00b0073da8185a2amr11851674ejc.159.1661742496888; Sun, 28 Aug 2022 20:08:16 -0700 (PDT) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com. [209.85.128.43]) by smtp.gmail.com with ESMTPSA id vs23-20020a170907139700b0072ed9efc9dfsm3897869ejb.48.2022.08.28.20.08.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Aug 2022 20:08:16 -0700 (PDT) Received: by mail-wm1-f43.google.com with SMTP id h204-20020a1c21d5000000b003a5b467c3abso7452578wmh.5 for ; Sun, 28 Aug 2022 20:08:15 -0700 (PDT) X-Received: by 2002:a7b:c399:0:b0:3a5:f3fb:85e0 with SMTP id s25-20020a7bc399000000b003a5f3fb85e0mr5607006wmj.38.1661742495614; Sun, 28 Aug 2022 20:08:15 -0700 (PDT) MIME-Version: 1.0 References: <20220824163100.224449-1-david@redhat.com> <20220824163100.224449-2-david@redhat.com> <0db131cf-013e-6f0e-c90b-5c1e840d869c@nvidia.com> In-Reply-To: From: Linus Torvalds Date: Sun, 28 Aug 2022 20:07:59 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC 1/2] coding-style.rst: document BUG() and WARN() rules ("do not crash the kernel") To: Dave Young Cc: David Hildenbrand , John Hubbard , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, kexec@lists.infradead.org, Andrew Morton , Ingo Molnar , David Laight , Jonathan Corbet , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Stephen Johnston , Prarit Bhargava Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661742498; a=rsa-sha256; cv=none; b=fUD5Hnq2GKAnQcSWbId9mZVOP9zmvETWH8T7mr6b4l9QhxQqrrQSVx21P5A0G1DjMfIdUS u/6AHAP1FU29QDIXdJ6+bawyaiSmRM8w6hhTAcElblSXYT63pr22DFyISZxXzvs2RjQVlS jKrUzOvRxaIxgQ12NC3HGAJZ5JDQmHg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=cPVVHSrI; spf=pass (imf10.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.218.48 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661742498; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=czsEz3uMSDGtuN3iX+1gBJ3GgnTp4SI1Njv08bLGbUU=; b=JdaGi5jTtjETbevYP8W3g68F6KcgDaZjxOSTbxAjBJ7jf2iSEfW0LlMUMT21k2m+UvSx/3 BPTK5G7kJ9BuMmyUQwFZQ3f6RGcZ/XyDkHuU99RuiHMxhB+/8C2a8eLQSbPCQMVImB07B8 Uq/RkyO6rfSfhSHDMmnCUZKdj1+9TX8= X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=cPVVHSrI; spf=pass (imf10.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.218.48 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-Rspamd-Server: rspam08 X-Stat-Signature: eeu87nwezn8ohh64kcrnz37nty7ohfyq X-Rspamd-Queue-Id: BD51FC0032 X-HE-Tag: 1661742498-68672 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 Sun, Aug 28, 2022 at 6:56 PM Dave Young wrote: > > > John mentioned PANIC_ON(). > > I would vote for PANIC_ON(), it sounds like a good idea, because > BUG_ON() is not obvious and, PANIC_ON() can alert the code author that > this will cause a kernel panic and one will be more careful before > using it. People, NO. We're trying to get rid of BUG_ON() because it kills the machine. Not replace it with another bogus thing that kills a machine. So no PANIC_ON(). We used to have "panic()" many many years ago, we got rid of it. We're not re-introducing it. People who want to panic on warnings can do so. WARN_ON() _becomes_ PANIC for those people. But those people are the "we have a million machines, we want to just fail things on any sign of trouble, and we have MIS people who can look at the logs". And it's not like we need to get rid of _all_ BUG_ON() cases. If you have a "this is major internal corruption, there's no way we can continue", then BUG_ON() is appropriate. It will try to kill that process and try to keep the machine running, and again, the kind of people who don't care about one machine (because - again - they have millions of them) can just turn that into a panic-and-reboot situation. But the kind of people for whom the machine they are on IS THEIR ONLY MACHINE - whether it be a workstation, a laptop, or a cellphone - there is absolutely zero situation where "let's just kill the machine" is *EVER* approproate. Even a BUG_ON() will try to continue as well as it can after killing the current thread, but it's going to be iffy, because locking etc. So WARN_ON_ONCE() is the thing to aim for. BUG_ON() is the thing for "oops, I really don't know what to do, and I physically *cannot* continue" (and that is *not* "I'm too lazy to do error handling"). There is no room for PANIC. None. Ever. The only thing there is are "I don't care about this machine because I've got 999,999 other machines, so I'd rather take one machine offline for analysis". Understand? The "should I panic and reboot" is fundamentally not about the code, and it's not a choice that the kernel code gets to make. It's purely about the choice of the person maintaining the machine. As a kernel developer, you do not EVER get to say "panic" or "kill the machine". End of story. Linus