Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Stefano Garzarella <sgarzare@redhat.com>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: io_uring: BUG: kernel NULL pointer dereference
Date: Mon, 25 May 2020 21:21:43 +0200	[thread overview]
Message-ID: <20200525192143.GG317569@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <b1689238-b236-cc93-9909-c09120e7975c@kernel.dk>

On Mon, May 25, 2020 at 08:10:27AM -0600, Jens Axboe wrote:
> I think the odd part here is that task_tick_numa() checks for a
> valid mm, and queues work if the task has it. But for the sqpoll
> kthread, the mm can come and go. By the time the task work is run,
> the mm is gone and we oops on current->mm == NULL.
> 
> I think the below should fix it:
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 538ba5d94e99..24a8557f001f 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -2908,7 +2908,8 @@ static void task_tick_numa(struct rq *rq, struct task_struct *curr)
>  	/*
>  	 * We don't care about NUMA placement if we don't have memory.
>  	 */
> -	if (!curr->mm || (curr->flags & PF_EXITING) || work->next != work)
> +	if (!curr->mm || (curr->flags & (PF_EXITING | PF_KTHREAD)) ||
> +	    work->next != work)
>  		return;

Ah, I think that's one more instance of '!p->mm' != is_kthread(). A
while ago someone went and cleaned a bunch of them up. Clearly this one
was missed.

I'm thinking just:

	if ((curr->flags & (PF_EXITING | PF_KTHREAD)) || work->next != work)

should be enough.

  parent reply	other threads:[~2020-05-25 19:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25 10:30 Stefano Garzarella
2020-05-25 13:45 ` Stefano Garzarella
2020-05-25 14:10   ` Jens Axboe
2020-05-25 15:02     ` Stefano Garzarella
2020-05-25 19:07       ` Jens Axboe
2020-05-25 19:21     ` Peter Zijlstra [this message]
2020-05-25 19:25       ` Jens Axboe
2020-05-25 14:11   ` Pavel Begunkov

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=20200525192143.GG317569@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sgarzare@redhat.com \
    --subject='Re: io_uring: BUG: kernel NULL pointer dereference' \
    /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

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).