[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <5e2f9342-4ee9-4b30-9dcf-393e57e0f7c6@app.fastmail.com>
Date: Tue, 05 Mar 2024 10:04:45 +0100
From: "Arnd Bergmann" <arnd@...db.de>
To: "Mina Almasry" <almasrymina@...gle.com>, Netdev <netdev@...r.kernel.org>,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
linux-alpha@...r.kernel.org, linux-mips@...r.kernel.org,
linux-parisc@...r.kernel.org, sparclinux@...r.kernel.org,
linux-trace-kernel@...r.kernel.org, Linux-Arch <linux-arch@...r.kernel.org>,
bpf@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-media@...r.kernel.org, dri-devel@...ts.freedesktop.org
Cc: "David S . Miller" <davem@...emloft.net>,
"Eric Dumazet" <edumazet@...gle.com>, "Jakub Kicinski" <kuba@...nel.org>,
"Paolo Abeni" <pabeni@...hat.com>, "Jonathan Corbet" <corbet@....net>,
"Richard Henderson" <richard.henderson@...aro.org>,
"Ivan Kokshaysky" <ink@...assic.park.msu.ru>,
"Matt Turner" <mattst88@...il.com>,
"Thomas Bogendoerfer" <tsbogend@...ha.franken.de>,
"James E . J . Bottomley" <James.Bottomley@...senPartnership.com>,
"Helge Deller" <deller@....de>, "Andreas Larsson" <andreas@...sler.com>,
"Jesper Dangaard Brouer" <hawk@...nel.org>,
"Ilias Apalodimas" <ilias.apalodimas@...aro.org>,
"Steven Rostedt" <rostedt@...dmis.org>,
"Masami Hiramatsu" <mhiramat@...nel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@...icios.com>,
"Alexei Starovoitov" <ast@...nel.org>,
"Daniel Borkmann" <daniel@...earbox.net>,
"Andrii Nakryiko" <andrii@...nel.org>,
"Martin KaFai Lau" <martin.lau@...ux.dev>,
"Eduard Zingerman" <eddyz87@...il.com>, "Song Liu" <song@...nel.org>,
"Yonghong Song" <yonghong.song@...ux.dev>,
"John Fastabend" <john.fastabend@...il.com>,
"KP Singh" <kpsingh@...nel.org>, "Stanislav Fomichev" <sdf@...gle.com>,
"Hao Luo" <haoluo@...gle.com>, "Jiri Olsa" <jolsa@...nel.org>,
"David Ahern" <dsahern@...nel.org>,
"Willem de Bruijn" <willemdebruijn.kernel@...il.com>,
shuah <shuah@...nel.org>, "Sumit Semwal" <sumit.semwal@...aro.org>,
Christian König <christian.koenig@....com>,
"Pavel Begunkov" <asml.silence@...il.com>, "David Wei" <dw@...idwei.uk>,
"Jason Gunthorpe" <jgg@...pe.ca>,
"Yunsheng Lin" <linyunsheng@...wei.com>,
"Shailend Chand" <shailend@...gle.com>,
"Harshitha Ramamurthy" <hramamurthy@...gle.com>,
"Shakeel Butt" <shakeelb@...gle.com>,
"Jeroen de Borst" <jeroendb@...gle.com>,
"Praveen Kaligineedi" <pkaligineedi@...gle.com>,
"Willem de Bruijn" <willemb@...gle.com>,
"Kaiyuan Zhang" <kaiyuanz@...gle.com>
Subject: Re: [RFC PATCH net-next v6 05/15] netdev: support binding dma-buf to netdevice
On Tue, Mar 5, 2024, at 03:01, Mina Almasry wrote:
> +int netdev_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd,
> + struct netdev_dmabuf_binding **out)
> +{
> + struct netdev_dmabuf_binding *binding;
> + static u32 id_alloc_next;
> + struct scatterlist *sg;
> + struct dma_buf *dmabuf;
> + unsigned int sg_idx, i;
> + unsigned long virtual;
> + int err;
> +
> + if (!capable(CAP_NET_ADMIN))
> + return -EPERM;
> +
> + dmabuf = dma_buf_get(dmabuf_fd);
> + if (IS_ERR_OR_NULL(dmabuf))
> + return -EBADFD;
You should never need to use IS_ERR_OR_NULL() for a properly
defined kernel interface. This one should always return an
error or a valid pointer, so don't check for NULL.
> + binding->attachment = dma_buf_attach(binding->dmabuf, dev->dev.parent);
> + if (IS_ERR(binding->attachment)) {
> + err = PTR_ERR(binding->attachment);
> + goto err_free_id;
> + }
> +
> + binding->sgt =
> + dma_buf_map_attachment(binding->attachment, DMA_BIDIRECTIONAL);
> + if (IS_ERR(binding->sgt)) {
> + err = PTR_ERR(binding->sgt);
> + goto err_detach;
> + }
Should there be a check to verify that this buffer
is suitable for network data?
In general, dmabuf allows buffers that are uncached or reside
in MMIO space of another device, but I think this would break
when you get an skb with those buffers and try to parse the
data inside of the kernel on architectures where MMIO space
is not a normal pointer or unaligned access is disallowed on
uncached data.
Arnd
Powered by blists - more mailing lists