Skip to contentSkip to conversation

io_uring: fix duplicated increase of cached_cq_overflow

PATCH In review Bob Liu 2 participants 6 messages Nov 15, 2019

Subsystems (2)
lore
Share & tools
lore

Bob Liu

author
#0 lore raw

PATCH 1/1 io_uring: fix duplicated increase of cached_cq_overflow

cached_cq_overflow already be increased in function io_cqring_overflow_flush().

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index 55f8b1d..eb23451 100644
@@ -701,7 +701,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
 		WRITE_ONCE(cqe->flags, 0);
 	} else if (ctx->cq_overflow_flushed) {
 		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
+				atomic_read(&ctx->cached_cq_overflow));
 	} else {
 		refcount_inc(&req->refs);
 		req->result = res;
Signature · 1 line
2.9.5
#1 lore raw
Quoted 13 lines · Bob Liu

cached_cq_overflow already be increased in function io_cqring_overflow_flush().

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +0 -0
index 55f8b1d..eb23451 100644

fs/io_uring.c static void io_cqring_fill_event(struct io_kiocb *req, long res) · line 704

Quoted 5 lines
fs/io_uring.c +1 -1
@@ -701,7 +701,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
 		WRITE_ONCE(cqe->flags, 0);
 	} else if (ctx->cq_overflow_flushed) {
 		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
+				atomic_read(&ctx->cached_cq_overflow));

Not really. It won't get into io_cqring_overflow_flush() if this branch is executed. See, it's enqueued for overflow in "else" right below.

i.e. list_add_tail(&req->list, &ctx->cq_overflow_list);

Quoted 4 lines
fs/io_uring.c +0 -0
 	} else {
 		refcount_inc(&req->refs);
 		req->result = res;
Signature · 1 line
Pavel Begunkov
author
#2 lore raw
Quoted 9 lines · Pavel Begunkov
Quoted 8 lines · Bob Liu

cached_cq_overflow already be increased in function io_cqring_overflow_flush().

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

fs/io_uring.c static void io_cqring_fill_event(struct io_kiocb *req, long res) · line 704

Quoted 10 lines
fs/io_uring.c +1 -1
index 55f8b1d..eb23451 100644
@@ -701,7 +701,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
 		WRITE_ONCE(cqe->flags, 0);
 	} else if (ctx->cq_overflow_flushed) {
 		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
+				atomic_read(&ctx->cached_cq_overflow));

Not really. It won't get into io_cqring_overflow_flush() if this branch is executed.

io_cqring_overflow_flush(force=true) must have been called when this branch is executed, since io_cqring_overflow_flush() is the only place can set 'ctx->cq_overflow_flushed' to true.

And 'ctx->cached_cq_overflow' may already be increased in io_cqring_overflow_flush() if force is true and cqe==NULL.

static void io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)

{
	...
        if (force)
                ctx->cq_overflow_flushed = true;
                
        while (!list_empty(&ctx->cq_overflow_list)) {
                cqe = io_get_cqring(ctx);
                if (!cqe && !force)
                        break;
                        
                req = list_first_entry(&ctx->cq_overflow_list, struct io_kiocb,
                                                list);
                list_move(&req->list, &list);   
                if (cqe) {
			...
                } else {
                        WRITE_ONCE(ctx->rings->cq_overflow,
                                atomic_inc_return(&ctx->cached_cq_overflow));
			  ^^^^^^^^^^^
			  ctx->cached_cq_overflow is increased if 'force=true' and 'ceq==NULL'.

Did I miss anything?

Quoted 8 lines

See, it's enqueued for overflow in "else" right below.

i.e. list_add_tail(&req->list, &ctx->cq_overflow_list);

Quoted 4 lines
fs/io_uring.c +0 -0
 	} else {
 		refcount_inc(&req->refs);
 		req->result = res;
#3 lore raw
Quoted 24 lines · Bob Liu
Quoted 9 lines · Pavel Begunkov
Quoted 8 lines · Bob Liu

cached_cq_overflow already be increased in function io_cqring_overflow_flush().

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

fs/io_uring.c static void io_cqring_fill_event(struct io_kiocb *req, long res) · line 704

Quoted 10 lines
fs/io_uring.c +1 -1
index 55f8b1d..eb23451 100644
@@ -701,7 +701,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
 		WRITE_ONCE(cqe->flags, 0);
 	} else if (ctx->cq_overflow_flushed) {
 		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
+				atomic_read(&ctx->cached_cq_overflow));

Not really. It won't get into io_cqring_overflow_flush() if this branch is executed.

Quoted 3 lines

io_cqring_overflow_flush(force=true) must have been called when this branch is executed, since io_cqring_overflow_flush() is the only place can set 'ctx->cq_overflow_flushed' to true.

Yes, it should have been called, but it sets this flag for the future users of io_cqring_fill_event(), so any _new_ requests in io_cqring_fill_event() will overflow instead of being added to @overflow_list.

Either a request completes/overflows in io_cqring_fill_event(), or it would be added to @overflow_list to be processed by io_cqring_overflow_flush().

Quoted 36 lines

And 'ctx->cached_cq_overflow' may already be increased in io_cqring_overflow_flush() if force is true and cqe==NULL.

static void io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)

{
	...
        if (force)
                ctx->cq_overflow_flushed = true;
                
        while (!list_empty(&ctx->cq_overflow_list)) {
                cqe = io_get_cqring(ctx);
                if (!cqe && !force)
                        break;
                        
                req = list_first_entry(&ctx->cq_overflow_list, struct io_kiocb,
                                                list);
                list_move(&req->list, &list);   
                if (cqe) {
			...
                } else {
                        WRITE_ONCE(ctx->rings->cq_overflow,
                                atomic_inc_return(&ctx->cached_cq_overflow));
			  ^^^^^^^^^^^
			  ctx->cached_cq_overflow is increased if 'force=true' and 'ceq==NULL'.

Did I miss anything?

Quoted 8 lines

See, it's enqueued for overflow in "else" right below.

i.e. list_add_tail(&req->list, &ctx->cq_overflow_list);

Quoted 4 lines
fs/io_uring.c +0 -0
 	} else {
 		refcount_inc(&req->refs);
 		req->result = res;
author
#4 lore raw
Quoted 25 lines · Pavel Begunkov
Quoted 24 lines · Bob Liu
Quoted 22 lines · Pavel Begunkov
Quoted 13 lines · Bob Liu

cached_cq_overflow already be increased in function io_cqring_overflow_flush().

---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +0 -0
index 55f8b1d..eb23451 100644

fs/io_uring.c static void io_cqring_fill_event(struct io_kiocb *req, long res) · line 704

Quoted 5 lines
fs/io_uring.c +1 -1
@@ -701,7 +701,7 @@ static void io_cqring_fill_event(struct io_kiocb *req, long res)
 		WRITE_ONCE(cqe->flags, 0);
 	} else if (ctx->cq_overflow_flushed) {
 		WRITE_ONCE(ctx->rings->cq_overflow,
-				atomic_inc_return(&ctx->cached_cq_overflow));
+				atomic_read(&ctx->cached_cq_overflow));

Not really. It won't get into io_cqring_overflow_flush() if this branch is executed.

Quoted 8 lines
Quoted 3 lines

io_cqring_overflow_flush(force=true) must have been called when this branch is executed, since io_cqring_overflow_flush() is the only place can set 'ctx->cq_overflow_flushed' to true.

Yes, it should have been called, but it sets this flag for the future users of io_cqring_fill_event(), so any _new_ requests in io_cqring_fill_event() will overflow instead of being added to @overflow_list.

Oh, I see..Thanks for the kindly explanation.

Quoted 41 lines

Either a request completes/overflows in io_cqring_fill_event(), or it would be added to @overflow_list to be processed by io_cqring_overflow_flush().

Quoted 36 lines

And 'ctx->cached_cq_overflow' may already be increased in io_cqring_overflow_flush() if force is true and cqe==NULL.

static void io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)

{
	...
        if (force)
                ctx->cq_overflow_flushed = true;
                
        while (!list_empty(&ctx->cq_overflow_list)) {
                cqe = io_get_cqring(ctx);
                if (!cqe && !force)
                        break;
                        
                req = list_first_entry(&ctx->cq_overflow_list, struct io_kiocb,
                                                list);
                list_move(&req->list, &list);   
                if (cqe) {
			...
                } else {
                        WRITE_ONCE(ctx->rings->cq_overflow,
                                atomic_inc_return(&ctx->cached_cq_overflow));
			  ^^^^^^^^^^^
			  ctx->cached_cq_overflow is increased if 'force=true' and 'ceq==NULL'.

Did I miss anything?

Quoted 8 lines

See, it's enqueued for overflow in "else" right below.

i.e. list_add_tail(&req->list, &ctx->cq_overflow_list);

Quoted 4 lines
fs/io_uring.c +0 -0
 	} else {
 		refcount_inc(&req->refs);
 		req->result = res;
#5 lore raw
Quoted 11 lines · Bob Liu
Quoted 8 lines
Quoted 3 lines

io_cqring_overflow_flush(force=true) must have been called when this branch is executed, since io_cqring_overflow_flush() is the only place can set 'ctx->cq_overflow_flushed' to true.

Yes, it should have been called, but it sets this flag for the future users of io_cqring_fill_event(), so any _new_ requests in io_cqring_fill_event() will overflow instead of being added to @overflow_list.

Oh, I see..Thanks for the kindly explanation.

Sure, no problem

Signature · 1 line
Pavel Begunkov