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
14#include <linux/acpi.h>14#include <linux/acpi.h>
15#include <linux/firmware-map.h>15#include <linux/firmware-map.h>
16#include <linux/sort.h>16#include <linux/sort.h>
17#include <linux/memory_hotplug.h>
17 18
18#include <asm/e820/api.h>19#include <asm/e820/api.h>
19#include <asm/setup.h>20#include <asm/setup.h>
@@ -881,6 +882,10 @@ static int __init parse_memopt(char *p) · 861 unmodified lines
881 882
882 e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);883 e820__range_remove(mem_size, ULLONG_MAX - mem_size, E820_TYPE_RAM, 1);
883 884
885#ifdef CONFIG_MEMORY_HOTPLUG
886 max_mem_size = mem_size;
887#endif
888
884 return 0;889 return 0;
885}890}
886early_param("mem", parse_memopt);891early_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
100 100
101extern int try_online_node(int nid);101extern int try_online_node(int nid);
102 102
103extern u64 max_mem_size;
104
103extern bool memhp_auto_online;105extern bool memhp_auto_online;
104/* If movable_node boot option specified */106/* If movable_node boot option specified */
105extern bool movable_node_enabled;107extern bool movable_node_enabled;
mm/memory_hotplug.c+6−0
@@ -96,10 +96,16 @@ void mem_hotplug_done(void) · 95 unmodified lines
96 cpus_read_unlock();96 cpus_read_unlock();
97}97}
98 98
99u64 max_mem_size = U64_MAX;
100
99/* add this memory to iomem resource */101/* add this memory to iomem resource */
100static struct resource *register_memory_resource(u64 start, u64 size)102static struct resource *register_memory_resource(u64 start, u64 size)
101{103{
102 struct resource *res, *conflict;104 struct resource *res, *conflict;
105
106 if (start + size > max_mem_size)
107 return ERR_PTR(-E2BIG);
108
103 res = kzalloc(sizeof(struct resource), GFP_KERNEL);109 res = kzalloc(sizeof(struct resource), GFP_KERNEL);
104 if (!res)110 if (!res)
105 return ERR_PTR(-ENOMEM);111 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