From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D245CC5478C for ; Sat, 2 Mar 2024 13:20:52 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LZPLUgzC; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Tn5Dz3wMFz3vj6 for ; Sun, 3 Mar 2024 00:20:51 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LZPLUgzC; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Tn5Bf31FTz3cTQ for ; Sun, 3 Mar 2024 00:18:50 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tn5Bf2XyJz4wcQ for ; Sun, 3 Mar 2024 00:18:50 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Tn5Bf2TLlz4wcT; Sun, 3 Mar 2024 00:18:50 +1100 (AEDT) Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=LZPLUgzC; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=hbathini@linux.ibm.com; receiver=ozlabs.org) 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 gandalf.ozlabs.org (Postfix) with ESMTPS id 4Tn5Bd6YvVz4wcQ for ; Sun, 3 Mar 2024 00:18:49 +1100 (AEDT) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 422ClBXb007577; Sat, 2 Mar 2024 13:18:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : from : subject : to : cc : content-type : content-transfer-encoding; s=pp1; bh=q8YBDHbs+qbSzjVa2od1T1+TqTTmivLnG98V/TtBiOI=; b=LZPLUgzCr2VbrTBeNfPaH/+DDkvwBt/GN1XFYw2ihN6tI4hzWQ1McfKkJDgE17qFiq8b SqRSzy13KRo2Qa/Ahe4POZn7w9BU2106IBPUDPAfIMUAwnG5a+RKCo7lwue15HpC3WsK kp1WhSCeqHbQyhTW0bNH8C+1Mpkz0c8OlGzMzuceiyHbxlBGoQ7XYRzryGg98J/K8kdU gLNQwm3Ef8Dk2pJX2nWVzGinR6untuzQ7tQWkVl25EoA2Em30lSzS4L/Z65BOu1wb6ZM 5DPq7TqTghICaXZIGT64jkUXkm/lJk/ovYkAeI+siB/X+Xr1WZgLT+GtiXwnphV6848W kA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wm4e38fdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 02 Mar 2024 13:18:32 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 422Co99u013538; Sat, 2 Mar 2024 13:18:32 GMT 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 3wm4e38fdk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 02 Mar 2024 13:18:32 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 422DHltE012324; Sat, 2 Mar 2024 13:18:31 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wfwg32dqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 02 Mar 2024 13:18:31 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 422DIP8G13959778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 2 Mar 2024 13:18:27 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9426E20040; Sat, 2 Mar 2024 13:18:25 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 85AF52004D; Sat, 2 Mar 2024 13:18:19 +0000 (GMT) Received: from [9.43.41.117] (unknown [9.43.41.117]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Sat, 2 Mar 2024 13:18:19 +0000 (GMT) Message-ID: <66076459-ea05-44ca-8c51-58452f6e1b1d@linux.ibm.com> Date: Sat, 2 Mar 2024 18:48:19 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Hari Bathini Subject: Re: [PATCH v17 3/6] powerpc/kexec: move *_memory_ranges functions to ranges.c To: Sourabh Jain , linuxppc-dev@ozlabs.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: mb73ar_Sysmnoe2RIrG_3h2t83_SwUiQ X-Proofpoint-GUID: F3fX69puXWZZla5EQ3oCRUckdlHG-2n9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-02_04,2024-03-01_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 clxscore=1015 mlxscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2403020115 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Valentin Schneider , x86@kernel.org, Andrew Morton , Baoquan He , David Hildenbrand , Greg Kroah-Hartman , Dave Hansen , kexec@lists.infradead.org, Naveen N Rao , Mimi Zohar , Mahesh Salgaonkar , "Aneesh Kumar K . V" , Laurent Dufour , Borislav Petkov , Akhil Raj , Boris Ostrovsky , Dave Young , Thomas Gleixner , Vivek Goyal , Oscar Salvador Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 26/02/24 2:11 pm, Sourabh Jain wrote: > Move the following functions form kexec/{file_load_64.c => ranges.c} and > make them public so that components other KEXEC_FILE can also use these > functions. > 1. get_exclude_memory_ranges > 2. get_reserved_memory_ranges > 3. get_crash_memory_ranges > 4. get_usable_memory_ranges > > Later in the series get_crash_memory_ranges function is utilized for > in-kernel updates to kdump image during CPU/Memory hotplug or > online/offline events for both kexec_load and kexec_file_load syscalls. > > Since the above functions are moved to ranges.c, some of the helper > functions in ranges.c are no longer required to be public. Mark them as > static and removed them from kexec_ranges.h header file. > > Finally, remove the CONFIG_KEXEC_FILE build dependency for range.c > because it is required for other config, such as CONFIG_CRASH_DUMP. > > No functional changes are intended. > Acked-by: Hari Bathini > Signed-off-by: Sourabh Jain > Cc: Akhil Raj > Cc: Andrew Morton > Cc: Aneesh Kumar K.V > Cc: Baoquan He > Cc: Borislav Petkov (AMD) > Cc: Boris Ostrovsky > Cc: Christophe Leroy > Cc: Dave Hansen > Cc: Dave Young > Cc: David Hildenbrand > Cc: Greg Kroah-Hartman > Cc: Hari Bathini > Cc: Laurent Dufour > Cc: Mahesh Salgaonkar > Cc: Michael Ellerman > Cc: Mimi Zohar > Cc: Naveen N Rao > Cc: Oscar Salvador > Cc: Thomas Gleixner > Cc: Valentin Schneider > Cc: Vivek Goyal > Cc: kexec@lists.infradead.org > Cc: x86@kernel.org > --- > arch/powerpc/include/asm/kexec_ranges.h | 19 +- > arch/powerpc/kexec/Makefile | 4 +- > arch/powerpc/kexec/file_load_64.c | 190 -------------------- > arch/powerpc/kexec/ranges.c | 227 +++++++++++++++++++++++- > 4 files changed, 224 insertions(+), 216 deletions(-) > > diff --git a/arch/powerpc/include/asm/kexec_ranges.h b/arch/powerpc/include/asm/kexec_ranges.h > index f83866a19e87..8489e844b447 100644 > --- a/arch/powerpc/include/asm/kexec_ranges.h > +++ b/arch/powerpc/include/asm/kexec_ranges.h > @@ -7,19 +7,8 @@ > 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 add_tce_mem_ranges(struct crash_mem **mem_ranges); > -int add_initrd_mem_range(struct crash_mem **mem_ranges); > -#ifdef CONFIG_PPC_64S_HASH_MMU > -int add_htab_mem_range(struct crash_mem **mem_ranges); > -#else > -static inline int add_htab_mem_range(struct crash_mem **mem_ranges) > -{ > - return 0; > -} > -#endif > -int add_kernel_mem_range(struct crash_mem **mem_ranges); > -int add_rtas_mem_range(struct crash_mem **mem_ranges); > -int add_opal_mem_range(struct crash_mem **mem_ranges); > -int add_reserved_mem_ranges(struct crash_mem **mem_ranges); > - > +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); > +int get_usable_memory_ranges(struct crash_mem **mem_ranges); > #endif /* _ASM_POWERPC_KEXEC_RANGES_H */ > diff --git a/arch/powerpc/kexec/Makefile b/arch/powerpc/kexec/Makefile > index 8e469c4da3f8..470eb0453e17 100644 > --- a/arch/powerpc/kexec/Makefile > +++ b/arch/powerpc/kexec/Makefile > @@ -3,11 +3,11 @@ > # Makefile for the linux kernel. > # > > -obj-y += core.o core_$(BITS).o > +obj-y += core.o core_$(BITS).o ranges.o > > obj-$(CONFIG_PPC32) += relocate_32.o > > -obj-$(CONFIG_KEXEC_FILE) += file_load.o ranges.o file_load_$(BITS).o elf_$(BITS).o > +obj-$(CONFIG_KEXEC_FILE) += file_load.o file_load_$(BITS).o elf_$(BITS).o > obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o > obj-$(CONFIG_CRASH_DUMP) += crash.o > > diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c > index 1bc65de6174f..6a01f62b8fcf 100644 > --- a/arch/powerpc/kexec/file_load_64.c > +++ b/arch/powerpc/kexec/file_load_64.c > @@ -47,83 +47,6 @@ const struct kexec_file_ops * const kexec_file_loaders[] = { > NULL > }; > > -/** > - * get_exclude_memory_ranges - Get exclude memory ranges. This list includes > - * regions like opal/rtas, tce-table, initrd, > - * kernel, htab which should be avoided while > - * setting up kexec load segments. > - * @mem_ranges: Range list to add the memory ranges to. > - * > - * Returns 0 on success, negative errno on error. > - */ > -static int get_exclude_memory_ranges(struct crash_mem **mem_ranges) > -{ > - int ret; > - > - ret = add_tce_mem_ranges(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_initrd_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_htab_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_kernel_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_rtas_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_opal_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_reserved_mem_ranges(mem_ranges); > - if (ret) > - goto out; > - > - /* exclude memory ranges should be sorted for easy lookup */ > - sort_memory_ranges(*mem_ranges, true); > -out: > - if (ret) > - pr_err("Failed to setup exclude memory ranges\n"); > - return ret; > -} > - > -/** > - * get_reserved_memory_ranges - Get reserve memory ranges. This list includes > - * memory regions that should be added to the > - * memory reserve map to ensure the region is > - * protected from any mischief. > - * @mem_ranges: Range list to add the memory ranges to. > - * > - * Returns 0 on success, negative errno on error. > - */ > -static int get_reserved_memory_ranges(struct crash_mem **mem_ranges) > -{ > - int ret; > - > - ret = add_rtas_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_tce_mem_ranges(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_reserved_mem_ranges(mem_ranges); > -out: > - if (ret) > - pr_err("Failed to setup reserved memory ranges\n"); > - return ret; > -} > - > /** > * __locate_mem_hole_top_down - Looks top down for a large enough memory hole > * in the memory regions between buf_min & buf_max > @@ -322,119 +245,6 @@ static int locate_mem_hole_bottom_up_ppc64(struct kexec_buf *kbuf, > } > > #ifdef CONFIG_CRASH_DUMP > -/** > - * get_usable_memory_ranges - Get usable memory ranges. This list includes > - * regions like crashkernel, opal/rtas & tce-table, > - * that kdump kernel could use. > - * @mem_ranges: Range list to add the memory ranges to. > - * > - * Returns 0 on success, negative errno on error. > - */ > -static int get_usable_memory_ranges(struct crash_mem **mem_ranges) > -{ > - int ret; > - > - /* > - * Early boot failure observed on guests when low memory (first memory > - * block?) is not added to usable memory. So, add [0, crashk_res.end] > - * instead of [crashk_res.start, crashk_res.end] to workaround it. > - * Also, crashed kernel's memory must be added to reserve map to > - * avoid kdump kernel from using it. > - */ > - ret = add_mem_range(mem_ranges, 0, crashk_res.end + 1); > - if (ret) > - goto out; > - > - ret = add_rtas_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_opal_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_tce_mem_ranges(mem_ranges); > -out: > - if (ret) > - pr_err("Failed to setup usable memory ranges\n"); > - return ret; > -} > - > -/** > - * get_crash_memory_ranges - Get crash memory ranges. This list includes > - * first/crashing kernel's memory regions that > - * would be exported via an elfcore. > - * @mem_ranges: Range list to add the memory ranges to. > - * > - * Returns 0 on success, negative errno on error. > - */ > -static int get_crash_memory_ranges(struct crash_mem **mem_ranges) > -{ > - phys_addr_t base, end; > - struct crash_mem *tmem; > - u64 i; > - int ret; > - > - for_each_mem_range(i, &base, &end) { > - u64 size = end - base; > - > - /* Skip backup memory region, which needs a separate entry */ > - if (base == BACKUP_SRC_START) { > - if (size > BACKUP_SRC_SIZE) { > - base = BACKUP_SRC_END + 1; > - size -= BACKUP_SRC_SIZE; > - } else > - continue; > - } > - > - ret = add_mem_range(mem_ranges, base, size); > - if (ret) > - goto out; > - > - /* Try merging adjacent ranges before reallocation attempt */ > - if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges) > - sort_memory_ranges(*mem_ranges, true); > - } > - > - /* Reallocate memory ranges if there is no space to split ranges */ > - tmem = *mem_ranges; > - if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) { > - tmem = realloc_mem_ranges(mem_ranges); > - if (!tmem) > - goto out; > - } > - > - /* Exclude crashkernel region */ > - ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end); > - if (ret) > - goto out; > - > - /* > - * FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL > - * regions are exported to save their context at the time of > - * crash, they should actually be backed up just like the > - * first 64K bytes of memory. > - */ > - ret = add_rtas_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - ret = add_opal_mem_range(mem_ranges); > - if (ret) > - goto out; > - > - /* create a separate program header for the backup region */ > - ret = add_mem_range(mem_ranges, BACKUP_SRC_START, BACKUP_SRC_SIZE); > - if (ret) > - goto out; > - > - sort_memory_ranges(*mem_ranges, false); > -out: > - if (ret) > - pr_err("Failed to setup crash memory ranges\n"); > - return ret; > -} > - > /** > * check_realloc_usable_mem - Reallocate buffer if it can't accommodate entries > * @um_info: Usable memory buffer and ranges info. > diff --git a/arch/powerpc/kexec/ranges.c b/arch/powerpc/kexec/ranges.c > index fb3e12f15214..297b8bc97b9f 100644 > --- a/arch/powerpc/kexec/ranges.c > +++ b/arch/powerpc/kexec/ranges.c > @@ -20,9 +20,13 @@ > #include > #include > #include > +#include > +#include > #include > #include > +#include > > +#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP) > /** > * get_max_nr_ranges - Get the max no. of ranges crash_mem structure > * could hold, given the size allocated for it. > @@ -234,13 +238,16 @@ int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size) > return __add_mem_range(mem_ranges, base, size); > } > > +#endif /* CONFIG_KEXEC_FILE || CONFIG_CRASH_DUMP */ > + > +#ifdef CONFIG_KEXEC_FILE > /** > * add_tce_mem_ranges - Adds tce-table range to the given memory ranges list. > * @mem_ranges: Range list to add the memory range(s) to. > * > * Returns 0 on success, negative errno on error. > */ > -int add_tce_mem_ranges(struct crash_mem **mem_ranges) > +static int add_tce_mem_ranges(struct crash_mem **mem_ranges) > { > struct device_node *dn = NULL; > int ret = 0; > @@ -279,7 +286,7 @@ int add_tce_mem_ranges(struct crash_mem **mem_ranges) > * > * Returns 0 on success, negative errno on error. > */ > -int add_initrd_mem_range(struct crash_mem **mem_ranges) > +static int add_initrd_mem_range(struct crash_mem **mem_ranges) > { > u64 base, end; > int ret; > @@ -296,7 +303,6 @@ int add_initrd_mem_range(struct crash_mem **mem_ranges) > return ret; > } > > -#ifdef CONFIG_PPC_64S_HASH_MMU > /** > * add_htab_mem_range - Adds htab range to the given memory ranges list, > * if it exists > @@ -304,14 +310,18 @@ int add_initrd_mem_range(struct crash_mem **mem_ranges) > * > * Returns 0 on success, negative errno on error. > */ > -int add_htab_mem_range(struct crash_mem **mem_ranges) > +static int add_htab_mem_range(struct crash_mem **mem_ranges) > { > + > +#ifdef CONFIG_PPC_64S_HASH_MMU > if (!htab_address) > return 0; > > return add_mem_range(mem_ranges, __pa(htab_address), htab_size_bytes); > -} > +#else > + return 0; > #endif > +} > > /** > * add_kernel_mem_range - Adds kernel text region to the given > @@ -320,18 +330,20 @@ int add_htab_mem_range(struct crash_mem **mem_ranges) > * > * Returns 0 on success, negative errno on error. > */ > -int add_kernel_mem_range(struct crash_mem **mem_ranges) > +static int add_kernel_mem_range(struct crash_mem **mem_ranges) > { > return add_mem_range(mem_ranges, 0, __pa(_end)); > } > +#endif /* CONFIG_KEXEC_FILE */ > > +#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP) > /** > * add_rtas_mem_range - Adds RTAS region to the given memory ranges list. > * @mem_ranges: Range list to add the memory range to. > * > * Returns 0 on success, negative errno on error. > */ > -int add_rtas_mem_range(struct crash_mem **mem_ranges) > +static int add_rtas_mem_range(struct crash_mem **mem_ranges) > { > struct device_node *dn; > u32 base, size; > @@ -356,7 +368,7 @@ int add_rtas_mem_range(struct crash_mem **mem_ranges) > * > * Returns 0 on success, negative errno on error. > */ > -int add_opal_mem_range(struct crash_mem **mem_ranges) > +static int add_opal_mem_range(struct crash_mem **mem_ranges) > { > struct device_node *dn; > u64 base, size; > @@ -374,7 +386,9 @@ int add_opal_mem_range(struct crash_mem **mem_ranges) > of_node_put(dn); > return ret; > } > +#endif /* CONFIG_KEXEC_FILE || CONFIG_CRASH_DUMP */ > > +#ifdef CONFIG_KEXEC_FILE > /** > * add_reserved_mem_ranges - Adds "/reserved-ranges" regions exported by f/w > * to the given memory ranges list. > @@ -382,7 +396,7 @@ int add_opal_mem_range(struct crash_mem **mem_ranges) > * > * Returns 0 on success, negative errno on error. > */ > -int add_reserved_mem_ranges(struct crash_mem **mem_ranges) > +static int add_reserved_mem_ranges(struct crash_mem **mem_ranges) > { > int n_mem_addr_cells, n_mem_size_cells, i, len, cells, ret = 0; > const __be32 *prop; > @@ -410,3 +424,198 @@ int add_reserved_mem_ranges(struct crash_mem **mem_ranges) > > return ret; > } > + > +/** > + * get_reserved_memory_ranges - Get reserve memory ranges. This list includes > + * memory regions that should be added to the > + * memory reserve map to ensure the region is > + * protected from any mischief. > + * @mem_ranges: Range list to add the memory ranges to. > + * > + * Returns 0 on success, negative errno on error. > + */ > +int get_reserved_memory_ranges(struct crash_mem **mem_ranges) > +{ > + int ret; > + > + ret = add_rtas_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_tce_mem_ranges(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_reserved_mem_ranges(mem_ranges); > +out: > + if (ret) > + pr_err("Failed to setup reserved memory ranges\n"); > + return ret; > +} > + > +/** > + * get_exclude_memory_ranges - Get exclude memory ranges. This list includes > + * regions like opal/rtas, tce-table, initrd, > + * kernel, htab which should be avoided while > + * setting up kexec load segments. > + * @mem_ranges: Range list to add the memory ranges to. > + * > + * Returns 0 on success, negative errno on error. > + */ > +int get_exclude_memory_ranges(struct crash_mem **mem_ranges) > +{ > + int ret; > + > + ret = add_tce_mem_ranges(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_initrd_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_htab_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_kernel_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_rtas_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_opal_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_reserved_mem_ranges(mem_ranges); > + if (ret) > + goto out; > + > + /* exclude memory ranges should be sorted for easy lookup */ > + sort_memory_ranges(*mem_ranges, true); > +out: > + if (ret) > + pr_err("Failed to setup exclude memory ranges\n"); > + return ret; > +} > + > +#ifdef CONFIG_CRASH_DUMP > +/** > + * get_usable_memory_ranges - Get usable memory ranges. This list includes > + * regions like crashkernel, opal/rtas & tce-table, > + * that kdump kernel could use. > + * @mem_ranges: Range list to add the memory ranges to. > + * > + * Returns 0 on success, negative errno on error. > + */ > +int get_usable_memory_ranges(struct crash_mem **mem_ranges) > +{ > + int ret; > + > + /* > + * Early boot failure observed on guests when low memory (first memory > + * block?) is not added to usable memory. So, add [0, crashk_res.end] > + * instead of [crashk_res.start, crashk_res.end] to workaround it. > + * Also, crashed kernel's memory must be added to reserve map to > + * avoid kdump kernel from using it. > + */ > + ret = add_mem_range(mem_ranges, 0, crashk_res.end + 1); > + if (ret) > + goto out; > + > + ret = add_rtas_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_opal_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_tce_mem_ranges(mem_ranges); > +out: > + if (ret) > + pr_err("Failed to setup usable memory ranges\n"); > + return ret; > +} > +#endif /* CONFIG_CRASH_DUMP */ > +#endif /* CONFIG_KEXEC_FILE */ > + > +#ifdef CONFIG_CRASH_DUMP > +/** > + * get_crash_memory_ranges - Get crash memory ranges. This list includes > + * first/crashing kernel's memory regions that > + * would be exported via an elfcore. > + * @mem_ranges: Range list to add the memory ranges to. > + * > + * Returns 0 on success, negative errno on error. > + */ > +int get_crash_memory_ranges(struct crash_mem **mem_ranges) > +{ > + phys_addr_t base, end; > + struct crash_mem *tmem; > + u64 i; > + int ret; > + > + for_each_mem_range(i, &base, &end) { > + u64 size = end - base; > + > + /* Skip backup memory region, which needs a separate entry */ > + if (base == BACKUP_SRC_START) { > + if (size > BACKUP_SRC_SIZE) { > + base = BACKUP_SRC_END + 1; > + size -= BACKUP_SRC_SIZE; > + } else > + continue; > + } > + > + ret = add_mem_range(mem_ranges, base, size); > + if (ret) > + goto out; > + > + /* Try merging adjacent ranges before reallocation attempt */ > + if ((*mem_ranges)->nr_ranges == (*mem_ranges)->max_nr_ranges) > + sort_memory_ranges(*mem_ranges, true); > + } > + > + /* Reallocate memory ranges if there is no space to split ranges */ > + tmem = *mem_ranges; > + if (tmem && (tmem->nr_ranges == tmem->max_nr_ranges)) { > + tmem = realloc_mem_ranges(mem_ranges); > + if (!tmem) > + goto out; > + } > + > + /* Exclude crashkernel region */ > + ret = crash_exclude_mem_range(tmem, crashk_res.start, crashk_res.end); > + if (ret) > + goto out; > + > + /* > + * FIXME: For now, stay in parity with kexec-tools but if RTAS/OPAL > + * regions are exported to save their context at the time of > + * crash, they should actually be backed up just like the > + * first 64K bytes of memory. > + */ > + ret = add_rtas_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + ret = add_opal_mem_range(mem_ranges); > + if (ret) > + goto out; > + > + /* create a separate program header for the backup region */ > + ret = add_mem_range(mem_ranges, BACKUP_SRC_START, BACKUP_SRC_SIZE); > + if (ret) > + goto out; > + > + sort_memory_ranges(*mem_ranges, false); > +out: > + if (ret) > + pr_err("Failed to setup crash memory ranges\n"); > + return ret; > +} > +#endif /* CONFIG_CRASH_DUMP */