From 0c73d69a7005941ddb47404cb412499f21bda33d Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 7 Jan 2023 20:58:12 +0100 Subject: [PATCH] Kernel: Fix shadow 12GiB reserved entry when running QEMU without KVM on Fix inspired by: https://github.com/serenityos/serenity/pull/16345 --- README.md | 2 -- kernel/src/memory/MemoryMap.cpp | 12 +++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6bf71a57..3691993a 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,6 @@ You can choose between 3 run scripts: `tools/debug.sh` will run Luna in QEMU with a port open for GDB to connect to. (run `tools/build-debug.sh`, `tools/gdb.sh`, and then `tools/debug.sh` in a separate terminal for an optimal debugging experience) -Beware that running without hardware acceleration does some weird stuff with the memory map, which is why I don't use it that often. - Essentially, since `run.sh` builds the toolchain if it hasn't been built, builds Luna if it hasn't been built, and runs it, you could just checkout this repo, run `run.sh`, and you're done. No need for the other scripts. Those are included for more fine-grained control/building step-by-step. You can pass any arguments you want to the run scripts, and those will be forwarded to QEMU. Example: `tools/run.sh -m 512M -net none -machine q35`. diff --git a/kernel/src/memory/MemoryMap.cpp b/kernel/src/memory/MemoryMap.cpp index 9d9cdca1..3e67fd76 100644 --- a/kernel/src/memory/MemoryMap.cpp +++ b/kernel/src/memory/MemoryMap.cpp @@ -43,7 +43,17 @@ Option MemoryMapIterator::at(usize index) const Option MemoryMapIterator::next() { - return at(m_cur_ent++); + auto entry = TRY(at(m_cur_ent++)); + +#ifdef ARCH_X86_64 + // Workaround for https://gitlab.com/qemu-project/qemu/-/commit/8504f129450b909c88e199ca44facd35d38ba4de + // This invalid 12GiB reserved entry is made up by QEMU (doesn't appear on any real hardware), so we can simply + // ignore it and move on to the next entry. + if (entry.address() == 0x000000fd00000000 && entry.size() == (0x000000ffffffffff - 0x000000fd00000000) + 1) + return at(m_cur_ent++); +#endif + + return entry; } MemoryMapEntry MemoryMapIterator::largest_free()