From ae689c5fe5ab12dd953b7e8ca92c434d6dd850a6 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 21 Aug 2023 01:26:23 +0200 Subject: vm_allocate_contiguous: better handle pmax In case pmax is inside a segment, we should avoid using it, and stay with the previous segment, thus being sure to respect the caller's constraints. --- vm/vm_user.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'vm/vm_user.c') diff --git a/vm/vm_user.c b/vm/vm_user.c index 18f79eda..f42c84bf 100644 --- a/vm/vm_user.c +++ b/vm/vm_user.c @@ -608,19 +608,23 @@ kern_return_t vm_allocate_contiguous( if (pmax > VM_PAGE_DMA_LIMIT) #ifdef VM_PAGE_DMA32_LIMIT #if VM_PAGE_DMA32_LIMIT < VM_PAGE_DIRECTMAP_LIMIT - selector = VM_PAGE_SEL_DMA32; + if (pmax <= VM_PAGE_DMA32_LIMIT) + selector = VM_PAGE_SEL_DMA32; if (pmax > VM_PAGE_DMA32_LIMIT) #endif #endif - selector = VM_PAGE_SEL_DIRECTMAP; + if (pmax <= VM_PAGE_DIRECTMAP_LIMIT) + selector = VM_PAGE_SEL_DIRECTMAP; if (pmax > VM_PAGE_DIRECTMAP_LIMIT) #ifdef VM_PAGE_DMA32_LIMIT #if VM_PAGE_DMA32_LIMIT > VM_PAGE_DIRECTMAP_LIMIT - selector = VM_PAGE_SEL_DMA32; + if (pmax <= VM_PAGE_DMA32_LIMIT) + selector = VM_PAGE_SEL_DMA32; if (pmax > VM_PAGE_DMA32_LIMIT) #endif #endif - selector = VM_PAGE_SEL_HIGHMEM; + if (pmax <= VM_PAGE_HIGHMEM_LIMIT) + selector = VM_PAGE_SEL_HIGHMEM; size = vm_page_round(size); -- cgit v1.2.3