From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Wei <dw@davidwei.uk>
Subject: [PATCH 1/4] io_uring/zcrx: add helper for importing user memory
Date: Tue, 22 Apr 2025 15:44:41 +0100 [thread overview]
Message-ID: <5e65726b486cad8fef0b6650997d69f3eb585e4a.1745328503.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1745328503.git.asml.silence@gmail.com>
There are two distinct steps for creating an area. First, we import
user memory, and then populate net_iov. In preparation to changes for
the first step, extract a helper function for it.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/zcrx.c | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index a8a9b79d3c23..0f9375e889c3 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -203,13 +203,38 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
kfree(area);
}
+static int io_import_area_memory(struct io_zcrx_ifq *ifq,
+ struct io_zcrx_area *area,
+ struct io_uring_zcrx_area_reg *area_reg)
+{
+ struct iovec iov;
+ int nr_pages;
+ int ret;
+
+ iov.iov_base = u64_to_user_ptr(area_reg->addr);
+ iov.iov_len = area_reg->len;
+ ret = io_buffer_validate(&iov);
+ if (ret)
+ return ret;
+
+ area->pages = io_pin_pages((unsigned long)area_reg->addr, area_reg->len,
+ &nr_pages);
+ if (IS_ERR(area->pages)) {
+ ret = PTR_ERR(area->pages);
+ area->pages = NULL;
+ return ret;
+ }
+ area->nr_folios = nr_pages;
+ return 0;
+}
+
static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
struct io_zcrx_area **res,
struct io_uring_zcrx_area_reg *area_reg)
{
+ unsigned nr_iovs = area_reg->len >> PAGE_SHIFT;
struct io_zcrx_area *area;
- int i, ret, nr_pages, nr_iovs;
- struct iovec iov;
+ int i, ret;
if (area_reg->flags || area_reg->rq_area_token)
return -EINVAL;
@@ -218,27 +243,17 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
if (area_reg->addr & ~PAGE_MASK || area_reg->len & ~PAGE_MASK)
return -EINVAL;
- iov.iov_base = u64_to_user_ptr(area_reg->addr);
- iov.iov_len = area_reg->len;
- ret = io_buffer_validate(&iov);
- if (ret)
- return ret;
-
ret = -ENOMEM;
area = kzalloc(sizeof(*area), GFP_KERNEL);
if (!area)
goto err;
+ area->nia.num_niovs = nr_iovs;
- area->pages = io_pin_pages((unsigned long)area_reg->addr, area_reg->len,
- &nr_pages);
- if (IS_ERR(area->pages)) {
- ret = PTR_ERR(area->pages);
- area->pages = NULL;
+ ret = io_import_area_memory(ifq, area, area_reg);
+ if (ret)
goto err;
- }
- area->nr_folios = nr_iovs = nr_pages;
- area->nia.num_niovs = nr_iovs;
+ ret = -ENOMEM;
area->nia.niovs = kvmalloc_array(nr_iovs, sizeof(area->nia.niovs[0]),
GFP_KERNEL | __GFP_ZERO);
if (!area->nia.niovs)
--
2.48.1
next prev parent reply other threads:[~2025-04-22 14:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-22 14:44 [PATCH 0/4] preparation for zcrx with huge pages Pavel Begunkov
2025-04-22 14:44 ` Pavel Begunkov [this message]
2025-04-22 14:44 ` [PATCH 2/4] io_uring/zcrx: add initial infra for large pages Pavel Begunkov
2025-04-22 14:44 ` [PATCH 3/4] io_uring: export io_coalesce_buffer() Pavel Begunkov
2025-04-22 14:44 ` [PATCH 4/4] io_uring/zcrx: coalesce areas with huge pages Pavel Begunkov
2025-04-25 14:01 ` [PATCH 0/4] preparation for zcrx " Pavel Begunkov
2025-04-25 15:42 ` David Wei
2025-04-26 0:01 ` Pavel Begunkov
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=5e65726b486cad8fef0b6650997d69f3eb585e4a.1745328503.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=dw@davidwei.uk \
--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