From: Dragos Tatulea <dtatulea@nvidia.com>
To: <almasrymina@google.com>, <asml.silence@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: Dragos Tatulea <dtatulea@nvidia.com>, <cratiu@nvidia.com>,
<tariqt@nvidia.com>, <parav@nvidia.com>,
Christoph Hellwig <hch@infradead.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: [RFC net-next v3 6/7] net: devmem: pre-read requested rx queues during bind
Date: Fri, 15 Aug 2025 14:03:47 +0300 [thread overview]
Message-ID: <20250815110401.2254214-8-dtatulea@nvidia.com> (raw)
In-Reply-To: <20250815110401.2254214-2-dtatulea@nvidia.com>
Instead of reading the requested rx queues after binding the buffer,
read the rx queues in advance in a bitmap and iterate over them when
needed.
This is a preparation for fetching the DMA device for each queue.
This patch has no functional changes.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
---
net/core/netdev-genl.c | 76 +++++++++++++++++++++++++++---------------
1 file changed, 49 insertions(+), 27 deletions(-)
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 3e2d6aa6e060..3e990f100bf0 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -869,17 +869,50 @@ int netdev_nl_qstats_get_dumpit(struct sk_buff *skb,
return err;
}
-int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
+static int netdev_nl_read_rxq_bitmap(struct genl_info *info,
+ unsigned long *rxq_bitmap)
{
struct nlattr *tb[ARRAY_SIZE(netdev_queue_id_nl_policy)];
+ struct nlattr *attr;
+ int rem, err = 0;
+ u32 rxq_idx;
+
+ nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
+ genlmsg_data(info->genlhdr),
+ genlmsg_len(info->genlhdr), rem) {
+ err = nla_parse_nested(
+ tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,
+ netdev_queue_id_nl_policy, info->extack);
+ if (err < 0)
+ return err;
+
+ if (NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_ID) ||
+ NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_TYPE))
+ return -EINVAL;
+
+ if (nla_get_u32(tb[NETDEV_A_QUEUE_TYPE]) != NETDEV_QUEUE_TYPE_RX) {
+ NL_SET_BAD_ATTR(info->extack, tb[NETDEV_A_QUEUE_TYPE]);
+ return -EINVAL;
+ }
+
+ rxq_idx = nla_get_u32(tb[NETDEV_A_QUEUE_ID]);
+
+ bitmap_set(rxq_bitmap, rxq_idx, 1);
+ }
+
+ return 0;
+}
+
+int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
+{
struct net_devmem_dmabuf_binding *binding;
u32 ifindex, dmabuf_fd, rxq_idx;
struct netdev_nl_sock *priv;
struct net_device *netdev;
+ unsigned long *rxq_bitmap;
struct device *dma_dev;
struct sk_buff *rsp;
- struct nlattr *attr;
- int rem, err = 0;
+ int err = 0;
void *hdr;
if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_DEV_IFINDEX) ||
@@ -922,37 +955,22 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
goto err_unlock;
}
+ rxq_bitmap = bitmap_alloc(netdev->num_rx_queues, GFP_KERNEL);
+ if (!rxq_bitmap) {
+ err = -ENOMEM;
+ goto err_unlock;
+ }
+ netdev_nl_read_rxq_bitmap(info, rxq_bitmap);
+
dma_dev = netdev_queue_get_dma_dev(netdev, 0);
binding = net_devmem_bind_dmabuf(netdev, dma_dev, DMA_FROM_DEVICE,
dmabuf_fd, priv, info->extack);
if (IS_ERR(binding)) {
err = PTR_ERR(binding);
- goto err_unlock;
+ goto err_rxq_bitmap;
}
- nla_for_each_attr_type(attr, NETDEV_A_DMABUF_QUEUES,
- genlmsg_data(info->genlhdr),
- genlmsg_len(info->genlhdr), rem) {
- err = nla_parse_nested(
- tb, ARRAY_SIZE(netdev_queue_id_nl_policy) - 1, attr,
- netdev_queue_id_nl_policy, info->extack);
- if (err < 0)
- goto err_unbind;
-
- if (NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_ID) ||
- NL_REQ_ATTR_CHECK(info->extack, attr, tb, NETDEV_A_QUEUE_TYPE)) {
- err = -EINVAL;
- goto err_unbind;
- }
-
- if (nla_get_u32(tb[NETDEV_A_QUEUE_TYPE]) != NETDEV_QUEUE_TYPE_RX) {
- NL_SET_BAD_ATTR(info->extack, tb[NETDEV_A_QUEUE_TYPE]);
- err = -EINVAL;
- goto err_unbind;
- }
-
- rxq_idx = nla_get_u32(tb[NETDEV_A_QUEUE_ID]);
-
+ for_each_set_bit(rxq_idx, rxq_bitmap, netdev->num_rx_queues) {
err = net_devmem_bind_dmabuf_to_queue(netdev, rxq_idx, binding,
info->extack);
if (err)
@@ -966,6 +984,8 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
if (err)
goto err_unbind;
+ bitmap_free(rxq_bitmap);
+
netdev_unlock(netdev);
mutex_unlock(&priv->lock);
@@ -974,6 +994,8 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
err_unbind:
net_devmem_unbind_dmabuf(binding);
+err_rxq_bitmap:
+ bitmap_free(rxq_bitmap);
err_unlock:
netdev_unlock(netdev);
err_unlock_sock:
--
2.50.1
next prev parent reply other threads:[~2025-08-15 11:07 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 11:03 [RFC net-next v3 0/7] devmem/io_uring: allow more flexibility for ZC DMA devices Dragos Tatulea
2025-08-15 11:03 ` [RFC net-next v3 1/7] queue_api: add support for fetching per queue DMA dev Dragos Tatulea
2025-08-15 17:16 ` Jakub Kicinski
2025-08-19 14:41 ` Dragos Tatulea
2025-08-19 15:30 ` Jakub Kicinski
2025-08-15 18:11 ` Mina Almasry
2025-08-16 8:55 ` Dragos Tatulea
2025-08-19 15:56 ` Pavel Begunkov
2025-08-15 11:03 ` [RFC net-next v3 2/7] io_uring/zcrx: add support for custom DMA devices Dragos Tatulea
2025-08-18 18:16 ` Mina Almasry
2025-08-19 16:04 ` Pavel Begunkov
2025-08-15 11:03 ` [RFC net-next v3 3/7] net: devmem: get netdev DMA device via new API Dragos Tatulea
2025-08-15 17:30 ` Mina Almasry
2025-08-15 11:03 ` [RFC net-next v3 4/7] net/mlx5e: add op for getting netdev DMA device Dragos Tatulea
2025-08-15 17:37 ` Mina Almasry
2025-08-18 17:40 ` Dragos Tatulea
2025-08-18 18:18 ` Mina Almasry
2025-08-15 11:03 ` [RFC net-next v3 5/7] net: devmem: pull out dma_dev out of net_devmem_bind_dmabuf Dragos Tatulea
2025-08-18 18:22 ` Mina Almasry
2025-08-15 11:03 ` Dragos Tatulea [this message]
2025-08-15 17:20 ` [RFC net-next v3 6/7] net: devmem: pre-read requested rx queues during bind Jakub Kicinski
2025-08-15 18:05 ` Mina Almasry
2025-08-16 8:59 ` Dragos Tatulea
2025-08-18 18:24 ` Mina Almasry
2025-10-02 16:38 ` ChaosEsque Team
2025-08-15 11:03 ` [RFC net-next v3 7/7] net: devmem: allow binding on rx queues with same MA devices Dragos Tatulea
2025-08-15 17:24 ` Jakub Kicinski
2025-08-16 9:05 ` Dragos Tatulea
2025-08-15 15:31 ` [RFC net-next v3 0/7] devmem/io_uring: allow more flexibility for ZC DMA devices Stanislav Fomichev
2025-08-15 15:48 ` Dragos Tatulea
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250815110401.2254214-8-dtatulea@nvidia.com \
--to=dtatulea@nvidia.com \
--cc=almasrymina@google.com \
--cc=asml.silence@gmail.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hch@infradead.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=parav@nvidia.com \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®