From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.136 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796094937; b=i7F1z+hECmCWuaafoudYYcRS8+QYxrFwJp6hAtHaI04yKu//Rhxai/Yv1gz5PcrUZCOa JkGOdEkWInwehBB0xCPNaubs0GyG4Eb9zzD9kJICeXpbLfaHGlVGgHoQzx/0gWy5wxh8q enp8qv9+M3ZcD1/WdWbiop7GJgAOw1vnJAPtEsZoWDF1kk9CnBrwbFlNKTVheqKyHAbL9 IaLOQbVQCFZ1HzcoYSvtD2SDrX6qY+qv7QPspZ/Oji1YZht9QGYlc43eP+BQG6Itrd5SP UBoK/YDPgZ2N6pViT7DzNiK0aIuxdo4FIlz2EHjd1DaV48YvKaUYlmZTZPzuwlSpfoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796094937; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=hJ6nEhLrNfJKTHcm7mRk0fizV0CdFlNbnpstq9jsqok=; b=c72hMSSPq4wdJbaGwoSF8BjC37XMC04XaCGBHd/+mg6iU5u60wVGzIBlgBIECK9n2Up+ 4hdkL7IXbZd+/BPFwpJ/9b8jLZeQFrlb8vO7H0mKA3Bn4eSsN/P1OsR6jmPTZ5hQuNArk g/T8/ItlcL2ITAlZwQ3MEBOugJN/PSGctm8wcQysG7zHrUxT9WOxvZwHcjsmCOWug3hAw 0ATEDtzxNfMNaZ/hxCG1qsTQJJjBNIMfFDnhTxjK36f/b+nb3HF515ftWV5XhnfS58eS/ yGnN6l7HfGIM3kyQ3HJBansMnOUhQ/uc1fYfVW6GpXkKLA4+79E1MZQKYbCsM8cbGug== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fWg4YGLz; arc=none smtp.remote-ip=74.125.227.136 Received: from mail-pj2-f8.google.com (mail-pj2-f8.google.com [74.125.227.136]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D099A606A327 for ; Tue, 1 Dec 2026 03:15:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D099A606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fWg4YGLz Received: by mail-pj2-f8.google.com with SMTP id 98e67ed59e1d1-3b40283c001so2528718a91.0 for ; Mon, 30 Nov 2026 19:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796094936; x=1796699736; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hJ6nEhLrNfJKTHcm7mRk0fizV0CdFlNbnpstq9jsqok=; b=fWg4YGLzxwI1rGbmPsrvpofFkHj6yqNbilp37mK+plrISDJc46WQiDYUaf1JFM8AOe IABG5Z5yw7HX3+aCtCpf6oBMYmFhRFI5dSLFE5pD6Cqn70VjphDV84CY/V8T0EVTEQ1V qwwvqXQfnZ57ZL6g4ZHUby/KLwaQrcfAOnCGo2m+GK0aROjFCr7i4J5YUnDpwiUPtHmB yZ5kOYFv+dJrDVwJLY71GyaEBbjiejYL/oR7/AdXnGFJc8+ahQvcSQFeaoTBkvDqdbyI 0oeWvzwAyfwZCyAGxwa7Owfz+OyEzdbhmGty/2hq6s9zTH53M3VhwNp32fgK+Mj8pIoj N11w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796094936; x=1796699736; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hJ6nEhLrNfJKTHcm7mRk0fizV0CdFlNbnpstq9jsqok=; b=M9K0auDXoir9GM2TsFmmwIN6P/Zy/vsHycpyeLWP8CCgxCtf+npFyJUvtBvdIcaSBW hgs+yZI+y7imJb/5q2d7FbDa1aydtLmrlUeKBrXsYd5qBdSusfMT0djJDP6wOr/rFQyE aV4DeSMvFEOxDwi+NC2E0UXG5rgkJQQodMQEvrPR9f6WMzgBOzG/1FRmEYjj2fWSug33 w5LP6P//LmKnvWdfc+FpTlamsmtfshZBNim9ponRJDaN8E6RP2YObFmcluFKamvSXGal QZ0lOhJ5+85r6xP4nf4ewqofSwQKkb4C/K8nIxum7ZjCTPlQxNOTpkURr6T+Hj9dkePL QG4w== X-Forwarded-Encrypted: i=1; AL+hErETHsW5yuJPqHOTzZNBShiS4EReCfGNLATaA4TRwcPQq4e+L5d6evGpMJpBVtZAiOyFxMqtiDLuHQtJchM=@vger.kernel.org X-Gm-Message-State: APuU4Z/ip4gjeUbfGayP3brq3fwVYwUeoy+VFET2kwr7j4mU8BYiWi2x wAbnSlPNzc2GNDeUQKwOAmBN3Tnw9lu7SeSXCM87AXZE2NmKYlQNYW0u X-Gm-Gg: AZFdTZe15qWpXEua6EywrHyPtEYjqXf4IPipqr5U0KMJ6Em6bEQOKAhiOEd/gZWytaI 7edj0VKwEmmxknkZtIgvh696L9FpsJq3L+oUL8aASh+gD3q+VWY8dKthvE+XJpGEJGdvmPUKSMA e5YM9b+u27H6X9sYOmFOM8IOUSS2erFhnZctrVIevUZ4FehkzbivbuuyRlCMCvkIoIe0quB7oCy VJef1ja9mAwCzbUelPvE0rR6TlZ+hwgpeeheMPc53nqOPGuWLMjWokSU48pc9HFcmm/Y0vEv4Qv 4ogO+SpMJUL+yGbfbbkqG1+S8jTfmX0JOJc28t52Vh/dXBzXlIhbHQlDtapJehPl5SaRH2N3W4n Nti1TX50Ya+fCLETKJs3fMFgBn1Uk9G5evCYslkl+fzA4uwb9LdclHWN088/Um5QRtU/r5i+u8s 8hhWjjrhEEdAXvZVofpMw55N5sLKRkQH5C99CWY/+qZTgDI5/Fg5r1WKBySDT8Amnilh4GDz0OL TbTzC3c6Dqleggdw3UxHP5eShzAadT/o5ceYDzmWsfddFjOWAWFd8j8WM1+atziyjNtqxVMcAjY Bg2fQ0syCRuNm3Y2V5tTXVC1UBF6q8xw6EE1nSWiCqDsric4rJS9Fr1s X-Received: by 2002:a17:90b:2688:b0:3b3:b71e:b2e7 with SMTP id 98e67ed59e1d1-3b41c92a209mr33874208a91.36.1796094935870; Mon, 30 Nov 2026 19:15:35 -0800 (PST) Received: from [10.125.112.22] ([122.11.210.25]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b4b3c71192sm39559765a91.5.2026.11.30.19.15.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 19:15:34 -0800 (PST) Message-ID: <982984d2-11ab-44a1-a91c-09bed3ac2b83@gmail.com> Date: Tue, 1 Dec 2026 11:15:20 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 3/8] crash_core: serialize crash header preparation against hotplug To: Jinjie Ruan Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, chenhuacai@kernel.org, kernel@xen0n.name, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, saravanak@kernel.org, akpm@linux-foundation.org, pasha.tatashin@soleen.com, pratyush@kernel.org, ruirui.yang@linux.dev, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, iommu@lists.linux.dev, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, robh@kernel.org, baoquan.he@linux.dev, rppt@kernel.org, m.szyprowski@samsung.com References: <20261127090723.741253-1-chenwandun1@gmail.com> <20261127090723.741253-4-chenwandun1@gmail.com> <6448a512-9c1a-441b-a8b8-7bf654e8b2a5@huawei.com> Content-Language: en-US From: Wandun In-Reply-To: <6448a512-9c1a-441b-a8b8-7bf654e8b2a5@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/28/26 10:03, Jinjie Ruan wrote: > > > 在 2026/11/27 17:07, 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 > > The order of the header files is completely messed up now. The include block was already unordered before this patch. To keep the fix focused, in v11 I will only place the new include in a proper position. Thanks, Wandun > >> @@ -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(); >> + >> + return ret; > > otherwise, LGTM > Reviewed-by: Jinjie Ruan > >> +} >> + >> /** >> * crash_exclude_mem_range - exclude a mem range for existing ranges >> * @mem: mem->range contains an array of ranges sorted in ascending order >