Skip to content

Commit 439a98b

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: deduplicate area mapping
With a common type for storing dma addresses and io_populate_area_dma(), type-specific area mapping helpers are trivial, so open code them and deduplicate the call to io_populate_area_dma(). Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 02bb047 commit 439a98b

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

io_uring/zcrx.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,6 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
157157
return ret;
158158
}
159159

160-
static int io_zcrx_map_area_dmabuf(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
161-
{
162-
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
163-
return -EINVAL;
164-
return io_populate_area_dma(ifq, area, area->mem.sgt,
165-
area->mem.dmabuf_offset);
166-
}
167-
168160
static unsigned long io_count_account_pages(struct page **pages, unsigned nr_pages)
169161
{
170162
struct folio *last_folio = NULL;
@@ -275,30 +267,29 @@ static void io_zcrx_unmap_area(struct io_zcrx_ifq *ifq,
275267
}
276268
}
277269

278-
static unsigned io_zcrx_map_area_umem(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
279-
{
280-
int ret;
281-
282-
ret = dma_map_sgtable(ifq->dev, &area->mem.page_sg_table,
283-
DMA_FROM_DEVICE, IO_DMA_ATTR);
284-
if (ret < 0)
285-
return ret;
286-
return io_populate_area_dma(ifq, area, &area->mem.page_sg_table, 0);
287-
}
288-
289270
static int io_zcrx_map_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
290271
{
272+
unsigned long offset;
273+
struct sg_table *sgt;
291274
int ret;
292275

293276
guard(mutex)(&ifq->dma_lock);
294277
if (area->is_mapped)
295278
return 0;
296279

297-
if (area->mem.is_dmabuf)
298-
ret = io_zcrx_map_area_dmabuf(ifq, area);
299-
else
300-
ret = io_zcrx_map_area_umem(ifq, area);
280+
if (!area->mem.is_dmabuf) {
281+
ret = dma_map_sgtable(ifq->dev, &area->mem.page_sg_table,
282+
DMA_FROM_DEVICE, IO_DMA_ATTR);
283+
if (ret < 0)
284+
return ret;
285+
sgt = &area->mem.page_sg_table;
286+
offset = 0;
287+
} else {
288+
sgt = area->mem.sgt;
289+
offset = area->mem.dmabuf_offset;
290+
}
301291

292+
ret = io_populate_area_dma(ifq, area, sgt, offset);
302293
if (ret == 0)
303294
area->is_mapped = true;
304295
return ret;

0 commit comments

Comments
 (0)