Skip to content

Commit 825f276

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: implement device-less mode for zcrx
Allow creating a zcrx instance without attaching it to a net device. All data will be copied through the fallback path. The user is also expected to use ZCRX_CTRL_FLUSH_RQ to handle overflows as it normally should even with a netdev, but it becomes even more relevant as there will likely be no one to automatically pick up buffers. Apart from that, it follows the zcrx uapi for the I/O path, and is useful for testing, experimentation, and potentially for the copy receive path in the future if improved. Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://patch.msgid.link/674f8ad679c5a0bc79d538352b3042cf0999596e.1774261953.git.asml.silence@gmail.com [axboe: fix spelling error in uapi header and commit message] Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 06fc3b6 commit 825f276

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

include/uapi/linux/io_uring/zcrx.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ struct io_uring_zcrx_area_reg {
4949
};
5050

5151
enum zcrx_reg_flags {
52-
ZCRX_REG_IMPORT = 1,
52+
ZCRX_REG_IMPORT = 1,
53+
54+
/*
55+
* Register a zcrx instance without a net device. All data will be
56+
* copied. The refill queue entries might not be automatically
57+
* consumed and need to be flushed, see ZCRX_CTRL_FLUSH_RQ.
58+
*/
59+
ZCRX_REG_NODEV = 2,
5360
};
5461

5562
enum zcrx_features {

io_uring/zcrx.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
127127
int dmabuf_fd = area_reg->dmabuf_fd;
128128
int i, ret;
129129

130+
if (!ifq->dev)
131+
return -EINVAL;
130132
if (off)
131133
return -EINVAL;
132-
if (WARN_ON_ONCE(!ifq->dev))
133-
return -EFAULT;
134134
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
135135
return -EINVAL;
136136

@@ -211,11 +211,13 @@ static int io_import_umem(struct io_zcrx_ifq *ifq,
211211
if (ret)
212212
goto out_err;
213213

214-
ret = dma_map_sgtable(ifq->dev, &mem->page_sg_table,
215-
DMA_FROM_DEVICE, IO_DMA_ATTR);
216-
if (ret < 0)
217-
goto out_err;
218-
mapped = true;
214+
if (ifq->dev) {
215+
ret = dma_map_sgtable(ifq->dev, &mem->page_sg_table,
216+
DMA_FROM_DEVICE, IO_DMA_ATTR);
217+
if (ret < 0)
218+
goto out_err;
219+
mapped = true;
220+
}
219221

220222
mem->account_pages = io_count_account_pages(pages, nr_pages);
221223
ret = io_account_mem(ifq->user, ifq->mm_account, mem->account_pages);
@@ -450,7 +452,8 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
450452
ret = io_import_area(ifq, &area->mem, area_reg);
451453
if (ret)
452454
goto err;
453-
area->is_mapped = true;
455+
if (ifq->dev)
456+
area->is_mapped = true;
454457

455458
if (buf_size_shift > io_area_max_shift(&area->mem)) {
456459
ret = -ERANGE;
@@ -486,9 +489,11 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
486489
niov->type = NET_IOV_IOURING;
487490
}
488491

489-
ret = io_populate_area_dma(ifq, area);
490-
if (ret)
491-
goto err;
492+
if (ifq->dev) {
493+
ret = io_populate_area_dma(ifq, area);
494+
if (ret)
495+
goto err;
496+
}
492497

493498
area->free_count = nr_iovs;
494499
/* we're only supporting one area per ifq for now */
@@ -826,6 +831,8 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
826831
return -EFAULT;
827832
if (reg.if_rxq == -1 || !reg.rq_entries)
828833
return -EINVAL;
834+
if ((reg.if_rxq || reg.if_idx) && (reg.flags & ZCRX_REG_NODEV))
835+
return -EINVAL;
829836
if (reg.rq_entries > IO_RQ_MAX_ENTRIES) {
830837
if (!(ctx->flags & IORING_SETUP_CLAMP))
831838
return -EINVAL;
@@ -861,9 +868,15 @@ int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
861868
if (ret)
862869
goto err;
863870

864-
ret = zcrx_register_netdev(ifq, &reg, &area);
865-
if (ret)
866-
goto err;
871+
if (!(reg.flags & ZCRX_REG_NODEV)) {
872+
ret = zcrx_register_netdev(ifq, &reg, &area);
873+
if (ret)
874+
goto err;
875+
} else {
876+
ret = io_zcrx_create_area(ifq, &area, &reg);
877+
if (ret)
878+
goto err;
879+
}
867880

868881
reg.zcrx_id = id;
869882

io_uring/zcrx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <net/page_pool/types.h>
99
#include <net/net_trackers.h>
1010

11-
#define ZCRX_SUPPORTED_REG_FLAGS (ZCRX_REG_IMPORT)
11+
#define ZCRX_SUPPORTED_REG_FLAGS (ZCRX_REG_IMPORT | ZCRX_REG_NODEV)
1212
#define ZCRX_FEATURES (ZCRX_FEATURE_RX_PAGE_SIZE)
1313

1414
struct io_zcrx_mem {

0 commit comments

Comments
 (0)