mirror of
https://github.com/torvalds/linux.git
synced 2026-01-25 15:03:52 +08:00
Add a netdev_dmabuf_binding struct which represents the dma-buf-to-netdevice binding. The netlink API will bind the dma-buf to rx queues 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: net_iov. We setup the net_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, and the binding is actuated by resetting the rx queue using the queue API. The netdev_dmabuf_binding struct is refcounted, and releases its resources only when all the refs are released. Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Kaiyuan Zhang <kaiyuanz@google.com> Signed-off-by: Mina Almasry <almasrymina@google.com> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> # excluding netlink Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20240910171458.219195-4-almasrymina@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
65 lines
1.5 KiB
C
65 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0
|
|
*
|
|
* Network memory
|
|
*
|
|
* Author: Mina Almasry <almasrymina@google.com>
|
|
*/
|
|
|
|
#ifndef _NET_NETMEM_H
|
|
#define _NET_NETMEM_H
|
|
|
|
/* net_iov */
|
|
|
|
struct net_iov {
|
|
struct dmabuf_genpool_chunk_owner *owner;
|
|
};
|
|
|
|
/* netmem */
|
|
|
|
/**
|
|
* typedef netmem_ref - a nonexistent type marking a reference to generic
|
|
* network memory.
|
|
*
|
|
* A netmem_ref currently is always a reference to a struct page. This
|
|
* abstraction is introduced so support for new memory types can be added.
|
|
*
|
|
* Use the supplied helpers to obtain the underlying memory pointer and fields.
|
|
*/
|
|
typedef unsigned long __bitwise netmem_ref;
|
|
|
|
/* This conversion fails (returns NULL) if the netmem_ref is not struct page
|
|
* backed.
|
|
*
|
|
* Currently struct page is the only possible netmem, and this helper never
|
|
* fails.
|
|
*/
|
|
static inline struct page *netmem_to_page(netmem_ref netmem)
|
|
{
|
|
return (__force struct page *)netmem;
|
|
}
|
|
|
|
/* Converting from page to netmem is always safe, because a page can always be
|
|
* a netmem.
|
|
*/
|
|
static inline netmem_ref page_to_netmem(struct page *page)
|
|
{
|
|
return (__force netmem_ref)page;
|
|
}
|
|
|
|
static inline int netmem_ref_count(netmem_ref netmem)
|
|
{
|
|
return page_ref_count(netmem_to_page(netmem));
|
|
}
|
|
|
|
static inline unsigned long netmem_to_pfn(netmem_ref netmem)
|
|
{
|
|
return page_to_pfn(netmem_to_page(netmem));
|
|
}
|
|
|
|
static inline netmem_ref netmem_compound_head(netmem_ref netmem)
|
|
{
|
|
return page_to_netmem(compound_head(netmem_to_page(netmem)));
|
|
}
|
|
|
|
#endif /* _NET_NETMEM_H */
|