Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1142926lqh; Sun, 5 May 2024 19:27:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHolJscOtDvkm6KFKr8KNJWr/FgzcQhOjdT6rznXMdtKmMjk8/1Mos35i+9+lB2gwN2x/QP0wfs5bWyDnc3+OWFaUJgyJWxg21etj8Ig== X-Google-Smtp-Source: AGHT+IFw9LzHsNd9Be3kcqX3D+iixf9+TcmC2DdNzS8gkgApEmuUHV3ln5QAUjECFk4WlgxtHibn X-Received: by 2002:a05:6870:1685:b0:22e:d13b:c13d with SMTP id j5-20020a056870168500b0022ed13bc13dmr10824275oae.18.1714962460502; Sun, 05 May 2024 19:27:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714962460; cv=pass; d=google.com; s=arc-20160816; b=XzNp6m3XytNKQ4lK4a4/FQznoRDJxpMX0/NSbaYko5SzFybRXQySy25DD1xVDgpkY3 JMqux9PSyoOkBzjQG/jRulvwf2BBQ3do8jHSoDMQBiGNLEviJPDmNF8dTVYpRFaUF8v+ YxW78QGGUFvcQ7sk5fxWNrJuKm7oaaI7BFhg7K5NOVqw9qfTyizlZH/rDej2NuuJYTam JpsmDuxvhSTHmWSWpo1zVEnF9MGN6s9oxyDfpGvMxWpRkxuobC5f0na1emsL2vbWME5t B2Jdom57f1oso6eb9+SofeMmfSBgiJgTjEOGQ5JG2sfltCfsePZ4utcC1oYRTIECzTAI JjBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=XZcebAj1tOpuNxt9ewLjX4z+yHH+WF19I/SsunPNY+Q=; fh=7GbjkGTXhTnPS0UmO2aNeTzGEslDcl87YFsjZeDaC+8=; b=K510ssnipeK+FRph3zpP0LR1Tu94InWOC//6IHaavM/EJAm/8z9yeImaLKC/M4G+19 9Jo8MWtwLf8IwF1H1SqR+Ik+K8qIebf5qqME3OC8y7MPeYM+Jbx+dOtPHUlC+TplI8sH NMSrm9QOP1C3MYqvA5QZNnWRaG0J7EFhhX84wIEraBpJxruksmDrDmOA3LkTNAOsqz3G JM5LKm/E+vpTRrH2uzrPM6mqwiN3T9bRhA5PTG1pH89k5z2pxSMJV4QIW46JqLIAxWaB wwugiJkvvWjTEAH+7P+cCt8H6cCkeXVLgQ0Z0od0mOnir4tcHD0S84tQD+suWr3B64Sr OTUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=2S+pwjKW; arc=pass (i=1 dkim=pass dkdomain=davidwei-uk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169255-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169255-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z15-20020aa791cf000000b006f4516e9876si4953370pfa.259.2024.05.05.19.27.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 19:27:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169255-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=2S+pwjKW; arc=pass (i=1 dkim=pass dkdomain=davidwei-uk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-169255-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169255-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2BAF6281E32 for ; Mon, 6 May 2024 02:27:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B503A40856; Mon, 6 May 2024 02:27:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="2S+pwjKW" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79A983F9EC for ; Mon, 6 May 2024 02:27:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714962453; cv=none; b=qc4kyX5uRtilB2ghFnrW9WeVs1rHo8Yi/LJ/DoeSd9mZy+eIGkxAAJxt+5PThruEPX7eavmtCE5y1T7y16IpNznOSHLhBGh+pouo45TRbkTmDD+3UK+t96WPtlGjWWIWNgKPpB+um8AU0okSmP4hnEAN6j1uLi31TC7fQFJqnQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714962453; c=relaxed/simple; bh=9SFYx28lbOjebzpeT1IaydZg7cFtpjFbVbcTaHrbfVE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Suq/xVr2kKoN+XXm/b6nlISs7jCnM14v3D0q9VQIYeNM29bZb8ngpfjkOFDLyirY3QcCc0a22Vri4JHylctvXXXtx4uMe6WopBpJWCjAVdDbFqgbtTmgowtPokx2CSuotTZ3ThGe0W3RUVRlQmcuaVWSIX9hrVr1j2fQTSbFnZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=2S+pwjKW; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6f30f69a958so839229b3a.1 for ; Sun, 05 May 2024 19:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1714962451; x=1715567251; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=XZcebAj1tOpuNxt9ewLjX4z+yHH+WF19I/SsunPNY+Q=; b=2S+pwjKWYlLbiuBIk3HZlOWpXEc4CXmptIS03eIOnTMcGybp8XBpbKITK9/kFRg/ic LbwRXnBI6CK7hAF8xFT24WlmBjb7YEHwvgMB8Ggb7SDSy0x3eu/shPeQQfnRjZw+NYA1 kbaoiqJb4DPFSnUmhmKxZKJvK5gdq8xJbgIMFmsLTQpXTqhNB4KX37OWnqSdir8sL8Lk jNazIC9k+hM6cV7ysWMAa0W5ajuYP+n++sigN4uxDW11dLBcTaZ1TkFS5N1FBdrArOn4 no+itV9cHw6eUBXvQYs3wNKVAWMIPnk2zfvrYV89CDyEGP3i5y1La5iWem9GdI0RmOpj 9VbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714962451; x=1715567251; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XZcebAj1tOpuNxt9ewLjX4z+yHH+WF19I/SsunPNY+Q=; b=EPNsz9CFP+Bc3OOfcVST+l07dop9qpRu8s+2V+NGulWeyhU+/HtthykqrvGjL1Yh7/ 3xtNGAr8jvq9Pj/IECDppYTdr0oJBIM52KGmfFB0czSauCo+bsSD+1voCLkJw97QvVOG /NBCV9EzIXWWHrFHm/b6O1yY/RyZUJbNMP+s1jUU71v2kd70G3MAK0RFE5OyE/8bAUVL LPO6AZBkZT2X4b4z5uai35FV07D2DyabwWoLlBSScq031dz+vQ7RAkaLyq7k/immZwhI ShD4JgFqc1cQH9IQQLTsFbX1YsZ5noj0/89PfFeI2WioD9MFDmPBg+FJzUoE8vdk2Fdd Pgaw== X-Forwarded-Encrypted: i=1; AJvYcCX69EwgFyr21APqxlQSwoRCcKJDIWKRv1Bl57nfkMIi9gJ0YvXxaggR+gkPC++vSpYOwPIuBqlVR4VQsJSAAU4mKSkLdO7zBRvXyfAn X-Gm-Message-State: AOJu0Yy8BMycrKiqlSxgPr5Lou5wcQVDs34ZN1BmbTia/HiluvPM5qBy mEVPVIX7Wa980YFrpn71/xdCSKdwVbx4i293Euevkeo+8zWAc0JMbV2AV/3rzF0= X-Received: by 2002:a05:6a20:d80c:b0:1af:7bbc:9f86 with SMTP id iv12-20020a056a20d80c00b001af7bbc9f86mr9359387pzb.0.1714962450620; Sun, 05 May 2024 19:27:30 -0700 (PDT) Received: from [192.168.1.15] (174-21-160-85.tukw.qwest.net. [174.21.160.85]) by smtp.gmail.com with ESMTPSA id n26-20020a63591a000000b005cf450e91d2sm6955159pgb.52.2024.05.05.19.27.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 May 2024 19:27:30 -0700 (PDT) Message-ID: <1d0c553c-18bb-4d0d-8358-eff0b65c6c56@davidwei.uk> Date: Sun, 5 May 2024 19:27:29 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] net/smc: fix netdev refcnt leak in smc_ib_find_route() Content-Language: en-GB To: Wen Gu , wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: alibuda@linux.alibaba.com, tonylu@linux.alibaba.com, linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240506015439.108739-1-guwen@linux.alibaba.com> From: David Wei In-Reply-To: <20240506015439.108739-1-guwen@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024-05-05 18:54, Wen Gu wrote: > A netdev refcnt leak issue was found when unregistering netdev after > using SMC. It can be reproduced as follows. > > - run tests based on SMC. > - unregister the net device. > > The following error message can be observed. > > 'unregister_netdevice: waiting for ethx to become free. Usage count = x' > > With CONFIG_NET_DEV_REFCNT_TRACKER set, more detailed error message can > be provided by refcount tracker: > > unregister_netdevice: waiting for eth1 to become free. Usage count = 2 > ref_tracker: eth%d@ffff9cabc3bf8548 has 1/1 users at > ___neigh_create+0x8e/0x420 > neigh_event_ns+0x52/0xc0 > arp_process+0x7c0/0x860 > __netif_receive_skb_list_core+0x258/0x2c0 > __netif_receive_skb_list+0xea/0x150 > netif_receive_skb_list_internal+0xf2/0x1b0 > napi_complete_done+0x73/0x1b0 > mlx5e_napi_poll+0x161/0x5e0 [mlx5_core] > __napi_poll+0x2c/0x1c0 > net_rx_action+0x2a7/0x380 > __do_softirq+0xcd/0x2a7 > > It is because in smc_ib_find_route(), neigh_lookup() takes a netdev > refcnt but does not release. So fix it. > > Fixes: e5c4744cfb59 ("net/smc: add SMC-Rv2 connection establishment") > Signed-off-by: Wen Gu > --- > net/smc/smc_ib.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c > index 97704a9e84c7..b431bd8a5172 100644 > --- a/net/smc/smc_ib.c > +++ b/net/smc/smc_ib.c > @@ -210,10 +210,11 @@ int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr, > goto out; > if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET) > goto out; > - neigh = rt->dst.ops->neigh_lookup(&rt->dst, NULL, &fl4.daddr); > + neigh = dst_neigh_lookup(&rt->dst, &fl4.daddr); Of the two implementations of neigh_lookup() I found that do not simply return NULL, all of them increment or init struct neighbour::refcnt. 1. ipv4_neigh_lookup() 2. ip6_dst_neigh_lookup() a. __ipv6_neigh_lookup() b. neigh_create() > if (neigh) { > memcpy(nexthop_mac, neigh->ha, ETH_ALEN); > *uses_gateway = rt->rt_uses_gateway; > + neigh_release(neigh); So releasing it here looks correct. > return 0; > } > out: