2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-06-24 01:54:48 +08:00
|
|
|
/*
|
|
|
|
* kexec for arm64
|
|
|
|
*
|
|
|
|
* Copyright (C) Linaro.
|
|
|
|
* Copyright (C) Huawei Futurewei Technologies.
|
|
|
|
*/
|
|
|
|
|
2017-04-03 10:24:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/kernel.h>
|
2016-06-24 01:54:48 +08:00
|
|
|
#include <linux/kexec.h>
|
2017-04-03 10:24:35 +08:00
|
|
|
#include <linux/page-flags.h>
|
2021-07-08 09:07:59 +08:00
|
|
|
#include <linux/set_memory.h>
|
2016-06-24 01:54:48 +08:00
|
|
|
#include <linux/smp.h>
|
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/cpu_ops.h>
|
2017-11-02 20:12:34 +08:00
|
|
|
#include <asm/daifflags.h>
|
2017-04-03 10:24:37 +08:00
|
|
|
#include <asm/memory.h>
|
2017-04-03 10:24:34 +08:00
|
|
|
#include <asm/mmu.h>
|
2016-06-24 01:54:48 +08:00
|
|
|
#include <asm/mmu_context.h>
|
2017-04-03 10:24:34 +08:00
|
|
|
#include <asm/page.h>
|
2021-09-30 22:31:08 +08:00
|
|
|
#include <asm/sections.h>
|
2021-09-30 22:31:06 +08:00
|
|
|
#include <asm/trans_pgd.h>
|
2016-06-24 01:54:48 +08:00
|
|
|
|
2016-06-24 01:54:48 +08:00
|
|
|
/**
|
|
|
|
* kexec_image_info - For debugging output.
|
|
|
|
*/
|
|
|
|
#define kexec_image_info(_i) _kexec_image_info(__func__, __LINE__, _i)
|
|
|
|
static void _kexec_image_info(const char *func, int line,
|
|
|
|
const struct kimage *kimage)
|
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
pr_debug("%s:%d:\n", func, line);
|
|
|
|
pr_debug(" kexec kimage info:\n");
|
|
|
|
pr_debug(" type: %d\n", kimage->type);
|
|
|
|
pr_debug(" start: %lx\n", kimage->start);
|
|
|
|
pr_debug(" head: %lx\n", kimage->head);
|
|
|
|
pr_debug(" nr_segments: %lu\n", kimage->nr_segments);
|
2021-09-30 22:31:06 +08:00
|
|
|
pr_debug(" dtb_mem: %pa\n", &kimage->arch.dtb_mem);
|
arm64: kexec: move relocation function setup
Currently, kernel relocation function is configured in machine_kexec()
at the time of kexec reboot by using control_code_page.
This operation, however, is more logical to be done during kexec_load,
and thus remove from reboot time. Move, setup of this function to
newly added machine_kexec_post_load().
Because once MMU is enabled, kexec control page will contain more than
relocation kernel, but also vector table, add pointer to the actual
function within this page arch.kern_reloc. Currently, it equals to the
beginning of page, we will add offsets later, when vector table is
added.
Signed-off-by: Pavel Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: James Morse <james.morse@arm.com>
Link: https://lore.kernel.org/r/20210125191923.1060122-10-pasha.tatashin@soleen.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-01-26 03:19:14 +08:00
|
|
|
pr_debug(" kern_reloc: %pa\n", &kimage->arch.kern_reloc);
|
2021-09-30 22:31:06 +08:00
|
|
|
pr_debug(" el2_vectors: %pa\n", &kimage->arch.el2_vectors);
|
2016-06-24 01:54:48 +08:00
|
|
|
|
|
|
|
for (i = 0; i < kimage->nr_segments; i++) {
|
|
|
|
pr_debug(" segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n",
|
|
|
|
i,
|
|
|
|
kimage->segment[i].mem,
|
|
|
|
kimage->segment[i].mem + kimage->segment[i].memsz,
|
|
|
|
kimage->segment[i].memsz,
|
|
|
|
kimage->segment[i].memsz / PAGE_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 01:54:48 +08:00
|
|
|
void machine_kexec_cleanup(struct kimage *kimage)
|
|
|
|
{
|
|
|
|
/* Empty routine needed to avoid build errors. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* machine_kexec_prepare - Prepare for a kexec reboot.
|
|
|
|
*
|
|
|
|
* Called from the core kexec code when a kernel image is loaded.
|
|
|
|
* Forbid loading a kexec kernel if we have no way of hotplugging cpus or cpus
|
|
|
|
* are stuck in the kernel. This avoids a panic once we hit machine_kexec().
|
|
|
|
*/
|
|
|
|
int machine_kexec_prepare(struct kimage *kimage)
|
|
|
|
{
|
|
|
|
if (kimage->type != KEXEC_TYPE_CRASH && cpus_are_stuck_in_kernel()) {
|
|
|
|
pr_err("Can't kexec: CPUs are stuck in the kernel.\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* kexec_segment_flush - Helper to flush the kimage segments to PoC.
|
|
|
|
*/
|
|
|
|
static void kexec_segment_flush(const struct kimage *kimage)
|
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
pr_debug("%s:\n", __func__);
|
|
|
|
|
|
|
|
for (i = 0; i < kimage->nr_segments; i++) {
|
|
|
|
pr_debug(" segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n",
|
|
|
|
i,
|
|
|
|
kimage->segment[i].mem,
|
|
|
|
kimage->segment[i].mem + kimage->segment[i].memsz,
|
|
|
|
kimage->segment[i].memsz,
|
|
|
|
kimage->segment[i].memsz / PAGE_SIZE);
|
|
|
|
|
arm64: Rename arm64-internal cache maintenance functions
Although naming across the codebase isn't that consistent, it
tends to follow certain patterns. Moreover, the term "flush"
isn't defined in the Arm Architecture reference manual, and might
be interpreted to mean clean, invalidate, or both for a cache.
Rename arm64-internal functions to make the naming internally
consistent, as well as making it consistent with the Arm ARM, by
specifying whether it applies to the instruction, data, or both
caches, whether the operation is a clean, invalidate, or both.
Also specify which point the operation applies to, i.e., to the
point of unification (PoU), coherency (PoC), or persistence
(PoP).
This commit applies the following sed transformation to all files
under arch/arm64:
"s/\b__flush_cache_range\b/caches_clean_inval_pou_macro/g;"\
"s/\b__flush_icache_range\b/caches_clean_inval_pou/g;"\
"s/\binvalidate_icache_range\b/icache_inval_pou/g;"\
"s/\b__flush_dcache_area\b/dcache_clean_inval_poc/g;"\
"s/\b__inval_dcache_area\b/dcache_inval_poc/g;"\
"s/__clean_dcache_area_poc\b/dcache_clean_poc/g;"\
"s/\b__clean_dcache_area_pop\b/dcache_clean_pop/g;"\
"s/\b__clean_dcache_area_pou\b/dcache_clean_pou/g;"\
"s/\b__flush_cache_user_range\b/caches_clean_inval_user_pou/g;"\
"s/\b__flush_icache_all\b/icache_inval_all_pou/g;"
Note that __clean_dcache_area_poc is deliberately missing a word
boundary check at the beginning in order to match the efistub
symbols in image-vars.h.
Also note that, despite its name, __flush_icache_range operates
on both instruction and data caches. The name change here
reflects that.
No functional change intended.
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20210524083001.2586635-19-tabba@google.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-05-24 16:30:01 +08:00
|
|
|
dcache_clean_inval_poc(
|
2021-05-24 16:29:55 +08:00
|
|
|
(unsigned long)phys_to_virt(kimage->segment[i].mem),
|
|
|
|
(unsigned long)phys_to_virt(kimage->segment[i].mem) +
|
|
|
|
kimage->segment[i].memsz);
|
2016-06-24 01:54:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 22:31:06 +08:00
|
|
|
/* Allocates pages for kexec page table */
|
|
|
|
static void *kexec_page_alloc(void *arg)
|
|
|
|
{
|
|
|
|
struct kimage *kimage = (struct kimage *)arg;
|
|
|
|
struct page *page = kimage_alloc_control_pages(kimage, 0);
|
2021-11-26 01:06:00 +08:00
|
|
|
void *vaddr = NULL;
|
2021-09-30 22:31:06 +08:00
|
|
|
|
|
|
|
if (!page)
|
|
|
|
return NULL;
|
|
|
|
|
2021-11-26 01:06:00 +08:00
|
|
|
vaddr = page_address(page);
|
|
|
|
memset(vaddr, 0, PAGE_SIZE);
|
2021-09-30 22:31:06 +08:00
|
|
|
|
2021-11-26 01:06:00 +08:00
|
|
|
return vaddr;
|
2021-09-30 22:31:06 +08:00
|
|
|
}
|
|
|
|
|
2021-09-30 22:31:02 +08:00
|
|
|
int machine_kexec_post_load(struct kimage *kimage)
|
|
|
|
{
|
2021-09-30 22:31:09 +08:00
|
|
|
int rc;
|
|
|
|
pgd_t *trans_pgd;
|
2021-09-30 22:31:02 +08:00
|
|
|
void *reloc_code = page_to_virt(kimage->control_code_page);
|
2021-09-30 22:31:08 +08:00
|
|
|
long reloc_size;
|
2021-09-30 22:31:06 +08:00
|
|
|
struct trans_pgd_info info = {
|
|
|
|
.trans_alloc_page = kexec_page_alloc,
|
|
|
|
.trans_alloc_arg = kimage,
|
|
|
|
};
|
2021-09-30 22:31:02 +08:00
|
|
|
|
2021-09-30 22:31:03 +08:00
|
|
|
/* If in place, relocation is not used, only flush next kernel */
|
|
|
|
if (kimage->head & IND_DONE) {
|
2021-09-30 22:31:02 +08:00
|
|
|
kexec_segment_flush(kimage);
|
2021-09-30 22:31:03 +08:00
|
|
|
kexec_image_info(kimage);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-09-30 22:31:02 +08:00
|
|
|
|
2021-09-30 22:31:06 +08:00
|
|
|
kimage->arch.el2_vectors = 0;
|
|
|
|
if (is_hyp_nvhe()) {
|
2021-09-30 22:31:09 +08:00
|
|
|
rc = trans_pgd_copy_el2_vectors(&info,
|
|
|
|
&kimage->arch.el2_vectors);
|
2021-09-30 22:31:06 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-09-30 22:31:09 +08:00
|
|
|
/* Create a copy of the linear map */
|
|
|
|
trans_pgd = kexec_page_alloc(kimage);
|
|
|
|
if (!trans_pgd)
|
|
|
|
return -ENOMEM;
|
|
|
|
rc = trans_pgd_create_copy(&info, &trans_pgd, PAGE_OFFSET, PAGE_END);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
kimage->arch.ttbr1 = __pa(trans_pgd);
|
arm64: kexec: use __pa_symbol(empty_zero_page)
In machine_kexec_post_load() we use __pa() on `empty_zero_page`, so that
we can use the physical address during arm64_relocate_new_kernel() to
switch TTBR1 to a new set of tables. While `empty_zero_page` is part of
the old kernel, we won't clobber it until after this switch, so using it
is benign.
However, `empty_zero_page` is part of the kernel image rather than a
linear map address, so it is not correct to use __pa(x), and we should
instead use __pa_symbol(x) or __pa(lm_alias(x)). Otherwise, when the
kernel is built with DEBUG_VIRTUAL, we'll encounter splats as below, as
I've seen when fuzzing v5.16-rc3 with Syzkaller:
| ------------[ cut here ]------------
| virt_to_phys used for non-linear address: 000000008492561a (empty_zero_page+0x0/0x1000)
| WARNING: CPU: 3 PID: 11492 at arch/arm64/mm/physaddr.c:15 __virt_to_phys+0x120/0x1c0 arch/arm64/mm/physaddr.c:12
| CPU: 3 PID: 11492 Comm: syz-executor.0 Not tainted 5.16.0-rc3-00001-g48bd452a045c #1
| Hardware name: linux,dummy-virt (DT)
| pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
| pc : __virt_to_phys+0x120/0x1c0 arch/arm64/mm/physaddr.c:12
| lr : __virt_to_phys+0x120/0x1c0 arch/arm64/mm/physaddr.c:12
| sp : ffff80001af17bb0
| x29: ffff80001af17bb0 x28: ffff1cc65207b400 x27: ffffb7828730b120
| x26: 0000000000000e11 x25: 0000000000000000 x24: 0000000000000001
| x23: ffffb7828963e000 x22: ffffb78289644000 x21: 0000600000000000
| x20: 000000000000002d x19: 0000b78289644000 x18: 0000000000000000
| x17: 74706d6528206131 x16: 3635323934383030 x15: 303030303030203a
| x14: 1ffff000035e2eb8 x13: ffff6398d53f4f0f x12: 1fffe398d53f4f0e
| x11: 1fffe398d53f4f0e x10: ffff6398d53f4f0e x9 : ffffb7827c6f76dc
| x8 : ffff1cc6a9fa7877 x7 : 0000000000000001 x6 : ffff6398d53f4f0f
| x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff1cc66f2a99c0
| x2 : 0000000000040000 x1 : d7ce7775b09b5d00 x0 : 0000000000000000
| Call trace:
| __virt_to_phys+0x120/0x1c0 arch/arm64/mm/physaddr.c:12
| machine_kexec_post_load+0x284/0x670 arch/arm64/kernel/machine_kexec.c:150
| do_kexec_load+0x570/0x670 kernel/kexec.c:155
| __do_sys_kexec_load kernel/kexec.c:250 [inline]
| __se_sys_kexec_load kernel/kexec.c:231 [inline]
| __arm64_sys_kexec_load+0x1d8/0x268 kernel/kexec.c:231
| __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline]
| invoke_syscall+0x90/0x2e0 arch/arm64/kernel/syscall.c:52
| el0_svc_common.constprop.2+0x1e4/0x2f8 arch/arm64/kernel/syscall.c:142
| do_el0_svc+0xf8/0x150 arch/arm64/kernel/syscall.c:181
| el0_svc+0x60/0x248 arch/arm64/kernel/entry-common.c:603
| el0t_64_sync_handler+0x90/0xb8 arch/arm64/kernel/entry-common.c:621
| el0t_64_sync+0x180/0x184 arch/arm64/kernel/entry.S:572
| irq event stamp: 2428
| hardirqs last enabled at (2427): [<ffffb7827c6f2308>] __up_console_sem+0xf0/0x118 kernel/printk/printk.c:255
| hardirqs last disabled at (2428): [<ffffb7828223df98>] el1_dbg+0x28/0x80 arch/arm64/kernel/entry-common.c:375
| softirqs last enabled at (2424): [<ffffb7827c411c00>] softirq_handle_end kernel/softirq.c:401 [inline]
| softirqs last enabled at (2424): [<ffffb7827c411c00>] __do_softirq+0xa28/0x11e4 kernel/softirq.c:587
| softirqs last disabled at (2417): [<ffffb7827c59015c>] do_softirq_own_stack include/asm-generic/softirq_stack.h:10 [inline]
| softirqs last disabled at (2417): [<ffffb7827c59015c>] invoke_softirq kernel/softirq.c:439 [inline]
| softirqs last disabled at (2417): [<ffffb7827c59015c>] __irq_exit_rcu kernel/softirq.c:636 [inline]
| softirqs last disabled at (2417): [<ffffb7827c59015c>] irq_exit_rcu+0x53c/0x688 kernel/softirq.c:648
| ---[ end trace 0ca578534e7ca938 ]---
With or without DEBUG_VIRTUAL __pa() will fall back to __kimg_to_phys()
for non-linear addresses, and will happen to do the right thing in this
case, even with the warning. But we should not depend upon this, and to
keep the warning useful we should fix this case.
Fix this issue by using __pa_symbol(), which handles kernel image
addresses (and checks its input is a kernel image address). This matches
what we do elsewhere, e.g. in arch/arm64/include/asm/pgtable.h:
| #define ZERO_PAGE(vaddr) phys_to_page(__pa_symbol(empty_zero_page))
Fixes: 3744b5280e67 ("arm64: kexec: install a copy of the linear-map")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Link: https://lore.kernel.org/r/20211130121849.3319010-1-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2021-11-30 20:18:49 +08:00
|
|
|
kimage->arch.zero_page = __pa_symbol(empty_zero_page);
|
2021-09-30 22:31:09 +08:00
|
|
|
|
2021-09-30 22:31:08 +08:00
|
|
|
reloc_size = __relocate_new_kernel_end - __relocate_new_kernel_start;
|
|
|
|
memcpy(reloc_code, __relocate_new_kernel_start, reloc_size);
|
2021-09-30 22:31:02 +08:00
|
|
|
kimage->arch.kern_reloc = __pa(reloc_code);
|
2021-09-30 22:31:10 +08:00
|
|
|
rc = trans_pgd_idmap_page(&info, &kimage->arch.ttbr0,
|
|
|
|
&kimage->arch.t0sz, reloc_code);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
kimage->arch.phys_offset = virt_to_phys(kimage) - (long)kimage;
|
2021-09-30 22:31:02 +08:00
|
|
|
|
|
|
|
/* Flush the reloc_code in preparation for its execution. */
|
|
|
|
dcache_clean_inval_poc((unsigned long)reloc_code,
|
2021-09-30 22:31:08 +08:00
|
|
|
(unsigned long)reloc_code + reloc_size);
|
2021-09-30 22:31:02 +08:00
|
|
|
icache_inval_pou((uintptr_t)reloc_code,
|
2021-09-30 22:31:08 +08:00
|
|
|
(uintptr_t)reloc_code + reloc_size);
|
2021-09-30 22:31:03 +08:00
|
|
|
kexec_image_info(kimage);
|
2021-09-30 22:31:02 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-24 01:54:48 +08:00
|
|
|
/**
|
|
|
|
* machine_kexec - Do the kexec reboot.
|
|
|
|
*
|
|
|
|
* Called from the core kexec code for a sys_reboot with LINUX_REBOOT_CMD_KEXEC.
|
|
|
|
*/
|
|
|
|
void machine_kexec(struct kimage *kimage)
|
|
|
|
{
|
2017-04-03 10:24:36 +08:00
|
|
|
bool in_kexec_crash = (kimage == kexec_crash_image);
|
|
|
|
bool stuck_cpus = cpus_are_stuck_in_kernel();
|
2016-06-24 01:54:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* New cpus may have become stuck_in_kernel after we loaded the image.
|
|
|
|
*/
|
2017-04-03 10:24:36 +08:00
|
|
|
BUG_ON(!in_kexec_crash && (stuck_cpus || (num_online_cpus() > 1)));
|
|
|
|
WARN(in_kexec_crash && (stuck_cpus || smp_crash_stop_failed()),
|
|
|
|
"Some CPUs may be stale, kdump will be unreliable.\n");
|
2016-06-24 01:54:48 +08:00
|
|
|
|
|
|
|
pr_info("Bye!\n");
|
|
|
|
|
2017-11-02 20:12:34 +08:00
|
|
|
local_daif_mask();
|
2016-06-24 01:54:48 +08:00
|
|
|
|
|
|
|
/*
|
2021-09-30 22:31:10 +08:00
|
|
|
* Both restart and kernel_reloc will shutdown the MMU, disable data
|
2021-09-30 22:31:03 +08:00
|
|
|
* caches. However, restart will start new kernel or purgatory directly,
|
2021-09-30 22:31:10 +08:00
|
|
|
* kernel_reloc contains the body of arm64_relocate_new_kernel
|
2018-11-15 13:52:52 +08:00
|
|
|
* In kexec case, kimage->start points to purgatory assuming that
|
|
|
|
* kernel entry and dtb address are embedded in purgatory by
|
|
|
|
* userspace (kexec-tools).
|
|
|
|
* In kexec_file case, the kernel starts directly without purgatory.
|
2016-06-24 01:54:48 +08:00
|
|
|
*/
|
2021-09-30 22:31:03 +08:00
|
|
|
if (kimage->head & IND_DONE) {
|
2021-09-30 22:31:12 +08:00
|
|
|
typeof(cpu_soft_restart) *restart;
|
2021-09-30 22:31:03 +08:00
|
|
|
|
|
|
|
cpu_install_idmap();
|
2021-09-30 22:31:12 +08:00
|
|
|
restart = (void *)__pa_symbol(function_nocfi(cpu_soft_restart));
|
2021-09-30 22:31:03 +08:00
|
|
|
restart(is_hyp_nvhe(), kimage->start, kimage->arch.dtb_mem,
|
|
|
|
0, 0);
|
|
|
|
} else {
|
2021-09-30 22:31:10 +08:00
|
|
|
void (*kernel_reloc)(struct kimage *kimage);
|
|
|
|
|
2021-09-30 22:31:06 +08:00
|
|
|
if (is_hyp_nvhe())
|
|
|
|
__hyp_set_vectors(kimage->arch.el2_vectors);
|
2021-09-30 22:31:10 +08:00
|
|
|
cpu_install_ttbr0(kimage->arch.ttbr0, kimage->arch.t0sz);
|
|
|
|
kernel_reloc = (void *)kimage->arch.kern_reloc;
|
|
|
|
kernel_reloc(kimage);
|
2021-09-30 22:31:03 +08:00
|
|
|
}
|
2016-06-24 01:54:48 +08:00
|
|
|
|
|
|
|
BUG(); /* Should never get here. */
|
|
|
|
}
|
|
|
|
|
2017-04-03 10:24:36 +08:00
|
|
|
static void machine_kexec_mask_interrupts(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct irq_desc *desc;
|
|
|
|
|
|
|
|
for_each_irq_desc(i, desc) {
|
|
|
|
struct irq_chip *chip;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
chip = irq_desc_get_chip(desc);
|
|
|
|
if (!chip)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try to remove the active state. If this
|
|
|
|
* fails, try to EOI the interrupt.
|
|
|
|
*/
|
|
|
|
ret = irq_set_irqchip_state(i, IRQCHIP_STATE_ACTIVE, false);
|
|
|
|
|
|
|
|
if (ret && irqd_irq_inprogress(&desc->irq_data) &&
|
|
|
|
chip->irq_eoi)
|
|
|
|
chip->irq_eoi(&desc->irq_data);
|
|
|
|
|
|
|
|
if (chip->irq_mask)
|
|
|
|
chip->irq_mask(&desc->irq_data);
|
|
|
|
|
|
|
|
if (chip->irq_disable && !irqd_irq_disabled(&desc->irq_data))
|
|
|
|
chip->irq_disable(&desc->irq_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* machine_crash_shutdown - shutdown non-crashing cpus and save registers
|
|
|
|
*/
|
2016-06-24 01:54:48 +08:00
|
|
|
void machine_crash_shutdown(struct pt_regs *regs)
|
|
|
|
{
|
2017-04-03 10:24:36 +08:00
|
|
|
local_irq_disable();
|
|
|
|
|
|
|
|
/* shutdown non-crashing cpus */
|
2017-08-17 10:24:27 +08:00
|
|
|
crash_smp_send_stop();
|
2017-04-03 10:24:36 +08:00
|
|
|
|
|
|
|
/* for crashing cpu */
|
|
|
|
crash_save_cpu(regs, smp_processor_id());
|
|
|
|
machine_kexec_mask_interrupts();
|
|
|
|
|
|
|
|
pr_info("Starting crashdump kernel...\n");
|
2016-06-24 01:54:48 +08:00
|
|
|
}
|
2017-04-03 10:24:34 +08:00
|
|
|
|
|
|
|
void arch_kexec_protect_crashkres(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < kexec_crash_image->nr_segments; i++)
|
|
|
|
set_memory_valid(
|
|
|
|
__phys_to_virt(kexec_crash_image->segment[i].mem),
|
|
|
|
kexec_crash_image->segment[i].memsz >> PAGE_SHIFT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void arch_kexec_unprotect_crashkres(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < kexec_crash_image->nr_segments; i++)
|
|
|
|
set_memory_valid(
|
|
|
|
__phys_to_virt(kexec_crash_image->segment[i].mem),
|
|
|
|
kexec_crash_image->segment[i].memsz >> PAGE_SHIFT, 1);
|
|
|
|
}
|
2017-04-03 10:24:35 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_HIBERNATION
|
|
|
|
/*
|
|
|
|
* To preserve the crash dump kernel image, the relevant memory segments
|
|
|
|
* should be mapped again around the hibernation.
|
|
|
|
*/
|
|
|
|
void crash_prepare_suspend(void)
|
|
|
|
{
|
|
|
|
if (kexec_crash_image)
|
|
|
|
arch_kexec_unprotect_crashkres();
|
|
|
|
}
|
|
|
|
|
|
|
|
void crash_post_resume(void)
|
|
|
|
{
|
|
|
|
if (kexec_crash_image)
|
|
|
|
arch_kexec_protect_crashkres();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* crash_is_nosave
|
|
|
|
*
|
|
|
|
* Return true only if a page is part of reserved memory for crash dump kernel,
|
|
|
|
* but does not hold any data of loaded kernel image.
|
|
|
|
*
|
|
|
|
* Note that all the pages in crash dump kernel memory have been initially
|
2019-03-06 07:47:28 +08:00
|
|
|
* marked as Reserved as memory was allocated via memblock_reserve().
|
2017-04-03 10:24:35 +08:00
|
|
|
*
|
|
|
|
* In hibernation, the pages which are Reserved and yet "nosave" are excluded
|
|
|
|
* from the hibernation iamge. crash_is_nosave() does thich check for crash
|
|
|
|
* dump kernel and will reduce the total size of hibernation image.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool crash_is_nosave(unsigned long pfn)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
phys_addr_t addr;
|
|
|
|
|
|
|
|
if (!crashk_res.end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* in reserved memory? */
|
|
|
|
addr = __pfn_to_phys(pfn);
|
2022-05-06 19:43:59 +08:00
|
|
|
if ((addr < crashk_res.start) || (crashk_res.end < addr)) {
|
|
|
|
if (!crashk_low_res.end)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((addr < crashk_low_res.start) || (crashk_low_res.end < addr))
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-03 10:24:35 +08:00
|
|
|
|
|
|
|
if (!kexec_crash_image)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* not part of loaded kernel image? */
|
|
|
|
for (i = 0; i < kexec_crash_image->nr_segments; i++)
|
|
|
|
if (addr >= kexec_crash_image->segment[i].mem &&
|
|
|
|
addr < (kexec_crash_image->segment[i].mem +
|
|
|
|
kexec_crash_image->segment[i].memsz))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
|
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
for (addr = begin; addr < end; addr += PAGE_SIZE) {
|
|
|
|
page = phys_to_page(addr);
|
|
|
|
free_reserved_page(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HIBERNATION */
|