Skip to contentSkip to conversation

random fixes

PATCH Applied Pavel Begunkov 2 participants 7 messages Feb 20, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover random fixes

Just two unrelated fixes batched together.

Pavel Begunkov (2):
io_uring: wait potential ->release() on resurrect
io_uring: fix leaving invalid req->flags

 fs/io_uring.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/2 io_uring: wait potential ->release() on resurrect

There is a short window where percpu_refs are already turned zero, but we try to do resurrect(). Play nicer and wait for all users to leave RCU section.

---
 fs/io_uring.c | 2 ++
 1 file changed, 2 insertions(+)
fs/io_uring.c +2 -0
index f3af499b12a9..ce5fccf00367 100644
@@ -7351,6 +7351,7 @@ static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
 			break;
 
 		percpu_ref_resurrect(&data->refs);
+		synchronize_rcu();
 		io_sqe_rsrc_set_node(ctx, data, backup_node);
 		reinit_completion(&data->done);
 		mutex_unlock(&ctx->uring_lock);
@@ -10089,6 +10090,7 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
 
 		if (ret) {
 			percpu_ref_resurrect(&ctx->refs);
+			synchronize_rcu();
 			goto out_quiesce;
 		}
 	}
Signature · 1 line
2.24.0
#5 lore raw

PATCH 2/2 io_uring: fix leaving invalid req->flags

In reply to Pavel Begunkov

sqe->flags are subset of req flags, so incorrectly copied may span into in-kernel flags and wreck havoc, e.g. by setting REQ_F_INFLIGHT.

Fixes 5be9ad1e4287e ("io_uring: optimise io_init_req() flags setting")
---
 fs/io_uring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/io_uring.c +3 -1
index ce5fccf00367..2bd10f89b837 100644
@@ -6687,8 +6687,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
 	req->result = 0;
 
 	/* enforce forwards compatibility on users */
-	if (unlikely(sqe_flags & ~SQE_VALID_FLAGS))
+	if (unlikely(sqe_flags & ~SQE_VALID_FLAGS)) {
+		req->flags = 0;
 		return -EINVAL;
+	}
 
 	if (unlikely(req->opcode >= IORING_OP_LAST))
 		return -EINVAL;
Signature · 1 line
2.24.0
maintainer
#2 lore raw

Re: [PATCH 1/2] io_uring: wait potential ->release() on resurrect

In reply to Pavel Begunkov
Quoted 3 lines · Pavel Begunkov

There is a short window where percpu_refs are already turned zero, but we try to do resurrect(). Play nicer and wait for all users to leave RCU section.

We need to do something better than synchronize_rcu() here, that can take a long time on a loaded box. I'll try and think about this one.

Signature · 1 line
Jens Axboe
#3 lore raw

Re: [PATCH 1/2] io_uring: wait potential ->release() on resurrect

Quoted 7 lines · Jens Axboe
Quoted 3 lines · Pavel Begunkov

There is a short window where percpu_refs are already turned zero, but we try to do resurrect(). Play nicer and wait for all users to leave RCU section.

We need to do something better than synchronize_rcu() here, that can take a long time on a loaded box. I'll try and think about this one.

It only happens when it can't be drained and there are task_works or signals. I have another patch, doing it via tryget, but it's uglier and I'd rather prefer synchronize_rcu for stable.

Want me to send it tomorrow (on top or not)?

Signature · 1 line
Pavel Begunkov
maintainer
#4 lore raw

Re: [PATCH 1/2] io_uring: wait potential ->release() on resurrect

Quoted 6 lines · Pavel Begunkov
Quoted 5 lines · Jens Axboe
Quoted 3 lines · Pavel Begunkov

There is a short window where percpu_refs are already turned zero, but we try to do resurrect(). Play nicer and wait for all users to leave RCU section.

Quoted 6 lines
Quoted 2 lines

We need to do something better than synchronize_rcu() here, that can take a long time on a loaded box. I'll try and think about this one.

It only happens when it can't be drained and there are task_works or signals. I have another patch, doing it via tryget, but it's uglier and I'd rather prefer synchronize_rcu for stable.

Right, but the task_work coming in may not be unlikely. So it's not strictly an error path.

Signature · 1 line
Jens Axboe
maintainer Applied
#6 lore raw

Re: [PATCH 2/2] io_uring: fix leaving invalid req->flags

In reply to Pavel Begunkov
Quoted 2 lines · Pavel Begunkov

sqe->flags are subset of req flags, so incorrectly copied may span into in-kernel flags and wreck havoc, e.g. by setting REQ_F_INFLIGHT.

Applied, thanks.

Signature · 1 line
Jens Axboe