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/HQz3SmuvUojpjQjDPOGmfmmwf9IzNcyUarVurNnBOiisdLyF2iEULhsINqJ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gfUq4y/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+GHi0N7Xpw4ippKrjze1H3FwRnO9KuLbJnsGAKkUaTxtGrhu87qNCorxTmgywwItzmVZkmijyk5X5DXECLVnNDQqSPLBQMzHu3VnRQ6VhcMUunHmCo/96P0uRSNQXCh8lIHhWfjvwpm98ZF1WYyhyOQJh1pQgMOb23YIzK9V9YsyJCSES7Pj7/wMjmXCvlT9tn5i/APk0Jb1zdO0BssxsTkgT98dOJj5Wey8i/YV+iwaedf11WTGTVzpSUJGKva80HOAPU/Sgw470YDDHG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3P8Bn3O1fOLd4usNNiseN/+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();