linux-stable/arch/arm/kernel
Ard Biesheuvel 9443076e43 ARM: p2v: reduce p2v alignment requirement to 2 MiB
The ARM kernel's linear map starts at PAGE_OFFSET, which maps to a
physical address (PHYS_OFFSET) that is platform specific, and is
discovered at boot. Since we don't want to slow down translations
between physical and virtual addresses by keeping the offset in a
variable in memory, we implement this by patching the code performing
the translation, and putting the offset between PAGE_OFFSET and the
start of physical RAM directly into the instruction opcodes.

As we only patch up to 8 bits of offset, yielding 4 GiB >> 8 == 16 MiB
of granularity, we have to round up PHYS_OFFSET to the next multiple if
the start of physical RAM is not a multiple of 16 MiB. This wastes some
physical RAM, since the memory that was skipped will now live below
PAGE_OFFSET, making it inaccessible to the kernel.

We can improve this by changing the patchable sequences and the patching
logic to carry more bits of offset: 11 bits gives us 4 GiB >> 11 == 2 MiB
of granularity, and so we will never waste more than that amount by
rounding up the physical start of DRAM to the next multiple of 2 MiB.
(Note that 2 MiB granularity guarantees that the linear mapping can be
created efficiently, whereas less than 2 MiB may result in the linear
mapping needing another level of page tables)

This helps Zhen Lei's scenario, where the start of DRAM is known to be
occupied. It also helps EFI boot, which relies on the firmware's page
allocator to allocate space for the decompressed kernel as low as
possible. And if the KASLR patches ever land for 32-bit, it will give
us 3 more bits of randomization of the placement of the kernel inside
the linear region.

For the ARM code path, it simply comes down to using two add/sub
instructions instead of one for the carryless version, and patching
each of them with the correct immediate depending on the rotation
field. For the LPAE calculation, which has to deal with a carry, it
patches the MOVW instruction with up to 12 bits of offset (but we only
need 11 bits anyway)

For the Thumb2 code path, patching more than 11 bits of displacement
would be somewhat cumbersome, but the 11 bits we need fit nicely into
the second word of the u16[2] opcode, so we simply update the immediate
assignment and the left shift to create an addend of the right magnitude.

Suggested-by: Zhen Lei <thunder.leizhen@huawei.com>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2020-10-28 16:59:43 +01:00
..
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
arch_timer.c ARM: 8913/1: arch_timer: include <asm/arch_timer.h> 2019-10-27 21:14:43 +00:00
armksyms.c crypto: lib/sha1 - remove unnecessary includes of linux/cryptohash.h 2020-05-08 15:32:17 +10:00
asm-offsets.c Raise gcc version requirement to 4.9 2020-07-08 10:48:35 -07:00
atags.h
atags_compat.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
atags_parse.c initrd: remove support for multiple floppies 2020-07-30 08:22:33 +02:00
atags_proc.c ARM: 8973/1: Add missing newline terminator to kernel message 2020-05-07 20:53:10 +01:00
bios32.c ARM/PCI: Remove unused fields from struct hw_pci 2020-09-18 22:39:09 +01:00
bugs.c treewide: fix typos of SPDX-License-Identifier 2019-06-01 18:29:58 +02:00
cpuidle.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
crash_dump.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
debug.S ARM: 9005/1: debug: Select flow control for all debug UARTs 2020-09-15 14:35:28 +01:00
devtree.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
dma-isa.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
dma.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
early_printk.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
efi.c mm/pgtable: drop pgtable_t variable from pte_fn_t functions 2019-07-12 11:05:46 -07:00
elf.c arm32/64/elf: Split READ_IMPLIES_EXEC from executable PT_GNU_STACK 2020-04-20 19:42:19 +02:00
entry-armv.S ARM: uaccess: consolidate uaccess asm to asm/uaccess-asm.h 2020-05-03 17:30:24 +01:00
entry-common.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
entry-ftrace.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
entry-header.S ARM: uaccess: consolidate uaccess asm to asm/uaccess-asm.h 2020-05-03 17:30:24 +01:00
entry-v7m.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
fiq.c arm: fix the flush_icache_range arguments in set_fiq_handler 2020-06-08 11:05:57 -07:00
fiqasm.S
ftrace.c maccess: rename probe_kernel_{read,write} to copy_{from,to}_kernel_nofault 2020-06-17 10:57:41 -07:00
head-common.S ARM: 8914/1: NOMMU: Fix exc_ret for XIP 2019-10-10 22:23:20 +01:00
head-inflate-data.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
head-nommu.S ARM: 8914/1: NOMMU: Fix exc_ret for XIP 2019-10-10 22:23:20 +01:00
head.S ARM: p2v: move patching code to separate assembler source file 2020-10-28 16:59:43 +01:00
hibernate.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 194 2019-05-30 11:29:22 -07:00
hw_breakpoint.c ARM: 8997/2: hw_breakpoint: Handle inexact watchpoint addresses 2020-09-15 14:35:24 +01:00
hyp-stub.S arm: Remove the ability to set HYP vectors outside of the decompressor 2020-03-24 10:56:05 +00:00
insn.c
io.c
irq.c ARM: Remove custom IRQ stat accounting 2020-09-17 16:37:28 +01:00
isa.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
iwmmxt.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
jump_label.c
kgdb.c maccess: rename probe_kernel_{read,write} to copy_{from,to}_kernel_nofault 2020-06-17 10:57:41 -07:00
machine_kexec.c mm: remove unneeded includes of <asm/pgalloc.h> 2020-08-07 11:33:26 -07:00
Makefile ARM: p2v: move patching code to separate assembler source file 2020-10-28 16:59:43 +01:00
module-plts.c ARM: 8910/1: fix missing declartion of module_frob_arch_sections 2019-10-27 21:14:38 +00:00
module.c ARM: module: add support for place relative relocations 2020-10-28 16:59:43 +01:00
opcodes.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
paravirt.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
patch.c arm/patch: Fix !MMU compile 2020-02-11 12:56:27 +01:00
perf_callchain.c
perf_event_v6.c
perf_event_v7.c ARM: 8873/1: perf: cleanup cppcheck shifting warning 2019-08-23 11:38:46 +01:00
perf_event_xscale.c
perf_regs.c
phys2virt.S ARM: p2v: reduce p2v alignment requirement to 2 MiB 2020-10-28 16:59:43 +01:00
pj4-cp0.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
process.c Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2020-08-09 13:33:54 -07:00
psci_smp.c ARM: 8919/1: make unexported functions static 2019-10-31 16:58:52 +00:00
ptrace.c arm: switch to ->regset_get() 2020-07-27 14:31:09 -04:00
reboot.c ARM: Use reboot_cpu instead of hardcoding it to 0 2020-03-25 12:59:33 +01:00
reboot.h
relocate_kernel.S ARM: 8962/1: kexec: drop invalid assembly argument 2020-03-12 11:29:02 +00:00
return_address.c ARM: 8918/2: only build return_address() if needed 2019-11-15 22:21:07 +00:00
setup.c arch, drivers: replace for_each_membock() with for_each_mem_range() 2020-10-13 18:38:35 -07:00
signal.c tracehook: clear TIF_NOTIFY_RESUME in tracehook_notify_resume() 2020-10-17 15:04:36 -06:00
signal.h ARM: 8920/1: share get_signal_page from signal.c to process.c 2019-10-31 16:58:53 +00:00
sigreturn_codes.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
sleep.S
smccc-call.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 282 2019-06-05 17:36:37 +02:00
smp.c ARM: Handle no IPI being registered in show_ipi_list() 2020-09-28 11:32:04 +01:00
smp_scu.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
smp_tlb.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
smp_twd.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
stacktrace.c ARM: 8992/1: Fix unwind_frame for clang-built kernels 2020-07-21 16:33:40 +01:00
suspend.c mm: remove unneeded includes of <asm/pgalloc.h> 2020-08-07 11:33:26 -07:00
swp_emulate.c mmap locking API: use coccinelle to convert mmap_sem rwsem call sites 2020-06-09 09:39:14 -07:00
sys_arm.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
sys_oabi-compat.c ARM: compat: remove KERNEL_DS usage in sys_oabi_epoll_ctl() 2020-04-21 17:49:30 +01:00
tcm.c ARM: 8925/1: tcm: include <asm/tcm.h> for missing declarations 2019-10-31 16:58:56 +00:00
thumbee.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
time.c ARM/time: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-05-15 22:54:57 +02:00
topology.c ARM, sched/topology: Revert back to default scheduler topology 2020-08-19 10:49:47 +02:00
traps.c maccess: make get_kernel_nofault() check for minimal type compatibility 2020-06-18 12:10:37 -07:00
unwind.c arm: add loglvl to unwind_backtrace() 2020-06-09 09:39:10 -07:00
v7m.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
vdso.c ARM: 8987/1: VDSO: Fix incorrect clock_gettime64 2020-07-21 16:32:55 +01:00
vmlinux-xip.lds.S arm/build: Assert for unwanted sections 2020-09-01 10:03:18 +02:00
vmlinux.lds.S arm/build: Assert for unwanted sections 2020-09-01 10:03:18 +02:00
xscale-cp0.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00