From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8494E606A319 for ; Thu, 22 Oct 2026 02:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=xs5EGHS3; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=Q+4ivRAN DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=loBgwUbLOnAAak0q9uGjIQKEwQ4a4j4TVh8P+20MXEg=; b=xs5EGHS3siv2zHQ4dF90dZhVs7 QwHCG2Way5IY6OxcQ0BANd3g5WM36l3rNgerpaTKk/9rsbwZaDXEnq+eB/odKMYNZnv9D2hRVPXbq zfywLQIrAQEsjNgUBYPscGgs/3SJxbGqe6XoY99nG6Wbyc8/HGRfW03VkcshVnBIX25yiWulEYi3p Zm7igaOclUiZJHYL3bzfZQ/51MG6xnj3GCdshxOC3mP2ATCgYZOEbFd0wUMzxJVsV+Uhi+0DBgJF6 8K0xYQCi/TuoXyKE7QF2oTGCAh4yd0kyD19t6BDyfNf7UMoqUjpNgJ4d72die6lLBC4utFgZOEOr9 A3NnObHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xJi7M-0000000DAdy-3kJN; Thu, 22 Oct 2026 02:01:20 +0000 Received: from [113.46.200.225] (helo=canpmsgout10.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xJi7J-0000000DAdA-02YA; Thu, 22 Oct 2026 02:01:19 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=loBgwUbLOnAAak0q9uGjIQKEwQ4a4j4TVh8P+20MXEg=; b=Q+4ivRANcgbbFZT+RuqnOmzfQRgx/LVfmZmJnBznw3aijzTfLqiAXmQFPpHZ4wQr5N/a+UnSk 9QkwZygXGFsy6k2d0kw287r6cGCOPL2MK5xfPM3ACXVTWwq6O1+K0stbkZqxhIDb9q0MkhN+DRw UTGHL86gM/CDOpMtrrbG38U= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4j98WL5Vhfz1K972; Thu, 22 Oct 2026 10:00:46 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 2FEAB40563; Thu, 22 Oct 2026 10:00:51 +0800 (CST) Received: from [10.67.110.68] (10.67.110.68) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Thu, 22 Oct 2026 10:00:49 +0800 Message-ID: <31d63208-3ef2-420f-a0c2-d9d6d49c5e21@huawei.com> Date: Thu, 22 Oct 2026 10:00:49 +0800 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 3/8] crash_core: serialize crash header preparation against hotplug To: Wandun , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20261021083011.2170525-1-chenwandun1@gmail.com> <20261021083011.2170525-4-chenwandun1@gmail.com> <12e4e687-1ff0-41b2-bdf8-7f48b29e1f2f@huawei.com> From: Jinjie Ruan In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261021_190117_372670_85AA50F8 X-CRM114-Status: GOOD ( 21.58 ) X-Spam-Score: -1.2 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 在 2026/10/21 17:48, Wandun 写道: > > > On 10/21/26 17:13, Jinjie Ruan wrote: >> >> >> 在 2026/10/21 16:30, Wandun Chen 写道: >>> From: Wandun Chen >>> >>> crash_prepare_headers() counts memory ranges before populating the >>> allocated crash_mem array. The weak implementation used by ARM64, >>> RISC-V and LoongArch walks memblock.memory, while x86 performs the same >>> two-pass operation over system RAM resources. Concurrent memory hotplug >>> can change range source between the two walks and make the populate >>> pass overflow cmem->ranges. >>> >>> Take device_hotplug_lock when preparing crash headers during >>> kexec_file_load(). The x86/riscv memory hotplug path already takes >>> device_hotplug_lock, so call __crash_prepare_headers() directly >>> to avoid recursive locking. >>> >>> Sashiko reported this issue in [1]. >>> >>> Fixes: 3751e728cef2 ("arm64: kexec_file: add crash dump support") >>> Fixes: 1bcca8620a91 ("LoongArch: Add crash dump support for kexec_file") >>> Fixes: 8acea455fafa ("RISC-V: Support for kexec_file on panic") >>> Fixes: dd5f726076cc ("kexec: support for kexec on panic using new system call") >>> Signed-off-by: Wandun Chen >>> Link: https://sashiko.dev/#/message/20260806101002.1F84E1F000E9@smtp.kernel.org [1] >>> Acked-by: Baoquan He >>> --- >>> arch/riscv/kernel/crash.c | 2 +- >>> arch/x86/kernel/crash.c | 2 +- >>> include/linux/crash_core.h | 2 ++ >>> kernel/crash_core.c | 17 +++++++++++++++-- >>> 4 files changed, 19 insertions(+), 4 deletions(-) >>> >>> diff --git a/arch/riscv/kernel/crash.c b/arch/riscv/kernel/crash.c >>> index fe5a4b306aae..ac8df2edf2a7 100644 >>> --- a/arch/riscv/kernel/crash.c >>> +++ b/arch/riscv/kernel/crash.c >>> @@ -70,7 +70,7 @@ void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) >>> * Create the new elfcorehdr reflecting the changes to CPU and/or >>> * memory resources. >>> */ >>> - if (crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) { >>> + if (__crash_prepare_headers(true, &elfbuf, &elfsz, NULL)) { >>> pr_err("unable to create new elfcorehdr"); >>> goto out; >>> } >>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c >>> index e6f23933a6df..bef008a0cb22 100644 >>> --- a/arch/x86/kernel/crash.c >>> +++ b/arch/x86/kernel/crash.c >>> @@ -465,7 +465,7 @@ void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) >>> * Create the new elfcorehdr reflecting the changes to CPU and/or >>> * memory resources. >>> */ >>> - if (crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &elfbuf, &elfsz, NULL)) { >>> + if (__crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &elfbuf, &elfsz, NULL)) { >>> pr_err("unable to create new elfcorehdr"); >>> goto out; >>> } >>> diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h >>> index bc087124cd78..28e7a81cf263 100644 >>> --- a/include/linux/crash_core.h >>> +++ b/include/linux/crash_core.h >>> @@ -61,6 +61,8 @@ extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_ma >>> void **addr, unsigned long *sz); >>> extern int crash_prepare_headers(int need_kernel_map, void **addr, >>> unsigned long *sz, unsigned long *nr_mem_ranges); >>> +int __crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, >>> + unsigned long *nr_mem_ranges); >>> extern int crash_exclude_core_ranges(struct crash_mem **cmem); >>> >>> struct kimage; >>> diff --git a/kernel/crash_core.c b/kernel/crash_core.c >>> index faa0f22dbb41..8a861a946e26 100644 >>> --- a/kernel/crash_core.c >>> +++ b/kernel/crash_core.c >>> @@ -16,6 +16,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> @@ -344,8 +345,8 @@ int crash_exclude_core_ranges(struct crash_mem **cmem) >>> return 0; >>> } >>> >>> -int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, >>> - unsigned long *nr_mem_ranges) >>> +int __crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, >>> + unsigned long *nr_mem_ranges) >>> { >>> unsigned int max_nr_ranges; >>> struct crash_mem *cmem; >>> @@ -382,6 +383,18 @@ int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, >>> return ret; >>> } >>> >>> +int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, >>> + unsigned long *nr_mem_ranges) >>> +{ >>> + int ret; >>> + >>> + lock_device_hotplug(); >>> + ret = __crash_prepare_headers(need_kernel_map, addr, sz, nr_mem_ranges); >>> + unlock_device_hotplug(); >> >> I think this patch conflicts with my changes and would also conflict >> with the implementation of arm64 crash hotplug. >> >> https://lore.kernel.org/all/20260921090450.807575-15-ruanjinjie@huawei.com/ >> > Have these patches already been merged? My current work is based on the latest > linux-next. If they have already been merged into the maintainer's branch, > please let me know, I will update my tree and rebase/re-adapt my changes accordingly. > > > Also, regarding the changes in kernel/crash_core.c: it looks like we modified > the same spot, the change is not wrong, is that right? Hi Wandun, However, I think someone should have informed me in advance; otherwise, doing duplicate fix work is pointless. I see that part of your patch series modifies code I previously changed, but I was not CC'd. > >> arm64 crash hotplug: >> https://lore.kernel.org/all/20260918100442.3841135-18-ruanjinjie@huawei.com/ > > In addition, if arm64 gains crash hotplug support, the code there would indeed > need to be modified (to avoid a deadlock). As of now, arm64 crash hotplug > support has not been merged yet either, has it? I just want to make sure I > haven't missed anything. Yes, you are right. If your patch series will be merged soon, I will develop based on it. > >> >>> + >>> + return ret; >>> +} >>> + >>> /** >>> * crash_exclude_mem_range - exclude a mem range for existing ranges >>> * @mem: mem->range contains an array of ranges sorted in ascending order >> > -- Best regards, Jinjie