]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
virtio-blk: fix V2P usage for kva_alloc addresses (H6 regression)
authorTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 01:43:33 +0000 (22:43 -0300)
committerTulio A M Mendes <[email protected]>
Thu, 11 Jun 2026 01:43:33 +0000 (22:43 -0300)
Bug: virtio_blk_init used V2P() macro to convert vring virtual address
to physical address. After H6, vring_va comes from kva_alloc_pages()
which may not be in the linear mapping region. V2P assumes linear
mapping (VA = PA + 0xC0000000), which is fragile.

Fix: Replace V2P(vring_va) with vmm_virt_to_phys(vring_va) to use
the proper VMM translation function that works for any mapped virtual
address.

This fixes the regression introduced by H6 where virtio-blk relied on
coincidental overlap between kva_alloc range (0xC0500000..0xC0800000)
and the initial 16MB linear mapping (0xC0000000..0xC0100000).

Test: make test-battery PASS (157/157), make analyzer PASS

src/drivers/virtio_blk.c

index 145be4213a7f62990c525fa140e5422cf5c23540..52bf1aaff452213b19b8f2ed852f7d64e8df1895 100644 (file)
@@ -201,8 +201,10 @@ int virtio_blk_init(void) {
     vblk_used = (struct vring_used*)(vring_va + used_off);
     vblk_last_used_idx = 0;
 
-    /* Tell device where the vring lives (page-aligned physical address) */
-    uint32_t vring_phys = (uint32_t)V2P(vring_va);
+    /* Tell device where the vring lives (page-aligned physical address)
+     * Use vmm_virt_to_phys instead of V2P because vring_va comes from
+     * kva_alloc_pages() and may not be in the linear mapping region. */
+    uint32_t vring_phys = (uint32_t)vmm_virt_to_phys(vring_va);
     outl(vblk_iobase + VIRTIO_PCI_QUEUE_PFN, vring_phys / 4096U);
 
     /* Mark driver ready */