From 06897ddfc523cea415bd139148c5276b8b61b016 Mon Sep 17 00:00:00 2001 From: Pavel Begunkov Date: Wed, 2 Jul 2025 15:29:05 +0100 Subject: [PATCH] io_uring/zcrx: return error from io_zcrx_map_area_* io_zcrx_map_area_*() helpers return the number of processed niovs, which we use to unroll some of the mappings for user memory areas. It's unhandy, and dmabuf doesn't care about it. Return an error code instead and move failure partial unmapping into io_zcrx_map_area_umem(). Signed-off-by: Pavel Begunkov Reviewed-by: David Wei Link: https://lore.kernel.org/r/42668e82be3a84b07ee8fc76d1d6d5ac0f137fe5.1751466461.git.asml.silence@gmail.com Signed-off-by: Jens Axboe --- io_uring/zcrx.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c index e94a4647d409b..6fb7c9bedfcb1 100644 --- a/io_uring/zcrx.c +++ b/io_uring/zcrx.c @@ -141,13 +141,13 @@ static int io_zcrx_map_area_dmabuf(struct io_zcrx_ifq *ifq, struct io_zcrx_area struct net_iov *niov = &area->nia.niovs[niov_idx]; if (net_mp_niov_set_dma_addr(niov, dma)) - return 0; + return -EFAULT; sg_len -= PAGE_SIZE; dma += PAGE_SIZE; niov_idx++; } } - return niov_idx; + return 0; } static int io_import_umem(struct io_zcrx_ifq *ifq, @@ -256,29 +256,30 @@ static int io_zcrx_map_area_umem(struct io_zcrx_ifq *ifq, struct io_zcrx_area *a break; } } - return i; + + if (i != area->nia.num_niovs) { + __io_zcrx_unmap_area(ifq, area, i); + return -EINVAL; + } + return 0; } static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area) { - unsigned nr; + int ret; guard(mutex)(&ifq->dma_lock); if (area->is_mapped) return 0; if (area->mem.is_dmabuf) - nr = io_zcrx_map_area_dmabuf(ifq, area); + ret = io_zcrx_map_area_dmabuf(ifq, area); else - nr = io_zcrx_map_area_umem(ifq, area); + ret = io_zcrx_map_area_umem(ifq, area); - if (nr != area->nia.num_niovs) { - __io_zcrx_unmap_area(ifq, area, nr); - return -EINVAL; - } - - area->is_mapped = true; - return 0; + if (ret == 0) + area->is_mapped = true; + return ret; } static void io_zcrx_sync_for_device(const struct page_pool *pool, -- 2.47.2