Lines Matching +full:memory +full:- +full:region
1 // SPDX-License-Identifier: GPL-2.0
3 * This file implements KASLR memory randomization for x86_64. It randomizes
4 * the virtual address space of kernel memory regions (physical memory
11 * The physical memory mapping code was adapted to support P4D/PUD level
13 * 30,000 possible virtual addresses in average for each memory region.
14 * An additional low memory page is used to ensure each CPU can start with
17 * The order of each memory region is not changed. The feature looks at
20 * physical memory mapping is the available physical memory.
44 * Memory regions randomized by KASLR (except modules that use a separate logic
65 /* The end of the possible address space for physical memory */
68 /* Get size in bytes used by the memory region */
69 static inline unsigned long get_padding(struct kaslr_memory_region *region) in get_padding() argument
71 return (region->size_tb << TB_SHIFT); in get_padding()
74 /* Initialize base and padding for each memory region randomized with KASLR */
88 * These BUILD_BUG_ON checks ensure the memory layout is consistent in kernel_randomize_memory()
96 /* Preset the end of the possible address space for physical memory */ in kernel_randomize_memory()
97 physmem_end = ((1ULL << MAX_PHYSMEM_BITS) - 1); in kernel_randomize_memory()
101 kaslr_regions[0].size_tb = 1 << (MAX_PHYSMEM_BITS - TB_SHIFT); in kernel_randomize_memory()
105 * Update Physical memory mapping to available and in kernel_randomize_memory()
106 * add padding if needed (especially for memory hotplug support). in kernel_randomize_memory()
112 /* Adapt physical memory region size based on available memory */ in kernel_randomize_memory()
117 * Calculate the vmemmap region size in TBs, aligned to a TB in kernel_randomize_memory()
120 vmemmap_size = (kaslr_regions[0].size_tb << (TB_SHIFT - PAGE_SHIFT)) * in kernel_randomize_memory()
125 remain_entropy = vaddr_end - vaddr_start; in kernel_randomize_memory()
127 remain_entropy -= get_padding(&kaslr_regions[i]); in kernel_randomize_memory()
129 prandom_seed_state(&rand_state, kaslr_get_random_long("Memory")); in kernel_randomize_memory()
138 entropy = remain_entropy / (ARRAY_SIZE(kaslr_regions) - i); in kernel_randomize_memory()
144 /* Calculate the end of the region */ in kernel_randomize_memory()
148 * direct-map. Update the physmem_end boundary. in kernel_randomize_memory()
149 * No rounding required as the region starts in kernel_randomize_memory()
153 *kaslr_regions[i].end = __pa_nodebug(vaddr - 1); in kernel_randomize_memory()
157 remain_entropy -= entropy; in kernel_randomize_memory()