Re: [PATCH] mm/khugepaged: fix a tracepoint for error cases

From: Andrew Morton
Date: Tue Apr 01 2025 - 17:09:44 EST


On Tue, 1 Apr 2025 16:23:53 -0400 Sweet Tea Dorminy <sweettea-kernel@xxxxxxxxxx> wrote:

> Fix a potential NULL pointer dereference in trace_mm_khugepaged_scan_pmd()
> when folio is NULL. This is possible if vm_normal_page() returned a NULL
> page -- which is unlikely, but was hit in testing.
>
> (The tracepoint in include/trace/events/huge_memory.h can already deal
> with a NULL page.)
>
> ...
>
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1435,8 +1435,9 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
> *mmap_locked = false;
> }
> out:
> - trace_mm_khugepaged_scan_pmd(mm, &folio->page, writable, referenced,
> - none_or_zero, result, unmapped);
> + trace_mm_khugepaged_scan_pmd(mm, folio ? &folio->page : NULL,
> + writable, referenced, none_or_zero,
> + result, unmapped);
> return result;

Confused. If folio==NULL then &folio->page==NULL also. The patch
appears to be a no-op?

Do you have the messages from that oops?