From patchwork Tue May 10 03:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12844518 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E2D5C433F5 for ; Tue, 10 May 2022 03:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235754AbiEJEBr (ORCPT ); Tue, 10 May 2022 00:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiEJEBo (ORCPT ); Tue, 10 May 2022 00:01:44 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2E0E2A975B for ; Mon, 9 May 2022 20:57:47 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id x88so3271181pjj.1 for ; Mon, 09 May 2022 20:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qW7Is/QI3iQbuuzWT6xbPmVOxR+S49NUMee/eBkfZUo=; b=hK7Ab4WNqA9FkHGb09k7+80YlDUcc38CDO87vf+IZ8o+GOiaTqmx5BO4dqrKdiKDxn YE8+XFqSzwZjsyM6BI/ZEftgv2N4Nh4eGlj6b8VgdPl5c2emb7/Egs9kpLwJXO7dwhPj fz4BHCfmEgom3FSzu3+CK6cl4hKzWKbC22Aqc7EX9RoAVyo6GcpM1S9p1hcWt7hz1YZt 31SGvMsn4jeYpA8FPAiDwHQV0ywBoNyJSA/b7znxuNNdeo+ci2IjxuzMluMtI4dnAg21 eWxRdaqqvRrt/N4Ii6C4wuP4WtdzCc6fyYMjf0o4FbdqyPdfESNqU8GiJn6AwDpJ/1ba zKPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qW7Is/QI3iQbuuzWT6xbPmVOxR+S49NUMee/eBkfZUo=; b=6tMDHnTxz7X8bSP46cyd4T35bLXPi0ThFg6HCrvi5/2ptW/pr3fnpwSYUfbg9Xtpw6 EHjbTjc0OKMSfBOriLnCqdmqoQ8MSN3+EbAl0Cf6ikSIA3aBSajyakuvSkZp+Bh5sHlq Rip5hj2+4u9QYsRfpftagCQcNT5YypvgN9CPBd1ChtNN/rYYG/ErMFoDaARWsi9S8cvN v6wu29Z4Fxz0xMGnOmFShDATPtgL3z3H02ONd8naufIVd1zxISwwNCfCyh68WlMlZpq7 DX7ztaNkUzDZ3WYbL0E9/dqoE+ol2XarGez8D79IMRdG5F59xTdww1nPML0RQCAmVnIw xp9A== X-Gm-Message-State: AOAM533hTWJ4lI3XC3fiOmqMemEeL4w6QFIZG3fLno23BOb1Dmt13jQM 6yfdOQo4UrDvBqa9+u/LtmjKv8KgY4w= X-Google-Smtp-Source: ABdhPJwwPkE6adcIWcd1cdalBbTYny2EaQl2a0+YZ7OpxSDGRdM0Y2icMtRnO+ICag9yKgKjzCo1wQ== X-Received: by 2002:a17:90b:17c3:b0:1dc:3f12:1dbc with SMTP id me3-20020a17090b17c300b001dc3f121dbcmr21045587pjb.169.1652155067465; Mon, 09 May 2022 20:57:47 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id d12-20020a17090ad3cc00b001d81a30c437sm568193pjw.50.2022.05.09.20.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 20:57:47 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 1/5] net: add include/net/net_debug.h Date: Mon, 9 May 2022 20:57:37 -0700 Message-Id: <20220510035741.2807829-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220510035741.2807829-1-eric.dumazet@gmail.com> References: <20220510035741.2807829-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Remove from include/linux/netdevice.h helpers that send debug/info/warnings to syslog. We plan adding more helpers in following patches. v2: added two includes, and 'struct net_device' forward declaration to avoid compile errors (kernel bots) Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 141 +---------------------------------- include/net/net_debug.h | 151 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+), 140 deletions(-) create mode 100644 include/net/net_debug.h diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 74c97a34921d48c593c08e2bed72e099f42520a3..5fb1de931bcb9d0caaa5449169012b192d69d892 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -50,6 +50,7 @@ #include #include #include +#include struct netpoll_info; struct device; @@ -5050,81 +5051,9 @@ static inline const char *netdev_reg_state(const struct net_device *dev) return " (unknown)"; } -__printf(3, 4) __cold -void netdev_printk(const char *level, const struct net_device *dev, - const char *format, ...); -__printf(2, 3) __cold -void netdev_emerg(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_alert(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_crit(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_err(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_warn(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_notice(const struct net_device *dev, const char *format, ...); -__printf(2, 3) __cold -void netdev_info(const struct net_device *dev, const char *format, ...); - -#define netdev_level_once(level, dev, fmt, ...) \ -do { \ - static bool __section(".data.once") __print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - netdev_printk(level, dev, fmt, ##__VA_ARGS__); \ - } \ -} while (0) - -#define netdev_emerg_once(dev, fmt, ...) \ - netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__) -#define netdev_alert_once(dev, fmt, ...) \ - netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__) -#define netdev_crit_once(dev, fmt, ...) \ - netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__) -#define netdev_err_once(dev, fmt, ...) \ - netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__) -#define netdev_warn_once(dev, fmt, ...) \ - netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__) -#define netdev_notice_once(dev, fmt, ...) \ - netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__) -#define netdev_info_once(dev, fmt, ...) \ - netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__) - #define MODULE_ALIAS_NETDEV(device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG) || \ - (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) -#define netdev_dbg(__dev, format, args...) \ -do { \ - dynamic_netdev_dbg(__dev, format, ##args); \ -} while (0) -#elif defined(DEBUG) -#define netdev_dbg(__dev, format, args...) \ - netdev_printk(KERN_DEBUG, __dev, format, ##args) -#else -#define netdev_dbg(__dev, format, args...) \ -({ \ - if (0) \ - netdev_printk(KERN_DEBUG, __dev, format, ##args); \ -}) -#endif - -#if defined(VERBOSE_DEBUG) -#define netdev_vdbg netdev_dbg -#else - -#define netdev_vdbg(dev, format, args...) \ -({ \ - if (0) \ - netdev_printk(KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif - /* * netdev_WARN() acts like dev_printk(), but with the key difference * of using a WARN/WARN_ON to get the message out, including the @@ -5138,74 +5067,6 @@ do { \ WARN_ONCE(1, "netdevice: %s%s: " format, netdev_name(dev), \ netdev_reg_state(dev), ##args) -/* netif printk helpers, similar to netdev_printk */ - -#define netif_printk(priv, type, level, dev, fmt, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - netdev_printk(level, (dev), fmt, ##args); \ -} while (0) - -#define netif_level(level, priv, type, dev, fmt, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - netdev_##level(dev, fmt, ##args); \ -} while (0) - -#define netif_emerg(priv, type, dev, fmt, args...) \ - netif_level(emerg, priv, type, dev, fmt, ##args) -#define netif_alert(priv, type, dev, fmt, args...) \ - netif_level(alert, priv, type, dev, fmt, ##args) -#define netif_crit(priv, type, dev, fmt, args...) \ - netif_level(crit, priv, type, dev, fmt, ##args) -#define netif_err(priv, type, dev, fmt, args...) \ - netif_level(err, priv, type, dev, fmt, ##args) -#define netif_warn(priv, type, dev, fmt, args...) \ - netif_level(warn, priv, type, dev, fmt, ##args) -#define netif_notice(priv, type, dev, fmt, args...) \ - netif_level(notice, priv, type, dev, fmt, ##args) -#define netif_info(priv, type, dev, fmt, args...) \ - netif_level(info, priv, type, dev, fmt, ##args) - -#if defined(CONFIG_DYNAMIC_DEBUG) || \ - (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) -#define netif_dbg(priv, type, netdev, format, args...) \ -do { \ - if (netif_msg_##type(priv)) \ - dynamic_netdev_dbg(netdev, format, ##args); \ -} while (0) -#elif defined(DEBUG) -#define netif_dbg(priv, type, dev, format, args...) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) -#else -#define netif_dbg(priv, type, dev, format, args...) \ -({ \ - if (0) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif - -/* if @cond then downgrade to debug, else print at @level */ -#define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \ - do { \ - if (cond) \ - netif_dbg(priv, type, netdev, fmt, ##args); \ - else \ - netif_ ## level(priv, type, netdev, fmt, ##args); \ - } while (0) - -#if defined(VERBOSE_DEBUG) -#define netif_vdbg netif_dbg -#else -#define netif_vdbg(priv, type, dev, format, args...) \ -({ \ - if (0) \ - netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ - 0; \ -}) -#endif - /* * The list of packet types we will receive (as opposed to discard) * and the routines to invoke. diff --git a/include/net/net_debug.h b/include/net/net_debug.h new file mode 100644 index 0000000000000000000000000000000000000000..19cd2700c20ea9945ae7662bacfa50f5d2bed398 --- /dev/null +++ b/include/net/net_debug.h @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_NET_DEBUG_H +#define _LINUX_NET_DEBUG_H + +#include +#include + +struct net_device; + +__printf(3, 4) __cold +void netdev_printk(const char *level, const struct net_device *dev, + const char *format, ...); +__printf(2, 3) __cold +void netdev_emerg(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_alert(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_crit(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_err(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_warn(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_notice(const struct net_device *dev, const char *format, ...); +__printf(2, 3) __cold +void netdev_info(const struct net_device *dev, const char *format, ...); + +#define netdev_level_once(level, dev, fmt, ...) \ +do { \ + static bool __section(".data.once") __print_once; \ + \ + if (!__print_once) { \ + __print_once = true; \ + netdev_printk(level, dev, fmt, ##__VA_ARGS__); \ + } \ +} while (0) + +#define netdev_emerg_once(dev, fmt, ...) \ + netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__) +#define netdev_alert_once(dev, fmt, ...) \ + netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__) +#define netdev_crit_once(dev, fmt, ...) \ + netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__) +#define netdev_err_once(dev, fmt, ...) \ + netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__) +#define netdev_warn_once(dev, fmt, ...) \ + netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__) +#define netdev_notice_once(dev, fmt, ...) \ + netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__) +#define netdev_info_once(dev, fmt, ...) \ + netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__) + +#if defined(CONFIG_DYNAMIC_DEBUG) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) +#define netdev_dbg(__dev, format, args...) \ +do { \ + dynamic_netdev_dbg(__dev, format, ##args); \ +} while (0) +#elif defined(DEBUG) +#define netdev_dbg(__dev, format, args...) \ + netdev_printk(KERN_DEBUG, __dev, format, ##args) +#else +#define netdev_dbg(__dev, format, args...) \ +({ \ + if (0) \ + netdev_printk(KERN_DEBUG, __dev, format, ##args); \ +}) +#endif + +#if defined(VERBOSE_DEBUG) +#define netdev_vdbg netdev_dbg +#else + +#define netdev_vdbg(dev, format, args...) \ +({ \ + if (0) \ + netdev_printk(KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif + +/* netif printk helpers, similar to netdev_printk */ + +#define netif_printk(priv, type, level, dev, fmt, args...) \ +do { \ + if (netif_msg_##type(priv)) \ + netdev_printk(level, (dev), fmt, ##args); \ +} while (0) + +#define netif_level(level, priv, type, dev, fmt, args...) \ +do { \ + if (netif_msg_##type(priv)) \ + netdev_##level(dev, fmt, ##args); \ +} while (0) + +#define netif_emerg(priv, type, dev, fmt, args...) \ + netif_level(emerg, priv, type, dev, fmt, ##args) +#define netif_alert(priv, type, dev, fmt, args...) \ + netif_level(alert, priv, type, dev, fmt, ##args) +#define netif_crit(priv, type, dev, fmt, args...) \ + netif_level(crit, priv, type, dev, fmt, ##args) +#define netif_err(priv, type, dev, fmt, args...) \ + netif_level(err, priv, type, dev, fmt, ##args) +#define netif_warn(priv, type, dev, fmt, args...) \ + netif_level(warn, priv, type, dev, fmt, ##args) +#define netif_notice(priv, type, dev, fmt, args...) \ + netif_level(notice, priv, type, dev, fmt, ##args) +#define netif_info(priv, type, dev, fmt, args...) \ + netif_level(info, priv, type, dev, fmt, ##args) + +#if defined(CONFIG_DYNAMIC_DEBUG) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE)) +#define netif_dbg(priv, type, netdev, format, args...) \ +do { \ + if (netif_msg_##type(priv)) \ + dynamic_netdev_dbg(netdev, format, ##args); \ +} while (0) +#elif defined(DEBUG) +#define netif_dbg(priv, type, dev, format, args...) \ + netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) +#else +#define netif_dbg(priv, type, dev, format, args...) \ +({ \ + if (0) \ + netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif + +/* if @cond then downgrade to debug, else print at @level */ +#define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \ + do { \ + if (cond) \ + netif_dbg(priv, type, netdev, fmt, ##args); \ + else \ + netif_ ## level(priv, type, netdev, fmt, ##args); \ + } while (0) + +#if defined(VERBOSE_DEBUG) +#define netif_vdbg netif_dbg +#else +#define netif_vdbg(priv, type, dev, format, args...) \ +({ \ + if (0) \ + netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif + + +#endif /* _LINUX_NET_DEBUG_H */ From patchwork Tue May 10 03:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12844519 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BC57C433F5 for ; Tue, 10 May 2022 03:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbiEJEBy (ORCPT ); Tue, 10 May 2022 00:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235308AbiEJEBq (ORCPT ); Tue, 10 May 2022 00:01:46 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F5D42A9CD8 for ; Mon, 9 May 2022 20:57:49 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id fv2so14812852pjb.4 for ; Mon, 09 May 2022 20:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TMfX5GLFh57pG2QX7283Ze9GK6r5LOYCLbe0PSu2BLw=; b=HcmAKU85ARqCeDN0Qul1H3gJrtJhxNA6un3sKMdyuqXt6P8D3yeBC6xXfOM8c22DCu qDPQbR6bLLUwzk3meg6bzlmN8xvShrA7gMvYLxxnam9KusoE+6CgqwMZIC2Z6k9RGg7A Wt77YqzT8IyzNjfKeXMpJ0G5/TP/wJmo6HHy0iOo9jFyc2+Dfsiv8zBkNAOQknyIMvJH 5ZrHEFf6ew7g8elsCGJ/MZaMZ5wDrYFsWgkhbDNVgLOyrfNREN+IXc/7F2QjBDcKyEPv U0jka2Qt8VZTPczI/4U9Szde6Ur2jGzXLnwTGohZVJIkzWhvDJJqmVA4L2FkT4ut6YWo 2Fog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TMfX5GLFh57pG2QX7283Ze9GK6r5LOYCLbe0PSu2BLw=; b=6NPe5cQS15/Ky9lut6uoQMdUXtV5MWX1NnsJa/yvGfz5wVQNIJ8lo6BNxgPJqgdWsC ILFlzheHOeZJ7Hnt3tHNO5Z65WwZ5zUCI/X/iM7O0YqOiXwzDVbm3do+4gaBMJaYQFUJ GdBywe0Jl3kfRqqbCYHXfDlQ0oYiyBAcbuB51etvt9rwPwlyi/2IkPJoEpHXTkIkpnNn AV+GpHJaKSnDX5nXv0WLiOK6TaFoo0CUTeytikaKXy0eY5zCXOOIsFNWwCuoc5KotonG movIAsWJEOVaBdcMp1hN+Ltxde02pTLvf/SgfiF3Ikl2p4Q+GQqTp6rNu3j6cEZMYEfB 0EpA== X-Gm-Message-State: AOAM533pCmsbuGV9yri8Q6IFSbbrsxGcsbmqEBDEj8u6n13/EkQqluZD RJNbPmcdYhEoAlUxQh4nIaFv7CysoKM= X-Google-Smtp-Source: ABdhPJyJiHY+va3NJMm30jASkVrolPiBPj4rE7ytgkBjAVfcPmZDkDb5LV9BuiEyQskkaHhwXwvgJg== X-Received: by 2002:a17:903:32c9:b0:15e:a1b8:c1ef with SMTP id i9-20020a17090332c900b0015ea1b8c1efmr19148178plr.173.1652155069147; Mon, 09 May 2022 20:57:49 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id d12-20020a17090ad3cc00b001d81a30c437sm568193pjw.50.2022.05.09.20.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 20:57:48 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 2/5] net: add CONFIG_DEBUG_NET Date: Mon, 9 May 2022 20:57:38 -0700 Message-Id: <20220510035741.2807829-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220510035741.2807829-1-eric.dumazet@gmail.com> References: <20220510035741.2807829-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This config option enables network debugging checks. This patch adds DEBUG_NET_WARN_ON_ONCE(cond) Note that this is not a replacement for WARN_ON_ONCE(cond) as (cond) is not evaluated if CONFIG_DEBUG_NET is not set. Signed-off-by: Eric Dumazet --- include/net/net_debug.h | 6 ++++++ net/Kconfig.debug | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/net/net_debug.h b/include/net/net_debug.h index 19cd2700c20ea9945ae7662bacfa50f5d2bed398..1e74684cbbdbcd5ba304b935e76376a72d6ba3f2 100644 --- a/include/net/net_debug.h +++ b/include/net/net_debug.h @@ -148,4 +148,10 @@ do { \ #endif +#if defined(CONFIG_DEBUG_NET) +#define DEBUG_NET_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond) +#else +#define DEBUG_NET_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond) +#endif + #endif /* _LINUX_NET_DEBUG_H */ diff --git a/net/Kconfig.debug b/net/Kconfig.debug index 2f50611df858911cf5190a361e4e9316e543ed3a..a5781cf63b16b32e5360df1ca26a753b6505d81f 100644 --- a/net/Kconfig.debug +++ b/net/Kconfig.debug @@ -17,3 +17,10 @@ config NET_NS_REFCNT_TRACKER help Enable debugging feature to track netns references. This adds memory and cpu costs. + +config DEBUG_NET + bool "Add generic networking debug" + depends on DEBUG_KERNEL + help + Enable extra sanity checks in networking. + This is mostly used by fuzzers, but is safe to select. From patchwork Tue May 10 03:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12844520 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 638C3C433FE for ; Tue, 10 May 2022 03:58:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235797AbiEJEBz (ORCPT ); Tue, 10 May 2022 00:01:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235752AbiEJEBr (ORCPT ); Tue, 10 May 2022 00:01:47 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A7F2AA2F1 for ; Mon, 9 May 2022 20:57:51 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id j6so13882686pfe.13 for ; Mon, 09 May 2022 20:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/z4M3GBGw6/WGXULFKw/7yx8sXpcmNAe2LOaka9wT5k=; b=ZIIkLBC3K9ZjYWSA/wfSSK7i26EffRzRT8fhwgsuGqhxpJWxI4ar7jYATqhSZfz2JQ 1YyJIHMek4Pkyn0vtdR0MDR/H9hrxalYEi/7/mBQyVKK6UqESDMN7AVxLzgWZVFHof1y u6vkrKULrFt78S7rU2m1G0MEY7JdA3Ac+HKaBj1IxkXK0Dp1IR0p4D8k6OCYzkgedk8R Ik5xBDhO3eRpypC3/ohnPsKte/PfVHaPu1jTZ2AhbW8MoLxZKRI+XC3nPOQrrnY+YrHG q+7+QJNLamjyfRKUAdE43M85oIAxo6PLazPoN/qpk7RJRImvq6NzFxSDjOM5EKA4GCzg iopw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/z4M3GBGw6/WGXULFKw/7yx8sXpcmNAe2LOaka9wT5k=; b=VLRIfWzKHhOZDZ7PfV5ujmgNPZwJqFbXyglPfi8Fu0VqnaXsIn8uKAPcNqNJA3/xEG bZAk1e8c8dGwFSl9OtEUBczoezQJIuvoyTB1dISdx3pDcyyFAJg/0KA1mcHm7GvPwn+1 CyCflKSrmHzZc57qUGECOpHYMBW9oB7Qs40JlN4cGUzOpMhxQdkGhUcKf+5x/GagLZQz CMukArm5GPt/bYdlcJj6Xep7xVQBlekz+pB+Bul7iDxTmnH0ST2TfD4w3FRD5lAsGQDx QA0E6Kgp4ry5/Yws+2MHcKE8vlcth7fXaDDeXMSPJozymsonnu8o1eyfJ9IZfe8CdRfU gE5Q== X-Gm-Message-State: AOAM5314bXd+eU6WCe02stWLVOGqIPWCCZqIAObQQTXjyM0qryA2FF7Y dlfCi5t6UEhL1OaFjOLzauU= X-Google-Smtp-Source: ABdhPJze6KYjhGoyIkPP/IZfsYfCWundReB9ewO5rEpEfSAfkwU3AOn4Zc/f3Diw0vNLcZGNq4RifA== X-Received: by 2002:aa7:9110:0:b0:4fa:e388:af57 with SMTP id 16-20020aa79110000000b004fae388af57mr18669547pfh.1.1652155070887; Mon, 09 May 2022 20:57:50 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id d12-20020a17090ad3cc00b001d81a30c437sm568193pjw.50.2022.05.09.20.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 20:57:50 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 3/5] net: warn if transport header was not set Date: Mon, 9 May 2022 20:57:39 -0700 Message-Id: <20220510035741.2807829-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220510035741.2807829-1-eric.dumazet@gmail.com> References: <20220510035741.2807829-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Make sure skb_transport_header() and skb_transport_offset() uses are not fooled if the transport header has not been set. This change will likely expose existing bugs in linux networking stacks. Signed-off-by: Eric Dumazet --- include/linux/skbuff.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d58669d6cb91aa30edc70d59a0a7e9d4e2298842..a1c73fccccc68641fe46066e6d1195b31483ca4c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -42,6 +42,7 @@ #if IS_ENABLED(CONFIG_NF_CONNTRACK) #include #endif +#include /* The interface for checksum offload between the stack and networking drivers * is as follows... @@ -2804,6 +2805,7 @@ static inline bool skb_transport_header_was_set(const struct sk_buff *skb) static inline unsigned char *skb_transport_header(const struct sk_buff *skb) { + DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb)); return skb->head + skb->transport_header; } From patchwork Tue May 10 03:57:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12844522 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81CFFC433FE for ; Tue, 10 May 2022 03:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235777AbiEJEB6 (ORCPT ); Tue, 10 May 2022 00:01:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235766AbiEJEBt (ORCPT ); Tue, 10 May 2022 00:01:49 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F4FC2AACC8 for ; Mon, 9 May 2022 20:57:52 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id l11so8060649pgt.13 for ; Mon, 09 May 2022 20:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F23hvNdZVN0CdwC6BDdwdQ1zcLt+U3y9nLMorclWjn4=; b=e+h+1AdoaW6x4sMIP6jh3B1gwLjq2OIaKGCNJg7A2bq1lEoI0alrTV3FyilvQV4EmZ FAhmHf0GXIZAetAMMT6/BZm/cG8g7rhIZHbr49Q55Avvb5GlkdZh+d2TBIsw5uACkLmR 4RLsAdHgkrrz/sGbyP3BuAeBRhPSodRC9Wy712FOEm7v7mhq6x0GOo0YdIn46UcdVJcQ rU4COrA5j8fBhb1NVtm44iRxCobqgOeG5QHRyg7L2dMUJ1Y/Ci2qXQVZcRqPzAQkCjWi oszZnZdIy4Poa2R+BcTZkKILPEPIuu4hyvw5yEWt8OBX79QNhhcdZ1UlFSWQ/NuVntkG /DTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F23hvNdZVN0CdwC6BDdwdQ1zcLt+U3y9nLMorclWjn4=; b=vGHgy4vC6DWYeA4wHKIGAtSlHV3rxzj6W/RuBVHCJP7n+g6ih2dc7mXmeHTtdGajfL UlByGYB4oxnL/L74tyBLkHMSQ/juFuZJ5LpzufQ8cilktvx0QJd1tEXpM0BbsqSgVl4n wY8/+pc1r5UFPQC8L11s0VFMtA4WcV3ZLHVqymWLQujT+r7rcnHC1lXE2tuB4F+D/RvY o+DS086ySWW3FSatmorQO+GX3sv+ZkG/YWFNZT5y/3PB70HR/vJN6ywZjy0Z1NjhGDCK zSdmmJdw8q4FcksoQOUjgsA1QLExqt/sUFZD8DhK+Tvwm8VWWIoKjDJaeIpcVhRZ0XYK 6U5Q== X-Gm-Message-State: AOAM5338axhJRi1OTxUIn3KQY8mAoQSNM7hVNaqbDCuldh749kiiCRGv K3a3MewQLZ0HzCsp4Iqshe4= X-Google-Smtp-Source: ABdhPJzSKUVdheO3C3Mtx8Mcr37FnUkc5REcaf4FhxHVSfqcRfcF0+mNdCVRsZJbutHERGd7nlfUUQ== X-Received: by 2002:a05:6a00:238f:b0:4f7:78b1:2f6b with SMTP id f15-20020a056a00238f00b004f778b12f6bmr18767003pfc.17.1652155072536; Mon, 09 May 2022 20:57:52 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id d12-20020a17090ad3cc00b001d81a30c437sm568193pjw.50.2022.05.09.20.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 20:57:52 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 4/5] net: remove two BUG() from skb_checksum_help() Date: Mon, 9 May 2022 20:57:40 -0700 Message-Id: <20220510035741.2807829-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220510035741.2807829-1-eric.dumazet@gmail.com> References: <20220510035741.2807829-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet I have a syzbot report that managed to get a crash in skb_checksum_help() If syzbot can trigger these BUG(), it makes sense to replace them with more friendly WARN_ON_ONCE() since skb_checksum_help() can instead return an error code. Note that syzbot will still crash there, until real bug is fixed. Signed-off-by: Eric Dumazet --- net/core/dev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index f036ccb61da4da3ffc52c4f2402427054b831e8a..e12f8310dd86b312092c5d8fd50fa2ab60fce310 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3265,11 +3265,15 @@ int skb_checksum_help(struct sk_buff *skb) } offset = skb_checksum_start_offset(skb); - BUG_ON(offset >= skb_headlen(skb)); + ret = -EINVAL; + if (WARN_ON_ONCE(offset >= skb_headlen(skb))) + goto out; + csum = skb_checksum(skb, offset, skb->len - offset, 0); offset += skb->csum_offset; - BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb)); + if (WARN_ON_ONCE(offset + sizeof(__sum16) > skb_headlen(skb))) + goto out; ret = skb_ensure_writable(skb, offset + sizeof(__sum16)); if (ret) From patchwork Tue May 10 03:57:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12844521 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 278CAC433F5 for ; Tue, 10 May 2022 03:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235759AbiEJEB4 (ORCPT ); Tue, 10 May 2022 00:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235779AbiEJEBy (ORCPT ); Tue, 10 May 2022 00:01:54 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8588A2AACF1 for ; Mon, 9 May 2022 20:57:54 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id s16so3540662pgs.3 for ; Mon, 09 May 2022 20:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0bseCsCgH8tvgn5RskGxEkKOuDX9KLq4aKs1hGam7p0=; b=N/NO5zL85HjNbsr9wIRtxT0u6NJNWEUg1aQd/LQ3OaiBCKm8iPG5u5cT9gX7r/LLnv ga9rEPEhnaYH/7lunaaeKbf8lTTmTjXchOG944VEjS9vZ9QuKKA80GZXSzJnN+F/LzqW TjI7W2Kenr7Cyt/IX4nTKKd5RsuoIGzJsY8KrsdbfyY9LYMJOZqaC8R79wtl/h3D36Jc KC9JPPmUr8FMorgDkiUa5Nkh/nmG5m7AwwTH9jIhQ39mRczjWMkRrzKb6+bOjoRCWZvR ++a+2KdCV/nwoKaJKxD4NmcKWzmletq2w1AaSMxhh0iFGQ6qOYzkMbIoN7Rr80BgsVQn RZRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0bseCsCgH8tvgn5RskGxEkKOuDX9KLq4aKs1hGam7p0=; b=KYqvXkEFaoVKOf05xejAztnXimFyet17oYoqQAb9qStki15V7jWNNlKIG9db2XfABB rveJL6AJ0NxA8D68oHrgRsIbTYLioCV5Pd4ZcUaKN43OLjd11k3sY0vMT+dB6vluxaL5 mpwC6FPFjXO5nrD8Iw0Z755Q5OgjDIp5Vu+VfQLTYULL/WONK+i+BMNKGX0/vgGmUqeG U0YH2b2nekP9nd0PUmzjgNBrumCZ92deonnR7NrrHPAMKvpkMJVrJjBgfzLjU+zY/iwH ltvbAclbCZu2TfkDFSzU+bFT7ZvygE7K2yKXUB79yKtnY+c6F0lsG+9doXdgm5WC+Ig1 PWJQ== X-Gm-Message-State: AOAM532FxmddZs5D/C1NpfATybep4/6WyC9Nyt/mH5Hy8R6Q6IvM5aI8 Ilvp03jph7T8g3owPmSGZZ8= X-Google-Smtp-Source: ABdhPJzNceyiDZIq7Cm7kkShXXhwJa3bF2AOdTklGkJ/uWNooRHGVIp44aEzzJouydJAG4V8Z4bEDw== X-Received: by 2002:a63:4f1e:0:b0:3a6:68b7:cedc with SMTP id d30-20020a634f1e000000b003a668b7cedcmr15349700pgb.29.1652155074014; Mon, 09 May 2022 20:57:54 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id d12-20020a17090ad3cc00b001d81a30c437sm568193pjw.50.2022.05.09.20.57.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 20:57:53 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 5/5] net: add more debug info in skb_checksum_help() Date: Mon, 9 May 2022 20:57:41 -0700 Message-Id: <20220510035741.2807829-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220510035741.2807829-1-eric.dumazet@gmail.com> References: <20220510035741.2807829-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet This is a followup of previous patch. Dumping the stack trace is a good start, but printing basic skb information is probably better. Signed-off-by: Eric Dumazet --- net/core/dev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index e12f8310dd86b312092c5d8fd50fa2ab60fce310..d3221ea4aab3bfded1d3d9e2b0d861afc1c2eed6 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3266,15 +3266,17 @@ int skb_checksum_help(struct sk_buff *skb) offset = skb_checksum_start_offset(skb); ret = -EINVAL; - if (WARN_ON_ONCE(offset >= skb_headlen(skb))) + if (WARN_ON_ONCE(offset >= skb_headlen(skb))) { + DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false); goto out; - + } csum = skb_checksum(skb, offset, skb->len - offset, 0); offset += skb->csum_offset; - if (WARN_ON_ONCE(offset + sizeof(__sum16) > skb_headlen(skb))) + if (WARN_ON_ONCE(offset + sizeof(__sum16) > skb_headlen(skb))) { + DO_ONCE_LITE(skb_dump, KERN_ERR, skb, false); goto out; - + } ret = skb_ensure_writable(skb, offset + sizeof(__sum16)); if (ret) goto out;