From patchwork Thu Nov 7 16:04:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866660 X-Patchwork-Delegate: kuba@kernel.org Received: from dispatch1-eu1.ppe-hosted.com (dispatch1-eu1.ppe-hosted.com [185.183.29.34]) (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 3AEA52144D4 for ; Thu, 7 Nov 2024 16:05:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.29.34 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995512; cv=fail; b=uLMDb+JhvyZvaFwksDQQA8tU7vIWsZrA2AE5wVVYHm+JGkOvISTcOhLW0J/VqgyhnOGjxnhdaxyiq3S8jd1BSNFLnDvHwlkKiYjKkCszWH4gtOj8EF5hcTEeSfqM7peDFRsnhZUAB9m6tT4odnPr+hgYUaenBrBtUBXxx0yn5lc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995512; c=relaxed/simple; bh=wRDXq4KnObBIDA4BqD3773XGaKp3SKWUJL81Lvhh+r8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=SnLESe+XSpoopSHGJ2U2ozVzVDwf+if73z4g+W8sLFjVo3KwSKFMuhtKU+GdDPyR1i24Rj+rMAUaZkh2T8rRgj9kdaMyWB7ArZrYRcg7KFG95V2Hqa1jJqR4+XlMP0pJwZoPNuNThyOPEwL5BQKW90tUzsnOaet63hB1aKwWglI= 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=d6HJmGKR; arc=fail smtp.client-ip=185.183.29.34 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="d6HJmGKR" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2170.outbound.protection.outlook.com [104.47.17.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mx1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 0B09D480063; Thu, 7 Nov 2024 16:05:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xKG0RKLx77D70grVAuWxd64EZ3TdntRb7GlbyvGXGMQxMAueQQpmnT8LRu16NMsKHgelnngU6R5x3eUIOG16ZETJKxoja10rtnekCFKNq1etJ8NT6ECZh98pmSwSMgBnm8OhtPYfU9mqObWYZnD1HULtbbM8f/Q8g1KoLIrKRr8SDY/kZtWW9gewfyW1m8Pn2R8T0Uk9d8wsWu50rNJTv6AUovkb2CtiiCp6U/HBo/qAzB9Kx7clofu+nLviWqDI9D3gPZYlJ8kpiKtAIVWuIi3I8Y7x0y5w0122+DC/X5blMu+sOn1yhohj+9+90I0hI3lg49nNgtgvGpLK0tdicA== 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=5XE8lGBpL4f3fHxpbegmRttBBbC5qazmOj6/n5o2SLM=; b=INs8/lUKHkftcL67bQ5/yYj7k9RC5EyLEIBG0k0Rth4ejvLkEfjEeOV3bk9jbhE5x/sT1glMDoIPldHYgo+eha4w05QqiGDXANUagjrgw8F4JQrVYd722CkEX8sxMPMTQXn7SxzJ0nCAOP08R2LHRpGOSHjX88YwXTjbEDmUkVKpq3kv+Ta8u0jcZ2b/1ng6bGuythWcTweKoyqw+Hr2mvT26bqdN1QqvBwbSQ2+NhoZsqwl8OnoLGXYj6Q4LCr+l+2hqFhXB3PZ/lTIPd0jfIvcY0Hhn4c2a8qX8yq74nRIKl7tLYB0+OpJzeETrTfpZITeimy1NOfj29DG2JEfxg== 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=5XE8lGBpL4f3fHxpbegmRttBBbC5qazmOj6/n5o2SLM=; b=d6HJmGKRgr6rfZ+J0ydhHydT70ALqEuuKpvvNonPR5HVbWWixU8jomA+/D5plMWRXQwz8vwmHDOTpzShlUIUD+s0OkKreNalTa0VSxPImhbLFeqyOfSXQjDF/rSmCfalDLuLv+79MT3FIOwuWBdUAEPDEzBhj92o0IeiU8jK5mY= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:04 +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.018; Thu, 7 Nov 2024 16:05:03 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 1/6] neighbour: Add hlist_node to struct neighbour Date: Thu, 7 Nov 2024 16:04:38 +0000 Message-Id: <20241107160444.2913124-2-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: 099680b7-d65c-49fb-a125-08dcff45f0d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: d/MqEBEa+lHYhohPNERDVVOI21PrL0tunOR0ayiQplMC80cR+5Ao3snN4J0LkI0XxdMP34BgxT162oEQP9kziXaP/+Lea4uElP9TpkL6DAxuIZzPmp2r6k0RxpXyrozm8NUHY683G9sgUFR7gV3e1CDfziG8l09QGUA8/tELs7fAsDR0jrV5QEvEsrZszDTYX9GJp2uqqt1UWOaWjQ5lI5piCA24IIiVjbu3xAgpzHxD+3D9Udt2YJXiFVfhEtIPGpgQRuXkJ9WCPOx2dhMg4AQD6ikT/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jTVbH7RI42YeIuhDgtwaxO0R9DE5WQ= 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)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yw3bejnUBtVPRrzuQvfR/vml01NQ3w5TeJqCJv/SMoJT4SHvXRVwDJdR+aoK2is6AWcOQgf19mOtmxXvffF3AUz6T8R08k7xM1sEiAi5SPyU9Xnw6lO9HdpmVU7WHpAJhzmJ9SNVw9SC6Zf+BpeYN2tY6SAaLGi//uP0c/c29joij0kOCf4MBI86PicaTBkBbnzjQqLDQyn28Ai3yGdDgie9/ZeTXtGngtUJO6a9oI/EKe7dMbGRH8IAFnZGGZA9kairRhZHgtno9hkQP1ZlGoYjy+/BFzn6rh52cFgEBux7oWwAMAc9zbpNKur6zkwbEJbXzuwiGqYT2bqvqks82QRiL6LqtR9T1okVgoDG2vMkyvcF223GtITyvxyheMjXizrW1zC1/ea/RucmagB8DKVKhmNr2DQXCBSBv/aIOlJxtMbV+W/Pl/hnV/7HlHBtNelyU8Owgw0EwOHQBOVIHHcnmydevE89DQjG95G08KT4MBlLLhU2qm5YRu6bTgWWTKs8XJ4+w22NZfY0DYYcArrnSsRvcFafUFWNtb1HekC9tf3bBRw9R1z3WrTtcGS1M9eFB6XGAM7Hsou0Lc7iD3WMH+sLlOCeLtAHZwijfuLmvKlS/SQA/WlSLQmhoB0gUxNpo8/7rZeuZp7xCKPrQzV5vsGX+qAgmP3X8Wvui2eGLjsgudk26/mdQH6sfOg5VqJv61hREGGiGUl5f3r2EwlNZPjipCGTWUTBs8gsMC93tZ8txbkhRxQ/mW8BMyaos9FZiEaYTrty9kTixZTTcCr2MMWwJSSbAmmNM/+/cNhwjWKS4gvWq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QUOv53Y0xgiIUZ4QpMSFtjVJzLmxuE1MeNbwrm0O0/QnhyRoU99NTaqe7D76/QLvzJHgDY0F1bu/ToZ2GMB57a4XhDHYt2pbDlw13D5ooRjDFmc3U7Woj2o5Ka9rfyITY6yVwQmNjpCdrF1y9bfR3HWzSVVOhDKnfM3PTaHaXBpDJrTKIlN6t8F1/1m9Hel0GhRLQtD/eYjMPlOe6vgevJN5sl7hffJZNzuNTTrAzTvo2ymc19vW+guovSJyC+bdDOBgyrATUZmO9u1G0FYfTz9iP5wJhEy6nX50d4bI7hLB4bTivM5tvDGAvJtDIzI2erFa4cxIEuMTGJCt4i7pFVZuCWVfltuBqJY1xaj8KIJnE7wAb+7BtfE162R79JRU/ZAS9WVfLOtuBowuAnE6DyutxRCf7BtHFlFMsuQAKKZ3zU0BrcN X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 099680b7-d65c-49fb-a125-08dcff45f0d7 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:03.9542 (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: 54U4k/meJm6SaMBRq36VZlbOrIk5R1FSDG78XLPu0C3la4/t13UG9Xhm3cAB6VHcjLwGrKCWSnKI5pM1vjp+NA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995506-Xo8XbgfRfsvf X-MDID-O: eu1;ams;1730995506;Xo8XbgfRfsvf;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Add a doubly-linked node to neighbours, so that they can be deleted without iterating the entire bucket they're in. Signed-off-by: Gilad Naaman Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/net/neighbour.h | 2 ++ net/core/neighbour.c | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 3887ed9e5026..0402447854c7 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -136,6 +136,7 @@ struct neigh_statistics { struct neighbour { struct neighbour __rcu *next; + struct hlist_node hash; struct neigh_table *tbl; struct neigh_parms *parms; unsigned long confirmed; @@ -191,6 +192,7 @@ struct pneigh_entry { struct neigh_hash_table { struct neighbour __rcu **hash_buckets; + struct hlist_head *hash_heads; unsigned int hash_shift; __u32 hash_rnd[NEIGH_NUM_HASH_RND]; struct rcu_head rcu; diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 4b871cecd2ce..5552e6b05c82 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -216,6 +216,7 @@ static bool neigh_del(struct neighbour *n, struct neighbour __rcu **np, neigh = rcu_dereference_protected(n->next, lockdep_is_held(&tbl->lock)); rcu_assign_pointer(*np, neigh); + hlist_del_rcu(&n->hash); neigh_mark_dead(n); retval = true; } @@ -402,6 +403,7 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev, rcu_assign_pointer(*np, rcu_dereference_protected(n->next, lockdep_is_held(&tbl->lock))); + hlist_del_rcu(&n->hash); write_lock(&n->lock); neigh_del_timer(n); neigh_mark_dead(n); @@ -529,20 +531,30 @@ static void neigh_get_hash_rnd(u32 *x) static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift) { + size_t hash_heads_size = (1 << shift) * sizeof(struct hlist_head); size_t size = (1 << shift) * sizeof(struct neighbour *); - struct neigh_hash_table *ret; struct neighbour __rcu **buckets; + struct hlist_head *hash_heads; + struct neigh_hash_table *ret; int i; ret = kmalloc(sizeof(*ret), GFP_ATOMIC); if (!ret) return NULL; + buckets = kvzalloc(size, GFP_ATOMIC); if (!buckets) { kfree(ret); return NULL; } + hash_heads = kvzalloc(hash_heads_size, GFP_ATOMIC); + if (!hash_heads) { + kvfree(buckets); + kfree(ret); + return NULL; + } ret->hash_buckets = buckets; + ret->hash_heads = hash_heads; ret->hash_shift = shift; for (i = 0; i < NEIGH_NUM_HASH_RND; i++) neigh_get_hash_rnd(&ret->hash_rnd[i]); @@ -556,6 +568,7 @@ static void neigh_hash_free_rcu(struct rcu_head *head) rcu); kvfree(nht->hash_buckets); + kvfree(nht->hash_heads); kfree(nht); } @@ -592,6 +605,8 @@ static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl, new_nht->hash_buckets[hash], lockdep_is_held(&tbl->lock))); rcu_assign_pointer(new_nht->hash_buckets[hash], n); + hlist_del_rcu(&n->hash); + hlist_add_head_rcu(&n->hash, &new_nht->hash_heads[hash]); } } @@ -702,6 +717,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, rcu_dereference_protected(nht->hash_buckets[hash_val], lockdep_is_held(&tbl->lock))); rcu_assign_pointer(nht->hash_buckets[hash_val], n); + hlist_add_head_rcu(&n->hash, &nht->hash_heads[hash_val]); write_unlock_bh(&tbl->lock); neigh_dbg(2, "neigh %p is created\n", n); rc = n; @@ -987,6 +1003,7 @@ static void neigh_periodic_work(struct work_struct *work) rcu_assign_pointer(*np, rcu_dereference_protected(n->next, lockdep_is_held(&tbl->lock))); + hlist_del_rcu(&n->hash); neigh_mark_dead(n); write_unlock(&n->lock); neigh_cleanup_and_release(n); @@ -3116,6 +3133,7 @@ void __neigh_for_each_release(struct neigh_table *tbl, rcu_assign_pointer(*np, rcu_dereference_protected(n->next, lockdep_is_held(&tbl->lock))); + hlist_del_rcu(&n->hash); neigh_mark_dead(n); } else np = &n->next; From patchwork Thu Nov 7 16:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866662 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 28A41215F51 for ; Thu, 7 Nov 2024 16:05:14 +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=1730995515; cv=fail; b=XrZQKIOkjw7xcrRkIeBqUZxl5OMon97hsAijffY65CBqKY5f7a2I9DG/OTyEpXReLPf0SpSEIfMjVBMHzmDp9pOxBMe9H01iwRe82K68h6XHtC6cfCo4wfq6Og9OBTtzIMeaCvrRhTLLQAobiYxNWZ4Vcqv7glW/7kOKvtT4bwU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995515; c=relaxed/simple; bh=o/sJmCH23AgOiBiW6FCiG0uh/qlrb5HwB1kB2FGNjm8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=j6yKExG5L4n0I11K4mXv8AsliBsSOj13JRKMnoxzmvg9hxFX4UVuxbOVjhzBN2hLE0U5K8D7oO/pLX0WnDvKz+iEksSrae5pAXwqkOpd9UDVV7S3ZEROhLlDQV0Dl0IXQxKSl9IexcRKmetX7QqD8/B9QSbS7jX993tcUsfD2EY= 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=hqcDUlub; 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="hqcDUlub" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2170.outbound.protection.outlook.com [104.47.17.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mx1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 395F2480061; Thu, 7 Nov 2024 16:05:06 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iUMXT48EvRX8Px3BCSyijk8Vg56bFS1d+4cWSLY/ZLFuipSe9gyhPuLaGkyI8g5QhTWvw47DYMHEbPZj8D+LTz5zZkeQYliyUNP2XT/wvsPBJTVx2t/sNU3WJDYFflPnheoA/eKbGOQ5mZcGhwhtCG9nRNvTl2XRCEbAla3L/vBZFemJ2h6dd/YVB6aWNIbwFWk51wl1kHsZlAuPhZirEHO0aWqxkdwSFR9T8dpoPLiO4KnMPXNeoX6xMQuOuWN6vgHmF2kljxCGCoy6p4jURHZPA2zv/z97D/ghlPp+8i8iyQEWfo5krIA2bo4CdAepLEoIFUvdsK3/bnlXLYc1eQ== 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=kRsvtrurKqv2Ls5pVFJGUXGd5ObigBJoVJu8c4OZPFc=; b=GHQLV3r+o8dXyoEq1J/DMZgOv0BbcBzQt8IpnmZUv7/u8Q0EZdmd7YhvJ8PWZ2mwQHspsPjfk85UyMYcxFiXPbx36DelQN6l6rbsoK9Ra+XGVk2pI2VzFe0jUwX75U0cw2YMBCGVpgIEDN2u5nhqpSgOs56YmkbZFyvY/l25iRCusxbNOdHKTYykzRMpF7Cj0hZgXZ1jOZyVYJIrpfSXes4W3NzEx90MPEYqfCKzlPX9DV+lRwJxF/O7D2uXH5bzcdZg5ocR+wqMw9wtkOWlzI8t5Myh90agN3NmXdFV02visREUmC9gzohF9Qjh/lA+zyCWK3Oq+a7sk9jOlZXzRA== 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=kRsvtrurKqv2Ls5pVFJGUXGd5ObigBJoVJu8c4OZPFc=; b=hqcDUlubQao9zQ651znxVcWAz/F8vnIP6Cpo2awGg/pUQPfDbziMPy6FIqm+7R9zP+MFPdhw8kpGPetXD0IWvDP/abCJi/77tYvhywYAwTrxmvxFeZsw2/+U3gW4Fh/jWaIm7lfxYCEM+pOPuJr9j7CExzp+iD23eJOYb/XJpbA= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:04 +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.018; Thu, 7 Nov 2024 16:05:04 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 2/6] neighbour: Define neigh_for_each_in_bucket Date: Thu, 7 Nov 2024 16:04:39 +0000 Message-Id: <20241107160444.2913124-3-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: 23fa45ca-b694-4d8c-7e12-08dcff45f166 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: 8CYn/fksjVDTiVgmnwDqfTbBxYFh/A1vS3M3i0jOafjnqQLtTY+GJQsh/CGDPV8UOz5xOehrwgcdkC0+4BiV27KItkjIq2HsU+tPdmU/1jjoLhkt3M4st7k62li4llSjvP/DbVaWbkMpMo+Zzz46lYBkGfo+9Jin+RLg1Z72+pibbG+qb9FpWJvYSwQc0StT5btY4+t4AzY/iRor6LS+KJfe7EpFssfQleCvxnmzG5nSUm/aLSaLcmfOd61Dzpf3Y0XbFT0tZHEYc1c3aybQ3T2z22jnZkyGdXMUQhgumQPZcxbHXY3aUGZe/vgum5g8jK/qDLyWRnd8lVrjxWlKe7vlUhB9EDcbTYMBvlzefUYDLTYTodsB4FDmj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H:DB8PR08MB5388.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b+F7VxA1Q4g8Qrj4kz6QIMGNhxAzEoO+WMHpeM9hXbtEUSIWCws82RpLbE7QXnOfwBTu5RNzqGfltgrsyFkkcd+PCCvKRC9mQB5jgowYFRPyoB5IYa5769W2Yrl7MOqpWy7tNRUa3FqiQZNgM6KqXTBjbO+CjC8yKUxAMJSDBWrtsxTgVBLK0PV91N349z13oLZhQwtZXRVRvJNd/gvS88PMXpL0vsaU0LGePrt975cXeBbqzcSqDvcT3NdoPGWjMM78sXrHqyyIsDSjPgj8vY3vIoS2koEwgA8QdBmNKG30pzBm/Uu6ZycJRgdKBNqdegfUXlwOsjD5zcdwS8BOcD2+Yku9HtceCj4U2ujxCUfitXETIcyQkKRANttCCcQgohkBuJ8YbtXsKWWWasrWlEcWgX1SFupb/hTF00adqpdawj4+5gttFyNKwSpRK/yUGECsRbPZqLJbahob1bx7EktO6KmwQTsO74wcjSBRJuegr5ZsxKyZiu73BH0cSlJJiEVrvFUon1dmreiIMYFawD3pcG1/MwmZfBz3QEN8Vd8OL7T4WPQnn74XZFf+zNtby1046uNYtpwsR0orv+lrcdv26JlBzrQcAFOjcsLgW7o70lSAzT3UTWE72b3OHNc1BF1pVEMXQ53ju/Nsb4ByiQJvjRy0VIjlrjJNfOxged/Y/BYIDt7CHaTjHuuf15TPssuUF+FpmLljAekB30dpz2QTauPdthK01zSV8KSeoRXin9W+Yvxg9euZAZbwS/Gl4yO3H6Ts+OyVdXCfQpFIY6lDE9/EbqoxfxbwZsiHoZ53SBhKrFSOsojzil1FpwLA3IsIxPCir8/JKPRMcUQrqLWgs/XfxeODLesCE8QJAats4msezwwQCXZFMaaO5SBtr5t+cmTVCxDgFmR0YG+96I0pB6iS7HBVXFrqyPdP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XT80aUBxvWLRuuqJZpGFTjHt4MQQNA9LG4GfXNEAr7GH0xk0LGlczc3a7Z8pFJiiHL0s2t54SJbEUDoho7ht20uiCzZ93+LYM32UJ3wSds/t6lcCP8iXJsVNOupiu19eVIa/nBsG2El+WhVNi4ewjoV6kF4iVj9hnUHzW8v2pX/8CZPFSNCam9Achz9lJSm6adFkywMWpmH13u2/TvSZD2mshX0YzfTvH81+gIfG3W5DcJ8YDdKCxJ4QoA6Ys7OTUUsYsuoTotqFu20aGBhDw750yq5ty2TXLeTPKvmqLPnA87vcOFzwDRuNoOSMbShMQ2aB X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23fa45ca-b694-4d8c-7e12-08dcff45f166 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:04.8980 (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: f8UmhZwlQ8ekrZgjUwyObFA7Kic81ub9lrVKf12z2osFKuQPSL0IPTvGq2zi77qU7D/S6xUtL8t4Mkxq27hBRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995507-wD4_NtQjtGpc X-MDID-O: eu1;ams;1730995507;wD4_NtQjtGpc;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Introduce neigh_for_each_in_bucket in neighbour.h, to help iterate over the neighbour table more succinctly. Signed-off-by: Gilad Naaman Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/net/neighbour.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 0402447854c7..4b9068c5e668 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -277,6 +277,12 @@ static inline void *neighbour_priv(const struct neighbour *n) extern const struct nla_policy nda_policy[]; +#define neigh_for_each_in_bucket(pos, head) hlist_for_each_entry(pos, head, hash) +#define neigh_for_each_in_bucket_rcu(pos, head) \ + hlist_for_each_entry_rcu(pos, head, hash) +#define neigh_for_each_in_bucket_safe(pos, tmp, head) \ + hlist_for_each_entry_safe(pos, tmp, head, hash) + static inline bool neigh_key_eq32(const struct neighbour *n, const void *pkey) { return *(const u32 *)n->primary_key == *(const u32 *)pkey; From patchwork Thu Nov 7 16:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866663 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 63B8C215F75 for ; Thu, 7 Nov 2024 16:05:16 +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=1730995518; cv=fail; b=jRQ76vESuWmthDF26B2LL3uEsWlOteMED23dHot5af5fOabeeMSCnrE4NjXtsWZHfSuszKN7ZrFolcstwkzAeK88DtfCsjsgzXYDpwTX6q2yZusKQvWCQM6LIBhFMsnRAMzdD5oenTlgkEMQz0ZJJf4JVux6RBV2O/74Z5P5DHY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995518; c=relaxed/simple; bh=M4YJlLQ6s4afoIkJFodK+n+5JONI3jyyzq7xXMostLU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=i+/i8j6q3vrXv48kacK2pzmDusYm1kXULAvQAaHmKeg86lpaHBNum+nhEAMs/SPXDTYDuasL6Hf38yRQLQYPKDNdBtiq9DkAGO+IWRFxT+rAOtdPTeMmmUNO4udk1/yZSHT2L8Hh+87prUPgYdz8M80vTeRGE3NAAuDmr72sX9I= 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=nKB1qf2v; 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="nKB1qf2v" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2170.outbound.protection.outlook.com [104.47.17.170]) (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 DA7D6340063; Thu, 7 Nov 2024 16:05:07 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M5ZKNLE3bHYEaFywsnt12chJg+xIxEJiLVjdqxZnmKtP3tISba+zu5d0Qc7uRqkkMQfh+J4tdmh2vjrSzmCh2JKT9lDMW+sNdZCejMcjLJ7ErkIOITzcyxepFbUoD/7D6e+JuuSZxsQGE1GkfQxEnTaIWd1beNFJL9Pv9FlkjF+7iVn+7PzZK3pohWocDH1BMkLdRWmPY3ZluCS/HBBBbVXsfPEg2/4M3pn/Wpht3m6CBXLEcos9+Ojx00gvUOu/m9sy8eLsbUw+HTU9tkQQLzXlAn1/AcqIYqgoovPOkqY/6KMaN6JCKmGIt5aEDpIj9YfS//Tk1cCFRGDjEpANrw== 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=ZEx5IR1Qry9GTB/i3m8Ac+3lw1zAtE/1MPQW2Wj8ACc=; b=AHkHaEQFSvH2a4bpbmwSN2/mtVC0HKKgF3eNGJOsjrp3z4wlND+NdZEoQ8gRhzbMCD7lymxtXnDu0O4WUDiBVNtSqdDbk1zKJ2y5rMfxo9qfovpQHAERCqN4FF2Vn/hODHJd437S8jGRkHL/8FJ9XydnOl4KZ1cpx8GGYug+u59Fzd2hR9d9a1YDCrjluD4veDe6RQNimvtyaTmeAlQYl1hfxMsjVY8SnvbBVVpAS2XvcmIT7vDYRAYkXtUygaEEEv54V95AJCG/J/v800F+TdDOC0LadKf1NgDtSICQSc3TJDU9dq68LgwskxJaTemL/+pQw7+ulEv4Yfr2G98X5Q== 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=ZEx5IR1Qry9GTB/i3m8Ac+3lw1zAtE/1MPQW2Wj8ACc=; b=nKB1qf2vh3Fe0RXTl/96J4bBpI+rlNJsTD+IJczJ0AxjzytLuIpZM8PkoUa0+ulN/6JKRYKjxDLkInfy8Zk389dnxPmFk9tUDrZhYBFfcq82lKqfW4wisY2NH7HXcKUkPzgXj/tgnQ6edi2ej+dLwawy51anlYAG1qU/rG5/eB8= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:06 +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.018; Thu, 7 Nov 2024 16:05:06 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 3/6] neighbour: Convert seq_file functions to use hlist Date: Thu, 7 Nov 2024 16:04:40 +0000 Message-Id: <20241107160444.2913124-4-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: fb154ee9-88c5-4086-8ce0-08dcff45f20e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: /tH6fsq7ktwOnIqdILnAPiIlh8ruo4H27Wt3CYbdBd64JZC5/RKfcw9ptyUF4gG0PTF3a1fRowEyjaq4X/4vSJUq2Rmx/Ey+ngUUOaIS+WtvFbodrQizE04hM37NmUQFeHTrfvFLcIbXpNQ4+QgKlzC9FNoxwsshKH1QVAz4AXlof00W0Yi4nkqNIa5OHeVCDW71ZnHsaYaEYC6My9LM/Jm4Yk3giGuPSmjipTl6s5XrPO6yHnoDKZQ3PBw9MyPONA7+51XnmF+ZwDmluceczfYOEqTk0Yfs6+iNyuZ2zJ6R6t6vI8kB5+04h9zn0MjOREaSeAGAPNMbsgFlFE3BcGt0MZcdSx3ndpycbsJ44qXf4kqsZp4D15LWv1PFHpNnWm+Q9ROuY3cFD4DbTzGIzpW1O8cLfxnyY/luKFW/QScRcSdqTY+RrdedPEVGpkMiUr6mr/x2YiBzSpgNySd+35cOczGSAB1sxVqcRHUTtJhxw1ODukhDBztLaC0IlA0uZGXbzOG2u1/dxkXEbxmVFf2/nKSpXGcIrIYP8C7vPlJSBotFgbTpyMdrmOPdYplrGk8olJsFqyD0NxxqPQO+8wsmfpVDcW0obtNFeM78fPs//4krJmrYzd/9oyXl7OttoukukTR2W0iy+ng9cnXcckPC8a1F2a6WgA7NnXJ+Eg2GS6EWvZ6rJWnZZcNzatLruFnMdrDNBCeQ2GGvQq8ArNljEHGkviG6yUVywrKz+aA2Lg378VEFKwlpxPfCAvqyti97LERJHivduvZh1JKdquFqsNYUfSjufKACm4Ki78yGVgFfHsKw7EHfiukCue+uSkTUHSSYsz7T1aLYUEWqvG9zM/v8hXiXB6Asf/6BAqlsaRje6rOSC1t/fBL0Cxb/39fb+RYrJQ2vdQbc7ZkSF0NY+u3pnotoxnt+/yvgXpCd/HXbgJNHGSSaYQqcsZHh3HmFNSz79zY3Pritw02cgCjssM7cBlcwB+BWTupFCz8TdGvpaNXICCMxP6D6Lte5zE1GgASuOl6SOtTngrMplN5KmzLW8C3xGKOMTDFYqxc4Yn4cpUjxkTCBSvpTtEXHijBFXtQw+rVGfnu25TJTC02AJN006PuLCwwVGFMRHn3bt2s4LZwpwdLsTDCCfSK9DAOlHaFTnNlUWinWRJc1JFVpC3TIdlR5VvY0nqqMS3+CNJ+G1k23ikaRlGS3RR5fa0eO7+ZVXnjFPBnBmGfBvJTLjjW7tBxe0z+w7t2qsSDjq73zfOdtRiUGmvTqUcw3YBW3uoZaRJVnNCnFpjM9YhQ8B2Vmm3WBgKTmB0UguqL0+YOb2J9vsXo2gptx6JZ2A8Ai/qCoGSgmDXECh2n3u4HuwfaUh5qSZdSa3sphMrs= 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)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S3yqMVb5VFgzI4NgAD9p1tlpPDzl1auWgXqjsLu0qeALOsZf5DJV4dsXSXhVzyJgOX+qyjpfW2pCZw5fkA+Nuu5FrVAdYPosF+htfFpojbKwQbBMBwbLjiWVakz4O0+l7l2PYpNJSRixZEbI08o3I85ZD4Y9SOL5TrO4IrCfQRPn5piruIlPF2BFKvZ9TbeSNUy2GeeNd8RqLeOM0FoUgr4vbRqUVNkMFGwt7b5QkKyTDD6YJmfNThfsmlobBH3S0ECaCNJQcDPWJ41FVFxdKwkkbdyM48cT9Liwn8IAoMnYQR45oDN+/sqTdaFqkHduF3kAxE8365nc4POsOcLbhyQXQkj5Gs9EkG9ADKnhg6FjUQnnTZcYuKjgMNzVXk45Vek9fcZjmuMweEz3mSUSI1CyIjQU7v6ceFvfRa7uNZk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oCSH+0S9fYLuLlC5+GwzOOx4e+e9l+4noCqXxBHvEaPBfr1sVAisswI3Tw0AnJvfr+GN83RS07g1Iy37AxQ7HKVXoOXzEDyhRUjpXoroMIXY8gEONZNANQEFg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: M/gXIxZDQET0zT0mYHRkeKdtOQlTAgxSNTXRizGE8n6JLSclXW2avEDL9m2EliA/Me3W+LiXPw2PiTjI6p41osJqTeLSIXXnu879RyzYBtRHFTzGpuVwqPjPwsLcTWjNtMoNF7olPxMQF1Jqn+uy5jzXLlB/CyKgSp72LSmwftv5niHunXWLteYomFZEYdaPPK3ydwiUmi0h8B3mbhAC7QbjRIeMqFW6GsBDftCLCXbf84JmH898taY30Nxc2VJtn80SrwVE6X/SEaV/6pps8scldNKL0cC+EZLZzbaTICTpUPynMaQ+q/7JDQPQqL91jntBTods1IejuRPG1DbQ8YkHuwNCqU2vbEjB8Br/jItPXRP8slSHMuHnBsutQElR5s5ABfTFUys75v8UlyehEDjAuUHtJtvC8o7A60a/8cX1YWvuMrHlX2HDSvpoKv7hwkI2VEwcsLLbMrjhDk9vpovxJv34wpmZBQrYEsxrgH7q2+ereC9BldrrEsV5s5UKkIe/p0O5CKb15pVsjfOQlTjvLluwMKRa6KS9MM/cMWzKc+4fPhV2JegHZefG2axHPcJgB8YLFDGqTaHVTYWiUGpJn9tDK3pC9wiRmoDboeOCOlSv17NQpLJSwj63XI4M X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb154ee9-88c5-4086-8ce0-08dcff45f20e X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:06.0063 (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: o+95Wtjjgg25M6FJy9UNxCHcgkXy0RAl99XjNWnBKcj3pHNH9kinQKGFXJwApi4coSIvBxX9MMEgLaXduK8Z9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995508-yyAElx5cG39c X-MDID-O: eu1;ams;1730995508;yyAElx5cG39c;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Convert seq_file-related neighbour functionality to use neighbour::hash and the related for_each macro. Signed-off-by: Gilad Naaman Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- net/core/neighbour.c | 104 ++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 5552e6b05c82..3485d6b3ba99 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -3193,43 +3193,53 @@ EXPORT_SYMBOL(neigh_xmit); #ifdef CONFIG_PROC_FS -static struct neighbour *neigh_get_first(struct seq_file *seq) +static struct neighbour *neigh_get_valid(struct seq_file *seq, + struct neighbour *n, + loff_t *pos) { struct neigh_seq_state *state = seq->private; struct net *net = seq_file_net(seq); + + if (!net_eq(dev_net(n->dev), net)) + return NULL; + + if (state->neigh_sub_iter) { + loff_t fakep = 0; + void *v; + + v = state->neigh_sub_iter(state, n, pos ? pos : &fakep); + if (!v) + return NULL; + if (pos) + return v; + } + + if (!(state->flags & NEIGH_SEQ_SKIP_NOARP)) + return n; + + if (READ_ONCE(n->nud_state) & ~NUD_NOARP) + return n; + + return NULL; +} + +static struct neighbour *neigh_get_first(struct seq_file *seq) +{ + struct neigh_seq_state *state = seq->private; struct neigh_hash_table *nht = state->nht; - struct neighbour *n = NULL; - int bucket; + struct neighbour *n, *tmp; state->flags &= ~NEIGH_SEQ_IS_PNEIGH; - for (bucket = 0; bucket < (1 << nht->hash_shift); bucket++) { - n = rcu_dereference(nht->hash_buckets[bucket]); - - while (n) { - if (!net_eq(dev_net(n->dev), net)) - goto next; - if (state->neigh_sub_iter) { - loff_t fakep = 0; - void *v; - v = state->neigh_sub_iter(state, n, &fakep); - if (!v) - goto next; - } - if (!(state->flags & NEIGH_SEQ_SKIP_NOARP)) - break; - if (READ_ONCE(n->nud_state) & ~NUD_NOARP) - break; -next: - n = rcu_dereference(n->next); + while (++state->bucket < (1 << nht->hash_shift)) { + neigh_for_each_in_bucket(n, &nht->hash_heads[state->bucket]) { + tmp = neigh_get_valid(seq, n, NULL); + if (tmp) + return tmp; } - - if (n) - break; } - state->bucket = bucket; - return n; + return NULL; } static struct neighbour *neigh_get_next(struct seq_file *seq, @@ -3237,46 +3247,28 @@ static struct neighbour *neigh_get_next(struct seq_file *seq, loff_t *pos) { struct neigh_seq_state *state = seq->private; - struct net *net = seq_file_net(seq); - struct neigh_hash_table *nht = state->nht; + struct neighbour *tmp; if (state->neigh_sub_iter) { void *v = state->neigh_sub_iter(state, n, pos); + if (v) return n; } - n = rcu_dereference(n->next); - - while (1) { - while (n) { - if (!net_eq(dev_net(n->dev), net)) - goto next; - if (state->neigh_sub_iter) { - void *v = state->neigh_sub_iter(state, n, pos); - if (v) - return n; - goto next; - } - if (!(state->flags & NEIGH_SEQ_SKIP_NOARP)) - break; - if (READ_ONCE(n->nud_state) & ~NUD_NOARP) - break; -next: - n = rcu_dereference(n->next); + hlist_for_each_entry_continue(n, hash) { + tmp = neigh_get_valid(seq, n, pos); + if (tmp) { + n = tmp; + goto out; } - - if (n) - break; - - if (++state->bucket >= (1 << nht->hash_shift)) - break; - - n = rcu_dereference(nht->hash_buckets[state->bucket]); } + n = neigh_get_first(seq); +out: if (n && pos) --(*pos); + return n; } @@ -3379,7 +3371,7 @@ void *neigh_seq_start(struct seq_file *seq, loff_t *pos, struct neigh_table *tbl struct neigh_seq_state *state = seq->private; state->tbl = tbl; - state->bucket = 0; + state->bucket = -1; state->flags = (neigh_seq_flags & ~NEIGH_SEQ_IS_PNEIGH); rcu_read_lock(); From patchwork Thu Nov 7 16:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866664 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 63B2B215F74 for ; Thu, 7 Nov 2024 16:05:16 +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=1730995518; cv=fail; b=mrziubaJjNjbT02f+M8qDGSgk4xzksPBCBQXaqEsac6u0agfbl9jBssNn8DG5+xairxhyyat2gWfML+ieiF8YFe24Rv1hCTeaJ1MMdFJZYXEDi8C8WACdxdaLsl2OPFvHJW2Rejug6WqwCjqqgBd1UXUPB0bujrWcht2fNma90E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995518; c=relaxed/simple; bh=CuMP1ckZxLEi35wz4GDGQI+S/Pq/oSNXOgW7/++BY9g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Z6A3z6Yc++Lcaot8D20o2fonNcjnTx69Z+awvRZEUAi/ZQjGA9EQffpsiQU1dG9foqGSG9rgHOxjkPZqSSH9jXz/EwIx5G3w5d4m5/TrwDdO0qvP8lwwgNa7v6BOQLGy8Woed4CWBOareMtEHV9xJJ4oDeazk03ljNmRiwC479E= 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=D0W6Skc+; 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="D0W6Skc+" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2172.outbound.protection.outlook.com [104.47.17.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by mx1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id 85ED3340059; Thu, 7 Nov 2024 16:05:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FFBGYO/8W3jwfNdX0JS0hGm8NNAMIYJTckAbfZtwvkypOSRLfVV4yXhLmeb7bw31JXQk/vwL5J9mCkaQAQYSNCY/7jCKqH78Ti5kSU8sIDNh9Pusvd0NsF1nqoUm6il74xNB67zSgwPoNKMwoZSlnrlUzwua8mnYpVuDGYS11gLLeEL9BfzyfXGgZUjnqC2ct6kZqjE2nFaUivQpmejm2KTUFeAsQMBILMykt0rsyRxniEXPl5I4Hl29PJ9pjRcXtOy/0UfT7MeThWEIxO5MglMkHhOHd/zDXg3VwBb1iMFywvP2MadVE30KyhSki31dPOK9ATTMsvFMmgg1ZYTW6Q== 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=Iur2WErsI5SQhnOd9ptyx4la21xH7T9pH+p1CPXpfdg=; b=ruPe51mv59QvnNc7UM7amAwOhfiwmAt1mo5ben2UjD0/6rrW7W1AVOiGc+XOkiLjkHXpvN6yfx4d5ngLLZg9l5WDjOr+7fswZnNpe7sSpIqUjgviViNWSfK6m7TkaDNdBOK4TOPLieGfaLhH1lBp7UY2qssVjiI5nqlgp0OkQeEWP+DOCm7vIo3xFbPyPplKAfgG1VIjLQuSG3j3aLYzssYkKzw0a7ldPxlu3D7RL06H2LjGKljG9lh3rQFfLvPcYClvxQywij+ekaccT+6Vd33WGcUUvhoztkOw9xgXukgP5DUCj+ORoGUoJSoB8RtX3NljTs8h67qqVPQIgbAbMw== 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=Iur2WErsI5SQhnOd9ptyx4la21xH7T9pH+p1CPXpfdg=; b=D0W6Skc+3M2CiVZ8bnB/s4IjTKcG4AgJmGkLYNvOl7p5P4NkIOs+RaEAnNDxph5MdtwpqRO4UvwE/2LyAF2A+BjJ+iVlP4BHoy4z2oy3BUVliUsyDsuBPkAy54JVZtkVQWOtTuEb/dm+zpMnHH1HQYyAdPcWJ67WuQy42AOijYA= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:07 +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.018; Thu, 7 Nov 2024 16:05:06 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 4/6] neighbour: Convert iteration to use hlist+macro Date: Thu, 7 Nov 2024 16:04:41 +0000 Message-Id: <20241107160444.2913124-5-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: 58827e91-cb2e-4a4a-2cde-08dcff45f29d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: NL3p3WDrh7qvgMEctFQoyzGBdokM6yiyxz/I6a7hykXvM/krlDqpzxNlzZfof7pK89nTAzeDgHUoZEs8u3HqSM6SQMhvjpJ8J/1Lw4nFLD0vi/8HJZnmVvt1TzjfxqRqTNm6kMjrGTaPV9/PKsiwMtomn8f6BsH1qGrTGuLtPoPFUhzdG7dJiW+54wT/4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QR0p/fmGmpKOFLlSIITG6ukKKbu7k8NiS2odzmBFIvv9TeziArzrsOHqu4xc3oINKcg8VYOQv3/0DgKX8V9CXqFAu3uphVzoyG7I66c9OIV8HxbUROUSN/XlyI= 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)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qQU+uNR7B6gui5me/RfSXJUkN3WchVK6vz89PmpmivxeXppGOtOdyzNp0fbsp6A5ohSRp3GBaVPjHSGV9r0N19DEpT1wtx5Z9YW3z5e6KlaXzmKihg3Rhy8L1AM5qCwafpjVOG2HtkS4ZtQ6D+2CAS/dhyTXXZV7uoGlVikPf7PlAHyX/pdxCMpSpmvWSFcm/OrQg4mqndBYqUXOvP/1DTOmNFUXoKzw/jIim5kRFLCVAvd/MfAHWrQDdJAmjQyeC3xAiFmJMYy9NsYY5bzzsIglZBRAEPYjLbaqo4iHk0/SNpNPkEzLQzgt1XX/hgGhH110pdRLNWiNfQwmtcYkB+1+HAWt3EBQxpZ2wyeSVEd6YD+QQTof2c6TbaqR+YQSNksutbEgNrfaz19i53gp3Y+VZ0qocSUSEDjO+RFRFZNSyKjAkptvnInzAIBdYFeT4n5nyPzTqGBcMUA1n89DKLl3RCHxWu6UUKK0QvBTxZTzlTzCZH2xvdq6ULPTA/oWkuJ15KbMhZvdPi+cXAYsdkoMJO3Ev9UrIfBUT1ayTBf9S2Ibh9AxaEKrZI2LyWwV5pSd53bOFQzgr3J+W4zKMfohsEKZrvmcKHEHvHbkauRiEDtQadA4lUwMJedhOLNaLtmjRcmcopqj3BXQNC/yZEOlFIw5VKkBuYRUn6wTnjjoonA3XwbVodDL5PPWFMrpMkTN8mmcoWprT2U4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6hJ0bqWQPsJFI5oVQ4CvH+77jR8Udndqwt1PqWQhZXdNlyyRpH5FQadCbM9cqd3p1fbvMQ9a+niNfVsuyxc4qMqGerymlPVdrNk7jeq9L03m2cv8Gmt5u0/QhsNGbeeAW5pJlXomYHDVfNM/iLeW/vZNxXLTx5qPDREN1y2Zyi8j00u0+phYJa2HoVCtTcUVA7YQ7kmkly/+usKmhxdEhY3xkDBXGRkyvqhDOTulXc2wUPoXHeHH5QfYO2rfXqchMRoBPsOJVTQ134o8+h0/P2PREKV4CC4zVALViNruceSKrgOYAa8CRlkhIcb4PR57tdv/sB4xRMzrKZfj3BDV9LSnrOama4ds0j2Pq9vqFiuh9f531Ivj6xAZncdSxCAaOXCUkeKJ8JAx9BL712+xWQe5d3dQO6gxUl00b1NovsoAg4WzzQcinjQjtmXE840suZsf7AMFzETTrKkWXBuh24q2WKwoeRv5Oyy/mDBDbrc5vkyA2Dtb5QuSu+iRWH7A0CEyTwkFwZDKrCFrmbqd7U5sUWjE X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58827e91-cb2e-4a4a-2cde-08dcff45f29d X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:06.9352 (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: oBUmQ0svHVVJxVy/cC1AVBGrKQek27BaNtGVZGAAgAY2tmBljLNOji0sJB4oh+soxC9GvBFUnywPRb9/amMfQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995509-vtkOJQwXHnO2 X-MDID-O: eu1;ams;1730995509;vtkOJQwXHnO2;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Remove all usage of the bare neighbour::next pointer, replacing them with neighbour::hash and its for_each macro. Signed-off-by: Gilad Naaman Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/net/neighbour.h | 5 +---- net/core/neighbour.c | 47 ++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 4b9068c5e668..94cf4f8c118f 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -311,12 +311,9 @@ static inline struct neighbour *___neigh_lookup_noref( u32 hash_val; hash_val = hash(pkey, dev, nht->hash_rnd) >> (32 - nht->hash_shift); - for (n = rcu_dereference(nht->hash_buckets[hash_val]); - n != NULL; - n = rcu_dereference(n->next)) { + neigh_for_each_in_bucket_rcu(n, &nht->hash_heads[hash_val]) if (n->dev == dev && key_eq(n, pkey)) return n; - } return NULL; } diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 3485d6b3ba99..f99354d768c2 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -387,11 +387,11 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev, lockdep_is_held(&tbl->lock)); for (i = 0; i < (1 << nht->hash_shift); i++) { - struct neighbour *n; struct neighbour __rcu **np = &nht->hash_buckets[i]; + struct hlist_node *tmp; + struct neighbour *n; - while ((n = rcu_dereference_protected(*np, - lockdep_is_held(&tbl->lock))) != NULL) { + neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[i]) { if (dev && n->dev != dev) { np = &n->next; continue; @@ -587,18 +587,14 @@ static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl, return old_nht; for (i = 0; i < (1 << old_nht->hash_shift); i++) { - struct neighbour *n, *next; + struct hlist_node *tmp; + struct neighbour *n; - for (n = rcu_dereference_protected(old_nht->hash_buckets[i], - lockdep_is_held(&tbl->lock)); - n != NULL; - n = next) { + neigh_for_each_in_bucket_safe(n, tmp, &old_nht->hash_heads[i]) { hash = tbl->hash(n->primary_key, n->dev, new_nht->hash_rnd); hash >>= (32 - new_nht->hash_shift); - next = rcu_dereference_protected(n->next, - lockdep_is_held(&tbl->lock)); rcu_assign_pointer(n->next, rcu_dereference_protected( @@ -693,11 +689,7 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, goto out_tbl_unlock; } - for (n1 = rcu_dereference_protected(nht->hash_buckets[hash_val], - lockdep_is_held(&tbl->lock)); - n1 != NULL; - n1 = rcu_dereference_protected(n1->next, - lockdep_is_held(&tbl->lock))) { + neigh_for_each_in_bucket(n1, &nht->hash_heads[hash_val]) { if (dev == n1->dev && !memcmp(n1->primary_key, n->primary_key, key_len)) { if (want_ref) neigh_hold(n1); @@ -949,10 +941,11 @@ static void neigh_connect(struct neighbour *neigh) static void neigh_periodic_work(struct work_struct *work) { struct neigh_table *tbl = container_of(work, struct neigh_table, gc_work.work); - struct neighbour *n; + struct neigh_hash_table *nht; struct neighbour __rcu **np; + struct hlist_node *tmp; + struct neighbour *n; unsigned int i; - struct neigh_hash_table *nht; NEIGH_CACHE_STAT_INC(tbl, periodic_gc_runs); @@ -979,8 +972,7 @@ static void neigh_periodic_work(struct work_struct *work) for (i = 0 ; i < (1 << nht->hash_shift); i++) { np = &nht->hash_buckets[i]; - while ((n = rcu_dereference_protected(*np, - lockdep_is_held(&tbl->lock))) != NULL) { + neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[i]) { unsigned int state; write_lock(&n->lock); @@ -2730,9 +2722,8 @@ static int neigh_dump_table(struct neigh_table *tbl, struct sk_buff *skb, for (h = s_h; h < (1 << nht->hash_shift); h++) { if (h > s_h) s_idx = 0; - for (n = rcu_dereference(nht->hash_buckets[h]), idx = 0; - n != NULL; - n = rcu_dereference(n->next)) { + idx = 0; + neigh_for_each_in_bucket_rcu(n, &nht->hash_heads[h]) { if (idx < s_idx || !net_eq(dev_net(n->dev), net)) goto next; if (neigh_ifindex_filtered(n->dev, filter->dev_idx) || @@ -3099,9 +3090,7 @@ void neigh_for_each(struct neigh_table *tbl, void (*cb)(struct neighbour *, void for (chain = 0; chain < (1 << nht->hash_shift); chain++) { struct neighbour *n; - for (n = rcu_dereference(nht->hash_buckets[chain]); - n != NULL; - n = rcu_dereference(n->next)) + neigh_for_each_in_bucket(n, &nht->hash_heads[chain]) cb(n, cookie); } read_unlock_bh(&tbl->lock); @@ -3113,18 +3102,18 @@ EXPORT_SYMBOL(neigh_for_each); void __neigh_for_each_release(struct neigh_table *tbl, int (*cb)(struct neighbour *)) { - int chain; struct neigh_hash_table *nht; + int chain; nht = rcu_dereference_protected(tbl->nht, lockdep_is_held(&tbl->lock)); for (chain = 0; chain < (1 << nht->hash_shift); chain++) { - struct neighbour *n; struct neighbour __rcu **np; + struct hlist_node *tmp; + struct neighbour *n; np = &nht->hash_buckets[chain]; - while ((n = rcu_dereference_protected(*np, - lockdep_is_held(&tbl->lock))) != NULL) { + neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[chain]) { int release; write_lock(&n->lock); From patchwork Thu Nov 7 16:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866665 X-Patchwork-Delegate: kuba@kernel.org Received: from dispatch1-eu1.ppe-hosted.com (dispatch1-eu1.ppe-hosted.com [185.183.29.33]) (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 37541215F6E for ; Thu, 7 Nov 2024 16:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.29.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995520; cv=fail; b=AjpdWeIXK7rieD2nWfoxAQBd9OARMtXoayawLFbaV+ygHDweEQ9CzhW130dwHf2J8IQ4Xqx7ctn7IwX3ldJHIHfzT51wNXbh9gaBOSJ0jIYIPD249V0fWbNixe7y15y3TTpQBSoJJIh+LI1u6J1JgIkmTcXQn7LiRQZNCNqzb4g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995520; c=relaxed/simple; bh=LbUnsF6+cSEKF8WJE0dSdqYPxwxIglpSCavQdi8vcos=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=DIKjt9A0mSarYp3bVr2Z9+8MAvLod/0m1gPp/ki7sct1J9NigUOR674nQfisAz2miluTF+2fqX6iGjOYNaF4ZbbxYf1Lz3IatQZg96V9DtkHVtiK2gMif7YbYz3PUNgrhAa5VWSPPx6M+Cdp46CuF+xdVxwwZZV5uPJFN/20QbU= 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=FIEM/RnW; arc=fail smtp.client-ip=185.183.29.33 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="FIEM/RnW" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2170.outbound.protection.outlook.com [104.47.17.170]) (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 BCFD21C0056; Thu, 7 Nov 2024 16:05:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k7LIRJEVfUJY4Fat/9ZFRhS1+itmmeHctefF49yV8MkZkNrsr1DApkAMWraQ9uqplgr67WvdNgwdBc0p/zyYU6bo/V1m+YnavYJqX0HlmQ7srgIrLplHMo8tsNvRSg06Pw96+CnEskeKlJ737B3gDmIkl1dw9b7UotU1Zi52YIpjSYDCw33RG/0Cw562HYjxYTGHqv7crCV9p8O3P2esLQpmP9woCSO0EiJ9gn9qhFoByKQG62fKy96kc20XGOj7L0YgbXsG+I3WHQbAR0KKQe8XhYwnVxCU+Q+mvEtHftAYeTKmVLHimctSJ1N89DBhkKOQYrpt3t03Pjn80Vjggw== 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=9RnCufkdkU39jH7/GK0/s+YLEM+e/LYbD9PDDHP91bQ=; b=Cl2mi8pbYcD71zHhZNmzoDnfrF5gUx8p2/UqaDEASzZ2/MpGUsgJaTrxxBNDVmI0t2VQzPcW0ybF3EfUf5BmDf8KEHhI7iBp+pWnl7WragVD309fpc+BjVcUCmNfkyaMVg4zS24VSwSVINW72+eVeOo094qDDFxmczH1/HQhs1VjPMeqVJP/L59SBDnfXHthzZpHYc7YA3nhtKvj9S8n0J1Cj1+iZJeinfQQrMwj6pxCFeRy17emDQP2p2drBVCA3xqN5rfsFDWvc5r+1Xqr4T5Mxa3mISbaDYECG/PV+IW96aXE2Mfi3Xre1nmV43CfxfFl0CAzI7StX5ZIPkVGNw== 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=9RnCufkdkU39jH7/GK0/s+YLEM+e/LYbD9PDDHP91bQ=; b=FIEM/RnWGB3eE0MGjGevRq17slt0DSUi4jtXCwDE9obJg7au7EHXfarzFG0MlhGGMXW2hsABTiA6DZQ9H5W80CSR6P8/09zCob7OY41HJgHNb4fn6cMKDv6VUtHN9NVybiT1diuw0gjjXuoCaZpece9wuYg2s8YKWgvdKYN+dww= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:08 +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.018; Thu, 7 Nov 2024 16:05:07 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 5/6] neighbour: Remove bare neighbour::next pointer Date: Thu, 7 Nov 2024 16:04:42 +0000 Message-Id: <20241107160444.2913124-6-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: 26260af8-845c-4602-b8a9-08dcff45f332 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: n1yiJc+WjDSD934PTaj7ZPjkZDwvSSohUvtpcfywtHqTecgEbVBjhBO6NghzaknlYGlUvTo0rkPWRY99EJiHBfk7FMsBdqvsZcsOrD/XajQFLwpc74pd2sKRjYxUFGfRO0n8hAfLEQPuC1W1YZHKP+CIt3PWH4U7yI7neMjZOxSl94g//mtDQX8TKLFF3h2s51ApDucX35zrx6eWWGxsM5+xR8G9vIfpL/veR6jISRR0/jZkouu284OU/5DNpzRfeK/XCzE/xFyXD4O5i4sT/rNG7OtSUD4fk7Dm8c7Ht/NXxd78m895tOaM7MNjkpcfrxQBUuT4PSIxsQh6l/c5UczyIyPJuHo5XgEPEX+H7Si5REue0xvxgkp3mZOLZy0yILo5ZWLd15QAtIs8lnBBz6ZTACOI6MAFyNVzidnQsbVufZ29UNdV/a+uYYe4Sjzr247PJAYwEMrPeqp7OnEg52kIy7KAkO2DLp/ojfhqzxitEazJG15ABNsN/Vy01EyYWXsXx2OnwoCGAilfQ+9RshAhQiOZoivo9uYF9A8XT0VoLG2Q7/ASKRaFJaxvGViDX/0ofJJuTt2KXeLozw51yBq5imYk+IdzbGo1FbV61SxyuP9dvV43drCTm3FrdcjuaEt21858T3b83rdjgdpq1uG+VDdPMMj3Gqqel5D6E6HDG1cYOpb+tusNAmwWGfRf7RIBDGSQeZkcshW2HqIRmb5Hp0XTF31evaaAmJOe9lFh9yjdXtoMiF2h6QlF2FRp4Bt6jeKJICqqi4aQIA0XkTYkpfyz0uxfnFQk27Vv8tUK/avSAuWZN4OiG2vgU8t3/CWi58EJZ3/FMn789nOq92zJ9rahf4wgVboRiO4hn6yzsxsPjClI3wmUvHggUzbp824P2twwEBvCOosyCM+fHHhQM228JGFwTv0Bvy8InxQe9aVdSr46ZW6oyTuFBVZSY4pX/DVEandMjKv/mzRfjjXaLiW7DJvSWZTTKjKNJdxDvBKsXpp7M7wUCiQW3WxPJc94ZwdRWr5dZ3skAsNsEjIXgUXivtsqAoxVf8TqQ4duxhgi5o2r0/zVuY5Kr5cyfSrV7MbjhEPFuPHmU5Dpt2yEVqlKFASC7qOT0AZEw0ZeNIA9mavQgjx7qJqkZ2E7O/5BBiFF9DXGRUoWTkqgbC00VG7/L3It2elIWLDFNIbWeSpYl/9bbxTyVwBQx5bPWGAxNg+a/3a7l6uBnA2wQP4GrWUDyIxSejTVXloVYhwjVit2WSpHRCHLCkUuCw3yBAXHTlkZyQjbpC0HwGxHCYghiVxVrOXofv9ho//d3FRifKvn8M+eVKdON7c2WM/7q7Q6P+ZYiWaE3jaHK61gC4aSUvTpBoezvNELV4xz1YU= 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)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EOYlhf6lTHi7Q6cZ+Oy9in8jq7Wmf7FPnKFW5L3ZH2pPU4B1bvmhoDnFyU3DG1G03AkbvE+32zW3tBjor3Yfu1SFAbfDuz/Od4YPjJsNAgAMAZZ6Rue43beEYgzzpunCxnE/nDOkdx0tdyob7l4wxmr4wDOD+YQYOJ5aEyXOwxCUlHYfY5ElLfjw7oVkZsxOw18dm3fCJQZFz5hG53sp33s19AyUWI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duz8RXud1yuyti6fLu/S4KFKwxmx3LPsot8RQWibbZoKRIaZR2uDRoJdxNfV4PfempnNRSIjr456snVoTiXcIECcCJEMocPn4n54Guy/DzaHbIxPd4YlVa8rZC8psFjPBZUQ0ph4gpoV4/H4QTIcv2UuZxb+nCszzpWHOrBJ9IvSK3FabcrSbLsRrxfaYVTdC94ZVKVR77lNh9WoIEkhRu3QjjEITRomAoQ6VKMLotIrKX64eEXNLMzfPab+yM9u7g0EGoajU4ol2e7N0ueuoDAs6UaLPNHNfUh2qlFjVpmvu/ieDD5x05KuEr X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: VLkSZtIAD0KFAcUXs3XDZFtorjy6jlN4RReZBMGjupjl+Ps1EZQl8TNDOwOu0cDlHwxMLqZBPidLnuRHE7ydL7yu3ECh/9hrO2ALV1H75EqKUpfnU4NqnfT/B0FkY7jgPkGecPbISyjTP1QT2SMuZCyB1tCufZfqLRBQQNarXLilvhRjIDtLC0+O1sAJU4gDFGYJj2V3HgqP+reEDylVEsPROBfVtpLXKRLwrUrh8gC2XYFXWZexdhX+OLXaKg1lphPjXCWSAoi8KR1wAbqkb23qZ4sOawul3Lz5J5lnOZix5sBRZ/2V+CXrpPvFDbOPYb6Af2TxbpHB4ikZjAsoUvlfbc1HiQuW+ckh9I7c5Ibqu4fcr0AinQvqMMe3vz6vaXByVNzB9OgZlPFnpremzJVrVp4wLtjeFv3HPY4aaK0eUVnPguY9HtTuUOpALxQyDL/623k5FqnrAxq96wr3Z9Pu1r6OdoFDPqBTrkuc4Pm/NuIAf91NtsY/exCyfh4Dkv5wtlnDjngHGP5nFLDhuR2WbfWFerQm3LcC+F8JcWQK3hIj998TMCH+Bh1huEYqorqEIKdaMWopkobtPBXPZpq/I6Qc5ZMmXb0f8SeaZrSQpBt6al2Zj2cgf6V8HmQY X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26260af8-845c-4602-b8a9-08dcff45f332 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:07.9284 (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: o6YC+HqPx+a8/w/B12EjbaRfLOIL3zAnr1vMirYkLITlKN4lgqZh8V/I1eOoo4Zsy5OAf3N/Ol/AZm6c+tRqHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995510-eohI4hK2qLR1 X-MDID-O: eu1;ams;1730995510;eohI4hK2qLR1;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Remove the now-unused neighbour::next pointer, leaving struct neighbour solely with the hlist_node implementation. Signed-off-by: Gilad Naaman Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet --- include/net/neighbour.h | 4 +- net/core/neighbour.c | 90 +++++------------------------------------ net/ipv4/arp.c | 2 +- 3 files changed, 12 insertions(+), 84 deletions(-) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 94cf4f8c118f..40aac1e24c68 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -135,7 +135,6 @@ struct neigh_statistics { #define NEIGH_CACHE_STAT_INC(tbl, field) this_cpu_inc((tbl)->stats->field) struct neighbour { - struct neighbour __rcu *next; struct hlist_node hash; struct neigh_table *tbl; struct neigh_parms *parms; @@ -191,7 +190,6 @@ struct pneigh_entry { #define NEIGH_NUM_HASH_RND 4 struct neigh_hash_table { - struct neighbour __rcu **hash_buckets; struct hlist_head *hash_heads; unsigned int hash_shift; __u32 hash_rnd[NEIGH_NUM_HASH_RND]; @@ -354,7 +352,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb, int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new, u32 flags, u32 nlmsg_pid); void __neigh_set_probe_once(struct neighbour *neigh); -bool neigh_remove_one(struct neighbour *ndel, struct neigh_table *tbl); +bool neigh_remove_one(struct neighbour *ndel); void neigh_changeaddr(struct neigh_table *tbl, struct net_device *dev); int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev); int neigh_carrier_down(struct neigh_table *tbl, struct net_device *dev); diff --git a/net/core/neighbour.c b/net/core/neighbour.c index f99354d768c2..59f359c7b5e3 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -204,18 +204,12 @@ static void neigh_update_flags(struct neighbour *neigh, u32 flags, int *notify, } } -static bool neigh_del(struct neighbour *n, struct neighbour __rcu **np, - struct neigh_table *tbl) +bool neigh_remove_one(struct neighbour *n) { bool retval = false; write_lock(&n->lock); if (refcount_read(&n->refcnt) == 1) { - struct neighbour *neigh; - - neigh = rcu_dereference_protected(n->next, - lockdep_is_held(&tbl->lock)); - rcu_assign_pointer(*np, neigh); hlist_del_rcu(&n->hash); neigh_mark_dead(n); retval = true; @@ -226,29 +220,6 @@ static bool neigh_del(struct neighbour *n, struct neighbour __rcu **np, return retval; } -bool neigh_remove_one(struct neighbour *ndel, struct neigh_table *tbl) -{ - struct neigh_hash_table *nht; - void *pkey = ndel->primary_key; - u32 hash_val; - struct neighbour *n; - struct neighbour __rcu **np; - - nht = rcu_dereference_protected(tbl->nht, - lockdep_is_held(&tbl->lock)); - hash_val = tbl->hash(pkey, ndel->dev, nht->hash_rnd); - hash_val = hash_val >> (32 - nht->hash_shift); - - np = &nht->hash_buckets[hash_val]; - while ((n = rcu_dereference_protected(*np, - lockdep_is_held(&tbl->lock)))) { - if (n == ndel) - return neigh_del(n, np, tbl); - np = &n->next; - } - return false; -} - static int neigh_forced_gc(struct neigh_table *tbl) { int max_clean = atomic_read(&tbl->gc_entries) - @@ -276,7 +247,7 @@ static int neigh_forced_gc(struct neigh_table *tbl) remove = true; write_unlock(&n->lock); - if (remove && neigh_remove_one(n, tbl)) + if (remove && neigh_remove_one(n)) shrunk++; if (shrunk >= max_clean) break; @@ -387,22 +358,15 @@ static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev, lockdep_is_held(&tbl->lock)); for (i = 0; i < (1 << nht->hash_shift); i++) { - struct neighbour __rcu **np = &nht->hash_buckets[i]; struct hlist_node *tmp; struct neighbour *n; neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[i]) { - if (dev && n->dev != dev) { - np = &n->next; + if (dev && n->dev != dev) continue; - } - if (skip_perm && n->nud_state & NUD_PERMANENT) { - np = &n->next; + if (skip_perm && n->nud_state & NUD_PERMANENT) continue; - } - rcu_assign_pointer(*np, - rcu_dereference_protected(n->next, - lockdep_is_held(&tbl->lock))); + hlist_del_rcu(&n->hash); write_lock(&n->lock); neigh_del_timer(n); @@ -531,9 +495,7 @@ static void neigh_get_hash_rnd(u32 *x) static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift) { - size_t hash_heads_size = (1 << shift) * sizeof(struct hlist_head); - size_t size = (1 << shift) * sizeof(struct neighbour *); - struct neighbour __rcu **buckets; + size_t size = (1 << shift) * sizeof(struct hlist_head); struct hlist_head *hash_heads; struct neigh_hash_table *ret; int i; @@ -542,18 +504,11 @@ static struct neigh_hash_table *neigh_hash_alloc(unsigned int shift) if (!ret) return NULL; - buckets = kvzalloc(size, GFP_ATOMIC); - if (!buckets) { - kfree(ret); - return NULL; - } - hash_heads = kvzalloc(hash_heads_size, GFP_ATOMIC); + hash_heads = kvzalloc(size, GFP_ATOMIC); if (!hash_heads) { - kvfree(buckets); kfree(ret); return NULL; } - ret->hash_buckets = buckets; ret->hash_heads = hash_heads; ret->hash_shift = shift; for (i = 0; i < NEIGH_NUM_HASH_RND; i++) @@ -567,7 +522,6 @@ static void neigh_hash_free_rcu(struct rcu_head *head) struct neigh_hash_table, rcu); - kvfree(nht->hash_buckets); kvfree(nht->hash_heads); kfree(nht); } @@ -596,11 +550,6 @@ static struct neigh_hash_table *neigh_hash_grow(struct neigh_table *tbl, hash >>= (32 - new_nht->hash_shift); - rcu_assign_pointer(n->next, - rcu_dereference_protected( - new_nht->hash_buckets[hash], - lockdep_is_held(&tbl->lock))); - rcu_assign_pointer(new_nht->hash_buckets[hash], n); hlist_del_rcu(&n->hash); hlist_add_head_rcu(&n->hash, &new_nht->hash_heads[hash]); } @@ -705,10 +654,6 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, list_add_tail(&n->managed_list, &n->tbl->managed_list); if (want_ref) neigh_hold(n); - rcu_assign_pointer(n->next, - rcu_dereference_protected(nht->hash_buckets[hash_val], - lockdep_is_held(&tbl->lock))); - rcu_assign_pointer(nht->hash_buckets[hash_val], n); hlist_add_head_rcu(&n->hash, &nht->hash_heads[hash_val]); write_unlock_bh(&tbl->lock); neigh_dbg(2, "neigh %p is created\n", n); @@ -942,7 +887,6 @@ static void neigh_periodic_work(struct work_struct *work) { struct neigh_table *tbl = container_of(work, struct neigh_table, gc_work.work); struct neigh_hash_table *nht; - struct neighbour __rcu **np; struct hlist_node *tmp; struct neighbour *n; unsigned int i; @@ -970,8 +914,6 @@ static void neigh_periodic_work(struct work_struct *work) goto out; for (i = 0 ; i < (1 << nht->hash_shift); i++) { - np = &nht->hash_buckets[i]; - neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[i]) { unsigned int state; @@ -981,7 +923,7 @@ static void neigh_periodic_work(struct work_struct *work) if ((state & (NUD_PERMANENT | NUD_IN_TIMER)) || (n->flags & NTF_EXT_LEARNED)) { write_unlock(&n->lock); - goto next_elt; + continue; } if (time_before(n->used, n->confirmed) && @@ -992,9 +934,6 @@ static void neigh_periodic_work(struct work_struct *work) (state == NUD_FAILED || !time_in_range_open(jiffies, n->used, n->used + NEIGH_VAR(n->parms, GC_STALETIME)))) { - rcu_assign_pointer(*np, - rcu_dereference_protected(n->next, - lockdep_is_held(&tbl->lock))); hlist_del_rcu(&n->hash); neigh_mark_dead(n); write_unlock(&n->lock); @@ -1002,9 +941,6 @@ static void neigh_periodic_work(struct work_struct *work) continue; } write_unlock(&n->lock); - -next_elt: - np = &n->next; } /* * It's fine to release lock here, even if hash table @@ -1951,7 +1887,7 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh, NETLINK_CB(skb).portid, extack); write_lock_bh(&tbl->lock); neigh_release(neigh); - neigh_remove_one(neigh, tbl); + neigh_remove_one(neigh); write_unlock_bh(&tbl->lock); out: @@ -3108,24 +3044,18 @@ void __neigh_for_each_release(struct neigh_table *tbl, nht = rcu_dereference_protected(tbl->nht, lockdep_is_held(&tbl->lock)); for (chain = 0; chain < (1 << nht->hash_shift); chain++) { - struct neighbour __rcu **np; struct hlist_node *tmp; struct neighbour *n; - np = &nht->hash_buckets[chain]; neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[chain]) { int release; write_lock(&n->lock); release = cb(n); if (release) { - rcu_assign_pointer(*np, - rcu_dereference_protected(n->next, - lockdep_is_held(&tbl->lock))); hlist_del_rcu(&n->hash); neigh_mark_dead(n); - } else - np = &n->next; + } write_unlock(&n->lock); if (release) neigh_cleanup_and_release(n); diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 11c1519b3699..cb9a7ed8abd3 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c @@ -1215,7 +1215,7 @@ int arp_invalidate(struct net_device *dev, __be32 ip, bool force) NEIGH_UPDATE_F_ADMIN, 0); write_lock_bh(&tbl->lock); neigh_release(neigh); - neigh_remove_one(neigh, tbl); + neigh_remove_one(neigh); write_unlock_bh(&tbl->lock); } From patchwork Thu Nov 7 16:04:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13866666 X-Patchwork-Delegate: kuba@kernel.org Received: from dispatch1-eu1.ppe-hosted.com (dispatch1-eu1.ppe-hosted.com [185.183.29.33]) (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 5C834215F74 for ; Thu, 7 Nov 2024 16:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.183.29.33 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995522; cv=fail; b=RM/JVMmexHHTrfkrEcD55RWM+md08Ou/FWoCSeVi2RUMr7GAenfQUvIJF06BgY+RXLAX6UKSsnjWKct2frORTDjbl8K3LSMlUJb/Q6wmxYleIxMTmX4gHJolsabzJQSrctQeo6bVOhqk/qZU/0HxrPng95YtpDD2ulf8bpExhM4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730995522; c=relaxed/simple; bh=vha8sFkkE1jBaPBpgiv5yQBlWzP/+qr1zQEzN+mSacI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fiXCtpco7L0WIX+eoIZ82wQR7ovwU/0WQpIpVPySn6OZEQPjz93D32bKcVRE1/uOW3uRXzMgbD70hB5c0VAS5XYnIJJzoCXkmAOqDALCMkq2U9qxYc7DI+djl8J61wEWYRaaM4llxn9yIWKXv1/bkJHGCB5qPpVcLJswpFRX8O0= 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=jXlXCRS7; arc=fail smtp.client-ip=185.183.29.33 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="jXlXCRS7" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2174.outbound.protection.outlook.com [104.47.17.174]) (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 AB8EE480057; Thu, 7 Nov 2024 16:05:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vW31m4eV+egM9GQkzcrarJ9SMzjcNpuYBC2rm+FuBpyK+Bo56AIg+bHVyUlerqyuj3oUprP1WGaA26fOKspjhqhpsfoOEVAUlxSD3xWC8oo9QdOoNp+EPXFOtkx+EzcaN2edkNTHJYHlZq+tBmDEmWcwNBKe04sKt2sUv4Rf67JIQ5wIMjmkMzaE7XLyreHwigDNOK07otdXJW9EvInK/XZld6/FD3YJ7p7r7l/kaXNLyXjlWcfsUMAU35UNL18NivAx7bzPSZ2wzWOLMsheAq1hufjJ7EyVpmancKg4L1zT0rOh/G5UBU7oQJ/2a1ciJo8JEOYfXp47uulAy2tGrg== 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=Mu6nyI9AYIjPx4yrevqVlnreiSklbmXgVOtC88UMn0Q=; b=yHSR0SJRYMfrLyDBqk41C0y5OaNJSPz92nyMguKFv7W/K7375V//In2fPpuG7j2rDEGQL6fMo0dbZ1rgrGwjd6xfUWCJqxpzMIin1nSUrxq8NNQYUe2Byvf1QqLcyyNh6ZjIKEJYYA2OvmqS+7MPjAd0jDjVMoFnwYWJWY48KTRZ1078cP0Cu71HenkJjhEFTb1KPF/SATtpwNCUtAnvfvx61u/cequcGExKCd1uuAfN0NcQpO1qGIRFWEIX3pDJV/dt1nySB9eh1VV2b+Vzd9+nAThbTZSTMRtEcW0QZfuswnib0f4fzM0OvGI+3WztBU1E3H2p0tn0zsTtYzN5zg== 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=Mu6nyI9AYIjPx4yrevqVlnreiSklbmXgVOtC88UMn0Q=; b=jXlXCRS7RaR8R5nArLHDVIbh1krx9bVg7v+TLQ3BZ7A44kmaT70k9iD0OEZugnnu5OlANZvJa4ml7DBabN1OYX94TKb4GbX0jesPgpD9yLXUD2g3BaE+UGBCncStb+fosUxVo9xkML9t4sLbEp724bBypfOA3fn8x1sh8QDBnL4= 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 AS2PR08MB9296.eurprd08.prod.outlook.com (2603:10a6:20b:598::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18; Thu, 7 Nov 2024 16:05:08 +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.018; Thu, 7 Nov 2024 16:05:08 +0000 From: Gilad Naaman To: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima Cc: Gilad Naaman Subject: [PATCH net-next v9 6/6] neighbour: Create netdev->neighbour association Date: Thu, 7 Nov 2024 16:04:43 +0000 Message-Id: <20241107160444.2913124-7-gnaaman@drivenets.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107160444.2913124-1-gnaaman@drivenets.com> References: <20241107160444.2913124-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO3P123CA0030.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::13) 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_|AS2PR08MB9296:EE_ X-MS-Office365-Filtering-Correlation-Id: cc73fb05-7cac-44a1-bd54-08dcff45f3c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|52116014|38350700014; X-Microsoft-Antispam-Message-Info: xUNMc5BcpetLetl07clXyrxZ0NQ5dvROkuIJZeMOmL8q7HuGpnirQKDbGMj4L3qfUqmaigDXWmr7xglBuU8XkZT8kj01XlrwN+sNoAHdisBR09K+EEIhtHgM4BTMhdBMGW5L0fqolsCb5sPZ+aJwI/AAAdgz0Hpd8yqT0LBcQ5Ex52t/Peck2u9k924l/kwmDWAxHuMmr8Lw88ZfL81h3X8I0o4oL5I/0aownf8O/JJSRNtbi5xnu7biYuBYC/0MGI8rdJsCEFLKrGzRq5HA9BiRTijHeHiBdEq6m7AayplWg3YHocTmiqnFiRio698UQZs6SWX0qQf0kgT4bqc5F/JgeUFvVdYHARPrw3svtlSek6T8mK+QrGuLqHZAqgshFVCoVuyLOsPwTva14g0w5vwjDvhtwbqLM8yJBhoz6sTIK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:(13230040)(376014)(366016)(1800799024)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U+oDI0sm1MQT04jLBOAKhfXV7bXtlt8uOKMsgTd4ctQ3EKi1l9FEs6fwhq9t3ZzpTYt69ZbHFriiF9ysoUqNU64Ao43py0c4oxEuTgXmBbIYyZhH3asv0AY/w0y+beuUrxE53K/VNjSaVXY5hSZbEiPLC+aZ7B9s+86OsG7b0KWFKxtnM/zD3Q4yiFBntQ90CZjqFN/tUVLrMAUpP51ATi/U23vT0iaWpjTCyg3zwvOIvcEdpjkbxVXpT3hCxU4CUpPHie3wd1x5F+UDoOeM+FoN5iFoj3dyemSqvfcjHzCvBEwWiA28dG4dDJzZMrpe2Gf4tziaPIGa8V4AzAaSxASA0RfNRPnUB0mnVUjmbCDjjQByyMiCBNSRUgxOMCJCzsUOgclQjKm6kPMYKtUHShhhvG2EuTId8PEe/cz7F2/LdkXr/tFwST2/RzcIyEBUpADONSa7K4+ptrQKcdm376RmVu/jore/CqDZy7GaPNaXraJo0QvMT9gaIdkg/+8ZSHsTY8J4AhQvCSUmkYAPPBg4rOPFqQC4L1DYETajcti1w1vnQ2yBXCGMe4gr/O6KWcJamgNmTYWrY1erbhAcBDK2jiwOglWjfmssRNVL4BYJ7sE5W+7Bv9y1SH7+OQKrLYsXoz4RDvtQuxfzYDexuzabOJPAC6lVZwGyHawrxrAiYM4IjTtxx2jx2MLR/Pu5ZCoKMRW+R44Xupn3OteyJ2XxQOcBXdWFdx3KHlfUAadeRXF244X7obE8FDVDG4JAcSy3JSw6VaH9UDGwgCAV0Pw9T9y5SVh252DKDEoJJHm704yhZBgMH82dcingd14kpH21PP7+k2iXX6dbbTPGEmKqKyHa/gG9VVusOLydyavR8LJPurOnZ41rW2eJFuw0eAtLjHda6EBywhAhz97ymdxH3lAW3ipMTFrp4cptOi0AqC0TR4BqaS9vPT9LfZNwgxpbibLQLQr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Uj8HnD2vShpTr4VkrIRaeebyFrr0pQ2/9ClEeHgkUED4NajdSTCmIb4wWLpO80tJKRV+7T2haqsvj4TuIYOyg5XAMJJs69byF3uErpymTYixxBL7Qpf2wAUJlCDDpyWZRFxzhggTNBwNlXn4llAWHDx0yktwDyVRrFtlUb+cMBwmWtK9xOofzI3vaWp7U5N/NNALsv0EuFi8I6jaHHKzfheOIKk28hqgw9gMSMzm3r0YtZ1V9B7/7W1Cm6cytqFe5XMCZTAicLE X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc73fb05-7cac-44a1-bd54-08dcff45f3c3 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2024 16:05:08.8862 (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: RlHj8/E+GcI6Q2NW7X/q2F0iFwj+tq5nfL1MGfOkNvNfbjDvE02zk9ZHsyll+PMkPdnpDpp6M2n2vrnloNAf8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9296 X-MDID: 1730995511-e50j2hFpCRx6 X-MDID-O: eu1;ams;1730995511;e50j2hFpCRx6;;495c1e7a27a6c3e35a5fabc922783896 X-PPE-TRUSTED: V=1;DIR=OUT; X-Patchwork-Delegate: kuba@kernel.org Create a mapping between a netdev and its neighoburs, allowing for much cheaper flushes. Signed-off-by: Gilad Naaman Reviewed-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 7 ++ include/net/neighbour.h | 9 +- include/net/neighbour_tables.h | 12 +++ net/core/neighbour.c | 96 +++++++++++-------- 5 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 include/net/neighbour_tables.h diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rst index ade50d4e67cf..15e31ece675f 100644 --- a/Documentation/networking/net_cachelines/net_device.rst +++ b/Documentation/networking/net_cachelines/net_device.rst @@ -188,4 +188,5 @@ u64 max_pacing_offload_horizon struct_napi_config* napi_config unsigned_long gro_flush_timeout u32 napi_defer_hard_irqs +struct hlist_head neighbours[2] =================================== =========================== =================== =================== =================================================================================== diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 3c552b648b27..df4483598628 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -52,6 +52,7 @@ #include #include #include +#include struct netpoll_info; struct device; @@ -2032,6 +2033,9 @@ enum netdev_reg_state { * @napi_defer_hard_irqs: If not zero, provides a counter that would * allow to avoid NIC hard IRQ, on busy queues. * + * @neighbours: List heads pointing to this device's neighbours' + * dev_list, one per address-family. + * * FIXME: cleanup struct net_device such that network protocol info * moves out. */ @@ -2440,6 +2444,9 @@ struct net_device { */ struct net_shaper_hierarchy *net_shaper_hierarchy; #endif + + struct hlist_head neighbours[NEIGH_NR_TABLES]; + u8 priv[] ____cacheline_aligned __counted_by(priv_len); } ____cacheline_aligned; diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 40aac1e24c68..9a832cab5b1d 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -29,6 +29,7 @@ #include #include #include +#include /* * NUD stands for "neighbor unreachability detection" @@ -136,6 +137,7 @@ struct neigh_statistics { struct neighbour { struct hlist_node hash; + struct hlist_node dev_list; struct neigh_table *tbl; struct neigh_parms *parms; unsigned long confirmed; @@ -236,13 +238,6 @@ struct neigh_table { struct pneigh_entry **phash_buckets; }; -enum { - NEIGH_ARP_TABLE = 0, - NEIGH_ND_TABLE = 1, - NEIGH_NR_TABLES, - NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */ -}; - static inline int neigh_parms_family(struct neigh_parms *p) { return p->tbl->family; diff --git a/include/net/neighbour_tables.h b/include/net/neighbour_tables.h new file mode 100644 index 000000000000..bcffbe8f7601 --- /dev/null +++ b/include/net/neighbour_tables.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _NET_NEIGHBOUR_TABLES_H +#define _NET_NEIGHBOUR_TABLES_H + +enum { + NEIGH_ARP_TABLE = 0, + NEIGH_ND_TABLE = 1, + NEIGH_NR_TABLES, + NEIGH_LINK_TABLE = NEIGH_NR_TABLES /* Pseudo table for neigh_xmit */ +}; + +#endif diff --git a/net/core/neighbour.c b/net/core/neighbour.c index 59f359c7b5e3..5e572f6eaf2c 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -60,6 +60,25 @@ static int pneigh_ifdown_and_unlock(struct neigh_table *tbl, static const struct seq_operations neigh_stat_seq_ops; #endif +static struct hlist_head *neigh_get_dev_table(struct net_device *dev, int family) +{ + int i; + + switch (family) { + default: + DEBUG_NET_WARN_ON_ONCE(1); + fallthrough; /* to avoid panic by null-ptr-deref */ + case AF_INET: + i = NEIGH_ARP_TABLE; + break; + case AF_INET6: + i = NEIGH_ND_TABLE; + break; + } + + return &dev->neighbours[i]; +} + /* Neighbour hash table buckets are protected with rwlock tbl->lock. @@ -211,6 +230,7 @@ bool neigh_remove_one(struct neighbour *n) write_lock(&n->lock); if (refcount_read(&n->refcnt) == 1) { hlist_del_rcu(&n->hash); + hlist_del_rcu(&n->dev_list); neigh_mark_dead(n); retval = true; } @@ -351,48 +371,42 @@ static void pneigh_queue_purge(struct sk_buff_head *list, struct net *net, static void neigh_flush_dev(struct neigh_table *tbl, struct net_device *dev, bool skip_perm) { - int i; - struct neigh_hash_table *nht; - - nht = rcu_dereference_protected(tbl->nht, - lockdep_is_held(&tbl->lock)); + struct hlist_head *dev_head; + struct hlist_node *tmp; + struct neighbour *n; - for (i = 0; i < (1 << nht->hash_shift); i++) { - struct hlist_node *tmp; - struct neighbour *n; + dev_head = neigh_get_dev_table(dev, tbl->family); - neigh_for_each_in_bucket_safe(n, tmp, &nht->hash_heads[i]) { - if (dev && n->dev != dev) - continue; - if (skip_perm && n->nud_state & NUD_PERMANENT) - continue; + hlist_for_each_entry_safe(n, tmp, dev_head, dev_list) { + if (skip_perm && n->nud_state & NUD_PERMANENT) + continue; - hlist_del_rcu(&n->hash); - write_lock(&n->lock); - neigh_del_timer(n); - neigh_mark_dead(n); - if (refcount_read(&n->refcnt) != 1) { - /* The most unpleasant situation. - We must destroy neighbour entry, - but someone still uses it. - - The destroy will be delayed until - the last user releases us, but - we must kill timers etc. and move - it to safe state. - */ - __skb_queue_purge(&n->arp_queue); - n->arp_queue_len_bytes = 0; - WRITE_ONCE(n->output, neigh_blackhole); - if (n->nud_state & NUD_VALID) - n->nud_state = NUD_NOARP; - else - n->nud_state = NUD_NONE; - neigh_dbg(2, "neigh %p is stray\n", n); - } - write_unlock(&n->lock); - neigh_cleanup_and_release(n); + hlist_del_rcu(&n->hash); + hlist_del_rcu(&n->dev_list); + write_lock(&n->lock); + neigh_del_timer(n); + neigh_mark_dead(n); + if (refcount_read(&n->refcnt) != 1) { + /* The most unpleasant situation. + * We must destroy neighbour entry, + * but someone still uses it. + * + * The destroy will be delayed until + * the last user releases us, but + * we must kill timers etc. and move + * it to safe state. + */ + __skb_queue_purge(&n->arp_queue); + n->arp_queue_len_bytes = 0; + WRITE_ONCE(n->output, neigh_blackhole); + if (n->nud_state & NUD_VALID) + n->nud_state = NUD_NOARP; + else + n->nud_state = NUD_NONE; + neigh_dbg(2, "neigh %p is stray\n", n); } + write_unlock(&n->lock); + neigh_cleanup_and_release(n); } } @@ -655,6 +669,10 @@ ___neigh_create(struct neigh_table *tbl, const void *pkey, if (want_ref) neigh_hold(n); hlist_add_head_rcu(&n->hash, &nht->hash_heads[hash_val]); + + hlist_add_head_rcu(&n->dev_list, + neigh_get_dev_table(dev, tbl->family)); + write_unlock_bh(&tbl->lock); neigh_dbg(2, "neigh %p is created\n", n); rc = n; @@ -935,6 +953,7 @@ static void neigh_periodic_work(struct work_struct *work) !time_in_range_open(jiffies, n->used, n->used + NEIGH_VAR(n->parms, GC_STALETIME)))) { hlist_del_rcu(&n->hash); + hlist_del_rcu(&n->dev_list); neigh_mark_dead(n); write_unlock(&n->lock); neigh_cleanup_and_release(n); @@ -3054,6 +3073,7 @@ void __neigh_for_each_release(struct neigh_table *tbl, release = cb(n); if (release) { hlist_del_rcu(&n->hash); + hlist_del_rcu(&n->dev_list); neigh_mark_dead(n); } write_unlock(&n->lock);