Message ID | 20250315172319.16770-2-sidong.yang@furiosa.ai (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | introduce io_uring_cmd_import_fixed_vec | expand |
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 <sidong.yang@furiosa.ai> > --- > 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);
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 <sidong.yang@furiosa.ai> > > --- > > 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 >
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 <sidong.yang@furiosa.ai> > > > --- > > > 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 > >
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);
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 <sidong.yang@furiosa.ai> --- 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(-)