Repository navigation
Panic in stage 4 in BIOS boot #331
Description
Activity
Thanks for reporting! Could you give us instructions how to reproduce this error?
I suspect that this could be caused by a non-PIE kernel that maps memory to the same address we use for the context switch in the bootloader. The error occurs because we load the context switch function into the kernel's address space. We currently need to do this because the address space switch is not the last instruction of the context switch, so the context switch function needs to be mapped in the kernel's address space to complete.
Similar errors could probably be provoked by setting other addresses (e.g. frame buffer, boot info) to this address.
This might be fixed by #240.
A potental fix would be to just ignore the error with an extra match arm
Err(MapToError::PageAlreadyMapped(frame)) => {}No, this wouldn't work, the current implementation expects the context switch function to be mapped in both address spaces. Ignoring the error would mean that the context switch function would jump into rogue kernel memory after doing the address space switch.
After removing
"-C","relocation-model=static"and"-C","link-arg=-no-pie"from rustflags the bootloader now boots correctly so it seems that is the likely cause.A potental fix would be to just ignore the error with an extra match arm
Err(MapToError::PageAlreadyMapped(frame)) > > => {}No, this wouldn't work, the current implementation expects the context switch function to be mapped in both address spaces. Ignoring the error would mean that the context switch function would jump into rogue kernel memory after doing the address space switch.
I was supposed to put a match guard in there. Using
gva2gpaon the page that threw the error and the ones before and after it all seem to be identity mapped already.After removing
"-C","relocation-model=static"and"-C","link-arg=-no-pie"from rustflags the bootloader now boots correctly so it seems that is the likely cause.I just tried to reproduce the error by adding these flags, but it still works fine for a small test kernel. Do you have the project where this happens online somewhere so that we can try to reproduce the error?
Do you have the project where this happens online somewhere so that we can try to reproduce the error?
Yep its here
The bootloader panics on line 242 with
failed to identity map fame PhysFrame[4kib](20a000): PageAlreadyMapped(PhysFrame[4Kib](0x20a000))bootloader/common/src/lib.rs
Lines 229 to 244 in c73786d
I checked the mapping for
0x20b000and QEMU says its mapped to0x20b000A potental fix would be to just ignore the error with an extra match arm
Err(MapToError::PageAlreadyMapped(frame)) => {}