ARM: kexec: fix oops after TLB are invalidated
authorRussell King <rmk+kernel@armlinux.org.uk>
Mon, 1 Feb 2021 19:40:01 +0000 (19:40 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Feb 2021 10:02:24 +0000 (11:02 +0100)
commit249735b011234a65a720952d5451156be8baa50f
treebee9c7cf2a05ce1a5cbb62b1721efe3789ae301b
parent7913ec05fc02ccd7df83280451504b0a3e543097
ARM: kexec: fix oops after TLB are invalidated

[ Upstream commit 4d62e81b60d4025e2dfcd5ea531cc1394ce9226f ]

Giancarlo Ferrari reports the following oops while trying to use kexec:

 Unable to handle kernel paging request at virtual address 80112f38
 pgd = fd7ef03e
 [80112f38] *pgd=0001141e(bad)
 Internal error: Oops: 80d [#1] PREEMPT SMP ARM
 ...

This is caused by machine_kexec() trying to set the kernel text to be
read/write, so it can poke values into the relocation code before
copying it - and an interrupt occuring which changes the page tables.
The subsequent writes then hit read-only sections that trigger a
data abort resulting in the above oops.

Fix this by copying the relocation code, and then writing the variables
into the destination, thereby avoiding the need to make the kernel text
read/write.

Reported-by: Giancarlo Ferrari <giancarlo.ferrari89@gmail.com>
Tested-by: Giancarlo Ferrari <giancarlo.ferrari89@gmail.com>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/arm/include/asm/kexec-internal.h [new file with mode: 0644]
arch/arm/kernel/asm-offsets.c
arch/arm/kernel/machine_kexec.c
arch/arm/kernel/relocate_kernel.S