Skip to content

Commit 54e89a9

Browse files
isilenceaxboe
authored andcommitted
io_uring/zcrx: introduce io_populate_area_dma
Add a helper that initialises page-pool dma addresses from a sg table. It'll be reused in following patches. Signed-off-by: Pavel Begunkov <[email protected]> Reviewed-by: David Wei <[email protected]> Link: https://lore.kernel.org/r/a8972a77be9b5675abc585d6e2e6e30f9c7dbd85.1751466461.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 06897dd commit 54e89a9

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

io_uring/zcrx.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ static inline struct page *io_zcrx_iov_page(const struct net_iov *niov)
4747
return area->mem.pages[net_iov_idx(niov)];
4848
}
4949

50+
static int io_populate_area_dma(struct io_zcrx_ifq *ifq,
51+
struct io_zcrx_area *area,
52+
struct sg_table *sgt, unsigned long off)
53+
{
54+
struct scatterlist *sg;
55+
unsigned i, niov_idx = 0;
56+
57+
for_each_sgtable_dma_sg(sgt, sg, i) {
58+
dma_addr_t dma = sg_dma_address(sg);
59+
unsigned long sg_len = sg_dma_len(sg);
60+
unsigned long sg_off = min(sg_len, off);
61+
62+
off -= sg_off;
63+
sg_len -= sg_off;
64+
dma += sg_off;
65+
66+
while (sg_len && niov_idx < area->nia.num_niovs) {
67+
struct net_iov *niov = &area->nia.niovs[niov_idx];
68+
69+
if (net_mp_niov_set_dma_addr(niov, dma))
70+
return -EFAULT;
71+
sg_len -= PAGE_SIZE;
72+
dma += PAGE_SIZE;
73+
niov_idx++;
74+
}
75+
}
76+
return 0;
77+
}
78+
5079
static void io_release_dmabuf(struct io_zcrx_mem *mem)
5180
{
5281
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
@@ -121,33 +150,10 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
121150

122151
static int io_zcrx_map_area_dmabuf(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
123152
{
124-
unsigned long off = area->mem.dmabuf_offset;
125-
struct scatterlist *sg;
126-
unsigned i, niov_idx = 0;
127-
128153
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
129154
return -EINVAL;
130-
131-
for_each_sgtable_dma_sg(area->mem.sgt, sg, i) {
132-
dma_addr_t dma = sg_dma_address(sg);
133-
unsigned long sg_len = sg_dma_len(sg);
134-
unsigned long sg_off = min(sg_len, off);
135-
136-
off -= sg_off;
137-
sg_len -= sg_off;
138-
dma += sg_off;
139-
140-
while (sg_len && niov_idx < area->nia.num_niovs) {
141-
struct net_iov *niov = &area->nia.niovs[niov_idx];
142-
143-
if (net_mp_niov_set_dma_addr(niov, dma))
144-
return -EFAULT;
145-
sg_len -= PAGE_SIZE;
146-
dma += PAGE_SIZE;
147-
niov_idx++;
148-
}
149-
}
150-
return 0;
155+
return io_populate_area_dma(ifq, area, area->mem.sgt,
156+
area->mem.dmabuf_offset);
151157
}
152158

153159
static int io_import_umem(struct io_zcrx_ifq *ifq,

0 commit comments

Comments
 (0)