From patchwork Thu Dec 5 17:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13895863 X-Patchwork-Delegate: kuba@kernel.org Received: from dispatch1-eu1.ppe-hosted.com (dispatch1-eu1.ppe-hosted.com [185.183.29.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BB10224AFB for ; Thu, 5 Dec 2024 17:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.29.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733419231; cv=fail; b=DH8SXNty2FgWHN9x/VZ9AM1tW00f8xdh/bDO9zydqkCzYiWKi75HKq5E/waYVY0eqhODWeeCE687zmbBc7DVXheR+LRKZsDljWmiO5RoS7U3NuZ1cOE9VoOCjEXwTAgBD/CcToxUwSufn9VuorH/apOfXHZuSOdFGrqifRwNHS8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733419231; c=relaxed/simple; bh=0yoooPkGov1rEm0QfPb+5DfsZ35XHtpxMi1AhemcLgk=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=sOqGnyk61JpSSeim+NLcL8m3DVNv90QRKRdpXy3Zl0ZpP744zwai9zvsck3NDaRDkAghimfgN2ccCTKeTQ2GSmE3xnrVZAvBC7ZFDBOljM4nlQMNKhy0zVrNn6SEzve31Fja6nAWhXHhzu2XnFCwrXaJ0xZSN+/Ci7PDVe/Xwkw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=drivenets.com; spf=pass smtp.mailfrom=drivenets.com; dkim=pass (1024-bit key) header.d=drivenets.onmicrosoft.com header.i=@drivenets.onmicrosoft.com header.b=L9xCbrRd; arc=fail smtp.client-ip=185.183.29.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=drivenets.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=drivenets.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=drivenets.onmicrosoft.com header.i=@drivenets.onmicrosoft.com header.b="L9xCbrRd" Received: from dispatch1-eu1.ppe-hosted.com (ip6-localhost [127.0.0.1]) by dispatch1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id D9CC7342940 for ; Thu, 5 Dec 2024 17:13:21 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazlp17012031.outbound.protection.outlook.com [40.93.64.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 74E731C0062; Thu, 5 Dec 2024 17:13:12 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m/ByceVXpjHbdJgWVBLNzxnT5Vtb0Yg1042ZHghUsBbzE2r19tpKm50cP5HBEmrXaer+MZCfto2YqaI9MmNXIvzL1ABfUZbQAl1n8cOMQ/u+sKJxgEB2IeZ/4qN5zSPOwJiIrTYR/sQv15YKq+6uTscAHaTKHiZlxESmIaBuQzokaGauZcI17EgCAIxFW98cpdcgfb7MeZ6/0A4EvfR/ubbLTJ86Uj79PSKW7YZy27j7ZdHBfMENoVoUZoaWTXVAaNbgPO4bI6HdEfCjxkjCEvBWG39G9jErwOftofixMn5372yt4xqYvi0/SxJqUuTJ1/vg5t0UUDbe6BH52b81zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zq3RCU1QH7duiIUmDru6xFZasGiCtRtq1AgLmGPcICw=; b=El8al7wTltP0uB/24PPLDcrDdPZvHNt64dyXfrLh81+fLBXxgl+d2iCaeKQasjNV5iiN5A8ynAKzIwWpnmwuKu0xAYJlVeabZ9ggos0pDbhRM/sU98GLwKZdgdtkja0HP7j1Kqy3hfptoj0OhWtb0qEYLRET74+somilQtvUeyYKojvzQjjoMJF6JlNGIK1M6CFQVxKoSG3ZZ/K5mNc/z6yP2Jq+p5kDli7Cbrfh9ZaAXuBJsRk2QPPhvIN+8rvClpJdA4j0WGLK89LmDcLKJPgfHhv5mNzwi2/ZWLrJBTqep98uKgLWNZrnlB9LgQcPwpCYoPndx0KthI4N/q34BA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=drivenets.com; dmarc=pass action=none header.from=drivenets.com; dkim=pass header.d=drivenets.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=drivenets.onmicrosoft.com; s=selector2-drivenets-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zq3RCU1QH7duiIUmDru6xFZasGiCtRtq1AgLmGPcICw=; b=L9xCbrRdbN3GpyM46KufYbWjw/5LR3W+ODe4EnDRVgXYaX3tzJ1WTi1DXnnyAmDM9LTmQ4BICPXjfNnntxZjCQCbmeMDgSK95Xgi0dFliP+eh5/TNRyEiCqS++iW0jIVBIM1W+98mNwM4DXwcNa7rbSr0iVsw6+ktdv5mcKRu4c= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=drivenets.com; Received: from DB8PR08MB5388.eurprd08.prod.outlook.com (2603:10a6:10:11c::7) by PAWPR08MB10120.eurprd08.prod.outlook.com (2603:10a6:102:365::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Thu, 5 Dec 2024 17:13:05 +0000 Received: from DB8PR08MB5388.eurprd08.prod.outlook.com ([fe80::29dd:6773:4977:dc4e]) by DB8PR08MB5388.eurprd08.prod.outlook.com ([fe80::29dd:6773:4977:dc4e%6]) with mapi id 15.20.8230.010; Thu, 5 Dec 2024 17:13:05 +0000 From: Gilad Naaman To: "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org Cc: Gilad Naaman Subject: [PATCH net-next v2] Do not invoke addrconf_verify_rtnl unnecessarily Date: Thu, 5 Dec 2024 17:12:47 +0000 Message-Id: <20241205171248.3958156-1-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: LO0P265CA0010.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::7) To DB8PR08MB5388.eurprd08.prod.outlook.com (2603:10a6:10:11c::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB8PR08MB5388:EE_|PAWPR08MB10120:EE_ X-MS-Office365-Filtering-Correlation-Id: 4af1fef8-abbb-435e-683f-08dd15501538 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: cPCdYxufBVPI3wEQeBW1/V3SJ/0iOsbNu2LL4nQ2i7URwFhX66ERHbqt/91xmikXaSJugFTkQ4+zJgWPLftCdZP4lDhXT3Md5ncTNKiog6T9TezXbDfGiNTRcENrIXhOPqJorBnQpW0U7N9wVO8LbDGHfM6r73Y/tlxqpeFmVrSnEhdpFNqX1Q0imE3Tkjew7KZhqM989bZyHEKrwWASVcRnPnQNV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Tb/AcGtpm1BKcDUm0llwqJWLOJjKZPNMam9lRZHejY7rylBJz5qiI6YCoZn9guIAVkIAses5yFbb5Lvb5ZGF4pxwBpBMT6qULLJqB0H0IuwTtTTg1lPaRDxgi+mIm/VQU3WVNZw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB8PR08MB5388.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: peWid1VXC7YR8lD5cVevevJ5hN+z8idpsj6R2zbdrN3B9tH8nLV+FZjPX+dUMUJJoOFYtd1Yp1MNBe+PNHIG8ObhTmHLJit2wEYVMX3R/d+yihQgae6YQtymyA4N46+vVdpFYG9kH8Bloe26pCn+dGayFxoUporwQ9vxJ7UX1Hh8SUxiN5j1FZ98sSIYnzX8mtYLDLaWesfQxyTAPe8C3Ji+zkoRwVh1MOBj6EKJ6Hb0p2TNr12yyLNxHL4ApYPbWymnJmutwdoXOWpkTJtw1ssZVI1rXKZzh8tT82IBZLLp16+wF9HLIzc+fPQzUimFUPNFWrzw0Vld9mmF1xMOIOrn3MD/JoeY2dtuKK577JBQlXhnw0TqTbVEYAIqs1KPO/cxrtDBF6dk86UcRdwqmRh4VjqwycFk5HHgfkjofBW5Py8xGBNM0+CsM7dCYysVfbTkFFlXANPIgZsdr2I56CB3m+gYSnJ0QtU/UsHcJcIkk7VtyLbGK6eGurAxBPIAHQ4Gzhnir/sPjg2h1xtaEu8x7Cil9J0doj9ROJrgcpKjTxqsTgbLc49WZTrGqEpxyzOZ2o1Fb3Pfxj2XO0LG8OmXe0Yke5EySlGPjjoL1qk0TSf3M28i7fvQt7sKr7r3Acw+A1cH4DuynZfNCf2uQYs4hrhU6cqTa1+WIz1JJzbtvxbNHqPXwBAmlboVZ0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av5luAL3Wdn2mA7MipKuZBrKb/T8bpB0nrGKdED7JqoAUc1QKxq/MhgA0TYMdTrCQkTYQELrvLuSL3bz7tqeBttbakBaOj5ubL0Cy2HNpudAoihYPpZnWEdYDpxp343rhUCaRZvhnk0Ue4F99mj24gPYxwHck6ZiLVzlU/gBGHqLLMYpjBwzTzOnhBrJHGzsRdoDdH9TLrRx/Y+QUINnd42OzLHz4/Q0NxQse8H6JC3rnA/HkvJmH/MFFcqDKviqqUldqO6uBfDkhMN1g/zbZ1p3vft8Gf7CIpwk9w3/SXPHrDTI40ySu1WdUmYyC6TiLbNsXOwk4JHBell9IM5Wsxv1CMbPHiESZkD5rNvrM7Nhg+Mm4/NTm6Fpm5aZigjlSrkSh+G+yo0u2HWjK+Yvg9UBUKT1AlOYq/PJz/2ro6QcxZ1CEssxSQWUeMj5fx1ugE9XCB5zhYqmuSHT+FsZ8eqAb+g+rX4OqhEFuMV3pBWYH9xxeU5e2Q0riL8AY37pyPSgA1woRlSkdYy7OqEQapl6enFusVxyudq1bDSrKcV1cwvvDucbEior X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4af1fef8-abbb-435e-683f-08dd15501538 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 17:13:05.6059 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 662f82da-cf45-4bdf-b295-33b083f5d229 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fYw3uBARmUgDINjW+8JMB7U7ZwOJ51sAbuVsgjZK4QlXIaTDtsplZUo4Qsm0FSRNR4UaDKByjENXnCN5FG3FGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB10120 X-MDID: 1733418793-D0g8dDL5seBc X-MDID-O: eu1;ams;1733418793;D0g8dDL5seBc;;489d0494e21146abff88c0d96984588f X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Do not invoke costly `addrconf_verify_rtnl` if the added address wouldn't need it, or affect the delayed_work timer. For new/modified addresses, call "verify" only if added address has an expiration, or if any temporary address was created. This is done to account for a case where the new expiration time might be sooner than the current delayed_work's expiration. For deleted addresses, avoid calling verify at all: If the address being deleted is not perishable, and thus does not affect the delayed_work expiration, there is not point in going over the entire table. If the address IS perishable, but is not the soonest-to-be-expired address, calling "verify" would not change the expiration, and would be a very expensive nop. If the address IS perishable, and IS the soonest-to-be-expired address, calling or not-calling "verify" for a single address deletion is equivalent in cost. But calling "verify" immediately will result in a performance hit when deleting many addresses. Signed-off-by: Gilad Naaman --- net/ipv6/addrconf.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index c489a1e6aec9..893502787554 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -310,6 +310,16 @@ static inline bool addrconf_link_ready(const struct net_device *dev) return netif_oper_up(dev) && !qdisc_tx_is_noop(dev); } +static inline bool addrconf_perishable(int ifa_flags, u32 prefered_lft) +{ + /* When setting preferred_lft to a value not zero or + * infinity, while valid_lft is infinity + * IFA_F_PERMANENT has a non-infinity life time. + */ + return !((ifa_flags & IFA_F_PERMANENT) && + (prefered_lft == INFINITY_LIFE_TIME)); +} + static void addrconf_del_rs_timer(struct inet6_dev *idev) { if (del_timer(&idev->rs_timer)) @@ -3090,8 +3100,7 @@ static int inet6_addr_add(struct net *net, int ifindex, */ if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD))) ipv6_ifa_notify(0, ifp); - /* - * Note that section 3.1 of RFC 4429 indicates + /* Note that section 3.1 of RFC 4429 indicates * that the Optimistic flag should not be set for * manually configured addresses */ @@ -3100,7 +3109,14 @@ 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(net); + + /* Verify only if it's possible that adding this address + * may modify the worker expiration time. + */ + if ((cfg->ifa_flags & IFA_F_MANAGETEMPADDR) || + addrconf_perishable(cfg->ifa_flags, cfg->preferred_lft)) + addrconf_verify_rtnl(net); + return 0; } else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, @@ -3148,7 +3164,6 @@ static int inet6_addr_del(struct net *net, int ifindex, u32 ifa_flags, (ifp->flags & IFA_F_MANAGETEMPADDR)) delete_tempaddrs(idev, ifp); - addrconf_verify_rtnl(net); if (ipv6_addr_is_multicast(pfx)) { ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, pfx, dev->ifindex); @@ -4645,12 +4660,7 @@ static void addrconf_verify_rtnl(struct net *net) 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 - * infinity, while valid_lft is infinity - * IFA_F_PERMANENT has a non-infinity life time. - */ - if ((ifp->flags & IFA_F_PERMANENT) && - (ifp->prefered_lft == INFINITY_LIFE_TIME)) + if (!addrconf_perishable(ifp->flags, ifp->prefered_lft)) continue; spin_lock(&ifp->lock); @@ -4979,7 +4989,9 @@ static int inet6_addr_modify(struct net *net, struct inet6_ifaddr *ifp, jiffies); } - addrconf_verify_rtnl(net); + if (was_managetempaddr || + addrconf_perishable(cfg->ifa_flags, cfg->preferred_lft)) + addrconf_verify_rtnl(net); return 0; }