diff mbox series

io_uring: use cpu_online() to check p->sq_thread_cpu instead of cpu_possible()

Message ID 20190507080319.2045-1-shhuiw@foxmail.com (mailing list archive)
State New, archived
Headers show
Series io_uring: use cpu_online() to check p->sq_thread_cpu instead of cpu_possible() | expand

Commit Message

Shenghui Wang May 7, 2019, 8:03 a.m. UTC
This issue is found by running liburing/test/io_uring_setup test.

When test run, the testcase "attempt to bind to invalid cpu" would not
pass with messages like:
   io_uring_setup(1, 0xbfc2f7c8), \
flags: IORING_SETUP_SQPOLL|IORING_SETUP_SQ_AFF, \
resv: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000, \
sq_thread_cpu: 2
   expected -1, got 3
   FAIL

On my system, there is:
   CPU(s) possible : 0-3
   CPU(s) online   : 0-1
   CPU(s) offline  : 2-3
   CPU(s) present  : 0-1

The sq_thread_cpu 2 is offline on my system, so the bind should fail.
But cpu_possible() will pass the check. We shouldn't be able to bind
to an offline cpu. Use cpu_online() to do the check.

After the change, the testcase run as expected: EINVAL will be returned
for cpu offlined.

Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jeff Moyer May 7, 2019, 11:22 a.m. UTC | #1
Shenghui Wang <shhuiw@foxmail.com> writes:

> This issue is found by running liburing/test/io_uring_setup test.
>
> When test run, the testcase "attempt to bind to invalid cpu" would not
> pass with messages like:
>    io_uring_setup(1, 0xbfc2f7c8), \
> flags: IORING_SETUP_SQPOLL|IORING_SETUP_SQ_AFF, \
> resv: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000, \
> sq_thread_cpu: 2
>    expected -1, got 3
>    FAIL
>
> On my system, there is:
>    CPU(s) possible : 0-3
>    CPU(s) online   : 0-1
>    CPU(s) offline  : 2-3
>    CPU(s) present  : 0-1
>
> The sq_thread_cpu 2 is offline on my system, so the bind should fail.
> But cpu_possible() will pass the check. We shouldn't be able to bind
> to an offline cpu. Use cpu_online() to do the check.
>
> After the change, the testcase run as expected: EINVAL will be returned
> for cpu offlined.
>
> Signed-off-by: Shenghui Wang <shhuiw@foxmail.com>
> ---
>  fs/io_uring.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index d91cbd53d3ca..718d7b873f4a 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -2472,7 +2472,7 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
>  							nr_cpu_ids);
>  
>  			ret = -EINVAL;
> -			if (!cpu_possible(cpu))
> +			if (!cpu_online(cpu))
>  				goto err;
>  
>  			ctx->sqo_thread = kthread_create_on_cpu(io_sq_thread,

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
diff mbox series

Patch

diff --git a/fs/io_uring.c b/fs/io_uring.c
index d91cbd53d3ca..718d7b873f4a 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2472,7 +2472,7 @@  static int io_sq_offload_start(struct io_ring_ctx *ctx,
 							nr_cpu_ids);
 
 			ret = -EINVAL;
-			if (!cpu_possible(cpu))
+			if (!cpu_online(cpu))
 				goto err;
 
 			ctx->sqo_thread = kthread_create_on_cpu(io_sq_thread,