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 4D3D7C54EE9 for ; Thu, 22 Sep 2022 14:12:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 964B7940007; Thu, 22 Sep 2022 10:12:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8ECBB6B0072; Thu, 22 Sep 2022 10:12:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D21940007; Thu, 22 Sep 2022 10:12:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6374C6B0071 for ; Thu, 22 Sep 2022 10:12:12 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3060A1411B1 for ; Thu, 22 Sep 2022 14:12:12 +0000 (UTC) X-FDA: 79939910904.07.B7B9010 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 5765912001C for ; Thu, 22 Sep 2022 14:12:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663855930; 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=Y/iFP6H1ozi01zUaORnvK3MXE2O4OXdY0B940ZuFJpQ=; b=L188jRMKXkk6qpP8V6cvQLe2EL8IcDDMvGZsg+GAEazgl/KMRAeZ0eLSFjfo7UfbG7Z+VS dXiSJ3PV6xS7eGo5dLThhayBaYUihvsW38pPDLYKBZIxyzvUcD+mrMFvTY7rb+9DGURRF8 n5GBbRv5TZbZaSfOry9h3ySw1Ni+Mso= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-17-dIIXOzxKNxmrzJ-MaiXKJg-1; Thu, 22 Sep 2022 10:12:09 -0400 X-MC-Unique: dIIXOzxKNxmrzJ-MaiXKJg-1 Received: by mail-wr1-f72.google.com with SMTP id v22-20020adf8b56000000b0022af189148bso3329848wra.22 for ; Thu, 22 Sep 2022 07:12:09 -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:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=Y/iFP6H1ozi01zUaORnvK3MXE2O4OXdY0B940ZuFJpQ=; b=ahtOiFbpLNXcvlzsEZSMz0KJ8NS0LZdM47w9EwcTA6JzFBJ1JwWK7nKUbl9ykhchWO gDqHNEnQZOXV5Dbc89dYpmacSY35miFeL3dnSvntqu8w2Y2gi0cKbs+QZZRXqim4+Vfv 1MyG95z6XLDuJeHqGvGATW/zWQVR16A5PVvaKsRfXn3nKoiqZgzhd3z7pN0MFzdUROt5 B6FZfInpy7zQz/uK7d/Omq/0rEChaCx1xRDkVNhcOz3X4IbGNwSwr0WFPLzIGexlXJ6/ P+V9BQ9YkQCMEUC25oiYLm1AfM/JQ7PS4i4ic7sXcojzxHkThPyKdHtn13EqiR5mIz/a LM+A== X-Gm-Message-State: ACrzQf0+UzzzX8EpWNyUrlhX0DIOLKyNZ4xAN3uCvz/MCccwmOKTZq4Q /g4CIKAJTh2XonulLDRLVO4R9FOHMY55m6J4qClkByUGLP2E1pIsYdrp8u2Zm3/j8DWJfvKw+YL Jwc7wexzY7HU= X-Received: by 2002:a5d:59c4:0:b0:22b:237c:3e23 with SMTP id v4-20020a5d59c4000000b0022b237c3e23mr2314026wry.291.1663855928452; Thu, 22 Sep 2022 07:12:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qIYRASR2IfsvAvIir7beVokLpyQg1uzYzGbKfWQNOhgzM7pV5+gao6b9nQQt3+MNJlTYtjA== X-Received: by 2002:a5d:59c4:0:b0:22b:237c:3e23 with SMTP id v4-20020a5d59c4000000b0022b237c3e23mr2314002wry.291.1663855928114; Thu, 22 Sep 2022 07:12:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c708:2200:d595:cc20:2e3a:fc5f? (p200300cbc7082200d595cc202e3afc5f.dip0.t-ipconnect.de. [2003:cb:c708:2200:d595:cc20:2e3a:fc5f]) by smtp.gmail.com with ESMTPSA id bt25-20020a056000081900b00228d52b935asm5332956wrb.71.2022.09.22.07.12.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 07:12:07 -0700 (PDT) Message-ID: Date: Thu, 22 Sep 2022 16:12:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH v1 1/3] coding-style.rst: document BUG() and WARN() rules ("do not crash the kernel") To: Kalle Valo Cc: linux-kernel@vger.kernel.org, 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 , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young , Jani Nikula , Michael Ellerman , Nicholas Piggin , Christophe Leroy References: <20220920122302.99195-1-david@redhat.com> <20220920122302.99195-2-david@redhat.com> <87pmfp8hnj.fsf@kernel.org> From: David Hildenbrand Organization: Red Hat In-Reply-To: <87pmfp8hnj.fsf@kernel.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663855931; 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=Y/iFP6H1ozi01zUaORnvK3MXE2O4OXdY0B940ZuFJpQ=; b=s0OYzA5cpHY1imgX1aCJtrX96/HiIQ6/UMf/bd2ijM8VgD5uAyZ9n2hSS894LT1J076Q0W X9QUNwM+039JupO4d3OZ66z1b0uuC1fl2rrKquwg4zEcA4QTut+v2nnLddNSlp3eTAODZb 8lB4pezc9S3rXhXXCB5ybLJmwQzbpOs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L188jRMK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663855931; a=rsa-sha256; cv=none; b=xpIlH5a6bGGgZNXrNhT2zULCpSTDJb/9nldpdNvrmW7TDcnQpWgWCNI4Djs7V5E3hXahw+ cz6jBaquQH3xEcdp9GuG++bcQ1OAqk3pwhjYoNu5hh1eSS4HGXBlbW279wZRgR0t4XvUcV MK6aPQg271uRK7iAP6qf1rIYeL2FTdE= X-Rspam-User: X-Stat-Signature: joutk6j4isk1s6sa5pwbh5ju4pwej6o4 X-Rspamd-Queue-Id: 5765912001C Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L188jRMK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam08 X-HE-Tag: 1663855931-336922 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 21.09.22 06:40, Kalle Valo wrote: > David Hildenbrand writes: > >> Linus notes [1] that the introduction of new code that uses VM_BUG_ON() >> is just as bad as BUG_ON(), because it will crash the kernel on >> distributions that enable CONFIG_DEBUG_VM (like Fedora): >> >> 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". [2] >> >> This resulted in a more generic discussion about usage of BUG() and >> friends. While there might be corner cases that still deserve a BUG_ON(), >> most BUG_ON() cases should simply use WARN_ON_ONCE() and implement a >> recovery path if reasonable: >> >> The only possible case where BUG_ON can validly be used is "I have >> some fundamental data corruption and cannot possibly return an >> error". [2] >> >> As a very good approximation is the general rule: >> >> "absolutely no new BUG_ON() calls _ever_" [2] >> >> ... not even if something really shouldn't ever happen and is merely for >> documenting that an invariant always has to hold. However, there are sill >> exceptions where BUG_ON() may be used: >> >> If you have a "this is major internal corruption, there's no way we can >> continue", then BUG_ON() is appropriate. [3] >> >> There is only one good BUG_ON(): >> >> Now, that said, there is one very valid sub-form of BUG_ON(): >> BUILD_BUG_ON() is absolutely 100% fine. [2] >> >> While WARN will also crash the machine with panic_on_warn set, that's >> exactly to be expected: >> >> So we have two very different cases: the "virtual machine with good >> logging where a dead machine is fine" - use 'panic_on_warn'. And >> the actual real hardware with real drivers, running real loads by >> users. [4] >> >> The basic idea is that warnings will similarly get reported by users >> and be found during testing. However, in contrast to a BUG(), there is a >> way to actually influence the expected behavior (e.g., panic_on_warn) >> and to eventually keep the machine alive to extract some debug info. >> >> Ingo notes that not all WARN_ON_ONCE cases need recovery. If we don't ever >> expect this code to trigger in any case, recovery code is not really >> helpful. >> >> I'd prefer to keep all these warnings 'simple' - i.e. no attempted >> recovery & control flow, unless we ever expect these to trigger. >> [5] >> >> There have been different rules floating around that were never properly >> documented. Let's try to clarify. >> >> [1] https://lkml.kernel.org/r/CAHk-=wiEAH+ojSpAgx_Ep=NKPWHU8AdO3V56BXcCsU97oYJ1EA@mail.gmail.com >> [2] https://lore.kernel.org/r/CAHk-=wg40EAZofO16Eviaj7mfqDhZ2gVEbvfsMf6gYzspRjYvw@mail.gmail.com >> [2] https://lkml.kernel.org/r/CAHk-=wit-DmhMfQErY29JSPjFgebx_Ld+pnerc4J2Ag990WwAA@mail.gmail.com >> [4] https://lore.kernel.org/r/CAHk-=wgF7K2gSSpy=m_=K3Nov4zaceUX9puQf1TjkTJLA2XC_g@mail.gmail.com >> [5] https://lore.kernel.org/r/YwIW+mVeZoTOxn%2F4@gmail.com >> >> Signed-off-by: David Hildenbrand > > [...] > >> +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. This can fill up and wrap the kernel log, and can even slow >> +the system enough that the excessive logging turns into its own, additional >> +problem. > > FWIW I have had cases where WARN() messages caused a reboot, maybe > mention that here? In my case the logging was so excessive that the > watchdog wasn't updated and in the end the device was forcefully > rebooted. > That should be covered by the last part, no? What would be your suggestion? -- Thanks, David / dhildenb