From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [PATCH v4 3/6] io_uring/zcrx: introduce io_populate_area_dma
Date: Wed, 2 Jul 2025 15:29:06 +0100 [thread overview]
Message-ID: <a8972a77be9b5675abc585d6e2e6e30f9c7dbd85.1751466461.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1751466461.git.asml.silence@gmail.com>
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 <asml.silence@gmail.com>
---
io_uring/zcrx.c | 56 +++++++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 25 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 2cde88988260..cef0763010a0 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -47,6 +47,35 @@ static inline struct page *io_zcrx_iov_page(const struct net_iov *niov)
return area->mem.pages[net_iov_idx(niov)];
}
+static int io_populate_area_dma(struct io_zcrx_ifq *ifq,
+ struct io_zcrx_area *area,
+ struct sg_table *sgt, unsigned long off)
+{
+ struct scatterlist *sg;
+ unsigned i, niov_idx = 0;
+
+ for_each_sgtable_dma_sg(sgt, sg, i) {
+ dma_addr_t dma = sg_dma_address(sg);
+ unsigned long sg_len = sg_dma_len(sg);
+ unsigned long sg_off = min(sg_len, off);
+
+ off -= sg_off;
+ sg_len -= sg_off;
+ dma += sg_off;
+
+ while (sg_len && niov_idx < area->nia.num_niovs) {
+ struct net_iov *niov = &area->nia.niovs[niov_idx];
+
+ if (net_mp_niov_set_dma_addr(niov, dma))
+ return -EFAULT;
+ sg_len -= PAGE_SIZE;
+ dma += PAGE_SIZE;
+ niov_idx++;
+ }
+ }
+ return 0;
+}
+
static void io_release_dmabuf(struct io_zcrx_mem *mem)
{
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
@@ -119,33 +148,10 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
static int io_zcrx_map_area_dmabuf(struct io_zcrx_ifq *ifq, struct io_zcrx_area *area)
{
- unsigned long off = area->mem.dmabuf_offset;
- struct scatterlist *sg;
- unsigned i, niov_idx = 0;
-
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EINVAL;
-
- for_each_sgtable_dma_sg(area->mem.sgt, sg, i) {
- dma_addr_t dma = sg_dma_address(sg);
- unsigned long sg_len = sg_dma_len(sg);
- unsigned long sg_off = min(sg_len, off);
-
- off -= sg_off;
- sg_len -= sg_off;
- dma += sg_off;
-
- while (sg_len && niov_idx < area->nia.num_niovs) {
- struct net_iov *niov = &area->nia.niovs[niov_idx];
-
- if (net_mp_niov_set_dma_addr(niov, dma))
- return -EFAULT;
- sg_len -= PAGE_SIZE;
- dma += PAGE_SIZE;
- niov_idx++;
- }
- }
- return 0;
+ return io_populate_area_dma(ifq, area, area->mem.sgt,
+ area->mem.dmabuf_offset);
}
static int io_import_umem(struct io_zcrx_ifq *ifq,
--
2.49.0
next prev parent reply other threads:[~2025-07-02 14:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 14:29 [PATCH v4 0/6] zcrx huge pages support Vol 1 Pavel Begunkov
2025-07-02 14:29 ` [PATCH v4 1/6] io_uring/zcrx: always pass page to io_zcrx_copy_chunk Pavel Begunkov
2025-07-02 22:32 ` David Wei
2025-07-02 14:29 ` [PATCH v4 2/6] io_uring/zcrx: return error from io_zcrx_map_area_* Pavel Begunkov
2025-07-02 22:27 ` David Wei
2025-07-02 22:50 ` Pavel Begunkov
2025-07-02 23:20 ` David Wei
2025-07-02 14:29 ` Pavel Begunkov [this message]
2025-07-02 23:13 ` [PATCH v4 3/6] io_uring/zcrx: introduce io_populate_area_dma David Wei
2025-07-02 14:29 ` [PATCH v4 4/6] io_uring/zcrx: allocate sgtable for umem areas Pavel Begunkov
2025-07-02 23:16 ` David Wei
2025-07-02 14:29 ` [PATCH v4 5/6] io_uring/zcrx: assert area type in io_zcrx_iov_page Pavel Begunkov
2025-07-02 14:29 ` [PATCH v4 6/6] io_uring/zcrx: prepare fallback for larger pages Pavel Begunkov
2025-07-02 23:12 ` [PATCH v4 0/6] zcrx huge pages support Vol 1 David Wei
2025-07-02 23:51 ` Pavel Begunkov
2025-07-08 18:00 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8972a77be9b5675abc585d6e2e6e30f9c7dbd85.1751466461.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox