Commit b9b8e5b7 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 boot updates from Thomas Gleixner:
 "Boot code updates for x86:

   - Allow to skip a given amount of huge pages for address layout
     randomization on the kernel command line to prevent regressions in
     the huge page allocation with small memory sizes

   - Various cleanups"

* 'x86-boot-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/boot: Use CC_SET()/CC_OUT() instead of open coding it
  x86/boot/KASLR: Make local variable mem_limit static
  x86/boot/KASLR: Skip specified number of 1GB huge pages when doing physical randomization (KASLR)
  x86/boot/KASLR: Add two new functions for 1GB huge pages handling
parents 66e22087 216a3720
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define _LINUX_BITOPS_H /* Inhibit inclusion of <linux/bitops.h> */ #define _LINUX_BITOPS_H /* Inhibit inclusion of <linux/bitops.h> */
#include <linux/types.h> #include <linux/types.h>
#include <asm/asm.h>
static inline bool constant_test_bit(int nr, const void *addr) static inline bool constant_test_bit(int nr, const void *addr)
{ {
...@@ -28,7 +29,7 @@ static inline bool variable_test_bit(int nr, const void *addr) ...@@ -28,7 +29,7 @@ static inline bool variable_test_bit(int nr, const void *addr)
bool v; bool v;
const u32 *p = (const u32 *)addr; const u32 *p = (const u32 *)addr;
asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr)); asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
return v; return v;
} }
......
...@@ -102,7 +102,7 @@ static bool memmap_too_large; ...@@ -102,7 +102,7 @@ static bool memmap_too_large;
/* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */ /* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */
unsigned long long mem_limit = ULLONG_MAX; static unsigned long long mem_limit = ULLONG_MAX;
enum mem_avoid_index { enum mem_avoid_index {
...@@ -215,7 +215,36 @@ static void mem_avoid_memmap(char *str) ...@@ -215,7 +215,36 @@ static void mem_avoid_memmap(char *str)
memmap_too_large = true; memmap_too_large = true;
} }
static int handle_mem_memmap(void) /* Store the number of 1GB huge pages which users specified: */
static unsigned long max_gb_huge_pages;
static void parse_gb_huge_pages(char *param, char *val)
{
static bool gbpage_sz;
char *p;
if (!strcmp(param, "hugepagesz")) {
p = val;
if (memparse(p, &p) != PUD_SIZE) {
gbpage_sz = false;
return;
}
if (gbpage_sz)
warn("Repeatedly set hugeTLB page size of 1G!\n");
gbpage_sz = true;
return;
}
if (!strcmp(param, "hugepages") && gbpage_sz) {
p = val;
max_gb_huge_pages = simple_strtoull(p, &p, 0);
return;
}
}
static int handle_mem_options(void)
{ {
char *args = (char *)get_cmd_line_ptr(); char *args = (char *)get_cmd_line_ptr();
size_t len = strlen((char *)args); size_t len = strlen((char *)args);
...@@ -223,7 +252,8 @@ static int handle_mem_memmap(void) ...@@ -223,7 +252,8 @@ static int handle_mem_memmap(void)
char *param, *val; char *param, *val;
u64 mem_size; u64 mem_size;
if (!strstr(args, "memmap=") && !strstr(args, "mem=")) if (!strstr(args, "memmap=") && !strstr(args, "mem=") &&
!strstr(args, "hugepages"))
return 0; return 0;
tmp_cmdline = malloc(len + 1); tmp_cmdline = malloc(len + 1);
...@@ -248,6 +278,8 @@ static int handle_mem_memmap(void) ...@@ -248,6 +278,8 @@ static int handle_mem_memmap(void)
if (!strcmp(param, "memmap")) { if (!strcmp(param, "memmap")) {
mem_avoid_memmap(val); mem_avoid_memmap(val);
} else if (strstr(param, "hugepages")) {
parse_gb_huge_pages(param, val);
} else if (!strcmp(param, "mem")) { } else if (!strcmp(param, "mem")) {
char *p = val; char *p = val;
...@@ -387,7 +419,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size, ...@@ -387,7 +419,7 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,
/* We don't need to set a mapping for setup_data. */ /* We don't need to set a mapping for setup_data. */
/* Mark the memmap regions we need to avoid */ /* Mark the memmap regions we need to avoid */
handle_mem_memmap(); handle_mem_options();
#ifdef CONFIG_X86_VERBOSE_BOOTUP #ifdef CONFIG_X86_VERBOSE_BOOTUP
/* Make sure video RAM can be used. */ /* Make sure video RAM can be used. */
...@@ -466,6 +498,60 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) ...@@ -466,6 +498,60 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size)
} }
} }
/*
* Skip as many 1GB huge pages as possible in the passed region
* according to the number which users specified:
*/
static void
process_gb_huge_pages(struct mem_vector *region, unsigned long image_size)
{
unsigned long addr, size = 0;
struct mem_vector tmp;
int i = 0;
if (!max_gb_huge_pages) {
store_slot_info(region, image_size);
return;
}
addr = ALIGN(region->start, PUD_SIZE);
/* Did we raise the address above the passed in memory entry? */
if (addr < region->start + region->size)
size = region->size - (addr - region->start);
/* Check how many 1GB huge pages can be filtered out: */
while (size > PUD_SIZE && max_gb_huge_pages) {
size -= PUD_SIZE;
max_gb_huge_pages--;
i++;
}
/* No good 1GB huge pages found: */
if (!i) {
store_slot_info(region, image_size);
return;
}
/*
* Skip those 'i'*1GB good huge pages, and continue checking and
* processing the remaining head or tail part of the passed region
* if available.
*/
if (addr >= region->start + image_size) {
tmp.start = region->start;
tmp.size = addr - region->start;
store_slot_info(&tmp, image_size);
}
size = region->size - (addr - region->start) - i * PUD_SIZE;
if (size >= image_size) {
tmp.start = addr + i * PUD_SIZE;
tmp.size = size;
store_slot_info(&tmp, image_size);
}
}
static unsigned long slots_fetch_random(void) static unsigned long slots_fetch_random(void)
{ {
unsigned long slot; unsigned long slot;
...@@ -546,7 +632,7 @@ static void process_mem_region(struct mem_vector *entry, ...@@ -546,7 +632,7 @@ static void process_mem_region(struct mem_vector *entry,
/* If nothing overlaps, store the region and return. */ /* If nothing overlaps, store the region and return. */
if (!mem_avoid_overlap(&region, &overlap)) { if (!mem_avoid_overlap(&region, &overlap)) {
store_slot_info(&region, image_size); process_gb_huge_pages(&region, image_size);
return; return;
} }
...@@ -556,7 +642,7 @@ static void process_mem_region(struct mem_vector *entry, ...@@ -556,7 +642,7 @@ static void process_mem_region(struct mem_vector *entry,
beginning.start = region.start; beginning.start = region.start;
beginning.size = overlap.start - region.start; beginning.size = overlap.start - region.start;
store_slot_info(&beginning, image_size); process_gb_huge_pages(&beginning, image_size);
} }
/* Return if overlap extends to or past end of region. */ /* Return if overlap extends to or past end of region. */
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <asm/asm.h>
#include "ctype.h" #include "ctype.h"
#include "string.h" #include "string.h"
...@@ -28,8 +29,8 @@ ...@@ -28,8 +29,8 @@
int memcmp(const void *s1, const void *s2, size_t len) int memcmp(const void *s1, const void *s2, size_t len)
{ {
bool diff; bool diff;
asm("repe; cmpsb; setnz %0" asm("repe; cmpsb" CC_SET(nz)
: "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len)); : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
return diff; return diff;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment