From nobody Thu Apr 2 14:07:58 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 7E1D4FC0A for ; Thu, 12 Feb 2026 06:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770876159; cv=none; b=Cvlrz2XKMY8De2tWuwl8MlWUhdTxlBgxuI8lCyx9NdqKlPQcCxJpIdg1gV7CUYVsZt4zZPxvYMdIaUYPkEYkLvTJHgHTESKaFHfFhK7sVzU17HKoDxtNAUqFUZ5+eI38Q/Aa9I2Y3KAV1mHmqTNXM662mUCzRh2JXwPs1vjqSVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770876159; c=relaxed/simple; bh=OnxOwu1oP8f1E1Q3tOZjl9iCuM9enID8HU5QAzUK36Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=tXqz7yCcYT/d38j7WP3WQttodSDxDknXPw+/jEZTY9exSI5hPoEOSVsDEJ8yUjWlfyndD8cC95AE00t/0L/xdNWy7pS+8GxdlAsKqIoC8TQC8cZlDSm1L4T4nJfxI8KQQta0VHUylagGoUwJ48NAFzPEsyK+U6CtmEpZB/VfKbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=oT+qVrmu; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="oT+qVrmu" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61BH3sgT2503229; Thu, 12 Feb 2026 06:02:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=Hmvg6P0d+9SZZHeOBqjrXjSt0XSUVnsXbvZhlLYFU A8=; b=oT+qVrmu4nhXd0YvMpsMRVnXsBjIMRQYnGSuc1swAPNkdm5Sw5hsDjbcU XAiGPxjXw9J8qM1nPo1CLOPIidCsW/0D1Kiqs5B3N+ZG+dS+JTC9aKVYGvdhjkff JfoNr23+C2WCQJro0nF3GwGJCxBJneH4I2niFzHzwxMvibiyTZErzUFA97L3TWSs NjcUV9lHiLitXjMNIV8ItIj05k9K9fzgSlI0+r99y0xwqJqBw0kW0HhciTdoTUdf AyTkwwSZw240ZNzuyq1Fnk7x796j9UqiZVuli7sXnroyeMkedpScG1I3+8hhGbx2 r/Nj2OmnJxVJdIqFG36czeaiBjVlw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4c696va110-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Feb 2026 06:02:12 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 61C4ZFJ2019251; Thu, 12 Feb 2026 06:02:12 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4c6hxk8x6q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Feb 2026 06:02:11 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 61C628YW50921876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Feb 2026 06:02:08 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3932120040; Thu, 12 Feb 2026 06:02:08 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CF7D420043; Thu, 12 Feb 2026 06:02:03 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.39.27.166]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 12 Feb 2026 06:02:03 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Jinjie Ruan , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , "Ritesh Harjani (IBM)" , Shivang Upadhyay , linux-kernel@vger.kernel.org Subject: [PATCH v2] powerpc/crash: sort crash memory ranges before preparing elfcorehdr Date: Thu, 12 Feb 2026 11:31:59 +0530 Message-ID: <20260212060159.733023-1-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-GUID: WgP2I7qtboAQMm2_IlCUvLoxp78N--v2 X-Proofpoint-ORIG-GUID: f13Zli5vsJY8EySErt_WPM3yP13ScLLl X-Authority-Analysis: v=2.4 cv=JdWxbEKV c=1 sm=1 tr=0 ts=698d6ce5 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=VwQbUJbxAAAA:8 a=i0EeH86SAAAA:8 a=Z4Rwk6OoAAAA:8 a=20KFwNOVAAAA:8 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=TNJSkpwCZzExJk-GAwUA:9 a=HkZW87K1Qel5hWWM3VKY:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjEyMDAzOSBTYWx0ZWRfXxUzH8bwc6Vhl ICqXAaASdGKselvMaXY9QWTK+cIZZqfB3KUsghes5XCmeYRv11cOCIfCd9Z3Ebow3whS+CT0Q+i 4J2zk2xILy+AtmRwbowgcnrIrlYhbDcfwmr2/HcNDPJlGspP0Vz644SXL/KJcQGz8dfMzl067st wCScmHxX7hXXq/b0nDCxVVyb1BdL+MsaM5WYUW/DyrXzYYOOJD3e26LL0oiSX8RPSKuj++UT9N3 e5ot/OTOwlO6R0wyM+xZL+I/SNAQpoAPQu9RjWb/RWsEIsBpo4Y6qESYPZLggZ/Yy4T/ACzOKHs RF1lqIPth9bMysoxCtGbMzv+dVKUlBI3+IDV7sOTH360lAkiojYegVKkhl+/QCanfB3Z5sQtEgC /6ap9ha/OJ9VUKnMo/p7ebY5tk+4SdniUIJ4TfGMygO/13BfoqwAchbe/pTbwAvH4y2Eh6MoFin rwJuKncJkSh1ywixcsw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-12_01,2026-02-11_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 impostorscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2602120039 Content-Type: text/plain; charset="utf-8" During a memory hot-remove event, the elfcorehdr is rebuilt to exclude the removed memory. While updating the crash memory ranges for this operation, the crash memory ranges array can become unsorted. This happens because remove_mem_range() may split a memory range into two parts and append the higher-address part as a separate range at the end of the array. So far, no issues have been observed due to the unsorted crash memory ranges. However, this could lead to problems once crash memory range removal is handled by generic code, as introduced in the upcoming patches in this series. Currently, powerpc uses a platform-specific function, remove_mem_range(), to exclude hot-removed memory from the crash memory ranges. This function performs the same task as the generic crash_exclude_mem_range() in crash_core.c. The generic helper also ensures that the crash memory ranges remain sorted. So remove the redundant powerpc-specific implementation and instead call crash_exclude_mem_range_guarded() (which internally calls crash_exclude_mem_range()) to exclude the hot-removed memory ranges. Cc: Andrew Morton Cc: Baoquan he Cc: Jinjie Ruan Cc: Hari Bathini Cc: Madhavan Srinivasan Cc: Mahesh Salgaonkar Cc: Michael Ellerman Cc: Ritesh Harjani (IBM) Cc: Shivang Upadhyay Cc: linux-kernel@vger.kernel.org Signed-off-by: Sourabh Jain --- Requesting this patch to part of the below patch series. https://lore.kernel.org/all/20260209095931.2813152-1-ruanjinjie@huawei.com/ Changelog: - Update hot removed memory end address calculation --- arch/powerpc/include/asm/kexec_ranges.h | 4 +- arch/powerpc/kexec/crash.c | 5 +- arch/powerpc/kexec/ranges.c | 87 +------------------------ 3 files changed, 7 insertions(+), 89 deletions(-) diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include= /asm/kexec_ranges.h index 14055896cbcb..ad95e3792d10 100644 --- a/arch/powerpc/include/asm/kexec_ranges.h +++ b/arch/powerpc/include/asm/kexec_ranges.h @@ -7,7 +7,9 @@ void sort_memory_ranges(struct crash_mem *mrngs, bool merge); struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges); int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size); -int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size); +int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges, + unsigned long long mstart, + unsigned long long mend); int get_exclude_memory_ranges(struct crash_mem **mem_ranges); int get_reserved_memory_ranges(struct crash_mem **mem_ranges); int get_crash_memory_ranges(struct crash_mem **mem_ranges); diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c index a325c1c02f96..898742a5205c 100644 --- a/arch/powerpc/kexec/crash.c +++ b/arch/powerpc/kexec/crash.c @@ -431,7 +431,7 @@ static void update_crash_elfcorehdr(struct kimage *imag= e, struct memory_notify * struct crash_mem *cmem =3D NULL; struct kexec_segment *ksegment; void *ptr, *mem, *elfbuf =3D NULL; - unsigned long elfsz, memsz, base_addr, size; + unsigned long elfsz, memsz, base_addr, size, end; =20 ksegment =3D &image->segment[image->elfcorehdr_index]; mem =3D (void *) ksegment->mem; @@ -450,7 +450,8 @@ static void update_crash_elfcorehdr(struct kimage *imag= e, struct memory_notify * if (image->hp_action =3D=3D KEXEC_CRASH_HP_REMOVE_MEMORY) { base_addr =3D PFN_PHYS(mn->start_pfn); size =3D mn->nr_pages * PAGE_SIZE; - ret =3D remove_mem_range(&cmem, base_addr, size); + end =3D base_addr + size - 1; + ret =3D crash_exclude_mem_range_guarded(&cmem, base_addr, end); if (ret) { pr_err("Failed to remove hot-unplugged memory from crash memory ranges\= n"); goto out; diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c index 867135560e5c..6c58bcc3e130 100644 --- a/arch/powerpc/kexec/ranges.c +++ b/arch/powerpc/kexec/ranges.c @@ -553,7 +553,7 @@ int get_usable_memory_ranges(struct crash_mem **mem_ran= ges) #endif /* CONFIG_KEXEC_FILE */ =20 #ifdef CONFIG_CRASH_DUMP -static int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges, +int crash_exclude_mem_range_guarded(struct crash_mem **mem_ranges, unsigned long long mstart, unsigned long long mend) { @@ -641,89 +641,4 @@ int get_crash_memory_ranges(struct crash_mem **mem_ran= ges) pr_err("Failed to setup crash memory ranges\n"); return ret; } - -/** - * remove_mem_range - Removes the given memory range from the range list. - * @mem_ranges: Range list to remove the memory range to. - * @base: Base address of the range to remove. - * @size: Size of the memory range to remove. - * - * (Re)allocates memory, if needed. - * - * Returns 0 on success, negative errno on error. - */ -int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size) -{ - u64 end; - int ret =3D 0; - unsigned int i; - u64 mstart, mend; - struct crash_mem *mem_rngs =3D *mem_ranges; - - if (!size) - return 0; - - /* - * Memory range are stored as start and end address, use - * the same format to do remove operation. - */ - end =3D base + size - 1; - - for (i =3D 0; i < mem_rngs->nr_ranges; i++) { - mstart =3D mem_rngs->ranges[i].start; - mend =3D mem_rngs->ranges[i].end; - - /* - * Memory range to remove is not part of this range entry - * in the memory range list - */ - if (!(base >=3D mstart && end <=3D mend)) - continue; - - /* - * Memory range to remove is equivalent to this entry in the - * memory range list. Remove the range entry from the list. - */ - if (base =3D=3D mstart && end =3D=3D mend) { - for (; i < mem_rngs->nr_ranges - 1; i++) { - mem_rngs->ranges[i].start =3D mem_rngs->ranges[i+1].start; - mem_rngs->ranges[i].end =3D mem_rngs->ranges[i+1].end; - } - mem_rngs->nr_ranges--; - goto out; - } - /* - * Start address of the memory range to remove and the - * current memory range entry in the list is same. Just - * move the start address of the current memory range - * entry in the list to end + 1. - */ - else if (base =3D=3D mstart) { - mem_rngs->ranges[i].start =3D end + 1; - goto out; - } - /* - * End address of the memory range to remove and the - * current memory range entry in the list is same. - * Just move the end address of the current memory - * range entry in the list to base - 1. - */ - else if (end =3D=3D mend) { - mem_rngs->ranges[i].end =3D base - 1; - goto out; - } - /* - * Memory range to remove is not at the edge of current - * memory range entry. Split the current memory entry into - * two half. - */ - else { - size =3D mem_rngs->ranges[i].end - end + 1; - mem_rngs->ranges[i].end =3D base - 1; - ret =3D add_mem_range(mem_ranges, end + 1, size); - } - } -out: - return ret; -} #endif /* CONFIG_CRASH_DUMP */ --=20 2.52.0