History

x86: respect memory size limiting via mem= parameter

When limiting memory size via kernel parameter "mem=" this should be respected even in case of memory made accessible via a PCI card. Today this kind of memory won't be made usable in initial memory setup as the memory won't be visible in E820 map, but it might be added when adding PCI devices due to corresponding ACPI table entries. Not respecting "mem=" can be corrected by adding a global max_mem_size variable set by parse_memopt() which will result in rejecting adding memory areas resulting in a memory size above the allowed limit.

Juergen Gross committed 7 years ago

Commit 357b4da1 parent 068e79f3 files · +13 −0Browse files

Unified · Split

3 files
  1. arch/x86/kernel/e820.c +5 −0
  2. include/linux/memory_hotplug.h +2 −0
  3. mm/memory_hotplug.c +6 −0
arch/x86/kernel/e820.c+5−0
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/acpi.h>
1515 #include <linux/firmware-map.h>
1616 #include <linux/sort.h>
17+#include <linux/memory_hotplug.h>
1718
1819 #include <asm/e820/api.h>
1920 #include <asm/setup.h>
@@ -881,6 +882,10 @@ static int __init parse_memopt(char *p) · 861 unmodified lines
881882
882883 e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
883884
885+#ifdef CONFIG_MEMORY_HOTPLUG
886+ max_mem_size = mem_size;
887+#endif
888+
884889 return 0;
885890 }
886891 early_param("mem", parse_memopt);
include/linux/memory_hotplug.h+2−0
@@ -100,6 +100,8 @@ extern void __online_page_free(struct page *page); · 99 unmodified lines
100100
101101 extern int try_online_node(int nid);
102102
103+extern u64 max_mem_size;
104+
103105 extern bool memhp_auto_online;
104106 /* If movable_node boot option specified */
105107 extern bool movable_node_enabled;
mm/memory_hotplug.c+6−0
@@ -96,10 +96,16 @@ void mem_hotplug_done(void) · 95 unmodified lines
9696 cpus_read_unlock();
9797 }
9898
99+u64 max_mem_size = U64_MAX;
100+
99101 /* add this memory to iomem resource */
100102 static struct resource *register_memory_resource(u64 start, u64 size)
101103 {
102104 struct resource *res, *conflict;
105+
106+ if (start + size > max_mem_size)
107+ return ERR_PTR(-E2BIG);
108+
103109 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
104110 if (!res)
105111 return ERR_PTR(-ENOMEM);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t