Re: [PATCH 10/32] mm/khugepaged: don't wait for userfaultfd
From: Gregory Price (Meta)
Date: Wed Dec 02 2026 - 16:57:52 EST
On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote:
> khugepaged and MADV_COLLAPSE can end up triggering userfaultfd faults if
> MADV_DONTNEED + UFFDIO_WRITEPROTECT races with collapse. The fault flags
> are FAULT_FLAG_ALLOW_RETRY alone, so handle_userfault() sleeps in
> TASK_UNINTERRUPTIBLE.
>
> Consequently, khugepaged or the MADV_COLLAPSE caller can sleep forever,
> if user space never resolves the fault.
>
> Let's fix it by rejecting anything non-present that is uffd related by
> checking pte_swp_uffd_any(), just like in collapse_scan_anon().
>
> This has medium urgency, as unprivileged users can make khugepaged sleep
> forever.
>
> Fixes: 2bad466cc9d9 ("mm/uffd: UFFD_FEATURE_WP_UNPOPULATED")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
I couldn't reproduce the actual hang, but I did reproduce the
bad condition that can lead to it. Seems pretty difficult to
hit unless you're really trying.
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
Reviewed-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory