From nobody Fri Dec 19 21:49:49 2025 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 2D4FD1F152B for ; Tue, 21 Jan 2025 11:55:11 +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=1737460513; cv=none; b=qlTvMwJdIGth0D1/4uEFagXPtiT6NdBKd3ittKXCj4H71RT7aPPRwSWnknCXTBEy7ULHe+5WC6d+5x6VdNYXSYSikvcNTbsDEozJt88Su4RQI6zc29kKqIKnZDoIjXbUGPrKO7wxa6vkgsdBCK9FjsUbZUl8qwyBOTQ1pw51pbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460513; c=relaxed/simple; bh=GSnAlmdA+I5daEzOtrHu9b7NALHDuLYpgNOi7yfK+b0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a2qv54fY9tCHmcDQiRtqwS67ZYL1ueOcl3lJhUywsofKriHaLnuPdwJgzMhpO1WCUTa0r1TeSurb/ODxOgFjldUGoVFOmXO5zwaHvweF/GfVNvuB+5odngj8IUJj9Mh41dj6TrUBXt2G1VjyZUx6wv2n49Km8YWAmtJDx/y0158= 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=LhX1H6Vw; 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="LhX1H6Vw" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L7XLpk010145; Tue, 21 Jan 2025 11:54:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=u+XP0qil85Jd0RWi0 SdlKQiqwId4V8KhgY5m8N1gbMI=; b=LhX1H6Vw5vM2pD3GygP2q6VVTFhjeXzXV WfeMtOJ3tMXwavWcXpDWlEX4cXig2OayWyylvU5xVGQ+FA2NBktPcM29KkqBfoRW 2Ep3fTsCk4KIVQOYYAqmJwRTGpgQweorREzBMPKdNijYxphRc6g1Yt31knrD/B+T qyt0DWmKydVRpynCeSIYM1WWwsV4+Zj7rsrk/vBRKwgIjpG4Jfi4lfohiPLc5iYc g/INfIB3DOKAhEuCKN87DVoqD6aTDHSd1QfbsN/eEovHnSvephZWbbv9SBCa7oPw 7v+aFYLYAJDaJrQIUoQMy8pF/d2vyZT0WAKf05BHx8GC6k93IcUvA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44a79n16u0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:54:57 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50LANerq022449; Tue, 21 Jan 2025 11:54:56 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 448r4k2v2x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:54:56 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBsrPo54133046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:54:53 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 040ED20040; Tue, 21 Jan 2025 11:54:53 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B83820043; Tue, 21 Jan 2025 11:54:50 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:54:49 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v2 1/6] kexec: Initialize ELF lowest address to ULONG_MAX Date: Tue, 21 Jan 2025 17:24:37 +0530 Message-ID: <20250121115442.1278458-2-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: 1oTdqcff110YdRJp_Nig7k38EEwwBPtm X-Proofpoint-ORIG-GUID: 1oTdqcff110YdRJp_Nig7k38EEwwBPtm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" kexec_elf_load() loads an ELF executable and sets the address of the lowest PT_LOAD section to the address held by the lowest_load_addr function argument. To determine the lowest PT_LOAD address, a local variable lowest_addr (type unsigned long) is initialized to UINT_MAX. After loading each PT_LOAD, its address is compared to lowest_addr. If a loaded PT_LOAD address is lower, lowest_addr is updated. However, setting lowest_addr to UINT_MAX won't work when the kernel image is loaded above 4G, as the returned lowest PT_LOAD address would be invalid. This is resolved by initializing lowest_addr to ULONG_MAX instead. This issue was discovered while implementing crashkernel high/low reservation on the PowerPC architecture. Fixes: a0458284f062 ("powerpc: Add support code for kexec_file_load()") Cc: Andrew Morton Cc: Hari Bathini Cc: Madhavan Srinivasan Cc: Mahesh Salgaonkar Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Acked-by: Baoquan He Signed-off-by: Sourabh Jain Acked-by: Hari Bathini --- kernel/kexec_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/kexec_elf.c b/kernel/kexec_elf.c index d3689632e8b9..3a5c25b2adc9 100644 --- a/kernel/kexec_elf.c +++ b/kernel/kexec_elf.c @@ -390,7 +390,7 @@ int kexec_elf_load(struct kimage *image, struct elfhdr = *ehdr, struct kexec_buf *kbuf, unsigned long *lowest_load_addr) { - unsigned long lowest_addr =3D UINT_MAX; + unsigned long lowest_addr =3D ULONG_MAX; int ret; size_t i; =20 --=20 2.47.1 From nobody Fri Dec 19 21:49:49 2025 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 4F4141F1918 for ; Tue, 21 Jan 2025 11:55:13 +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=1737460516; cv=none; b=P/0SsuUbH8aV4rxatrUbLS4uKYiBzF56kwTH94Eb/AsfhWdSBx1fSsbadczb0CsaHZWBXlxdXZcxAHeGB2CF2vZWK8X5ZA866XJmTaQpWr4s6YQk0nzZOlxyaeRW17dJn2AIl72cteBQzYIU4ueOb63y6/35j4Bo7t+0p5fQc+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460516; c=relaxed/simple; bh=MfIRGVNStgxeAUNEsVeNhdw4upFabmoGgPmYljLpzn8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fzcOamhc82siAeCOokNhUfzFZyND7mFs6Sw0dvytAHJJ3au0JYPOCk9Rr0s1LlabnAaDX9XZLkFm7N/zKcJsB4MjxEuiiPESosOYHEa7vi0OEl7we6w13bPFHyFxpV45nJ8sYqm5ChUQjaKrT4Fg2PibwpLUc5y8CcZymRoKulA= 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=myEcGYrC; 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="myEcGYrC" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L20jru003271; Tue, 21 Jan 2025 11:55:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=7MKiwUiMorQ2m9dug km4c4e1LN4evDlFQwO4FRny26c=; b=myEcGYrCA217doP4fXYc3kQIL6Hv9NN4w fUabfBOZLYYQmgMhsUYW6JgTZWQ0fRiMpxHhr2uGlMlIx3Gi/xC28dd82Do/xZ7u jQ3SVxLenoGOTS8H1B0Pt0K0pc5bKTmIaN5OtN2ur+FkUHVc2Jh6xPOpNc3U4kaw 6NvDJvO8lS1YecJkoyLbqzHF2pCA19OlCMvnzF6oE5060szS1X4yhEbLOI+G4q/W T8KbH99PYKKN4os4jawaLR29/8mHgZ7jmyKSstROJcXUaXcX9eEflOv9jsa4Pojt GFHn3DMZrodBUnuAtSSmLsMiY4x0XRcu4Jlo+j0KPO0BPdxS42vYw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44a2dyabbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:01 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50LAP7wp029622; Tue, 21 Jan 2025 11:55:00 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 448qmnayq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:00 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBsuti58786262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:54:56 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9121A2004B; Tue, 21 Jan 2025 11:54:56 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2DA120040; Tue, 21 Jan 2025 11:54:53 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:54:53 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v2 2/6] crash: remove an unused argument from reserve_crashkernel_generic() Date: Tue, 21 Jan 2025 17:24:38 +0530 Message-ID: <20250121115442.1278458-3-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: Z6-DVn_Dz9QAnLAslqPL55Q8Q_uaILiA X-Proofpoint-ORIG-GUID: Z6-DVn_Dz9QAnLAslqPL55Q8Q_uaILiA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 mlxscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=857 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" cmdline argument is not used in reserve_crashkernel_generic() so remove it. Correspondingly, all the callers have been updated as well. No functional change intended. Cc: Andrew Morton Cc: Hari Bathini Cc: Madhavan Srinivasan Cc: Mahesh Salgaonkar Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Acked-by: Baoquan He Signed-off-by: Sourabh Jain Acked-by: Hari Bathini --- arch/arm64/mm/init.c | 6 ++---- arch/loongarch/kernel/setup.c | 5 ++--- arch/riscv/mm/init.c | 6 ++---- arch/x86/kernel/setup.c | 6 ++---- include/linux/crash_reserve.h | 11 +++++------ kernel/crash_reserve.c | 9 ++++----- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9c0b8d9558fc..6c5a1ee4b5d3 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -98,21 +98,19 @@ static void __init arch_reserve_crashkernel(void) { unsigned long long low_size =3D 0; unsigned long long crash_base, crash_size; - char *cmdline =3D boot_command_line; bool high =3D false; int ret; =20 if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) return; =20 - ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), + ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base, &low_size, &high); if (ret) return; =20 - reserve_crashkernel_generic(cmdline, crash_size, crash_base, - low_size, high); + reserve_crashkernel_generic(crash_size, crash_base, low_size, high); } =20 static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 56934fe58170..ece9c4266c3f 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -259,18 +259,17 @@ static void __init arch_reserve_crashkernel(void) int ret; unsigned long long low_size =3D 0; unsigned long long crash_base, crash_size; - char *cmdline =3D boot_command_line; bool high =3D false; =20 if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) return; =20 - ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), + ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base, &low_size, &high); if (ret) return; =20 - reserve_crashkernel_generic(cmdline, crash_size, crash_base, low_size, hi= gh); + reserve_crashkernel_generic(crash_size, crash_base, low_size, high); } =20 static void __init fdt_setup(void) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 8d167e09f1fe..16b81beb41bf 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1392,21 +1392,19 @@ static void __init arch_reserve_crashkernel(void) { unsigned long long low_size =3D 0; unsigned long long crash_base, crash_size; - char *cmdline =3D boot_command_line; bool high =3D false; int ret; =20 if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) return; =20 - ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), + ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base, &low_size, &high); if (ret) return; =20 - reserve_crashkernel_generic(cmdline, crash_size, crash_base, - low_size, high); + reserve_crashkernel_generic(crash_size, crash_base, low_size, high); } =20 void __init paging_init(void) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index f1fea506e20f..15b6823556c8 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -469,14 +469,13 @@ static void __init memblock_x86_reserve_range_setup_d= ata(void) static void __init arch_reserve_crashkernel(void) { unsigned long long crash_base, crash_size, low_size =3D 0; - char *cmdline =3D boot_command_line; bool high =3D false; int ret; =20 if (!IS_ENABLED(CONFIG_CRASH_RESERVE)) return; =20 - ret =3D parse_crashkernel(cmdline, memblock_phys_mem_size(), + ret =3D parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base, &low_size, &high); if (ret) @@ -487,8 +486,7 @@ static void __init arch_reserve_crashkernel(void) return; } =20 - reserve_crashkernel_generic(cmdline, crash_size, crash_base, - low_size, high); + reserve_crashkernel_generic(crash_size, crash_base, low_size, high); } =20 static struct resource standard_io_resources[] =3D { diff --git a/include/linux/crash_reserve.h b/include/linux/crash_reserve.h index 5a9df944fb80..1fe7e7d1b214 100644 --- a/include/linux/crash_reserve.h +++ b/include/linux/crash_reserve.h @@ -32,13 +32,12 @@ int __init parse_crashkernel(char *cmdline, unsigned lo= ng long system_ram, #define CRASH_ADDR_HIGH_MAX memblock_end_of_DRAM() #endif =20 -void __init reserve_crashkernel_generic(char *cmdline, - unsigned long long crash_size, - unsigned long long crash_base, - unsigned long long crash_low_size, - bool high); +void __init reserve_crashkernel_generic(unsigned long long crash_size, + unsigned long long crash_base, + unsigned long long crash_low_size, + bool high); #else -static inline void __init reserve_crashkernel_generic(char *cmdline, +static inline void __init reserve_crashkernel_generic( unsigned long long crash_size, unsigned long long crash_base, unsigned long long crash_low_size, diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index a620fb4b2116..aff7c0fdbefa 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -375,11 +375,10 @@ static int __init reserve_crashkernel_low(unsigned lo= ng long low_size) return 0; } =20 -void __init reserve_crashkernel_generic(char *cmdline, - unsigned long long crash_size, - unsigned long long crash_base, - unsigned long long crash_low_size, - bool high) +void __init reserve_crashkernel_generic(unsigned long long crash_size, + unsigned long long crash_base, + unsigned long long crash_low_size, + bool high) { unsigned long long search_end =3D CRASH_ADDR_LOW_MAX, search_base =3D 0; bool fixed_base =3D false; --=20 2.47.1 From nobody Fri Dec 19 21:49:49 2025 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 94EA31F238C for ; Tue, 21 Jan 2025 11:55:17 +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=1737460519; cv=none; b=TpVZtkqbimqFTAFWCl6wstRqqkYpNHdQM4/yWtgsDglZCsRKbj1AeQ3+QIgFEOn6bBD+FRxTCFlT9vPNZxOsNLWQgxtQkFgkX8tMaXSzTV7fazi8YgSLRKJIyoiIWUxzPvoJWeDfkTJehVeb+vxdcWVfuU88+2+Bu7yq15mo5Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460519; c=relaxed/simple; bh=6x4K30IE9vVWBgMPIDcbCdxw6ib+YLWBzJ6AAiCeDjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Uq/FT+TjhhD0hcstnZ9sfXMghH/uXva7jLHOwokda3GSO0L+OZN/AvD0CWZ0tVdvdgW1eQP3EACHqOOzLXctfaMZfYyYdbi9ojUr49YLgrMM6TY9Hfym5aurfK0daXRrDBxNf2ISww3MCbKcTHSXe9qXtiDM+n67yKrK6Maz+KQ= 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=GqpPwR/E; 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="GqpPwR/E" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L7XLB5010140; Tue, 21 Jan 2025 11:55:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=qADcYPa4bM+Ff0Qcz 2KjMujcQUaYXmGNS3B1iOxKeEA=; b=GqpPwR/Eqv1J8y90NZHQ0vutCCG7DMz7J ZVmau3hFyjUr38ysRRjdZI9pmxs32g+5it1Oyv0o0bSZ9xAjhCqghhXDg5T0FtJh aKe2kDccy+MPYus3A3pGw/lZMIipEw/tlrzEVs+EAFTCUAqSbs72X9cRN6aXenuX KWxdLbdllb1r+6D55VoTHkRc5Mswb2dWKk411L9sAhJB3exnY9hHQFnHtyiibKKP fYewsXA3Uat8eRrfDdksElr6G8jtRTuMXp8zfbEFAcNhpkeyUK+sHn4F9A9kn2f9 CjMOfYrQY9z5CtMhgWpB7Im5+DDQEH+hKohVzCFl1GoRA4/3qwPoQ== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44a79n16ug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:04 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50LAtOU4021012; Tue, 21 Jan 2025 11:55:04 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 448sb1anh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:04 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBt0PP54133066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:55:00 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AE7220040; Tue, 21 Jan 2025 11:55:00 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC75120043; Tue, 21 Jan 2025 11:54:57 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:54:57 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/6] crash: let arch decide crash memory export to iomem_resource Date: Tue, 21 Jan 2025 17:24:39 +0530 Message-ID: <20250121115442.1278458-4-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: Gpkoxbm4_lMfrIfIwJce-msFe3yKyBvb X-Proofpoint-ORIG-GUID: Gpkoxbm4_lMfrIfIwJce-msFe3yKyBvb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" insert_crashkernel_resources() adds crash memory to iomem_resource if generic crashkernel reservation is enabled on an architecture. On PowerPC, system RAM is added to iomem_resource. See commit c40dd2f766440 ("powerpc: Add System RAM to /proc/iomem"). Enabling generic crashkernel reservation on PowerPC leads to a conflict when system RAM is added to iomem_resource because a part of the system RAM, the crashkernel memory, has already been added to iomem_resource. The next commit in the series "powerpc/crash: use generic crashkernel reservation" enables generic crashkernel reservation on PowerPC. If the crashkernel is added to iomem_resource, the kernel fails to add system RAM to /proc/iomem and prints the following traces: CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.13.0-rc2+ snip... NIP [c000000002016b3c] add_system_ram_resources+0xf0/0x15c LR [c000000002016b34] add_system_ram_resources+0xe8/0x15c Call Trace: [c00000000484bbc0] [c000000002016b34] add_system_ram_resources+0xe8/0x15c [c00000000484bc20] [c000000000010a4c] do_one_initcall+0x7c/0x39c [c00000000484bd00] [c000000002005418] do_initcalls+0x144/0x18c [c00000000484bd90] [c000000002005714] kernel_init_freeable+0x21c/0x290 [c00000000484bdf0] [c0000000000110f4] kernel_init+0x2c/0x1b8 [c00000000484be50] [c00000000000dd3c] ret_from_kernel_user_thread+0x14/0x1c To avoid this, an architecture hook is added in insert_crashkernel_resources(), allowing the architecture to decide whether crashkernel memory should be added to iomem_resource. Cc: Andrew Morton Cc: Baoquan he Cc: Hari Bathini Cc: Madhavan Srinivasan Cc: Mahesh Salgaonkar Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Sourabh Jain --- include/linux/crash_reserve.h | 11 +++++++++++ kernel/crash_reserve.c | 3 +++ 2 files changed, 14 insertions(+) diff --git a/include/linux/crash_reserve.h b/include/linux/crash_reserve.h index 1fe7e7d1b214..f1205d044dae 100644 --- a/include/linux/crash_reserve.h +++ b/include/linux/crash_reserve.h @@ -18,6 +18,17 @@ int __init parse_crashkernel(char *cmdline, unsigned lon= g long system_ram, unsigned long long *crash_size, unsigned long long *crash_base, unsigned long long *low_size, bool *high); =20 +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + +#ifndef arch_add_crash_res_to_iomem +static inline bool arch_add_crash_res_to_iomem(void) +{ + return true; +} +#endif + +#endif + #ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION #ifndef DEFAULT_CRASH_KERNEL_LOW_SIZE #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20) diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index aff7c0fdbefa..190104f32fe1 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -460,6 +460,9 @@ void __init reserve_crashkernel_generic(unsigned long l= ong crash_size, #ifndef HAVE_ARCH_ADD_CRASH_RES_TO_IOMEM_EARLY static __init int insert_crashkernel_resources(void) { + if (!arch_add_crash_res_to_iomem()) + return 0; + if (crashk_res.start < crashk_res.end) insert_resource(&iomem_resource, &crashk_res); =20 --=20 2.47.1 From nobody Fri Dec 19 21:49:49 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 435EC1F2C3B for ; Tue, 21 Jan 2025 11:55:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460523; cv=none; b=ftSNTfUrheEXk1cNnU1tQ/gd9zhckIrophamDSsn3H9aGvorY3yM/+d/zehdRismVTV3e++UePxL8f1zPSxzNjnUbODuWmlgHLSczUbgHqjK7YuWd8YpTJOy0fMerhPFgmjk7VjnWahQbiLFUIxyS7ufMR+p1yOEgELLRD8wP4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460523; c=relaxed/simple; bh=AedxT2WQLDq9iySmBlLJs5/tqBKOobcyw2HxpzWB1Qg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ELAg0qTJu3UPmtMjIXLDVVf9oOZjKtVwt/0lYYDw9XEtN6veubZsqmP2YArP40vn/dGwk+bUnw3HvbzZf08Uz70djZUxfK53ZPiRSe2TrwUOWavAL/YjtzZodYbdX4+SPbtlNAaO/e7oJO/y5osTq4O8KTzbzAFkGUtbQ9OeDdY= 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=JTFl2gr5; arc=none smtp.client-ip=148.163.156.1 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="JTFl2gr5" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L6iRSR004613; Tue, 21 Jan 2025 11:55:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=KjRS4jKfUPyn+07y/ 7uSLkCDwkxCgQHfk6gYB+4bjqg=; b=JTFl2gr576rOcPUJmfQdLHf9lqZt535Jq k7g9X1kj0hHQuDPwS9Nl7bSGFLGGLD1FQgx/EPc8txVsxBWMlPDyxRSVb1UpDVeq 9s6wkMPgR4TpoaJoBjd8mphnuQG3LdYm/VwS6i7du/MU4bk3jhNa4tK/WjMP+RxA zudlI3vrmReKTrrJ6AKSlzOZVB+TWw4bXyQoFnrAdjvlqG448CW/t2tIQix81Hnk kattmRF5+kWwIme7+1vZDv6P5sQPj54VXNCXfRnxZbp2M9Rp9fUocz3htlHA9S3o HEPAlnfC6lh8o14t+WGAAr6LiW+QhEGURafRuM1nsEuRfzMLTMJDw== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 449rrych5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:08 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50L92Zaw019218; Tue, 21 Jan 2025 11:55:08 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 448pmsb5p4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:07 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBt44d28115630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:55:04 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B6EB2004B; Tue, 21 Jan 2025 11:55:04 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9185D20040; Tue, 21 Jan 2025 11:55:01 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:55:01 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Hari Bathini , Madhavan Srinivasan , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Mahesh Salgaonkar Subject: [PATCH v2 4/6] powerpc/kdump: preserve user-specified memory limit Date: Tue, 21 Jan 2025 17:24:40 +0530 Message-ID: <20250121115442.1278458-5-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: KbBykFowyEE_QlXtcdph-dB5IUFImKzF X-Proofpoint-ORIG-GUID: KbBykFowyEE_QlXtcdph-dB5IUFImKzF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 phishscore=0 priorityscore=1501 suspectscore=0 spamscore=0 bulkscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" Commit 59d58189f3d9 ("crash: fix crash memory reserve exceed system memory bug") fails crashkernel parsing if the crash size is found to be higher than system RAM, which makes the memory_limit adjustment code ineffective due to an early exit from reserve_crashkernel(). Regardless lets not violated the user-specified memory limit by adjusting it. Remove this adjustment to ensure all reservations stay within the limit. Commit f94f5ac07983 ("powerpc/fadump: Don't update the user-specified memory limit") did the same for fadump. Cc: Andrew Morton Cc: Baoquan he Cc: Hari Bathini CC: Madhavan Srinivasan Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Mahesh Salgaonkar Signed-off-by: Sourabh Jain Acked-by: Hari Bathini --- arch/powerpc/kexec/core.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index b8333a49ea5d..4945b33322ae 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -150,14 +150,6 @@ void __init reserve_crashkernel(void) return; } =20 - /* Crash kernel trumps memory limit */ - if (memory_limit && memory_limit <=3D crashk_res.end) { - memory_limit =3D crashk_res.end + 1; - total_mem_sz =3D memory_limit; - printk("Adjusted memory limit for crashkernel, now 0x%llx\n", - memory_limit); - } - printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " "for crashkernel (System RAM: %ldMB)\n", (unsigned long)(crash_size >> 20), --=20 2.47.1 From nobody Fri Dec 19 21:49:49 2025 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 75FFC1F192B for ; Tue, 21 Jan 2025 11:55:28 +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=1737460530; cv=none; b=f1ZMqCsuqC2bsaXKXBYqhXjgdOAZTdnaf3bvxH0vkivPkaNA8/X6VbAULAAxe+LO3ed3ow7FV7yvNSCtd8bEummxEPPj3BBMmMXQjXiBEEd+V2qTQ7SJkXtfrLiAiRXeZDnlWCgSS9Je0cboc4jzvjevu/FjV5/t8SARXb5cYQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460530; c=relaxed/simple; bh=Qd8UZ9CIIkdcHyf4PA2hUwpDp2Rx13LdvDMvbiBtws4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dPvFOxDIBCWk6rJGpScatrLUV46SYyCnu9yH+AfZTl0ZN/pD/hGSgjgGTUgcFJgpfxlgeE8h7UIcNDYRlGla814idNRyhKtf0/e20pem4phebsn3X8FRRsV2pUACTMW21l8cKU4Zk7vCUnkvvb0EvZkLRFaJH4sZ7iP/EXdEcdA= 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=joWyVAIT; 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="joWyVAIT" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L762R8014707; Tue, 21 Jan 2025 11:55:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=Y3og00CYYUHHhfJdo glwsSlB8Uwxf5EtrD39C7pdlnQ=; b=joWyVAIT5rn+FpAfvM7ls4VP8SmrG6MYs FckqYA3pYrknhmcf3sFgQp+ehn7QDgDwQUDB0WoJ3/m7HQPGTL3d+uHVMcoKOeet qjb76CYisAwxnakhafOp7/hUf1hJjgJI7zyNcncxrILnzorlHMJuoTgcatncEI+v cD+an+U8HzLpcEMi+34RUdInn91Nvn1hJhfsO0gA99hX3fQyDTVX6Pq7aIrAihC6 Fe8r8LPfxQ/6Kvf7GlPjK3Bie1xx01Oy66uFrRZdAl2fGZ6T5uX+xvtYc8xQH28Y B2FYrFPaowQmwROSj46BDfsAObjxwRvzbzgBteqvgkLzXETEXhM6w== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 449sat48hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:12 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50LA4d7Q029610; Tue, 21 Jan 2025 11:55:12 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 448qmnayqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:12 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBt8GL17367538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:55:08 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F4262004B; Tue, 21 Jan 2025 11:55:08 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A44D620040; Tue, 21 Jan 2025 11:55:05 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:55:05 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Hari Bathini , Madhavan Srinivasan , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Mahesh Salgaonkar Subject: [PATCH v2 5/6] powerpc/crash: use generic crashkernel reservation Date: Tue, 21 Jan 2025 17:24:41 +0530 Message-ID: <20250121115442.1278458-6-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: SKkDRHO4VECGhv8jfzoCgzQgm2zsGkHk X-Proofpoint-ORIG-GUID: SKkDRHO4VECGhv8jfzoCgzQgm2zsGkHk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 clxscore=1015 impostorscore=0 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" Commit 0ab97169aa05 ("crash_core: add generic function to do reservation") added a generic function to reserve crashkernel memory. So let's use the same function on powerpc and remove the architecture-specific code that essentially does the same thing. The generic crashkernel reservation also provides a way to split the crashkernel reservation into high and low memory reservations, which can be enabled for powerpc in the future. Along with moving to the generic crashkernel reservation, the code related to finding the base address for the crashkernel has been separated into its own function name get_crash_base() for better readability and maintainability. To prevent crashkernel memory from being added to iomem_resource, the function arch_add_crash_res_to_iomem() has been introduced. For further details on why this should not be done for the PowerPC architecture, please refer to the previous commit titled "crash: let arch decide crash memory export to iomem_resource. Cc: Andrew Morton Cc: Baoquan he Cc: Hari Bathini CC: Madhavan Srinivasan Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Mahesh Salgaonkar Signed-off-by: Sourabh Jain Acked-by: Hari Bathini --- arch/powerpc/Kconfig | 3 + arch/powerpc/include/asm/crash_reserve.h | 18 +++++ arch/powerpc/include/asm/kexec.h | 4 +- arch/powerpc/kernel/prom.c | 2 +- arch/powerpc/kexec/core.c | 90 ++++++++++-------------- 5 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 arch/powerpc/include/asm/crash_reserve.h diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index db9f7b2d07bf..880d35fadf40 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -718,6 +718,9 @@ config ARCH_SUPPORTS_CRASH_HOTPLUG def_bool y depends on PPC64 =20 +config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + def_bool CRASH_RESERVE + config FA_DUMP bool "Firmware-assisted dump" depends on CRASH_DUMP && PPC64 && (PPC_RTAS || PPC_POWERNV) diff --git a/arch/powerpc/include/asm/crash_reserve.h b/arch/powerpc/includ= e/asm/crash_reserve.h new file mode 100644 index 000000000000..f5e60721de41 --- /dev/null +++ b/arch/powerpc/include/asm/crash_reserve.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_POWERPC_CRASH_RESERVE_H +#define _ASM_POWERPC_CRASH_RESERVE_H + +/* crash kernel regions are Page size agliged */ +#define CRASH_ALIGN PAGE_SIZE + +#ifdef CONFIG_ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION + +static inline bool arch_add_crash_res_to_iomem(void) +{ + return false; +} +#define arch_add_crash_res_to_iomem arch_add_crash_res_to_iomem +#endif + +#endif /* _ASM_POWERPC_CRASH_RESERVE_H */ + diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/ke= xec.h index 270ee93a0f7d..64741558071f 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -113,9 +113,9 @@ int setup_new_fdt_ppc64(const struct kimage *image, voi= d *fdt, struct crash_mem =20 #ifdef CONFIG_CRASH_RESERVE int __init overlaps_crashkernel(unsigned long start, unsigned long size); -extern void reserve_crashkernel(void); +extern void arch_reserve_crashkernel(void); #else -static inline void reserve_crashkernel(void) {} +static inline void arch_reserve_crashkernel(void) {} static inline int overlaps_crashkernel(unsigned long start, unsigned long = size) { return 0; } #endif =20 diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index e0059842a1c6..9ed9dde7d231 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -860,7 +860,7 @@ void __init early_init_devtree(void *params) */ if (fadump_reserve_mem() =3D=3D 0) #endif - reserve_crashkernel(); + arch_reserve_crashkernel(); early_reserve_mem(); =20 if (memory_limit > memblock_phys_mem_size()) diff --git a/arch/powerpc/kexec/core.c b/arch/powerpc/kexec/core.c index 4945b33322ae..b21cfa814492 100644 --- a/arch/powerpc/kexec/core.c +++ b/arch/powerpc/kexec/core.c @@ -80,38 +80,20 @@ void machine_kexec(struct kimage *image) } =20 #ifdef CONFIG_CRASH_RESERVE -void __init reserve_crashkernel(void) -{ - unsigned long long crash_size, crash_base, total_mem_sz; - int ret; =20 - total_mem_sz =3D memory_limit ? memory_limit : memblock_phys_mem_size(); - /* use common parsing */ - ret =3D parse_crashkernel(boot_command_line, total_mem_sz, - &crash_size, &crash_base, NULL, NULL); - if (ret =3D=3D 0 && crash_size > 0) { - crashk_res.start =3D crash_base; - crashk_res.end =3D crash_base + crash_size - 1; - } - - if (crashk_res.end =3D=3D crashk_res.start) { - crashk_res.start =3D crashk_res.end =3D 0; - return; - } - - /* We might have got these values via the command line or the - * device tree, either way sanitise them now. */ - - crash_size =3D resource_size(&crashk_res); +static unsigned long long __init get_crash_base(unsigned long long crash_b= ase) +{ =20 #ifndef CONFIG_NONSTATIC_KERNEL - if (crashk_res.start !=3D KDUMP_KERNELBASE) + if (crash_base !=3D KDUMP_KERNELBASE) printk("Crash kernel location must be 0x%x\n", KDUMP_KERNELBASE); =20 - crashk_res.start =3D KDUMP_KERNELBASE; + return KDUMP_KERNELBASE; #else - if (!crashk_res.start) { + unsigned long long crash_base_align; + + if (!crash_base) { #ifdef CONFIG_PPC64 /* * On the LPAR platform place the crash kernel to mid of @@ -123,45 +105,51 @@ void __init reserve_crashkernel(void) * kernel starts at 128MB offset on other platforms. */ if (firmware_has_feature(FW_FEATURE_LPAR)) - crashk_res.start =3D min_t(u64, ppc64_rma_size / 2, SZ_512M); + crash_base =3D min_t(u64, ppc64_rma_size / 2, SZ_512M); else - crashk_res.start =3D min_t(u64, ppc64_rma_size / 2, SZ_128M); + crash_base =3D min_t(u64, ppc64_rma_size / 2, SZ_128M); #else - crashk_res.start =3D KDUMP_KERNELBASE; + crash_base =3D KDUMP_KERNELBASE; #endif } =20 - crash_base =3D PAGE_ALIGN(crashk_res.start); - if (crash_base !=3D crashk_res.start) { - printk("Crash kernel base must be aligned to 0x%lx\n", - PAGE_SIZE); - crashk_res.start =3D crash_base; - } + crash_base_align =3D PAGE_ALIGN(crash_base); + if (crash_base !=3D crash_base_align) + pr_warn("Crash kernel base must be aligned to 0x%lx\n", PAGE_SIZE); =20 + return crash_base_align; #endif - crash_size =3D PAGE_ALIGN(crash_size); - crashk_res.end =3D crashk_res.start + crash_size - 1; +} =20 - /* The crash region must not overlap the current kernel */ - if (overlaps_crashkernel(__pa(_stext), _end - _stext)) { - printk(KERN_WARNING - "Crash kernel can not overlap current kernel\n"); - crashk_res.start =3D crashk_res.end =3D 0; +void __init arch_reserve_crashkernel(void) +{ + unsigned long long crash_size, crash_base, crash_end; + unsigned long long kernel_start, kernel_size; + unsigned long long total_mem_sz; + int ret; + + total_mem_sz =3D memory_limit ? memory_limit : memblock_phys_mem_size(); + + /* use common parsing */ + ret =3D parse_crashkernel(boot_command_line, total_mem_sz, &crash_size, + &crash_base, NULL, NULL); + + if (ret) return; - } =20 - printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " - "for crashkernel (System RAM: %ldMB)\n", - (unsigned long)(crash_size >> 20), - (unsigned long)(crashk_res.start >> 20), - (unsigned long)(total_mem_sz >> 20)); + crash_base =3D get_crash_base(crash_base); + crash_end =3D crash_base + crash_size - 1; =20 - if (!memblock_is_region_memory(crashk_res.start, crash_size) || - memblock_reserve(crashk_res.start, crash_size)) { - pr_err("Failed to reserve memory for crashkernel!\n"); - crashk_res.start =3D crashk_res.end =3D 0; + kernel_start =3D __pa(_stext); + kernel_size =3D _end - _stext; + + /* The crash region must not overlap the current kernel */ + if ((kernel_start + kernel_size > crash_base) && (kernel_start <=3D crash= _end)) { + pr_warn("Crash kernel can not overlap current kernel\n"); return; } + + reserve_crashkernel_generic(crash_size, crash_base, 0, false); } =20 int __init overlaps_crashkernel(unsigned long start, unsigned long size) --=20 2.47.1 From nobody Fri Dec 19 21:49:49 2025 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 15CEB1448D5 for ; Tue, 21 Jan 2025 11:55:29 +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=1737460531; cv=none; b=awLiIJEjS2E0sOGAOULMTwy3qPsINAoqd9dMTEWAhuSXDnv+0dJEX4vmG3wv9+F/LzGMMOTo7QeGkzXd2l58V8aCCY5gU3fxXMnTlw5UIUBWP4WRwWaAodt1ndW2DRWumfS2jCcgOEPXcbWM3SQI03tqLPoQaCLm6xM0klrIgtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737460531; c=relaxed/simple; bh=qKzVeFccKLlM17zo3NDvDN3T6a58he0iTF6aPEyQ/g4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dxsUop6UGFmuxp8Ic1RlGOPEhxGU3Gpll8R3GAffLSSlBBF5pehs2CLILuFwgFquFIYccRKB8w4n5U7imirdgQH5wytmUppFgLURgExTRMZuJ3uM24MGfspRWvm5LcWPOgDQx1NillaRikfDQFWbtc0J2hGardCeezjYlxyF8d0= 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=NjcELZ0w; 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="NjcELZ0w" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50L20r90003876; Tue, 21 Jan 2025 11:55:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=TEOsjd0kOfsKjU6sQ KsR5plpv3P+yDUOpn9HqWpc7cA=; b=NjcELZ0wEBwvM9KR0Thwo/TP78WgpPLWB Wc444RChwANsWPsMc5vTp2ovNypawzDfv74BFXFgdx8p42M+SUP+kxtujXPqZSy3 MzCniyUqnJyXulKJnfKq1bwAvrd6PPJvXnoKgk7s2A/Hq8pimUo9Oa6Rd913bK/E RpBSspetFs2Uj2/NHCrD3/nBbpjZ1Q6dO8rkEk+kPXb41ioZ2EDuKE8HURWJsapa KMOePOWGqBU+47GWPZCS8VgYsnS8LmpM+6ysji2fw8OOPhx89yBtUthcQvN/QEoT qVBnpBRfWXKBhAeBpqIrjjDxWIxnvVM1Y73bvdkuf1tuf/7U675Uw== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44a2dyabcy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:16 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 50LAPPpG029594; Tue, 21 Jan 2025 11:55:16 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 448qmnayr0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2025 11:55:16 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 50LBtCse62259546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Jan 2025 11:55:12 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 760B52004B; Tue, 21 Jan 2025 11:55:12 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B87B20040; Tue, 21 Jan 2025 11:55:09 +0000 (GMT) Received: from li-4f5ba44c-27d4-11b2-a85c-a08f5b49eada.ibm.com.com (unknown [9.43.54.128]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Jan 2025 11:55:09 +0000 (GMT) From: Sourabh Jain To: linuxppc-dev@lists.ozlabs.org Cc: Sourabh Jain , Andrew Morton , Baoquan he , Hari Bathini , Madhavan Srinivasan , Mahesh Salgaonkar , Michael Ellerman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/6] crash: option to let arch decide mem range is usable Date: Tue, 21 Jan 2025 17:24:42 +0530 Message-ID: <20250121115442.1278458-7-sourabhjain@linux.ibm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> References: <20250121115442.1278458-1-sourabhjain@linux.ibm.com> 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-GUID: r4yBdaaAIm9mwvVi3LINExR4QewaPzip X-Proofpoint-ORIG-GUID: r4yBdaaAIm9mwvVi3LINExR4QewaPzip X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-21_05,2025-01-21_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 mlxscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2501210095 Content-Type: text/plain; charset="utf-8" On PowerPC, the memory reserved for the crashkernel can contain components like RTAS, TCE, OPAL, etc., which should be avoided when loading kexec segments into crashkernel memory. Due to these special components, PowerPC has its own set of functions to locate holes in the crashkernel memory for loading kexec segments for kdump. However, for loading kexec segments in the kexec case, PowerPC uses generic functions to locate holes. So, let's use generic functions to locate memory holes for kdump on PowerPC by adding an arch hook to handle such special regions while loading kexec segments, and remove the PowerPC functions to locate holes. Cc: Andrew Morton Cc: Baoquan he Cc: Hari Bathini Cc: Madhavan Srinivasan Cc: Mahesh Salgaonkar Cc: Michael Ellerman Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Sourabh Jain --- arch/powerpc/include/asm/kexec.h | 6 +- arch/powerpc/kexec/file_load_64.c | 259 ++---------------------------- include/linux/kexec.h | 9 ++ kernel/kexec_file.c | 12 ++ 4 files changed, 34 insertions(+), 252 deletions(-) diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/ke= xec.h index 64741558071f..5e4680f9ff35 100644 --- a/arch/powerpc/include/asm/kexec.h +++ b/arch/powerpc/include/asm/kexec.h @@ -95,8 +95,10 @@ int arch_kexec_kernel_image_probe(struct kimage *image, = void *buf, unsigned long int arch_kimage_file_post_load_cleanup(struct kimage *image); #define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_clea= nup =20 -int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); -#define arch_kexec_locate_mem_hole arch_kexec_locate_mem_hole +int arch_check_excluded_range(struct kimage *image, unsigned long start, + unsigned long end); +#define arch_check_excluded_range arch_check_excluded_range + =20 int load_crashdump_segments_ppc64(struct kimage *image, struct kexec_buf *kbuf); diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_lo= ad_64.c index dc65c1391157..e7ef8b2a2554 100644 --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -49,201 +49,18 @@ const struct kexec_file_ops * const kexec_file_loaders= [] =3D { NULL }; =20 -/** - * __locate_mem_hole_top_down - Looks top down for a large enough memory h= ole - * in the memory regions between buf_min & bu= f_max - * for the buffer. If found, sets kbuf->mem. - * @kbuf: Buffer contents and memory parameters. - * @buf_min: Minimum address for the buffer. - * @buf_max: Maximum address for the buffer. - * - * Returns 0 on success, negative errno on error. - */ -static int __locate_mem_hole_top_down(struct kexec_buf *kbuf, - u64 buf_min, u64 buf_max) -{ - int ret =3D -EADDRNOTAVAIL; - phys_addr_t start, end; - u64 i; - - for_each_mem_range_rev(i, &start, &end) { - /* - * memblock uses [start, end) convention while it is - * [start, end] here. Fix the off-by-one to have the - * same convention. - */ - end -=3D 1; - - if (start > buf_max) - continue; - - /* Memory hole not found */ - if (end < buf_min) - break; - - /* Adjust memory region based on the given range */ - if (start < buf_min) - start =3D buf_min; - if (end > buf_max) - end =3D buf_max; - - start =3D ALIGN(start, kbuf->buf_align); - if (start < end && (end - start + 1) >=3D kbuf->memsz) { - /* Suitable memory range found. Set kbuf->mem */ - kbuf->mem =3D ALIGN_DOWN(end - kbuf->memsz + 1, - kbuf->buf_align); - ret =3D 0; - break; - } - } - - return ret; -} - -/** - * locate_mem_hole_top_down_ppc64 - Skip special memory regions to find a - * suitable buffer with top down approach. - * @kbuf: Buffer contents and memory parameters. - * @buf_min: Minimum address for the buffer. - * @buf_max: Maximum address for the buffer. - * @emem: Exclude memory ranges. - * - * Returns 0 on success, negative errno on error. - */ -static int locate_mem_hole_top_down_ppc64(struct kexec_buf *kbuf, - u64 buf_min, u64 buf_max, - const struct crash_mem *emem) +int arch_check_excluded_range(struct kimage *image, unsigned long start, + unsigned long end) { - int i, ret =3D 0, err =3D -EADDRNOTAVAIL; - u64 start, end, tmin, tmax; - - tmax =3D buf_max; - for (i =3D (emem->nr_ranges - 1); i >=3D 0; i--) { - start =3D emem->ranges[i].start; - end =3D emem->ranges[i].end; - - if (start > tmax) - continue; - - if (end < tmax) { - tmin =3D (end < buf_min ? buf_min : end + 1); - ret =3D __locate_mem_hole_top_down(kbuf, tmin, tmax); - if (!ret) - return 0; - } - - tmax =3D start - 1; - - if (tmax < buf_min) { - ret =3D err; - break; - } - ret =3D 0; - } - - if (!ret) { - tmin =3D buf_min; - ret =3D __locate_mem_hole_top_down(kbuf, tmin, tmax); - } - return ret; -} - -/** - * __locate_mem_hole_bottom_up - Looks bottom up for a large enough memory= hole - * in the memory regions between buf_min & b= uf_max - * for the buffer. If found, sets kbuf->mem. - * @kbuf: Buffer contents and memory parameters. - * @buf_min: Minimum address for the buffer. - * @buf_max: Maximum address for the buffer. - * - * Returns 0 on success, negative errno on error. - */ -static int __locate_mem_hole_bottom_up(struct kexec_buf *kbuf, - u64 buf_min, u64 buf_max) -{ - int ret =3D -EADDRNOTAVAIL; - phys_addr_t start, end; - u64 i; - - for_each_mem_range(i, &start, &end) { - /* - * memblock uses [start, end) convention while it is - * [start, end] here. Fix the off-by-one to have the - * same convention. - */ - end -=3D 1; - - if (end < buf_min) - continue; - - /* Memory hole not found */ - if (start > buf_max) - break; - - /* Adjust memory region based on the given range */ - if (start < buf_min) - start =3D buf_min; - if (end > buf_max) - end =3D buf_max; - - start =3D ALIGN(start, kbuf->buf_align); - if (start < end && (end - start + 1) >=3D kbuf->memsz) { - /* Suitable memory range found. Set kbuf->mem */ - kbuf->mem =3D start; - ret =3D 0; - break; - } - } - - return ret; -} - -/** - * locate_mem_hole_bottom_up_ppc64 - Skip special memory regions to find a - * suitable buffer with bottom up approa= ch. - * @kbuf: Buffer contents and memory parameters. - * @buf_min: Minimum address for the buffer. - * @buf_max: Maximum address for the buffer. - * @emem: Exclude memory ranges. - * - * Returns 0 on success, negative errno on error. - */ -static int locate_mem_hole_bottom_up_ppc64(struct kexec_buf *kbuf, - u64 buf_min, u64 buf_max, - const struct crash_mem *emem) -{ - int i, ret =3D 0, err =3D -EADDRNOTAVAIL; - u64 start, end, tmin, tmax; - - tmin =3D buf_min; - for (i =3D 0; i < emem->nr_ranges; i++) { - start =3D emem->ranges[i].start; - end =3D emem->ranges[i].end; - - if (end < tmin) - continue; - - if (start > tmin) { - tmax =3D (start > buf_max ? buf_max : start - 1); - ret =3D __locate_mem_hole_bottom_up(kbuf, tmin, tmax); - if (!ret) - return 0; - } - - tmin =3D end + 1; + struct crash_mem *emem; + int i; =20 - if (tmin > buf_max) { - ret =3D err; - break; - } - ret =3D 0; - } + emem =3D image->arch.exclude_ranges; + for (i =3D 0; i < emem->nr_ranges; i++) + if (start < emem->ranges[i].end && end > emem->ranges[i].start) + return 1; =20 - if (!ret) { - tmax =3D buf_max; - ret =3D __locate_mem_hole_bottom_up(kbuf, tmin, tmax); - } - return ret; + return 0; } =20 #ifdef CONFIG_CRASH_DUMP @@ -1004,64 +821,6 @@ int setup_new_fdt_ppc64(const struct kimage *image, v= oid *fdt, struct crash_mem return ret; } =20 -/** - * arch_kexec_locate_mem_hole - Skip special memory regions like rtas, opa= l, - * tce-table, reserved-ranges & such (exclude - * memory ranges) as they can't be used for k= exec - * segment buffer. Sets kbuf->mem when a suit= able - * memory hole is found. - * @kbuf: Buffer contents and memory parameters. - * - * Assumes minimum of PAGE_SIZE alignment for kbuf->memsz & kbuf->buf_alig= n. - * - * Returns 0 on success, negative errno on error. - */ -int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) -{ - struct crash_mem **emem; - u64 buf_min, buf_max; - int ret; - - /* Look up the exclude ranges list while locating the memory hole */ - emem =3D &(kbuf->image->arch.exclude_ranges); - if (!(*emem) || ((*emem)->nr_ranges =3D=3D 0)) { - pr_warn("No exclude range list. Using the default locate mem hole method= \n"); - return kexec_locate_mem_hole(kbuf); - } - - buf_min =3D kbuf->buf_min; - buf_max =3D kbuf->buf_max; - /* Segments for kdump kernel should be within crashkernel region */ - if (IS_ENABLED(CONFIG_CRASH_DUMP) && kbuf->image->type =3D=3D KEXEC_TYPE_= CRASH) { - buf_min =3D (buf_min < crashk_res.start ? - crashk_res.start : buf_min); - buf_max =3D (buf_max > crashk_res.end ? - crashk_res.end : buf_max); - } - - if (buf_min > buf_max) { - pr_err("Invalid buffer min and/or max values\n"); - return -EINVAL; - } - - if (kbuf->top_down) - ret =3D locate_mem_hole_top_down_ppc64(kbuf, buf_min, buf_max, - *emem); - else - ret =3D locate_mem_hole_bottom_up_ppc64(kbuf, buf_min, buf_max, - *emem); - - /* Add the buffer allocated to the exclude list for the next lookup */ - if (!ret) { - add_mem_range(emem, kbuf->mem, kbuf->memsz); - sort_memory_ranges(*emem, true); - } else { - pr_err("Failed to locate memory buffer of size %lu\n", - kbuf->memsz); - } - return ret; -} - /** * arch_kexec_kernel_image_probe - Does additional handling needed to setup * kexec segments. diff --git a/include/linux/kexec.h b/include/linux/kexec.h index f0e9f8eda7a3..407f8b0346aa 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -205,6 +205,15 @@ static inline int arch_kimage_file_post_load_cleanup(s= truct kimage *image) } #endif =20 +#ifndef arch_check_excluded_range +static inline int arch_check_excluded_range(struct kimage *image, + unsigned long start, + unsigned long end) +{ + return 0; +} +#endif + #ifdef CONFIG_KEXEC_SIG #ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_le= n); diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 3eedb8c226ad..fba686487e3b 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -464,6 +464,12 @@ static int locate_mem_hole_top_down(unsigned long star= t, unsigned long end, continue; } =20 + /* Make sure this does not conflict with exclude range */ + if (arch_check_excluded_range(image, temp_start, temp_end)) { + temp_start =3D temp_start - PAGE_SIZE; + continue; + } + /* We found a suitable memory range */ break; } while (1); @@ -498,6 +504,12 @@ static int locate_mem_hole_bottom_up(unsigned long sta= rt, unsigned long end, continue; } =20 + /* Make sure this does not conflict with exclude range */ + if (arch_check_excluded_range(image, temp_start, temp_end)) { + temp_start =3D temp_start + PAGE_SIZE; + continue; + } + /* We found a suitable memory range */ break; } while (1); --=20 2.47.1