Skip to content

Commit b61e948

Browse files
committed
[Kernel] Physical range allocations are always padded to page boundaries
1 parent d518e99 commit b61e948

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

kernel/kernel/util/amc/core_commands.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,14 @@ static void _amc_core_alloc_physical_range(const char* source_service, void* buf
310310

311311
amc_alloc_physical_range_request_t* req = (amc_alloc_physical_range_request_t*)buf;
312312

313-
printf("[AMC] %s allocating memory mapping of size 0x%p\n", source->name, req->size);
314-
315-
uintptr_t phys_base = pmm_alloc_continuous_range(buf_size);
316-
uintptr_t virt_base = vas_map_range_exact(vas_get_active_state(), 0x7d0000000000, buf_size, phys_base, VAS_RANGE_ACCESS_LEVEL_READ_WRITE, VAS_RANGE_PRIVILEGE_LEVEL_USER);
317-
printf("\tAllocated Phys [0x%p - 0x%p], Virt [0x%p - 0x%p]\n", phys_base, phys_base + req->size, virt_base, virt_base + req->size);
313+
uintptr_t range_size = addr_space_page_ceil(req->size);
314+
printf("[AMC] %s allocating memory mapping of size 0x%p (padded = 0x%p)\n", source->name, req->size, range_size);
315+
316+
// Pad the requested size to the next page
317+
uintptr_t phys_base = pmm_alloc_continuous_range(range_size);
318+
// TODO(PT): vas_map_range_exact() should fail if the range is already allocated
319+
uintptr_t virt_base = vas_map_range(vas_get_active_state(), 0x7d0000000000, range_size, phys_base, VAS_RANGE_ACCESS_LEVEL_READ_WRITE, VAS_RANGE_PRIVILEGE_LEVEL_USER);
320+
printf("\tAllocated Phys [0x%p - 0x%p], Virt [0x%p - 0x%p]\n", phys_base, phys_base + range_size, virt_base, virt_base + range_size);
318321

319322
amc_alloc_physical_range_response_t resp = {0};
320323
resp.event = AMC_ALLOC_PHYSICAL_RANGE_RESPONSE;

0 commit comments

Comments
 (0)