]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
kaslr: rename physmem_end and PHYSMEM_END to direct_map_physmem_end
authorJohn Hubbard <jhubbard@nvidia.com>
Wed, 9 Oct 2024 02:50:24 +0000 (19:50 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 1 Nov 2024 04:29:04 +0000 (21:29 -0700)
For clarity.  It's increasingly hard to reason about the code, when KASLR
is moving around the boundaries.  In this case where KASLR is randomizing
the location of the kernel image within physical memory, the maximum
number of address bits for physical memory has not changed.

What has changed is the ending address of memory that is allowed to be
directly mapped by the kernel.

Let's name the variable, and the associated macro accordingly.

Also, enhance the comment above the direct_map_physmem_end definition,
to further clarify how this all works.

Link: https://lkml.kernel.org/r/20241009025024.89813-1-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Will Deacon <will@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jordan Niethe <jniethe@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/arm64/include/asm/memory.h
arch/x86/include/asm/page_64.h
arch/x86/include/asm/pgtable_64_types.h
arch/x86/mm/init_64.c
arch/x86/mm/kaslr.c
include/linux/mm.h
kernel/resource.c
mm/memory_hotplug.c
mm/sparse.c

index 0480c61dbb4f30f592cdd27f08a51ff01bd940b2..73eaa8c2536aecac1d896f974412745dbb30395a 100644 (file)
 #define PAGE_END               (_PAGE_END(VA_BITS_MIN))
 #endif /* CONFIG_KASAN */
 
-#define PHYSMEM_END            __pa(PAGE_END - 1)
+#define DIRECT_MAP_PHYSMEM_END __pa(PAGE_END - 1)
 
 #define MIN_THREAD_SHIFT       (14 + KASAN_THREAD_SHIFT)
 
index f3d257c452254dd564146314c8a668afb9454d6b..d63576608ce765127bd3b3c654dc4d2d9ca4c46a 100644 (file)
@@ -17,7 +17,7 @@ extern unsigned long phys_base;
 extern unsigned long page_offset_base;
 extern unsigned long vmalloc_base;
 extern unsigned long vmemmap_base;
-extern unsigned long physmem_end;
+extern unsigned long direct_map_physmem_end;
 
 static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
 {
index a98e53491a4e6e6d888ac3037d24a6f31ff20cb1..ec68f8369bdca4ebdf76c00373bc66dd1013b515 100644 (file)
@@ -141,7 +141,7 @@ extern unsigned int ptrs_per_p4d;
 #endif /* CONFIG_DYNAMIC_MEMORY_LAYOUT */
 
 #ifdef CONFIG_RANDOMIZE_MEMORY
-# define PHYSMEM_END           physmem_end
+# define DIRECT_MAP_PHYSMEM_END        direct_map_physmem_end
 #endif
 
 /*
index 50c7595f7228c314c0bce118637f359b664ed091..01ea7c6df3036bd185cdb3f54ddf244b79cbce8c 100644 (file)
@@ -961,7 +961,7 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
        unsigned long end = ((start_pfn + nr_pages) << PAGE_SHIFT) - 1;
        int ret;
 
-       if (WARN_ON_ONCE(end > PHYSMEM_END))
+       if (WARN_ON_ONCE(end > DIRECT_MAP_PHYSMEM_END))
                return -ERANGE;
 
        ret = __add_pages(nid, start_pfn, nr_pages, params);
index 230f1dee4f0954de03aa4432296d114e0733f5b4..70d3353c92fac1a5e5da15b0096be16043b9db44 100644 (file)
@@ -52,7 +52,7 @@ static __initdata struct kaslr_memory_region {
 } kaslr_regions[] = {
        {
                .base   = &page_offset_base,
-               .end    = &physmem_end,
+               .end    = &direct_map_physmem_end,
        },
        {
                .base   = &vmalloc_base,
@@ -62,8 +62,12 @@ static __initdata struct kaslr_memory_region {
        },
 };
 
-/* The end of the possible address space for physical memory */
-unsigned long physmem_end __ro_after_init;
+/*
+ * The end of the physical address space that can be mapped directly by the
+ * kernel. This starts out at (1<<MAX_PHYSMEM_BITS) - 1), but KASLR may reduce
+ * that in order to increase the available entropy for mapping other regions.
+ */
+unsigned long direct_map_physmem_end __ro_after_init;
 
 /* Get size in bytes used by the memory region */
 static inline unsigned long get_padding(struct kaslr_memory_region *region)
@@ -94,7 +98,7 @@ void __init kernel_randomize_memory(void)
        BUILD_BUG_ON(vaddr_end > __START_KERNEL_map);
 
        /* Preset the end of the possible address space for physical memory */
-       physmem_end = ((1ULL << MAX_PHYSMEM_BITS) - 1);
+       direct_map_physmem_end = ((1ULL << MAX_PHYSMEM_BITS) - 1);
        if (!kaslr_memory_enabled())
                return;
 
@@ -145,7 +149,7 @@ void __init kernel_randomize_memory(void)
                vaddr += get_padding(&kaslr_regions[i]);
                /*
                 * KASLR trims the maximum possible size of the
-                * direct-map. Update the physmem_end boundary.
+                * direct-map. Update the direct_map_physmem_end boundary.
                 * No rounding required as the region starts
                 * PUD aligned and size is in units of TB.
                 */
index 46d0654df3bd880377286b4dc99bcd6f38c6a3d5..5f9f055ed21aa6c376c88403de957eabd45d86c7 100644 (file)
@@ -97,11 +97,11 @@ extern const int mmap_rnd_compat_bits_max;
 extern int mmap_rnd_compat_bits __read_mostly;
 #endif
 
-#ifndef PHYSMEM_END
+#ifndef DIRECT_MAP_PHYSMEM_END
 # ifdef MAX_PHYSMEM_BITS
-# define PHYSMEM_END   ((1ULL << MAX_PHYSMEM_BITS) - 1)
+# define DIRECT_MAP_PHYSMEM_END        ((1ULL << MAX_PHYSMEM_BITS) - 1)
 # else
-# define PHYSMEM_END   (((phys_addr_t)-1)&~(1ULL<<63))
+# define DIRECT_MAP_PHYSMEM_END        (((phys_addr_t)-1)&~(1ULL<<63))
 # endif
 #endif
 
index 4101016e8b205c8e2ffed5dfd20ce439603d53b7..d2c8143ae4ff9f204d8bed21fb7237b17cb85a6a 100644 (file)
@@ -1869,7 +1869,7 @@ static resource_size_t gfr_start(struct resource *base, resource_size_t size,
        if (flags & GFR_DESCENDING) {
                resource_size_t end;
 
-               end = min_t(resource_size_t, base->end, PHYSMEM_END);
+               end = min_t(resource_size_t, base->end, DIRECT_MAP_PHYSMEM_END);
                return end - size + 1;
        }
 
@@ -1886,7 +1886,7 @@ static bool gfr_continue(struct resource *base, resource_size_t addr,
         * @size did not wrap 0.
         */
        return addr > addr - size &&
-              addr <= min_t(resource_size_t, base->end, PHYSMEM_END);
+              addr <= min_t(resource_size_t, base->end, DIRECT_MAP_PHYSMEM_END);
 }
 
 static resource_size_t gfr_next(resource_size_t addr, resource_size_t size,
index 621ae1015106c51067bef82a6b7e86ffc622524f..c43b4e7fb2984f08a637539c5eec2da470a903ca 100644 (file)
@@ -1681,7 +1681,7 @@ struct range __weak arch_get_mappable_range(void)
 
 struct range mhp_get_pluggable_range(bool need_mapping)
 {
-       const u64 max_phys = PHYSMEM_END;
+       const u64 max_phys = DIRECT_MAP_PHYSMEM_END;
        struct range mhp_range;
 
        if (need_mapping) {
index 6ba5354cf2e117e5f19221fc8caff38779b5cc93..13b6624d356263755d19f6827a7022e0bbfd4751 100644 (file)
@@ -129,7 +129,7 @@ static inline int sparse_early_nid(struct mem_section *section)
 static void __meminit mminit_validate_memmodel_limits(unsigned long *start_pfn,
                                                unsigned long *end_pfn)
 {
-       unsigned long max_sparsemem_pfn = (PHYSMEM_END + 1) >> PAGE_SHIFT;
+       unsigned long max_sparsemem_pfn = (DIRECT_MAP_PHYSMEM_END + 1) >> PAGE_SHIFT;
 
        /*
         * Sanity checks - do not allow an architecture to pass