Lines Matching +full:memory +full:- +full:region
1 // SPDX-License-Identifier: GPL-2.0
8 * handles walking the physical memory maps (and tracking memory regions
9 * to avoid) in order to select a physical memory location that can
41 /* Simplified build-specific string for starting entropy. */
53 hash = (hash << ((sizeof(hash) * 8) - 7)) | (hash >> 7); in rotate_xor()
82 * Store memory limit: MAXMEM on 64-bit and KERNEL_IMAGE_SIZE on 32-bit.
87 /* Number of immovable memory regions */
96 MEM_AVOID_MEMMAP_END = MEM_AVOID_MEMMAP_BEGIN + MAX_MEMMAP_REGIONS - 1,
105 if (one->start + one->size <= two->start) in mem_overlaps()
108 if (one->start >= two->start + two->size) in mem_overlaps()
133 return -EINVAL; in parse_memmap()
137 return -EINVAL; in parse_memmap()
142 return -EINVAL; in parse_memmap()
153 * memmap=nn@ss specifies usable region, should in parse_memmap()
162 * flags that might imply a soft-reservation. in parse_memmap()
179 * system can use. Region above the limit should be avoided. in parse_memmap()
185 return -EINVAL; in parse_memmap()
209 /* Store the specified memory limit if size > 0 */ in mem_avoid_memmap()
265 len = strnlen(args, COMMAND_LINE_SIZE-1); in handle_mem_options()
279 /* Stop at -- */ in handle_mem_options()
280 if (!val && strcmp(param, "--") == 0) in handle_mem_options()
309 * on 64-bit, and [16M, KERNEL_IMAGE_SIZE) on 32-bit.
316 * memory ranges lead to really hard to debug boot failures.
322 * What is not obvious how to avoid is the range of memory that is used
332 * in header.S, and the memory diagram is based on the one found in misc.c.
336 * - input + input_size >= output + output_size
337 * - kernel_total_size <= init_size
338 * - kernel_total_size <= output_size (see Note below)
339 * - output + init_size >= output + output_size
352 * |-----|--------|--------|--------------|-----------|--|-------------|
355 * output+init_size-ZO_INIT_SIZE output+output_size output+kernel_total_size
357 * [output, output+init_size) is the entire memory range used for
367 * [output+init_size-ZO_INIT_SIZE, output+init_size) is the worst-case
386 unsigned long init_size = boot_params->hdr.init_size; in mem_avoid_init()
391 * Avoid the region that is unsafe to overlap during in mem_avoid_init()
395 mem_avoid[MEM_AVOID_ZO_RANGE].size = (output + init_size) - input; in mem_avoid_init()
398 initrd_start = (u64)boot_params->ext_ramdisk_image << 32; in mem_avoid_init()
399 initrd_start |= boot_params->hdr.ramdisk_image; in mem_avoid_init()
400 initrd_size = (u64)boot_params->ext_ramdisk_size << 32; in mem_avoid_init()
401 initrd_size |= boot_params->hdr.ramdisk_size; in mem_avoid_init()
410 cmd_line_size = strnlen((char *)cmd_line, COMMAND_LINE_SIZE-1) + 1; in mem_avoid_init()
424 /* Enumerate the immovable memory regions */ in mem_avoid_init()
429 * Does this memory vector overlap a known avoided area? If so, record the
430 * overlap region with the lowest address.
437 u64 earliest = img->start + img->size; in mem_avoid_overlap()
444 earliest = overlap->start; in mem_avoid_overlap()
450 ptr = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data; in mem_avoid_overlap()
455 avoid.size = sizeof(*ptr) + ptr->len; in mem_avoid_overlap()
459 earliest = overlap->start; in mem_avoid_overlap()
463 if (ptr->type == SETUP_INDIRECT && in mem_avoid_overlap()
464 ((struct setup_indirect *)ptr->data)->type != SETUP_INDIRECT) { in mem_avoid_overlap()
465 avoid.start = ((struct setup_indirect *)ptr->data)->addr; in mem_avoid_overlap()
466 avoid.size = ((struct setup_indirect *)ptr->data)->len; in mem_avoid_overlap()
470 earliest = overlap->start; in mem_avoid_overlap()
475 ptr = (struct setup_data *)(unsigned long)ptr->next; in mem_avoid_overlap()
492 static void store_slot_info(struct mem_vector *region, unsigned long image_size) in store_slot_info() argument
499 slot_area.addr = region->start; in store_slot_info()
500 slot_area.num = 1 + (region->size - image_size) / CONFIG_PHYSICAL_ALIGN; in store_slot_info()
507 * Skip as many 1GB huge pages as possible in the passed region
511 process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) in process_gb_huge_pages() argument
518 store_slot_info(region, image_size); in process_gb_huge_pages()
522 /* Are there any 1GB pages in the region? */ in process_gb_huge_pages()
523 pud_start = ALIGN(region->start, PUD_SIZE); in process_gb_huge_pages()
524 pud_end = ALIGN_DOWN(region->start + region->size, PUD_SIZE); in process_gb_huge_pages()
528 store_slot_info(region, image_size); in process_gb_huge_pages()
532 /* Check if the head part of the region is usable. */ in process_gb_huge_pages()
533 if (pud_start >= region->start + image_size) { in process_gb_huge_pages()
534 tmp.start = region->start; in process_gb_huge_pages()
535 tmp.size = pud_start - region->start; in process_gb_huge_pages()
540 gb_huge_pages = (pud_end - pud_start) >> PUD_SHIFT; in process_gb_huge_pages()
545 max_gb_huge_pages -= gb_huge_pages; in process_gb_huge_pages()
548 /* Check if the tail part of the region is usable. */ in process_gb_huge_pages()
549 if (region->start + region->size >= pud_end + image_size) { in process_gb_huge_pages()
551 tmp.size = region->start + region->size - pud_end; in process_gb_huge_pages()
569 slot -= slot_areas[i].num; in slots_fetch_random()
584 struct mem_vector region, overlap; in __process_mem_region() local
587 /* Enforce minimum and memory limit. */ in __process_mem_region()
588 region.start = max_t(u64, entry->start, minimum); in __process_mem_region()
589 region_end = min(entry->start + entry->size, mem_limit); in __process_mem_region()
594 region.start = ALIGN(region.start, CONFIG_PHYSICAL_ALIGN); in __process_mem_region()
596 /* Did we raise the address above the passed in memory entry? */ in __process_mem_region()
597 if (region.start > region_end) in __process_mem_region()
601 region.size = region_end - region.start; in __process_mem_region()
603 /* Return if region can't contain decompressed kernel */ in __process_mem_region()
604 if (region.size < image_size) in __process_mem_region()
607 /* If nothing overlaps, store the region and return. */ in __process_mem_region()
608 if (!mem_avoid_overlap(®ion, &overlap)) { in __process_mem_region()
609 process_gb_huge_pages(®ion, image_size); in __process_mem_region()
613 /* Store beginning of region if holds at least image_size. */ in __process_mem_region()
614 if (overlap.start >= region.start + image_size) { in __process_mem_region()
615 region.size = overlap.start - region.start; in __process_mem_region()
616 process_gb_huge_pages(®ion, image_size); in __process_mem_region()
619 /* Clip off the overlapping region and start over. */ in __process_mem_region()
620 region.start = overlap.start + overlap.size; in __process_mem_region()
624 static bool process_mem_region(struct mem_vector *region, in process_mem_region() argument
630 * If no immovable memory found, or MEMORY_HOTREMOVE disabled, in process_mem_region()
631 * use @region directly. in process_mem_region()
634 __process_mem_region(region, minimum, image_size); in process_mem_region()
645 * If immovable memory found, filter the intersection between in process_mem_region()
646 * immovable memory and @region. in process_mem_region()
652 if (!mem_overlaps(region, &immovable_mem[i])) in process_mem_region()
657 region_end = region->start + region->size; in process_mem_region()
659 entry.start = clamp(region->start, start, end); in process_mem_region()
661 entry.size = entry_end - entry.start; in process_mem_region()
682 struct efi_info *e = &boot_params->efi_info; in process_efi_entries()
684 struct mem_vector region; in process_efi_entries() local
691 signature = (char *)&e->efi_loader_signature; in process_efi_entries()
698 if (e->efi_memmap_hi) { in process_efi_entries()
702 pmap = e->efi_memmap; in process_efi_entries()
704 pmap = (e->efi_memmap | ((__u64)e->efi_memmap_hi << 32)); in process_efi_entries()
707 nr_desc = e->efi_memmap_size / e->efi_memdesc_size; in process_efi_entries()
709 md = efi_early_memdesc_ptr(pmap, e->efi_memdesc_size, i); in process_efi_entries()
710 if (md->attribute & EFI_MEMORY_MORE_RELIABLE) { in process_efi_entries()
717 md = efi_early_memdesc_ptr(pmap, e->efi_memdesc_size, i); in process_efi_entries()
720 * Here we are more conservative in picking free memory than in process_efi_entries()
724 * free memory and thus available to place the kernel image into, in process_efi_entries()
725 * but in practice there's firmware where using that memory leads in process_efi_entries()
730 if (md->type != EFI_CONVENTIONAL_MEMORY) in process_efi_entries()
734 (md->attribute & EFI_MEMORY_SP)) in process_efi_entries()
738 !(md->attribute & EFI_MEMORY_MORE_RELIABLE)) in process_efi_entries()
741 region.start = md->phys_addr; in process_efi_entries()
742 region.size = md->num_pages << EFI_PAGE_SHIFT; in process_efi_entries()
743 if (process_mem_region(®ion, minimum, image_size)) in process_efi_entries()
760 struct mem_vector region; in process_e820_entries() local
764 for (i = 0; i < boot_params->e820_entries; i++) { in process_e820_entries()
765 entry = &boot_params->e820_table[i]; in process_e820_entries()
766 /* Skip non-RAM entries. */ in process_e820_entries()
767 if (entry->type != E820_TYPE_RAM) in process_e820_entries()
769 region.start = entry->addr; in process_e820_entries()
770 region.size = entry->size; in process_e820_entries()
771 if (process_mem_region(®ion, minimum, image_size)) in process_e820_entries()
787 debug_putstr("Aborted memory entries scan (more than 4 memmap= args)!\n"); in find_random_phys_addr()
811 * There are how many CONFIG_PHYSICAL_ALIGN-sized slots in find_random_virt_addr()
815 slots = 1 + (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICAL_ALIGN; in find_random_virt_addr()
839 boot_params->hdr.loadflags |= KASLR_FLAG; in choose_random_location()
846 /* Record the various known unsafe memory ranges. */ in choose_random_location()
858 /* Walk available memory entries to find a random address. */ in choose_random_location()
861 warn("Physical KASLR disabled: no suitable memory region!"); in choose_random_location()