Skip to content

Commit 06897dd

Browse files
isilenceaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: David Wei <[email protected]> Link: https://lore.kernel.org/r/42668e82be3a84b07ee8fc76d1d6d5ac0f137fe5.1751466461.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent e9a9ddb commit 06897dd

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

io_uring/zcrx.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ static int io_zcrx_map_area_dmabuf(struct io_zcrx_ifq *ifq, struct io_zcrx_area
141141
struct net_iov *niov = &area->nia.niovs[niov_idx];
142142

143143
if (net_mp_niov_set_dma_addr(niov, dma))
144-
return 0;
144+
return -EFAULT;
145145
sg_len -= PAGE_SIZE;
146146
dma += PAGE_SIZE;
147147
niov_idx++;
148148
}
149149
}
150-
return niov_idx;
150+
return 0;
151151
}
152152

153153
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
256256
break;
257257
}
258258
}
259-
return i;
259+
260+
if (i != area->nia.num_niovs) {
261+
__io_zcrx_unmap_area(ifq, area, i);
262+
return -EINVAL;
263+
}
264+
return 0;
260265
}
261266

262267
static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
263268
{
264-
unsigned nr;
269+
int ret;
265270

266271
guard(mutex)(&ifq->dma_lock);
267272
if (area->is_mapped)
268273
return 0;
269274

270275
if (area->mem.is_dmabuf)
271-
nr = io_zcrx_map_area_dmabuf(ifq, area);
276+
ret = io_zcrx_map_area_dmabuf(ifq, area);
272277
else
273-
nr = io_zcrx_map_area_umem(ifq, area);
278+
ret = io_zcrx_map_area_umem(ifq, area);
274279

275-
if (nr != area->nia.num_niovs) {
276-
__io_zcrx_unmap_area(ifq, area, nr);
277-
return -EINVAL;
278-
}
279-
280-
area->is_mapped = true;
281-
return 0;
280+
if (ret == 0)
281+
area->is_mapped = true;
282+
return ret;
282283
}
283284

284285
static void io_zcrx_sync_for_device(const struct page_pool *pool,

0 commit comments

Comments
 (0)