Commit afe789b7 authored by John Hubbard's avatar John Hubbard Committed by Andrew Morton
Browse files

kaslr: rename physmem_end and PHYSMEM_END to direct_map_physmem_end

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: default avatarJohn Hubbard <jhubbard@nvidia.com>
Reviewed-by: default avatarPankaj Gupta <pankaj.gupta@amd.com>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Acked-by: default avatarWill Deacon <will@kernel.org>
Reviewed-by: default avatarMike 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 01a9097a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@
#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)

+1 −1
Original line number Diff line number Diff line
@@ -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)
{
+1 −1
Original line number Diff line number Diff line
@@ -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

/*
+1 −1
Original line number Diff line number Diff line
@@ -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);
+9 −5
Original line number Diff line number Diff line
@@ -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.
		 */
Loading