* [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec
@ 2025-03-15 17:23 Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd Sidong Yang
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Sidong Yang @ 2025-03-15 17:23 UTC (permalink / raw)
To: Josef Bacik, David Sterba, Jens Axboe, Pavel Begunkov
Cc: linux-btrfs, linux-kernel, io-uring, Sidong Yang
This patche series introduce io_uring_cmd_import_vec. With this function,
Multiple fixed buffer could be used in uring cmd. It's vectored version
for io_uring_cmd_import_fixed(). Also this patch series includes a usage
for new api for encoded read/write in btrfs by using uring cmd.
There was approximately 10 percent of performance improvements through benchmark.
The benchmark code is in
https://github.com/SidongYang/btrfs-encoded-io-test/blob/main/main.c
./main -l
Elapsed time: 0.598997 seconds
./main -l -f
Elapsed time: 0.540332 seconds
v2:
- don't export iou_vc, use bvec for btrfs
- use io_is_compat for checking compat
- reduce allocation/free for import fixed vec
v3:
- add iou_vec cache in io_uring_cmd and use it
- also encoded write fixed supported
Sidong Yang (3):
io-uring/cmd: add iou_vec field for io_uring_cmd
io-uring/cmd: introduce io_uring_cmd_import_fixed_vec
btrfs: ioctl: introduce btrfs_uring_import_iovec()
fs/btrfs/ioctl.c | 32 +++++++++++++++++++++--------
include/linux/io_uring/cmd.h | 15 ++++++++++++++
io_uring/io_uring.c | 2 +-
io_uring/opdef.c | 1 +
io_uring/uring_cmd.c | 39 ++++++++++++++++++++++++++++++++++++
io_uring/uring_cmd.h | 3 +++
6 files changed, 83 insertions(+), 9 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd
2025-03-15 17:23 [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Sidong Yang
@ 2025-03-15 17:23 ` Sidong Yang
2025-03-16 7:24 ` Pavel Begunkov
2025-03-15 17:23 ` [RFC PATCH v3 2/3] io-uring/cmd: introduce io_uring_cmd_import_fixed_vec Sidong Yang
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Sidong Yang @ 2025-03-15 17:23 UTC (permalink / raw)
To: Josef Bacik, David Sterba, Jens Axboe, Pavel Begunkov
Cc: linux-btrfs, linux-kernel, io-uring, Sidong Yang
This patch adds iou_vec field for io_uring_cmd. Also it needs to be
cleanup for cache. It could be used in uring cmd api that imports
multiple fixed buffers.
Signed-off-by: Sidong Yang <[email protected]>
---
include/linux/io_uring/cmd.h | 1 +
io_uring/io_uring.c | 2 +-
io_uring/opdef.c | 1 +
io_uring/uring_cmd.c | 20 ++++++++++++++++++++
io_uring/uring_cmd.h | 3 +++
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
index 598cacda4aa3..74b9f0aec229 100644
--- a/include/linux/io_uring/cmd.h
+++ b/include/linux/io_uring/cmd.h
@@ -22,6 +22,7 @@ struct io_uring_cmd {
struct io_uring_cmd_data {
void *op_data;
struct io_uring_sqe sqes[2];
+ struct iou_vec iou_vec;
};
static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 5ff30a7092ed..55334fa53abf 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)
io_alloc_cache_free(&ctx->apoll_cache, kfree);
io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
- io_alloc_cache_free(&ctx->uring_cache, kfree);
+ io_alloc_cache_free(&ctx->uring_cache, io_cmd_cache_free);
io_alloc_cache_free(&ctx->msg_cache, kfree);
io_futex_cache_free(ctx);
io_rsrc_cache_free(ctx);
diff --git a/io_uring/opdef.c b/io_uring/opdef.c
index 7fd173197b1e..e275180c2077 100644
--- a/io_uring/opdef.c
+++ b/io_uring/opdef.c
@@ -755,6 +755,7 @@ const struct io_cold_def io_cold_defs[] = {
},
[IORING_OP_URING_CMD] = {
.name = "URING_CMD",
+ .cleanup = io_uring_cmd_cleanup,
},
[IORING_OP_SEND_ZC] = {
.name = "SEND_ZC",
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index de39b602aa82..315c603cfdd4 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -28,6 +28,13 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
if (issue_flags & IO_URING_F_UNLOCKED)
return;
+
+ req->flags &= ~REQ_F_NEED_CLEANUP;
+
+ io_alloc_cache_vec_kasan(&cache->iou_vec);
+ if (cache->iou_vec.nr > IO_VEC_CACHE_SOFT_CAP)
+ io_vec_free(&cache->iou_vec);
+
if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) {
ioucmd->sqe = NULL;
req->async_data = NULL;
@@ -35,6 +42,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
}
}
+void io_uring_cmd_cleanup(struct io_kiocb *req)
+{
+ io_req_uring_cleanup(req, 0);
+}
+
bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
struct io_uring_task *tctx, bool cancel_all)
{
@@ -339,3 +351,11 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
}
EXPORT_SYMBOL_GPL(io_uring_cmd_sock);
#endif
+
+void io_cmd_cache_free(const void *entry)
+{
+ struct io_uring_cmd_data *cache = (struct io_uring_cmd_data *)entry;
+
+ io_vec_free(&cache->iou_vec);
+ kfree(cache);
+}
diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h
index f6837ee0955b..d2b9c1522e22 100644
--- a/io_uring/uring_cmd.h
+++ b/io_uring/uring_cmd.h
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/io_uring_types.h>
int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
+void io_uring_cmd_cleanup(struct io_kiocb *req);
bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
struct io_uring_task *tctx, bool cancel_all);
+void io_cmd_cache_free(const void *entry);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC PATCH v3 2/3] io-uring/cmd: introduce io_uring_cmd_import_fixed_vec
2025-03-15 17:23 [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd Sidong Yang
@ 2025-03-15 17:23 ` Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 3/3] btrfs: ioctl: introduce btrfs_uring_import_iovec() Sidong Yang
2025-03-16 7:22 ` [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Pavel Begunkov
3 siblings, 0 replies; 8+ messages in thread
From: Sidong Yang @ 2025-03-15 17:23 UTC (permalink / raw)
To: Josef Bacik, David Sterba, Jens Axboe, Pavel Begunkov
Cc: linux-btrfs, linux-kernel, io-uring, Sidong Yang
io_uring_cmd_import_fixed_vec() could be used for using multiple
fixed buffer in uring_cmd callback.
Signed-off-by: Sidong Yang <[email protected]>
---
include/linux/io_uring/cmd.h | 14 ++++++++++++++
io_uring/uring_cmd.c | 19 +++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
index 74b9f0aec229..2c7ae8474a56 100644
--- a/include/linux/io_uring/cmd.h
+++ b/include/linux/io_uring/cmd.h
@@ -45,6 +45,12 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
struct io_uring_cmd *ioucmd,
unsigned int issue_flags);
+int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
+ const struct iovec __user *uvec,
+ unsigned long uvec_segs, int ddir,
+ unsigned int issue_flags,
+ struct iov_iter *iter);
+
/*
* Completes the request, i.e. posts an io_uring CQE and deallocates @ioucmd
* and the corresponding io_uring request.
@@ -77,6 +83,14 @@ io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
{
return -EOPNOTSUPP;
}
+int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
+ const struct iovec __user *uvec,
+ unsigned long uvec_segs, int ddir,
+ unsigned int issue_flags,
+ struct iov_iter *iter)
+{
+ return -EOPNOTSUPP;
+}
static inline void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret,
u64 ret2, unsigned issue_flags)
{
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index 315c603cfdd4..e2bf9edca9df 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -267,6 +267,25 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
}
EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed);
+int io_uring_cmd_import_fixed_vec(struct io_uring_cmd *ioucmd,
+ const struct iovec __user *uvec,
+ unsigned long uvec_segs, int ddir,
+ unsigned int issue_flags,
+ struct iov_iter *iter)
+{
+ struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
+ struct io_uring_cmd_data *cache = req->async_data;
+ int ret;
+
+ ret = io_prep_reg_iovec(req, &cache->iou_vec, uvec, uvec_segs);
+ if (ret)
+ return ret;
+
+ return io_import_reg_vec(ddir, iter, req, &cache->iou_vec,
+ cache->iou_vec.nr, issue_flags);
+}
+EXPORT_SYMBOL_GPL(io_uring_cmd_import_fixed_vec);
+
void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd)
{
struct io_kiocb *req = cmd_to_io_kiocb(ioucmd);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC PATCH v3 3/3] btrfs: ioctl: introduce btrfs_uring_import_iovec()
2025-03-15 17:23 [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 2/3] io-uring/cmd: introduce io_uring_cmd_import_fixed_vec Sidong Yang
@ 2025-03-15 17:23 ` Sidong Yang
2025-03-16 7:22 ` [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Pavel Begunkov
3 siblings, 0 replies; 8+ messages in thread
From: Sidong Yang @ 2025-03-15 17:23 UTC (permalink / raw)
To: Josef Bacik, David Sterba, Jens Axboe, Pavel Begunkov
Cc: linux-btrfs, linux-kernel, io-uring, Sidong Yang
This patch introduces btrfs_uring_import_iovec(). In encoded read/write
with uring cmd, it uses import_iovec without supporting fixed buffer.
btrfs_using_import_iovec() could use fixed buffer if cmd flags has
IORING_URING_CMD_FIXED.
Signed-off-by: Sidong Yang <[email protected]>
---
fs/btrfs/ioctl.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 6c18bad53cd3..a7b52fd99059 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4802,6 +4802,28 @@ struct btrfs_uring_encoded_data {
struct iov_iter iter;
};
+static int btrfs_uring_import_iovec(struct io_uring_cmd *cmd,
+ unsigned int issue_flags, int rw)
+{
+ struct btrfs_uring_encoded_data *data =
+ io_uring_cmd_get_async_data(cmd)->op_data;
+ int ret;
+
+ if (cmd && (cmd->flags & IORING_URING_CMD_FIXED)) {
+ data->iov = NULL;
+ ret = io_uring_cmd_import_fixed_vec(cmd, data->args.iov,
+ data->args.iovcnt,
+ ITER_DEST, issue_flags,
+ &data->iter);
+ } else {
+ data->iov = data->iovstack;
+ ret = import_iovec(rw, data->args.iov, data->args.iovcnt,
+ ARRAY_SIZE(data->iovstack), &data->iov,
+ &data->iter);
+ }
+ return ret;
+}
+
static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue_flags)
{
size_t copy_end_kernel = offsetofend(struct btrfs_ioctl_encoded_io_args, flags);
@@ -4874,10 +4896,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
goto out_acct;
}
- data->iov = data->iovstack;
- ret = import_iovec(ITER_DEST, data->args.iov, data->args.iovcnt,
- ARRAY_SIZE(data->iovstack), &data->iov,
- &data->iter);
+ ret = btrfs_uring_import_iovec(cmd, issue_flags, ITER_DEST);
if (ret < 0)
goto out_acct;
@@ -5022,10 +5041,7 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
if (data->args.len > data->args.unencoded_len - data->args.unencoded_offset)
goto out_acct;
- data->iov = data->iovstack;
- ret = import_iovec(ITER_SOURCE, data->args.iov, data->args.iovcnt,
- ARRAY_SIZE(data->iovstack), &data->iov,
- &data->iter);
+ ret = btrfs_uring_import_iovec(cmd, issue_flags, ITER_SOURCE);
if (ret < 0)
goto out_acct;
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec
2025-03-15 17:23 [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Sidong Yang
` (2 preceding siblings ...)
2025-03-15 17:23 ` [RFC PATCH v3 3/3] btrfs: ioctl: introduce btrfs_uring_import_iovec() Sidong Yang
@ 2025-03-16 7:22 ` Pavel Begunkov
3 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2025-03-16 7:22 UTC (permalink / raw)
To: Sidong Yang, Josef Bacik, David Sterba, Jens Axboe,
Mark Harmstone
Cc: linux-btrfs, linux-kernel, io-uring
On 3/15/25 17:23, Sidong Yang wrote:
> This patche series introduce io_uring_cmd_import_vec. With this function,
> Multiple fixed buffer could be used in uring cmd. It's vectored version
> for io_uring_cmd_import_fixed(). Also this patch series includes a usage
> for new api for encoded read/write in btrfs by using uring cmd.
>
> There was approximately 10 percent of performance improvements through benchmark.
> The benchmark code is in
> https://github.com/SidongYang/btrfs-encoded-io-test/blob/main/main.c
>
> ./main -l
> Elapsed time: 0.598997 seconds
> ./main -l -f
> Elapsed time: 0.540332 seconds
It's probably precise, but it's usually hard to judge about
performance from such short runs. Mark, do we have some benchmark
for the io_uring cmd?
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd
2025-03-15 17:23 ` [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd Sidong Yang
@ 2025-03-16 7:24 ` Pavel Begunkov
2025-03-16 8:02 ` Sidong Yang
0 siblings, 1 reply; 8+ messages in thread
From: Pavel Begunkov @ 2025-03-16 7:24 UTC (permalink / raw)
To: Sidong Yang, Josef Bacik, David Sterba, Jens Axboe
Cc: linux-btrfs, linux-kernel, io-uring
On 3/15/25 17:23, Sidong Yang wrote:
> This patch adds iou_vec field for io_uring_cmd. Also it needs to be
> cleanup for cache. It could be used in uring cmd api that imports
> multiple fixed buffers.
Sidong, I think you accidentially erased my authorship over the
patch. The only difference I see is that you rebased it and dropped
prep patches by placing iou_vec into struct io_uring_cmd_data. And
the prep patch was mandatory, once something is exported there is
a good chance it gets [ab]used, and iou_vec is not ready for it.
> Signed-off-by: Sidong Yang <[email protected]>
> ---
> include/linux/io_uring/cmd.h | 1 +
> io_uring/io_uring.c | 2 +-
> io_uring/opdef.c | 1 +
> io_uring/uring_cmd.c | 20 ++++++++++++++++++++
> io_uring/uring_cmd.h | 3 +++
> 5 files changed, 26 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
> index 598cacda4aa3..74b9f0aec229 100644
> --- a/include/linux/io_uring/cmd.h
> +++ b/include/linux/io_uring/cmd.h
> @@ -22,6 +22,7 @@ struct io_uring_cmd {
> struct io_uring_cmd_data {
> void *op_data;
> struct io_uring_sqe sqes[2];
> + struct iou_vec iou_vec;
> };
>
> static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
> diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> index 5ff30a7092ed..55334fa53abf 100644
> --- a/io_uring/io_uring.c
> +++ b/io_uring/io_uring.c
> @@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)
> io_alloc_cache_free(&ctx->apoll_cache, kfree);
> io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
> io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
> - io_alloc_cache_free(&ctx->uring_cache, kfree);
> + io_alloc_cache_free(&ctx->uring_cache, io_cmd_cache_free);
> io_alloc_cache_free(&ctx->msg_cache, kfree);
> io_futex_cache_free(ctx);
> io_rsrc_cache_free(ctx);
> diff --git a/io_uring/opdef.c b/io_uring/opdef.c
> index 7fd173197b1e..e275180c2077 100644
> --- a/io_uring/opdef.c
> +++ b/io_uring/opdef.c
> @@ -755,6 +755,7 @@ const struct io_cold_def io_cold_defs[] = {
> },
> [IORING_OP_URING_CMD] = {
> .name = "URING_CMD",
> + .cleanup = io_uring_cmd_cleanup,
> },
> [IORING_OP_SEND_ZC] = {
> .name = "SEND_ZC",
> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> index de39b602aa82..315c603cfdd4 100644
> --- a/io_uring/uring_cmd.c
> +++ b/io_uring/uring_cmd.c
> @@ -28,6 +28,13 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
>
> if (issue_flags & IO_URING_F_UNLOCKED)
> return;
> +
> + req->flags &= ~REQ_F_NEED_CLEANUP;
> +
> + io_alloc_cache_vec_kasan(&cache->iou_vec);
> + if (cache->iou_vec.nr > IO_VEC_CACHE_SOFT_CAP)
> + io_vec_free(&cache->iou_vec);
> +
> if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) {
> ioucmd->sqe = NULL;
> req->async_data = NULL;
> @@ -35,6 +42,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
> }
> }
>
> +void io_uring_cmd_cleanup(struct io_kiocb *req)
> +{
> + io_req_uring_cleanup(req, 0);
> +}
> +
> bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> struct io_uring_task *tctx, bool cancel_all)
> {
> @@ -339,3 +351,11 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
> }
> EXPORT_SYMBOL_GPL(io_uring_cmd_sock);
> #endif
> +
> +void io_cmd_cache_free(const void *entry)
> +{
> + struct io_uring_cmd_data *cache = (struct io_uring_cmd_data *)entry;
> +
> + io_vec_free(&cache->iou_vec);
> + kfree(cache);
> +}
> diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h
> index f6837ee0955b..d2b9c1522e22 100644
> --- a/io_uring/uring_cmd.h
> +++ b/io_uring/uring_cmd.h
> @@ -1,7 +1,10 @@
> // SPDX-License-Identifier: GPL-2.0
> +#include <linux/io_uring_types.h>
>
> int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
> int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
> +void io_uring_cmd_cleanup(struct io_kiocb *req);
>
> bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> struct io_uring_task *tctx, bool cancel_all);
> +void io_cmd_cache_free(const void *entry);
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd
2025-03-16 7:24 ` Pavel Begunkov
@ 2025-03-16 8:02 ` Sidong Yang
2025-03-16 8:49 ` Sidong Yang
0 siblings, 1 reply; 8+ messages in thread
From: Sidong Yang @ 2025-03-16 8:02 UTC (permalink / raw)
To: Pavel Begunkov
Cc: Josef Bacik, David Sterba, Jens Axboe, linux-btrfs, linux-kernel,
io-uring
On Sun, Mar 16, 2025 at 07:24:32AM +0000, Pavel Begunkov wrote:
> On 3/15/25 17:23, Sidong Yang wrote:
> > This patch adds iou_vec field for io_uring_cmd. Also it needs to be
> > cleanup for cache. It could be used in uring cmd api that imports
> > multiple fixed buffers.
>
> Sidong, I think you accidentially erased my authorship over the
> patch. The only difference I see is that you rebased it and dropped
> prep patches by placing iou_vec into struct io_uring_cmd_data. And
> the prep patch was mandatory, once something is exported there is
> a good chance it gets [ab]used, and iou_vec is not ready for it.
Yes, First I thought it's not mandatory for this function. But it seems that
it's needed. I see that your patch hides all fields in io_uring_cmd_data but
op_data needed to be accessable for btrfs cmd. And I'll take a look for the
code referencing sqes in io_uring_cmd_data. Let me add the commit for next
version v4.
Thanks,
Sidong
>
>
> > Signed-off-by: Sidong Yang <[email protected]>
> > ---
> > include/linux/io_uring/cmd.h | 1 +
> > io_uring/io_uring.c | 2 +-
> > io_uring/opdef.c | 1 +
> > io_uring/uring_cmd.c | 20 ++++++++++++++++++++
> > io_uring/uring_cmd.h | 3 +++
> > 5 files changed, 26 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
> > index 598cacda4aa3..74b9f0aec229 100644
> > --- a/include/linux/io_uring/cmd.h
> > +++ b/include/linux/io_uring/cmd.h
> > @@ -22,6 +22,7 @@ struct io_uring_cmd {
> > struct io_uring_cmd_data {
> > void *op_data;
> > struct io_uring_sqe sqes[2];
> > + struct iou_vec iou_vec;
> > };
> > static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
> > diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> > index 5ff30a7092ed..55334fa53abf 100644
> > --- a/io_uring/io_uring.c
> > +++ b/io_uring/io_uring.c
> > @@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)
> > io_alloc_cache_free(&ctx->apoll_cache, kfree);
> > io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
> > io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
> > - io_alloc_cache_free(&ctx->uring_cache, kfree);
> > + io_alloc_cache_free(&ctx->uring_cache, io_cmd_cache_free);
> > io_alloc_cache_free(&ctx->msg_cache, kfree);
> > io_futex_cache_free(ctx);
> > io_rsrc_cache_free(ctx);
> > diff --git a/io_uring/opdef.c b/io_uring/opdef.c
> > index 7fd173197b1e..e275180c2077 100644
> > --- a/io_uring/opdef.c
> > +++ b/io_uring/opdef.c
> > @@ -755,6 +755,7 @@ const struct io_cold_def io_cold_defs[] = {
> > },
> > [IORING_OP_URING_CMD] = {
> > .name = "URING_CMD",
> > + .cleanup = io_uring_cmd_cleanup,
> > },
> > [IORING_OP_SEND_ZC] = {
> > .name = "SEND_ZC",
> > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> > index de39b602aa82..315c603cfdd4 100644
> > --- a/io_uring/uring_cmd.c
> > +++ b/io_uring/uring_cmd.c
> > @@ -28,6 +28,13 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
> > if (issue_flags & IO_URING_F_UNLOCKED)
> > return;
> > +
> > + req->flags &= ~REQ_F_NEED_CLEANUP;
> > +
> > + io_alloc_cache_vec_kasan(&cache->iou_vec);
> > + if (cache->iou_vec.nr > IO_VEC_CACHE_SOFT_CAP)
> > + io_vec_free(&cache->iou_vec);
> > +
> > if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) {
> > ioucmd->sqe = NULL;
> > req->async_data = NULL;
> > @@ -35,6 +42,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
> > }
> > }
> > +void io_uring_cmd_cleanup(struct io_kiocb *req)
> > +{
> > + io_req_uring_cleanup(req, 0);
> > +}
> > +
> > bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> > struct io_uring_task *tctx, bool cancel_all)
> > {
> > @@ -339,3 +351,11 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
> > }
> > EXPORT_SYMBOL_GPL(io_uring_cmd_sock);
> > #endif
> > +
> > +void io_cmd_cache_free(const void *entry)
> > +{
> > + struct io_uring_cmd_data *cache = (struct io_uring_cmd_data *)entry;
> > +
> > + io_vec_free(&cache->iou_vec);
> > + kfree(cache);
> > +}
> > diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h
> > index f6837ee0955b..d2b9c1522e22 100644
> > --- a/io_uring/uring_cmd.h
> > +++ b/io_uring/uring_cmd.h
> > @@ -1,7 +1,10 @@
> > // SPDX-License-Identifier: GPL-2.0
> > +#include <linux/io_uring_types.h>
> > int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
> > int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
> > +void io_uring_cmd_cleanup(struct io_kiocb *req);
> > bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> > struct io_uring_task *tctx, bool cancel_all);
> > +void io_cmd_cache_free(const void *entry);
>
> --
> Pavel Begunkov
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd
2025-03-16 8:02 ` Sidong Yang
@ 2025-03-16 8:49 ` Sidong Yang
0 siblings, 0 replies; 8+ messages in thread
From: Sidong Yang @ 2025-03-16 8:49 UTC (permalink / raw)
To: Pavel Begunkov
Cc: Josef Bacik, David Sterba, Jens Axboe, linux-btrfs, linux-kernel,
io-uring
On Sun, Mar 16, 2025 at 05:02:19PM +0900, Sidong Yang wrote:
> On Sun, Mar 16, 2025 at 07:24:32AM +0000, Pavel Begunkov wrote:
> > On 3/15/25 17:23, Sidong Yang wrote:
> > > This patch adds iou_vec field for io_uring_cmd. Also it needs to be
> > > cleanup for cache. It could be used in uring cmd api that imports
> > > multiple fixed buffers.
> >
> > Sidong, I think you accidentially erased my authorship over the
> > patch. The only difference I see is that you rebased it and dropped
> > prep patches by placing iou_vec into struct io_uring_cmd_data. And
> > the prep patch was mandatory, once something is exported there is
> > a good chance it gets [ab]used, and iou_vec is not ready for it.
>
> Yes, First I thought it's not mandatory for this function. But it seems that
> it's needed. I see that your patch hides all fields in io_uring_cmd_data but
> op_data needed to be accessable for btrfs cmd. And I'll take a look for the
> code referencing sqes in io_uring_cmd_data. Let me add the commit for next
> version v4.
I've just realized that your commit don't need to be modified. It's okay to
cast async_data to io_uring_cmd_data.
Thanks,
Sidong
>
> Thanks,
> Sidong
>
> >
> >
> > > Signed-off-by: Sidong Yang <[email protected]>
> > > ---
> > > include/linux/io_uring/cmd.h | 1 +
> > > io_uring/io_uring.c | 2 +-
> > > io_uring/opdef.c | 1 +
> > > io_uring/uring_cmd.c | 20 ++++++++++++++++++++
> > > io_uring/uring_cmd.h | 3 +++
> > > 5 files changed, 26 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/include/linux/io_uring/cmd.h b/include/linux/io_uring/cmd.h
> > > index 598cacda4aa3..74b9f0aec229 100644
> > > --- a/include/linux/io_uring/cmd.h
> > > +++ b/include/linux/io_uring/cmd.h
> > > @@ -22,6 +22,7 @@ struct io_uring_cmd {
> > > struct io_uring_cmd_data {
> > > void *op_data;
> > > struct io_uring_sqe sqes[2];
> > > + struct iou_vec iou_vec;
> > > };
> > > static inline const void *io_uring_sqe_cmd(const struct io_uring_sqe *sqe)
> > > diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
> > > index 5ff30a7092ed..55334fa53abf 100644
> > > --- a/io_uring/io_uring.c
> > > +++ b/io_uring/io_uring.c
> > > @@ -289,7 +289,7 @@ static void io_free_alloc_caches(struct io_ring_ctx *ctx)
> > > io_alloc_cache_free(&ctx->apoll_cache, kfree);
> > > io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
> > > io_alloc_cache_free(&ctx->rw_cache, io_rw_cache_free);
> > > - io_alloc_cache_free(&ctx->uring_cache, kfree);
> > > + io_alloc_cache_free(&ctx->uring_cache, io_cmd_cache_free);
> > > io_alloc_cache_free(&ctx->msg_cache, kfree);
> > > io_futex_cache_free(ctx);
> > > io_rsrc_cache_free(ctx);
> > > diff --git a/io_uring/opdef.c b/io_uring/opdef.c
> > > index 7fd173197b1e..e275180c2077 100644
> > > --- a/io_uring/opdef.c
> > > +++ b/io_uring/opdef.c
> > > @@ -755,6 +755,7 @@ const struct io_cold_def io_cold_defs[] = {
> > > },
> > > [IORING_OP_URING_CMD] = {
> > > .name = "URING_CMD",
> > > + .cleanup = io_uring_cmd_cleanup,
> > > },
> > > [IORING_OP_SEND_ZC] = {
> > > .name = "SEND_ZC",
> > > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> > > index de39b602aa82..315c603cfdd4 100644
> > > --- a/io_uring/uring_cmd.c
> > > +++ b/io_uring/uring_cmd.c
> > > @@ -28,6 +28,13 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
> > > if (issue_flags & IO_URING_F_UNLOCKED)
> > > return;
> > > +
> > > + req->flags &= ~REQ_F_NEED_CLEANUP;
> > > +
> > > + io_alloc_cache_vec_kasan(&cache->iou_vec);
> > > + if (cache->iou_vec.nr > IO_VEC_CACHE_SOFT_CAP)
> > > + io_vec_free(&cache->iou_vec);
> > > +
> > > if (io_alloc_cache_put(&req->ctx->uring_cache, cache)) {
> > > ioucmd->sqe = NULL;
> > > req->async_data = NULL;
> > > @@ -35,6 +42,11 @@ static void io_req_uring_cleanup(struct io_kiocb *req, unsigned int issue_flags)
> > > }
> > > }
> > > +void io_uring_cmd_cleanup(struct io_kiocb *req)
> > > +{
> > > + io_req_uring_cleanup(req, 0);
> > > +}
> > > +
> > > bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> > > struct io_uring_task *tctx, bool cancel_all)
> > > {
> > > @@ -339,3 +351,11 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags)
> > > }
> > > EXPORT_SYMBOL_GPL(io_uring_cmd_sock);
> > > #endif
> > > +
> > > +void io_cmd_cache_free(const void *entry)
> > > +{
> > > + struct io_uring_cmd_data *cache = (struct io_uring_cmd_data *)entry;
> > > +
> > > + io_vec_free(&cache->iou_vec);
> > > + kfree(cache);
> > > +}
> > > diff --git a/io_uring/uring_cmd.h b/io_uring/uring_cmd.h
> > > index f6837ee0955b..d2b9c1522e22 100644
> > > --- a/io_uring/uring_cmd.h
> > > +++ b/io_uring/uring_cmd.h
> > > @@ -1,7 +1,10 @@
> > > // SPDX-License-Identifier: GPL-2.0
> > > +#include <linux/io_uring_types.h>
> > > int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags);
> > > int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
> > > +void io_uring_cmd_cleanup(struct io_kiocb *req);
> > > bool io_uring_try_cancel_uring_cmd(struct io_ring_ctx *ctx,
> > > struct io_uring_task *tctx, bool cancel_all);
> > > +void io_cmd_cache_free(const void *entry);
> >
> > --
> > Pavel Begunkov
> >
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-03-16 8:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-15 17:23 [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 1/3] io-uring/cmd: add iou_vec field for io_uring_cmd Sidong Yang
2025-03-16 7:24 ` Pavel Begunkov
2025-03-16 8:02 ` Sidong Yang
2025-03-16 8:49 ` Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 2/3] io-uring/cmd: introduce io_uring_cmd_import_fixed_vec Sidong Yang
2025-03-15 17:23 ` [RFC PATCH v3 3/3] btrfs: ioctl: introduce btrfs_uring_import_iovec() Sidong Yang
2025-03-16 7:22 ` [RFC PATCH v3 0/3] introduce io_uring_cmd_import_fixed_vec Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox