提交 0afec0da 编写于 作者: P Pavel Begunkov 提交者: Cheng Jian

io_uring: order refnode recycling

mainline inclusion
from mainline-5.10-rc5
commit e297822b
category: feature
bugzilla: 27
CVE: NA
---------------------------

Don't recycle a refnode until we're done with all requests of nodes
ejected before.
Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: Nyangerkun <yangerkun@huawei.com>
Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 2d606ae0
...@@ -199,6 +199,7 @@ struct fixed_file_ref_node { ...@@ -199,6 +199,7 @@ struct fixed_file_ref_node {
struct list_head file_list; struct list_head file_list;
struct fixed_file_data *file_data; struct fixed_file_data *file_data;
struct llist_node llist; struct llist_node llist;
bool done;
}; };
struct fixed_file_data { struct fixed_file_data {
...@@ -6884,10 +6885,6 @@ static void __io_file_put_work(struct fixed_file_ref_node *ref_node) ...@@ -6884,10 +6885,6 @@ static void __io_file_put_work(struct fixed_file_ref_node *ref_node)
kfree(pfile); kfree(pfile);
} }
spin_lock(&file_data->lock);
list_del(&ref_node->node);
spin_unlock(&file_data->lock);
percpu_ref_exit(&ref_node->refs); percpu_ref_exit(&ref_node->refs);
kfree(ref_node); kfree(ref_node);
percpu_ref_put(&file_data->refs); percpu_ref_put(&file_data->refs);
...@@ -6914,17 +6911,32 @@ static void io_file_put_work(struct work_struct *work) ...@@ -6914,17 +6911,32 @@ static void io_file_put_work(struct work_struct *work)
static void io_file_data_ref_zero(struct percpu_ref *ref) static void io_file_data_ref_zero(struct percpu_ref *ref)
{ {
struct fixed_file_ref_node *ref_node; struct fixed_file_ref_node *ref_node;
struct fixed_file_data *data;
struct io_ring_ctx *ctx; struct io_ring_ctx *ctx;
bool first_add; bool first_add = false;
int delay = HZ; int delay = HZ;
ref_node = container_of(ref, struct fixed_file_ref_node, refs); 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; delay = 0;
first_add = llist_add(&ref_node->llist, &ctx->file_put_llist);
if (!delay) if (!delay)
mod_delayed_work(system_wq, &ctx->file_put_work, 0); mod_delayed_work(system_wq, &ctx->file_put_work, 0);
else if (first_add) else if (first_add)
...@@ -6948,6 +6960,7 @@ static struct fixed_file_ref_node *alloc_fixed_file_ref_node( ...@@ -6948,6 +6960,7 @@ static struct fixed_file_ref_node *alloc_fixed_file_ref_node(
INIT_LIST_HEAD(&ref_node->node); INIT_LIST_HEAD(&ref_node->node);
INIT_LIST_HEAD(&ref_node->file_list); INIT_LIST_HEAD(&ref_node->file_list);
ref_node->file_data = ctx->file_data; ref_node->file_data = ctx->file_data;
ref_node->done = false;
return ref_node; return ref_node;
} }
...@@ -7043,7 +7056,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, ...@@ -7043,7 +7056,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
file_data->node = ref_node; file_data->node = ref_node;
spin_lock(&file_data->lock); spin_lock(&file_data->lock);
list_add(&ref_node->node, &file_data->ref_list); list_add_tail(&ref_node->node, &file_data->ref_list);
spin_unlock(&file_data->lock); spin_unlock(&file_data->lock);
percpu_ref_get(&file_data->refs); percpu_ref_get(&file_data->refs);
return ret; return ret;
...@@ -7202,7 +7215,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx, ...@@ -7202,7 +7215,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
if (needs_switch) { if (needs_switch) {
percpu_ref_kill(&data->node->refs); percpu_ref_kill(&data->node->refs);
spin_lock(&data->lock); spin_lock(&data->lock);
list_add(&ref_node->node, &data->ref_list); list_add_tail(&ref_node->node, &data->ref_list);
data->node = ref_node; data->node = ref_node;
spin_unlock(&data->lock); spin_unlock(&data->lock);
percpu_ref_get(&ctx->file_data->refs); percpu_ref_get(&ctx->file_data->refs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册