From patchwork Fri Nov 8 05:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13867577 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 709D61CABF for ; Fri, 8 Nov 2024 05:26:20 +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=1731043582; cv=fail; b=VStTtWxIDv+8kbfPNB7Hk9A8GHVM2Ncal7y4aQtx47e+4Acl9n8VGZ05tQVw4NT17A5r4FhTBlFWHtcDgPMRdhKCHdNfCMuZYSEO3V8QbX3WrICtyQywHdm0pyRDO209O8jGqxRcjb0wwseRZJoLAMtDD9oadDledE81Tl9i3ks= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731043582; c=relaxed/simple; bh=AdTvBHNPou++MKnjPpwSAYAuw801yB/i1FyCNaDBKkU=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=GfKBm5D5oe0+chds0rVCXob8UyuCud7ZcJEsCetMI9GXQD8gpJPTGxKBsrvNdahnTLdct6+JF1wc8Xd8t6k5Yh6CRwYYPzlRhFmBvZ2Kik1xVw6qFn6wmtnVDVa830mkTJd/B3EKaK2F0HPC439cxW0S9GqvI2ATY0A/IFIMAw8= 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=upgZhTsc; 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="upgZhTsc" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2107.outbound.protection.outlook.com [104.47.18.107]) (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 7A9B134005C; Fri, 8 Nov 2024 05:26:17 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YPKK022+66tCDuSjK7XrSMkepDElXJvYTH1BA/OhhEWY7WQEeZKDgGVYifAjdXykuj8c8CF6PXxnayvsB9ZPxISbmTfUuHQUi1govAcU19gcE3clPgueMhwenVMtPB1/rf+Atm0mB2Gg2XPtlPPT4ltm+TnQJvp0kScxqICxbuDBiacWX27cXzLADmE5jX9hva/7eA0LvNl8SANok9aXCTz+uE4cJWKmfeaYDL6CvFvmhq6pPBKMvoUbfUEbReiFZNDOArzXWIW3vvPF3by1MwCSt357oXWX0nKpWQlV5zRpipcm9dglGabGEnwIxUfSHP/0UDHDLoigxQJSsoq7Kg== 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=JUUJxUNsjA8ER48Bh3Rgg/pXpal4/2IrLcVOD3XriQQ=; b=Z4lifnG4zCUz7ZIyVAevVYqxdhieEwCBY69KqdxsiVw30w6saA9Rq9BS92JZYY/2K6kLpLDXgy17m61rK4XNv7ZkIo/y8Dv8WhOHitavwUwcZarch9Naj9NVp+nCovvNHjcOGWkfMujVM0aHpfCqHFIjjiGFEH6ErMzBazyQEwPajkU4nCHX6b+jfqk894ZrQdfVlvcgt7n1AlZzHumIw/dDJz9ayeOlfa4rWMr6cgSg28t/XNwOiMScs7g8McDPvEatkjtdbPBXxNwG6RwniaWnsal3ZtV5SAwKsnW0Gbpthy3BoszB09zz7BQHxWCm9Rrni4g8cpe1bIFJCEnZbA== 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=JUUJxUNsjA8ER48Bh3Rgg/pXpal4/2IrLcVOD3XriQQ=; b=upgZhTscN5CvJr6HTYEHheOv7kmDNIb7BAWNtaUhaBb+tUDYac651fAtqvMuXEJO6+LJ2xwcW93BC8bLlrfEPIedzfsgy2xYcU/zxjI/c+TJ6pLv03eegVpNGkj1wTJbp3Vu+voQhBLD7L+hQWVG3V3lCYbFNXcYxu65Zn72CQc= 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 PAXPR08MB6431.eurprd08.prod.outlook.com (2603:10a6:102:157::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.20; Fri, 8 Nov 2024 05:26:15 +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.8137.019; Fri, 8 Nov 2024 05:26:15 +0000 From: Gilad Naaman To: Kuniyuki Iwashima , "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] Avoid traversing addrconf hash on ifdown Date: Fri, 8 Nov 2024 05:25:59 +0000 Message-Id: <20241108052559.2926114-1-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: LO6P123CA0057.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:310::14) 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_|PAXPR08MB6431:EE_ X-MS-Office365-Filtering-Correlation-Id: f2841071-b50c-40f6-80d4-08dcffb5dd86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: UkVLZEk1NlXAgWCZ8zsZWyGLv/gBIKqVm00987Yna/UwqX+LGyflzkL88ynA2EAwMrLJJ8KiqN311y0L8Ds4+ZdqezRSVe47M5I27vjAMOtK+xiyFQFl79vFj3QqjT5VLsElZzl5OXJksg9NVrOkRKUGa+ev03Dij23cE+z5QTpiCWYgK+BH2U/0BmI/22+nLpG/nqEXK2WCEZVXZJorDiMojrvPtFcqh4R7slpN9eo7qSidqlGUV3m6be6DpoNew2jlMiUUA53itqmEjt2wUXyLmrcMWBawuCiNAtdhXXv5z0Qd2TEbUQzoFAC9BL4M4O6XhFJmjo+OBJZjoEiYOU1HtqRwVm4X3vtu5lYy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:NLI;SFV:NSPM;H:DB8PR08MB5388.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wZDswWwITIpnKUOy7ARgOqNcsSKY+10GLHAo0MAhH9KmiGJT7yLCbuONWr3Youxw+XYPYD7fjYll8AR8Uykn9FrNT0idGMYfxejCf9Z2ugotHg81JxKv3ayni/Ks/KbdyIcpad/ksoyqY5UtdkT/f/OzUHMM8q1xEA9PDOQ/fkrGz+SQ3PkiZ6aA+2kld9i8Gk4Ce0SWh64nRqvOr1ezSEZ5oyzbkD0qlMqnCjbBSQ+qbzqEXEcd/PVG1OkhUcC+pgt2WQhTZMntQo9akX1LdMOHXNB8319adAFF0FNRUl9EtyNf91yFA3Zc5BtlcZlrZfuCtLZ9ui7cePtifJQ5oeddNAE3mAM8SvdRGXXrbjUkgXk967cbExGBFLlfIXfxmwxzMttQS1+ccQPsRhI1TOtqqPyfUU9JZqMuuZQMBmQ47n3oqNGOzdSc5/Rz3eJLVDGJFBGdwSP/JInykMtD7bQ6sR92OgaKl963+eOHrv/6WYHgcrlvLH3djveKGLA8oCxxdwzkJtJGOcPEeGdMMNFeEMzzpa3yjuk9bLSqMTItNZJ3ONWyNVTyuJUVq6wOksFJwZ5MF3TfmbQC1pbLwPXf8NuaztbbaneQrp9hybsexy0eXm3D47Ay3tqgTzQAmJ4yWm4J1XUW0RJ3KeXptfmj4WzlAMqniSoxbVcM1e5uswrjSuIgSztpZSZoKy7GA6EVAoUy9Iq6wIANpge5Jwa1D4CVhR7wtp23BbSbue64C2o8cPfoQAxoIGAUik9sK7FrU/mHZDpmPaXj0/lQ9xfYZ+wvwmk7RcggqHZuwnuxuAQuML4dlaX99mVZiXo4C9XWMkEeBECZB/sjp+FWz/WQmYb4hLKWmM9HplquC959YQyDpC7NUhB3C4s9krwaerA+I4gGYBKSUYMuA43ftgzOCS1KyAmVhsjsBYeyG2bJ3c+aCqlT45S8CkMVBYoOTGUb6OrCxADFXTzLHDdKOloLdZhcSE/x1v1jmKrj2k2tig6mXEfy8HgK8YFIivt9APiU170HjyphkpjAClfSb1k6MaUvvEF4hdNjtw6+XwL0BR/9u6l40SoSXrROdcl+Zn3ymNr3WtAim0zYObPJY8nM1uOMuxLHOue4GvYLKoIUavos1FsERhBWnUOlu0p9DImDxh0uPm/lgBnay+wJVofW6r38OkDI81qDblFQkmZDT8vssmWM5VZKfLh4n6KUMSyKqTTosmPfgYVA5iXl7J+dVk3OeK4LpX458bZPS+eElpruRhWFTudwarumq5Y/WNwroUUBTYGNfhkhP0neXtsK2CBj9lTYILnZExpP4SPQbTmAu/FTpUt/dYbTMzrVljIrVb6kqPakEs4F779wvN8ArRg62g2trN+qVhIv1sNVw2KVmkdQXeZrOX5zDY7eY1W2v9XYhJJ6ycc3GKVdMmzfrQtPsJUzPGLNLm/sjQCyJqllcOjHkNGgnyhkrcFWwWXjCciyTG84k6BoZkBJnhNWz0LUprGeX8SMLe7xkhEwpDgaSG6lFHKTyqdoyJDvJrfZ1Obab1qSOD4FzOMDE/6ONeNnRROLop7hK1wvDFR1BkwFazePwZBhaoIxwB6mgrtmhByMoB0CTPu6gbZlyg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: msJNpq67+4BVoYE6eDtd+jLFECCOpfiEtSGza5qBdmGVLQ55m0gjjdaCUHqUscNyXqCqH42Ge4Uau3b/PRwu6mN9UlDK+/bMNWp6g11/e0DH7J2H7MHv1z+6CORCN/BoohSoEmxyoBfxXmJiJQUA3uA3NcdDD4NIFbowzKZJb7VN6kb8HCioD/1VgUTpHmM+QAaT7QudDlkSjLR1znqpE1AO36IsqYF6VkCSe1YpWhwKj88dxnc3SvouvBv1wbd/e+s6ZbH/JG9RLTNlWbdRlDzDUVs1u4QNLU5hkMqAwFWCEIM3IHotpf0ZXSWP8oPWs6BhGBta96Db4SDPp0BoFEt88hzJdMK2orKHdbofEs8lhusBiKscN9Opt8Kh+29sSONH4lj2Eb6pt4UT3b7dCBR4086Ygim3vG36FjFao2tcIWodRi36xu/bXgcZWIL2xBJmbsgW7GmH0qKcPxOrXdyklI2DtQLATb4pJek9ecyDxl4kOcRpTZaSHGiZcD19jArZG+3nR2N/CJHvxN6+UkOxSHCC68rA+VRSOhCt9FdmPd8zS5PWrCTBlQhJrEYDBJda+b77K7LqcbkeIR3aus/1YpiY6K5/PGHWAGAeEHrbZm8C8OkdNrhD53l/SJ9C X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2841071-b50c-40f6-80d4-08dcffb5dd86 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2024 05:26:15.2333 (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: RgtihQFB7zxjzyfkfS8Gr70BIRCkKDvTXO594qE1ecx4fJ0yxTFw8s82vpgDCcmJwyaZNBuyBbpglqb0fpwzjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6431 X-MDID: 1731043578-n64g4K_PuzBg X-MDID-O: eu1;ams;1731043578;n64g4K_PuzBg;;3d1c658def2edc17f2dc3c0c0047d85f X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org struct inet6_dev already has a list of addresses owned by the device, enabling us to traverse this much shorter list, instead of scanning the entire hash-table. Signed-off-by: Gilad Naaman --- Changes in v2: - Remove double BH sections - Styling fixes (extra {}, extra newline) --- net/ipv6/addrconf.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index d0a99710d65d..c6fbd634912a 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -3846,12 +3846,12 @@ static int addrconf_ifdown(struct net_device *dev, bool unregister) { unsigned long event = unregister ? NETDEV_UNREGISTER : NETDEV_DOWN; struct net *net = dev_net(dev); - struct inet6_dev *idev; struct inet6_ifaddr *ifa; LIST_HEAD(tmp_addr_list); + struct inet6_dev *idev; bool keep_addr = false; bool was_ready; - int state, i; + int state; ASSERT_RTNL(); @@ -3890,28 +3890,24 @@ 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 = &net->ipv6.inet6_addr_lst[i]; + read_lock_bh(&idev->lock); + spin_lock(&net->ipv6.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) { - addrconf_del_dad_work(ifa); - /* combined flag + permanent flag decide if - * address is retained on a down event - */ - if (!keep_addr || - !(ifa->flags & IFA_F_PERMANENT) || - addr_is_local(&ifa->addr)) { - hlist_del_init_rcu(&ifa->addr_lst); - goto restart; - } - } - } - spin_unlock_bh(&net->ipv6.addrconf_hash_lock); + list_for_each_entry(ifa, &idev->addr_list, if_list) { + addrconf_del_dad_work(ifa); + + /* combined flag + permanent flag decide if + * address is retained on a down event + */ + if (!keep_addr || + !(ifa->flags & IFA_F_PERMANENT) || + addr_is_local(&ifa->addr)) + hlist_del_init_rcu(&ifa->addr_lst); } + spin_unlock(&net->ipv6.addrconf_hash_lock); + read_unlock_bh(&idev->lock); + write_lock_bh(&idev->lock); addrconf_del_rs_timer(idev);