From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 897D046AA66 for ; Mon, 21 Sep 2026 09:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981467; cv=none; b=UDE+ab66NUlPcK5tE2gqQCbwyzEz5PFtnTWPY3TSMJ7dvDGikHzZeaHhZO3BSI+4+DhsTBpdwBDJjX1S0l5mz/R/ivt509OYmuCf3yBQNL3nMEWucGFwEfJ3lHkMP96BjpXgpYHRMMR0i2L4PcKVKWxzZz9KdKndfl3ui0qTLdA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789981467; c=relaxed/simple; bh=2KdupsWceweyWYND6ijvaYhreMt2HBNEZIG8MHJnBs8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IxHnGDR8SWAyQ5jFY86X7hZwYxBeAl0weZKVXyd6CKkbTs3qa+N8Rk29M7U1fisIZFnUfbyofg9hKlCYUvLq1Jell1+TxV/kfwxDtUrcDwjO+4ysAi7Q0UwsBTkocVQOoefPk9ka0Zk/ATZuR+S2asjnVR57c+feovDRyw15oqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=QDOtzo0Y; arc=none smtp.client-ip=113.46.200.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="QDOtzo0Y" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=+SZRrezQ0aGrf6aoi2mjbpyD9DzDa0MzzJwmMo2zVh0=; b=QDOtzo0YbEPraF8hBNN1eIHHylUMG/0f8u5ka7yGUNTwM1OnOYxP9zWXeAlrcrPh3LHLBghb2 nIQRJeX/fS4RhMOLtRND7crtI/jS6NinldAxrfL97sRs7OyUEmKcrvK/a+f42xeMlDcgBE0logz Y70h41sj0wu9iQS94ph0bQ8= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4hpH7Y2wKfz1K9XH; Mon, 21 Sep 2026 16:53:13 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id 50C9D402AB; Mon, 21 Sep 2026 17:04:15 +0800 (CST) Received: from huawei.com (10.90.53.73) 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; Mon, 21 Sep 2026 17:04:13 +0800 From: Jinjie Ruan To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: Subject: [PATCH v6 10/14] crash: Extract crash_get_memory_ranges() helper Date: Mon, 21 Sep 2026 17:04:46 +0800 Message-ID: <20260921090450.807575-11-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921090450.807575-1-ruanjinjie@huawei.com> References: <20260921090450.807575-1-ruanjinjie@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemk200008.china.huawei.com (7.202.194.74) Factor out the crash memory range collection logic from crash_prepare_headers() into a separate function. This allows the memory hotplug path to obtain and modify the range list (e.g. remove offlined memory) before generating the elfcorehdr. Cc: Andrew Morton Cc: Baoquan He Cc: Mike Rapoport Cc: Pasha Tatashin Cc: Pratyush Yadav Cc: Dave Young Signed-off-by: Jinjie Ruan --- include/linux/crash_core.h | 1 + kernel/crash_core.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index bc087124cd78..b1c816e98143 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -62,6 +62,7 @@ extern int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_ma extern 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); +int crash_get_memory_ranges(struct crash_mem **mem_ranges); struct kimage; struct kexec_segment; diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 2b36aa9fade0..406b68d2adfd 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -317,8 +317,7 @@ 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_get_memory_ranges(struct crash_mem **mem_ranges) { unsigned int max_nr_ranges; struct crash_mem *cmem; @@ -344,13 +343,30 @@ int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, if (ret) goto out; + *mem_ranges = cmem; + return 0; + +out: + kvfree(cmem); + return ret; +} + +int crash_prepare_headers(int need_kernel_map, void **addr, unsigned long *sz, + unsigned long *nr_mem_ranges) +{ + struct crash_mem *cmem = NULL; + int ret; + + ret = crash_get_memory_ranges(&cmem); + if (ret) + return ret; + /* Return the computed number of memory ranges, for hotplug usage */ if (nr_mem_ranges) *nr_mem_ranges = cmem->nr_ranges; ret = crash_prepare_elf64_headers(cmem, need_kernel_map, addr, sz); -out: kvfree(cmem); return ret; } -- 2.34.1