From patchwork Mon Feb 7 17:17:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737705 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 4429DC433EF for ; Mon, 7 Feb 2022 17:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235661AbiBGRSb (ORCPT ); Mon, 7 Feb 2022 12:18:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384217AbiBGRSG (ORCPT ); Mon, 7 Feb 2022 12:18:06 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1328C0401D8 for ; Mon, 7 Feb 2022 09:18:05 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id t9so9431266plg.13 for ; Mon, 07 Feb 2022 09:18:05 -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=HNqXLXBMJ9ztAmENVyIS8rmIuvKj/5kdUcrzzGJZUmc=; b=KmK9Fcz8I9dVkP8GTEKDmc8kiy4OmvJIqlobX6Qf3X0b6fBAiX2SPcfY4EXLJ8pXbS NoZmWHGhGdrw9/dFvdaGT/3GHdwbQpegCSqsG+aJxBqHlkImF9Rs3Umobv4M5CcL5qF4 vQxNu9Usfv3PmyrSRleTVQd7Y2hgKte+To2s1ZQRt++1QOrg/d+hHfFd4jRkpCcUVCrj G3IyQkQY6ZZC9jURTZlh1K8LcKj9ubRtkb9ZewKAxD03W5VQdVZxL234u7Rr3IFFumqx PZMHMlPifep2l5vASuWtt7DVMx/FE2bcrLQHYZrY581kKP60PEfJ1CUf1cbKWrHQnIbQ SYmw== 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=HNqXLXBMJ9ztAmENVyIS8rmIuvKj/5kdUcrzzGJZUmc=; b=S161S2mFuixAvrYt4IiS1LFPQkC0db2/8QR1pChua05xUiRgi408joCF16mkZyfbn0 sRGX8BfAKUBb5c7lnPaZSAxweAAMpJkDTyiLzu78qTwnUFwaI9Ww+4mYRhe18lp67MYw 4GzJACLiqjP5tdiRRvq3N+no+AOJ2XD5XaI++p6Y7TDzXuSXS5JmH36Sj17Jw2LFy3mO xmvqVfpSkaqMz+uO5A2RnP1N8neWd4s+o7MqknxnLeTiYXSbXeb4KH7TuWE9xrcmkPtc o/ZI/3n8tJghKmcHcXYh0oQpUNyWqlaUMu/meFA5iUiHGY7zJnqwXPuEknYSTSnV+rjh qPOA== X-Gm-Message-State: AOAM532sDYcKN6PNn52aSTjjPMi9RvqN48viWkrvOnOMEiYsiF/+eyqR bg6hk5W7HNVxQboLMDOg9n9DQJcwoxc= X-Google-Smtp-Source: ABdhPJwTq8Snle6/CRwoeP3LibSqyQ7VUTgQOjPxAQzhWwg/vL7sC5FHMzoCCjSfnEYwpf4u/eNYKg== X-Received: by 2002:a17:903:1209:: with SMTP id l9mr705851plh.3.1644254285518; Mon, 07 Feb 2022 09:18:05 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:05 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 01/11] ipv6/addrconf: allocate a per netns hash table Date: Mon, 7 Feb 2022 09:17:46 -0800 Message-Id: <20220207171756.1304544-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Mon Feb 7 17:17:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737704 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 53010C4332F for ; Mon, 7 Feb 2022 17:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237375AbiBGRSc (ORCPT ); Mon, 7 Feb 2022 12:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242434AbiBGRSK (ORCPT ); Mon, 7 Feb 2022 12:18:10 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C31CC0401D5 for ; Mon, 7 Feb 2022 09:18:09 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id t4-20020a17090a510400b001b8c4a6cd5dso2997312pjh.5 for ; Mon, 07 Feb 2022 09:18:09 -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=HBzIYM8OCfk6OS8NlZSUItfJ/dgQzZJu7sN803ms/H8=; b=oWEDxLkNFFpbd/9iNg78Gj4kQM6vwUYpsp/cL1809rgiNS4Wn4A1MBAEyQbKJahRU/ 5S2ec98bQq/Mp3QVUE2fXKa2kDF1dEXxdIV+hr6+LF17oCMk0ptnnmZbz9UE4nvUHXco 5+VGdSJkUUuoG0hNqhSZWUaawD7J9NOR3qbd5iPzhwEOD/Eoe74B5Y2CAK6xDYHhxkjj QZdPJJmqxhDoLVFYn2RsykDaLyUN1nxHc0b8bYVkxCUeMZFuBA0K7ThOrPPpkjSWlEz1 d3LdSNo8TxaEOdZni8orbJ8jsaKXQKPs77iPcqxZOrhycXMC2ZAztuiQquH5bjiuX9ib v0GA== 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=HBzIYM8OCfk6OS8NlZSUItfJ/dgQzZJu7sN803ms/H8=; b=3K3DPtKZTXgdhbL1g+tdA3aZE2U3sQLtgLjAndz5KevHtwZvwt3Gat5FrqMXyaaC6Z CR5Pdc9juDA0KY73mAY4JOdUEQGepv7zK//EXzDBTdCWdHwdgkGTDxgRvzICGQYXQilW 1jTzi+Mv/uvyaVK6oh5KcKLvpWdp1xC0Qht6etJQr4KM67jeXJiH4+aQ5FynAk/ChGVa 9M2+h8n/ZOYvZK9tQfb1GzwPER3ABwky25N4Q/vMXT2N1UTXu3KbGbU9ybLh8lTO4lzi 9wbkZgT4jD890kv+lWLz8ATiWu8juygYw7lzH5GNKVqu7CA120HOilvWxs3N3jGOFI1Y gNeg== X-Gm-Message-State: AOAM532qqvG6n0/EvBuv9+IjojsfUQmiohVd6ctgg6FqV52v2H6X5GkB crUldvttB//lf67PQtbas8IFYte7MiQ= X-Google-Smtp-Source: ABdhPJx/5ltYVLQKaIWUc+zMwcWSdRnUu4vGSCVtiNAeLbrdZUS2NmCzFPYZD3KUYh8DQ/IYXiC8tw== X-Received: by 2002:a17:902:f1cb:: with SMTP id e11mr632262plc.48.1644254288682; Mon, 07 Feb 2022 09:18:08 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:08 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 02/11] ipv6/addrconf: use one delayed work per netns Date: Mon, 7 Feb 2022 09:17:47 -0800 Message-Id: <20220207171756.1304544-3-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Mon Feb 7 17:17:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737723 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 28BFCC41535 for ; Mon, 7 Feb 2022 17:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358803AbiBGR1M (ORCPT ); Mon, 7 Feb 2022 12:27:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379632AbiBGRSM (ORCPT ); Mon, 7 Feb 2022 12:18:12 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F206CC0401D5 for ; Mon, 7 Feb 2022 09:18:11 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id y9so5896829pjf.1 for ; Mon, 07 Feb 2022 09:18: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=2AxX85k1d0hN/MGUTvuw6Ch2nZkv1PG/gK3JZE3m3RM=; b=Drk2QXStmCMqT06ErPkNpHU0yrA3ezmkIA6ApGqaaFFVJgHgEYt2HVW9xx0/3rktIF 4eci/s30EL1FpvnCn7mrTMKnE9OVgE5rGKLHZdMcZXSSuzQMj6ih4qPw3qSdRZejEhnk xARTNSNzHWGEmEYrtPiJdhIxhcDtjSJI+FjcUX5aunB2eggafuVk6L1qaMeUdN+LigVu 0vwxtvcjKP2S1nKg7rGjMKp/zTGnOLNGG32pHB7faMfydkvsKfRlYra9RkBTAdgYvS2o ulHACiEiyjlGOEKW68SodgcAUqHKErRz7tg4+NRIgih94WPQ/IJYKFp7ydvipHIAhfIW p7EQ== 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=2AxX85k1d0hN/MGUTvuw6Ch2nZkv1PG/gK3JZE3m3RM=; b=6W1trZk6gjHnopINNs08+w9EWiN2ow5opGvbc4vUWTDW5Xm514cb4AUPAi1Ask+U2c nkCut/3ujr+W4ZoaRL4Wv2p6k7tYgTwKaslsEjWdjC3NUZRhAGahfU7nsMYnRjQ/oJMq +AsWE4ctRpz2r89P5D8cwPtApKjI8vfKWBj+LzWmhCYEgWh8PUaSbbD6pmFA2CPfzLRi Ff6pJoC90OjBv1n+gATv5FDZfUStvXEsJ89dYWwtZnC7Tnfsi0F6hPjOEjhflDR2OgSv z2b7AdIHKI+6yi1U1F4Zu2p2LzyHfBT0GgKgNgVAZH9Qd0ZDksfsM10e7DyIbrA/fp/c 30HA== X-Gm-Message-State: AOAM530mopkR28+rtjGu3fFJ1uOt5Qh9SbjCpm/ciTgN8mYIM7vQiU1P U341QzmKrooRnLaHqwqwm29xTFTZu1U= X-Google-Smtp-Source: ABdhPJwiRP3q+WewD9peFi+tI+pITcT47s42seDdM5fjExy4f3NxkC13kKj2rm8a1nCTRTkc12U3sg== X-Received: by 2002:a17:902:7606:: with SMTP id k6mr476943pll.56.1644254291390; Mon, 07 Feb 2022 09:18:11 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:11 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 03/11] ipv6/addrconf: switch to per netns inet6_addr_lst hash table Date: Mon, 7 Feb 2022 09:17:48 -0800 Message-Id: <20220207171756.1304544-4-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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. 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 Mon Feb 7 17:17:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737711 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 D8EADC4332F for ; Mon, 7 Feb 2022 17:28:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243187AbiBGR1F (ORCPT ); Mon, 7 Feb 2022 12:27:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384317AbiBGRST (ORCPT ); Mon, 7 Feb 2022 12:18:19 -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 B24A2C0401DA for ; Mon, 7 Feb 2022 09:18:14 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id e28so14109955pfj.5 for ; Mon, 07 Feb 2022 09:18: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=hF7w07jG5pYTKkawKidH4XIxVWWjxIRivkIAyqYYm/c=; b=kdhZmpA8HNkKqEKvX7URHb/fLyWnojd+mDjjk758XQ4Gm1ZTLyXrGh4nQQkEHzEtMj 9zX9IkkmA7X4J9guSdA620/03SQoNzoNLrKUQzo8ciDOZhJZ0ej9tpL4h55eG1WFj9oE NuLaiWLev3p18blcWtYW654freOqrGmkI90dFU7d12ZpcDXxhsByCnSeKV+8h1QLJvAw 8YRTmlRNznIzFoPKnjQBMgCDKYXaHWl9Ez9nw9KaMdEQfR+Cqgx+Ox6zV1XwLrRL+afL uGLG1yyn2kLvtgAYfSiwrgZnuSkrgENfzNE1jRjDNWZzPMDkEhACyIOrBCREQ/OXnvyw KBIA== 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=hF7w07jG5pYTKkawKidH4XIxVWWjxIRivkIAyqYYm/c=; b=XCpwgxlHdhea3EzM7vwnx6k3BV+AjTQHfqUZ2UMGH5JkaZmgoCaXamp4JLZEqez5Cd Hw6HMiVlaEbSrROowdnm9nF+Jq+TcwNdzunB1Ugp+KH2X1r6xRLEwynDNs7WJzKVMfSQ 99YW2sXhA8FJXJ3mHuWNUC9px0SjBKWsZpuV8D+3tU+8DzlAwFAAaNrdXoZpjMChG5an /EB11rnuPGZPiK9otRnM0oGdAzjX2v4Qv1OMbjpNUdndB//1o4RIyIuHWmDhvAkdpKE9 ekRNGeZBTHOgv9Z9BWw5JYYeR3yqsxXYhFpjmlbHWkv3TH4cFnLzOO+HFWMP6HTDuKWB qtwQ== X-Gm-Message-State: AOAM5335pFDq1Z021UYQqqTY7fp+liTpxXVJE3GLujX5YpzFu8Gc7iOj ITsDFjwQO0ZD/OQSrfABkTE= X-Google-Smtp-Source: ABdhPJxZ4X37xTCSkj446Z7DgRp58q73BVK3DuxDOCvDJfz4dWYL4QtrBihw050p3wGtKqMWsiiygw== X-Received: by 2002:a63:1d4a:: with SMTP id d10mr346960pgm.92.1644254294319; Mon, 07 Feb 2022 09:18:14 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:14 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 04/11] nexthop: change nexthop_net_exit() to nexthop_net_exit_batch() Date: Mon, 7 Feb 2022 09:17:49 -0800 Message-Id: <20220207171756.1304544-5-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Cc: David Ahern 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 Mon Feb 7 17:17:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737731 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 A63BEC4707F for ; Mon, 7 Feb 2022 17:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376411AbiBGR1R (ORCPT ); Mon, 7 Feb 2022 12:27:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384300AbiBGRSS (ORCPT ); Mon, 7 Feb 2022 12:18:18 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D9AEC0401DB for ; Mon, 7 Feb 2022 09:18:17 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id t9so9431669plg.13 for ; Mon, 07 Feb 2022 09:18: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=Nhf1JSHmzyYOiRZJUl9QvXuJlSfQJ/xOOZHY4kfhBUA=; b=N1ramoYW8p47+1cqUgGPOJnl0PEB1okXHm0kgoyVQECeH5IMVs3VX8diuU5kL509Ro qG83bq8gKM7Q+nvioBO1jMkJO4QnSw4QGcFbRk6SaXRQurQOTr/NWgKHnmfB/hRVeO3l OAHDgp0ehXXR2lQ9HcC7DQ6L9VbaQ5JF03Mgc2Whhbv4DN+yCUfrxXUp/+kWG92iUzeK /zn/p2o0fMEghpmv+eHcLwaGeXyCLF4lxDPenKDiZ+bKZNXGQBCzfB5qHWgBQMM4LZKk 8Qz//wjV4UxU2LTGiYDenJxDm96fxTpPb+rvQ7QJPs/NkUepmL9E9ShASTsbD75vR3Tu 7NtQ== 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=Nhf1JSHmzyYOiRZJUl9QvXuJlSfQJ/xOOZHY4kfhBUA=; b=TGDr1KkCsDlC+TeklbIbVmLqMhETMDyNYinAXb3DV5d7oy3DSjaaNw7aqzs8Y+d9Go ioBY44As6aVF6FhrotaU+RemyluorBvUmv7PKS7PYTxo2R0xoBt+RlPcrg2dN6LWuaxX 6xK8BSEPlZ4yKB09Nrn8HIvZ2gaGCBvLgC8iZr2cn4TEuExoro83D5PWgsT4ReXnmAHu MEdhlQyphjqNipmbRrQqn1/8yJIIzkZTu/gBTC/PA6Df2ot1SoWxy7YYK6wvqG/B+xtG tOniRIkwbp6fW0VsARjUWIVMHelEgitQdIJtR0CtRxHL+VG6Mif/8pE5DFeLLdHqONCC YhEg== X-Gm-Message-State: AOAM531uCTt72KjqQI39ZqHP58ueKD/zyaN6q+bzVzvYcaLAzmULCulr ypYoxL4XYnNjQprZ5St3F7o= X-Google-Smtp-Source: ABdhPJwwPUZaDCzlULztzopOaD4/FQUWMYhmIzA+X5oIM7rQJ2pxFIuMC8giAMIe34SlCzVaCO8Y+w== X-Received: by 2002:a17:90b:3907:: with SMTP id ob7mr5099546pjb.29.1644254296881; Mon, 07 Feb 2022 09:18:16 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:16 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 05/11] ipv4: add fib_net_exit_batch() Date: Mon, 7 Feb 2022 09:17:50 -0800 Message-Id: <20220207171756.1304544-6-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Cc: David Ahern 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 Mon Feb 7 17:17:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737713 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 7FAD7C433EF for ; Mon, 7 Feb 2022 17:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358029AbiBGR1H (ORCPT ); Mon, 7 Feb 2022 12:27:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384318AbiBGRSU (ORCPT ); Mon, 7 Feb 2022 12:18:20 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4589BC0401D5 for ; Mon, 7 Feb 2022 09:18:20 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id v4so7601281pjh.2 for ; Mon, 07 Feb 2022 09:18:20 -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=4MfbMaZu275dw5aSyof6NzcxX8JCYParEayV3uN2EHs=; b=U87s9MdCw5CPdWle4eD6x9sKigZuC9bnXiVerULZ8FLeEfMQ2RmlxXehKL5FxWN0ZI 5fYxSjvLHNYN9CTPBtkj+owf1YsEf1y/nsdHEvqcFt8HvEbXdm94g6FGukQJ+mXCreKN rLQE019SIQxe96GTNeF9KmdzMlmSJ1+i+qKIFMFPPZ7r6/1HlPgx3EtZ3F8CoryBl5t1 KW9l563V+SIDfqOpw97UZpsQeJeK2bJx8VOgDGKmXVgntCxmbxD0Ah5IrslN8Lqrw00N xjoZkCaBEs8LquxYKopml8XklHwqrJ+bGdI/mAsSFfhIAH1N/e6Kh/hr57vPaGhAXoD9 T40g== 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=4MfbMaZu275dw5aSyof6NzcxX8JCYParEayV3uN2EHs=; b=uaLURM8zcQGn/+q7UhJuR0KD+m2r6LINwyCYZ97/hfFdyLFf53YmGofx1NMB8A/ThZ YagBlOTasK+qOyVWdIwnkBz/1r2GSdtyvyxYl3VX+k6A7XOXOE5Y3bAITePwDmovGL35 9MDKAuVVdZsOMzDxB8DozzIo1O5PJw9v9cx/JpFyk0he/3d6cJJZyECQtJ7cSIWM4ewb lllQAbz+WXXsHz1N9SkRCrDRKSHVth891RVmVd6yaXc7lFqjVwkg7hHhyxdcd3dfQ6rT b4UoMXCcaqLCNdtueKzOz3U1iFHvF3Al5Kp8OK9M55C8YFL3z9aS7p4tl6yej7gSILpy a5uw== X-Gm-Message-State: AOAM531hkKL79FbB88DYB32sAhTxE698uJL1B2Sutju8nrti3DDPdk0e MQAjFGSNtidCUH3pc0/jxSu+Hnilx4s= X-Google-Smtp-Source: ABdhPJwbPRp+xlzkD5iZwqBT2OIgqvQNYJupTXBRhQaNhQMNaBijnOkTpzYWPiQwl1u0ORw2fRnTZQ== X-Received: by 2002:a17:902:da88:: with SMTP id j8mr574946plx.105.1644254299802; Mon, 07 Feb 2022 09:18:19 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:19 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 06/11] ipv6: change fib6_rules_net_exit() to batch mode Date: Mon, 7 Feb 2022 09:17:51 -0800 Message-Id: <20220207171756.1304544-7-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Cc: David Ahern 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 Mon Feb 7 17:17:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737722 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 19ABDC4167B for ; Mon, 7 Feb 2022 17:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358767AbiBGR1L (ORCPT ); Mon, 7 Feb 2022 12:27:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384330AbiBGRSX (ORCPT ); Mon, 7 Feb 2022 12:18:23 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E937C0401D5 for ; Mon, 7 Feb 2022 09:18:23 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id v5-20020a17090a4ec500b001b8b702df57so3837887pjl.2 for ; Mon, 07 Feb 2022 09:18:23 -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=dQpQM4iUZjuMJjkLRdye2zNOEEpVCXxMY8XwFdiYAng=; b=EVrF9WxR5ej8XTSpBO1LkmL16RPo24jgQFdur1aNjW1NcIdc34BY5VqEXK8L7ly8t0 LV6XCCc7lDFuyN5UXwV+zvE5PelY4zPCpvi8in7T94EhCsJMbGxm/HuBCZliLmdRBoFF ir73vSxejhZdWQJ+eCkR9fXhUyavpJAXLP0nRgPJPScCyGuvxd01PSVxfBZKBHpsdyn5 f2ajc7gZh8JkNbCUbjjg5OYxZGMDZWZ24ECJseGWcHO50FBCiDQS7j44M5NaAYrEdGx1 adlVil8YmTfCB7SmygBUA8fPC6UXkf3SnphT6Z7bAcktHwIKGW0OMzaiJJQPg2Y8rwbT sobQ== 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=dQpQM4iUZjuMJjkLRdye2zNOEEpVCXxMY8XwFdiYAng=; b=nKeLTwVvg6qsNa6++uHUFWdNXHVnKH2kiLbhdqr6QXEfJHu7x9fQsBMMb/mIB4hKdm 6r7U5mapEo6xzNFxrkRg42OSLNC/YaHMPaUKcU+BJga3RUMIgLa2zuk+joZVMUqLueWK G0I+cqYJEwJgVr4Gja0RqrGMGspI2fKd3iupGaISuqqS6XjJzPNE0Svfks13jyBlZE21 XOrVooTIPtanoVVqICwh45t2n2o4ldoyCU77r8h9hqL5+m8iGR6VruvyqufhzLrRwvn6 pW01+6r3X76f8MU5zbVbJL8NOAk3u8UqII2axeWlLCa3eklR65/cytIBckWBslETX7G7 qQXw== X-Gm-Message-State: AOAM530735vtWTiBM+USTvfMjg39/bbkOlWhozkWI/TDuabQ8pcyduvr 0OO3B72XuNstXtFyhtE2L1iSMMbFJoM= X-Google-Smtp-Source: ABdhPJw4aC2leAwzHmLrUU+FN7gGCDXRlix8vJ7BJ7a6Kxu+m4XetMHpJuf0jOoj582brAhffM6JeQ== X-Received: by 2002:a17:903:2350:: with SMTP id c16mr630147plh.4.1644254302610; Mon, 07 Feb 2022 09:18:22 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:22 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 07/11] ip6mr: introduce ip6mr_net_exit_batch() Date: Mon, 7 Feb 2022 09:17:52 -0800 Message-Id: <20220207171756.1304544-8-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Mon Feb 7 17:17:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737738 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 768DDC433EF for ; Mon, 7 Feb 2022 17:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377525AbiBGR12 (ORCPT ); Mon, 7 Feb 2022 12:27:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384348AbiBGRS0 (ORCPT ); Mon, 7 Feb 2022 12:18:26 -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 D0B04C0401D8 for ; Mon, 7 Feb 2022 09:18:25 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id a8so14100100pfa.6 for ; Mon, 07 Feb 2022 09:18:25 -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=AevgfzwpFF0x/3DbgQzBrGCua8A9+rsxA+kfGfkdq6k=; b=g4KXOKOKBlrBJ37eUlBXDb51cLBcQqzWQEDt6gUJF3/I2RmCqbj/JGHcDQ/6o+pbA+ PzHCJ7aU26+F6rbpb1Q30q4Nj59ep1GmaB4RuRBPXVxb1B89tbnZErLlPF7IB/2iMmRA YU7K1UdMruHPNLLYl4sdS3gwKkU9U9uRz8x6kDWtCnFkcNGhnl03Zw5fZVtwoMI66qGM GgGroF9mx6uHWq8P4ZHYQFoT1XfTF2aVs8UvounOJdDQafPWvvn4iaKmRMwS5irWZ1Fb frfjEts4PVhXMAP9UPjc9BPq7dKyOed0JEG42zLG3e+0/AStJNrmaEzS+OBW5FNzX9px +62A== 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=AevgfzwpFF0x/3DbgQzBrGCua8A9+rsxA+kfGfkdq6k=; b=dtVpC1vY9/MICMtp/gsor4yl43OWjqm/vB3mX3SXBdFwCNgirZ/9BTeouwqS/Yqlfe ZIAOsnmwl85e5YJsT5g1HTmJXiMGOvxEuMF0htk9KnZWpXVKHtmquzQPfHuxNNqzyCDE IDyIDDN0AqjoMWVsUDYB2Ij8FXngZHP4Lco5RG7AzXzorRYr/ant05Mxth2T4etn0yiB SVrHiHHF9BHuw5tKaIJ+9gI/Y9oi6cY0Hvp8KD3i2I60lR+sV+HOsJDbpJQHEtvEdtGZ pl2XrFch6Lywa9gmbf5QV1ld6Kbpe354LFgWBGAGp4e8mU+gEKvEfR4Kgg9Yg8a54UDt JokQ== X-Gm-Message-State: AOAM5337nkDiidvucC2RCw0om4pz4G5kMtCjmOEc50vULsdL+WIUFZUu /VofHgKZXPUmYC15evhIk9g= X-Google-Smtp-Source: ABdhPJy6ojAe9I5rirt9sYRNUYb8gKYP6SGXXDfaZktMdPDlhbTDoOPFGsiPgrCZafTBlivZIVwlqw== X-Received: by 2002:a63:c156:: with SMTP id p22mr311849pgi.215.1644254305339; Mon, 07 Feb 2022 09:18:25 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:25 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 08/11] ipmr: introduce ipmr_net_exit_batch() Date: Mon, 7 Feb 2022 09:17:53 -0800 Message-Id: <20220207171756.1304544-9-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Cc: David Ahern 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..37bc9ad0df9933290ce91ae02321dee339294163 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_RNTL(); 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 Mon Feb 7 17:17:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737742 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 A65F0C47085 for ; Mon, 7 Feb 2022 17:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377697AbiBGR12 (ORCPT ); Mon, 7 Feb 2022 12:27:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384349AbiBGRS3 (ORCPT ); Mon, 7 Feb 2022 12:18:29 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A67C0401D5 for ; Mon, 7 Feb 2022 09:18:28 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id t4-20020a17090a510400b001b8c4a6cd5dso2998374pjh.5 for ; Mon, 07 Feb 2022 09:18: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=zzYXbAI9QAjG7qz27KZbmKUJU0Aol5TgzItO93+yuUo=; b=mjD1du4AN4UoL4Oi6U9VhAs1IMq8gIMjLDgJ7rXHTzjCODxYmUqYHhz/p+ME9lXuVy RJVZbB6G1rGca2pvDR3P2GDRl9EwqeW2Np7KdWu12NaT90gahjFbrTQh3Y9it+XWAWlD SHB8RSsywC1XkqzQL+0cGr//qoonbMifsKnbvjeX1eQFqClFFCZ2aSbimY52aUY9yURe T32PbXdjeD984LxZ1JxfOge0E6qkV4pUxUqoW/rMkQnewjvHIZvbRMEBGZJBSuxuvu8Y zQzOZd+8jiyGgfmds7pOpCwc7sp4t3OlZLI8E22vYxAUem0UdCzE/9NzJJIUYxgbeJ/1 7/eg== 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=zzYXbAI9QAjG7qz27KZbmKUJU0Aol5TgzItO93+yuUo=; b=zqGKFyBtE9Rhz5q4o0mv7aj4WH42w6KSNtCS88WxXL4ENY495BTfi/TsPKQM3QYgkW t1YP0lKSTL5sZuuNUhIbyjyrZfx+AzToAGTJ6mW02XzushwL/jWq5m/doCvuRrKahAOl bNziCkKmqsndWLk/ab0rxXZ7Mt2xaEJN+aUtK3MEnQ2bU8rDxYU6hdXZHdSrkxj1uYm/ Lnl6xvtx0kpJtPt4PML43M8fiDy902THwD6tRmMRuviudWx7yJHPmjNnwCX0JhZjfZnB 3e5Y3yRmVFbwHsqcw9ZK5/kHxwhA73P+Fj3D23pur1an6kkmyq/YcflQycaiR1fl3BNm mdgg== X-Gm-Message-State: AOAM531m2fj7DG6KI5GydvzoiUgRUKy/872mScDDHBzZEmo1o6NcHKYB y6SRtarx/9AnGM/sMaXF3D0= X-Google-Smtp-Source: ABdhPJxFTpEb1fldfwS6NeV4yIaLtZqkcGsJOLyAUBiw71WQULXdR2a1kc4/wLfzae8/0+R23mvDGg== X-Received: by 2002:a17:902:d487:: with SMTP id c7mr735888plg.0.1644254308272; Mon, 07 Feb 2022 09:18:28 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:27 -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 net-next 09/11] can: gw: switch cangw_pernet_exit() to batch mode Date: Mon, 7 Feb 2022 09:17:54 -0800 Message-Id: <20220207171756.1304544-10-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Cc: Oliver Hartkopp Cc: Marc Kleine-Budde Acked-by: Oliver Hartkopp --- 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 Mon Feb 7 17:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737736 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 46E77C47084 for ; Mon, 7 Feb 2022 17:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377401AbiBGR1Y (ORCPT ); Mon, 7 Feb 2022 12:27:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238630AbiBGRSd (ORCPT ); Mon, 7 Feb 2022 12:18:33 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BD51C0401D9 for ; Mon, 7 Feb 2022 09:18:33 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id y5so13171200pfe.4 for ; Mon, 07 Feb 2022 09:18:33 -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=gkLqfuWhQQidwxSdWh4J62YGSEzZJeqIMM57SzeZpJp57/v6n9neIcUHdE98kdaJKq t2zwHfG459QWSdT3h49R172jdHv0YzHTcOL64w9N49nLGioas7oeDARVBGQ3LOThKD8n JBgT4Q/g9lCjSHCZXTwg5syAP+YsRksPPiF6MpmAhoKjjU958LzM/g6zPkLA4elK0JMU JClcGH7LpE0hDhQn6e/FnmwLlAWE2/xHm/kcvxXHAfmwR+Hwiu2FjXX90jMRyj0TXWj8 dI+yKeY9QiP09bJi/s99zHRG3A/d+UcmTPxmS8C4s8k+mtQso05uMaYXNMuQaeUgD70L N3pg== 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=kWkkX47/eX8//Q53eJGun/otH8Utvvi88n00d6YCjcfmxV/Ogi2+CQ+sP9LYaMCg3z fg4FLcJkV/IrkmKri33qxjVMQ6IvTlFzJheFVeOicCIQsgZMJ10vaYzvuwVySDAGW07s unOHSnlbJ/kqnTfh4rYwas/kr8+2DqOM1I5qaRYMwrlrsbH/xQB1vvu0BU/opJHYyJ/f 2r6jte8JFFTyaIimoW9Or/LA6k8eyvW6FOZH3MYxcpa5JmiGsXVgvWlwPDOFCFOT20bg gG6B4G+FYKWJyG6ky+AE/d2piiXdAH6a1oDc6zbK/w3LmpDp0GGBqlHbBUAQzzVxK4po YZqg== X-Gm-Message-State: AOAM532pDDjQCp/C2oKAXwSSFRbigfWq++Owu96bxt08FJLkvu54WAY+ yP+EVK/NCQ11NOhCrRWOVFA= X-Google-Smtp-Source: ABdhPJyErN2zyhcXnzpgMf5RblAPyk1bsfuDVfDXZChp12EqWl4WlqrkwwuuAG0Pb/u3JcZ6axBjhw== X-Received: by 2002:a63:1043:: with SMTP id 3mr343801pgq.16.1644254312584; Mon, 07 Feb 2022 09:18:32 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:32 -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 net-next 10/11] bonding: switch bond_net_exit() to batch mode Date: Mon, 7 Feb 2022 09:17:55 -0800 Message-Id: <20220207171756.1304544-11-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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 Mon Feb 7 17:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12737725 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 776E1C3526E for ; Mon, 7 Feb 2022 17:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359713AbiBGR1P (ORCPT ); Mon, 7 Feb 2022 12:27:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239156AbiBGRSj (ORCPT ); Mon, 7 Feb 2022 12:18:39 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0F23C0401D9 for ; Mon, 7 Feb 2022 09:18:35 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id i186so14154071pfe.0 for ; Mon, 07 Feb 2022 09:18:35 -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=ZWsV/Q/92/ziNxuz2yNYUYJtM7LiQqqzaRRVAP5luY0=; b=MarH6reczKbc/XLSLlzrSd5OzTyWDR8nYgQ74vrSTzPE+hRL3B5i3ISrsJNqNfBVZb FZEv5GWtuxy3RTeXKd102LKkXLv0eTV6v/KmzdExhtH5j2uIxLpUWF/QbTIDJlcmlUJ2 rsasuxNSbAc8prD/1OEsFvHGzu/Qt7w5IFkYF9rrPtonqs07FgsFiFOj/ThDmCsr66yD Rn9ux4/ElKhQgAzO0S5vsUgYGf284RVJpsSRbjC1ejdSlPtvCJKCtDPeSGO4V/HXsM2Q JS91gKdcwnqT6V/F/Vmhx6N25SpC+E5YBOArncbndzq4579UmFYC81+ZwuezT1xIbHvP ONmg== 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=ZWsV/Q/92/ziNxuz2yNYUYJtM7LiQqqzaRRVAP5luY0=; b=PIGRtnB1ZZ07qXILIlvZpqh2vo99HTBJY9X+oE1fsSTLKDvwr3i9a7JG65eDIk1MRb g6sGLwBObMCP1V2JkmmDVplW0RDBoMNezTEzh4T2axdq9gKTKT4lpaSX/RiCkxTpN/8c +WvvSAOHE/J+5TMf3IZEtfuTOrE+uaEuo82d56QCtvH9N8x9vK6XL/CKO2NfyRjB2x7k yAAmHRzWYRepnbS/L0K5mq8KmsK8oZYwOGsEGPBgEAi5MlO0MAM+wq/RCaV5HPZUnmse pGHDRmL+cq3FN4uIcDBaf+rZAPjBNPbVEDNS6EzId2bnADN8su6i++G4lTlmpf8Yj4FN lB5A== X-Gm-Message-State: AOAM533JielXdK2mlxwwbrSO8FVSmJ4s6OMTmSqY8YeZLhW1ih/Xaiu2 SuTxyrTFxDz1sOk3AIkZyuQ= X-Google-Smtp-Source: ABdhPJy5H4QWWzqwskoPRt17RU7L8CGFN9skqT+K3ztM0ALx2hv7Tw1OATHuUjOhy278DZ1Clt9SQQ== X-Received: by 2002:a63:e84f:: with SMTP id a15mr311846pgk.191.1644254315545; Mon, 07 Feb 2022 09:18:35 -0800 (PST) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:6dea:218:38e6:9e0]) by smtp.gmail.com with ESMTPSA id lr8sm24415156pjb.11.2022.02.07.09.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 09:18:35 -0800 (PST) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , David Ahern , Eric Dumazet , Eric Dumazet Subject: [PATCH net-next 11/11] net: remove default_device_exit() Date: Mon, 7 Feb 2022 09:17:56 -0800 Message-Id: <20220207171756.1304544-12-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220207171756.1304544-1-eric.dumazet@gmail.com> References: <20220207171756.1304544-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, };