You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 gva2gpa on 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?
Activity
phil-opp commentedon Jan 21, 2023
Thanks for reporting! Could you give us instructions how to reproduce this error?
Freax13 commentedon Jan 21, 2023
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.
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.
an-owl commentedon Jan 21, 2023
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 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.phil-opp commentedon Jan 26, 2023
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?
an-owl commentedon Jan 27, 2023
Yep its here
phil-opp commentedon Jan 27, 2023
Thanks a lot! I created a PR to avoid that issue for now at #337.
In the long term, I agree that we need a more general fix for this, such as #240 (which I still haven't had time to review yet unfortunately).