From 5d26b114a498042bcb4ed133940e32a6b6c69de8 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 15 Feb 2025 15:16:50 +0100 Subject: [PATCH] core: Add workaround for QEMU-specific triple-faults without KVM Without KVM, qemu inserts an invalid 12-GiB reserved entry at the end of the physical address space, making the kernel reserve way more space than necessary for the page bitmap (and overwriting the page directory pages). --- core/src/mmap.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/mmap.zig b/core/src/mmap.zig index e9622e5..4634a07 100644 --- a/core/src/mmap.zig +++ b/core/src/mmap.zig @@ -1,4 +1,5 @@ const easyboot = @cImport(@cInclude("easyboot.h")); +const target = @import("builtin").target; const MemoryMapIterator = struct { tag: *easyboot.multiboot_tag_mmap_t, @@ -15,6 +16,16 @@ const MemoryMapIterator = struct { if (@intFromPtr(self.entry) >= self.end) self.entry = null; + if (target.cpu.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 (current_entry) |entry| { + if (entry.base_addr == 0x000000fd00000000 and entry.length == (0x000000ffffffffff - 0x000000fd00000000) + 1) + return self.next(); + } + } + return current_entry; }