]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
x86: respect memory size limiting via mem= parameter
authorJuergen Gross <jgross@suse.com>
Thu, 14 Feb 2019 10:42:39 +0000 (11:42 +0100)
committerJuergen Gross <jgross@suse.com>
Mon, 18 Feb 2019 05:50:34 +0000 (06:50 +0100)
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.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
arch/x86/kernel/e820.c
include/linux/memory_hotplug.h
mm/memory_hotplug.c

index 50895c2f937d144f9fd2b133c0522aadc7841c9e..e67513e2cbbb1711ebe0a972d6642161dee36392 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/acpi.h>
 #include <linux/firmware-map.h>
 #include <linux/sort.h>
+#include <linux/memory_hotplug.h>
 
 #include <asm/e820/api.h>
 #include <asm/setup.h>
@@ -881,6 +882,10 @@ static int __init parse_memopt(char *p)
 
        e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
 
+#ifdef CONFIG_MEMORY_HOTPLUG
+       max_mem_size = mem_size;
+#endif
+
        return 0;
 }
 early_param("mem", parse_memopt);
index 368267c1b71b101f3d1d9927197014e2a24efa85..cfd12078172ad54682107324054d4c73c972d339 100644 (file)
@@ -100,6 +100,8 @@ extern void __online_page_free(struct page *page);
 
 extern int try_online_node(int nid);
 
+extern u64 max_mem_size;
+
 extern bool memhp_auto_online;
 /* If movable_node boot option specified */
 extern bool movable_node_enabled;
index 124e794867c564c693e80a2b5827aebe3d3643d3..519f9db063ff5f875e862a0656041660e3bec412 100644 (file)
@@ -96,10 +96,16 @@ void mem_hotplug_done(void)
        cpus_read_unlock();
 }
 
+u64 max_mem_size = U64_MAX;
+
 /* add this memory to iomem resource */
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
        struct resource *res, *conflict;
+
+       if (start + size > max_mem_size)
+               return ERR_PTR(-E2BIG);
+
        res = kzalloc(sizeof(struct resource), GFP_KERNEL);
        if (!res)
                return ERR_PTR(-ENOMEM);