xhci
xhci copied to clipboard
unmap with size 0x1
Hi, I have implemented a mapper, and my kernel gave me an error originating from the unmap
function. I've logged the allocations and deallocations that the mapper wants to perform, and I get
allocated interval at 0x0000111111110000 size 0x1000
allocated interval at 0x0000111111111000 size 0x1000
allocated interval at 0x0000111111112000 size 0x1000
allocated interval at 0x0000111111113000 size 0x1000
allocated interval at 0x0000111111114000 size 0x1000
allocated interval at 0x0000111111115000 size 0x1000
allocated interval at 0x0000111111116000 size 0x1000
allocated interval at 0x0000111111117000 size 0x1000
allocated interval at 0x0000111111118000 size 0x1000
allocated interval at 0x0000111111119000 size 0x1000
allocated interval at 0x000011111111a000 size 0x1000
allocated interval at 0x000011111111b000 size 0x1000
allocated interval at 0x000011111111c000 size 0x1000
allocated interval at 0x000011111111d000 size 0x1000
allocated interval at 0x000011111111e000 size 0x1000
allocated interval at 0x000011111111f000 size 0x1000
allocated interval at 0x0000111111120000 size 0x1000
allocated interval at 0x0000111111121000 size 0x1000
allocated interval at 0x0000111111122000 size 0x1000
allocated interval at 0x0000111111123000 size 0x1000
unmap: 0x0000111111110000 size 0x1
My kernel does all of these allocations, but then the mapper wants to deallocate a valid pointer with an invalid size.
My mapper is the following:
impl Mapper for XhciMapper {
unsafe fn map(&mut self, phys_start: usize, bytes: usize) -> NonZeroUsize {
let frames = {
let start = PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(phys_start as u64));
let end = PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(phys_start as u64 + bytes as u64 - 1));
PhysFrameRangeInclusive { start, end }
};
let interval = vmm().reserve(bytes).unwrap().leak();
serial_println!("allocated interval at {:#p} size {:#x}", interval.start(), interval.size());
for (i, frame) in frames.enumerate() {
let vaddr = interval.start() + (i as u64 * frame.size());
map_page!(
Page::containing_address(vaddr),
frame,
Size4KiB,
PageTableFlags::PRESENT
);
}
NonZeroUsize::new(interval.start().as_u64() as usize).unwrap()
}
fn unmap(&mut self, virt_start: usize, bytes: usize) {
serial_println!("unmap: {:#p} size {:#x}", VirtAddr::new(virt_start as u64), bytes);
assert!(vmm().release(Interval::new(VirtAddr::new(virt_start as u64), bytes)));
}
}
To me, it seems like the mapper is called incorrectly from inside the xhci crate, but I may be wrong. I'd be thankful for any help.