From nobody Tue Feb 10 02:49:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 810AEC00528 for ; Fri, 21 Jul 2023 08:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbjGUIVk (ORCPT ); Fri, 21 Jul 2023 04:21:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231489AbjGUIV2 (ORCPT ); Fri, 21 Jul 2023 04:21:28 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E5030C2 for ; Fri, 21 Jul 2023 01:21:18 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R6jF613Y7z4f41Gc for ; Fri, 21 Jul 2023 16:21:14 +0800 (CST) Received: from huaweicloud.com (unknown [10.174.178.55]) by APP4 (Coremail) with SMTP id gCh0CgAHoZT2P7pkhprcOQ--.24672S7; Fri, 21 Jul 2023 16:21:15 +0800 (CST) From: thunder.leizhen@huaweicloud.com To: Dave Young , Baoquan He , Vivek Goyal , "Eric W . Biederman" , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org Cc: Zhen Lei Subject: [PATCH 3/3] arm64: kdump: add support access protection for crashkernel region Date: Fri, 21 Jul 2023 16:17:26 +0800 Message-Id: <20230721081726.882-4-thunder.leizhen@huaweicloud.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230721081726.882-1-thunder.leizhen@huaweicloud.com> References: <20230721081726.882-1-thunder.leizhen@huaweicloud.com> MIME-Version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UJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42 IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU7-eoUUUUU X-CM-SenderInfo: hwkx0vthuozvpl2kv046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Zhen Lei arch_kexec_protect_crashkres() and arch_kexec_unprotect_crashkres() are meant to be called by kexec_load() in order to protect the memory allocated for crash dump kernel once the image is loaded. This is basically revert commit 0d124e96051b ("arm64: kdump : take off the protection on crashkernel memory region"), except for the crashkernel region has been fallen back. Because we didn't do page-level mapping for the newly allocated region. Signed-off-by: Zhen Lei --- arch/arm64/include/asm/kexec.h | 8 ++++++++ arch/arm64/kernel/machine_kexec.c | 26 ++++++++++++++++++++++++++ arch/arm64/mm/init.c | 4 ++++ 3 files changed, 38 insertions(+) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 9ac9572a3bbee2c..a55388ff045e980 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -102,6 +102,14 @@ void cpu_soft_restart(unsigned long el2_switch, unsign= ed long entry, =20 int machine_kexec_post_load(struct kimage *image); #define machine_kexec_post_load machine_kexec_post_load + +extern bool crash_fallback; + +void arch_kexec_protect_crashkres(void); +#define arch_kexec_protect_crashkres arch_kexec_protect_crashkres + +void arch_kexec_unprotect_crashkres(void); +#define arch_kexec_unprotect_crashkres arch_kexec_unprotect_crashkres #endif =20 #define ARCH_HAS_KIMAGE_ARCH diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_= kexec.c index 078910db77a41b6..00392b48501d35c 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -269,6 +269,32 @@ void machine_crash_shutdown(struct pt_regs *regs) pr_info("Starting crashdump kernel...\n"); } =20 +void arch_kexec_protect_crashkres(void) +{ + int i; + + if (crash_fallback) + return; + + for (i =3D 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; + + if (crash_fallback) + return; + + for (i =3D 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); +} + #ifdef CONFIG_HIBERNATION /* * To preserve the crash dump kernel image, the relevant memory segments diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d2ab377520b2742..b544ed0ab04193d 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -74,6 +74,7 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit; =20 #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) =20 +bool crash_fallback; static int crashkernel_type __initdata; =20 static phys_addr_t __init crashkernel_phys_alloc_range(phys_addr_t size, @@ -199,6 +200,9 @@ static void __init late_reserve_crashkernel(void) crashk_res.end =3D crash_base + crash_size - 1; insert_resource(&iomem_resource, &crashk_res); =20 + crash_fallback =3D true; + pr_info("cannot allocate all crashkernel memory as expected, fallen back.= \n"); + ok: crash_base =3D crashk_res.start; crash_size =3D resource_size(&crashk_res); --=20 2.25.1