From patchwork Tue Sep 22 11:36:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 1369020 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4BwfW43rCvz9sSC for ; Tue, 22 Sep 2020 21:40:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726631AbgIVLkN (ORCPT ); Tue, 22 Sep 2020 07:40:13 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:13823 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726454AbgIVLkD (ORCPT ); Tue, 22 Sep 2020 07:40:03 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 5966745496516D02CC23; Tue, 22 Sep 2020 19:40:01 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Tue, 22 Sep 2020 19:39:53 +0800 From: Yunsheng Lin To: , , , , , , , , , , CC: , , Subject: [PATCH RFC] net: add in_softirq() debug checking in napi_consume_skb() Date: Tue, 22 Sep 2020 19:36:21 +0800 Message-ID: <1600774581-150072-1-git-send-email-linyunsheng@huawei.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The current semantic for napi_consume_skb() is that caller need to provide non-zero budget when calling from NAPI context, and breaking this semantic will cause hard to debug problem, because _kfree_skb_defer() need to run in atomic context in order to push the skb to the particular cpu' napi_alloc_cache atomically. So add a in_softirq() debug checking in napi_consume_skb() to catch this kind of error. Suggested-by: Eric Dumazet Signed-off-by: Yunsheng Lin --- include/linux/netdevice.h | 6 ++++++ net/Kconfig | 7 +++++++ net/core/skbuff.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index fef0eb9..e06d5e5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -5095,6 +5095,12 @@ do { \ }) #endif +#if defined(CONFIG_DEBUG_NET) +#define DEBUG_NET_WARN(condition, ...) WARN(condition, ##__VA_ARGS__) +#else +#define DEBUG_NET_WARN(condition, ...) +#endif + /* * The list of packet types we will receive (as opposed to discard) * and the routines to invoke. diff --git a/net/Kconfig b/net/Kconfig index 3831206..b176670 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -460,6 +460,13 @@ config ETHTOOL_NETLINK netlink. It provides better extensibility and some new features, e.g. notification messages. +config DEBUG_NET + bool "Net debugging and diagnostics" + depends on DEBUG_KERNEL + default n + help + Say Y here to add some extra checks and diagnostics to networking. + endif # if NET # Used by archs to tell that they support BPF JIT compiler plus which flavour. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e077447..378e66c 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -901,6 +901,10 @@ void napi_consume_skb(struct sk_buff *skb, int budget) return; } + DEBUG_NET_WARN(!in_softirq(), + "%s is called with non-zero budget outside softirq context.\n", + __func__); + if (!skb_unref(skb)) return;