linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: axboe@kernel.dk, Shenghui Wang <shhuiw@foxmail.com>
Cc: viro@zeniv.linux.org.uk, linux-block@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] io_uring: use cpu_online() to check p->sq_thread_cpu instead of cpu_possible()
Date: Wed, 01 May 2019 07:56:29 -0400	[thread overview]
Message-ID: <x49wojaxuaa.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <20190501072430.6674-1-shhuiw@foxmail.com> (Shenghui Wang's message of "Wed, 1 May 2019 15:24:30 +0800")

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 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 0e9fb2cb1984..aa3d39860a1c 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -2241,7 +2241,7 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
>  	ctx->sqo_mm = current->mm;
>  
>  	ret = -EINVAL;
> -	if (!cpu_possible(p->sq_thread_cpu))
> +	if (!cpu_online(p->sq_thread_cpu))
>  		goto err;
>  
>  	if (ctx->flags & IORING_SETUP_SQPOLL) {
> @@ -2258,7 +2258,7 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
>  
>  			cpu = array_index_nospec(p->sq_thread_cpu, NR_CPUS);
>  			ret = -EINVAL;
> -			if (!cpu_possible(p->sq_thread_cpu))
> +			if (!cpu_online(p->sq_thread_cpu))
>  				goto err;
>  
>  			ctx->sqo_thread = kthread_create_on_cpu(io_sq_thread,

Hmm.  Why are we doing this check twice?  Oh... Jens, I think you
braino'd commit 917257daa0fea.  Have a look.  You probably wanted to get
rid of the first check for cpu_possible.

-Jeff

  reply	other threads:[~2019-05-01 11:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01  7:24 [PATCH] io_uring: use cpu_online() to check p->sq_thread_cpu instead of cpu_possible() Shenghui Wang
2019-05-01 11:56 ` Jeff Moyer [this message]
2019-05-01 14:15   ` Jens Axboe
2019-05-01 14:32     ` Jeff Moyer
2019-05-01 14:39       ` Jens Axboe
2019-05-01 15:40         ` Jeff Moyer
  -- strict thread matches above, loose matches on Subject: below --
2019-05-07  8:00 Shenghui Wang
2019-05-07 14:40 ` Jens Axboe
2019-05-07  8:03 Shenghui Wang
2019-05-07 11:22 ` Jeff Moyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x49wojaxuaa.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=shhuiw@foxmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).