From patchwork Mon Dec 9 10:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13899236 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) (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 03A102165E4 for ; Mon, 9 Dec 2024 10:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738873; cv=none; b=gCo3x9SgNdcPIsxCx0EP/KljVr641DWDgrPpgWnvP2DTIT7RpaT9SSq31gXYpHA81xh2sXacu6X0ujyKBIvsSIbON7V5Aqvic7gAR4L6WfDByy3FdDtHqIU5uF3PxuNN1WLOZlJ9+bC++Se65IOEnQytE29Rzzj9/tj9NpS6MrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738873; c=relaxed/simple; bh=8wjfXbBusMgIJ/ZbkgD/nmQt9LQsdPXnhRkNqSxF/a8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ihJmpzpa2FAWoNY2rahsXDfBVrluuRn/eZUgwE4qqbXABfpm+6De+ehR+2ko7XtkXY8ColGdYmYhNt0GZ11Z6jtvJ8bP0P5JlIdLs58pTOsr1t9oS+Ran49htaB0CN2880hrJfJgv7ueK83Ea41o4Sw1uXNBWR75DgtZ2jcEzfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4NsMzeNS; arc=none smtp.client-ip=209.85.160.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4NsMzeNS" Received: by mail-qt1-f201.google.com with SMTP id d75a77b69052e-466abc6e8f6so3692191cf.2 for ; Mon, 09 Dec 2024 02:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733738871; x=1734343671; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sCQefQI9mRGgRlujJ/oYfPZxHalY0bDXC3atgnHWslI=; b=4NsMzeNSXxLPTsj44+mrnCz2yC7jjKCzYZX1vdIMXFWGdbi+uL5nkDpBILboQ8ag/Z 8APW7KqTvcIlRtTjXJ9RhxZHsA4aqNvs62NESyJeYD7WZcM8VRgAtyFjoGnqAl6UfyZ1 Xw+6YExChm8WnZlmwQuGPvPeABKASPV7WvmtjuZxU41mbdtjsT0cGVAIuWf9/DfaKsDR si1xWseVsoF9x5ojpSDyCN4Cq255AxVLy/1FBtq9+kArHrB9+IaCq2uiu9Nap+9h1lpn SYtiX9wyUF7gNitO7olnejtMfHulPzzKUTJlu4N4psqpDmfjIWieheXnGFmDdroADZAs j/TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733738871; x=1734343671; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sCQefQI9mRGgRlujJ/oYfPZxHalY0bDXC3atgnHWslI=; b=OlZ96mrapkPLJKgN1paThcVpnDU+bN1UfxAFii3TSabZEqbYjtjfe/V1YYBEuUQCaZ xUfZKXJBvF9P2MTT8XFA3nIaK99hsp+otbOUWZoR92j7pxXesWQkq6HDAyYJzWBW9LHI v03IrfmqWy3a+HG3HfbHaES5BYFoxxZOzqzfRrmHibtYfi7cVPvvVB0azoOFTt2HGHk/ alcvw7yCjDzSyXTp0doHZfEJPQVGkPE3lI3OOD0ZcQ+aSPxbwCdMIsCwgBu3K/hfO9Z8 Wd2aWbemJavSN+U6g+SDADMgQDZqHIx6mGfr4h7OdkxbQovXXcQwzJ+bHoKLvPvm7Nww A0RQ== X-Gm-Message-State: AOJu0YyRJj2FE0cuaUVKHio7PmT5TmAqYCemRucMbD3qXKgEk3+9notB bR0G4+WlbzXRkcTvtYLL2s+6a6+YlgMgreH4axML5sSe3qX9gY6PwkP5nOqxY4dPbFdxG2fvYbq ijejzktgkHg== X-Google-Smtp-Source: AGHT+IFFgWiSbi0xs/CwzoVFVIwFkq0g6Y7ZP3Vld+dI32gG/gAHxGsrCntr6hE0kd2fMmHg47+qad5jt4iHLQ== X-Received: from qtbey7.prod.google.com ([2002:a05:622a:4c07:b0:467:637d:58d0]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:ac8:7c52:0:b0:467:6201:818a with SMTP id d75a77b69052e-4676201a841mr70521251cf.36.1733738870981; Mon, 09 Dec 2024 02:07:50 -0800 (PST) Date: Mon, 9 Dec 2024 10:07:45 +0000 In-Reply-To: <20241209100747.2269613-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241209100747.2269613-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241209100747.2269613-2-edumazet@google.com> Subject: [PATCH v2 net-next 1/3] rtnetlink: add ndo_fdb_dump_context From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org rtnl_fdb_dump() and various ndo_fdb_dump() helpers share a hidden layout of cb->ctx. Before switching rtnl_fdb_dump() to for_each_netdev_dump() in the following patch, make this more explicit. Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- .../ethernet/freescale/dpaa2/dpaa2-switch.c | 3 ++- drivers/net/ethernet/mscc/ocelot_net.c | 3 ++- drivers/net/vxlan/vxlan_core.c | 5 ++-- include/linux/rtnetlink.h | 7 +++++ net/bridge/br_fdb.c | 3 ++- net/core/rtnetlink.c | 26 ++++++++++--------- net/dsa/user.c | 3 ++- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c index a293b08f36d46dfde7e25412951da78c15e2dfd6..147a93bf9fa913f663676f30559202de9e889f40 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c @@ -780,13 +780,14 @@ struct ethsw_dump_ctx { static int dpaa2_switch_fdb_dump_nl(struct fdb_dump_entry *entry, struct ethsw_dump_ctx *dump) { + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; int is_dynamic = entry->type & DPSW_FDB_ENTRY_DINAMIC; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 558e03301aa8ed89e15c5f37d148a287feaf0018..8d48468cddd7cf91fb49ad23a5c57110900160ef 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -758,12 +758,13 @@ static int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, bool is_static, void *data) { struct ocelot_dump_ctx *dump = data; + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index b46a799bd3904c4183775cb2e86172a0b127bb4f..2cb33c2cb836cf38b6e03b8a620594aa616f00fa 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -1352,6 +1352,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, struct net_device *filter_dev, int *idx) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct vxlan_dev *vxlan = netdev_priv(dev); unsigned int h; int err = 0; @@ -1364,7 +1365,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct vxlan_rdst *rd; if (rcu_access_pointer(f->nh)) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip_nh; err = vxlan_fdb_info(skb, vxlan, f, NETLINK_CB(cb->skb).portid, @@ -1381,7 +1382,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, } list_for_each_entry_rcu(rd, &f->remotes, list) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; err = vxlan_fdb_info(skb, vxlan, f, diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 14b88f55192085def8f318c7913a76d5447b4975..a91dfea64724615c9db778646e52cb8573f47e06 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -178,6 +178,13 @@ void rtnetlink_init(void); void __rtnl_unlock(void); void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); +/* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ +struct ndo_fdb_dump_context { + unsigned long s_h; + unsigned long s_idx; + unsigned long fdb_idx; +}; + extern int ndo_dflt_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, struct net_device *dev, diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 82bac2426631bcea63ea834e72f074fa2eaf0cee..902694c0ce643ec448978e4c4625692ccb1facd9 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -955,6 +955,7 @@ int br_fdb_dump(struct sk_buff *skb, struct net_device *filter_dev, int *idx) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct net_bridge *br = netdev_priv(dev); struct net_bridge_fdb_entry *f; int err = 0; @@ -970,7 +971,7 @@ int br_fdb_dump(struct sk_buff *skb, rcu_read_lock(); hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; if (filter_dev && (!f->dst || f->dst->dev != filter_dev)) { if (filter_dev != dev) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index ab5f201bf0ab41b463175f501e8560b4d64d9b0a..453cc8bf18fbe0d2ac41fed13576279b4c7a2c07 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4762,15 +4762,16 @@ static int nlmsg_populate_fdb(struct sk_buff *skb, int *idx, struct netdev_hw_addr_list *list) { + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct netdev_hw_addr *ha; - int err; u32 portid, seq; + int err; portid = NETLINK_CB(cb->skb).portid; seq = cb->nlh->nlmsg_seq; list_for_each_entry(ha, &list->list, list) { - if (*idx < cb->args[2]) + if (*idx < ctx->fdb_idx) goto skip; err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0, @@ -4909,10 +4910,9 @@ static int valid_fdb_dump_legacy(const struct nlmsghdr *nlh, static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) { - struct net_device *dev; - struct net_device *br_dev = NULL; - const struct net_device_ops *ops = NULL; - const struct net_device_ops *cops = NULL; + const struct net_device_ops *ops = NULL, *cops = NULL; + struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; + struct net_device *dev, *br_dev = NULL; struct net *net = sock_net(skb->sk); struct hlist_head *head; int brport_idx = 0; @@ -4922,6 +4922,8 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) int err = 0; int fidx = 0; + NL_ASSERT_CTX_FITS(struct ndo_fdb_dump_context); + if (cb->strict_check) err = valid_fdb_dump_strict(cb->nlh, &br_idx, &brport_idx, cb->extack); @@ -4939,8 +4941,8 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) ops = br_dev->netdev_ops; } - s_h = cb->args[0]; - s_idx = cb->args[1]; + s_h = ctx->s_h; + s_idx = ctx->s_idx; for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { idx = 0; @@ -4992,7 +4994,7 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) cops = NULL; /* reset fdb offset to 0 for rest of the interfaces */ - cb->args[2] = 0; + ctx->fdb_idx = 0; fidx = 0; cont: idx++; @@ -5000,9 +5002,9 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) } out: - cb->args[0] = h; - cb->args[1] = idx; - cb->args[2] = fidx; + ctx->s_h = h; + ctx->s_idx = idx; + ctx->fdb_idx = fidx; return skb->len; } diff --git a/net/dsa/user.c b/net/dsa/user.c index 06c30a9e29ff820d2dd58fb1801d5e76a5928326..c736c019e2af90747738f10b667e6ad936c9eb0b 100644 --- a/net/dsa/user.c +++ b/net/dsa/user.c @@ -515,12 +515,13 @@ dsa_user_port_fdb_do_dump(const unsigned char *addr, u16 vid, bool is_static, void *data) { struct dsa_user_dump_ctx *dump = data; + struct ndo_fdb_dump_context *ctx = (void *)dump->cb->ctx; u32 portid = NETLINK_CB(dump->cb->skb).portid; u32 seq = dump->cb->nlh->nlmsg_seq; struct nlmsghdr *nlh; struct ndmsg *ndm; - if (dump->idx < dump->cb->args[2]) + if (dump->idx < ctx->fdb_idx) goto skip; nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH, From patchwork Mon Dec 9 10:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13899237 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) (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 6C944216611 for ; Mon, 9 Dec 2024 10:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738875; cv=none; b=Qkuo4sm6x8oodcA7mUAXgx5EoQLnDHkNC3ZuENI1//NPVV0eAdXLU9oqbrvWFkhLjVx/zT+r7oBkmrGfOlcPjm5teG2Nbfd6ePzCYkFNErzRSamDfmXIk1byao7A7l+9339z3Ro+Lc4AkT/CUA3LQgrJYd0o82LB/vL12r+qMCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738875; c=relaxed/simple; bh=2cL5qNmYJ/VPNv4E9JhXhjTEnakvAx/aV8PDkLBqdDw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eo0wOQTuSDFruZd64NcqzWRiu8T7ab1DklW0wQDjI7K7NBEMGLmis3n7Jb0AWeVkYq62jk7Sn/9xn4zol49z9D/OoDOWVJ4jonb+5lChc1wo7EMAbjspqrfkrp2qZxeaEWEmSIJccFafawJLvY+PkSoYdCg7F0+lfzdwjwOIoF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uD859AVI; arc=none smtp.client-ip=209.85.160.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uD859AVI" Received: by mail-qt1-f202.google.com with SMTP id d75a77b69052e-4668f208ff7so89803671cf.0 for ; Mon, 09 Dec 2024 02:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733738872; x=1734343672; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qblZ6PQss9q9GHhzkkP8KvYUrI0jUrlzeKUCXqtiubc=; b=uD859AVIAe0UWsKCkM2XZy/CLrxDVhC6jR5n0/Q0Q9oTVSmNOmetSExzBbp227fagu 5DOJ8uteb0vprnzs+uaqQrSjJreOXq+1Q58eg9PE4fY+ReQvtWGV3afXPZ4gd2rWTGf5 1sTLcJqDtKkDLJxNfvYf0TI0FbNfakHqvGEVSTKsfJRj9KmbGHGZiyZFE+9p8F2dI9wX 8xY+Zp8B3u40wfhdDcJ1SjpcYRu/J+hLbKNLof4IN44UJUOPaFTxf025hyiTj/R5oTWa Lkr+9QjZ72vNl7DsxaeWM0F/1aXicuvlHg8k5ZwEUgfBSQDzl0WmMNJ9nnx3O5BCUHG8 P4OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733738872; x=1734343672; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qblZ6PQss9q9GHhzkkP8KvYUrI0jUrlzeKUCXqtiubc=; b=cpX7/SwwizJ3GeBz0D5AxiYv4+UcRB9BXmq36ceoO5XabkRVsU0UsL4grOhTTuxR/Y SFll7eSkWhRzYUK6Gvycp29FCfUBKa+AUqyFFFY+MJt5teMAnsBInMiuEFQv0lj5PseJ +FCzyi7WxMsDfkmFvq9igqdDsbvuhNBMbbE/n+/vJEZYL9UGBHis/vBO9zaD9HG1X4z8 dqc7rrvzffrFF/APPrdFP4Q5whEIRG2U8adRyTRJY0osJZ6NOJMU3ErBl8bqTAw2Bjgk 0/mK7v7nr/D6W8xECFQpiY/O9fo/n2R/+K8jzbvYd6Uf85eCrb88LtUrrKkqmTMX3dvb O4KA== X-Gm-Message-State: AOJu0Yzv2sE1QJmrAEJV8a6RaXp0qE+hI5hY285RS0xl4wuOY62pr6ie tQ8jCOahjw+TnET2/e7CZfoeMPuXaORyWJiB8IMgvPnM8faGep/Eor6sQe+E7+f0lwQihFWEdqH eyE3MfH4U2w== X-Google-Smtp-Source: AGHT+IH6/F2ADq02KWZVqKSXCukcTTS+u4izLKISgFoEcufTtBjfdx9vhTUC/r7S9+5X8N4ssrAgNVSTuavnaw== X-Received: from qtcw37.prod.google.com ([2002:a05:622a:1925:b0:466:867e:7235]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:8e1a:b0:467:45f2:58b with SMTP id d75a77b69052e-46745f209fcmr85054081cf.6.1733738872398; Mon, 09 Dec 2024 02:07:52 -0800 (PST) Date: Mon, 9 Dec 2024 10:07:46 +0000 In-Reply-To: <20241209100747.2269613-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241209100747.2269613-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241209100747.2269613-3-edumazet@google.com> Subject: [PATCH v2 net-next 2/3] rtnetlink: switch rtnl_fdb_dump() to for_each_netdev_dump() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org This is the last netdev iterator still using net->dev_index_head[]. Convert to modern for_each_netdev_dump() for better scalability, and use common patterns in our stack. Following patch in this series removes the pad field in struct ndo_fdb_dump_context. Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- include/linux/rtnetlink.h | 4 +- net/core/rtnetlink.c | 92 +++++++++++++++------------------------ 2 files changed, 37 insertions(+), 59 deletions(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index a91dfea64724615c9db778646e52cb8573f47e06..2b17d7eebd92342e472b9eb3b2ade84bc8ae2e94 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -180,8 +180,8 @@ void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); /* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ struct ndo_fdb_dump_context { - unsigned long s_h; - unsigned long s_idx; + unsigned long ifindex; + unsigned long pad; unsigned long fdb_idx; }; diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 453cc8bf18fbe0d2ac41fed13576279b4c7a2c07..8fe252c298a2dbcb3a187a117741cd0149fac4cf 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4914,13 +4914,10 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) struct ndo_fdb_dump_context *ctx = (void *)cb->ctx; struct net_device *dev, *br_dev = NULL; struct net *net = sock_net(skb->sk); - struct hlist_head *head; int brport_idx = 0; int br_idx = 0; - int h, s_h; - int idx = 0, s_idx; - int err = 0; int fidx = 0; + int err; NL_ASSERT_CTX_FITS(struct ndo_fdb_dump_context); @@ -4941,69 +4938,50 @@ static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb) ops = br_dev->netdev_ops; } - s_h = ctx->s_h; - s_idx = ctx->s_idx; - - for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { - idx = 0; - head = &net->dev_index_head[h]; - hlist_for_each_entry(dev, head, index_hlist) { - - if (brport_idx && (dev->ifindex != brport_idx)) - continue; - - if (!br_idx) { /* user did not specify a specific bridge */ - if (netif_is_bridge_port(dev)) { - br_dev = netdev_master_upper_dev_get(dev); - cops = br_dev->netdev_ops; - } - } else { - if (dev != br_dev && - !netif_is_bridge_port(dev)) - continue; + for_each_netdev_dump(net, dev, ctx->ifindex) { + if (brport_idx && (dev->ifindex != brport_idx)) + continue; - if (br_dev != netdev_master_upper_dev_get(dev) && - !netif_is_bridge_master(dev)) - continue; - cops = ops; + if (!br_idx) { /* user did not specify a specific bridge */ + if (netif_is_bridge_port(dev)) { + br_dev = netdev_master_upper_dev_get(dev); + cops = br_dev->netdev_ops; } + } else { + if (dev != br_dev && + !netif_is_bridge_port(dev)) + continue; - if (idx < s_idx) - goto cont; + if (br_dev != netdev_master_upper_dev_get(dev) && + !netif_is_bridge_master(dev)) + continue; + cops = ops; + } - if (netif_is_bridge_port(dev)) { - if (cops && cops->ndo_fdb_dump) { - err = cops->ndo_fdb_dump(skb, cb, - br_dev, dev, - &fidx); - if (err == -EMSGSIZE) - goto out; - } + if (netif_is_bridge_port(dev)) { + if (cops && cops->ndo_fdb_dump) { + err = cops->ndo_fdb_dump(skb, cb, br_dev, dev, + &fidx); + if (err == -EMSGSIZE) + break; } + } - if (dev->netdev_ops->ndo_fdb_dump) - err = dev->netdev_ops->ndo_fdb_dump(skb, cb, - dev, NULL, - &fidx); - else - err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, - &fidx); - if (err == -EMSGSIZE) - goto out; + if (dev->netdev_ops->ndo_fdb_dump) + err = dev->netdev_ops->ndo_fdb_dump(skb, cb, dev, NULL, + &fidx); + else + err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, &fidx); + if (err == -EMSGSIZE) + break; - cops = NULL; + cops = NULL; - /* reset fdb offset to 0 for rest of the interfaces */ - ctx->fdb_idx = 0; - fidx = 0; -cont: - idx++; - } + /* reset fdb offset to 0 for rest of the interfaces */ + ctx->fdb_idx = 0; + fidx = 0; } -out: - ctx->s_h = h; - ctx->s_idx = idx; ctx->fdb_idx = fidx; return skb->len; From patchwork Mon Dec 9 10:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13899238 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 F0971216E0D for ; Mon, 9 Dec 2024 10:07:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738876; cv=none; b=jMXws8BklxQCJ65KBTNcpRnh9DzlkEqTmQYJwCbcQUThAdu2bj8JuQ0+LyvWCNBuKzlkf+QnZu6tnURB1QPK5wLJ0ycTPrIZ+cxN9ARq9/NmsK0T+CBVUxlK8paXMOSGCEh7JMrKyeUCiFxmecep4Wbpl+7i8CN7AeAKq0rOpSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733738876; c=relaxed/simple; bh=8xxlCLEmX5IzwHr+HlPsh8ho+d8E+ltz36Vu01KXIO0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xk4H2AbaJKR8uHbF8R/f7Rz8tOMx9PJJqqcjzgUOC0mkbix6OFa/SVu9/S4GhI52B3luvgU63RBtv3pzRwAwKeGxcFzNTQT5PP27OClYqJoHnMm7XkmWywMLXJBixCgROJ54AYnGV3Wi/t4vp1JFndHFJ6h6v5V1f/bqy5u287g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kosHdIfK; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kosHdIfK" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e38902a3200so8496020276.2 for ; Mon, 09 Dec 2024 02:07:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733738874; x=1734343674; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ZwMO66CnlgZQswBuDJJhAg7/MBDE5Pzh4mwB6lYj7Ys=; b=kosHdIfKiXj7yWxwoA/sB+jj2kt82cIT6tzIXc+n3HOhrrbHVoAXNMM/A56Eo7GncK CtkB4ARBJi8IJs+tfRS82zgfxhXjIS6fwcjFBQQTmfvZtFJxPrqiPWQ0svL9dobJgNxX IsGG02r3ySohmVL07oJfaMBZZTs7rSLBrsgU6j/ZgKZ9qTKaEq+PifuvyZW3L9ZGNZ1T i4p6FSPJyMCKMNXF+/3w1qky7HIZideruqGimLFv4By6PxdF6VVzktGYVOznJVgk+yma HcIKQQUHZ+bbBTkbNuqqG2D9F2hDqiCGVrc6RGmC5G8cj//htDxW7V6wGT6Dcf1Q1yPS jmCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733738874; x=1734343674; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZwMO66CnlgZQswBuDJJhAg7/MBDE5Pzh4mwB6lYj7Ys=; b=GFYtu2hNamMTZQ5c65eXeBBhG5A212uoOgDkW508/8lT4c+r9sepJk/qjANfR0+KcY 1hcow5LIBqV3+SM7/sAGGSdV18/ZeL5hAx10BIYuWiat5c6OSkr6fB4bPUMKlcB5pCsz tUk0X9LO8LidRly2v3EaghkQO0b9EgNE/JjlwDjDPSmz8pZ/YNOP5Bc4HqihL8vW2uKw EwBXSUPdIamkmzErmXSf8zaS3FHXixDX9Y+mG1Kfnsn/2EFQOBVU7ORgnXeU4N6FTVtP TpuGrKEDWvKo/D7DyBT11go85Sk1l2mS1b8QodakkFgCabyLQBzHrlTO+BZ/t+JTXSnw FN9w== X-Gm-Message-State: AOJu0YyTWWOdMRNJ3HJfi2YXA+8BjzyE2NEoBvbUycsHbUU5foFi5MAo 5YoSg4nA9izf/ju8I12s4YeJzj2/VyvGBip+uqn6gw1BLIl/Niq77aru1MKBoDHWK8hI39x2fK+ it5s3hBfy4g== X-Google-Smtp-Source: AGHT+IHs0DyW1RDgo3EvbunQHqAjGHyqm/3WruQUE68Yg+3cozyqkpZ2pUgzoTnpm1YQnPMXjjnOLmfaZqyNYA== X-Received: from qtbhg22.prod.google.com ([2002:a05:622a:6116:b0:462:4391:1c48]) (user=edumazet job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6902:2b8f:b0:e2b:e0ba:d50 with SMTP id 3f1490d57ef6-e3a0b072fccmr13163722276.5.1733738874021; Mon, 09 Dec 2024 02:07:54 -0800 (PST) Date: Mon, 9 Dec 2024 10:07:47 +0000 In-Reply-To: <20241209100747.2269613-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241209100747.2269613-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241209100747.2269613-4-edumazet@google.com> Subject: [PATCH v2 net-next 3/3] rtnetlink: remove pad field in ndo_fdb_dump_context From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, Simon Horman , Roopa Prabhu , Kuniyuki Iwashima , Ido Schimmel , eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org I chose to remove this field in a separate patch to ease potential bisection, in case one ndo_fdb_dump() is still using the old way (cb->args[2] instead of ctx->fdb_idx) Signed-off-by: Eric Dumazet Reviewed-by: Ido Schimmel Reviewed-by: Kuniyuki Iwashima --- include/linux/rtnetlink.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 2b17d7eebd92342e472b9eb3b2ade84bc8ae2e94..af668b79eb757c86970b2455d9d820c902699a13 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -181,7 +181,6 @@ void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); /* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */ struct ndo_fdb_dump_context { unsigned long ifindex; - unsigned long pad; unsigned long fdb_idx; };