From 6f21a0ae17048c66f1fdcf50333672afa92f7ef4 Mon Sep 17 00:00:00 2001 From: Tulio A M Mendes Date: Wed, 10 Jun 2026 22:43:33 -0300 Subject: [PATCH] virtio-blk: fix V2P usage for kva_alloc addresses (H6 regression) 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drivers/virtio_blk.c b/src/drivers/virtio_blk.c index 145be421..52bf1aaf 100644 --- a/src/drivers/virtio_blk.c +++ b/src/drivers/virtio_blk.c @@ -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 */ -- 2.43.0