Re: [PATCH 13/32] mm/khugepaged: stop MADV_COLLAPSE on a fatal signal

From: Dev Jain

Date: Thu Dec 03 2026 - 08:56:22 EST




On 29/11/26 3:36 pm, David Hildenbrand (Arm) wrote:
> A task that gets a fatal signal during MADV_COLLAPSE keeps collapsing
> the rest of the range. Consequently, the exit of the task can be delayed
> for a while for a large range.
>
> Let's fix it by checking for a fatal signal before each PMD, simply
> breaking out of the loop. User space will never see the return value,
> so no need to return -EINTR.
>
> This has low urgency, as it only delays the exit of the task. No need to
> CC stable.
>
> Fixes: 7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse")
> Reported-by: Chris Mason <mason@xxxxxxxxxx>
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> ---

Reviewed-by: Dev Jain <dev.jain@xxxxxxx>


> mm/khugepaged.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index 091e4136ba037..0495fb1a9e31c 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -4,6 +4,7 @@
> #include <linux/mm.h>
> #include <linux/sched.h>
> #include <linux/sched/mm.h>
> +#include <linux/sched/signal.h>
> #include <linux/mmu_notifier.h>
> #include <linux/rmap.h>
> #include <linux/swap.h>
> @@ -3372,6 +3373,9 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
> for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
> enum scan_result result = SCAN_FAIL;
>
> + if (fatal_signal_pending(current))
> + break;
> +
> if (mmap_unlocked) {
> cond_resched();
> mmap_read_lock(mm);
>