From patchwork Tue Oct 22 13:43:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Naaman X-Patchwork-Id: 13845722 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 EC3C519EEC7 for ; Tue, 22 Oct 2024 13:44:10 +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=1729604652; cv=fail; b=I8SqIyquWAjVlWqDeyScu9N4eT2JS8IINjnPhIDlb0yeKu2AslAXyOMZYpeHXcHHxkpdsdN36hs5MkBVDh6+83ul4DTMh6PiATqehHvG6m0HMBayV82slARcbKkpSDQ0cVl6DPaR9PJ44kCqZv7B7uMsLxEfPT5d4+vkE5T9d3I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729604652; c=relaxed/simple; bh=8obzbqWFluULiPWIcD2Ia5X94nIIJAO7gk8WhIbeMW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OnU0HDzjnaQwo4EpTF6clE6sMCe0niM7g90eDrtxyhYgE7iagBW5cb1FcUNri9K/YF4yYneu71Oiqpd4/JxC/7aF6IqA18I0Tw6r6EMaO622GS0GeWGd3wt87HkqNQZErSjl3P+Q3JO9jYtMTM5w9L1MEXBjpaURWKaoI7lriGc= 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=VxRhYkzo; 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="VxRhYkzo" 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 74EEA8189A for ; Tue, 22 Oct 2024 13:44:09 +0000 (UTC) X-Virus-Scanned: Proofpoint Essentials engine Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05lp2105.outbound.protection.outlook.com [104.47.18.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1-eu1.ppe-hosted.com (PPE Hosted ESMTP Server) with ESMTPS id D1D8D480061; Tue, 22 Oct 2024 13:44:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tFb7pomGdanQpVqru7X6btUka2bSkyAbqJGzOla/bWr6QSuB+VobiONwRSQ1LqHNP6qbxwF6euqNCr+80YEOiSiZNvX5ClGwExex/QgVoH3gg0eSTmJ8DB1tq/53ZPzPBR1zI4WhH/MaThReG3O+U9lgDGwPKtX0w3typPLzTuqChxPBf3FCGSrzSDXXl9j24bdAIeLd4YDOu6bEfD+M5mNFOUBeXajj15ra2kGptH6d9C0vaWrMMYrWVqLkdmqCc5WwyhqnkN1DBJtO28iG3iwI4GR47uhAwPGB5X5+z+UHLkGaLW4GVMsGnB3OywC9aLcFmbK9RoBwCz5JdhCmdQ== 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=NMuORxLc2CeQrv7llk+FMcVOzXT+Hz464psQ3Jf4gos=; b=O9ybjr86HOE6eqVvxorson8EosgljZzudOlRz56pDfsWda4oFmhYg3qlAe6TiaQEt63rm2WRxQ97XDb/rROBdb6CNRp/WJuhtxo9g+DyCaaqSZaf4G1jeO+1/IAlrKxjI5bjzFkkKz45r1/j02D3aQ0obEpuXj54pADYr1HJhv3bbPO1kZ6etZ6HsD0EhKqx4+MlbCtmvbS+EMD0mi/ja135zhNjR8vjrRZsFYP7woPdfxMH0TkSLjZ91/4P/PowZFD+O6xp0NE3HuPQtU+7FJasx39QL3ZajuA+bDf+ChYbSic0E3ylLsQqc9JB/Ul7Zkw7cqXU2BoXhWbdyCIuwQ== 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=NMuORxLc2CeQrv7llk+FMcVOzXT+Hz464psQ3Jf4gos=; b=VxRhYkzoUp+Y20qG/imEVFYrShrZgNfP3kv6/9xJI8ZlZfYd7UScTg4oKPzDWNOxrlpGiVWpZuB593XvuLMc0LvgWffKM3YAPVxbKR0MT4b8J3S04YXUUoYLBopfmc3lRJmUx5fArmr+5OOBzbYChXclHfn/Iw34ZOub9yeClMU= 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 GV2PR08MB9928.eurprd08.prod.outlook.com (2603:10a6:150:be::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 13:43:55 +0000 Received: from DB8PR08MB5388.eurprd08.prod.outlook.com ([fe80::29dd:6773:4977:dc4e]) by DB8PR08MB5388.eurprd08.prod.outlook.com ([fe80::29dd:6773:4977:dc4e%5]) with mapi id 15.20.8069.027; Tue, 22 Oct 2024 13:43:55 +0000 From: Gilad Naaman To: netdev , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Gilad Naaman , Kuniyuki Iwashima Subject: [PATCH net-next v7 3/6] neighbour: Convert seq_file functions to use hlist Date: Tue, 22 Oct 2024 13:43:38 +0000 Message-ID: <20241022134343.3354111-4-gnaaman@drivenets.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241022134343.3354111-1-gnaaman@drivenets.com> References: <20241022134343.3354111-1-gnaaman@drivenets.com> X-ClientProxiedBy: LO2P265CA0192.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::36) 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_|GV2PR08MB9928:EE_ X-MS-Office365-Filtering-Correlation-Id: 711e122f-8dd3-4f33-8fe8-08dcf29f928a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: bH7lZNQV8fLxT79dRdArVpmufFsBREC3l2p9cY74N80MWRlOic5fnLdVxAD3fKss5iHuZ7ymjKaaGC+9TOuBKV2JCTVttzgiLDM5WIwkJUY1FLIkXCWj5n85kRex79TTTZnZbqRFZZNZ9+gIxX+Y8sg0PrHj6YakvC1K0r2zyNegKrENq819TtLup8Mrin2XPacM+x+/HXJvwpLadd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xzbgdtu0SFuDK/q2iuXLuZo6KAj2/bNizD5OhTWfO5ldaS0MWToCGhC3VeWAu+68IK60ga9A6v7fX81eyW4VjaBYzAsAGqUgI9bbE= 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)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p2bAvvZVDQ8r1VlX2IHJ410aQvskCu+yC8ziLCuV+6VQ545Aj5gnZazlWnbSVhw/dnh/jmSW3bWKlHa0Vwgj4lGXTeuycSKrg5L2ozXoaxR7tUZXOhmB/+5aPVPLrwjyTihPcNAoUMYx9rPWVGMYCsck2h7M3LOXLOmI2yt7foAp8MLlLRUehjNhB58XlDMYRRiSD9ZRI9VSKAdxBK1Eb9UPFScsL3BbhL3QAgtmNjHA687sHeluuKTjRygitGTe8n7dzH/ZXYyyEd9sTS6iBEpmA6elDOqOJrUEwy7GLqLq9YDEzD4R03qMwo74SQWZiSP8tetC8MAIT+00joPhCz5d9fc2WzX+38gOqcQvQZMwaFe4I7LNPl1n3CF6/bKib3u601dYyxMGAfFR+DwzN3fxWz4vdcamKf7VyR5YI5N/zoKu06Vuba3TrlM/VXIx4dZcmfhVALTWz5EHqvAfehd1A62Aee1/h66IHR/jJLP4NusSCaihvz0sG2lUG57K6BJtRd49g/gXCHsSmBp11OBFkH9lbPDzgqdPIMIXyDCS5JLs5XvrVT6jTwwrFrboTTwzKgFGP9kwBNRiamVV3RLq08YP7IA+98drX4I4yILchhux3eSXYrzMUDMfIiEiZG7yJbh1YBP081uFJ/ZPUDhpXsxMx4RHzKDdKWI0KNBm/5kgyxijl7wJ3l0bTjN/gCDIIiO/TFVSpF21Yb4pwvS6SvoBWwTxfmRcUjSSxtdfEsYcC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uoHpKRtQG4noZ/MMKLctXklwcOZAfV2ke4fuZ0hqQrirmTxO/PC+3zVmPuqNdDUIaUPHDXmd12XvpdTtxBZbgwkaJGe9DLT4iizeu0pqzmWsLnK7X6QZsNqTixZZMoq1rtMdFbcc2Qx3sbDcAHpzdWix+7Pq5nWbK0QR4RNQpzwlNJEArkr1qERLiO+DcNKFTuOES5YvSGDXF3DWbRZ/fzfCkqF3AOuY3wlTOQ2dcLR9zbdD82sXqGcBnqlwbSXnuSQG9U3FPKQE+iEoGbXjxlXdQj1vkn9GWDBu6R4bA0nUJbVB4JZyh3DxfHfmDJeNHzrYMtEIUt2jZtbyk9KXSrNSc+dMAVfL62BCjUStTD4IMiRoeEaV2y+IZxq9FS3txBIE9Xhb7PTGakZRRAzMl44Bee6E20lmj3OnMhh7EokisMD2YFyfumwkITzmlHToIienkJkPXSIQfw3bPNt7K9UMAIw/QFw3hwhea8l X-OriginatorOrg: drivenets.com X-MS-Exchange-CrossTenant-Network-Message-Id: 711e122f-8dd3-4f33-8fe8-08dcf29f928a X-MS-Exchange-CrossTenant-AuthSource: DB8PR08MB5388.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 13:43:55.3250 (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: yCxjwq1L99v4Bz0qDpTDo0qQMKPTvXwtxe5NKqG/QuEfb2g0vyd4HtQFvhLNKeg0Y7IHqsqrOXjoHqPash9cLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9928 X-MDID: 1729604641-uYmGoQ50e_iR X-MDID-O: eu1;ams;1729604641;uYmGoQ50e_iR;;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 --- 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 7df4cfc0ac9a..80bb1eef7edf 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -3226,43 +3226,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, @@ -3270,46 +3280,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; } @@ -3412,7 +3404,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();