From patchwork Tue Oct 1 02:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13817354 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 651263B78D for ; Tue, 1 Oct 2024 02:49:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727750970; cv=none; b=AUuDK309K6x5IFX3h360QUQ1pqbmKl3s08gQkVhRzbsQDBePb2n5Tf4MRP1MnT4A7JJuywIgAKubP3WQmS3SnxEezgE7spg5X5f/4cYaxXm2NXvAYILCqITAwwMTV28qygBAbJ64GJ/VuNe4vY7fzXdIN6m0U7fIKcuPvZTSle0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727750970; c=relaxed/simple; bh=aPypaMet8gQuRiKLY2AZJTtnVi61JtyVb/CjJKspRrc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iN1kfDk45YF5cxYjKaWtMS5QVnfZ2VzAtgf0KoU3f29aVG0wtZKoE5T/V5ER6avqp5HcNV+eqzYMnMJGDfg5ItpghT4drKIfxTHSb9v8kUC34T0gTJk2RFNVTlT29X4NHAtrh7lWWVkTWOTu+d2vrf8auck9TRUhiF3jB6XKTos= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=GiO9BEhg; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="GiO9BEhg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727750969; x=1759286969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XiUyuTg4T/DHJbYNYSmoZg2vxYc9CVrMrJTAFZYrcHY=; b=GiO9BEhgGNDLoU1cmWdXtFKeuNSj9efhBJah5CeqLtCGbH1C3TwAB2Qg qYYH34aDuAQKsh8Ijs9a1hL5Yyco2V/YgJZ69VxDak9x9YB2oKCQ2fdJp rTBb3yO8woJWgTEZFkVj1HtBQ5rBCcjyOJX7MPOdD4HzYjx9YBM5o/KON s=; X-IronPort-AV: E=Sophos;i="6.11,167,1725321600"; d="scan'208";a="133233538" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 02:49:28 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.21.151:11886] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.24.191:2525] with esmtp (Farcaster) id f970e763-9edc-439f-a920-bab77589027f; Tue, 1 Oct 2024 02:49:28 +0000 (UTC) X-Farcaster-Flow-ID: f970e763-9edc-439f-a920-bab77589027f Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 1 Oct 2024 02:49:28 +0000 Received: from 88665a182662.ant.amazon.com (10.1.212.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Tue, 1 Oct 2024 02:49:23 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 1/5] ipv4: Link IPv4 address to per-net hash table. Date: Tue, 1 Oct 2024 05:48:33 +0300 Message-ID: <20241001024837.96425-2-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241001024837.96425-1-kuniyu@amazon.com> References: <20241001024837.96425-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D033UWA001.ant.amazon.com (10.13.139.103) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org As a prep for per-net RTNL conversion, we want to namespacify the IPv4 address hash table and the GC work. Let's allocate the per-net IPv4 address hash table to net->ipv4.inet_addr_lst and link IPv4 addresses into it. The actual users will be converted later. Note that the IPv6 address hash table is already namespacified. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/linux/inetdevice.h | 1 + include/net/netns/ipv4.h | 1 + net/ipv4/devinet.c | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index cb5280e6cc21..d0c2bf67a9b0 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -142,6 +142,7 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev) struct in_ifaddr { struct hlist_node hash; + struct hlist_node addr_lst; struct in_ifaddr __rcu *ifa_next; struct in_device *ifa_dev; struct rcu_head rcu_head; diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 276f622f3516..29eba2eaaa26 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -270,5 +270,6 @@ struct netns_ipv4 { atomic_t rt_genid; siphash_key_t ip_id_key; + struct hlist_head *inet_addr_lst; }; #endif diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index ab76744383cf..059807a627a6 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -134,11 +134,13 @@ static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) ASSERT_RTNL(); hlist_add_head_rcu(&ifa->hash, &inet_addr_lst[hash]); + hlist_add_head_rcu(&ifa->addr_lst, &net->ipv4.inet_addr_lst[hash]); } static void inet_hash_remove(struct in_ifaddr *ifa) { ASSERT_RTNL(); + hlist_del_init_rcu(&ifa->addr_lst); hlist_del_init_rcu(&ifa->hash); } @@ -228,6 +230,7 @@ static struct in_ifaddr *inet_alloc_ifa(struct in_device *in_dev) ifa->ifa_dev = in_dev; INIT_HLIST_NODE(&ifa->hash); + INIT_HLIST_NODE(&ifa->addr_lst); return ifa; } @@ -2663,14 +2666,21 @@ static struct ctl_table ctl_forward_entry[] = { static __net_init int devinet_init_net(struct net *net) { - int err; - struct ipv4_devconf *all, *dflt; #ifdef CONFIG_SYSCTL - struct ctl_table *tbl; struct ctl_table_header *forw_hdr; + struct ctl_table *tbl; #endif + struct ipv4_devconf *all, *dflt; + int err; + int i; err = -ENOMEM; + net->ipv4.inet_addr_lst = kmalloc_array(IN4_ADDR_HSIZE, + sizeof(struct hlist_head), + GFP_KERNEL); + if (!net->ipv4.inet_addr_lst) + goto err_alloc_hash; + all = kmemdup(&ipv4_devconf, sizeof(ipv4_devconf), GFP_KERNEL); if (!all) goto err_alloc_all; @@ -2731,6 +2741,9 @@ static __net_init int devinet_init_net(struct net *net) net->ipv4.forw_hdr = forw_hdr; #endif + for (i = 0; i < IN4_ADDR_HSIZE; i++) + INIT_HLIST_HEAD(&net->ipv4.inet_addr_lst[i]); + net->ipv4.devconf_all = all; net->ipv4.devconf_dflt = dflt; return 0; @@ -2748,6 +2761,8 @@ static __net_init int devinet_init_net(struct net *net) err_alloc_dflt: kfree(all); err_alloc_all: + kfree(net->ipv4.inet_addr_lst); +err_alloc_hash: return err; } @@ -2766,6 +2781,7 @@ static __net_exit void devinet_exit_net(struct net *net) #endif kfree(net->ipv4.devconf_dflt); kfree(net->ipv4.devconf_all); + kfree(net->ipv4.inet_addr_lst); } static __net_initdata struct pernet_operations devinet_ops = { From patchwork Tue Oct 1 02:48:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13817359 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB04F3C092 for ; Tue, 1 Oct 2024 02:50:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751006; cv=none; b=l1muYbv/pd0/ECqcSleOI84n4735d2fFHGf8KsGlmuGAoDIK/1PZLZBRdgM7F3NLuE4SiEZX84jn4f49ytMIFpNC3vXAuWrSW4T6A56oywjnR41iqHWZKxISISm6fNcVPZk329rbuz0JtulHPTrx5Ki5SIbJfrpEU00fD9dOWMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751006; c=relaxed/simple; bh=bUz4CR5vvkJnC1BbBuBa33kyy7qe/yD+oNml5SxPpmY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FYfODAKJVtFKc/Db351lSa4SJsHLfGlINbTvQYU3oT1dHIRYM8ea6ah3m9UJ968ro+ZsyYfTpmwe1l248u0BYEWTU43cbFj5smIlPWp6dJ4bl12p1ahWzcpPNZKoUtbD69tyfc7y6wKmh1p2+X8ghqeAb8MbbJONwfLKpzAKc8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=fNdBMbUk; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="fNdBMbUk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727751005; x=1759287005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W5K29+DQT2nj4mu8rPDY6ZfsmPitHtszE7eWmWzAPrc=; b=fNdBMbUkylQD6WPs0ZCF4dmNjIOczbKbrWqq3wy1nXAj95Qg73ZQ/Thf wPyDk+j/kAXiZxqBI9GMmmlec2ewK4jNNgteXqpyAtlDrlrpCVLo3GmUY nqefQViS6Ds1ihhbiKPaDLqJq9TpFsRstH+YHz1S6Y2VggZmHTB2NEk1N 4=; X-IronPort-AV: E=Sophos;i="6.11,167,1725321600"; d="scan'208";a="235755416" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 02:50:02 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:61736] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.22.18:2525] with esmtp (Farcaster) id b590815b-9eb6-438a-94b2-9fc51b3a9122; Tue, 1 Oct 2024 02:50:00 +0000 (UTC) X-Farcaster-Flow-ID: b590815b-9eb6-438a-94b2-9fc51b3a9122 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 1 Oct 2024 02:50:00 +0000 Received: from 88665a182662.ant.amazon.com (10.1.212.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Tue, 1 Oct 2024 02:49:54 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 2/5] ipv4: Use per-net hash table in inet_lookup_ifaddr_rcu(). Date: Tue, 1 Oct 2024 05:48:34 +0300 Message-ID: <20241001024837.96425-3-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241001024837.96425-1-kuniyu@amazon.com> References: <20241001024837.96425-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D038UWC004.ant.amazon.com (10.13.139.229) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Now, all IPv4 addresses are put in the per-net hash table. Let's use it in inet_lookup_ifaddr_rcu(). Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- net/ipv4/devinet.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 059807a627a6..cf47b5ac061f 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -188,9 +188,8 @@ struct in_ifaddr *inet_lookup_ifaddr_rcu(struct net *net, __be32 addr) u32 hash = inet_addr_hash(net, addr); struct in_ifaddr *ifa; - hlist_for_each_entry_rcu(ifa, &inet_addr_lst[hash], hash) - if (ifa->ifa_local == addr && - net_eq(dev_net(ifa->ifa_dev->dev), net)) + hlist_for_each_entry_rcu(ifa, &net->ipv4.inet_addr_lst[hash], addr_lst) + if (ifa->ifa_local == addr) return ifa; return NULL; From patchwork Tue Oct 1 02:48:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13817360 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43C214F883 for ; Tue, 1 Oct 2024 02:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.95.48.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751036; cv=none; b=ov1wXaD0vCX6j89L5l+CeVrlf3pGyNRgG/Pv0QDAUoQLnWMzMpwznvuZ3Lks8ObTRbVSfwM8OdaL2Z4zJQIg+WeZ1cc/jDgFrF7pUM6Tr4CvedGfkiY4SLF3uAfb87V8YI3CxUXbOYqJltDMExvPTUp6j3mleEeeULKiqVqPsRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751036; c=relaxed/simple; bh=q+bdNpAxd6hgCql1hkb/jPYaQH3RXzTUvHYI6F4BTmo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ae7QWhY4pWkN8RVigipX63VLsTC7Yjw7zG8gqp0zXSpat/M4cYt8dfrDU/LQcMipXOUvP1szYqfCNFDW1sh6+0NoHW7fIlJ/7y8q8EmANKDf5fPw94ufnXBJWkVXsL0WKEqLDQWdwu1aKmPVAv6DotPmEKRjYaeq9XDHyVtiHog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=dxoeAluI; arc=none smtp.client-ip=52.95.48.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="dxoeAluI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727751034; x=1759287034; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ehBbqGnYqTFVCQZutQ3QPyYNUDMNo3ikdRIJD8yR/wI=; b=dxoeAluISytnqH5TamnlS1XU7LMF0FEMYM1EMIWXCjAWbwhULEXD6ZDl cK57IcMmhyWBzoOwxeGBBDIMQ/9cNa/OL2KJnY56l9LNjwgYAC69yHXEI ZXSoLV4XZGxMeTGWOkSpOl8rBFSu7nep/PHqFEW5km6lvHrgXR1+i8m4P Y=; X-IronPort-AV: E=Sophos;i="6.11,167,1725321600"; d="scan'208";a="427833935" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 02:50:30 +0000 Received: from EX19MTAUWB001.ant.amazon.com [10.0.21.151:2172] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.57.100:2525] with esmtp (Farcaster) id bef925d5-940a-4762-9222-096d60e5b767; Tue, 1 Oct 2024 02:50:29 +0000 (UTC) X-Farcaster-Flow-ID: bef925d5-940a-4762-9222-096d60e5b767 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 1 Oct 2024 02:50:29 +0000 Received: from 88665a182662.ant.amazon.com (10.1.212.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Tue, 1 Oct 2024 02:50:24 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 3/5] ipv4: Namespacify IPv4 address GC. Date: Tue, 1 Oct 2024 05:48:35 +0300 Message-ID: <20241001024837.96425-4-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241001024837.96425-1-kuniyu@amazon.com> References: <20241001024837.96425-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D038UWC004.ant.amazon.com (10.13.139.229) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org Each IPv4 address could have a lifetime, which is useful for DHCP, and GC is periodically executed as check_lifetime_work. check_lifetime() does the actual GC under RTNL. 1. Acquire RTNL 2. Iterate inet_addr_lst 3. Remove IPv4 address if expired 4. Release RTNL Namespacifying the GC is required for per-net RTNL, but using the per-net hash table will shorten the time on the hash bucket iteration under RTNL. Let's add per-net GC work and use the per-net hash table. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/net/netns/ipv4.h | 1 + net/ipv4/devinet.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 29eba2eaaa26..66a4cffc44ee 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -271,5 +271,6 @@ struct netns_ipv4 { atomic_t rt_genid; siphash_key_t ip_id_key; struct hlist_head *inet_addr_lst; + struct delayed_work addr_chk_work; }; #endif diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index cf47b5ac061f..ac245944e89e 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -486,15 +486,12 @@ static void inet_del_ifa(struct in_device *in_dev, __inet_del_ifa(in_dev, ifap, destroy, NULL, 0); } -static void check_lifetime(struct work_struct *work); - -static DECLARE_DELAYED_WORK(check_lifetime_work, check_lifetime); - static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, u32 portid, struct netlink_ext_ack *extack) { struct in_ifaddr __rcu **last_primary, **ifap; struct in_device *in_dev = ifa->ifa_dev; + struct net *net = dev_net(in_dev->dev); struct in_validator_info ivi; struct in_ifaddr *ifa1; int ret; @@ -563,8 +560,8 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, inet_hash_insert(dev_net(in_dev->dev), ifa); - cancel_delayed_work(&check_lifetime_work); - queue_delayed_work(system_power_efficient_wq, &check_lifetime_work, 0); + cancel_delayed_work(&net->ipv4.addr_chk_work); + queue_delayed_work(system_power_efficient_wq, &net->ipv4.addr_chk_work, 0); /* Send message first, then call notifier. Notifier will trigger FIB update, so that @@ -710,16 +707,19 @@ static void check_lifetime(struct work_struct *work) unsigned long now, next, next_sec, next_sched; struct in_ifaddr *ifa; struct hlist_node *n; + struct net *net; int i; + net = container_of(to_delayed_work(work), struct net, ipv4.addr_chk_work); now = jiffies; next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); for (i = 0; i < IN4_ADDR_HSIZE; i++) { + struct hlist_head *head = &net->ipv4.inet_addr_lst[i]; bool change_needed = false; rcu_read_lock(); - hlist_for_each_entry_rcu(ifa, &inet_addr_lst[i], hash) { + hlist_for_each_entry_rcu(ifa, head, addr_lst) { unsigned long age, tstamp; u32 preferred_lft; u32 valid_lft; @@ -757,7 +757,7 @@ static void check_lifetime(struct work_struct *work) if (!change_needed) continue; rtnl_lock(); - hlist_for_each_entry_safe(ifa, n, &inet_addr_lst[i], hash) { + hlist_for_each_entry_safe(ifa, n, head, addr_lst) { unsigned long age; if (ifa->ifa_flags & IFA_F_PERMANENT) @@ -806,8 +806,8 @@ static void check_lifetime(struct work_struct *work) if (time_before(next_sched, now + ADDRCONF_TIMER_FUZZ_MAX)) next_sched = now + ADDRCONF_TIMER_FUZZ_MAX; - queue_delayed_work(system_power_efficient_wq, &check_lifetime_work, - next_sched - now); + queue_delayed_work(system_power_efficient_wq, &net->ipv4.addr_chk_work, + next_sched - now); } static void set_ifa_lifetime(struct in_ifaddr *ifa, __u32 valid_lft, @@ -1004,9 +1004,9 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, ifa->ifa_proto = new_proto; set_ifa_lifetime(ifa, valid_lft, prefered_lft); - cancel_delayed_work(&check_lifetime_work); + cancel_delayed_work(&net->ipv4.addr_chk_work); queue_delayed_work(system_power_efficient_wq, - &check_lifetime_work, 0); + &net->ipv4.addr_chk_work, 0); rtmsg_ifa(RTM_NEWADDR, ifa, nlh, NETLINK_CB(skb).portid); } return 0; @@ -2743,6 +2743,8 @@ static __net_init int devinet_init_net(struct net *net) for (i = 0; i < IN4_ADDR_HSIZE; i++) INIT_HLIST_HEAD(&net->ipv4.inet_addr_lst[i]); + INIT_DEFERRABLE_WORK(&net->ipv4.addr_chk_work, check_lifetime); + net->ipv4.devconf_all = all; net->ipv4.devconf_dflt = dflt; return 0; @@ -2769,7 +2771,11 @@ static __net_exit void devinet_exit_net(struct net *net) { #ifdef CONFIG_SYSCTL const struct ctl_table *tbl; +#endif + + cancel_delayed_work_sync(&net->ipv4.addr_chk_work); +#ifdef CONFIG_SYSCTL tbl = net->ipv4.forw_hdr->ctl_table_arg; unregister_net_sysctl_table(net->ipv4.forw_hdr); __devinet_sysctl_unregister(net, net->ipv4.devconf_dflt, @@ -2806,8 +2812,6 @@ void __init devinet_init(void) register_pernet_subsys(&devinet_ops); register_netdevice_notifier(&ip_netdev_notifier); - queue_delayed_work(system_power_efficient_wq, &check_lifetime_work, 0); - rtnl_af_register(&inet_af_ops); rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, 0); From patchwork Tue Oct 1 02:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13817361 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-52004.amazon.com (smtp-fw-52004.amazon.com [52.119.213.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0F0F43178 for ; Tue, 1 Oct 2024 02:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.119.213.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751063; cv=none; b=dP5Uo3yxeuqESnX7Fw64gt9dXdPrdfYLD6fOLmEDNfkf9zlj9NuPgGq9hLiUOjfjUmpzdC60bYyJ8w5N/TeKpQMHa3RIjmh+K4t8YyVhZ5LHfipmSyBW5IV0ubyoSSDV04aWf+/8uh+fWQ9NyRjWPky6qnNZh5sBoG50FbgxJNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751063; c=relaxed/simple; bh=HBWKCgE5EY78NmPOf3z/dGtMPpNnFUhICgHwI6GWNK8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PJbFM3LIVMEOiYl4lbcN/BbXaUmoFl0zAV3HkxzVkS9dp0niUj6rLkPI4QiQfT5WFszFyo2oAFL+ORk/IFyH7BJAPoXvSOY98SO/GNwiTO6gPhfOSgt1Jsw/HS76klItjqbElOBZ0j5y7+J5iXY1yjA9ecWHSGcpwtY6cI6zpUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=VuJTlmYL; arc=none smtp.client-ip=52.119.213.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="VuJTlmYL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727751062; x=1759287062; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JVaTk5JnmONlWw4j0Cheg9c9QDUyy42Jw7yUalwPwMQ=; b=VuJTlmYLkz1aweJ01icCo3zB2ZIPNsO7ciF9UK2lPdUIa0sruPgI/e7c wmPXqlh54RDXnH8xejAZnJe+2tLWATjktcqudrhstPgdQ0NS0jcy1KxBk TqUwj40Tu7BB6ci7U1b32f2qgZcti4Ba85UKfhcGQuajb5yTiB5QRDLuJ o=; X-IronPort-AV: E=Sophos;i="6.11,167,1725321600"; d="scan'208";a="235755525" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.2]) by smtp-border-fw-52004.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 02:51:01 +0000 Received: from EX19MTAUWC001.ant.amazon.com [10.0.21.151:53858] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.25.223:2525] with esmtp (Farcaster) id 045d401b-8193-4227-b27b-a8d8f166a631; Tue, 1 Oct 2024 02:50:59 +0000 (UTC) X-Farcaster-Flow-ID: 045d401b-8193-4227-b27b-a8d8f166a631 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 1 Oct 2024 02:50:59 +0000 Received: from 88665a182662.ant.amazon.com (10.1.212.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Tue, 1 Oct 2024 02:50:54 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 4/5] ipv4: Retire global IPv4 hash table inet_addr_lst. Date: Tue, 1 Oct 2024 05:48:36 +0300 Message-ID: <20241001024837.96425-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241001024837.96425-1-kuniyu@amazon.com> References: <20241001024837.96425-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D040UWB003.ant.amazon.com (10.13.138.8) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org No one uses inet_addr_lst anymore, so let's remove it. While at it, we can remove net_hash_mix() from the hash calculation. Signed-off-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/linux/inetdevice.h | 1 - net/ipv4/devinet.c | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h index d0c2bf67a9b0..d9c690c8c80b 100644 --- a/include/linux/inetdevice.h +++ b/include/linux/inetdevice.h @@ -141,7 +141,6 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev) ARP_EVICT_NOCARRIER) struct in_ifaddr { - struct hlist_node hash; struct hlist_node addr_lst; struct in_ifaddr __rcu *ifa_next; struct in_device *ifa_dev; diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index ac245944e89e..96fc4aacc539 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -119,13 +119,9 @@ struct inet_fill_args { #define IN4_ADDR_HSIZE_SHIFT 8 #define IN4_ADDR_HSIZE (1U << IN4_ADDR_HSIZE_SHIFT) -static struct hlist_head inet_addr_lst[IN4_ADDR_HSIZE]; - static u32 inet_addr_hash(const struct net *net, __be32 addr) { - u32 val = (__force u32) addr ^ net_hash_mix(net); - - return hash_32(val, IN4_ADDR_HSIZE_SHIFT); + return hash_32(addr, IN4_ADDR_HSIZE_SHIFT); } static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) @@ -133,7 +129,6 @@ static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) u32 hash = inet_addr_hash(net, ifa->ifa_local); ASSERT_RTNL(); - hlist_add_head_rcu(&ifa->hash, &inet_addr_lst[hash]); hlist_add_head_rcu(&ifa->addr_lst, &net->ipv4.inet_addr_lst[hash]); } @@ -141,7 +136,6 @@ static void inet_hash_remove(struct in_ifaddr *ifa) { ASSERT_RTNL(); hlist_del_init_rcu(&ifa->addr_lst); - hlist_del_init_rcu(&ifa->hash); } /** @@ -228,7 +222,6 @@ static struct in_ifaddr *inet_alloc_ifa(struct in_device *in_dev) in_dev_hold(in_dev); ifa->ifa_dev = in_dev; - INIT_HLIST_NODE(&ifa->hash); INIT_HLIST_NODE(&ifa->addr_lst); return ifa; @@ -2804,11 +2797,6 @@ static struct rtnl_af_ops inet_af_ops __read_mostly = { void __init devinet_init(void) { - int i; - - for (i = 0; i < IN4_ADDR_HSIZE; i++) - INIT_HLIST_HEAD(&inet_addr_lst[i]); - register_pernet_subsys(&devinet_ops); register_netdevice_notifier(&ip_netdev_notifier); From patchwork Tue Oct 1 02:48:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13817362 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A87F433A2 for ; Tue, 1 Oct 2024 02:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751099; cv=none; b=Gt3yCW7xTyaUZu4KUUsMsAjCm43DE3WAY+lZ1x+Dz/ecJdekTIHO3ISd/p9ywgIsmDFF7dHJgmeWuyZi7Tr+HZfuPYOGooPZGNJp6qmgyyygmR+zWmC0JbTL/z1rtvDXzob9E1eOFEL0gc0PPGa80lrHNF7Ly0IKgu+f97xmqGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727751099; c=relaxed/simple; bh=f+25mNvpWEGZuResiOiwFm3krJUbIdhlRov4jxhwVS4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lZYOptHGi3usIb1F/J6+3JQtVBAUdWcuApULpM6h679BR5jMJppjjPLGXgQvuxMukj4y6v6kE+XaT3tt++olfUgkO9tkOGXSTdJv3L46SeX4Pj7L4SUU8+XN2lxbLTZPHWCyVC8ZpADnu86I0Uzzxocwe97jIjXOdLwsaHqk2vs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=LNa/3Wzk; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="LNa/3Wzk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1727751097; x=1759287097; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N8NK0DuLa+RBUqX50QSuzr3CBPqdGBNM05YDfGH+Gik=; b=LNa/3WzkJgPb/STATHpBxVNPps7Q5PEkwxozhfzfkM0Cz6vCetDEQsSK 9PdWugSrKgLGF34IexEuMB86pw76wT6Y29jj41f06K/68DfpbfIS1fC45 IHCL6ziiAG/aJ+3pYEB6Vaq2cdfMjcSqkcJFDz+t7pHdgRtEVI57G22Yo k=; X-IronPort-AV: E=Sophos;i="6.11,167,1725321600"; d="scan'208";a="133234201" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2024 02:51:37 +0000 Received: from EX19MTAUWC002.ant.amazon.com [10.0.21.151:41849] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.4.107:2525] with esmtp (Farcaster) id 889ec91d-6cbc-43ca-b489-8cae9154dfd2; Tue, 1 Oct 2024 02:51:37 +0000 (UTC) X-Farcaster-Flow-ID: 889ec91d-6cbc-43ca-b489-8cae9154dfd2 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWC002.ant.amazon.com (10.250.64.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 1 Oct 2024 02:51:36 +0000 Received: from 88665a182662.ant.amazon.com (10.1.212.48) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.35; Tue, 1 Oct 2024 02:51:28 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 5/5] ipv4: Trigger check_lifetime() only when necessary. Date: Tue, 1 Oct 2024 05:48:37 +0300 Message-ID: <20241001024837.96425-6-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20241001024837.96425-1-kuniyu@amazon.com> References: <20241001024837.96425-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D046UWB003.ant.amazon.com (10.13.139.174) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org DHCP is unlikely to be used in non-root network namespaces, and GC is unnecessary in such cases. Let's count the number of non-permanent IPv4 addresses and schedule GC only when the count is not zero. Signed-off-by: Kuniyuki Iwashima --- include/net/netns/ipv4.h | 1 + net/ipv4/devinet.c | 45 +++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 66a4cffc44ee..e37001572111 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -272,5 +272,6 @@ struct netns_ipv4 { siphash_key_t ip_id_key; struct hlist_head *inet_addr_lst; struct delayed_work addr_chk_work; + unsigned int addr_non_perm; }; #endif diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 96fc4aacc539..2510d3ef3291 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -124,18 +124,38 @@ static u32 inet_addr_hash(const struct net *net, __be32 addr) return hash_32(addr, IN4_ADDR_HSIZE_SHIFT); } +static bool inet_ifa_has_lifetime(struct in_ifaddr *ifa) +{ + return !(ifa->ifa_flags & IFA_F_PERMANENT); +} + static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) { u32 hash = inet_addr_hash(net, ifa->ifa_local); ASSERT_RTNL(); hlist_add_head_rcu(&ifa->addr_lst, &net->ipv4.inet_addr_lst[hash]); + + if (inet_ifa_has_lifetime(ifa)) { + WRITE_ONCE(net->ipv4.addr_non_perm, net->ipv4.addr_non_perm + 1); + cancel_delayed_work(&net->ipv4.addr_chk_work); + queue_delayed_work(system_power_efficient_wq, + &net->ipv4.addr_chk_work, 0); + } } static void inet_hash_remove(struct in_ifaddr *ifa) { ASSERT_RTNL(); hlist_del_init_rcu(&ifa->addr_lst); + + if (inet_ifa_has_lifetime(ifa)) { + struct net *net = dev_net(ifa->ifa_dev->dev); + + WRITE_ONCE(net->ipv4.addr_non_perm, net->ipv4.addr_non_perm - 1); + if (!net->ipv4.addr_non_perm) + cancel_delayed_work(&net->ipv4.addr_chk_work); + } } /** @@ -484,7 +504,6 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, { struct in_ifaddr __rcu **last_primary, **ifap; struct in_device *in_dev = ifa->ifa_dev; - struct net *net = dev_net(in_dev->dev); struct in_validator_info ivi; struct in_ifaddr *ifa1; int ret; @@ -553,9 +572,6 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, inet_hash_insert(dev_net(in_dev->dev), ifa); - cancel_delayed_work(&net->ipv4.addr_chk_work); - queue_delayed_work(system_power_efficient_wq, &net->ipv4.addr_chk_work, 0); - /* Send message first, then call notifier. Notifier will trigger FIB update, so that listeners of netlink will know about new ifaddr */ @@ -787,6 +803,9 @@ static void check_lifetime(struct work_struct *work) rtnl_unlock(); } + if (!READ_ONCE(net->ipv4.addr_non_perm)) + return; + next_sec = round_jiffies_up(next); next_sched = next; @@ -979,6 +998,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, } else { u32 new_metric = ifa->ifa_rt_priority; u8 new_proto = ifa->ifa_proto; + int delta = 0; inet_free_ifa(ifa); @@ -996,10 +1016,21 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, ifa->ifa_proto = new_proto; + if (inet_ifa_has_lifetime(ifa)) + delta -= 1; + set_ifa_lifetime(ifa, valid_lft, prefered_lft); - cancel_delayed_work(&net->ipv4.addr_chk_work); - queue_delayed_work(system_power_efficient_wq, - &net->ipv4.addr_chk_work, 0); + + if (inet_ifa_has_lifetime(ifa)) + delta += 1; + + if (delta) { + WRITE_ONCE(net->ipv4.addr_non_perm, net->ipv4.addr_non_perm + delta); + cancel_delayed_work(&net->ipv4.addr_chk_work); + queue_delayed_work(system_power_efficient_wq, + &net->ipv4.addr_chk_work, 0); + } + rtmsg_ifa(RTM_NEWADDR, ifa, nlh, NETLINK_CB(skb).portid); } return 0;