git: 03b214a35db1 - main - linuxkpi: gracefully handle page lookup failure in lkpi_vmf_insert_pfn_prot_locked

From: Austin Shafer <ashafer_at_FreeBSD.org>
Date: Wed, 29 Oct 2025 20:59:16 UTC
The branch main has been updated by ashafer:

URL: https://cgit.FreeBSD.org/src/commit/?id=03b214a35db1ebdc7575cad8d695c65daf2817bf

commit 03b214a35db1ebdc7575cad8d695c65daf2817bf
Author:     Austin Shafer <ashafer@FreeBSD.org>
AuthorDate: 2025-10-28 18:08:01 +0000
Commit:     Austin Shafer <ashafer@FreeBSD.org>
CommitDate: 2025-10-29 20:58:41 +0000

    linuxkpi: gracefully handle page lookup failure in lkpi_vmf_insert_pfn_prot_locked
    
    Currently lkpi_vmf_insert_pfn_prot_locked will check the page iter to
    find a usage of the page. If no page was found, it continues on to
    try using PHYS_TO_VM_PAGE() to get a page. Currently it does not check
    if a valid page was found before passing it to vm_page_busy_acquire,
    which can cause a kernel page fault as vm_page_busy_acquire expects
    a valid page pointer.
    
    This can easily be triggered while starting KDE6 in wayland mode, which
    many users have been reporting. With this change plasma6 starts properly
    in wayland mode.
    
    Sponsored by:   NVIDIA
    PR:             288565
    Reviewed by:    markj, kbowling (mentor)
    Differential Revision:  https://reviews.freebsd.org/D53412
---
 sys/compat/linuxkpi/common/src/linux_page.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c
index 628af17df853..9cc981b2ba43 100644
--- a/sys/compat/linuxkpi/common/src/linux_page.c
+++ b/sys/compat/linuxkpi/common/src/linux_page.c
@@ -345,6 +345,10 @@ retry:
 	page = vm_page_grab_iter(vm_obj, pindex, VM_ALLOC_NOCREAT, &pages);
 	if (page == NULL) {
 		page = PHYS_TO_VM_PAGE(IDX_TO_OFF(pfn));
+		if (page == NULL) {
+			pctrie_iter_reset(&pages);
+			return (VM_FAULT_SIGBUS);
+		}
 		if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL)) {
 			pctrie_iter_reset(&pages);
 			goto retry;