kernel/vm: Allow locking kernel space if allocating page_protections for userspace.

Some applications may request per-page protections for an especially
large area (e.g. multiple GB), which leads to allocating a rather
large page protections area (e.g. 512KB), which we cannot allocate
without locking the kernel space to get new slabs.

We only need to avoid locking the kernel space if the area in question
is in the kernel space, as in that case, kernel space will already be
read-locked by the current thread.

Fixes #16898.

Change-Id: If52413a594da66edfc2821811d959085a2c3c78e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/4436
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2021-09-10 18:49:33 +00:00
committed by waddlesplash
parent 2f001d82b6
commit 60fee365f5
2 changed files with 7 additions and 7 deletions
+2 -5
View File
@@ -48,11 +48,8 @@ VMArea::VMArea(VMAddressSpace* addressSpace, uint32 wiring, uint32 protection)
VMArea::~VMArea()
{
const uint32 flags = HEAP_DONT_WAIT_FOR_MEMORY
| HEAP_DONT_LOCK_KERNEL_SPACE;
// TODO: This might be stricter than necessary.
free_etc(page_protections, flags);
free_etc(page_protections, address_space == VMAddressSpace::Kernel()
? HEAP_DONT_WAIT_FOR_MEMORY | HEAP_DONT_LOCK_KERNEL_SPACE : 0);
}
+5 -2
View File
@@ -465,7 +465,8 @@ allocate_area_page_protections(VMArea* area)
// so we use 4 bits per page.
size_t bytes = (area->Size() / B_PAGE_SIZE + 1) / 2;
area->page_protections = (uint8*)malloc_etc(bytes,
HEAP_DONT_LOCK_KERNEL_SPACE);
area->address_space == VMAddressSpace::Kernel()
? HEAP_DONT_LOCK_KERNEL_SPACE : 0);
if (area->page_protections == NULL)
return B_NO_MEMORY;
@@ -2634,7 +2635,9 @@ vm_copy_area(team_id team, const char* name, void** _address,
if (source->page_protections != NULL) {
size_t bytes = (source->Size() / B_PAGE_SIZE + 1) / 2;
targetPageProtections = (uint8*)malloc_etc(bytes,
HEAP_DONT_LOCK_KERNEL_SPACE);
(source->address_space == VMAddressSpace::Kernel()
|| targetAddressSpace == VMAddressSpace::Kernel())
? HEAP_DONT_LOCK_KERNEL_SPACE : 0);
if (targetPageProtections == NULL)
return B_NO_MEMORY;