]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
kva: implement dynamic VA allocator to remove fixed VAs (H6)
authorTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 01:19:23 +0000 (22:19 -0300)
committerTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 01:19:23 +0000 (22:19 -0300)
commit1dbea378e97b5d2a3f2df900aa0e9c0e82403d74
tree7a134ba3acd628e5aefcf722da670717355cb8ae
parent572dfb8a4c39ac7d7e97fafe271a6c3ee0b04b70
kva: implement dynamic VA allocator to remove fixed VAs (H6)

Created kernel virtual address allocator to replace fixed VAs:
- include/kva_alloc.h: KVA allocator interface
- src/kernel/kva_alloc.c: Bitmap-based allocator with spinlock protection
  - Region: 0xC0500000 .. 0xC0800000 (3 MB, 768 pages)
  - kva_alloc_init(): Initialize bitmap and spinlock
  - kva_alloc_pages(): Allocate contiguous page range
  - kva_free_pages(): Free allocated range

Migrated fixed VA usages to dynamic allocation:
- src/hal/x86/mm.c: hal_mm_map_physical_range() now uses kva_alloc_pages
  instead of fixed KVA_PHYS_MAP (0xDC000000U)
- src/drivers/virtio_blk.c: virtio vring allocation now uses kva_alloc_pages
  instead of fixed VIRTIO_VRING_VA (0xC0340000U)

Removed obsolete constants:
- include/arch/x86/kernel_va_map.h: Removed KVA_PHYS_MAP constant
  Updated layout comment to document KVA allocator region

Boot integration:
- src/kernel/main.c: Added kva_alloc_init() call after kheap_init()

Validation:
- make -j$(nproc): PASS
- make test SMOKE_SMP=4: 131/131 PASS
- make test-battery: 157/157 PASS

This completes H6: remove fixed VAs, replacing hardcoded virtual
addresses with dynamic allocation to prevent collisions and improve
architectural flexibility.
include/arch/x86/kernel_va_map.h
include/kva_alloc.h [new file with mode: 0644]
src/drivers/virtio_blk.c
src/hal/x86/mm.c
src/kernel/kva_alloc.c [new file with mode: 0644]
src/kernel/main.c