From patchwork Tue Feb 8 04:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738166 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 D63FDC433FE for ; Tue, 8 Feb 2022 05:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347441AbiBHFdQ (ORCPT ); Tue, 8 Feb 2022 00:33:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347036AbiBHEux (ORCPT ); Mon, 7 Feb 2022 23:50:53 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E773CC0401DC for ; Mon, 7 Feb 2022 20:50:52 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id v74so16837670pfc.1 for ; Mon, 07 Feb 2022 20:50:52 -0800 (PST) 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=63exI1ltBaNIjAmOFS8kkvew9jNC7V48+ebJLxT61ic=; b=T/B4rcSzl98VV0E6rPsjrIk9rjOUqudy0g4MJ4VLUMDf0/zI84qDaOzbgGFQD+5HkH nMEngmxz4nhFMnia21PSUXDQLv93RySBFnbVPhKEfVZXGvnGVUL6e5wJH5qu8R21HGR7 FRGIXgmad6+K42Sc+myLRl/I9Eb/6NPxsY4kuG+B5JDB08BHYCyo17uU3YXzVbPOSgSK Jlgqm7pcNwpfWhN1qkceYn9e2ZfdAPpTHr3s6IlhR7No/FusGRpRW3onzDd4CdO8MJir 21PsnzLHSe9ndO41yR40vJh0o9vSYCes00CRa6RH6vCVj0pSQWkOSdmcXLHEHmVcXiQt 9CGw== 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=63exI1ltBaNIjAmOFS8kkvew9jNC7V48+ebJLxT61ic=; b=KYdZCZFnmxV+d5xvKUqkYhCDYnqk9A6TGPwafAQLFxp1vfuehsaf2JX0gEwIaHjrPp Cx5mHoJ1yIj/eR6jZRW/f+psUJOjVa+Et2ktxiTUzqU5eH0b4TU3TS1IKxVXefF5OV6n VHNZLmPM6f8QCmJxuPDtlk8JrL8u4utbn1vFpCivA2kK/22qgoLqw300dcybuCZlw6rw sySoVxMuUbRQnCcdhixlRy//6S8sZ+5Q22I1XpP54jO2iiZgfvBgfCAuYjJi+liI/1Yo 9TfQqlfoE2QyEuHJp0qP1JgGUnxYWfqd35eNmaqKrTgl6b/aMgs89eRxlBGlPfzHWD+U 3p3Q== X-Gm-Message-State: AOAM531Kfc2nnPkfd+4bC0s4PiRo5y4nEpcyrEnQYTY7BKzEe93gYC5L KejwvQ777sdcmWhPursr2jc= X-Google-Smtp-Source: ABdhPJxa4pYl8F3Ybghl7uknMH8ghkUVv4roHDKfMdKFi/hPkVNGME+ueFp0JEIk7NzaMfscKvdMZA== X-Received: by 2002:a63:5d0c:: with SMTP id r12mr1636731pgb.183.1644295852406; Mon, 07 Feb 2022 20:50:52 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:50:52 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 01/11] ipv6/addrconf: allocate a per netns hash table Date: Mon, 7 Feb 2022 20:50:28 -0800 Message-Id: <20220208045038.2635826-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 Add a per netns hash table and a dedicated spinlock, first step to get rid of the global inet6_addr_lst[] one. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- include/net/netns/ipv6.h | 4 ++++ net/ipv6/addrconf.c | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index 30cdfc4e1615424b1c691b53499a1987d7fd0496..755f12001c8b2a73ad1895e73c7aebcba67c6728 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -92,6 +92,10 @@ struct netns_ipv6 { struct sock *tcp_sk; struct sock *igmp_sk; struct sock *mc_autojoin_sk; + + struct hlist_head *inet6_addr_lst; + spinlock_t addrconf_hash_lock; + #ifdef CONFIG_IPV6_MROUTE #ifndef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES struct mr_table *mrt6; diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index ef23e7dc538ad983a28853865dd4281f7f0ea8de..cda9e59cab4343507f670e7f59e2b72fd3cded0f 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -7111,6 +7111,13 @@ static int __net_init addrconf_init_net(struct net *net) int err = -ENOMEM; struct ipv6_devconf *all, *dflt; + spin_lock_init(&net->ipv6.addrconf_hash_lock); + net->ipv6.inet6_addr_lst = kcalloc(IN6_ADDR_HSIZE, + sizeof(struct hlist_head), + GFP_KERNEL); + if (!net->ipv6.inet6_addr_lst) + goto err_alloc_addr; + all = kmemdup(&ipv6_devconf, sizeof(ipv6_devconf), GFP_KERNEL); if (!all) goto err_alloc_all; @@ -7172,11 +7179,15 @@ static int __net_init addrconf_init_net(struct net *net) err_alloc_dflt: kfree(all); err_alloc_all: + kfree(net->ipv6.inet6_addr_lst); +err_alloc_addr: return err; } static void __net_exit addrconf_exit_net(struct net *net) { + int i; + #ifdef CONFIG_SYSCTL __addrconf_sysctl_unregister(net, net->ipv6.devconf_dflt, NETCONFA_IFINDEX_DEFAULT); @@ -7187,6 +7198,15 @@ static void __net_exit addrconf_exit_net(struct net *net) net->ipv6.devconf_dflt = NULL; kfree(net->ipv6.devconf_all); net->ipv6.devconf_all = NULL; + + /* + * Check hash table, then free it. + */ + for (i = 0; i < IN6_ADDR_HSIZE; i++) + WARN_ON_ONCE(!hlist_empty(&net->ipv6.inet6_addr_lst[i])); + + kfree(net->ipv6.inet6_addr_lst); + net->ipv6.inet6_addr_lst = NULL; } static struct pernet_operations addrconf_ops = { From patchwork Tue Feb 8 04:50:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738164 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 3001EC433F5 for ; Tue, 8 Feb 2022 05:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231778AbiBHFdM (ORCPT ); Tue, 8 Feb 2022 00:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347037AbiBHEu6 (ORCPT ); Mon, 7 Feb 2022 23:50:58 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 706CBC0401DC for ; Mon, 7 Feb 2022 20:50:57 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id i17so16798447pfq.13 for ; Mon, 07 Feb 2022 20:50:57 -0800 (PST) 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=4EsVHO1j93+zknKhBX4yib6nrA45XuKP1cgfl2DPi9g=; b=Zq54UyPDWYJtS8ZrQD8cmzwRUAaL1Gu9z9fVL/SUN/L+wEKL8SvLxl26vCfQMYCjyA vYUYO3gWwGu2+PpifD7zcKC4csfHFkL08wAThCaN2Gjq73AD6jgfWqUKgyz+dyytripm +KmPZdVrPXtKeAKOpvMZSY4nhrfKnB2SpQzB+5bYIcBCkAg9jn07wOKyj4cqW7Xp5Gpw fum/9i06I6ZdqCVFYsKx7t3LQXjt6OubsSxNIb4nSx0CRs6I155yirgFekVRYJzfaRtx ObVK0fCbRotNpx89WOTmEu81TSQxWnpOib/jzm4GeQkHnQ+/8+xVwAQPUuLSGGiJh3Le A7+w== 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=4EsVHO1j93+zknKhBX4yib6nrA45XuKP1cgfl2DPi9g=; b=dZfc74qvh1zz3qmrNd2bRWR8q4ZO7El43cQlOfGvbHY/QW+x0CEE5nn7gmzF9uXZHJ hl158sSOq/9tKa2gGVMeE4+P6pt6Ti0c6pNGMyMIuz1DTqDChRsM4geNckMTirzM6aOc h8/hnrH2WWNNXKnuDkrDJaEvJBRijOlEY1OZrPkMTlFLQZ/ArToe5TFuKsLZbvJfW6Wo kKdoyBN1hgQ9xt7pp8pprZ++hpheuEN2Qro3VcCEvdVKLaVhEwQ3iUH0oUwsRV+hLvzx Y9QjyGnRhh4cR0aEX4gqxXJEXXnTm4dIcnQCKYemkJ6bPCzVWauCWFMM6tA3L1elCWlK jhFg== X-Gm-Message-State: AOAM530Pdn9uRFnwcBR+1XLe3f/b3bIdm6iAjnnVqX3ZB3lRZDDrENvB y+DQgArBL9d5ZaDS7qbyh6IYFJ2LAx8= X-Google-Smtp-Source: ABdhPJyfFkVHDfxDSPol50b58F0EMpOT9Ag6Dmc5Sbx6+2zjwlwHoO32VUPkz6ElCdFS2nhreukDHA== X-Received: by 2002:a63:7a53:: with SMTP id j19mr2095878pgn.533.1644295856811; Mon, 07 Feb 2022 20:50:56 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:50:56 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 02/11] ipv6/addrconf: use one delayed work per netns Date: Mon, 7 Feb 2022 20:50:29 -0800 Message-Id: <20220208045038.2635826-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 Next step for using per netns inet6_addr_lst is to have per netns work item to ultimately call addrconf_verify_rtnl() and addrconf_verify() with a new 'struct net*' argument. Everything is still using the global inet6_addr_lst[] table. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- include/net/netns/ipv6.h | 1 + net/ipv6/addrconf.c | 44 ++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index 755f12001c8b2a73ad1895e73c7aebcba67c6728..d145f196668240bf5c3e509255f3f9b06f0e91bc 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -95,6 +95,7 @@ struct netns_ipv6 { struct hlist_head *inet6_addr_lst; spinlock_t addrconf_hash_lock; + struct delayed_work addr_chk_work; #ifdef CONFIG_IPV6_MROUTE #ifndef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index cda9e59cab4343507f670e7f59e2b72fd3cded0f..dab291cd39ba20c8dad29854297e8699c067b1e7 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -152,12 +152,10 @@ static int ipv6_generate_stable_address(struct in6_addr *addr, static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE]; static DEFINE_SPINLOCK(addrconf_hash_lock); -static void addrconf_verify(void); -static void addrconf_verify_rtnl(void); -static void addrconf_verify_work(struct work_struct *); +static void addrconf_verify(struct net *net); +static void addrconf_verify_rtnl(struct net *net); static struct workqueue_struct *addrconf_wq; -static DECLARE_DELAYED_WORK(addr_chk_work, addrconf_verify_work); static void addrconf_join_anycast(struct inet6_ifaddr *ifp); static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); @@ -2675,7 +2673,7 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, create, now); in6_ifa_put(ifp); - addrconf_verify(); + addrconf_verify(net); } return 0; @@ -2987,7 +2985,7 @@ static int inet6_addr_add(struct net *net, int ifindex, manage_tempaddrs(idev, ifp, cfg->valid_lft, cfg->preferred_lft, true, jiffies); in6_ifa_put(ifp); - addrconf_verify_rtnl(); + addrconf_verify_rtnl(net); return 0; } else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, @@ -3027,7 +3025,7 @@ static int inet6_addr_del(struct net *net, int ifindex, u32 ifa_flags, manage_tempaddrs(idev, ifp, 0, 0, false, jiffies); ipv6_del_addr(ifp); - addrconf_verify_rtnl(); + addrconf_verify_rtnl(net); if (ipv6_addr_is_multicast(pfx)) { ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, pfx, dev->ifindex); @@ -4246,7 +4244,7 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, * before this temporary address becomes deprecated. */ if (ifp->flags & IFA_F_TEMPORARY) - addrconf_verify_rtnl(); + addrconf_verify_rtnl(dev_net(dev)); } static void addrconf_dad_run(struct inet6_dev *idev, bool restart) @@ -4484,7 +4482,7 @@ int ipv6_chk_rpl_srh_loop(struct net *net, const struct in6_addr *segs, * Periodic address status verification */ -static void addrconf_verify_rtnl(void) +static void addrconf_verify_rtnl(struct net *net) { unsigned long now, next, next_sec, next_sched; struct inet6_ifaddr *ifp; @@ -4496,7 +4494,7 @@ static void addrconf_verify_rtnl(void) now = jiffies; next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); - cancel_delayed_work(&addr_chk_work); + cancel_delayed_work(&net->ipv6.addr_chk_work); for (i = 0; i < IN6_ADDR_HSIZE; i++) { restart: @@ -4599,20 +4597,23 @@ static void addrconf_verify_rtnl(void) pr_debug("now = %lu, schedule = %lu, rounded schedule = %lu => %lu\n", now, next, next_sec, next_sched); - mod_delayed_work(addrconf_wq, &addr_chk_work, next_sched - now); + mod_delayed_work(addrconf_wq, &net->ipv6.addr_chk_work, next_sched - now); rcu_read_unlock_bh(); } static void addrconf_verify_work(struct work_struct *w) { + struct net *net = container_of(to_delayed_work(w), struct net, + ipv6.addr_chk_work); + rtnl_lock(); - addrconf_verify_rtnl(); + addrconf_verify_rtnl(net); rtnl_unlock(); } -static void addrconf_verify(void) +static void addrconf_verify(struct net *net) { - mod_delayed_work(addrconf_wq, &addr_chk_work, 0); + mod_delayed_work(addrconf_wq, &net->ipv6.addr_chk_work, 0); } static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local, @@ -4708,7 +4709,8 @@ static int modify_prefix_route(struct inet6_ifaddr *ifp, return 0; } -static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg) +static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp, + struct ifa6_config *cfg) { u32 flags; clock_t expires; @@ -4822,7 +4824,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, struct ifa6_config *cfg) jiffies); } - addrconf_verify_rtnl(); + addrconf_verify_rtnl(net); return 0; } @@ -4909,7 +4911,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, !(nlh->nlmsg_flags & NLM_F_REPLACE)) err = -EEXIST; else - err = inet6_addr_modify(ifa, &cfg); + err = inet6_addr_modify(net, ifa, &cfg); in6_ifa_put(ifa); @@ -5794,7 +5796,7 @@ static int inet6_set_iftoken(struct inet6_dev *idev, struct in6_addr *token, write_unlock_bh(&idev->lock); inet6_ifinfo_notify(RTM_NEWLINK, idev); - addrconf_verify_rtnl(); + addrconf_verify_rtnl(dev_net(dev)); return 0; } @@ -7112,6 +7114,7 @@ static int __net_init addrconf_init_net(struct net *net) struct ipv6_devconf *all, *dflt; spin_lock_init(&net->ipv6.addrconf_hash_lock); + INIT_DEFERRABLE_WORK(&net->ipv6.addr_chk_work, addrconf_verify_work); net->ipv6.inet6_addr_lst = kcalloc(IN6_ADDR_HSIZE, sizeof(struct hlist_head), GFP_KERNEL); @@ -7199,6 +7202,7 @@ static void __net_exit addrconf_exit_net(struct net *net) kfree(net->ipv6.devconf_all); net->ipv6.devconf_all = NULL; + cancel_delayed_work(&net->ipv6.addr_chk_work); /* * Check hash table, then free it. */ @@ -7281,7 +7285,7 @@ int __init addrconf_init(void) register_netdevice_notifier(&ipv6_dev_notf); - addrconf_verify(); + addrconf_verify(&init_net); rtnl_af_register(&inet6_ops); @@ -7364,7 +7368,7 @@ void addrconf_cleanup(void) for (i = 0; i < IN6_ADDR_HSIZE; i++) WARN_ON(!hlist_empty(&inet6_addr_lst[i])); spin_unlock_bh(&addrconf_hash_lock); - cancel_delayed_work(&addr_chk_work); + rtnl_unlock(); destroy_workqueue(addrconf_wq); From patchwork Tue Feb 8 04:50:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738155 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 A8F20C433EF for ; Tue, 8 Feb 2022 05:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243915AbiBHFc3 (ORCPT ); Tue, 8 Feb 2022 00:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347038AbiBHEvC (ORCPT ); Mon, 7 Feb 2022 23:51:02 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA666C0401DC for ; Mon, 7 Feb 2022 20:51:00 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id e28so16827501pfj.5 for ; Mon, 07 Feb 2022 20:51:00 -0800 (PST) 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=YocVE5eZik1tiPsP0ujFo28MkujqtR9FCp0qy4+Xms4=; b=Jg7bpGjxVkKtlil3CT0q2PQ8k/0d/bK4VgPxTrQIIOaHDuJ2FSNMGhqK9+O8sZHR44 QQRzAJUUEhfIiOZjGjc+1WfZabwK045aoe6OZCGT0NUbH0Tl7h6BS72enQiTNoG2i28c 8Ywcc7xEl9k1QPdYLCoVoXb26v5/zERzIMOUybFGsiuVRkE2+W1CrZLgt0sx1XyLJ4DB bk/z4nxm9oJq5kCxrfVx+BxFbnjQgfsA039GZ3nDqarobM95jOmz4OA8VxOfYRInhMBU Yvmha9F7uB9DwcJB88xiJWSkz8K1X44cvIC27V1kwWe1kX7S1L80FTJOLvCAGqbV/CjF ux/g== 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=YocVE5eZik1tiPsP0ujFo28MkujqtR9FCp0qy4+Xms4=; b=onmjEPD5ALK8A3DHGeaRAss4MxbKEOTp0Zzce0lFcVxTWXpnCyEUNrmbzID78Ddxbd 6/W8w+805lojheofMRDA0T5Cz8c3BMho/Wf0mkJFR+++pBanrrhmsqtFFeP4szWubohL EjxHFMw6e3bHj2esUQl33YNhLi2S51rAMgsBqkZvW8FJS1AvCTQ0NtELs7TIpFwX4xs+ JtvX/N9BQlw4ThH10ESPJAtPqZ0jV1jCMf6ded1grMjDAUpdCqn3tCdKENdKPD8dvWQK Kjp6m0F+vMk5FwaKG9xtvOyk+YHXpIF92m32uhA/nnwyCmfpSn0QKdLFswlTAEMRRi0H 9Lbw== X-Gm-Message-State: AOAM533pbs32aM7FGExTXtTwwz31THzhywEwfE38id90iQ9yH21Meflg rNWSVsSnwdq3uOOwaUjPZZc= X-Google-Smtp-Source: ABdhPJzV4eojucbWFVJybAxdV/kpBzafUdb9sU0bRbCoK5m4A9zsDI6iGBDTVrPiDUhPq4fatRoMKA== X-Received: by 2002:aa7:8a14:: with SMTP id m20mr2608173pfa.63.1644295860365; Mon, 07 Feb 2022 20:51:00 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:00 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 03/11] ipv6/addrconf: switch to per netns inet6_addr_lst hash table Date: Mon, 7 Feb 2022 20:50:30 -0800 Message-Id: <20220208045038.2635826-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 IPv6 does not scale very well with the number of IPv6 addresses. It uses a global (shared by all netns) hash table with 256 buckets. Some functions like addrconf_verify_rtnl() and addrconf_ifdown() have to iterate all addresses in the hash table. I have seen addrconf_verify_rtnl() holding the cpu for 10ms or more. Switch to the per netns hashtable (and spinlock) added in prior patches. This considerably speeds up netns dismantle times on hosts with thousands of netns. This also has an impact on regular (fast path) IPv6 processing. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv6/addrconf.c | 77 ++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 54 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index dab291cd39ba20c8dad29854297e8699c067b1e7..4f402bc38f056e08f3761e63a7bc7a51e54e9384 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -146,11 +146,6 @@ static int ipv6_generate_stable_address(struct in6_addr *addr, #define IN6_ADDR_HSIZE_SHIFT 8 #define IN6_ADDR_HSIZE (1 << IN6_ADDR_HSIZE_SHIFT) -/* - * Configured unicast address hash table - */ -static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE]; -static DEFINE_SPINLOCK(addrconf_hash_lock); static void addrconf_verify(struct net *net); static void addrconf_verify_rtnl(struct net *net); @@ -1009,9 +1004,7 @@ static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, { struct inet6_ifaddr *ifp; - hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) { - if (!net_eq(dev_net(ifp->idev->dev), net)) - continue; + hlist_for_each_entry(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { if (ipv6_addr_equal(&ifp->addr, addr)) { if (!dev || ifp->idev->dev == dev) return true; @@ -1022,20 +1015,21 @@ static bool ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr, static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa) { - unsigned int hash = inet6_addr_hash(dev_net(dev), &ifa->addr); + struct net *net = dev_net(dev); + unsigned int hash = inet6_addr_hash(net, &ifa->addr); int err = 0; - spin_lock(&addrconf_hash_lock); + spin_lock(&net->ipv6.addrconf_hash_lock); /* Ignore adding duplicate addresses on an interface */ - if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev, hash)) { + if (ipv6_chk_same_addr(net, &ifa->addr, dev, hash)) { netdev_dbg(dev, "ipv6_add_addr: already assigned\n"); err = -EEXIST; } else { - hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); + hlist_add_head_rcu(&ifa->addr_lst, &net->ipv6.inet6_addr_lst[hash]); } - spin_unlock(&addrconf_hash_lock); + spin_unlock(&net->ipv6.addrconf_hash_lock); return err; } @@ -1259,9 +1253,10 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, static void ipv6_del_addr(struct inet6_ifaddr *ifp) { - int state; enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP; + struct net *net = dev_net(ifp->idev->dev); unsigned long expires; + int state; ASSERT_RTNL(); @@ -1273,9 +1268,9 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) if (state == INET6_IFADDR_STATE_DEAD) goto out; - spin_lock_bh(&addrconf_hash_lock); + spin_lock_bh(&net->ipv6.addrconf_hash_lock); hlist_del_init_rcu(&ifp->addr_lst); - spin_unlock_bh(&addrconf_hash_lock); + spin_unlock_bh(&net->ipv6.addrconf_hash_lock); write_lock_bh(&ifp->idev->lock); @@ -1918,10 +1913,8 @@ __ipv6_chk_addr_and_flags(struct net *net, const struct in6_addr *addr, if (skip_dev_check) dev = NULL; - hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { + hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { ndev = ifp->idev->dev; - if (!net_eq(dev_net(ndev), net)) - continue; if (l3mdev_master_dev_rcu(ndev) != l3mdev) continue; @@ -2025,9 +2018,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *add struct inet6_ifaddr *ifp, *result = NULL; rcu_read_lock(); - hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { - if (!net_eq(dev_net(ifp->idev->dev), net)) - continue; + hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { if (ipv6_addr_equal(&ifp->addr, addr)) { if (!dev || ifp->idev->dev == dev || !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { @@ -2094,7 +2085,7 @@ static int addrconf_dad_end(struct inet6_ifaddr *ifp) void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) { struct inet6_dev *idev = ifp->idev; - struct net *net = dev_net(ifp->idev->dev); + struct net *net = dev_net(idev->dev); if (addrconf_dad_end(ifp)) { in6_ifa_put(ifp); @@ -3770,9 +3761,9 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) /* Step 2: clear hash table */ for (i = 0; i < IN6_ADDR_HSIZE; i++) { - struct hlist_head *h = &inet6_addr_lst[i]; + struct hlist_head *h = &net->ipv6.inet6_addr_lst[i]; - spin_lock_bh(&addrconf_hash_lock); + spin_lock_bh(&net->ipv6.addrconf_hash_lock); restart: hlist_for_each_entry_rcu(ifa, h, addr_lst) { if (ifa->idev == idev) { @@ -3788,7 +3779,7 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) } } } - spin_unlock_bh(&addrconf_hash_lock); + spin_unlock_bh(&net->ipv6.addrconf_hash_lock); } write_lock_bh(&idev->lock); @@ -4286,10 +4277,8 @@ static struct inet6_ifaddr *if6_get_first(struct seq_file *seq, loff_t pos) } for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { - hlist_for_each_entry_rcu(ifa, &inet6_addr_lst[state->bucket], + hlist_for_each_entry_rcu(ifa, &net->ipv6.inet6_addr_lst[state->bucket], addr_lst) { - if (!net_eq(dev_net(ifa->idev->dev), net)) - continue; /* sync with offset */ if (p < state->offset) { p++; @@ -4312,8 +4301,6 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct net *net = seq_file_net(seq); hlist_for_each_entry_continue_rcu(ifa, addr_lst) { - if (!net_eq(dev_net(ifa->idev->dev), net)) - continue; state->offset++; return ifa; } @@ -4321,9 +4308,7 @@ static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, state->offset = 0; while (++state->bucket < IN6_ADDR_HSIZE) { hlist_for_each_entry_rcu(ifa, - &inet6_addr_lst[state->bucket], addr_lst) { - if (!net_eq(dev_net(ifa->idev->dev), net)) - continue; + &net->ipv6.inet6_addr_lst[state->bucket], addr_lst) { return ifa; } } @@ -4411,9 +4396,7 @@ int ipv6_chk_home_addr(struct net *net, const struct in6_addr *addr) int ret = 0; rcu_read_lock(); - hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { - if (!net_eq(dev_net(ifp->idev->dev), net)) - continue; + hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { if (ipv6_addr_equal(&ifp->addr, addr) && (ifp->flags & IFA_F_HOMEADDRESS)) { ret = 1; @@ -4451,9 +4434,7 @@ int ipv6_chk_rpl_srh_loop(struct net *net, const struct in6_addr *segs, hash = inet6_addr_hash(net, addr); hash_found = false; - hlist_for_each_entry_rcu(ifp, &inet6_addr_lst[hash], addr_lst) { - if (!net_eq(dev_net(ifp->idev->dev), net)) - continue; + hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { if (ipv6_addr_equal(&ifp->addr, addr)) { hash_found = true; @@ -4498,7 +4479,7 @@ static void addrconf_verify_rtnl(struct net *net) for (i = 0; i < IN6_ADDR_HSIZE; i++) { restart: - hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[i], addr_lst) { + hlist_for_each_entry_rcu_bh(ifp, &net->ipv6.inet6_addr_lst[i], addr_lst) { unsigned long age; /* When setting preferred_lft to a value not zero or @@ -7233,7 +7214,7 @@ static struct rtnl_af_ops inet6_ops __read_mostly = { int __init addrconf_init(void) { struct inet6_dev *idev; - int i, err; + int err; err = ipv6_addr_label_init(); if (err < 0) { @@ -7280,9 +7261,6 @@ int __init addrconf_init(void) ip6_route_init_special_entries(); - for (i = 0; i < IN6_ADDR_HSIZE; i++) - INIT_HLIST_HEAD(&inet6_addr_lst[i]); - register_netdevice_notifier(&ipv6_dev_notf); addrconf_verify(&init_net); @@ -7343,7 +7321,6 @@ int __init addrconf_init(void) void addrconf_cleanup(void) { struct net_device *dev; - int i; unregister_netdevice_notifier(&ipv6_dev_notf); unregister_pernet_subsys(&addrconf_ops); @@ -7361,14 +7338,6 @@ void addrconf_cleanup(void) } addrconf_ifdown(init_net.loopback_dev, true); - /* - * Check hash table. - */ - spin_lock_bh(&addrconf_hash_lock); - for (i = 0; i < IN6_ADDR_HSIZE; i++) - WARN_ON(!hlist_empty(&inet6_addr_lst[i])); - spin_unlock_bh(&addrconf_hash_lock); - rtnl_unlock(); destroy_workqueue(addrconf_wq); From patchwork Tue Feb 8 04:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738187 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 20F45C433FE for ; Tue, 8 Feb 2022 05:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbiBHFd0 (ORCPT ); Tue, 8 Feb 2022 00:33:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347040AbiBHEvE (ORCPT ); Mon, 7 Feb 2022 23:51:04 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60550C0401E9 for ; Mon, 7 Feb 2022 20:51:04 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id i17so16798854pfq.13 for ; Mon, 07 Feb 2022 20:51:04 -0800 (PST) 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=FvcC9+Awj3oLlqD6kMLWnWRMbi+Vd2Rz0NaLG9avzbk=; b=fChm/+PTCwaivYAF/1sUAnQmaWSERFzRQUQFuf7GW5ZwByDkuIIXRZHN7AGDnwj1TZ xcwtZSIuVBaPnQ8My+RC/nj8xSiwdRipQini1xZAaglifqe2l+rEfzMfXdqt82H7cQJC AYP3pIlMlf9UgYjEomUmWiFyeNrRics69nY8Y7/o8gmBlF5fNnzp5C6Crmb9cbEBdtEK 2jxlu2yHyCMAne5X9+iPZBPWAijoglvBcWt3fDkK6RTyCuKszsiZvw/HsHkbREwclIS2 NTXdnMjeHRbZyymk9BM44sPYnnqfgOebR0aG5U7JrT56DnBVInLz9befUrvfODAb9Yk2 PW3w== 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=FvcC9+Awj3oLlqD6kMLWnWRMbi+Vd2Rz0NaLG9avzbk=; b=BHdjqt9ivrrezqc8RxTk6Ch6FrXLz3NR2l/ZP2k/+taKUKtkPzullSgxkl1h6yRJv5 IpR9F6tu546213X7G8tXRqlORY+l7hxPNKdY6uz6/z0/6zQeTZGE1LKZo1lngEIkUg64 DSceVEO8hNgFxbtL8SL1dQWS+8e+grxh8k7qLH3q9In8u/zfRGuYfwa0ID735xpc4uIK NFC8VEKHW2vRzjaXsri1dnKeoM1QSkbvfHnw+39z3OFUvxRggeGWEc0sL3jq8NnPm+rX iL9CG1ZzqKj6/kWQ2hevpN6WoKxsMqoIr1sPp1WrqmrmFpkmX767IMx4i1BYWALLO6KS vycg== X-Gm-Message-State: AOAM5337GjvkeJeRNu2HqIMpELGkhsfCblHIdRg6r/7GybTx+ZtJdFKb c6Llj0YMTIWQVk2q1k+1rGg= X-Google-Smtp-Source: ABdhPJwtpvTyc6Y3aAAEUHwIroZpyhcoIU83HjobP6mzNtwVCcIwEM0hKMI+YLXyaCt04AD+jo9KhQ== X-Received: by 2002:a63:33c4:: with SMTP id z187mr2112140pgz.474.1644295863895; Mon, 07 Feb 2022 20:51:03 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:03 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 04/11] nexthop: change nexthop_net_exit() to nexthop_net_exit_batch() Date: Mon, 7 Feb 2022 20:50:31 -0800 Message-Id: <20220208045038.2635826-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. nexthop_net_exit() seems a good candidate for exit_batch(), as this gives chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index eeafeccebb8d44629085f504e26cb4e171c8c782..e459a391e607d34e16828bef13a5ce22ba6dde89 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3733,12 +3733,16 @@ void nexthop_res_grp_activity_update(struct net *net, u32 id, u16 num_buckets, } EXPORT_SYMBOL(nexthop_res_grp_activity_update); -static void __net_exit nexthop_net_exit(struct net *net) +static void __net_exit nexthop_net_exit_batch(struct list_head *net_list) { + struct net *net; + rtnl_lock(); - flush_all_nexthops(net); + list_for_each_entry(net, net_list, exit_list) { + flush_all_nexthops(net); + kfree(net->nexthop.devhash); + } rtnl_unlock(); - kfree(net->nexthop.devhash); } static int __net_init nexthop_net_init(struct net *net) @@ -3756,7 +3760,7 @@ static int __net_init nexthop_net_init(struct net *net) static struct pernet_operations nexthop_net_ops = { .init = nexthop_net_init, - .exit = nexthop_net_exit, + .exit_batch = nexthop_net_exit_batch, }; static int __init nexthop_init(void) From patchwork Tue Feb 8 04:50:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738188 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 9301CC433EF for ; Tue, 8 Feb 2022 05:33:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242961AbiBHFd3 (ORCPT ); Tue, 8 Feb 2022 00:33:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347044AbiBHEvI (ORCPT ); Mon, 7 Feb 2022 23:51:08 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C99C0401E5 for ; Mon, 7 Feb 2022 20:51:07 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id u130so16839063pfc.2 for ; Mon, 07 Feb 2022 20:51:07 -0800 (PST) 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=MO0sIC6aoDSHuE1A77wb7716OltOM6QAoh5qnGMh2Os=; b=nUiSgYkcAATTYcKmRrIUmZ2D70W7aZUVeLkwWoacnQrT9IdEJWdIMWpEHPyacz9TNr aXR+ZaMu7Wl/pOZJ1Fdm7ZcoXHgQT4Fc/fjB/xESEp01bq5s8CUYpJa6yW3MgiQDAs2r OIWzVSEbY2TGKDgRqFsokJmmgC0jZulmdDMm6R383ewjMZX4f95qTwJ6GgfhGutKdK/X EUOTAcCvrrseBeAQB7u7OpLEC6CeYohcb4tMaR4jcl/99KDcTF63+38n+L1pgPmJzEam RGdpKSNOsfBC7QDTpskxArzSVgpz6mrE5PJcq6VKlyAO8r6l7G6TOLV78iMdG8CQC8mB 3Vnw== 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=MO0sIC6aoDSHuE1A77wb7716OltOM6QAoh5qnGMh2Os=; b=p+fYDxpwPsZxvY0QGlMSdXYp6J96zVmzI6c4ZLiFR3O/jDBNexebvvZPQ4ZLSHMDKq KcCu0e/0kjwWd2fGLsGOKB1azweO15HSiXsJ4V27dto5Da+JPoTl9dWvQMgS+H7leG+q BgNBlzi9rGcidtiNVHsW6er7rxCqFmS5+2ZyX8OoLQTZbQoLZ2ogk3kAoZ9Y+UI1J5IG 0ICHjxMiD9gDMywg9tHnP4z76z7s9Ai8Ygj6PJZ3VOokw0yizWmAbfAP9X7KUrCBtSo/ x+rJ8VeRGSOTV+iyqCKH0hIksUg2EpRXvga5dzRAm7TzpAAj5ONgpUV8uadcucZnglUs wRxg== X-Gm-Message-State: AOAM533W1vEJwWnswVIvnTJUNsQEHMC6I72QYPRvEAEX1Ow+WVFo8bfH B7m6IQ1HpDxKViZ+xewEfRw= X-Google-Smtp-Source: ABdhPJwksc0PYZZqCsTLGAhfRJfxmh/cuQhzoGyaOL4JE4KByUsmRTVKwjvijW7YG8XiPiNpRPphQA== X-Received: by 2002:a05:6a00:1588:: with SMTP id u8mr2690475pfk.4.1644295867415; Mon, 07 Feb 2022 20:51:07 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:07 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 05/11] ipv4: add fib_net_exit_batch() Date: Mon, 7 Feb 2022 20:50:32 -0800 Message-Id: <20220208045038.2635826-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. Instead of acquiring rtnl at each fib_net_exit() invocation, add fib_net_exit_batch() so that rtnl is acquired once. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv4/fib_frontend.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 4d61ddd8a0ecfc4cc47b4802eb5a573beb84ee44..8c10f671d24db7f5751b6aed8e90a902bd1be5b4 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -1547,7 +1547,7 @@ static void ip_fib_net_exit(struct net *net) { int i; - rtnl_lock(); + ASSERT_RTNL(); #ifdef CONFIG_IP_MULTIPLE_TABLES RCU_INIT_POINTER(net->ipv4.fib_main, NULL); RCU_INIT_POINTER(net->ipv4.fib_default, NULL); @@ -1572,7 +1572,7 @@ static void ip_fib_net_exit(struct net *net) #ifdef CONFIG_IP_MULTIPLE_TABLES fib4_rules_exit(net); #endif - rtnl_unlock(); + kfree(net->ipv4.fib_table_hash); fib4_notifier_exit(net); } @@ -1599,7 +1599,9 @@ static int __net_init fib_net_init(struct net *net) out_proc: nl_fib_lookup_exit(net); out_nlfl: + rtnl_lock(); ip_fib_net_exit(net); + rtnl_unlock(); goto out; } @@ -1607,12 +1609,23 @@ static void __net_exit fib_net_exit(struct net *net) { fib_proc_exit(net); nl_fib_lookup_exit(net); - ip_fib_net_exit(net); +} + +static void __net_exit fib_net_exit_batch(struct list_head *net_list) +{ + struct net *net; + + rtnl_lock(); + list_for_each_entry(net, net_list, exit_list) + ip_fib_net_exit(net); + + rtnl_unlock(); } static struct pernet_operations fib_net_ops = { .init = fib_net_init, .exit = fib_net_exit, + .exit_batch = fib_net_exit_batch, }; void __init ip_fib_init(void) From patchwork Tue Feb 8 04:50:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738162 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 BA0B2C43217 for ; Tue, 8 Feb 2022 05:33:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231652AbiBHFdA (ORCPT ); Tue, 8 Feb 2022 00:33:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347046AbiBHEvL (ORCPT ); Mon, 7 Feb 2022 23:51:11 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5255DC0401E5 for ; Mon, 7 Feb 2022 20:51:11 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id c3so12877738pls.5 for ; Mon, 07 Feb 2022 20:51:11 -0800 (PST) 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=zsNMXE+P45OQsH5Dutxol2CPtyXwO7PMwPm5gWuakjs=; b=Dy6sluPV98pHSN6HjX+d8ZqNevr0X2lkD9OOBtGZbFN9bMeVHLFXdKlnq6Tk4MW46S 0A231bN7Jhum+BX05rh6EKpoPC6FBtwsLFJjFGDd/RPPal72Wo3T3tD8elcy0U6mAx/e Xldxu7YNVjigA7yI4U6x+behMo13vOimBDO+gNhK6ZNtG5yV8ohBNaqpQgD1zJOSbN0N d9JyiC9ozru5VzIqy7BUJQQgT8OI5hNLRMvBOOHe0IFJrg2QHm2b2MSu1IS0aHpauYbt 0XEMDF4eH2urPyAKxbzrpXnwy7LYWzQLSRfAnWAYXQLiKKaOT1nq7BThTE4kSAZJW03l NMzw== 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=zsNMXE+P45OQsH5Dutxol2CPtyXwO7PMwPm5gWuakjs=; b=ZRYvudOMvx7zTgjE5kOMQ8vWVv9NalE/YWuWbYO47lrzZDcNvkQHmqUrx6P1YhlCqM 7+torR+NS+ARl7aOZQtU8690VCpinucNf2auZraL6mJoC+sJzl2KvfoSAmXkg+Ahnhkk 7vfY5VeM8Y5I1dLtZWRcNU3aYiNYHTtEiMgAH+QIZL2ylkR1jADqShOOZgN9BtkFvBmn 8fjwgn3xh9yEep0VMhjAF9bZrGFutnFPKPdAKPDFRAYduErKbYF3ahcu18YVGItQjc28 aBsYaQ89n8dZlDoiiwjqTBwsgLvXsFW1ocdQvUjHHTQj0TVk9iefI++kTIUotIIOcbu3 YSYw== X-Gm-Message-State: AOAM531HcTPtrrc5W9Og+66Mez6OL0l4Nj/EfBqW9iYcWArV7a1XqYmQ Waa3CxNza8FJSO/I+7J/GYk= X-Google-Smtp-Source: ABdhPJwUjvW9Zg1bEeA7mdRcRMHLLqLe3BJ8f5/tyB37sAcjWuaoJol53x7D5Tw5lxUf0sGl1RycDw== X-Received: by 2002:a17:902:8ec5:: with SMTP id x5mr2791258plo.161.1644295870893; Mon, 07 Feb 2022 20:51:10 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:10 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 06/11] ipv6: change fib6_rules_net_exit() to batch mode Date: Mon, 7 Feb 2022 20:50:33 -0800 Message-Id: <20220208045038.2635826-7-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. fib6_rules_net_exit() seems a good candidate for exit_batch(), as this gives chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv6/fib6_rules.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c index ec029c86ae06828c1cfe886ad0f401318b114310..8ad4f49cbe0bb1a31645bbdd4735c69b9b52d8bb 100644 --- a/net/ipv6/fib6_rules.c +++ b/net/ipv6/fib6_rules.c @@ -486,16 +486,21 @@ static int __net_init fib6_rules_net_init(struct net *net) goto out; } -static void __net_exit fib6_rules_net_exit(struct net *net) +static void __net_exit fib6_rules_net_exit_batch(struct list_head *net_list) { + struct net *net; + rtnl_lock(); - fib_rules_unregister(net->ipv6.fib6_rules_ops); + list_for_each_entry(net, net_list, exit_list) { + fib_rules_unregister(net->ipv6.fib6_rules_ops); + cond_resched(); + } rtnl_unlock(); } static struct pernet_operations fib6_rules_net_ops = { .init = fib6_rules_net_init, - .exit = fib6_rules_net_exit, + .exit_batch = fib6_rules_net_exit_batch, }; int __init fib6_rules_init(void) From patchwork Tue Feb 8 04:50:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738158 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 86959C43217 for ; Tue, 8 Feb 2022 05:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347055AbiBHFc5 (ORCPT ); Tue, 8 Feb 2022 00:32:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347048AbiBHEvP (ORCPT ); Mon, 7 Feb 2022 23:51:15 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D21D5C0401E5 for ; Mon, 7 Feb 2022 20:51:14 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id c3so12877829pls.5 for ; Mon, 07 Feb 2022 20:51:14 -0800 (PST) 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=kVKXyuZ9ByNL5gRoA1X/9lUBlGLA/Ue4kD0z9O4JtmE=; b=ndm/EqwT20dbUfQaQoP68hxyiyTrMqRB8BNRcWIqlkuq4+gqqT5bmAZtWz+nAMxHsY 26wE2zWfawlZ8yqCE/i0WE2n08/f/iF0mWVSZ3FoSRjyjGsa12Vmghm2CUu0oPKh8TEF lE9I6ibYtN8QxkeHbjYJJTPMPGt9971FEQdfpya+nfp0slF3tt2JTptJvCFUrsbVRK0X qP0WIVs/ZySsFn9WWFyeZus2uU4bR32IJtp8boMWK9iFESedW1gfdsjDQrc8jEmJ1e8e U9tg0gmVsLJCbPxhTQOPaneVdHMKFKga9dUwnFulfyq03ItF9F2ewTNSPwND8U9FZKw8 Gz3g== 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=kVKXyuZ9ByNL5gRoA1X/9lUBlGLA/Ue4kD0z9O4JtmE=; b=s4q4alyuPiOehUMU1fZY9IHJlXDPyGkC9HbBO9FtMdxFhPoFodpfl7T9Dti2XAY8Ki ExASnaBbHWVELh/tBr6Rp7h9z3QIVrSmWinKTWb3dXLmiG9p3TYTl7Pg7QvvEZXzpKCg mIeQSvvyac7HWJXiNVAVsCFZ5r3QvtmbESNh2VtIka6nB+/iN5HnZmPGk8w7LSK5f6FN WrFY4dqzHGbHWN3zJumK/jKJZ1AUMeOV6WMf3mRGcAhQyXmvqUrjZofNkMK/7GgvSmR+ SVqv1vnJae/rhSrDSA5Z0u9WWqz97796+miDc4spTr/thdrjOiePlz+SqltJKTPbTe0n g6SA== X-Gm-Message-State: AOAM532dV6m/44gmG9+SaNph6Q0rz/bEBg5DGT3CTrY1HTrU+tEa2CZJ M/PxyR5SHIjwajUfPrJJZB43CR6M6XQ= X-Google-Smtp-Source: ABdhPJyPJKUjx5OQIumhTyzp5EB1OwduSeQGNOe/QOByCordY1RiCft0Wmk7RGWmhw0SEMMzHjBfCg== X-Received: by 2002:a17:902:d4c1:: with SMTP id o1mr2995240plg.167.1644295874393; Mon, 07 Feb 2022 20:51:14 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:14 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 07/11] ip6mr: introduce ip6mr_net_exit_batch() Date: Mon, 7 Feb 2022 20:50:34 -0800 Message-Id: <20220208045038.2635826-8-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. Avoiding to acquire rtnl for each netns before calling ip6mr_rules_exit() gives chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv6/ip6mr.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index fd660414d482a30c6d339bb7360bd91d8f3c6f05..881fe6b503072598384b7d935eab66087cd555b6 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -253,13 +253,12 @@ static void __net_exit ip6mr_rules_exit(struct net *net) { struct mr_table *mrt, *next; - rtnl_lock(); + ASSERT_RTNL(); list_for_each_entry_safe(mrt, next, &net->ipv6.mr6_tables, list) { list_del(&mrt->list); ip6mr_free_table(mrt); } fib_rules_unregister(net->ipv6.mr6_rules_ops); - rtnl_unlock(); } static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb, @@ -316,10 +315,9 @@ static int __net_init ip6mr_rules_init(struct net *net) static void __net_exit ip6mr_rules_exit(struct net *net) { - rtnl_lock(); + ASSERT_RTNL(); ip6mr_free_table(net->ipv6.mrt6); net->ipv6.mrt6 = NULL; - rtnl_unlock(); } static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb, @@ -1323,7 +1321,9 @@ static int __net_init ip6mr_net_init(struct net *net) proc_cache_fail: remove_proc_entry("ip6_mr_vif", net->proc_net); proc_vif_fail: + rtnl_lock(); ip6mr_rules_exit(net); + rtnl_unlock(); #endif ip6mr_rules_fail: ip6mr_notifier_exit(net); @@ -1336,13 +1336,23 @@ static void __net_exit ip6mr_net_exit(struct net *net) remove_proc_entry("ip6_mr_cache", net->proc_net); remove_proc_entry("ip6_mr_vif", net->proc_net); #endif - ip6mr_rules_exit(net); ip6mr_notifier_exit(net); } +static void __net_exit ip6mr_net_exit_batch(struct list_head *net_list) +{ + struct net *net; + + rtnl_lock(); + list_for_each_entry(net, net_list, exit_list) + ip6mr_rules_exit(net); + rtnl_unlock(); +} + static struct pernet_operations ip6mr_net_ops = { .init = ip6mr_net_init, .exit = ip6mr_net_exit, + .exit_batch = ip6mr_net_exit_batch, }; int __init ip6_mr_init(void) From patchwork Tue Feb 8 04:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738160 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 EA5BAC43217 for ; Tue, 8 Feb 2022 05:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347333AbiBHFdF (ORCPT ); Tue, 8 Feb 2022 00:33:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347049AbiBHEvS (ORCPT ); Mon, 7 Feb 2022 23:51:18 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFBD7C0401E5 for ; Mon, 7 Feb 2022 20:51:17 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id y9so7472451pjf.1 for ; Mon, 07 Feb 2022 20:51:17 -0800 (PST) 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=/e0ictUQzluRJgt7JrTdVRCzpOV3bwWprr9d9iNmdK4=; b=Z2mISDPxthQYLdzypQLMKyrMiRtT9ypk7HYCnbJwDEP9G47P6W7n00qrBgOZHtBRuM bWuEsOkmWKF08/pDd/B+Qq7Qqq1wR540fffvMKS2AYgQEDkaVntMwvIgvpHObTWvuByx HkhJ+SqnJ9ElEsWJZCsuInYPgnwBhEkbhIXaKM2s/cZ6h83/WptzSIGDbNg4NkGQC1V5 ELYUrZfZrtjbkoqa2pj2PiDrMfilHhPgORvxDwJOpDWyutsNKlZMMmgoeoIxpW6t1m40 rBEoBRRDE8fQOC5XvNetV5ETrOfKIl6LPfTR5/whzWqBjfpM7CL1/9KRA1MLwUyt41tu tXYA== 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=/e0ictUQzluRJgt7JrTdVRCzpOV3bwWprr9d9iNmdK4=; b=ZAcd3c9VZVe5uYUHSkwGrHbx3wNh9RQzIkpj9kgcg54qW0bHQ3mB4HDTiP1F87Gmnx fZqLs2MSYvO3Jxv/haOYw9AxPZRr+uzERB6L4zG3ych3CWiJmeJG79sRz1BBhP4h147f V5/KGdEL5nemif31bdue8L3Q3B0e95WZ+xbTmQOsc3APsT2z6NnSjdoGmqX/vyljz5Mx dxx4qyFPYEDB54WevJXRZswTCUSSycystDrGv7ntEESzmQnSMX5tou52l6Pj5g7QXBPm VCEANPvXshvAqBcDh2klQo4Ccm37v5+SUYLtdEfBJsxDtVnt/euPmUMiqLDA4VrQhBgc sxCA== X-Gm-Message-State: AOAM532lGgWc67EbKN1tbEcYIOONJW6LlfGrlUNSbLACvO9AxjbO0G1U kAKRKbtrQdDHqAd/BtMI4X8= X-Google-Smtp-Source: ABdhPJzyM6HEXiicR6ax7vZdfZo0kuSxuwOcAfuliiCXotBYOUizKXl+NwOvExiAKfLvh1p8CDek9g== X-Received: by 2002:a17:90b:4a82:: with SMTP id lp2mr2501384pjb.179.1644295877408; Mon, 07 Feb 2022 20:51:17 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:17 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 08/11] ipmr: introduce ipmr_net_exit_batch() Date: Mon, 7 Feb 2022 20:50:35 -0800 Message-Id: <20220208045038.2635826-9-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. Avoiding to acquire rtnl for each netns before calling ipmr_rules_exit() gives chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/ipv4/ipmr.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 07274619b9ea11837501f8fe812d616d20573ee0..4a55a620e52675b7a4bdbea8ca0476b8c92dcb13 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -266,13 +266,12 @@ static void __net_exit ipmr_rules_exit(struct net *net) { struct mr_table *mrt, *next; - rtnl_lock(); + ASSERT_RTNL(); list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) { list_del(&mrt->list); ipmr_free_table(mrt); } fib_rules_unregister(net->ipv4.mr_rules_ops); - rtnl_unlock(); } static int ipmr_rules_dump(struct net *net, struct notifier_block *nb, @@ -328,10 +327,9 @@ static int __net_init ipmr_rules_init(struct net *net) static void __net_exit ipmr_rules_exit(struct net *net) { - rtnl_lock(); + ASSERT_RTNL(); ipmr_free_table(net->ipv4.mrt); net->ipv4.mrt = NULL; - rtnl_unlock(); } static int ipmr_rules_dump(struct net *net, struct notifier_block *nb, @@ -3075,7 +3073,9 @@ static int __net_init ipmr_net_init(struct net *net) proc_cache_fail: remove_proc_entry("ip_mr_vif", net->proc_net); proc_vif_fail: + rtnl_lock(); ipmr_rules_exit(net); + rtnl_unlock(); #endif ipmr_rules_fail: ipmr_notifier_exit(net); @@ -3090,12 +3090,22 @@ static void __net_exit ipmr_net_exit(struct net *net) remove_proc_entry("ip_mr_vif", net->proc_net); #endif ipmr_notifier_exit(net); - ipmr_rules_exit(net); +} + +static void __net_exit ipmr_net_exit_batch(struct list_head *net_list) +{ + struct net *net; + + rtnl_lock(); + list_for_each_entry(net, net_list, exit_list) + ipmr_rules_exit(net); + rtnl_unlock(); } static struct pernet_operations ipmr_net_ops = { .init = ipmr_net_init, .exit = ipmr_net_exit, + .exit_batch = ipmr_net_exit_batch, }; int __init ip_mr_init(void) From patchwork Tue Feb 8 04:50:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738161 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 60EC2C433FE for ; Tue, 8 Feb 2022 05:33:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiBHFdE (ORCPT ); Tue, 8 Feb 2022 00:33:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347050AbiBHEvV (ORCPT ); Mon, 7 Feb 2022 23:51:21 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31621C0401E5 for ; Mon, 7 Feb 2022 20:51:21 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id r19so1072013pfh.6 for ; Mon, 07 Feb 2022 20:51:21 -0800 (PST) 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=peBaA7kLTFMHNdqrp6EFqwBYzVxcQ7eDSyelvqpjrPw=; b=YA1eZoM2cGPYHaBn2kGnAA+jeqXRQFurQFQsfMboN5gotBRB4EhDB3WWvOI3xkuqYb DEBSURqmj/PFGhny1CSJIX9KieIr1uPE2YtgM3YvO7a485Nv7cFN4zZtJ9tdL+5Uuy// COBm8tcnBKII8uTvfrBO1Kidd1rNu82hoNkF8LcBY35cGt6zx7KQmbiK+wb/08kcRiNR 7680Pqixjj2JJ4tBp/hFpOp+9WQHe+c5y4V1uNDob+ihZ4wIUdy6d5JYNvUCVJJEkjrs FwGrrxNa6cKT/nHydqojo3sWcZyS7iv34fyOwmyO6QyRdOR4V95sm0OmtTmeBoeg5X3j 6XDg== 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=peBaA7kLTFMHNdqrp6EFqwBYzVxcQ7eDSyelvqpjrPw=; b=iJM0yN01W/tcAMswA2bfiwvsqpAhW1pznj9NWCvgHfjytn9BdMlwLurE1u6qv3Wp7g yC3eGT3IlqrfETVkmbaycq+w7qIzlXSesS5WZCzFOitI0CwNc7y5JqVQGPr6OF5yM197 n6Qua/psgzDu6OW3A1bADQ1wL+/KSQTU0nG7zvZw5/AfBokMeRL5X05G5C/i5z5dB5f+ aRQkEMxOJ14d4vuadbKzG2TxLgZ9oxp4tWhUrshEFLmo5RZOZdjP6ogwukn8DmpubmJn NWrD5sChz5C0fNESm/iT+xdYwWE68mFuUAZhrQRqKZgomcXvttTWgMvt2A0j5DzxFjFM 5uTw== X-Gm-Message-State: AOAM5315Bu6VKu7KHG4VJzBXibIgZtSkauj9fpoZWPaRohzJ38IMmDAT wKBB/lwaR5RXIiyqrRBPcSErUa62Eec= X-Google-Smtp-Source: ABdhPJxzZc1+DbaQN6ZdAuTiVGYUdbcbzOD5e38A5ofb0TlJulSobfuPfQL2lAkIqjKNOXAVbfTcTg== X-Received: by 2002:a63:f958:: with SMTP id q24mr2179371pgk.372.1644295880764; Mon, 07 Feb 2022 20:51:20 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:20 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH v2 net-next 09/11] can: gw: switch cangw_pernet_exit() to batch mode Date: Mon, 7 Feb 2022 20:50:36 -0800 Message-Id: <20220208045038.2635826-10-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. Avoiding to acquire rtnl for each netns before calling cgw_remove_all_jobs() gives chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Acked-by: Oliver Hartkopp Cc: Marc Kleine-Budde Acked-by: Marc Kleine-Budde --- net/can/gw.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/can/gw.c b/net/can/gw.c index d8861e862f157aec36c417b71eb7e8f59bd064b9..24221352e059be9fb9aca3819be6a7ac4cdef144 100644 --- a/net/can/gw.c +++ b/net/can/gw.c @@ -1239,16 +1239,19 @@ static int __net_init cangw_pernet_init(struct net *net) return 0; } -static void __net_exit cangw_pernet_exit(struct net *net) +static void __net_exit cangw_pernet_exit_batch(struct list_head *net_list) { + struct net *net; + rtnl_lock(); - cgw_remove_all_jobs(net); + list_for_each_entry(net, net_list, exit_list) + cgw_remove_all_jobs(net); rtnl_unlock(); } static struct pernet_operations cangw_pernet_ops = { .init = cangw_pernet_init, - .exit = cangw_pernet_exit, + .exit_batch = cangw_pernet_exit_batch, }; static __init int cgw_module_init(void) From patchwork Tue Feb 8 04:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738165 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 C366EC4321E for ; Tue, 8 Feb 2022 05:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347400AbiBHFdP (ORCPT ); Tue, 8 Feb 2022 00:33:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347052AbiBHEvZ (ORCPT ); Mon, 7 Feb 2022 23:51:25 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5487BC0401E5 for ; Mon, 7 Feb 2022 20:51:24 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id i30so16811441pfk.8 for ; Mon, 07 Feb 2022 20:51:24 -0800 (PST) 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=86erZqV65XT7HOKTwd7EuyR31bW9wtxCPKCH1CEIE5E=; b=hdPi1y6Yn4f5iLrmKF6i4zEObFSqqkyjp2w44rPcWP3Z+QwrNgy64/V0UUFdzqb6// s+fiOivyFwFapryI3NtPkVL7pfrS23jVCcLhdBFria5CdVA+S8gBMB45VmD51djK9Cg5 PIBcyF2vhEvLFB46MNAAmmMm7PTjyUzQXSQRwRl1+2RAaS0fmBP8eIn3zbm7+DGyCz34 kj1YywTI4K1BkI4dUXnKGuQiIBmFtQ9pMRyId1ncSDscPRHuOXNG5Rl11TMV1Dfm4hqP IirpbKAtuw8lbnYuFCTzsKpG+G+YPh8nj1eURGa7t5LukFh5t4Y68fnhu9KtvDYPgr+u E0Dw== 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=86erZqV65XT7HOKTwd7EuyR31bW9wtxCPKCH1CEIE5E=; b=CwhIol7pfrAzckBXR5rmZisB9mKlB/LBQ8X2cZoBcPAvEbNyFnxX43qGvpaBlttcp1 vT+AGdII0tQ3oUB3bQKgtAzoMC4RNaYJC0k3izdTvCTGppBtkbeEgsulPyMJ9D+Yjb01 /DQR2rhxtnokm7eLsnlm8yWuJJZ3Ygb9y0Kd6Ij6tgBlitYbMmbvGkczxcml5XPALvuS nVX2ZAxcT4+WA1f3H+EUn0lzJc0G+ERptnqkRaFTveuLUp8wTUr4c+gW/rFLHjC7MJ2Z kzel1sMGxo8L9DakGFroXnrYLNGWK7lZRlTjzPWyQEn1AZqFcAwxqlQBenApqV8h3UVr 0/9g== X-Gm-Message-State: AOAM531Bub+k4Z1Zx2Cu3OKHFVKsA4A6OxyUwcSciH4ZtYU+GuPHWA/Q ur+twINqmawhqgl/JN7dFLE= X-Google-Smtp-Source: ABdhPJyvWo9hjB4OR6IzM9Rxbd3Tr8zcfJi5bEO1n30RDqJnE6U/Dhxh/EcVyOOqNCd16S8SOSEpnw== X-Received: by 2002:a05:6a00:1902:: with SMTP id y2mr2650946pfi.57.1644295883860; Mon, 07 Feb 2022 20:51:23 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:23 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek Subject: [PATCH v2 net-next 10/11] bonding: switch bond_net_exit() to batch mode Date: Mon, 7 Feb 2022 20:50:37 -0800 Message-Id: <20220208045038.2635826-11-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 cleanup_net() is competing with other rtnl users. Batching bond_net_exit() factorizes all rtnl acquistions to a single one, giving chance for cleanup_net() to progress much faster, holding rtnl a bit longer. Signed-off-by: Eric Dumazet Cc: Jay Vosburgh Cc: Veaceslav Falico Cc: Andy Gospodarek --- drivers/net/bonding/bond_main.c | 27 +++++++++++++++++++-------- drivers/net/bonding/bond_procfs.c | 1 - 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 238b56d77c369d9595d55bc681c2191c49dd2905..617c2bf8c5a7f71ece82a20dbd3a9740b928ef6a 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -6048,27 +6048,38 @@ static int __net_init bond_net_init(struct net *net) return 0; } -static void __net_exit bond_net_exit(struct net *net) +static void __net_exit bond_net_exit_batch(struct list_head *net_list) { - struct bond_net *bn = net_generic(net, bond_net_id); - struct bonding *bond, *tmp_bond; + struct bond_net *bn; + struct net *net; LIST_HEAD(list); - bond_destroy_sysfs(bn); + list_for_each_entry(net, net_list, exit_list) { + bn = net_generic(net, bond_net_id); + bond_destroy_sysfs(bn); + } /* Kill off any bonds created after unregistering bond rtnl ops */ rtnl_lock(); - list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list) - unregister_netdevice_queue(bond->dev, &list); + list_for_each_entry(net, net_list, exit_list) { + struct bonding *bond, *tmp_bond; + + bn = net_generic(net, bond_net_id); + list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list) + unregister_netdevice_queue(bond->dev, &list); + } unregister_netdevice_many(&list); rtnl_unlock(); - bond_destroy_proc_dir(bn); + list_for_each_entry(net, net_list, exit_list) { + bn = net_generic(net, bond_net_id); + bond_destroy_proc_dir(bn); + } } static struct pernet_operations bond_net_ops = { .init = bond_net_init, - .exit = bond_net_exit, + .exit_batch = bond_net_exit_batch, .id = &bond_net_id, .size = sizeof(struct bond_net), }; diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c index 46b150e6289ef4607c8ddbcd2b833ff4dd64cc9b..cfe37be42be4e0edb218c45127a378b53e487df8 100644 --- a/drivers/net/bonding/bond_procfs.c +++ b/drivers/net/bonding/bond_procfs.c @@ -307,7 +307,6 @@ void __net_init bond_create_proc_dir(struct bond_net *bn) } /* Destroy the bonding directory under /proc/net, if empty. - * Caller must hold rtnl_lock. */ void __net_exit bond_destroy_proc_dir(struct bond_net *bn) { From patchwork Tue Feb 8 04:50:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12738159 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 8D9DAC4321E for ; Tue, 8 Feb 2022 05:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347289AbiBHFc7 (ORCPT ); Tue, 8 Feb 2022 00:32:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347053AbiBHEv3 (ORCPT ); Mon, 7 Feb 2022 23:51:29 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A3AC0401E5 for ; Mon, 7 Feb 2022 20:51:28 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id i17so16800364pfq.13 for ; Mon, 07 Feb 2022 20:51:28 -0800 (PST) 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=W9SJ+JIzO4YpVyuc5zFzbPz+F4qocdc922RikmWgzPc=; b=f7NKvLmzXK26V3rNDS+bqdDoQE7dqy8zfhDrHxxUS1KMht8VfKAYh7n2rI2xV4Yr3m 4X/UjQfHaxsnc8r1FLM0anXliRogUTXm8/H7UB/8SJW8S0KedSQW5RizHBQAMeBjCzH2 ZswftST/LDPR2nUVPno42fGXTP2Arq0/ZvEjFIrz+brpXDk3TPq6xVghr4XtjK2Z1ZML mzCMeG9NcohE1gK5DcqletIW0VmKZ6BkGivoQCkpbtwUftvfezp+K0SxRHHGRtaHgWVm tnFgVBctuGIHwfey1CiMvGq+TcQdJdJmkvk6q+OKLA6mulhFcucEKUXJO1wiwV3v0x2C D/BA== 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=W9SJ+JIzO4YpVyuc5zFzbPz+F4qocdc922RikmWgzPc=; b=OHU8+UzKIyx3iR6ZnKmDk1GxHTG9gIWxsJRadHavHFrPdi64mwkIxEhBSnUfW67poM fRCB6gbgwSZyuCe9wSdkcbjLp5iMrPiWPCk6J2708qAvsPqWN2bqVM192QrP2g+Dbg73 A348cR2rSZ96NFlI+Kie2OXa7/24KsgIomu/4LKNazpAcfN6FDf2CndX1vskzXmvfADo 8mK39HKyvAtvTZ4Kd9ZwAzcTEzC78dMudY30cdl6tEEcFI9pbj4JZb9NFkST/O3kbHN0 Txog/iJnWsWThHwabLTo2x2vnS4Lxpjp1iE2T98rtqpQiP5qmX9kOXFOSJs1EwPi9JdI vLYQ== X-Gm-Message-State: AOAM5323nE7BTa+rkciN2zoMfS9GP7DDF7lf22RzgF7NuNFxM0QrUWK6 A39/cm+bfAeqWrjTXUbRW9TK1eNz4Ho= X-Google-Smtp-Source: ABdhPJycInHtNDnnLFZUw4wpjRnSeni4sBjbMiMCOLPiAkznQmDS7/E0sUM3vLUwzPFvZGqVFpZTlA== X-Received: by 2002:a05:6a00:cd2:: with SMTP id b18mr2640350pfv.63.1644295888060; Mon, 07 Feb 2022 20:51:28 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:8f56:515b:a442:2bd5]) by smtp.gmail.com with ESMTPSA id j23sm9810257pgb.75.2022.02.07.20.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 20:51:27 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 11/11] net: remove default_device_exit() Date: Mon, 7 Feb 2022 20:50:38 -0800 Message-Id: <20220208045038.2635826-12-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208045038.2635826-1-eric.dumazet@gmail.com> References: <20220208045038.2635826-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 For some reason default_device_ops kept two exit method: 1) default_device_exit() is called for each netns being dismantled in a cleanup_net() round. This acquires rtnl for each invocation. 2) default_device_exit_batch() is called once with the list of all netns int the batch, allowing for a single rtnl invocation. Get rid of the .exit() method to handle the logic from default_device_exit_batch(), to decrease the number of rtnl acquisition to one. Signed-off-by: Eric Dumazet Reviewed-by: David Ahern --- net/core/dev.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index f662c6a7d7b49b836a05efc74aeffc7fc9e4e147..e39c2897f6475dfa77c478603cfced76ba0b9078 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10848,14 +10848,14 @@ static struct pernet_operations __net_initdata netdev_net_ops = { .exit = netdev_exit, }; -static void __net_exit default_device_exit(struct net *net) +static void __net_exit default_device_exit_net(struct net *net) { struct net_device *dev, *aux; /* * Push all migratable network devices back to the * initial network namespace */ - rtnl_lock(); + ASSERT_RTNL(); for_each_netdev_safe(net, dev, aux) { int err; char fb_name[IFNAMSIZ]; @@ -10879,22 +10879,22 @@ static void __net_exit default_device_exit(struct net *net) BUG(); } } - rtnl_unlock(); } static void __net_exit rtnl_lock_unregistering(struct list_head *net_list) { - /* Return with the rtnl_lock held when there are no network + /* Return (with the rtnl_lock held) when there are no network * devices unregistering in any network namespace in net_list. */ - struct net *net; - bool unregistering; DEFINE_WAIT_FUNC(wait, woken_wake_function); + bool unregistering; + struct net *net; + ASSERT_RTNL(); add_wait_queue(&netdev_unregistering_wq, &wait); for (;;) { unregistering = false; - rtnl_lock(); + list_for_each_entry(net, net_list, exit_list) { if (net->dev_unreg_count > 0) { unregistering = true; @@ -10906,6 +10906,7 @@ static void __net_exit rtnl_lock_unregistering(struct list_head *net_list) __rtnl_unlock(); wait_woken(&wait, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT); + rtnl_lock(); } remove_wait_queue(&netdev_unregistering_wq, &wait); } @@ -10921,6 +10922,11 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list) struct net *net; LIST_HEAD(dev_kill_list); + rtnl_lock(); + list_for_each_entry(net, net_list, exit_list) { + default_device_exit_net(net); + cond_resched(); + } /* To prevent network device cleanup code from dereferencing * loopback devices or network devices that have been freed * wait here for all pending unregistrations to complete, @@ -10933,6 +10939,7 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list) * default_device_exit_batch. */ rtnl_lock_unregistering(net_list); + list_for_each_entry(net, net_list, exit_list) { for_each_netdev_reverse(net, dev) { if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) @@ -10946,7 +10953,6 @@ static void __net_exit default_device_exit_batch(struct list_head *net_list) } static struct pernet_operations __net_initdata default_device_ops = { - .exit = default_device_exit, .exit_batch = default_device_exit_batch, };