Re: [PATCH] mm: remove unintentional voluntary preemption in get_mmap_lock_carefully

Linus Torvalds
2023-08-21T04:55:25Z

On Mon, 21 Aug 2023 at 05:58, Matthew Wilcox <willy@infradead.org> wrote:
>
> The might_sleep() is clearly safe, but I thought of a different take on
> the problem you've found, which is that we used to check need_resched
> on _every_ page fault, because we used to take the mmap_lock on every
> page fault. Now we only check it on the minority of page faults which
> can't be handled under the VMA lock. But we can't just slam a
> might_resched() into the start of the fault handler, because of the
> problem you outlined above.

Bah.

I decided that there is no way the might_sleep() can be the right
thing to do inside get_mmap_lock_carefully(), because the whole point
of that function existing is that we might have a kernel bug causing a
wild pointer access.

And that kernel bug would be about the subsequent oops, not the fact
that we might be sleeping in a bad context.

So I have just removed the existing might_sleep() entirely, because
both the warning it can generate _and_ the voluntary scheduling point
are bad things in that context.

I do think that maybe we should then re-introduce the might_sleep() in
some actually appropriate place in the page fault path, which might be
'handle_mm_fault()'.

But I think that's a separate - if related - issue to the whole "this
was always the wrong point for might_sleep()" issue that Mateusz
noticed.

We are generally much too timid about removing old debug checks that
don't really make sense.

Linus