From patchwork Mon May 9 19:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12843984 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 7E82FC433F5 for ; Mon, 9 May 2022 19:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240432AbiEITM4 (ORCPT ); Mon, 9 May 2022 15:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240413AbiEITMx (ORCPT ); Mon, 9 May 2022 15:12:53 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6862C2C479E for ; Mon, 9 May 2022 12:08:57 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id j10-20020a17090a94ca00b001dd2131159aso211636pjw.0 for ; Mon, 09 May 2022 12:08:57 -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=85QckvXFMUdmWYQBYCLBCt4jXsUMYPpZ5c6TS69VDrE=; b=Z6Xaa1sSIwWt1nWffnc2+inmIO3i3Xeh/Ll9GG98QFjzyO4cigtEMnKJ524lxEQELE zyuiERHnfgTpdfh0IDG2UxRzvB35PC0q0hUtjMSm5ZP+5gcjMtI4eKAMi+C4Uv83Hy/v Xh1iDJQ30E/Dr2TQz0cA2DjzP69zVvJJQxAbAl3j/iW+Jnfn/NmVen2vPiiV3JDZLOd7 p2Mif0EHp4UXSn/9HDKlDT+qn7+Jt+l5xmmRvyOzyRK/3ppp2Gqk3kNcCT1ook8Jg3+V k5vxZN6KCY7PDA9/BZ9KjoMcR0mKImm+WofEXX9Lg3CgYpwQuVWBNWxTgpGGRRi3I2vG M+0w== 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=85QckvXFMUdmWYQBYCLBCt4jXsUMYPpZ5c6TS69VDrE=; b=FsMhSvp5G0Q6hnlkDloPPL/JF+EZZ2o3soer6R0+S+ELOdQqjTOiGKwRWo1x6PYLac +6rdIgV4CkwergbYEUsgIXbID/tOoJnNCQHt2k7AIzbbuafSmXtm7A17I5RNAf9sRtSE 5DtgeaYZYiPnOM1UQ7EZS1tyCsIEKR5zyqaeELcN5K5JEns7ImYSguO40m20DM1rJPPd yyzysrNRCawAahHqvPmRXqZGkkH6xPf+lDe9HE+JPGqhf4tXbH/iCO5xqtXWeEUMinkJ hk3Flx1IgSDY+MeWPaL7hMj9W0QUXUKJ5UeU6+9p+5UzK5eEeORk6eC3GlSELGJISHTo 4rwg== X-Gm-Message-State: AOAM530GGfPweATyWg3avX4gFryQnRMSQeCQ+xZcGfS1pi3ne3t7c2Z8 pZPMdGLxjKS5iB6ERZIYupc= X-Google-Smtp-Source: ABdhPJxLvDX+Yir1SvwAxE2/LV1tO/OttDurvN3HKz7zkVBGsUvlMsE+pvHGMvKlK8svJrot3F+10A== X-Received: by 2002:a17:903:41c9:b0:15e:ae15:294f with SMTP id u9-20020a17090341c900b0015eae15294fmr17215988ple.44.1652123336863; Mon, 09 May 2022 12:08:56 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id a6-20020aa79706000000b0050dc7628174sm9032631pfg.78.2022.05.09.12.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 12:08:56 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 1/4] net: add include/net/net_debug.h Date: Mon, 9 May 2022 12:08:48 -0700 Message-Id: <20220509190851.1107955-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220509190851.1107955-1-eric.dumazet@gmail.com> References: <20220509190851.1107955-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. Signed-off-by: Eric Dumazet --- include/linux/netdevice.h | 154 +----------------------------------- include/net/net_debug.h | 159 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 153 deletions(-) create mode 100644 include/net/net_debug.h diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 74c97a34921d48c593c08e2bed72e099f42520a3..88ee2bcf35cf5f48fa41dc98e840802fbd81b36a 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,162 +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 - * file/line information and a backtrace. - */ -#define netdev_WARN(dev, format, args...) \ - WARN(1, "netdevice: %s%s: " format, netdev_name(dev), \ - netdev_reg_state(dev), ##args) - -#define netdev_WARN_ONCE(dev, format, args...) \ - 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..d8769ee7bced92decf126fe6c521db75e458565c --- /dev/null +++ b/include/net/net_debug.h @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_NET_DEBUG_H +#define _LINUX_NET_DEBUG_H + +__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 + +/* + * netdev_WARN() acts like dev_printk(), but with the key difference + * of using a WARN/WARN_ON to get the message out, including the + * file/line information and a backtrace. + */ +#define netdev_WARN(dev, format, args...) \ + WARN(1, "netdevice: %s%s: " format, netdev_name(dev), \ + netdev_reg_state(dev), ##args) + +#define netdev_WARN_ONCE(dev, format, args...) \ + 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 + + +#endif /* _LINUX_NET_DEBUG_H */ From patchwork Mon May 9 19:08:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12843983 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 98490C433EF for ; Mon, 9 May 2022 19:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240439AbiEITM6 (ORCPT ); Mon, 9 May 2022 15:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240404AbiEITMx (ORCPT ); Mon, 9 May 2022 15:12:53 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D89B02C4F51 for ; Mon, 9 May 2022 12:08:58 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id t11-20020a17090ad50b00b001d95bf21996so182376pju.2 for ; Mon, 09 May 2022 12:08:58 -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=aFBfcNcwAbGF/DTqoRVJfp+d5dgsrm0osd9T3/yAeF4=; b=M1GY3FHSQCSEfoaUyeFPHYf7YZmDrFg2adpCpQtP8MnUkADXBqBtE6tIiZtdj1rcPv tE5Z8Q9FqqS5Rv2KoKMRgBq1Ivf0fRbKn2XtaMlwdPiVY6s7Cc81BK1X0eJV3TyhGxRD cfNrCfqaxXEz/b+R5V1EfLbPh0X77lXWpiCegLnQKJcRLKlIdX8dngkZDWpx3ZpHrsYl lp0d8o0vTUYVf/e/OPHaFPkluHs1oVGgOeF9cz+N3LFgzGOMYp2LmiCgWkOzfCIqdVH0 qYpPXI65ghM8Mw+O9MCiqKmLKjdASgkbyETlJ7JvSXMeOKwXZ2WwQKWE6rSZIhUHHYd6 JBMQ== 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=aFBfcNcwAbGF/DTqoRVJfp+d5dgsrm0osd9T3/yAeF4=; b=uQAbUkBJj1yxiYw5tL+4nLH1JhDNOfhIfM2B7wDOOfG3zshtYhJ2ha4bT4WOaFmVmF KV8OWKeWOMmCRbtKSM22RLIAhc2LRqQi4tUcr8WppMO3dNoJtcgvKHfj/eXlU3meV3da qG4VRhAM4Aq8srR50BhuV2AJ0oYKhRrQ60HCjAGrY83aczbU9RYC1kKbnXUYTkRqyoUI Am9rhuSOaQzue8j9VYRJzVq2aqFnuH3dWZinOudOrh65D5rS+tiZldUUbwseZ3fkRZRE SR+/BCQgHcPbgur2DW2Ox5wXbCFConkgTD9/9eRzAuyNP9gzuW1oEwwoWwNELKGQQJKP vTAw== X-Gm-Message-State: AOAM530BcUlwpkqBGHOBt4BKCLvUdJKw+vaGe08x1nQCnGoyYsS1ODUv Rp+G/Hjxt1kHJ4hyDj/urTY= X-Google-Smtp-Source: ABdhPJzywUH1E2k8OHwDt+EjSB+FvW9Neqz9XTIhlsP8KbEk69RrMZA5j0qVRX9Q3RwsfjLi908/fw== X-Received: by 2002:a17:90b:3649:b0:1db:a201:5373 with SMTP id nh9-20020a17090b364900b001dba2015373mr19380820pjb.175.1652123338413; Mon, 09 May 2022 12:08:58 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id a6-20020aa79706000000b0050dc7628174sm9032631pfg.78.2022.05.09.12.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 12:08:58 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 2/4] net: add CONFIG_DEBUG_NET Date: Mon, 9 May 2022 12:08:49 -0700 Message-Id: <20220509190851.1107955-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220509190851.1107955-1-eric.dumazet@gmail.com> References: <20220509190851.1107955-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 d8769ee7bced92decf126fe6c521db75e458565c..f972ed3766a157f3f4de958fb6d4789dffc2923c 100644 --- a/include/net/net_debug.h +++ b/include/net/net_debug.h @@ -156,4 +156,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 Mon May 9 19:08:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12843985 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 769ABC433FE for ; Mon, 9 May 2022 19:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240448AbiEITNI (ORCPT ); Mon, 9 May 2022 15:13:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240431AbiEITM4 (ORCPT ); Mon, 9 May 2022 15:12:56 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69A862C5107 for ; Mon, 9 May 2022 12:09:00 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id s16so2725687pgs.3 for ; Mon, 09 May 2022 12:09:00 -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=P4PNCkNxZzf+Qp+/hcaor5d4IiBBYo198uaFWDrEPBrihRc99+d1kdRvulgT2Gt4VZ L8qqOLgBWYRlE/DPuCn+f6E674unzOR2fPQfyeD0oXeRyRAE1Ps3ASfEL0qhNA+qgbYL u8E0GL8mScLV87hwy6UYDX67F0XzoZPrc8XGbuCtfBjc/Iuzhi/TxsX42AssUUJ43AeL 62lCmqQwJyBdaU5q3Xf9cxvjbgTkLJ4Rd2ltMVY1D/J4/fZKf+PuzhSJv1Jb8BCjPDCH 2suYkqUlLPcAVNhF3zY+lWoMXcFfjqK2PL29Xywq+a/gmnaUw2IbMuihMTCsCo2Yd9q9 m8Hg== 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=gW+LRH0oTyw/1zDgfYkoBkKJmAF6plNbZLIgKRpKaqrhoLRZ4mI6ZpdI1hoU6VRS5o stG1OjWnqVxdahZVwkiLmvPrayQd4oe0GI79UN9Nghm5K2iDTFNzW1odX1O+5+RN2oYM XX/IXVPCR62GRZ1qCMhp1CwOnjLoQtzLY+SO5JsNPzKWZl3GMQ5X1QggYSODS6PbZzW1 GQ7xNMHMiM8W2oGaBxR2aMgrfi3ULGV7yECe67wee4u9Uk77k5nYdCu9RLde2Rgd16Gj ujPcg/xIy6OdHAXlywX1MIOIE/dkww2mG/HJZMTVzip7vv9AzYJCjsq3jyvoCVyVX44S R6Ug== X-Gm-Message-State: AOAM533F+jALWlCNDVfsNQxAcIHOnLLjqo3Q/UzREX5/UUojtkms5bRF agnj9mvRai46ehfSTCLF8NA= X-Google-Smtp-Source: ABdhPJypJATFp8RkOv6KYmXmuEg+IWzP6NTqkPWFypxNVMz/4mcGgVzUcAprUmR8/DK4olIpEZrgSw== X-Received: by 2002:a63:41c1:0:b0:3c6:e382:c125 with SMTP id o184-20020a6341c1000000b003c6e382c125mr1491668pga.383.1652123340014; Mon, 09 May 2022 12:09:00 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id a6-20020aa79706000000b0050dc7628174sm9032631pfg.78.2022.05.09.12.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 12:08:59 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 3/4] net: warn if transport header was not set Date: Mon, 9 May 2022 12:08:50 -0700 Message-Id: <20220509190851.1107955-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220509190851.1107955-1-eric.dumazet@gmail.com> References: <20220509190851.1107955-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 Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: kernel test robot --- 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 Mon May 9 19:08:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12843986 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 4DFBBC433EF for ; Mon, 9 May 2022 19:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240431AbiEITNI (ORCPT ); Mon, 9 May 2022 15:13:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240438AbiEITM5 (ORCPT ); Mon, 9 May 2022 15:12:57 -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 EEB392C512D for ; Mon, 9 May 2022 12:09:01 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id x12so12814468pgj.7 for ; Mon, 09 May 2022 12:09:01 -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=GmPS2/u/atWfhpEDJ46EekvU36Yt0L2WEtm6xRsSZyXTbsLmjkLnD1OcLeqIGZPsoa dAGVgHj5XMFAZ0JF1X8ZYORVoqL356t0JBytSRS/9GEK5e1VOmL4tRzEhC7qxkUEastB zOg/jNIqEC8bLwftvqarQE+GDIIeO60Ap5SJjt1eQETu/AFSgD4FIhG7JyWUgO91ywJX v46WJOYFZyvXWqloza1qGqTp/TMLvPggly8oxnJcA3FmtzzVsR1Fu1q14ozdBEidTUOI M8F+m6GOE7zJP1vYTLYbB7wJulrdqyFhJ4jLSqks52iaq49r9RjPAS6+FX9Biwt+mArb IVmw== 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=DrGnW8LGnAXAr0rsEZBEOqb8QQUxlvUJKsEXtaO8F2qi5zRqxcCbY94JERu552SVun 7nEqBF5JQyk2Q5TqQmva7Gxda055d/iqJUn8a9cHE/NlnCbfyeuCkXhSR/fSxWhCgXit 7qju14iq5U7VLqQe28P/eyhh3g+DkBFyMbvxrExrez1l+rOSbBb0b8ZhFWeblOLozGAi fn2YTInfMrAXRen6foKkrLJVS5ajjAOqF8J2xRkifjl/2neGzv2K0JbGwuoTcauL5lHD y8yk2XfmCCnrVVam+kwh2aL7fKavUwTv+UYchWHs55WwAl26gkLBBF04Bu2VteMIpggm H9aw== X-Gm-Message-State: AOAM533njIhTdtEI1G5j2K554HMNgV4qBrDaW6pU/2kvcyNEoZj9OV6/ PoSST2eza83EpXk4ysvIdJs= X-Google-Smtp-Source: ABdhPJwt06tor8/5bLEYJ3btoY2iYz/FzuDxuPlVo9yfFRyGmm4d2NiJ+j4DLXKfkVYQeUuExT/3Lw== X-Received: by 2002:a05:6a00:230d:b0:4f6:ec4f:35ff with SMTP id h13-20020a056a00230d00b004f6ec4f35ffmr17270195pfh.53.1652123341451; Mon, 09 May 2022 12:09:01 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:5d30:4e79:203f:a909]) by smtp.gmail.com with ESMTPSA id a6-20020aa79706000000b0050dc7628174sm9032631pfg.78.2022.05.09.12.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 12:09:01 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 4/4] net: remove two BUG() from skb_checksum_help() Date: Mon, 9 May 2022 12:08:51 -0700 Message-Id: <20220509190851.1107955-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.0.512.ge40c2bad7a-goog In-Reply-To: <20220509190851.1107955-1-eric.dumazet@gmail.com> References: <20220509190851.1107955-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)