Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1227253lqp; Sun, 14 Apr 2024 22:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXUoLucsauMI6Aih0hJ3YNUFuLEYfDmKsHTrHeGpG/q4nY6Esm4juJpAwhzMeFb9xSvIt9AuUxzwWp2VQO0dlmOAxXtdy1aQZFWtXVjIQ== X-Google-Smtp-Source: AGHT+IGSsnNdHYvA8x6VWMqm1s3ocadkweeDbhpOvj3Cvp5yCqoVw4hz2A+N8n5Ice5hXHh28hwT X-Received: by 2002:a50:cdd5:0:b0:56c:195d:b162 with SMTP id h21-20020a50cdd5000000b0056c195db162mr7874210edj.6.1713158512205; Sun, 14 Apr 2024 22:21:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713158512; cv=pass; d=google.com; s=arc-20160816; b=f/Q/0VS+yylkhwiHVEisdoZvdcs+N5UKgFGhjwngxz/i4NBYWCQi1siGb/C312G6ZF q57H29NljZN7rUNiIckQ5L6TlgBGWolA5NTGlFzvd+zH3798oT0OIVOOKUMYSKkyXS6E dgdRMJB8fErNdRYiPCsgqywsWpWVbUWyaw5zkzl7GesvLLL6KTOhBs80/qe2QQfzzdEK wGULRcKrc88AQq/azX3+UqNFoiurjwfixBuq537Y1tu6RlN68wLB+H4PT5b2on5QGkU4 Wb+8TVsr0acnJOpEzWdObzj4KQcElWxJa5nnh2UgHrKkTC5bpw+HghZobbpArQrrNVh3 o9nw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Snwf7HmNaKYslkZKRJcg7VC3bWKhRfTVmg3LKaXrmgA=; fh=UTGfig//7YKzpAuMDRd39Vjbx2jNUWVSJccH64jiq/I=; b=YOG4PLeZR1ZgkP2TqJj4fNPZnrxxrD8kUL14HPeSbOB9jjSbrnFX9oItBxAEMsVmko yFQtQQrIBbLeS1PhQL7sq5T2i6FvkLO1aV5aJcEELGIHINaDwlupoP07jp5LRZP2DVFd H5Let7tJhauy3Azuwtlg5DvqibIxRYiLqeyhL0M0Qx2bdYnCeesLAdGH1Q4Msf2JWRQH YVmHMASGyJDUJBsP+aj1ln/ISky0prcBnm8MshtTXeQLLNwLsKu0HhdUXSYPQ1TiS9C0 R6BTkjOfVsBvo3/Qem34jnVzDFiQ+8PtGs2TwYWO4GRNAKB5lJBve14HLTEnbL8vKE8x Mkpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fzOuenNS; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-144536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y7-20020a056402270700b0056dfabd3875si4272573edd.667.2024.04.14.22.21.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 22:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fzOuenNS; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-144536-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EC41F1F21CE9 for ; Mon, 15 Apr 2024 05:21:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 678224C9D; Mon, 15 Apr 2024 05:21:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="fzOuenNS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57289F9C8; Mon, 15 Apr 2024 05:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713158503; cv=none; b=nb8SqY2QLWw16b/qbIXFKfO5W9MreY2uxg4DAmlYTQBYUrUDxSyLV+sZE+8l80+p5F9FEc7ui11lIoBFXfE4BciedNgBtqvktlHaT/qBoG0h1iDFXKAy4KML3rbmWRk78L4QIGbxC4Iyl4HzdutJuygtVTKOv5n7uK/hZvReb2Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713158503; c=relaxed/simple; bh=nlsa6YgRAFchswkyn7KkmzAVbBm3XbY20uZqZXRwrnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=exiapsBbAp0+ZZ3TfAwadstCrKAq8OPNuUR2+3SnbKQujCG4aB4oXX0oGLqjapncYW4rJvUrrwyPUxaUIn10poDHY6LXGlJyLbaks8qyEXF7VeHxbxmLaFPmjFO/lFLjX5uLsLkMR28/jJr0VKPH2G9GtxkOavdGTvbpfZ6o86o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=fzOuenNS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EF97C113CC; Mon, 15 Apr 2024 05:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713158502; bh=nlsa6YgRAFchswkyn7KkmzAVbBm3XbY20uZqZXRwrnE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fzOuenNSgx06ppXJccfIqUwcs1fhWSId1+Mz3jtnG34Ep+W9tUwIcwm91dFZqJYgD 84sKXjWf9fJ3QY9u489oGiR33PkxTyyD4+I+0mfDnV/FNxNG4F/MxhC2hPl7LxtDWU DIKpgrRKfPy8i4BH7hjtnK4g1SjKZiJBu0UcFn5M= Date: Mon, 15 Apr 2024 07:21:37 +0200 From: Greg KH To: Laurent Pinchart Cc: Alex Elder , corbet@lwn.net, workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Documentation: coding-style: don't encourage WARN*() Message-ID: <2024041503-affidavit-stopwatch-72d7@gregkh> References: <20240414170850.148122-1-elder@linaro.org> <20240414194835.GA12561@pendragon.ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240414194835.GA12561@pendragon.ideasonboard.com> On Sun, Apr 14, 2024 at 10:48:35PM +0300, Laurent Pinchart wrote: > Hi Alex, > > Thank you for the patch. > > On Sun, Apr 14, 2024 at 12:08:50PM -0500, Alex Elder wrote: > > Several times recently Greg KH has admonished that variants of WARN() > > should not be used, because when the panic_on_warn kernel option is set, > > their use can lead to a panic. His reasoning was that the majority of > > Linux instances (including Android and cloud systems) run with this option > > enabled. And therefore a condition leading to a warning will frequently > > cause an undesirable panic. > > > > The "coding-style.rst" document says not to worry about this kernel > > option. Update it to provide a more nuanced explanation. > > > > Signed-off-by: Alex Elder > > --- > > Documentation/process/coding-style.rst | 21 +++++++++++---------- > > 1 file changed, 11 insertions(+), 10 deletions(-) > > > > diff --git a/Documentation/process/coding-style.rst b/Documentation/process/coding-style.rst > > index 9c7cf73473943..bce43b01721cb 100644 > > --- a/Documentation/process/coding-style.rst > > +++ b/Documentation/process/coding-style.rst > > @@ -1235,17 +1235,18 @@ 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 > > -************************************** > > +The panic_on_warn kernel option > > +******************************** > > > > -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. > > +Note that ``panic_on_warn`` is an available kernel option. If it is enabled, > > +a WARN*() call whose condition holds leads to a kernel panic. Many users > > +(including Android and many cloud providers) set this option, and this is > > +why there is a "Do not WARN lightly" writeup, above. > > + > > +The existence of this option is not a valid reason to avoid the judicious > > +use of warnings. There are other options: ``dev_warn*()`` and ``pr_warn*()`` > > +issue warnings but do **not** cause the kernel to crash. Use these if you > > +want to prevent such panics. > > Those options are not equivalent, they print a single message, which is > much easier to ignore. WARN() is similar to -Werror in some sense, it > pushes vendors to fix the warnings. I have used WARN() in the past to > indicate usage of long-deprecated APIs that we were getting close to > removing for instance. dev_warn() wouldn't have had the same effect. If you want to reboot a box because someone called an "improper" api, then sure, use WARN(), but that feels like a really bad idea. Just remove the api and fix up all in-kernel users instead. Why wait? If you want to show a traceback, then just print that out, but I've seen that totally ignored as well, removing the api is usually the only way to get people to actually notice, as then their builds break. thanks, greg k-h