Skip to content

Commit

Permalink
fix(bitmap): Correct the bitmap and cpu base addr for MMU systems
Browse files Browse the repository at this point in the history
In mmu-based systems, the vm_image_size is already encompassed in the
image_size. This lead to miscalculations in the base address of the bitmap
and cpu.

Signed-off-by: Miguel Silva <[email protected]>
  • Loading branch information
miguelafsilva5 committed Nov 29, 2024
1 parent 9d46fe7 commit da6b7aa
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/core/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <fences.h>
#include <config.h>

extern uint8_t _image_start, _image_load_end, _image_end, _vm_image_start, _vm_image_end;
extern uint8_t _image_start, _image_load_end, _image_end, _vm_image_start, _vm_image_end, _image_noload_start, _dmem_phys_beg;

struct list page_pool_list;

Expand Down Expand Up @@ -138,16 +138,14 @@ void* mem_alloc_page(size_t num_pages, enum AS_SEC sec, bool phys_aligned)

static bool root_pool_set_up_bitmap(paddr_t load_addr, struct page_pool* root_pool)
{
size_t image_size = (size_t)(&_image_end - &_image_start);
size_t vm_image_size = (size_t)(&_vm_image_end - &_vm_image_start);
size_t cpu_size = platform.cpu_num * mem_cpu_boot_alloc_size();
paddr_t bitmap_base = load_addr + (paddr_t)(&_dmem_phys_beg - &_image_start) + cpu_size;

size_t bitmap_num_pages =
root_pool->size / (8 * PAGE_SIZE) + ((root_pool->size % (8 * PAGE_SIZE) != 0) ? 1 : 0);
if (root_pool->size <= bitmap_num_pages) {
return false;
}
size_t bitmap_base = load_addr + image_size + vm_image_size + cpu_size;

struct ppages bitmap_pp = mem_ppages_get(bitmap_base, bitmap_num_pages);
bitmap_t* root_bitmap = (bitmap_t*)mem_alloc_map(&cpu()->as, SEC_HYP_GLOBAL, &bitmap_pp,
Expand All @@ -160,11 +158,10 @@ static bool root_pool_set_up_bitmap(paddr_t load_addr, struct page_pool* root_po

static bool pp_root_reserve_hyp_mem(paddr_t load_addr, struct page_pool* root_pool)
{
size_t image_load_size = (size_t)(&_image_load_end - &_image_start);
size_t image_noload_size = (size_t)(&_image_end - &_image_load_end);
size_t vm_image_size = (size_t)(&_vm_image_end - &_vm_image_start);
size_t image_load_size = (size_t)(&_image_load_end - &_image_start);
size_t image_noload_size = (size_t)(&_image_end - &_image_noload_start);
size_t cpu_size = platform.cpu_num * mem_cpu_boot_alloc_size();
paddr_t image_noload_addr = load_addr + image_load_size + vm_image_size;
paddr_t image_noload_addr = load_addr + (paddr_t)(&_image_noload_start- &_image_start);
paddr_t cpu_base_addr = image_noload_addr + image_noload_size;

struct ppages images_load_ppages = mem_ppages_get(load_addr, NUM_PAGES(image_load_size));
Expand Down

0 comments on commit da6b7aa

Please sign in to comment.