Re: [PATCH] lib/test_hmm: fix NULL deref and wrong direction in devmem fault debug message

From: Andrew Morton

Date: Tue Aug 11 2026 - 21:24:47 EST


On Tue, 11 Aug 2026 17:22:55 +0800 liuqiangneo@xxxxxxx wrote:

> From: Qiang Liu <liuqiang@xxxxxxxxxx>
>
> Move pr_debug() inside the `if (dpage)` block to avoid a NULL deref,
> and fix the direction label from "sys to dev" to "dev to sys" to match
> the device-to-system copy.
>
> ...
>
> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -1151,10 +1151,9 @@ static vm_fault_t dmirror_devmem_fault_alloc_and_copy(struct migrate_vma *args,
> if (!dpage && !order)
> return VM_FAULT_OOM;
>
> - pr_debug("migrating from sys to dev pfn src: 0x%lx pfn dst: 0x%lx\n",
> - page_to_pfn(spage), page_to_pfn(dpage));
> -
> if (dpage) {
> + pr_debug("migrating from dev to sys pfn src: 0x%lx pfn dst: 0x%lx\n",
> + page_to_pfn(spage), page_to_pfn(dpage));
> lock_page(dpage);
> *dst |= migrate_pfn(page_to_pfn(dpage));
> }

Current kernel code doesn't look like this?