From 661a83f9bf9f6028c5617d413d59b7f0d9201abd Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Mon, 29 Apr 2024 12:22:36 -0400 Subject: [PATCH] vm: Fix error handling in vm_thread_stack_back() vm_object_page_remove() wants to busy the page, but that won't work here. (Kernel stack pages are always busy.) Make the error handling path look more like vm_thread_stack_dispose(). Reported by: pho Reviewed by: kib, bnovkov Fixes: 7a79d0669761 ("vm: improve kstack_object pindex calculation to avoid pindex holes") Differential Revision: https://reviews.freebsd.org/D45019 --- sys/vm/vm_glue.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/vm/vm_glue.c b/sys/vm/vm_glue.c index f9235fe03fa..979a0fc2712 100644 --- a/sys/vm/vm_glue.c +++ b/sys/vm/vm_glue.c @@ -630,7 +630,11 @@ vm_thread_stack_back(vm_offset_t ks, vm_page_t ma[], int npages, int req_class, return (0); cleanup: - vm_object_page_remove(obj, pindex, pindex + n, 0); + for (int i = 0; i < n; i++) { + m = ma[i]; + (void)vm_page_unwire_noq(m); + vm_page_free(m); + } VM_OBJECT_WUNLOCK(obj); return (ENOMEM); -- 2.45.0