Re: [PATCH] mm/gup: fix handling of zero page in follow_page_pte()

From: David Hildenbrand (Red Hat)

Date: Wed Nov 12 2025 - 03:05:11 EST


On 12.11.25 08:24, peng8420.li@xxxxxxxxx wrote:
From: "peng8420.li" <peng8420.li@xxxxxxxxx>

In some scenarios, `__vm_normal_page` might return NULL.
In this case, if `is_zero_pfn(pte_pfn(pte))` is true, simply return `page = pte_page(pte)`;
no further folio processing is needed.

Signed-off-by: peng8420.li <peng8420.li@xxxxxxxxx>
---
mm/gup.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/gup.c b/mm/gup.c
index 95d948c8e86c..60ae5f0c20e0 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -838,6 +838,7 @@ static struct page *follow_page_pte(struct vm_area_struct *vma,
if (is_zero_pfn(pte_pfn(pte))) {
page = pte_page(pte);
+ goto out;
} else {
ret = follow_pfn_pte(vma, address, ptep, flags);
page = ERR_PTR(ret);

I'm sorry, but that's just wrong. Observe how me might run into the gup_must_unshare() branch and how try_grab_folio() would grab references on the FOLL_GET path.

--
Cheers

David