Skip to content

Commit cb881f1

Browse files
committed
fix(mmio): don't return MMIO virtual addresses to the free list
check_linux_args MMIO device registers into a PageBox-allocated VA, then return a VolatileRef<'static> pointing at it. When the PageBox is dropped, the VA range goes back to the free list. A subsequent allocation could reuse and remap the same VA, corrupting the driver's VolatileRef. Use into_raw() to prevent the VA from being reclaimed when a device is found.
1 parent 4912505 commit cb881f1

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/arch/x86_64/kernel/mmio.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ fn check_linux_args(
9898
linux_mmio: &'static [String],
9999
) -> Vec<(VolatileRef<'static, DeviceRegisters>, u8)> {
100100
let layout = PageLayout::from_size(BasePageSize::SIZE as usize).unwrap();
101-
let page_range = PageBox::new(layout).unwrap();
102-
let virtual_address = VirtAddr::from(page_range.start());
101+
let mut page_range = PageBox::new(layout).unwrap();
102+
let mut virtual_address = VirtAddr::from(page_range.start());
103103

104104
let mut devices = vec![];
105105
for arg in linux_mmio {
@@ -138,6 +138,12 @@ fn check_linux_args(
138138
FrameAlloc::allocate_at(frame_range).unwrap_err();
139139
}
140140

141+
// Don't return the VA to the free list: the driver holds a VolatileRef into this mapping.
142+
PageBox::into_raw(page_range);
143+
// Pick a fresh VA for subsequent iterations.
144+
page_range = PageBox::new(layout).unwrap();
145+
virtual_address = VirtAddr::from(page_range.start());
146+
141147
devices.push((mmio, irq));
142148
}
143149
_ => {

0 commit comments

Comments
 (0)