Commit be9e8d95 authored by Arvind Sankar's avatar Arvind Sankar Committed by Ingo Molnar

x86/kaslr: Simplify process_gb_huge_pages()

Replace the loop to determine the number of 1Gb pages with arithmetic.
Signed-off-by: default avatarArvind Sankar <nivedita@alum.mit.edu>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200728225722.67457-13-nivedita@alum.mit.edu
parent 50def269
...@@ -547,49 +547,44 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) ...@@ -547,49 +547,44 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size)
static void static void
process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) process_gb_huge_pages(struct mem_vector *region, unsigned long image_size)
{ {
unsigned long addr, size = 0; unsigned long pud_start, pud_end, gb_huge_pages;
struct mem_vector tmp; struct mem_vector tmp;
int i = 0;
if (!IS_ENABLED(CONFIG_X86_64) || !max_gb_huge_pages) { if (!IS_ENABLED(CONFIG_X86_64) || !max_gb_huge_pages) {
store_slot_info(region, image_size); store_slot_info(region, image_size);
return; return;
} }
addr = ALIGN(region->start, PUD_SIZE); /* Are there any 1GB pages in the region? */
/* Did we raise the address above the passed in memory entry? */ pud_start = ALIGN(region->start, PUD_SIZE);
if (addr < region->start + region->size) pud_end = ALIGN_DOWN(region->start + region->size, PUD_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: */ /* No good 1GB huge pages found: */
if (!i) { if (pud_start >= pud_end) {
store_slot_info(region, image_size); store_slot_info(region, image_size);
return; return;
} }
/* /* Check if the head part of the region is usable. */
* Skip those 'i'*1GB good huge pages, and continue checking and if (pud_start >= region->start + image_size) {
* processing the remaining head or tail part of the passed region
* if available.
*/
if (addr >= region->start + image_size) {
tmp.start = region->start; tmp.start = region->start;
tmp.size = addr - region->start; tmp.size = pud_start - region->start;
store_slot_info(&tmp, image_size); store_slot_info(&tmp, image_size);
} }
size = region->size - (addr - region->start) - i * PUD_SIZE; /* Skip the good 1GB pages. */
if (size >= image_size) { gb_huge_pages = (pud_end - pud_start) >> PUD_SHIFT;
tmp.start = addr + i * PUD_SIZE; if (gb_huge_pages > max_gb_huge_pages) {
tmp.size = size; pud_end = pud_start + (max_gb_huge_pages << PUD_SHIFT);
max_gb_huge_pages = 0;
} else {
max_gb_huge_pages -= gb_huge_pages;
}
/* Check if the tail part of the region is usable. */
if (region->start + region->size >= pud_end + image_size) {
tmp.start = pud_end;
tmp.size = region->start + region->size - pud_end;
store_slot_info(&tmp, image_size); store_slot_info(&tmp, image_size);
} }
} }
......
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