Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp598182imm; Wed, 20 Jun 2018 03:38:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJSY6dwS18nOw5RFDl0Zjazv2T/6Ab52ZacLRsbgXepio+9zluVoakuRZpB4psA79s/fePD X-Received: by 2002:a65:40c3:: with SMTP id u3-v6mr18267456pgp.356.1529491102945; Wed, 20 Jun 2018 03:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529491102; cv=none; d=google.com; s=arc-20160816; b=um0LjY37fGnVYDgaAIj4rT2qJiJSBAXDe2nujmTNr6UkZ8hH/UWLtA99vzqfMGIBQ7 UWuH/w0JKyVSFUEo4LtZtZvXbSGpVjmlPQE1J/k58joUEWs3o6YZVuGvm9xYiqECqdS9 Itx6KfsT1B8elS4sK9gEXXqmIVWP5Uinejnzka7NUenXUcLF+g9bnkzJPSRkfjzlErHT z3JL1FC0o1JscAZBDuMnt0X0nnL2kkTSOay+Dbe15YGYF64af9isI0WUoMgvocoACghq fXBZl98xfPVUKaZ1y0ZIw7yfLEPETGtjYr4mSj7VxGcjkP07/KakkMegUdH6puEXluFa Eogw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=6s+p1TIw0pBcs/Fh+j/cgRtp6ZB9xEU7re7j+lxdpjQ=; b=i8bkUP0+D5ycmnZPo+P2HtHbihmX9C+X7kAeiE3zluGUvPjQXSs3RRuchxY4GD8iUs 2yKV+JyUtInwMQnxnFN3kk+s5L3r9m708G6+iC09bFPU2fuUm//7EP+7lMfXZLJqlCVV /Xp5VRufQN1XhIjbE8KO0+G2+fIuwzt/D32kO/CuZX2mEdkRzopu310zedZfi37a/6Q3 sGzOxYjPqbgMkfhKFrXxLkAi4++6YnISaPMll6XO2Ov/cDsa9rzRnD3Z+m2fdABpFwKZ uRmwQ1B/hpeNy5OwYeNWsmjKRJPH7xQL76l3e2aAPnXoOEFNnw1pEe/IUPWWrwvLc7w3 g9pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O5qvnv+h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r25-v6si1617239pgd.74.2018.06.20.03.38.08; Wed, 20 Jun 2018 03:38:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=O5qvnv+h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754077AbeFTKh1 (ORCPT + 99 others); Wed, 20 Jun 2018 06:37:27 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40068 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbeFTKh0 (ORCPT ); Wed, 20 Jun 2018 06:37:26 -0400 Received: by mail-wm0-f67.google.com with SMTP id n5-v6so5879655wmc.5 for ; Wed, 20 Jun 2018 03:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6s+p1TIw0pBcs/Fh+j/cgRtp6ZB9xEU7re7j+lxdpjQ=; b=O5qvnv+hHg0fdhBwUG0wlAnuURNEfGZMzYOr3bjiHF5yhbgcrnM9grlBCUnko3YrFG 4O5x9f80gnpuy/dqq6kvOIJwEoVv/fs43A97elW7xNNo3MmJs/eJ7vOYM7zfxDvUQHYU Ny2WzBUCwJNVTzg03IINmn0WThLiALgVUsobLVPhtJH+xZr6fAflOEO9OpbTLPzxTejJ P2OklyvUBIEdBMsntPHbfC49WZ1uI3U2+q6mhYhhLvz2uEWaRjclO3JKaw0TPCLAcpIe kMM90pwBVAeHG59OVRQBXUZh8m8f6ZAUWivIEHKhAo/MLxByNzq8AnEWy2b8YUYvYPl0 504Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6s+p1TIw0pBcs/Fh+j/cgRtp6ZB9xEU7re7j+lxdpjQ=; b=Qp9iKEO4z6DmYzl8uwNDLNykkDNFLv0wTf5lcGNEP08tuDmZ4g6IlmoBttH+5MzuAN SPJzgdrnZCbOumPvlzx3x9C304fS6uaqyQ7ZeoqSlEYpVlGAUk7udLYCIAjEFGqkz2gM mV4CWyWjQCz/1Dp7E9EgJ3DKOtERSL8wKYEspVWMnkM90PZO2vhhFRlvwjzgTSzO4hoc u+C1BRYASPQcN6Be4PioMnjyripRZoA0IvxGZNEQaOnGKsOnRDl1hFPf/NUNlUTyxPy3 kQGLmJwXmvefFmxiXFOjV0yAlZwB9lwpSNV5XUCDYojnpyrKJdqvmVzXDBucqAvSiNeu 9p+Q== X-Gm-Message-State: APt69E22DNCRHpXE8i+Hca1/NoqeBe98xF54tH0sAzxZ5zQ8tp6TZ8iU 0CdC4/FT4qAct8xW2Wv71TqvRA== X-Received: by 2002:a1c:b211:: with SMTP id b17-v6mr1171088wmf.74.1529491044787; Wed, 20 Jun 2018 03:37:24 -0700 (PDT) Received: from dvyukov-z840.muc.corp.google.com ([2a00:79e0:15:10:8971:4ae9:dd1c:10e]) by smtp.gmail.com with ESMTPSA id e81-v6sm3567427wmi.28.2018.06.20.03.37.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 03:37:23 -0700 (PDT) From: Dmitry Vyukov To: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, akpm@linux-foundation.org, torvalds@linux-foundation.org Cc: Dmitry Vyukov Subject: [PATCH] include/asm-generic/bug.h: clarify valid uses of WARN() Date: Wed, 20 Jun 2018 12:37:16 +0200 Message-Id: <20180620103716.61636-1-dvyukov@gmail.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Vyukov Explicitly state that WARN*() should be used only for recoverable kernel issues/bugs and that it should not be used for any kind of invalid external inputs or transient conditions. Motivation: it's a very useful capability to be able to understand if a particular kernel splat means a kernel bug or simply an invalid user-space program. For the former one wants to notify kernel developers, while notifying kernel developers for the latter is annoying. Even a kernel developer may not know what to do with a WARNING in an unfamiliar subsystem. This is especially critical for any automated testing systems that may use panic_on_warn and mail kernel developers. The clear separation also serves as an additional documentation: is it a condition that must never occur because of additional checks/logic elsewhere? or is it simply a check for invalid inputs or unfortunate conditions? Use of pr_err() for user messages also leads to better error messages. "Something is wrong in file foo on line X" is not particularly useful message for end user. pr_err() forces developers to write more meaningful error messages for user. As of now we are almost there. We are doing systematic kernel testing with panic_on_warn and are not seeing massive amounts of false positives. But every now and then another WARN on ENOMEM or invalid inputs pops up and leads to a lengthy argument each time. The goal of this change is to officially document the rules. Signed-off-by: Dmitry Vyukov --- include/asm-generic/bug.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index a7613e1b0c87..20561a60db9c 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -75,9 +75,19 @@ struct bug_entry { /* * WARN(), WARN_ON(), WARN_ON_ONCE, and so on can be used to report - * significant issues that need prompt attention if they should ever - * appear at runtime. Use the versions with printk format strings - * to provide better diagnostics. + * significant kernel issues that need prompt attention if they should ever + * appear at runtime. + * + * Do not use these macros when checking for invalid external inputs + * (e.g. invalid system call arguments, or invalid data coming from + * network/devices), and on transient conditions like ENOMEM or EAGAIN. + * These macros should be used for recoverable kernel issues only. + * For invalid external inputs, transient conditions, etc use + * pr_err[_once/_ratelimited]() followed by dump_stack(), if necessary. + * Do not include "BUG"/"WARNING" in format strings manually to make these + * conditions distinguishable from kernel issues. + * + * Use the versions with printk format strings to provide better diagnostics. */ #ifndef __WARN_TAINT extern __printf(3, 4) -- 2.18.0.rc1.244.gcf134e6275-goog