mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Since commit
97d6786e06
("arm64: mm: account for hotplug memory when randomizing the linear region")
the decision whether or not to randomize the placement of the system's
DRAM inside the linear map is based on the capabilities of the CPU
rather than how much memory is present at boot time. This change was
necessary because memory hotplug may result in DRAM appearing in places
that are not covered by the linear region at all (and therefore
unusable) if the decision is solely based on the memory map at boot.
In the Android GKI kernel, which requires support for memory hotplug,
and is built with a reduced virtual address space of only 39 bits wide,
randomization of the linear map never happens in practice as a result.
And even on arm64 kernels built with support for 48 bit virtual
addressing, the wider PArange of recent CPUs means that linear map
randomization is slowly becoming a feature that only works on systems
that will soon be obsolete.
So let's just remove this feature. We can always bring it back in an
improved form if there is a real need for it.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Kees Cook <kees@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250318134949.3194334-2-ardb+git@google.com
Signed-off-by: Will Deacon <will@kernel.org>
62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
// Copyright 2022 Google LLC
|
|
// Author: Ard Biesheuvel <ardb@google.com>
|
|
|
|
// NOTE: code in this file runs *very* early, and is not permitted to use
|
|
// global variables or anything that relies on absolute addressing.
|
|
|
|
#include <linux/libfdt.h>
|
|
#include <linux/init.h>
|
|
#include <linux/linkage.h>
|
|
#include <linux/types.h>
|
|
#include <linux/sizes.h>
|
|
#include <linux/string.h>
|
|
|
|
#include <asm/archrandom.h>
|
|
#include <asm/memory.h>
|
|
#include <asm/pgtable.h>
|
|
|
|
#include "pi.h"
|
|
|
|
static u64 __init get_kaslr_seed(void *fdt, int node)
|
|
{
|
|
static char const seed_str[] __initconst = "kaslr-seed";
|
|
fdt64_t *prop;
|
|
u64 ret;
|
|
int len;
|
|
|
|
if (node < 0)
|
|
return 0;
|
|
|
|
prop = fdt_getprop_w(fdt, node, seed_str, &len);
|
|
if (!prop || len != sizeof(u64))
|
|
return 0;
|
|
|
|
ret = fdt64_to_cpu(*prop);
|
|
*prop = 0;
|
|
return ret;
|
|
}
|
|
|
|
u64 __init kaslr_early_init(void *fdt, int chosen)
|
|
{
|
|
u64 seed, range;
|
|
|
|
if (kaslr_disabled_cmdline())
|
|
return 0;
|
|
|
|
seed = get_kaslr_seed(fdt, chosen);
|
|
if (!seed) {
|
|
if (!__early_cpu_has_rndr() ||
|
|
!__arm64_rndr((unsigned long *)&seed))
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* OK, so we are proceeding with KASLR enabled. Calculate a suitable
|
|
* kernel image offset from the seed. Let's place the kernel in the
|
|
* 'middle' half of the VMALLOC area, and stay clear of the lower and
|
|
* upper quarters to avoid colliding with other allocations.
|
|
*/
|
|
range = (VMALLOC_END - KIMAGE_VADDR) / 2;
|
|
return range / 2 + (((__uint128_t)range * seed) >> 64);
|
|
}
|