Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp829762rwe; Wed, 24 Aug 2022 09:35:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR7eiwqeihKHIHo6ypdMxMfwCZHhUCaSCKtS8DAqUcCABXcnm4v8LYxhb/J6woRKUSxnXJNw X-Received: by 2002:aa7:c7da:0:b0:440:d482:36b5 with SMTP id o26-20020aa7c7da000000b00440d48236b5mr8379837eds.21.1661358915199; Wed, 24 Aug 2022 09:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661358915; cv=none; d=google.com; s=arc-20160816; b=CXoUy/AuhCJhncUPJZbrWnTiZFm40/VwWpVblYa0937Ks3c2dflBcpeoMXbMlhMHgF VxOFyRAifxqpMWEpcUgjbc+0xYGyvMlGzIbZKNHDN0lPmRxEzqq9yfv7kulmyg8fyK/N Kmt1G1wQIXXCKUXxbg25JWS3cQS5c9VPVAnWrTb8QnPndzRC1pmrW1OLI30rXByHsJpE hMbaa21UUvmR63U+Ug6wDaUTTOA04uxJO4RTMRLYm0RXvyBaAbYdBX5XVWsJFxlb4GAF CttgWD00+8a5SUYbzzxfkWL/KszZb3nD030T3hn9+V1PjfkQPLh2Jp5WduHJl3Nxy4MM jUXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=1Meo/JVVOcnrflu5rlIGOgtbrV+Zw+zKCUGgyNys75s=; b=gZzo72ksx2yX7fqk5nFV/UTUDC1ryrofvk6erbgctkDONzJX7VKxm6pHY9eI65Aggk Go4h1NeaOQJeYPBVH2zmi6vkmKJgosnuvZP5+RXrr1bTXQuxGQ+K+ulBFp3ZBVdE/fUB G/T/6Fmd/l6oZ1c3S8vNnZKhZSsoIz/tYvDBgS3ib+9WyGS3ZFHJKzaB/qUgVNLmEipI emGa2Rwrz4ZCl4GMyQfwEh8geCVUsT40VaUBVanyevbrfudKX7YYfkA3I5evKYa68DzI yM6dX/ck3ie89ST9UpQOTa/OYHILwns3invlXyjwp8V20H7OoZKbqQJcpElvtijD3w57 Vyww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LVR0GDn0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp25-20020a1709073e1900b0073dbc331a40si1566310ejc.188.2022.08.24.09.34.47; Wed, 24 Aug 2022 09:35:14 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LVR0GDn0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239381AbiHXQd1 (ORCPT + 99 others); Wed, 24 Aug 2022 12:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239845AbiHXQbK (ORCPT ); Wed, 24 Aug 2022 12:31:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19C31923FA for ; Wed, 24 Aug 2022 09:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661358668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=1Meo/JVVOcnrflu5rlIGOgtbrV+Zw+zKCUGgyNys75s=; b=LVR0GDn0LlyANRjs6QyFyC51RNHINXxrk/oxc4e4Eyz4x7AYogbT/ptBti4eew3Fw995Gv ZTRLPg7pi56roHhW3+JXFaabrR38l2Hi8sNJuiMIyq3ysEkddR5rGQY+QPBU5j0DQ660BA ftK9nY4n6FKyTRLpClmSIsZmfxefqV8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-1hJq29stMFOCbma2_vFXbA-1; Wed, 24 Aug 2022 12:31:06 -0400 X-MC-Unique: 1hJq29stMFOCbma2_vFXbA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17417185A7B2; Wed, 24 Aug 2022 16:31:06 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.193.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D4C6492C3B; Wed, 24 Aug 2022 16:31:02 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, kexec@lists.infradead.org, David Hildenbrand , Linus Torvalds , Andrew Morton , Ingo Molnar , David Laight , Jonathan Corbet , Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , Baoquan He , Vivek Goyal , Dave Young Subject: [PATCH RFC 0/2] coding-style.rst: document BUG() and WARN() rules Date: Wed, 24 Aug 2022 18:30:58 +0200 Message-Id: <20220824163100.224449-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 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 As it seems to be rather unclear if/when to use BUG(), BUG_ON(), VM_BUG_ON(), WARN_ON_ONCE(), ... let's try to document the result of a recent discussion. Details can be found in patch #1. -------------------------------------------------------------------------- Here is some braindump after thinking about BUG_ON(), WARN_ON(), ... and how it interacts with kdump. I was wondering what the expectation on a system with armed kdump are, for example, after we removed most BUG_ON() instances and replaced them by WARN_ON_ONCE(). I would assume that we actually want to panic in some cases to capture a proper system dump instead of continuing and eventually ending up with a completely broken system where it's hard to extract any useful debug information. We'd have to enable panic_on_warn. But we'd only want to do that in case kdump is actually armed after boot. So one idea would be to have some kind of "panic_on_warn_with_kdump" mode. But then, we'd actually crash+kdump even on the most harmless WARN_ON() conditions, because they all look alike. To compensate, we would need some kind of "severity" levels of a warning -- at least some kind of "this is harmless and we can easily recover, but please tell the developers" vs. "this is real bad and unexpected, capture a dump immediately instead of trying to recover and eventually failing miserably". But then, maybe we really want something like BUG_ON() -- let's call it CBUG_ON() for simplicity -- but be able to make it be usable in conditionals (to implement recovery code if easily possible) and make the runtime behavior configurable. if (CBUG_ON(whatever)) try_to_recover() Whereby, for example, "panic_on_cbug" and "panic_on_cbug_with_kdump" could control the runtime behavior. But this is just a braindump and I assume people reading along have other, better ideas. Especially, a better name for CBUG. Cc: Linus Torvalds Cc: Andrew Morton Cc: Ingo Molnar Cc: David Laight Cc: Jonathan Corbet Cc: Andy Whitcroft Cc: Joe Perches Cc: Dwaipayan Ray Cc: Lukas Bulwahn Cc: Baoquan He Cc: Vivek Goyal Cc: Dave Young David Hildenbrand (2): coding-style.rst: document BUG() and WARN() rules ("do not crash the kernel") checkpatch: warn on usage of VM_BUG_ON() and friends Documentation/process/coding-style.rst | 27 ++++++++++++++++++++++++++ scripts/checkpatch.pl | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) -- 2.37.1