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 E5D12C04AA5 for ; Thu, 25 Aug 2022 12:12:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 368436B0074; Thu, 25 Aug 2022 08:12:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 318236B0075; Thu, 25 Aug 2022 08:12:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BA09940007; Thu, 25 Aug 2022 08:12:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 08DCC6B0074 for ; Thu, 25 Aug 2022 08:12:56 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BDF4341ADE for ; Thu, 25 Aug 2022 12:12:55 +0000 (UTC) X-FDA: 79838003910.19.E271C80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 6C18C140006 for ; Thu, 25 Aug 2022 12:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661429574; h=from:from: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=8i+ljzn6MB/eBmFGfmQrAmtwmX21MBronF2Ff991Uq0=; b=RTG/Z4iOIMLZ6gVDjrFOtWA/tAV0lMU3605kZiFp62HCi6rrqivbMUQcwAxu/0FT39kHQC CcZSjHVs2m7p+P3i7Jr6XtXtNF8p4eOUg0FfFKZOX2O+fH+9hIc8rC7pjUg5tdxjKNi77y PTLVnSmbL7HZro+R+jmwKIni0RUE+w8= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-619-rW9mBW4TM-Cc2Od0WTpl_A-1; Thu, 25 Aug 2022 08:12:53 -0400 X-MC-Unique: rW9mBW4TM-Cc2Od0WTpl_A-1 Received: by mail-wr1-f71.google.com with SMTP id r23-20020adfa157000000b00225660d47b7so1468130wrr.6 for ; Thu, 25 Aug 2022 05:12:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=8i+ljzn6MB/eBmFGfmQrAmtwmX21MBronF2Ff991Uq0=; b=UTAuPla/dUjzezHQ/UrR6DaZEUCL6EYnmYhGJM5OUlL7ndcd4ufh3npBYix7H2zbAK m9aHCKDw0TS5bcNnT0BYSP3UmkHSJqWjUxyYzdLEDzSA+vhuUiIab1mSa6g/sWhQ0u1j IHoqsv8T140Vu3O/XMfSiCUZyYVKet0NuXyepQlwnv4040Tlf2f04hYTVOnghtQEjSz9 Y9LXFpBfF05q1M7Bcql+yFKIH8dDryF4PdVhhjcuPiZctA5K/upvGuNHDQttoAMxPD+U R71h6RjOVmlLlOp5pXJlVH5nCsAP9rFZRK9aCVg6Ap/Kjnahwrx3t77A8Dotc2axxbHg X1AA== X-Gm-Message-State: ACgBeo1f1sOl2hUyeyPv7EJl7hp+m4DIdHo8lkHnA/3/X+iHV5xgpElW 3+R8fECd4s7uFS15+k/5UCpjfiG8ldO699tK4dUDCgwcr3bi/xS0/FINqC45D4L2JAQ7D4Vcmnv xj4LHcdZZEiE= X-Received: by 2002:a05:6000:250:b0:225:624b:13 with SMTP id m16-20020a056000025000b00225624b0013mr2006740wrz.127.1661429572667; Thu, 25 Aug 2022 05:12:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR4XU9Thjdw3dtY8hDYFZgZjn5H98wAmkQlzCVmgXAIYgtj8pToIYo+QGnxLFtQp8Qh/i6f5kw== X-Received: by 2002:a05:6000:250:b0:225:624b:13 with SMTP id m16-20020a056000025000b00225624b0013mr2006717wrz.127.1661429572383; Thu, 25 Aug 2022 05:12:52 -0700 (PDT) Received: from ?IPV6:2a09:80c0:192:0:20af:34be:985b:b6c8? ([2a09:80c0:192:0:20af:34be:985b:b6c8]) by smtp.gmail.com with ESMTPSA id n5-20020a05600c4f8500b003a601a1c2f7sm5259554wmq.19.2022.08.25.05.12.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Aug 2022 05:12:51 -0700 (PDT) Message-ID: Date: Thu, 25 Aug 2022 14:12:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 To: John Hubbard , 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 , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young References: <20220824163100.224449-1-david@redhat.com> <20220824163100.224449-2-david@redhat.com> <0db131cf-013e-6f0e-c90b-5c1e840d869c@nvidia.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH RFC 1/2] coding-style.rst: document BUG() and WARN() rules ("do not crash the kernel") In-Reply-To: <0db131cf-013e-6f0e-c90b-5c1e840d869c@nvidia.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661429575; a=rsa-sha256; cv=none; b=0ouzveogFuAYcV7VuzdmVONTTaEpoHUyYmRRMGU5y3weMonO0ga/J1esNDViPJM6zqBlYR uLYcfNKZ3yWhnW0/fDFYUknMWNqqjjQkBQobNdjn+Xu4NZRUO1DMDb3BtAsIrGAt/CpjWu vpL+id+HecXMAzyI5+OXo5fmQuw7zwc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RTG/Z4iO"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661429575; 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:dkim-signature; bh=8i+ljzn6MB/eBmFGfmQrAmtwmX21MBronF2Ff991Uq0=; b=gWGuWeYoAUqT88nqp9pDY6mqYy7GaGddz6ZVG5oIEQ0Yxjyrpcpcp236LQW3KkBWJHnTyf I0phNJBfKDrN1aOEGAYiEdkU+Bp019DEIg13zrhe4douKUOOCoEDXVQ2nGeBMxOTlr/Cnj B4nS9kRpgiDL1ICQzYD8LdrpUvZbZSM= X-Stat-Signature: dognfdgbq6qpcn1sknjn5z8tybfxeir7 X-Rspamd-Queue-Id: 6C18C140006 X-Rspam-User: X-Rspamd-Server: rspam11 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="RTG/Z4iO"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-HE-Tag: 1661429575-907063 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 24.08.22 23:59, John Hubbard wrote: > On 8/24/22 09:30, David Hildenbrand wrote: >> diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst >> index 03eb53fd029a..a6d81ff578fe 100644 >> --- a/Documentation/process/coding-style.rst >> +++ b/Documentation/process/coding-style.rst >> @@ -1186,6 +1186,33 @@ expression used. For instance: >> #endif /* CONFIG_SOMETHING */ >> > > I like the idea of adding this documentation, and this is the right > place. Naturally, if one likes something, one must immediately change > it. :) Therefore, here is an alternative writeup that I think captures > what you and the email threads were saying. > > How's this sound? Much better, thanks! :) > > diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst > index 03eb53fd029a..32df0d503388 100644 > --- a/Documentation/process/coding-style.rst > +++ b/Documentation/process/coding-style.rst > @@ -1185,6 +1185,53 @@ expression used. For instance: > ... > #endif /* CONFIG_SOMETHING */ > > +22) Do not crash the kernel > +--------------------------- > + > +Use WARN() rather than BUG() > +**************************** > + > +Do not add new code that uses any of the BUG() variants, such as BUG(), > +BUG_ON(), or VM_BUG_ON(). Instead, use a WARN*() variant, preferably > +WARN_ON_ONCE(), and possibly with recovery code. Recovery code is not required > +if there is no reasonable way to at least partially recover. I'll tend to keep in this section: "Unavoidable data corruption / security issues might be a very rare exception to this rule and need good justification." Because there are rare exceptions, and I'd much rather document the clear exception to this rule. > + > +Use WARN_ON_ONCE() rather than WARN() or WARN_ON() > +************************************************** > + > +WARN_ON_ONCE() is generally preferred over WARN() or WARN_ON(), because it is > +common for a given warning condition, if it occurs at all, to occur multiple > +times. (For example, once per file, or once per struct page.) This can fill up I'll drop the "For example" part. I feel like this doesn't really need an example -- most probably we've all been there already when the kernel log was flooded :) > +and wrap the kernel log, and can even slow the system enough that the excessive > +logging turns into its own, additional problem. > + > +Do not WARN lightly > +******************* > + > +WARN*() is intended for unexpected, this-should-never-happen situations. WARN*() > +macros are not to be used for anything that is expected to happen during normal > +operation. These are not pre- or post-condition asserts, for example. Again: > +WARN*() must not be used for a condition that is expected to trigger easily, for > +example, by user space actions. pr_warn_once() is a possible alternative, if you > +need to notify the user of a problem. > + > +Do not worry about panic_on_warn users > +************************************** > + > +A few more words about panic_on_warn: Remember that ``panic_on_warn`` is an > +available kernel option, and that many users set this option. This is why there > +is a "Do not WARN lightly" writeup, above. However, the existence of > +panic_on_warn users is not a valid reason to avoid the judicious use WARN*(). > +That is because, whoever enables panic_on_warn has explicitly asked the kernel > +to crash if a WARN*() fires, and such users must be prepared to deal with the > +consequences of a system that is somewhat more likely to crash. Side note: especially with kdump() I feel like we might see much more widespread use of panic_on_warn to be able to actually extract debug information in a controlled manner -- for example on enterprise distros. ... which would then make these systems more likely to crash, because there is no way to distinguish a rather harmless warning from a severe warning :/ . But let's see if some kdump() folks will share their opinion as reply to the cover letter. -- Thanks, David / dhildenb