commit 6ea74eec0beb6e840774ad230f3ce38002410ec7
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Mar 29 01:47:50 2026 +0100

    biosmem: Add MAX_PHYS_END to limit physical memory use
    
    to what was actually tested as working considering the limited amount of
    available virtual memory.

---
 i386/i386/vm_param.h     |   10 ++++++++++
 i386/i386at/biosmem.c    |   19 +++++++++++++++++++
 x86_64/x86_64/vm_param.h |   10 ++++++++++
 3 files changed, 39 insertions(+)

--- a/x86_64/x86_64/vm_param.h
+++ b/x86_64/x86_64/vm_param.h
@@ -85,6 +85,16 @@
 #define VM_KERNEL_MAP_SIZE (170 * 1024 * 1024)
 #endif
 
+/*
+ * Maximum supported memory size.
+ * These were tested as working.
+ */
+#ifdef __x86_64__
+#define MAX_PHYS_END (30ULL * 1024 * 1024 * 1024)
+#else
+#define MAX_PHYS_END (8ULL * 1024 * 1024 * 1024)
+#endif
+
 /* This is the kernel address range in linear addresses.  */
 #ifdef __x86_64__
 #define LINEAR_MIN_KERNEL_ADDRESS	VM_MIN_KERNEL_ADDRESS
--- a/i386/i386/vm_param.h
+++ b/i386/i386/vm_param.h
@@ -85,6 +85,16 @@
 #define VM_KERNEL_MAP_SIZE (170 * 1024 * 1024)
 #endif
 
+/*
+ * Maximum supported memory size.
+ * These were tested as working.
+ */
+#ifdef __x86_64__
+#define MAX_PHYS_END (30ULL * 1024 * 1024 * 1024)
+#else
+#define MAX_PHYS_END (8ULL * 1024 * 1024 * 1024)
+#endif
+
 /* This is the kernel address range in linear addresses.  */
 #ifdef __x86_64__
 #define LINEAR_MIN_KERNEL_ADDRESS	VM_MIN_KERNEL_ADDRESS
--- a/i386/i386at/biosmem.c
+++ b/i386/i386at/biosmem.c
@@ -918,6 +918,18 @@ biosmem_load_segment(struct biosmem_segm
         phys_end = max_phys_end;
     }
 
+    if (phys_end > MAX_PHYS_END) {
+        if (MAX_PHYS_END <= phys_start) {
+            printf("biosmem: warning: segment %s beyond tested memory size, "
+                   "not loaded\n", vm_page_seg_name(seg_index));
+            return;
+        }
+
+        printf("biosmem: warning: segment %s truncated to tested %#"PRIx64"\n",
+               vm_page_seg_name(seg_index), MAX_PHYS_END);
+        phys_end = MAX_PHYS_END;
+    }
+
     vm_page_load(seg_index, phys_start, phys_end);
 
     /*
@@ -1034,12 +1046,19 @@ biosmem_free_usable(void)
         if (start >= VM_PAGE_HIGHMEM_LIMIT)
             break;
 
+        if (start >= MAX_PHYS_END)
+            break;
+
         end = vm_page_trunc(entry->base_addr + entry->length);
 
         if (end > VM_PAGE_HIGHMEM_LIMIT) {
             end = VM_PAGE_HIGHMEM_LIMIT;
         }
 
+        if (end > MAX_PHYS_END) {
+            end = MAX_PHYS_END;
+        }
+
         if (start < BIOSMEM_BASE)
             start = BIOSMEM_BASE;
 
