Re: [RFC PATCH v2 02/11] netdev: implement netlink api to bind dma-buf to netdevice
From: Leon Romanovsky <leon@kernel.org>
Date: 2023-08-13 11:26:58
Also in:
dri-devel, linux-media
On Wed, Aug 09, 2023 at 06:57:38PM -0700, Mina Almasry wrote:
Add a netdev_dmabuf_binding struct which represents the dma-buf-to-netdevice binding. The netlink API will bind the dma-buf to an rx queue on the netdevice. On the binding, the dma_buf_attach & dma_buf_map_attachment will occur. The entries in the sg_table from mapping will be inserted into a genpool to make it ready for allocation. The chunks in the genpool are owned by a dmabuf_chunk_owner struct which holds the dma-buf offset of the base of the chunk and the dma_addr of the chunk. Both are needed to use allocations that come from this chunk. We create a new type that represents an allocation from the genpool: page_pool_iov. We setup the page_pool_iov allocation size in the genpool to PAGE_SIZE for simplicity: to match the PAGE_SIZE normally allocated by the page pool and given to the drivers. The user can unbind the dmabuf from the netdevice by closing the netlink socket that established the binding. We do this so that the binding is automatically unbound even if the userspace process crashes. The binding and unbinding leaves an indicator in struct netdev_rx_queue that the given queue is bound, but the binding doesn't take effect until the driver actually reconfigures its queues, and re-initializes its page pool. This issue/weirdness is highlighted in the memory provider proposal[1], and I'm hoping that some generic solution for all memory providers will be discussed; this patch doesn't address that weirdness again. The netdev_dmabuf_binding struct is refcounted, and releases its resources only when all the refs are released. [1] https://lore.kernel.org/netdev/20230707183935.997267-1-kuba@kernel.org/ (local) Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Kaiyuan Zhang <redacted> Signed-off-by: Mina Almasry <redacted> --- include/linux/netdevice.h | 57 ++++++++++++ include/net/page_pool.h | 27 ++++++ net/core/dev.c | 178 ++++++++++++++++++++++++++++++++++++++ net/core/netdev-genl.c | 101 ++++++++++++++++++++- 4 files changed, 361 insertions(+), 2 deletions(-)
<...>
+void __netdev_devmem_binding_free(struct netdev_dmabuf_binding *binding);
+
+static inline void
+netdev_devmem_binding_get(struct netdev_dmabuf_binding *binding)
+{
+ refcount_inc(&binding->ref);
+}
+
+static inline void
+netdev_devmem_binding_put(struct netdev_dmabuf_binding *binding)
+{
+ if (!refcount_dec_and_test(&binding->ref))
+ return;
+
+ __netdev_devmem_binding_free(binding);
+}Not a big deal, but it looks like reimplemented version of kref_get/kref_put to me. Thanks