Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel oopses with 4GiB of RAM in QEMU #507

Open
hawkw opened this issue Jan 5, 2025 · 0 comments
Open

kernel oopses with 4GiB of RAM in QEMU #507

hawkw opened this issue Jan 5, 2025 · 0 comments
Assignees
Labels
good first issue Good for newcomers kind/bug Something isn't working

Comments

@hawkw
Copy link
Owner

hawkw commented Jan 5, 2025

running in QEMU with -machine accel=KVM -cpu host -m 4G gets us a kernel panic when adding the memory map to the page-frame allocator.

if i run with

$ cargo run-x64 --serial -- -m 4G

i get this oops:

[     ?.??????][i] ├mycelium_kernel:   PAddr(0x01500000)            FREE      3131269122 B
[     ?.??????][*] ├mycelium_kernel::allocator: adding to page allocator, region=Region {
                   │     base: PAddr(0x1500000),
                   │     size: 3131269122,
                   │     kind: FREE,
                   │ }
[     ?.??????][?] ├oops: Oops {
                   │     already_panicked: false,
                   │     already_faulted: false,
                   │     alloc: State {
                   │         allocating: 0,
                   │         deallocating: 1,
                   │         heap_size: 20336640,
                   │         allocated: 0,
                   │         min_size: 64,
                   │         bump_mode: false,
                   │         bump_allocated: 0,
                   │         bump_size: 1024,
                   │     },
                   │     situation: OopsSituation::Panic(
                   │         PanicInfo {
                   │             message: assertion failed: size <= core::i32::MAX as usize,
                   │             location: Location {
                   │                 file: "/home/eliza/Code/mycelium/hal-core/src/mem.rs",
                   │                 line: 103,
                   │                 col: 9,
                   │             },
                   │             can_unwind: true,
                   │             force_no_backtrace: false,
                   │         },
                   │     ),
                   │ }

which is this assertion in mem::Region::split_back:

pub fn split_back(&mut self, size: usize) -> Option<Self> {
assert!(size <= core::i32::MAX as usize);

this is because the Address::offset function tries to be clever and takes an i32 as the offset to ensure the offset is always in-bounds:

fn offset(self, offset: i32) -> Self {
if offset > 0 {
self + offset as usize
} else {
let offset = -offset;
self - offset as usize
}
}

so we have to make sure that the size of the region is < the max i32 to call that. this is silly. we should be able to handle memory regions bigger than 2,147,483,647 bytes (this one is 3,131,269,122 B).

we could either make Address::offset take an isize isntead, or have split_back not use Address::offset.

@hawkw hawkw added kind/bug Something isn't working good first issue Good for newcomers labels Jan 5, 2025
@hawkw hawkw self-assigned this Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant