Skip to contentSkip to conversation

FAILED: patch "[PATCH] io_uring/kbuf: defer release of mapped buffer rings" failed to apply to 6.6-stable tree

PATCH [email protected] 2 participants 3 messages Dec 3, 2023

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x c392cbecd8eca4c53f2bf508731257d9d0a21c2d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120359-fit-broom-4a79@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Possible dependencies:

c392cbecd8ec ("io_uring/kbuf: defer release of mapped buffer rings")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From c392cbecd8eca4c53f2bf508731257d9d0a21c2d Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Mon, 27 Nov 2023 16:47:04 -0700
Subject: [PATCH] io_uring/kbuf: defer release of mapped buffer rings

If a provided buffer ring is setup with IOU_PBUF_RING_MMAP, then the kernel allocates the memory for it and the application is expected to mmap(2) this memory. However, io_uring uses remap_pfn_range() for this operation, so we cannot rely on normal munmap/release on freeing them for us.

Stash an io_buf_free entry away for each of these, if any, and provide a helper to free them post ->release().

Fixes c56e022c0a27 ("io_uring: add support for user mapped provided buffer ring")
include/linux/io_uring_types.h +3 -0
index d3009d56af0b..805bb635cdf5 100644
@@ -340,6 +340,9 @@ struct io_ring_ctx {
 
 	struct list_head	io_buffers_cache;
 
+	/* deferred free list, protected by ->uring_lock */
+	struct hlist_head	io_buf_list;
+
 	/* Keep this last, we don't need it for the fast path */
 	struct wait_queue_head		poll_wq;
 	struct io_restriction		restrictions;
io_uring/io_uring.c +2 -0
index e40b11438210..3a216f0744dd 100644
@@ -325,6 +325,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
 	INIT_LIST_HEAD(&ctx->sqd_list);
 	INIT_LIST_HEAD(&ctx->cq_overflow_list);
 	INIT_LIST_HEAD(&ctx->io_buffers_cache);
+	INIT_HLIST_HEAD(&ctx->io_buf_list);
 	io_alloc_cache_init(&ctx->rsrc_node_cache, IO_NODE_ALLOC_CACHE_MAX,
 			    sizeof(struct io_rsrc_node));
 	io_alloc_cache_init(&ctx->apoll_cache, IO_ALLOC_CACHE_MAX,
@@ -2950,6 +2951,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
 		ctx->mm_account = NULL;
 	}
 	io_rings_free(ctx);
+	io_kbuf_mmap_list_free(ctx);
 
 	percpu_ref_exit(&ctx->refs);
 	free_uid(ctx->user);
io_uring/kbuf.c +39 -5

80 lines not on this page · raw message

io_uring/kbuf.h +2 -0
index f2d615236b2c..6c7646e6057c 100644
@@ -51,6 +51,8 @@ int io_provide_buffers(struct io_kiocb *req, unsigned int issue_flags);
 int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg);
 int io_unregister_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg);
 
+void io_kbuf_mmap_list_free(struct io_ring_ctx *ctx);
+
 unsigned int __io_put_kbuf(struct io_kiocb *req, unsigned issue_flags);
 
 bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags);
maintainer
#1 lore raw
Quoted 6 lines · On 12/3/23 6:47 AM, [email protected] wrote:

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

Quoted 8 lines

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x c392cbecd8eca4c53f2bf508731257d9d0a21c2d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120359-fit-broom-4a79@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Pick this one first:

commit edecf1689768452ba1a64b7aaf3a47a817da651a

Author: Jens Axboe <[email protected]>
Date:   Mon Nov 27 20:53:52 2023 -0700

io_uring: enable io_mem_alloc/free to be used in other parts

then it'll work fine.

Signature · 1 line
Jens Axboe
author maintainer
#2 lore raw
Quoted 18 lines · Jens Axboe
Quoted 6 lines · On 12/3/23 6:47 AM, [email protected] wrote:

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

Quoted 8 lines

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x c392cbecd8eca4c53f2bf508731257d9d0a21c2d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120359-fit-broom-4a79@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Pick this one first:

Quoted 7 lines

commit edecf1689768452ba1a64b7aaf3a47a817da651a

Author: Jens Axboe <[email protected]>
Date:   Mon Nov 27 20:53:52 2023 -0700

io_uring: enable io_mem_alloc/free to be used in other parts

then it'll work fine.

Thanks, that worked!

greg k-h