Commit 170aafe3 authored by Mina Almasry's avatar Mina Almasry Committed by Jakub Kicinski
Browse files

netdev: support binding dma-buf to netdevice



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: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarKaiyuan Zhang <kaiyuanz@google.com>
Signed-off-by: default avatarMina Almasry <almasrymina@google.com>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> # excluding netlink
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Link: https://patch.msgid.link/20240910171458.219195-4-almasrymina@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3efd7ab4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -667,6 +667,10 @@ operations:
          attributes:
            - id

kernel-family:
  headers: [ "linux/list.h"]
  sock-priv: struct list_head

mcast-groups:
  list:
    -
+2 −0
Original line number Diff line number Diff line
@@ -3953,6 +3953,8 @@ u8 dev_xdp_prog_count(struct net_device *dev);
int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf);
u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);

u32 dev_get_min_mp_channel_count(const struct net_device *dev);

int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);
+2 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include <linux/netdevice.h>
#include <linux/sysfs.h>
#include <net/xdp.h>
#include <net/page_pool/types.h>

/* This structure contains an instance of an RX queue. */
struct netdev_rx_queue {
@@ -25,6 +26,7 @@ struct netdev_rx_queue {
	 * Readers and writers must hold RTNL
	 */
	struct napi_struct		*napi;
	struct pp_memory_provider_params mp_params;
} ____cacheline_aligned_in_smp;

/*
+8 −0
Original line number Diff line number Diff line
@@ -8,6 +8,14 @@
#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.
+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,10 @@ struct page_pool_stats {
 */
#define PAGE_POOL_FRAG_GROUP_ALIGN	(4 * sizeof(long))

struct pp_memory_provider_params {
	void *mp_priv;
};

struct page_pool {
	struct page_pool_params_fast p;

@@ -197,6 +201,8 @@ struct page_pool {
	 */
	struct ptr_ring ring;

	void *mp_priv;

#ifdef CONFIG_PAGE_POOL_STATS
	/* recycle stats are per-cpu to avoid locking */
	struct page_pool_recycle_stats __percpu *recycle_stats;
Loading