Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp512665ybc; Tue, 12 Nov 2019 05:11:16 -0800 (PST) X-Google-Smtp-Source: APXvYqy11lmlhsaPdda5628tHJ+Y2w7uUT95CummcB/byC1ZGWkGPyFduNaBsMdOZje+JaK4tqeY X-Received: by 2002:a17:906:5fd0:: with SMTP id k16mr27709030ejv.243.1573564276764; Tue, 12 Nov 2019 05:11:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573564276; cv=none; d=google.com; s=arc-20160816; b=voqMUSOkmBmqEZ6ZbD63qiSx691mWjf8zQKqB0Em8R9HSc/KZVZPrKgys7+2ReOydi YnVlpi8C4OGAzhcB4JYSOIjs63ez4jeMbJfBDWXr5Xxrt+B+P8H7ns+qM18zGMrZI37H TLf4vdJ1g4pwoPIOsl7Egm7ZtIq6OlQEM3aLS6mAMC2pllbabrhP1M+vSpc/pAEqVZST suhm83pHN4UQOzZreFQ9tPptlVC1Anq/pf/4Tq0OQuZfFMHwqvIjDXNG6oFotYHWcWIq V8Z5a6YvKN4gN3mXbKwExEZdHObDu34/juUJ92C38tH9zMewB+SJ1x2heI9Q+rVyhS1K cvDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+N1z6zWsHSAF3+q+A3Kn00I1EfoUKs4jRg+ek5lxxKQ=; b=Ret+L57woe7uBXrdnrWHmqi0Zn5H0O+drVPU5chkbzEzCUbQzK9pfYpSjqtbQkEuYb 0KlhTY27uoHglkSTavmRQY8t8FPi8aNFv9wUi811du+dUKG3LorGj842fVPs3tFNPlor aP0ryn7Y2CFOeR9RUD35VehA78DIvgV9jU1AKtTiZz8IZtbmlbPfEQXIFn/FN7l28ixa gR69ydK2GaiSynOQxuqkWuxkoJwJ4ZcgeWRlBw8XJkr9p7uKVEhC0WhYtvENli/DPxub 75PJUIzvag7R7l2ddG0rLBPhUymdZc/vj/jsaMK3XUckFohbSJ7vctUNI9KitUJ8KKE0 +kIQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z6si11339105ejx.384.2019.11.12.05.10.52; Tue, 12 Nov 2019 05:11:16 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727354AbfKLNIJ (ORCPT + 99 others); Tue, 12 Nov 2019 08:08:09 -0500 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:59582 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbfKLNIJ (ORCPT ); Tue, 12 Nov 2019 08:08:09 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=tonylu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0ThuOeKd_1573564085; Received: from localhost(mailfrom:tonylu@linux.alibaba.com fp:SMTPD_---0ThuOeKd_1573564085) by smtp.aliyun-inc.com(127.0.0.1); Tue, 12 Nov 2019 21:08:06 +0800 From: Tony Lu To: davem@davemloft.net Cc: xiyou.wangcong@gmail.com, eric.dumazet@gmail.com, shemminger@osdl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] net: add trace events for net_device refcnt Date: Tue, 12 Nov 2019 21:05:13 +0800 Message-Id: <20191112130510.91570-2-tonylu@linux.alibaba.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191112130510.91570-1-tonylu@linux.alibaba.com> References: <20191112130510.91570-1-tonylu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The net_device refcnt leak is hard to trace and debug for now. We need the ability to know when and who manipulated the refcnt. Adding the trace events for net_device pcpu_refcnt and also tracepoints in dev_put()/dev_hold(), provides the history of net_device refcnt inc and desc. With trace logs analysis, paring the put and hold history, we can find out who leaked. Signed-off-by: Dust Li Signed-off-by: Tony Lu --- include/trace/events/net.h | 41 ++++++++++++++++++++++++++++++++++++++ net/core/dev.c | 4 ++++ 2 files changed, 45 insertions(+) diff --git a/include/trace/events/net.h b/include/trace/events/net.h index 3b28843652d2..3bf6dd738882 100644 --- a/include/trace/events/net.h +++ b/include/trace/events/net.h @@ -326,6 +326,47 @@ DEFINE_EVENT(net_dev_rx_exit_template, netif_receive_skb_list_exit, TP_ARGS(ret) ); +DECLARE_EVENT_CLASS(net_dev_refcnt_template, + + TP_PROTO(struct net_device *dev, void *location), + + TP_ARGS(dev, location), + + TP_STRUCT__entry( + __string( name, dev->name ) + __field( int, refcnt ) + __field( void *, location ) + ), + + TP_fast_assign( + int i, refcnt = 0; + + for_each_possible_cpu(i) + refcnt += *per_cpu_ptr(dev->pcpu_refcnt, i); + + __assign_str(name, dev->name); + __entry->refcnt = refcnt; + __entry->location = location; + ), + + TP_printk("dev=%s refcnt=%d location=%p", + __get_str(name), __entry->refcnt, __entry->location) +); + +DEFINE_EVENT(net_dev_refcnt_template, net_dev_put, + + TP_PROTO(struct net_device *dev, void *location), + + TP_ARGS(dev, location) +); + +DEFINE_EVENT(net_dev_refcnt_template, net_dev_hold, + + TP_PROTO(struct net_device *dev, void *location), + + TP_ARGS(dev, location) +); + #endif /* _TRACE_NET_H */ /* This part must be outside protection */ diff --git a/net/core/dev.c b/net/core/dev.c index 620fb3d6718a..163870a09984 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1302,6 +1302,8 @@ EXPORT_SYMBOL(netdev_notify_peers); */ void dev_put(struct net_device *dev) { + trace_net_dev_put(dev, __builtin_return_address(0)); + this_cpu_dec(*dev->pcpu_refcnt); } EXPORT_SYMBOL(dev_put); @@ -1314,6 +1316,8 @@ EXPORT_SYMBOL(dev_put); */ void dev_hold(struct net_device *dev) { + trace_net_dev_hold(dev, __builtin_return_address(0)); + this_cpu_inc(*dev->pcpu_refcnt); } EXPORT_SYMBOL(dev_hold); -- 2.24.0