Skip to content

Commit bf457be

Browse files
nivedita76ingomolnar
authored andcommitted
x86/kaslr: Drop some redundant checks from __process_mem_region()
Clip the start and end of the region to minimum and mem_limit prior to the loop. region.start can only increase during the loop, so raising it to minimum before the loop is enough. A region that becomes empty due to this will get checked in the first iteration of the loop. Drop the check for overlap extending beyond the end of the region. This will get checked in the next loop iteration anyway. Rename end to region_end for symmetry with region.start. Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20200728225722.67457-10-nivedita@alum.mit.edu
1 parent ef7b07d commit bf457be

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

arch/x86/boot/compressed/kaslr.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -623,34 +623,23 @@ static void __process_mem_region(struct mem_vector *entry,
623623
unsigned long image_size)
624624
{
625625
struct mem_vector region, overlap;
626-
unsigned long end;
626+
unsigned long region_end;
627627

628-
/* Ignore entries entirely below our minimum. */
629-
if (entry->start + entry->size < minimum)
630-
return;
631-
632-
/* Ignore entries above memory limit */
633-
end = min(entry->size + entry->start, mem_limit);
634-
if (entry->start >= end)
635-
return;
636-
637-
region.start = entry->start;
628+
/* Enforce minimum and memory limit. */
629+
region.start = max_t(unsigned long long, entry->start, minimum);
630+
region_end = min(entry->start + entry->size, mem_limit);
638631

639632
/* Give up if slot area array is full. */
640633
while (slot_area_index < MAX_SLOT_AREA) {
641-
/* Potentially raise address to minimum location. */
642-
if (region.start < minimum)
643-
region.start = minimum;
644-
645634
/* Potentially raise address to meet alignment needs. */
646635
region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN);
647636

648637
/* Did we raise the address above the passed in memory entry? */
649-
if (region.start > end)
638+
if (region.start > region_end)
650639
return;
651640

652641
/* Reduce size by any delta from the original address. */
653-
region.size = end - region.start;
642+
region.size = region_end - region.start;
654643

655644
/* Return if region can't contain decompressed kernel */
656645
if (region.size < image_size)
@@ -668,10 +657,6 @@ static void __process_mem_region(struct mem_vector *entry,
668657
process_gb_huge_pages(&region, image_size);
669658
}
670659

671-
/* Return if overlap extends to or past end of region. */
672-
if (overlap.start + overlap.size >= region.start + region.size)
673-
return;
674-
675660
/* Clip off the overlapping region and start over. */
676661
region.start = overlap.start + overlap.size;
677662
}

0 commit comments

Comments
 (0)