mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mina Almasry <almasrymina@google.com>
To: Dragos Tatulea <dtatulea@nvidia.com>
Cc: 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>,
	cratiu@nvidia.com, tariqt@nvidia.com, parav@nvidia.com,
	 Christoph Hellwig <hch@infradead.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC net-next v3 6/7] net: devmem: pre-read requested rx queues during bind
Date: Mon, 18 Aug 2025 11:24:16 -0700	[thread overview]
Message-ID: <CAHS8izOosrkGw_aaL4-Rf1ue8UOMvaWWYXc48OBjO4F2UQa3VQ@mail.gmail.com> (raw)
In-Reply-To: <nv2z4vvycay3eygcjfmxcqjgrftmmqm3nmesui4vjenexjbnvk@ll7km6oblghm>

On Sat, Aug 16, 2025 at 1:59 AM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> On Fri, Aug 15, 2025 at 11:05:56AM -0700, Mina Almasry wrote:
> > On Fri, Aug 15, 2025 at 4:07 AM Dragos Tatulea <dtatulea@nvidia.com> wrote:
> > >
> > > 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) {
> >
> > Is this code assuming that netdev->num_rx_queues (or
> > real_num_rx_queues) <= BITS_PER_ULONG? Aren't there devices out there
> > that support more than 64 hardware queues? If so, I guess you need a
> > different data structure than a bitmap (or maybe there is arbirary
> > sized bitmap library somewhere to use).
> >
> The bitmap API can handle any number of bits. Can it not?
>

Ah, yes, I missed this:

+       rxq_bitmap = bitmap_alloc(netdev->num_rx_queues, GFP_KERNEL);


Which allocates netdev->num_rx_queues bits. I was confused by the fact
that rxq_bitmap is an unsigned long * and thought that was the # of
bits in the map.

This patch should be good just with conversion to netdev->real_num_rx_queues.

-- 
Thanks,
Mina

  reply	other threads:[~2025-08-18 18:24 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 ` [RFC net-next v3 6/7] net: devmem: pre-read requested rx queues during bind Dragos Tatulea
2025-08-15 17:20   ` Jakub Kicinski
2025-08-15 18:05   ` Mina Almasry
2025-08-16  8:59     ` Dragos Tatulea
2025-08-18 18:24       ` Mina Almasry [this message]
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=CAHS8izOosrkGw_aaL4-Rf1ue8UOMvaWWYXc48OBjO4F2UQa3VQ@mail.gmail.com \
    --to=almasrymina@google.com \
    --cc=asml.silence@gmail.com \
    --cc=cratiu@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --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®