stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data
@ 2020-11-23 22:34 Pavel Begunkov
  2020-11-23 22:34 ` [PATCH 2/2][5.9 backport] io_uring: order refnode recycling Pavel Begunkov
  2020-11-24 16:50 ` [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Begunkov @ 2020-11-23 22:34 UTC (permalink / raw)
  To: gregkh, stable; +Cc: Jens Axboe

commit 1e5d770bb8a23dd01e28e92f4fb0b1093c8bdbe6 upstream

An active ref_node always can be found in ctx->files_data, it's much
safer to get it this way instead of poking into files_data->ref_list.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/io_uring.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 352bd3ad446b..24c0ad17ec4c 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -6855,9 +6855,8 @@ static int io_sqe_files_unregister(struct io_ring_ctx *ctx)
 		return -ENXIO;
 
 	spin_lock(&data->lock);
-	if (!list_empty(&data->ref_list))
-		ref_node = list_first_entry(&data->ref_list,
-				struct fixed_file_ref_node, node);
+	ref_node = container_of(data->cur_refs, struct fixed_file_ref_node,
+				refs);
 	spin_unlock(&data->lock);
 	if (ref_node)
 		percpu_ref_kill(&ref_node->refs);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2][5.9 backport] io_uring: order refnode recycling
  2020-11-23 22:34 [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Pavel Begunkov
@ 2020-11-23 22:34 ` Pavel Begunkov
  2020-11-24 16:50 ` [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Begunkov @ 2020-11-23 22:34 UTC (permalink / raw)
  To: gregkh, stable; +Cc: Jens Axboe

commit e297822b20e7fe683e107aea46e6402adcf99c70 upstream

Don't recycle a refnode until we're done with all requests of nodes
ejected before.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 fs/io_uring.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 24c0ad17ec4c..e98e58d1f690 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -200,6 +200,7 @@ struct fixed_file_ref_node {
 	struct list_head		file_list;
 	struct fixed_file_data		*file_data;
 	struct llist_node		llist;
+	bool				done;
 };
 
 struct fixed_file_data {
@@ -7107,10 +7108,6 @@ static void __io_file_put_work(struct fixed_file_ref_node *ref_node)
 		kfree(pfile);
 	}
 
-	spin_lock(&file_data->lock);
-	list_del(&ref_node->node);
-	spin_unlock(&file_data->lock);
-
 	percpu_ref_exit(&ref_node->refs);
 	kfree(ref_node);
 	percpu_ref_put(&file_data->refs);
@@ -7137,17 +7134,33 @@ static void io_file_put_work(struct work_struct *work)
 static void io_file_data_ref_zero(struct percpu_ref *ref)
 {
 	struct fixed_file_ref_node *ref_node;
+	struct fixed_file_data *data;
 	struct io_ring_ctx *ctx;
-	bool first_add;
+	bool first_add = false;
 	int delay = HZ;
 
 	ref_node = container_of(ref, struct fixed_file_ref_node, refs);
-	ctx = ref_node->file_data->ctx;
+	data = ref_node->file_data;
+	ctx = data->ctx;
+
+	spin_lock(&data->lock);
+	ref_node->done = true;
+
+	while (!list_empty(&data->ref_list)) {
+		ref_node = list_first_entry(&data->ref_list,
+					struct fixed_file_ref_node, node);
+		/* recycle ref nodes in order */
+		if (!ref_node->done)
+			break;
+		list_del(&ref_node->node);
+		first_add |= llist_add(&ref_node->llist, &ctx->file_put_llist);
+	}
+	spin_unlock(&data->lock);
+
 
-	if (percpu_ref_is_dying(&ctx->file_data->refs))
+	if (percpu_ref_is_dying(&data->refs))
 		delay = 0;
 
-	first_add = llist_add(&ref_node->llist, &ctx->file_put_llist);
 	if (!delay)
 		mod_delayed_work(system_wq, &ctx->file_put_work, 0);
 	else if (first_add)
@@ -7171,6 +7184,7 @@ static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
 	INIT_LIST_HEAD(&ref_node->node);
 	INIT_LIST_HEAD(&ref_node->file_list);
 	ref_node->file_data = ctx->file_data;
+	ref_node->done = false;
 	return ref_node;
 }
 
@@ -7298,7 +7312,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 
 	ctx->file_data->cur_refs = &ref_node->refs;
 	spin_lock(&ctx->file_data->lock);
-	list_add(&ref_node->node, &ctx->file_data->ref_list);
+	list_add_tail(&ref_node->node, &ctx->file_data->ref_list);
 	spin_unlock(&ctx->file_data->lock);
 	percpu_ref_get(&ctx->file_data->refs);
 	return ret;
@@ -7443,7 +7457,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 	if (needs_switch) {
 		percpu_ref_kill(data->cur_refs);
 		spin_lock(&data->lock);
-		list_add(&ref_node->node, &data->ref_list);
+		list_add_tail(&ref_node->node, &data->ref_list);
 		data->cur_refs = &ref_node->refs;
 		spin_unlock(&data->lock);
 		percpu_ref_get(&ctx->file_data->refs);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data
  2020-11-23 22:34 [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Pavel Begunkov
  2020-11-23 22:34 ` [PATCH 2/2][5.9 backport] io_uring: order refnode recycling Pavel Begunkov
@ 2020-11-24 16:50 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2020-11-24 16:50 UTC (permalink / raw)
  To: Pavel Begunkov; +Cc: stable, Jens Axboe

On Mon, Nov 23, 2020 at 10:34:06PM +0000, Pavel Begunkov wrote:
> commit 1e5d770bb8a23dd01e28e92f4fb0b1093c8bdbe6 upstream
> 
> An active ref_node always can be found in ctx->files_data, it's much
> safer to get it this way instead of poking into files_data->ref_list.
> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> Cc: stable@vger.kernel.org # v5.7+
> Signed-off-by: Jens Axboe <axboe@kernel.dk>
> ---
>  fs/io_uring.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Both patches now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-24 16:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 22:34 [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Pavel Begunkov
2020-11-23 22:34 ` [PATCH 2/2][5.9 backport] io_uring: order refnode recycling Pavel Begunkov
2020-11-24 16:50 ` [PATCH 1/2][5.9 backport] io_uring: get an active ref_node from files_data Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).