From: Simon Horman <horms@kernel.org>
To: Mina Almasry <almasrymina@google.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, kvm@vger.kernel.org,
virtualization@lists.linux.dev, linux-kselftest@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David Ahern" <dsahern@kernel.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Shuah Khan" <shuah@kernel.org>,
sdf@fomichev.me, asml.silence@gmail.com, dw@davidwei.uk,
"Jamal Hadi Salim" <jhs@mojatatu.com>,
"Victor Nogueira" <victor@mojatatu.com>,
"Pedro Tammela" <pctammela@mojatatu.com>,
"Kaiyuan Zhang" <kaiyuanz@google.com>
Subject: Re: [PATCH RFC net-next v2 5/6] net: devmem: Implement TX path
Date: Fri, 31 Jan 2025 09:09:27 +0000 [thread overview]
Message-ID: <20250131090927.GB24105@kernel.org> (raw)
In-Reply-To: <20250130211539.428952-6-almasrymina@google.com>
On Thu, Jan 30, 2025 at 09:15:38PM +0000, Mina Almasry wrote:
> Augment dmabuf binding to be able to handle TX. Additional to all the RX
> binding, we also create tx_vec needed for the TX path.
>
> Provide API for sendmsg to be able to send dmabufs bound to this device:
>
> - Provide a new dmabuf_tx_cmsg which includes the dmabuf to send from.
> - MSG_ZEROCOPY with SCM_DEVMEM_DMABUF cmsg indicates send from dma-buf.
>
> Devmem is uncopyable, so piggyback off the existing MSG_ZEROCOPY
> implementation, while disabling instances where MSG_ZEROCOPY falls back
> to copying.
>
> We additionally pipe the binding down to the new
> zerocopy_fill_skb_from_devmem which fills a TX skb with net_iov netmems
> instead of the traditional page netmems.
>
> We also special case skb_frag_dma_map to return the dma-address of these
> dmabuf net_iovs instead of attempting to map pages.
>
> Based on work by Stanislav Fomichev <sdf@fomichev.me>. A lot of the meat
> of the implementation came from devmem TCP RFC v1[1], which included the
> TX path, but Stan did all the rebasing on top of netmem/net_iov.
>
> Cc: Stanislav Fomichev <sdf@fomichev.me>
> Signed-off-by: Kaiyuan Zhang <kaiyuanz@google.com>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
...
> diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
> index 0e41699df419..9ba6994e2a05 100644
> --- a/net/core/netdev-genl.c
> +++ b/net/core/netdev-genl.c
...
> @@ -911,10 +912,68 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info)
> return err;
> }
>
> -/* stub */
> int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
> {
> - return 0;
> + struct net_devmem_dmabuf_binding *binding;
> + struct list_head *sock_binding_list;
> + struct net_device *netdev;
> + u32 ifindex, dmabuf_fd;
> + struct sk_buff *rsp;
> + int err = 0;
> + void *hdr;
> +
> + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_DEV_IFINDEX) ||
> + GENL_REQ_ATTR_CHECK(info, NETDEV_A_DMABUF_FD))
> + return -EINVAL;
> +
> + ifindex = nla_get_u32(info->attrs[NETDEV_A_DEV_IFINDEX]);
> + dmabuf_fd = nla_get_u32(info->attrs[NETDEV_A_DMABUF_FD]);
> +
> + sock_binding_list =
> + genl_sk_priv_get(&netdev_nl_family, NETLINK_CB(skb).sk);
> + if (IS_ERR(sock_binding_list))
> + return PTR_ERR(sock_binding_list);
> +
> + rsp = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
> + if (!rsp)
> + return -ENOMEM;
> +
> + hdr = genlmsg_iput(rsp, info);
> + if (!hdr) {
> + err = -EMSGSIZE;
> + goto err_genlmsg_free;
> + }
> +
> + rtnl_lock();
> +
> + netdev = __dev_get_by_index(genl_info_net(info), ifindex);
> + if (!netdev || !netif_device_present(netdev)) {
> + err = -ENODEV;
> + goto err_unlock;
> + }
> +
> + binding = net_devmem_bind_dmabuf(netdev, DMA_TO_DEVICE, dmabuf_fd,
> + info->extack);
> + if (IS_ERR(binding)) {
> + err = PTR_ERR(binding);
> + goto err_unlock;
> + }
> +
> + list_add(&binding->list, sock_binding_list);
> +
> + nla_put_u32(rsp, NETDEV_A_DMABUF_ID, binding->id);
> + genlmsg_end(rsp, hdr);
> +
> + rtnl_unlock();
> +
> + return genlmsg_reply(rsp, info);
> +
> + net_devmem_unbind_dmabuf(binding);
Hi Mina,
It appears that the line above is unreachable.
I guess it was part of an unwind that is no-longer needed
and thus can now be removed.
Flagged by Smatch.
> +err_unlock:
> + rtnl_unlock();
> +err_genlmsg_free:
> + nlmsg_free(rsp);
> + return err;
> }
...
next prev parent reply other threads:[~2025-01-31 9:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-30 21:15 [PATCH RFC net-next v2 0/6] Device memory TCP TX Mina Almasry
2025-01-30 21:15 ` [PATCH RFC net-next v2 1/6] net: add devmem TCP TX documentation Mina Almasry
2025-01-30 22:59 ` Stanislav Fomichev
2025-01-30 23:22 ` Mina Almasry
2025-01-31 17:39 ` Stanislav Fomichev
2025-01-30 21:15 ` [PATCH RFC net-next v2 2/6] selftests: ncdevmem: Implement devmem TCP TX Mina Almasry
2025-01-30 23:05 ` Stanislav Fomichev
2025-01-30 23:29 ` Mina Almasry
2025-01-31 17:41 ` Stanislav Fomichev
2025-01-31 17:45 ` Stanislav Fomichev
2025-01-30 21:15 ` [PATCH RFC net-next v2 3/6] net: add get_netmem/put_netmem support Mina Almasry
2025-01-30 21:15 ` [PATCH RFC net-next v2 4/6] net: devmem: TCP tx netlink api Mina Almasry
2025-01-31 8:29 ` Simon Horman
2025-01-30 21:15 ` [PATCH RFC net-next v2 5/6] net: devmem: Implement TX path Mina Almasry
2025-01-30 23:07 ` Stanislav Fomichev
2025-01-31 9:09 ` Simon Horman [this message]
2025-01-30 21:15 ` [PATCH RFC net-next v2 6/6] net: devmem: make dmabuf unbinding scheduled work Mina Almasry
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=20250131090927.GB24105@kernel.org \
--to=horms@kernel.org \
--cc=almasrymina@google.com \
--cc=andrew+netdev@lunn.ch \
--cc=asml.silence@gmail.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=jhs@mojatatu.com \
--cc=kaiyuanz@google.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pctammela@mojatatu.com \
--cc=sdf@fomichev.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=stefanha@redhat.com \
--cc=victor@mojatatu.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.