Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp264547ybc; Tue, 12 Nov 2019 00:50:41 -0800 (PST) X-Google-Smtp-Source: APXvYqz242sGeJDLp3aiYoqqLveFnhFeUp3yKPL8iZb3XS/KvFQAhtVvmg6yQDfyDvwupVYE0dFH X-Received: by 2002:a50:becf:: with SMTP id e15mr31326615edk.135.1573548641159; Tue, 12 Nov 2019 00:50:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573548641; cv=none; d=google.com; s=arc-20160816; b=o3vIs7pqGn3jAxxnCNt+lOd49suQOGEvq3s2adg2ssUlwg3t+ShWHxhClIWFger4ko HuyeE7JvsnB1o4KdlIvQhCLosI4zahQQAnEOREH6V27LDxyp4bHez94I07nKPf2HkgBF kTeRlFfDqixoExhqRNCqYXImrattoYPLiB0lPrqKUdxMONeOkxUuHLm0Vvt2yZHamuYQ 39JdAQItAslDCNhpLR9lZI/SdhpFzwA6kvZf+ifK/l4CCjObSCo5eiMHQxi8C0K2M9oV QbLt6D+h2mglLbGrt34J9C0omKM4RHTVrPm7ehgxjMpUjzQVjafBDXeBhdijMLWX0zDh 9NJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date; bh=r0Mm7iOE32/4atbKfOvUjqHs8UefQv+0qfxJZ39t/nY=; b=U7uv6QBjZmHpfYTvX46egjKNqmRsr1+7NQXJio7vBilR/isAsnPHUdd5OKwSFWyJfI birLmvd4uERVbBo39Ud8fnQLJIMH7TKLyIYM9uKaG4mpQNG8TsIXk6IjdAe04d4aSeNP 8yhFeq05iM6RPzMwydzEP0wXznrFoyeoSVg5DhORghp9lN/QQ8ya7g8s47fBRaDjXE37 jKqwjo4O7NggCYH4kL4fPPhhxaLZ8K2RfWKiTb1QgD7CVM2hyfjijFDYoo5v0qOQWQr4 O82oqWFXNggxvKAYf1aIXvzrVWW/6CJcAI/DRfgvbWi69/1eB8Mlb7k3450XhZ4DCZn1 wtDQ== 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 y4si5067901edp.177.2019.11.12.00.50.16; Tue, 12 Nov 2019 00:50:41 -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 S1727361AbfKLIrT (ORCPT + 99 others); Tue, 12 Nov 2019 03:47:19 -0500 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:57005 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfKLIrT (ORCPT ); Tue, 12 Nov 2019 03:47:19 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R881e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=tonylu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0ThsxEsr_1573548435; Received: from localhost(mailfrom:tonylu@linux.alibaba.com fp:SMTPD_---0ThsxEsr_1573548435) by smtp.aliyun-inc.com(127.0.0.1); Tue, 12 Nov 2019 16:47:15 +0800 Date: Tue, 12 Nov 2019 16:47:14 +0800 From: Tony Lu To: Cong Wang Cc: David Miller , shemminger@osdl.org, Linux Kernel Network Developers , LKML Subject: Re: [PATCH] net: remove static inline from dev_put/dev_hold Message-ID: <20191112084714.GC67139@TonyMac-Alibaba> Reply-To: Tony Lu References: <20191111140502.17541-1-tonylu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 11, 2019 at 01:26:13PM -0800, Cong Wang wrote: > On Mon, Nov 11, 2019 at 6:12 AM Tony Lu wrote: > > > > This patch removes static inline from dev_put/dev_hold in order to help > > trace the pcpu_refcnt leak of net_device. > > > > We have sufferred this kind of issue for several times during > > manipulating NIC between different net namespaces. It prints this > > log in dmesg: > > > > unregister_netdevice: waiting for eth0 to become free. Usage count = 1 > > I debugged a nasty dst refcnt leak in TCP a long time ago, so I can > feel your pain. > > > > > > However, it is hard to find out who called and leaked refcnt in time. It > > only left the crime scene but few evidence. Once leaked, it is not > > safe to fix it up on the running host. We can't trace dev_put/dev_hold > > directly, for the functions are inlined and used wildly amoung modules. > > And this issue is common, there are tens of patches fix net_device > > refcnt leak for various causes. > > > > To trace the refcnt manipulating, this patch removes static inline from > > dev_put/dev_hold. We can use handy tools, such as eBPF with kprobe, to > > find out who holds but forgets to put refcnt. This will not be called > > frequently, so the overhead is limited. > > I think tracepoint serves the purpose of tracking function call history, > you can add tracepoint for each of dev_put()/dev_hold(), which could > also inherit the trace filter and trigger too. Thanks for your advice. I already made a patch set to add a pair of tracepoints to trace dev_hold()/dev_put() as an available solution. I used to want to give a flexible approach for people who want to choose. I will send it out later. > > The netdev refcnt itself is not changed very frequently, but it is > refcnt'ed by other things like dst too which is changed frequently. > This is why usually when you see the netdev refcnt leak warning, > the problem is probably somewhere else, like dst refcnt leak. We also suffered dst refcnt leak issue before. It is really hard to investigate. I will think about this place well. > > Hope this helps. > > Thanks. Thanks. Tony Lu