From patchwork Mon Nov 4 08:04:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861014 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 5F02C19D8B2 for ; Mon, 4 Nov 2024 08:05:07 +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=1730707509; cv=fail; b=uxAsP7db5tV0VXhVCnrvroeSOjhrb1Ewx13s19bYSZFZiTaOn5T2W+7CWlLXKbU96AvY5hbkKt06xeqYhClNkIlYZgApUPfaXkCBkn6VO501WmtQxo8IOk0MXHsjfl4luW5gZ1u03OOC6abE/XDMuWUKPq1+SesRATmzv6GzHUY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707509; c=relaxed/simple; bh=unQClmdb7DhPMqlNnd9Q0r05kE24XEkl/yMpvtJGAOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gJMFfknV8w4K5AH0BLL6+ryPs0E2bqyxj2dXhDZqrtOs50g8EDxxYY35BmQ8FAqAJ9bKoAVia7T7aje7c6I9UzhYTeNBpsu6OIF5CrTqJ7b8ZTV03xQrFDmg5fyye6T3siljKh2dvV7Y8+IWHMU+IXu2hZeDvy+C86vDsTOadCo= 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=LCNmWTb1; 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="LCNmWTb1" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2173.outbound.protection.outlook.com [104.47.17.173]) (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 33E62340065; Mon, 4 Nov 2024 08:04:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HgR5T6R78pAMQghEYw4Aj6SdsEWgMjLSTZ6CikOA4MQqHSiT3ziHCbgH2rNziKRLMRvKV7fUQ9QOWb6vdWdV9XzHoI82C4hc6axxfGiA/+bARwFnHd3f6i5hEK3iUGvn+QYjpMafX2fI/Go+4FbulTZilWfrA30VTdIXcdEaTUXP0dCkrgo8seNhtdEE/uxlbLuLomS8CoDISrEow2WQydyaMHfuuKcLuLAJGZ6l12AEhy/phLOGoqfuEX7o6EG711sTsAz6NwfdqXLV9w/zE6GGXME1GmwPrRPQdrJ3FSRtABqujnGuBg+tliwObYfgLLnNfuigvOWOrztkmyMWhw== 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=RLEf7WzQYguIPSRloqAzAB+4WoiA2ddyb8jtyIftuyk=; b=beNgjBxfHyDl3FBhfO21moysORStoJyQ1Z6Q75+ESNKSoOPOiRWShf6+tGm4yIostN4xp3W3fDExCXjUttwH24rIcS346uyw6RXwYRXn4Nf7CXGhqw9GUHpln7LrhBRI0B9goDONj01N25ddHQQJPdyUVL008h9RkXQuBwB2ux+EYYzE7tkM6tdGCNtJV+BmttSt0jvO7oATPqujoXvb/afvQzb3QeetVIia8smbCnFUKk5yOOTwE//fcUJRjPTdk7GOnD5/RSWAyxw6X1Yukf2yTvNUjIGO06oBXHc2z12ewnA/EGyAVM5hJMyXF0VH/eOPpLGNfxjx/dkNUo13BQ== 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=RLEf7WzQYguIPSRloqAzAB+4WoiA2ddyb8jtyIftuyk=; b=LCNmWTb1qz/d4pEq1BzncBJNrD8YFhdhR6i6TVHYrLWB15dbwqDq/0sl7FhA9Rl7xDG434EOSj1MLuk2oEULJWzI8wmZpoeCSEUc/QCS40asegsLJkYSuNfuqpNhNDbqvaT8ctEY7i3GTOnfX2DCcYcLjupor4wuc29yM9FaSeI= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:04:56 +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.8114.028; Mon, 4 Nov 2024 08:04:56 +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 v8 1/6] neighbour: Add hlist_node to struct neighbour Date: Mon, 4 Nov 2024 08:04:29 +0000 Message-ID: <20241104080437.103-2-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e7225e6-5af6-4122-60a3-08dcfca75ee3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: iaPXklG4L5aL04chtclWgOyk58UAZU/k2tw31gPLcliJlCu0X+5rq+ioLA3mCOi6RxCW70WEqQOvc37TTzsPoLJUKolJz1OMPKRFQ3yLmGPXLBXeMXz0WPZ2Kho/cRMR65yCuHfnpUjNCWAMLLvE3Ym70wkI3mDj7X5mHuCtvnc8yEgy7uT/1p+PpMgicjTw6hSZVWFmWEttu/Gpp2poFjwj+Bz1NrUDK3WmfA1Rk2ytEQ8bZSd75Bcd+oX6tfEO8N04ARDXIxlz5RGywgw7TZRDgJ+7SjkB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5J7xtQ731Xe/tuR9KhCmcaTE= 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)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nnMhkFSEFse3SGfnSec28+r9gDq/+frNh7FZO7fkyzoR0m1ecCN9fPfVX4sjknenIiu4cj+coQBTE9kt7w1hkmVizfnRgB0l/Pvmo7QadRANt84jnvAR4Y/+f3s7ApzTChjx8mqUgHD9glp+U3HBNRDPi5xyIRrZ/ruq4FXDiX4GPJYZCJt7EjH0Q+h9QqG/YRGra7kt/QdswGFBiYOg0xMsXyTjur+WNidT4+wi3jBRMqENWBeFWTuVKa0oVgCoNi5p8V5ytvDYvlndNvfXpEMK/jTui9i9PxLsAjRWnKhfj6DrM5Rc8BCWIwjU4h1vaXYoqJkuwiISOsaJj6wKiCnKUsEbhP4o0Nc9UokxTtSaBIFTS5QT/jBWGxBQk6uWbd0wgcSmZF86u7UF7UfudLRrgc2ctfGhmjuM/3qF7dBQqJOI18opnfGerua3vxY1X1KINVAqdv0YfjSZS5ND9xuekEmZPm05aTMtI8jiQru9ZMqf8VvgT+Iv9gjdd7X6HTMcmH80qjkLUOmXJjWbUCGBQGYK1EcuD2sViF7MIqwoAeI96YcWIDOXp7xF65ENMySyVIMzxYOCoX+tF/8GnOkpqWPZxkNRceHvdB8HlS6BtmafqCITPHKF/463MrdtuZRt2hXExq+2qgViw5mYrmwA7D1ls78uyScL0/kUsrAqbt4CTHH7qd4lF1wcSqjYlYQgZ0FQZjQodWdo2huycOcAuRT34kHU0pwpo+oi1AXxkY5rk4eNMinc3/a7BWhpX7X1TmWXgHXN7KR6dE7OaEAA0iWe4j+1Z7ZGfyUKN9mtQCuHP4YToVcJn80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8ykAZewCfGJyXGvxNkNK1kHkEeuFniArfZGece2XUc1BUM+8XBxtAYjMkp/ErMrP9J6tSZsB04+2DzGqPHeVj/V9uPVelmaACz9Fj9Y/o0k9fFB8kkRQCKzj2aUnxDPpFdd6ROU6P6HoADWdz11mridjeoNHAb/RXX0xh1jQqzJz5aid5NOHpzF0CM659m/YwAYq7AkDSM/IXH/ffrgINuNA1JuvhFNYSZiDG8R3grvMqn73a1LyCypjN8WaarKyPgOg1rBUP+fAddyVNWI+tPrTXYgSmFN4KZ5kcgNDol/kSez4YMmnW/TD2R9sVtHSkQe42LGVo0vRO4A4TbwmF+9egaa/jDdSXbsHIp38eISNC1R+eVmcxf6yr1Okc4U5cs1psKpPazItNkkN/5E0cIMZ23rYvyShyRauPxnJhV/cudNKGbXTkBTLA X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e7225e6-5af6-4122-60a3-08dcfca75ee3 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:04:56.3133 (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: nnKd4JUcGKjSLZBcHprFAmurv1pS4XtUxwy75QqY+PmmSJaYX2ZyBtbWvh5HE0vffOgQGofqVTGct9YlULdz0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707499-5q1XUtbhKssC X-MDID-O: eu1;ams;1730707499;5q1XUtbhKssC;;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 --- 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 Mon Nov 4 08:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861013 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 5CA1819D086 for ; Mon, 4 Nov 2024 08:05:07 +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=1730707509; cv=fail; b=lf72GmfAvfdSsBRzcN7JPAbZNhGALK5NIPyaCIgHdL5dIwupeykEEwHVR7bsqeFS8+0gF9RZIuRQAx4xylrDTcq5bLH5E9Dg0gQakT2N+rCkEeOudStUwB30PkxZSJ48Q62sPxGNTgZ7PUnT5Qpdj2c7y6uTkKfPcR90flKC1GY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707509; c=relaxed/simple; bh=LwMu4h2Ye+0tuGnGuBfFIiHEXf6MgETVtnCzvS1mL78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=HmqYyXc8OPUlv4FOKDfpTHhHA9UZx5NBH8uuJ+9sQOMoed1SVoSHCeA90FLLeYep2PAvMOBSxDvkw9A3djMiyVHKJUJzcswuABOzHpesfzaJl0WJaHjL+LW9sn7JN1C6JXQjvoa7ct2BlvnlBqhg+FKZUyIc8A/LlR8u8WHajQ4= 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=JfUFf4B/; 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="JfUFf4B/" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2173.outbound.protection.outlook.com [104.47.17.173]) (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 D038734005A; Mon, 4 Nov 2024 08:04:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D7y35UKVShj5vVzjGIAmsqOAyjtD/2a6U2rMczQYSJ1CHhAWMdyUwimYDoX8TTQqlbwowoNhzG85f1DQrshRdHpSzlGvZLpWnWeBZ8fLwh66HUcKsZc0H3yW7aDwRggoQIcxRJ1CseYe9T5hJ2oMthoT38jpQjGk8hm4fRI4rQk6boBxFwHaX7FI1NjOH/U4CQA926YwJTSg457H4CFAB6D3aGJWKO7rW1KGA9OS4T0Tp0KNWLz9Zx2/Pqtjpanw58RMxpkp6nsIhRYlZWVd7TIox47W0daxb3ouHSnnLpFJG1LfUKw2bqDQViI4KgdFlbiGmSLMSouJAAbQeSgsvg== 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=dfI6vxSqWjoLvb5Z9vMWxTB7MGLt7R8kjlSMGt19DWE=; b=k2OVymWwPEFMNbCnFQGQJJt4xYbORlSDewK9Wn1Nl+/IeAS07FX6eXkOsB15WDvdPLmHm7uMOOd/8p5H760oThxi7jW3izy3QiHQ2XgMLUZhJ3SPy0h9npz+uOb0cctA7RHbg+Q7gh15IcuAhio4FSdOOBe/UBHroi2QWO6BxDPqo2H7NZ89SX2utu9i6xd0OfOA81uRfRD7NFh1eq296C7qFaPQhpiRNENw4yBY4EhjjkzJG5HnshrFqcBfinK6us43E8gG8BQTQiSuNGwYmWVD415pYOgfjzzmQ/G55FgsfWdIDaZyuo6kB01p+G10w/6tAWDljg7hUwFNSaTRzQ== 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=dfI6vxSqWjoLvb5Z9vMWxTB7MGLt7R8kjlSMGt19DWE=; b=JfUFf4B/yEee6OP4y02pe5W8gN1oB0Q8sNY3TML2UIPyfSkerJuTorSvZMqzWwd0tXUP5tN0rJGvkif1FWaO7BSCvdPcEs3U5M76kJXCHo3BRwU614B6r2CkG2duhTqCP9UPOq6wpzhM17BhgeB0sX5nWxKC135+oxAHLJHJfGI= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:04:57 +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.8114.028; Mon, 4 Nov 2024 08:04:57 +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 v8 2/6] neighbour: Define neigh_for_each_in_bucket Date: Mon, 4 Nov 2024 08:04:30 +0000 Message-ID: <20241104080437.103-3-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d92bfb9-e6a5-46e0-b43a-08dcfca75f76 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: mVcDOr1FdtfFnXzkYYBSm2OExP3OrEMBq/jXz9ayllpjvYyry6l9p789b69AocWbUJhJJwGysxGtsiVbzlL3VxrfAiiGVV6rPuACFSOSZqhpEH8ywu91kwrXg9PyiKYnCcuE+jJFz6CRM86fpkzs23jkdBnBibCojTDIAxtf9vXWmAcT9mI34LRdtcbBoj7E2g9vz1eoWCxVrwkM+jMqTOokgiaC4CHizFOu1BXDDCBXPz06XmyQm1IQIQPQZSHQ1vR09H6WpmdyTpaVcTFT97U8JsOlv3HRQQ5rVrRIfZycIlNIOULG7iN2DdfuPxlwKB2aQvAX/hmiY9hvtidyJ5qWzM0pFqf74v+4bB3KaSquWRyzLJBo2IFXLPuTHzBuEFXv8NatT6fKs/Nqzj8xwgGteXHZPG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NONE;SFS:(13230040)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AI0DLQNCB7i3yj5N6HVONi6Pd/I5oueX9nDCUGzIHEqGH5idlO1n+Gv9+7DdDsoVe1K1SaAxEz/adS14Z49cYOF90c38dZQ9J1GthGxMlba2ZtKSClivHTK6uN22msFUrHeptZ6nsDIAH/TOBOfctB7etxAN7fGBNk+meYDcPq6OP3e+tSE/sKjAyTkn8+vJWfoNLhlYhLHgmPu+eeuHC3CsT8h5mdyzr+Sh62Z/2dU+VIRJQd7RpPwjCfwReUokblcsRokQPjXEfOKYOXfpOvg/niJg1j76aXKBWeb+SKRhICFgwKg/0Qh/aHD3/v6vUn6TItL7SYswc0/1und/bXykstxtC27l+HWzS3GRphTRT9BogWb9RU06j/zhPuelfDKG6Xousx7BUecpXo11zpXS9pFn4yNcYxiXVhWHJ4aQEYoxfIrP3bLPG3/VmSGCO4Q+leIljXsz5bhx9SsP9Vkh+2lgj4zoe/xAPDYTG74IyNakYxdNa/lxobEIwmoFc4ZV0bWMipIaZo0uTvLsFVQP1r/zJIqBeAavaOX4FvN/gar9uiHrrkQywabj8IspLSx/0Ewg/+rX1wMqylJoQ8D1u9DKhiYHm8DjNm9GPSMkCGUTtPZLTyhohwq46O9oz9nHqFKvglpPeuEK240nsBC7899Wvvi3AR4niVk50MWC2BEdPmnvR/qZaLMtAXM5Ch3ReuesTq7Qg9fPuifn31V+OHygyh6ZZE3x6vGDWkG+VYhfnc1870TtxlroNcjYY++uQvGk4tju1gtt+gUmgIxLtFxW3BNViSewE+ASKGNfA+GzgGBVcInRGGt1CnPxdBaP0bVebkEmrGR04gH8rOXRv2xbkcwB2ZF5gulxmRDrKroN4kAZuUl/ekJAgfYhCj5Pup4LzRLOx891wdKxzn8dRcdKRZqFTJMXXuTYrsnsBG3mczXrsCPBAHGUgnsiTbGcdx0OM9GohmZmDKAKDEYTYYsNqr/k2JfUBRN7loDRQyy3YatZ8jbBFhywcc4nXMU9coQm/ALtdHqwoxmNmZoh/EQ3BEL7tsq6CESot1Amf0LV2zSrNVhUzLtbFtwJ29ckhW1naj0CS1Mq4x6bNQXMEDPaphuMo3BP/NOUuV7m6kgXuXEIfWXA/wiVGahCOEeSyKJR5J9Fe421UziaO8Yhuy+A7mmb9QkpMLg573hTDM3dUrjyLavsKVPCmGYAe4pBSYysvlKD5+LW4hMlvvlafIOf2Zpf4hlNEMVFxuL4OsoycFFzMsxEsINNu+M7cExiX61ze3xEWp9bxE//Q7tokHM8m0iW8fJUIEsKk+oZkVViFj/AJwlDFLyZxy9dX9ja7si6Strjees3Ie80aF4FMPHWPQuBrH2411cGTi4Gvnx2mORCCbe+6Ogw6RvTDc+TnIXndrBKAmDOq6N5Eve8T4jBzFNLedHXSHBpqlTU1OTNCljFTZGMYfdM9JMS1F410bm572LToNIRrCoet9qWPDM598Vryr5e6xc2tkYWFGy5y4igR2dv9/1BbiEuAsCtRSJNkZI1v93E6oq0zuO8ALBWiJ9LML7J9dxAeRfKkVhPJUDh2Ogtzkt5wm5299upV46vapXHc3hw1e0mvA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: g/EK8/S/9JartVvpiuw6aaduBYtRD2tpaZn2wE2137nkbeW8POFifCGohiK/GoIb6sUkpDl4dOvDRamh9LYu/KfpDTQhcXEDPyowNt0CcMAUE58AM0XY9ABiRZ36oVdBJV3oljzZLoopd8MYH5apx0H7lcZiNxaPbgXka9IoEOyL/5SYmz25MvBH3AebQw6eSbUiqxWkOXdMsb7UoD6Z6SmRuL7hx9ggrYr7zoCTWna1t1MX3MbkDowTs9rvY1O/fojLd3clYHQPY+x+/6H7US45oU3okQb1h89hw2LcToIQdVLZjiJ35AfkQg+uha4UnxcyW4geaXW6djiTwDhfF5AAKmKUy0QuK8szoQG2TzMDOj2ZWVJ1A6UTR4W9vd3cifWtXLmQu8PyggQTE8eH0vtzPNi8Ch5OfrSrGBYE5ubtpjbHi0cDbfD9rXyZ/0zIdOca3nRyjkw6GluoPyg7ZbrnW7XbAxgzSHrSV4QYasSG8wjwLOg+U8JYOfCpFBq3T6nkuTbz08sG7//VblCztXUUmHuf4t0HlqaSkeLhOxm5N0o16U1KSbxf4jWGySg+ZAFnJEphedN+5isPJASE4CKQp59L8idn50uPwtQZc3H+plLMs/bxrGwP7RDor3go X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d92bfb9-e6a5-46e0-b43a-08dcfca75f76 X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:04:57.2746 (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: 82sa+rSyBnNrJLGPG5xpvN98LGyYKWCZUpUh4O9F0zI42sWQpgJyBjLkyfp90cGjDpL5Aq0WXbCBGNUt+CQ2zA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707499-rYjyf8LOoc2a X-MDID-O: eu1;ams;1730707499;rYjyf8LOoc2a;;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 --- include/net/neighbour.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/net/neighbour.h b/include/net/neighbour.h index 0402447854c7..69aaacd1419f 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -277,6 +277,10 @@ 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_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 Mon Nov 4 08:04:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861016 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 ED65D1A3BA1 for ; Mon, 4 Nov 2024 08:05:09 +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=1730707511; cv=fail; b=r5sZc1NNiK0wVqLNXmb3R8rl5DlieFprvvD6vG99fqbmXu/hy855f66KoJP6jN9gNtTUwuyXdj8XXiNn1g0Gbd9s8KbC4975P4MrQnEBKKKC+WnlGss2gQF4SOoHAzJMFFFUeba+gf8lr6Gp5V/LQ+VPg6sOwJHlFRKevBdebJg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707511; c=relaxed/simple; bh=mq7rZ+7AHEK3RXn10tJGzUddFIHMyQnezT/W2ifJsh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=YxMjYj6FhAEbk5q0hoA2DPWG7NZUGjAMkqOaz0Y3RhA6fBXrlIRqd0p3WDaa/v2xYbBSIqZz+W166OJPdCaHdeG4F4s9pb2eaMmy9x6DkEJJdvFDAZw6qVYHGpOywmLHFWsm3nj/mGisPpJruSqAyq7A78RiKpLK1O4keyfjy4Y= 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=uRe8nEv0; 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="uRe8nEv0" Received: from dispatch1-eu1.ppe-hosted.com (ip6-localhost [127.0.0.1]) by dispatch1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 5879D80E88 for ; Mon, 4 Nov 2024 08:05:08 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) (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 8390E340068; Mon, 4 Nov 2024 08:04:59 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tr6/EJcin0KmeOkHn/97PTzrDqjhWxT9D2MY4JlObr5Ihv9tsYuKCTxuO5l3A1+lRrxFHyoAiKG6UO6d2Co3T1kZbTzgKpe0gWWPCX6Au9bnBdJ29EwsyMyxBfnD+l4xZNL+db4q9r0EEOgCIKooQvoWAOuv5bZVuAJnWk5SN9ZpodzdwbZt7roxIFPZ2/9PxLtf0PisKk1EfRGg3ndXNVuEXGYXCOZa14sf51Wmw/xhiYW18fqB4PWtHnzPKErPXr50FFmdTwOIEuPmgLv14tk60kZ3dHrPA8IiAFF7FkbWjEoVyRRZnFnx0qsWWFvTNak23k3oLDRG1nvCRJifUw== 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=AU55zyXM/S6+ag7LI3NSAug29n5avPYjQfhAWqIaJQc=; b=Z6FgQl2spEJC4nvr5ZoZDRDCy8xrzaItbvD37VGC05J/4kxR5fOzHO+oGDnBniWtRs19n79B1u3v0AzTRPI5y/ce5xp8lBpvQT8Gz/XheRDit8ouYYOdvilMOJMSM8yCZHI2lFlbhZzkUG0c+sBV9XPX/jEy2G+oKxxB306ZtuwvdlsTbslp2ZbQpfwd9ScdeOO10PJtjebdtFwq2SMG369Fy7KdLB7a8xcPxwNQBBsCVABy7trpfG74sX3iY9bEMSy7ZV+kqtUiNMZQhmYnpxnRCJhG1UX4yTmTZmKXA8fBcrfSYIBQemke5V3vWlUkcvDQKcbEsuHpOdtuQRTaMA== 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=AU55zyXM/S6+ag7LI3NSAug29n5avPYjQfhAWqIaJQc=; b=uRe8nEv0Ypg5jJtlHrPkSWe6UkvsiXCrzIdeYFyijGE5MSjfazfj7wCyH1ECU67dcRrbEq+mpiBZBBxxQPjAqP73gNA1SLo49Lmy0iGOlj6ILrON2pKowmNveJDx9VRnZBk+ANpEIgqPyavJXKshVZI8kD2RVHflJ6KHkGFhKAM= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:04:58 +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.8114.028; Mon, 4 Nov 2024 08:04:58 +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 v8 3/6] neighbour: Convert seq_file functions to use hlist Date: Mon, 4 Nov 2024 08:04:31 +0000 Message-ID: <20241104080437.103-4-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: 84ffd21a-b9be-48ba-5f38-08dcfca7600b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: 6K9ewSZVaUseAEx2rcIlrqtm2MENKTA5ncOBMW+JmozDTtei4DS40Q/lOgmdDH+mqlb/oVXGLO1uwACXBSgECt/HQz3SmuvUojpjQjDPOGmfmmwf9IzNcyUarVurNnBOiisdLyF2iEULhsINqJYA/fVv4k3rWEgGralLRZGTBztY1bmSXXvdnHigVZhaiHNHn21xPoybQv9qGg+bKXdfYTJycGK/F/HH+EAoS7x966NorUYk0H0bl1pOHTAHZKWK8UAHCfvNTs8Jxf2pcW86BLRCsAjuNUR/F34STZF0ulEyT+YmKeRb69LoFl0xVjOVwPhdke0Q70BdigbmBqoCfEqIOutF1N+wMzL2btAG9r66s8U0qox4pj1QxqOeq4XMRmKYq5+yKYClzSRl1pK49ExJe+GGdGu4qREpg80R8wqlbZiiEDHUbdc/ru7AFu6o5cu4awpCIw52+3JFrsCpRqwRIszd6jwMPGmPaZi/1TgQDOKYGfFdooIuo4zAF4WH/3n/XEiXqWHoYX03jCkgrkReJCNlCoCQ0L69Se5zkiUmq9yPScMXohXJGX5m1cCVgmNMRaRjjyuWUFitDmmuBD3lZS6/ABxJ6uHfA4GqBC98TKTHj5zAETg+zs91y/IFFstzkGsTpsIMCqCP2LF63EiQ7tmRvFG5bv6fG33I7JSlcKc2oUfNFvDUvDnX9YCOl4y29scHdUL/cFoI4Onhxu29iHs1JJjnAdDTikKmObFJUFF4Jofy6dbbU17OEPggbbv6wH/AOVI8TD6J/+HmgyENbncwtD6jERKKI3VGTWNyGhhFLHGHPGOiBDHTyrdqyPBkVeMjZRn4+bDyQT5LBmKXDCiieqpIIymwC6D5ki9NQYQZlL8dRACu2QZvcHKE5yD71E/Gz2rDoTN5Qjw64aM+DQCB0atEcmT0KTsgWbD7NhmPIM8+zQ1A3Y5bbJ8PXApp7NFt25FGF4ShaG1dq/fqIMw8vCj/5QU49kE/oTT95k84YnCRsBlvz4zVzrTlT7EpmhujkdDPjO7IDd2FIcbzttIhzolEelANAYH/JB/cA+h+Lwl+/zh8qz5lnPQbiT1VXZ3aHBedzbCqSpo7HNJjAqmepw6YTKBPP4PrtxD9Tonn1EMGRETwpus2WriHj0JHCi7tIN2HSTjCIRrHBPMjgLU1W1tJyneSIICtBEkCbkLFUGsS+b2Q6vj0tBNxg7DsveYtAc+g3UcbgfUq4y/FctjOKw+5wuNX78y3hv14y0wb6xNraDcgZ/TA+wozpmmHYh8ETW4NGMu8AUj2YPh5o/fX9d2gqFz7uEeZVgtBEnVZkrWKV0SZT4WqtEzdfHVozV6lrBkswmU6D4soknQFCE20lWmCOoR9Sq2voss= 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)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xSZlO+GJEtSLACwhYGMGCz7MoXj3QTMbVjCN6j63mvht+RFrn88CTWpOG1jCqxBV8VN2+Bj3u7uAD6R9yKC7c0bdH1sYNkKeCG42LdwQotQboYeO/uFDOyCM1e9j8DGfYYKHc5JVsX2qtiItIyUZa5EwX1bTaukP7NipdobmWgUnGTKPziPcvOSXmFak/uUYqTjyaRr+iRK+AiDK97OrXOFR6m2+SWYVxtCQ7L3K1ugEM/gArJ7W4mM6ZoBYGwRaeJDsBEk/eaAlekfcgXWpEX3cnjbn+mBlyeePsqvFlDeiROF/C5mT0sn4DXRkvtQWkhyqXjD2iSKwFyRXwwUQBfB1m06zY1EfZkZ4+3FwiMrrFU0ZetHEoJSEEAuQIyj0J8SirYOXhzEriA9oeZAqs7oRWKsE36BtIiw2SJSg+GHi0N7Xpw4ippKrjze1H3FwRnO9KuLbJnsGAKkU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AcSYXZk3oY5AFwWQgqD2gVn03GTz4t9gE2xdjZ7R6RdtFiFK0c0g+7gLqhC2SWsxZ1t+cBcSjrzfGyIUwisvAiEkff6A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: UcnqMcJRDJnYjk+vq0fnHfY8/qRUdx9LCqi91gp3rADTA0WlsA5+Dpj8fw3P8Bn3O1fOLd4usNNiseN/+xnTiWZHi+ttMOViRgxHZlCwM0F6b961WqwhC9O1C8umkjR2kNIUzr+VzILCEQl/qrA1ISDurEXTmIypxPkIMiIPEFaP52gBpAJlQOMvs0Wdz1SSNwkjS2r1FTensDlsgqjr2WiRVBV4UuLsW3Ai1NVoU603QNJ8vSeuzbcYmO/Pm9G9AIohCS7Afte57ZYjF05Wqj/kXbPWTQCaoel4hKj6dQE0X49/UOhhgsuSn1Nz/PI5r1u9QjZT8ajKgeuQnr2CG3zZi+qO4ZixDVRy9NMiT02Sexp8bZgq7VPA62zRGmS4j/gZYx4W9rfcsHBM+lWHJM2zWAx5UwLKDUDBDkkQDOen89Cra1wiWOMDkYHR5uHUWKZK2DWvPuI4mOPw2AtJ1lVh1mWQDK4HAqFC7Ny6Cppy5xdVxlbSQ6eRohiepA5Gnpr8JkEAXCDwrZikYgYipo0/ZYiPnpJRnkaT2pIwHzJumAteBFPReJkvFv8QxWX/GOf0xrPdtAbop4N+HvtwKT1OxVX0ut3QeL/WpX5PF4mPNZJEu9+lHz5UGCLSheXv X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84ffd21a-b9be-48ba-5f38-08dcfca7600b X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:04:58.2289 (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: FFaM9SfUfp143A4iWLHIc8HmlRE2DyS7ZxElab+FLwLRw8L0U9NOXsR0BYxevOJo6fHfF1B9+Cn7oeiSzCQKzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707500-TgJ1FTVn3Qh4 X-MDID-O: eu1;ams;1730707500;TgJ1FTVn3Qh4;;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 --- 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 Mon Nov 4 08:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861015 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 492E8198E81 for ; Mon, 4 Nov 2024 08:05:08 +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=1730707510; cv=fail; b=pm0PAUNWd3OemHdN/uos8Q7uFlEys9cFqPIBjrvxv04PGjX6k/7NL+6pQ8bLZaG7wFGs1gR1FdaJ8shH0nWDS7R3OdBecGsJQQI2+fzcf+Zr0b34r3IbsydpT9ZZMjR05p4rq/OfYiiOwcEylCwn1kOohDTKXl2E0WdG+TwfHu0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707510; c=relaxed/simple; bh=vVrFD+mYj8KaLwn71l4y1PgIZG/YTtZWZ4x8ILga3K4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gwEQDUPo/SggrzP+N8knlVB3PqFhW6146NrIjkTWtr1b0TNAHrqoVL4sGV9sIQzatWcQs82pNQ5e34Um6ZRGcgFuxMxb0EGwFp4rwMLA5GDZ04s7zl2UREZhrY9+HJI/Z4Vi5vZVsNmeDBb5rTiMYFsaytE5brqvaXXqFZb87H4= 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=ZYu8t/su; 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="ZYu8t/su" X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2168.outbound.protection.outlook.com [104.47.17.168]) (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 8EB1E200059; Mon, 4 Nov 2024 08:05:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AvBJA03RaKe5KIx7dAmLc7JrjKzkHUB/cG5K1qyFIHPjwinyMEAs5d60yYE/BewKc+ktLnvKxHcc+AiL7zhbQ5GP+xY6XKeaX8WiCGwacks1ENScSGlOxnPq75QOEy+nN6pGxFPR0bhtfqI897vTQ5dlmCa1Gpy/GWpaP+GqnxFAqpVSTxobrOzdixY6LtZNgDqxH64grRXgcDvQEw6EolTJ3l6jKV82DFVM7g2fmBx+oQ/Bx+sUyq77T0/R8Es5WfiDA84SnPNKfxp65mCe8cXYZftHgVt8cPMcGrX4NcwO4EYSRo77/V8RTEUQUTXEPCrG7ISKfeFfB5JKoMYBIw== 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=ZbgFucxQvEkfPX3c4BS+jKyeG6S9cBJLgvhxhFnned4=; b=v5o+56qKYgQrYiQK4liwovnCggOQkztvfBDbYKJCgHpmCgBcAEGHptlSovRKxU27WapgOMwfdWlE6+/8HepSfYL41QcDXPsuyFtKAg7M4a3LCAujn3Pd2nMX0Q8Jzj55MpJDHqTHtDuhr1XJXuzGXR/2WQro9Fry5QHMMAOAKsetYjXWlYeJA7XMT1WcLJEmGpffQtj9RuVrVUMhfiMVbOzYzKP8AEcBmtm7aNdHptB6a7szOjW8HT88hQO3VXkUI+VsD5iEQqRwgZoxPpKvGMmQC0b1WzlftVBm7UulP91mTUriEnzNBpsTk9at6Z2Z7eGDBtdV7mlWSTWexouuag== 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=ZbgFucxQvEkfPX3c4BS+jKyeG6S9cBJLgvhxhFnned4=; b=ZYu8t/su4CCOxg5ZzwNaisHqHPNsnB42xZHm70NiNYq61okIrzSoV1KZKLL1ZMZwqthFrrtPSAFAXiyhIBpQSt6kdyhZ8QXt8dg/4aUdaYnDJ0vCrFpMxK0yryL0UfL1MeukjWDPDStmOdZ9XC1KqgSFlJjn7kUFyk6wAhKdX2c= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:04:59 +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.8114.028; Mon, 4 Nov 2024 08:04:59 +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 v8 4/6] neighbour: Convert iteration to use hlist+macro Date: Mon, 4 Nov 2024 08:04:32 +0000 Message-ID: <20241104080437.103-5-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: ce8a3e5d-5af4-4d71-8242-08dcfca7609d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: h3MEMcyCIqHyZRFikKudxShbJ8lJUf264ooy73vsOF//N9fAnGJHmropQXKLKTQs3bjsHk5jZ3d2jRqiXgM8VFRkoSylHlByVnXOF0MEVX5TcaZ/wT9H2YoLE/9YWfN0gl2mDcILsRuoHoIMueZLE+wdteVWPmh2L3Eduwmi2oXZek8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LJFlULA8MFRiGR4S7hymZVlRFR4zZsuGZ+wfb5pl/6vjiSLME0cWBwC2/xu8MM2j2D/IqRmjqlkiZFfd/R9pB5fiGwxMIRxHd3qj5urGwtDx5sKfg3mVarbI8= 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)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j45KtvoJ1UKZVP5+3dUxzWwxW42XXbsfUiqPzzmG7O6R0A4Zbt459ogCIdqLMgTKu1GZtqNFscOs1ZBVyWcq09qilL8AqTC1hFjcx+HxLbX2BjHDb7JwpjHF3BN/PYLW1lFeFnrFrwgz/rIshtjrVqUrWZMT90JLEmBSiVAp/KYMUcO+CjOnJxyMTGbQbQdp3Ny+pIt1B+5N8x3kF2YVCxbjBxVTuWtsJ7E1UxYVun8UWXmevajVu+C/xVa2vcDAURC7Gc2FEvSBz+ETnfshH24aGMxZUcbQkSoHGAXljp4g/QFV8+r2OZYVlPkVXJ54/Ej/L7OwzNLxap7jup83FlOvvPew5xNq6IQ1SXulX0GKW0OpOlwhyS7sl5RTCwICHchk5b3iKKvDS3tkFCADx3hYYkbOsKlzhQMFpdUEZ8xP08yKQCQ2z0DNlqwsfWyV1JOE857uqwi6LYD4++7retqS0hikFy2+jJhcBXac5NeoRtKsANkwgYf2RpwB5v3zqecRJnAPAZhWnZZwdnjK74Q6uer4XbT3PCdBLwGGI/gi/0IqYrii7Rsa0v4qTOfUVTZkeCa2VAMWYEBePpZC+M4nyjMMWRaYBhx4yI+R8NpSGztvarhJgV9sOcjGjKtlnNYsZhEFLDxZpLMfW95zWFP/2tdLBnThOYEAgxmg9V2QV+vLdXWNdIzYn21fpOYbSRLQAhl4t5Htt/gv42949m/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ZYVMW1DJ3k8dUO2VpwnG7wllae8XmdDmFrz+1F03xdyrOieoIweG7W8xEojh/snRpYj4DaukTAanmO6ODkhQUDRUCgJsyDq0SKCAUKRMyD0nulkQHfGY1WrZu4pcSdn/aXKgAUcp2qBVQivG0WUvwVYJ1NKZMVHlp4vwKmc3y/3qhGpeGiVa+NzGGZkncsmjAZfxteALaWFXu+VBHg3KhAbfS/2eVsfXhqbv/6F7elC8XMhz8+n7QhFa4t5bSbuYJ633KCOhjG8YIjY73j/u02kst6mz3ZEVxkyuqijgIiaGE69NS2D1fE4T/WJxxPChUTA2BbT8H0URhA/k6n6OULwE898z5oh6eEaD1RWd+22X9bkM4q40P6lHPN2IrUe73TpOxc/C3tkly/YPKseOntqZUefcusf0LjY6MtWdpdt/A2DyRut5VhPIvmSY+xql+oWoI9zSbB1+TwRDhx4+m31/upQXVVkbCj3WozW+B1ziTbrZxNBtfesfnrxqYv45h0EwPTBiFPMrX X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce8a3e5d-5af4-4d71-8242-08dcfca7609d X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:04:59.1943 (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: v/TMbZ/1lm8b2AW8Cy05t4km2Ic0hJaf3M4Po50OzGBlMdmYXRU72si4rlAJ8sZCLNq5w7zOzXFyetHiPkNgWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707501-bVQLl_P179bN X-MDID-O: eu1;ams;1730707501;bVQLl_P179bN;;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 --- 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 69aaacd1419f..68b1970d9045 100644 --- a/include/net/neighbour.h +++ b/include/net/neighbour.h @@ -309,12 +309,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(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..f7119380d983 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(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 Mon Nov 4 08:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861017 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 EDFEB1AAE2E for ; Mon, 4 Nov 2024 08:05:11 +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=1730707513; cv=fail; b=O07ra0mrPLs9W683W0WFCHSUV0mFQhhaY4yn1BkCFwAwzlHKJyhhCBkscnX9pb52M4kBLDCAydz1jf9C/3SqgWejOU3qQRAahxe7KluoSYJqKTdN4fY9cNlEB9DX28ggcf1jpfNiAMPh6cE8q+jKSSQzb/bCnlfKlq9jsvK/Q/M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707513; c=relaxed/simple; bh=3tGlXzP8AknKUxI6+OusgQ77cEMUNblclCtU+i0BzMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Z0B2osjP9Mf/KNNoXG7ZRwON8kETqhrJgXEY8QY/OITqWIiGlFt2vAXJppJ10CR2XbPT1eRIrqyUpAVkLpQILMKLLLUa+KxPHkgF27G/BsrfFP9aabqg+gWJUQJrDpx0FHiRmIo879DRwW788fFXmjxPrIIA84TlZ0EkWavVhSE= 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=oC7tIOIv; 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="oC7tIOIv" Received: from dispatch1-eu1.ppe-hosted.com (ip6-localhost [127.0.0.1]) by dispatch1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 7B20F8106A for ; Mon, 4 Nov 2024 08:05:10 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2176.outbound.protection.outlook.com [104.47.17.176]) (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 9F996480060; Mon, 4 Nov 2024 08:05:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=BAsJXHGADd81V9PvhAwhrJAPSYQGk13aYl9ff2HDHo6+0Dc3k/V1RVHJigkJPowy1FABIPRJRmwrR6VDOIUhvW+aKsRjKMTFO3t9z+XEIUJDFc6zZ0+fvzpg9Htrhm9k95lUZR40c1RhU8x3DdQK6qXb8mi+Sn26JfJGv3zuImexZKtl4C4bHK+meZfjqiip9iZ4K4sgKOJxl8v3CGFb6R99M145FuQEo3GqtUOgOtKaiaJpsvw+nHseiw4fxn4kS8OXuYOrxgQiKxTbDhUfl6e8h8JVJsV17mtEgEvEbxpYoOXbj8KtLnWWLkqD4d9xC3YGBv36NlaivSJko2WpKg== 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=0R/gdCQ4BA0TNUb+9Z/fotfYm04ri4mNE+iAoddXxZ0=; b=YUm2z2MegOuPguMXXqrWSDXM0BRW/m/HhupkfTsaQ0HaQbfgyOrMqyEbmANXhJYzZu4Hl4gYzcE/xPRjs4CA6wkup8pLZS3Sfg+vb8WnHpccq+VkDOvnZKU7zeqCJNAahOJ5Kb+8hbOuq+H38nLct/LrdYWMx4Y57AxA3whcWGksOOaWOZzrPZvzUjkTBGmm4NaxaGG+O8b+gOm+Czz7aAXdOSQj+NXICzpPHHoxPEIjPsLETrw7d8gVhGNChh2pyXP4/rSTNeef8WFRpv0ou40dvHnLN6cOJS14iigICKWroB5p1zu1v5rcUOGDYMfrt8IbyY+j37zCrMUnrRgeCw== 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=0R/gdCQ4BA0TNUb+9Z/fotfYm04ri4mNE+iAoddXxZ0=; b=oC7tIOIvY0okSBY2v6lXmIEhQRVtm9YFfgtM8SSvxBstIXpc3cY/YlV1iTUcmuclfHYUspKzhI1/sv6wwvNOmegffECBNzB4Ghmh42HdU/GtqA356YP7LuU02f95qJ0aKZ0/eHV2pc6q6Tt6vp5/E1OYTYLAaE33BbUtDY3UZjs= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:05:00 +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.8114.028; Mon, 4 Nov 2024 08:05:00 +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 v8 5/6] neighbour: Remove bare neighbour::next pointer Date: Mon, 4 Nov 2024 08:04:33 +0000 Message-ID: <20241104080437.103-6-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: 0da494a8-edf0-4764-c3ae-08dcfca7612e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: QjiJZ8QJvOdgsIHSRJIe9+qn4sWkNTGoyBYtks9osO0S6Blvqqzi9Ik3ZZknJbHkp6vNUi76i+wisKgWWocnt/CT2rrgxVeIjknkqSoskZIJNaW2iEfn1xqWSfDJQgHBJt6LC8XIMJr0aBFDdJMvFtC6OAskToUmZH3rk4iBs6fmWHlT0NVDn6aDg9sG8aQvQAZcxUwg6LPjXQHQnrlvtIRMNJRBZv5jguds0KPQVLinx7T0hjPpKkbUdLHTYkCVlY5gFimHL5W6Ck+ms5TV+KzLfc564dSWzque1hqBJ8GjCKAEcHVBBpoTdY5SHCyKmQNtJ5NTGjzkPspzEzRh6dgm4qbnzNg9ykNBxmfunljlY4yFKrLYrQmvzjAqN071EyXhHDFV9QHnGNZbbiKG2wtoBsQkKnBq0VZIiJzkTXWuMVRFzqOK1RKvn552eqelCPl56l7VtX1QhkPbFLEyxMcZDNTj88ZaYGT7qqyjTSw/auemc4bDKDI6QHvkmKnyGQ1sQ3DHvyyZkmbR82gAbb0asSYBMPXgUsYLQxZ2ZKGDsHMxKJBoCRFDFUISNJdpN+Cfgo8YN7SNJiwborEJrGWL0fSYB/+uDe1c9Y0ZQ25/nqnrg3wFJSgth77pcvgP7kUF1ThT0sCrvhOhJLTGs208YZxNobJLYV3PyuQsy2XQlXsTDs89T+QEg6FeL/XpR8kOg6pzGi4osy+5jkMF4C1tUjAZl5ZM1yjVTe003l0Lu2CcmTjB5GOQQwQdVjXg54VleLeujibDO/d1zwL6f2o5YM/ta8PSmsHQA7XhlbzGFOVCllRaPo50/lzQIN7lff4rQZ9gKZuGX8f0Zi3G1HZrTTXBOWybrOJNRkssmpfaG4hlI3WLDF5jOYOF7zB0nvu27uMqBOWcri62mOE7xyOA61XyR0KI/U82WHbEZ7Dgx1KTyM+EAoYMqktsEaOlpv4nRoq6eN0Xn+6kHMxVnyMh/CyyQkWgxd3qMsVhuOJUc3QV0AmtNF1Q5uk7VGoGfgVIN0bp1so0lf6mlT8KC0seWbR/Uv4aF06ilGIUwLEUKUyN6RBIVrNH5WOqlroVGJMtjZVw5NH6OH8i6Q/6CUAoWPc/V0maWtsNksNJBYBBcJCmpn1IgIErf0zBGAHTJccTT5/iIvF6XxRjX+qU05C8KlFik3+r4peIfmHCuXxHV5OXuA2+LAtRQPmrLQ/haan3LtVsOUNMu+y/LQtGnM9jgwAZ0J75sewSDa/NGgCzyb213V0/14FfY+NGYiWWrIUtipqMdgtzo/K7hcfqxzRCsug9hrfoJSL+deiWMVlwn0dEsFj/FjPgpMfPn/2jZp2wwOzu9q2YmHKhZuCG46GLymKptQt7SLoLKaN0MOY= 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)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +f4pGIc81ZPw1GIrZEkY7q3HvZsIJfSkaxWwrvjPo4B43r9ZcIJQGhHtgi2CnhPEzaEYaamepN+DyHzdPWIanF9aPB4VmggwNfhXrrKb1lTEZbfWsHncemG1/TY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WzkaamGiXGVv9pcaSG5W+Mq7ghx9DiLhwRO2Ts4G1MjBje2tYV8j4IYruVIFaOdOMy X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0da494a8-edf0-4764-c3ae-08dcfca7612e X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:05:00.1706 (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: aRJq16c181h3PQgPle1//WijA6j67kJBcWnsj+mfWM+U5wq66E+9tMKlBa7uxZDDzbLUcuD3HN+oehTIFSWwXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707502-783C_4kWdLEp X-MDID-O: eu1;ams;1730707502;783C_4kWdLEp;;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 --- 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 68b1970d9045..0244fbd22a1f 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]; @@ -352,7 +350,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 f7119380d983..a379b80a22c5 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 Mon Nov 4 08:04:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13861018 X-Patchwork-Delegate: kuba@kernel.org Received: from dispatch1-eu1.ppe-hosted.com (dispatch1-eu1.ppe-hosted.com [185.132.181.7]) (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 6FDCB19D07C for ; Mon, 4 Nov 2024 08:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=185.132.181.7 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707519; cv=fail; b=HzzHr6chAUtvq7Z6eo0/1mizwXnjgEKW4sY0YMXNv0UmIQPP+ycyR8hDnKIFMPeUVqOrAWgSt5P3Us9nbIYS4+3nRIJ4nAuJXAw9hOcbKjsZH/NUhWYAqZxbtJtu8sJaIO9oFU96n+284O4XIz4bg5LFTBaHG8E+/2Z33bXE4Bk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730707519; c=relaxed/simple; bh=ZHqYrq/ylBS/wdiLLl4FqAPc2N74jNahCdb8pqEyB1M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=bfywpuaY2mArQuNg00wWauEEZBm0xStRvXOIDMnzZ015ENmLnh1HOhkRe8Lczp59GA13DP5qXHlPiVzT27kwbBTu+jsmCMaquE7hS/lIfz2ebL2SIG15FtLAOdh2PffZ+d62eWufS7UXaVaSKGBCiapOyNXT5Aqobj/gOojWApg= 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=K1/1Kcg5; arc=fail smtp.client-ip=185.132.181.7 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="K1/1Kcg5" Received: from dispatch1-eu1.ppe-hosted.com (ip6-localhost [127.0.0.1]) by dispatch1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTP id 93161341213 for ; Mon, 4 Nov 2024 08:05:10 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) (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 943F5C005B; Mon, 4 Nov 2024 08:05:02 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nM0Vq2JYYpChcokmdOgG7OC+hKboVqM3arpjJ8aAlChDRarLHWN9kAT8YryHe8y2MK4AuYcgCmLPUvdnsk+lqjozAw40kLxoIWnC/g7moC6RUc9c1gk1fw6LPgMGioOcXepJl3SjFhUMw24+jT/O0nktLGZ0wUSasewb3C0cx6sHPx5pcwmMfo5Q5KHh0+MsHn4m0k1Rl8wi4wmIs+2UYMPyfoSEg0WqclG8EmXnZPv3h94kaZJ850mWy+3U0wx6eI9VrEYOpmQoeDqnTvyM3ImviOzXLuPTZ//exAReK1ciFmLu9XLkP7rKqFWqeyQIlfVGe7dP1J5WYpBpX1t18w== 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=OpycxAzXwTYk3lcYeL9ldk5kHhn5p+dwhvL8dP72kDs=; b=d4cPxO/OjB0fsaFlmf7MrMX7rztOubXviqqBiX3Go9dBiGY3rCf31JSylNWQUZB7ns+ZzcgrIyVJNjW8LVKFH4TGrCkRss/tFghHL4xP39lCDqO27X/aW7acJ1R3AB7HG1ItbCuGTZmE0lk3eQTkUNzsn/+pXvLnPSvSk/fW3lJ6FGQ7SZFtkT0ZmQYAbsOgc7RybzEu/8R/yzStZaCKvP73AeEQyxQbFnuCVUfEeoWPUy2ce9WG5SIZRDFKrBBFcFloHR+ByoWRJFhlcjjFcqipi5jmgZ8+MMlJGYwg8heBLpDxW/98QKZRW2kBpmBmUpFq55dx0OXDraICzUTpeA== 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=OpycxAzXwTYk3lcYeL9ldk5kHhn5p+dwhvL8dP72kDs=; b=K1/1Kcg5qy1Y8d2l136Os5pNl+05yfj/WHNs1jjp0yRNzd5B9snyII5pVuGHcWVi66H2uzlByM1TCMEUFpkJvzblZBa8UGcG8Zjpg4dk06JCWYpMzMHMoP9pQvon7zZSllkt98sWGWl/YeO4y5PWS53Gx1rz+yNjoEfDqtYKTwk= 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 AM8PR08MB5553.eurprd08.prod.outlook.com (2603:10a6:20b:1da::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.30; Mon, 4 Nov 2024 08:05:01 +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.8114.028; Mon, 4 Nov 2024 08:05:01 +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 v8 6/6] neighbour: Create netdev->neighbour association Date: Mon, 4 Nov 2024 08:04:34 +0000 Message-ID: <20241104080437.103-7-gnaaman@drivenets.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104080437.103-1-gnaaman@drivenets.com> References: <20241104080437.103-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO4P123CA0206.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a5::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_|AM8PR08MB5553:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e0ddf24-3d07-4150-b14f-08dcfca761bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|52116014|38350700014; X-Microsoft-Antispam-Message-Info: i/7gdRMliAi8UrlUyhWFPNh5GmurVnv0p5T1IA1g8kQPCNp4q0CibIywywCKcVHIqFseeo9SMeos8kyN7vwH0gh4sKIfc1nNm8cjWfQzjq722ULjpwGjkoyWyK1PvwJkFYO5oMDzLzTp6oBIic+hVH8LbG7F9pKdVsdo8KrUkClnaKquEXPs2YCS3tC3ObPwYc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EBagFfGQCkstLZmmzz2x9lpA86+QFVgkeYTZolKyuAUrTwfEYIQZCQX6gLwCDE4oT+5Ah/se+Y5vgC2aY2Mmk= 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)(1800799024)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2xOTv7h43CtNQHatC6n03QN4oa5s/cxYrWkFoKmvOI+erI8XsQ5OFpx67OBbbONGy0/MaBOni878P6Bq7fPOd/NjGb6E1ofvwUkHWp2Ee64YslhxpXXyMvSRt61NWZle95iekw8MrQWPyWOIURvuqmlvHaC44YQWLqqPxufj53i1FrG0LuoHNaac8Z2QKX+VNSffxp9cL2kXRyVxE2PwWiWm782tBvD+08FHwnjJSHnMlK5vndWekHrezLwhl/h4mDwPId+HWsB9fNvjPrDs2mdddfDcmc5HDDBhK88YTzQseKGxOEiPj+1Lqa77ax3hRZnt94fJghkGP7Q7l7ueIpByYpaAiGO5GA1q9TB3jOgOsMlZkRcyupPQM9NLhlUeY6Cp6TavP6dsJ2xA1SK0M6SsfzZjpdhTWO48XPCh8XHC+AyQowQdB0v/VrvFQIMcVYjGukz3qprBDH0WmtwgqZh/Gu0wssxjFxdCFrn1N/lnP+UaqBpHSJAXlZajB0orsDmhbNF/CdZYjXJ/FRKBw7XTvX9THWw0qJfXqC/IP7CyZWRzAhuV3IOM7mL/3FGlrJmtfWdjPqVc51yNpZTXj8dHN1ldJhp8xgYkdRlSWJD6pYPEEZglvxGFfV7ZWlztXIYZNlTzaaNIWf6y6TbjzEnd8wIgklCC3omAtiQ/Bkpi/R0Bhlu5amhy6yisgvSrfEa/7QJDRyNkvrVzdx+ifNtQI9K139tKPLiNypEWRYqcWM2w26MLNtefw2RAyZWUy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QJdeQVcFFTigiHQrQgosVi6dZ7V9zyibDFpqzOQvfzFZ5Ldna1x2ust1ed8VWsr9+E8phLyN6Q4uPAb7ncvTj+HnJX5sBjdqDtYjkQoZB+cHGpFz1B/04sTCV+5HQNdz/xvgDHrGgfc68eGDZzfSVJuWLcRjuVTmjSj1Dp/7uaS+o/hqvMyg15hxMc/R2kORFvhvNBAx+3pxQJnEqbvjClR8HaoEBveAraGe7ecaUwbNbDuJiGIAcZglFGAJ6lNHP2uGaumEyeQjXQ46dklbZkMda1YsAQIh4sYY6NsLIjLoCBfsPajznMqIggS/hsV/YY4mvpjGZirjEtVfhuSoTjoDtoKq02c91pedhm8ermh6Pw77tn/U10oGrLvMEPgEGC89CLmwFZXDRH5TM2/6298gKDXb9iqV6k1jSCAk90wgraqGGC2zycuKs/M3WtvEy1F6A1tOR6w55ijiVTSFAjJeykO3MXQR5IotlUfi1K1ux X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e0ddf24-3d07-4150-b14f-08dcfca761bd X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2024 08:05:01.0902 (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: QRjygNqop6t2kdSNFOwAORH6fHC53CEF+3M9aJBER4rUzr3lPwceUaTUL341EWYDVJs1L7OJIEPe0VluF21tPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5553 X-MDID: 1730707503-ay1-1s-gy4fc X-MDID-O: eu1;fra;1730707503;ay1-1s-gy4fc;;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 --- .../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 0244fbd22a1f..bb345ce8bbf8 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 a379b80a22c5..6135ae2001d6 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);