Message ID | 20230527123439.772-6-thunder.leizhen@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp307725vqr; Sat, 27 May 2023 05:38:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4n8yq5SbUIorcSGuquySyi7hWcBGvt6IFADQyM/IIJfRYMNd++YKux9XTbaBNqZ8qN3NKw X-Received: by 2002:a05:6a20:12cc:b0:110:2593:9ccd with SMTP id v12-20020a056a2012cc00b0011025939ccdmr3181749pzg.21.1685191080443; Sat, 27 May 2023 05:38:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685191080; cv=none; d=google.com; s=arc-20160816; b=iRYPEuIwA3o/RliUcZ26/LFjI/Bd2fTKApP6Ie4PtAkX5NLLmHdITXkTFEHZkHrMg/ sXbPzN5rZtXs0WDiwsm7/kFZmDKMIC6JYt2p03hPyNd9MfQKwoXpxqTjICBjyFlA7aad gLufB8p329N75C+UPdMLCI2yEf3MhHyZeMt8YT6cwkkv+FQV5AUWNKVqsLlF6dRhYhXb d8n5v/soNa74hiXZrBEpvdXJqj6ZJxfvSa/tl0HxAhdbopij15zWtoDqjLaftmjddPiD LIPbuTSgx7gXnEllGybpi27bjbsvaGBa7ChP+JVExvMKSZM5l1boMjUpSnuqUxaLbMzx XvlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+gDnxaV+5+GkqAOMdlNMPdtP7Nf9lUt0cZzl6Qup9ps=; b=DHJ3D4ATYNN2P3wYzk+2ST/SoK6Em6KLzSqqKYT0tiYOKPS9AMnVLrzOZWWtViUrJm qY91miPBqiKpgcXYcv5vxQzNJYVhyCxi5JSskHIMZzzIQdTFQ03C6BlfthvnZUaupuRf g7ionhNCGa42jbpEeCRnFpMcNI/yR/K7xZEu+a6QIC6z/TkWRjogObRv0c+IV8HhA2EF uH0ov3df32aSmhuh9NwfhyXH4+3wfkNCW5bkNOZVhtS06mDPGog5r11ZX73JrZuzKhMz LY3voHuoEluAvsh0ya0V46tcmN8+RepEtvz7+BQAZz6uPYUtFwA/VH4qRMjB6amh0BFv QLAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q62-20020a632a41000000b005137bf7e2d4si6313134pgq.652.2023.05.27.05.37.45; Sat, 27 May 2023 05:38:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232599AbjE0MgV (ORCPT <rfc822;zhanglyra.2023@gmail.com> + 99 others); Sat, 27 May 2023 08:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232254AbjE0MgL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 27 May 2023 08:36:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D279013A for <linux-kernel@vger.kernel.org>; Sat, 27 May 2023 05:35:51 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QT1Qr2ln2zLpvQ; Sat, 27 May 2023 20:32:52 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sat, 27 May 2023 20:35:49 +0800 From: Zhen Lei <thunder.leizhen@huawei.com> To: Eric Biederman <ebiederm@xmission.com>, Baoquan He <bhe@redhat.com>, <kexec@lists.infradead.org>, <linux-kernel@vger.kernel.org> CC: Zhen Lei <thunder.leizhen@huawei.com>, Michael Holzheu <holzheu@linux.vnet.ibm.com>, Andrew Morton <akpm@linux-foundation.org>, Amerigo Wang <amwang@redhat.com> Subject: [PATCH 5/6] kexec: add helper __crash_shrink_memory() Date: Sat, 27 May 2023 20:34:38 +0800 Message-ID: <20230527123439.772-6-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.37.3.windows.1 In-Reply-To: <20230527123439.772-1-thunder.leizhen@huawei.com> References: <20230527123439.772-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767050922347968600?= X-GMAIL-MSGID: =?utf-8?q?1767050922347968600?= |
Series |
kexec: enable kexec_crash_size to support two crash kernel regions
|
|
Commit Message
Zhen Lei
May 27, 2023, 12:34 p.m. UTC
No functional change, in preparation for the next patch so that it is
easier to review.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
kernel/kexec_core.c | 50 +++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 22 deletions(-)
Comments
Hi Zhen, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.4-rc3 next-20230525] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230527123439.772-6-thunder.leizhen%40huawei.com patch subject: [PATCH 5/6] kexec: add helper __crash_shrink_memory() config: riscv-randconfig-r042-20230526 (https://download.01.org/0day-ci/archive/20230528/202305280717.Pw06aLkz-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 4faf3aaf28226a4e950c103a14f6fc1d1fdabb1b) reproduce (this is a W=1 build): mkdir -p ~/bin wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install riscv cross compiling tool for clang build # apt-get install binutils-riscv64-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/dea97cef503d26e05d0e11818ae44176056ddf64 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 git checkout dea97cef503d26e05d0e11818ae44176056ddf64 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202305280717.Pw06aLkz-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/kexec_core.c:1108:5: warning: no previous prototype for function '__crash_shrink_memory' [-Wmissing-prototypes] int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) ^ kernel/kexec_core.c:1108:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) ^ static 1 warning generated. vim +/__crash_shrink_memory +1108 kernel/kexec_core.c 1107 > 1108 int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) 1109 { 1110 struct resource *ram_res; 1111 1112 ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); 1113 if (!ram_res) 1114 return -ENOMEM; 1115 1116 ram_res->start = old_res->start + new_size; 1117 ram_res->end = old_res->end; 1118 ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; 1119 ram_res->name = "System RAM"; 1120 1121 if (!new_size) { 1122 release_resource(old_res); 1123 old_res->start = 0; 1124 old_res->end = 0; 1125 } else { 1126 crashk_res.end = ram_res->start - 1; 1127 } 1128 1129 crash_free_reserved_phys_range(ram_res->start, ram_res->end); 1130 insert_resource(&iomem_resource, ram_res); 1131 1132 return 0; 1133 } 1134
Hi Zhen, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master v6.4-rc3 next-20230525] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230527123439.772-6-thunder.leizhen%40huawei.com patch subject: [PATCH 5/6] kexec: add helper __crash_shrink_memory() config: mips-randconfig-r012-20230528 (https://download.01.org/0day-ci/archive/20230528/202305280949.yYtbjy5B-lkp@intel.com/config) compiler: mipsel-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): mkdir -p ~/bin wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/dea97cef503d26e05d0e11818ae44176056ddf64 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 git checkout dea97cef503d26e05d0e11818ae44176056ddf64 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202305280949.yYtbjy5B-lkp@intel.com/ All warnings (new ones prefixed by >>): >> kernel/kexec_core.c:1108:5: warning: no previous prototype for '__crash_shrink_memory' [-Wmissing-prototypes] 1108 | int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) | ^~~~~~~~~~~~~~~~~~~~~ vim +/__crash_shrink_memory +1108 kernel/kexec_core.c 1107 > 1108 int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) 1109 { 1110 struct resource *ram_res; 1111 1112 ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); 1113 if (!ram_res) 1114 return -ENOMEM; 1115 1116 ram_res->start = old_res->start + new_size; 1117 ram_res->end = old_res->end; 1118 ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; 1119 ram_res->name = "System RAM"; 1120 1121 if (!new_size) { 1122 release_resource(old_res); 1123 old_res->start = 0; 1124 old_res->end = 0; 1125 } else { 1126 crashk_res.end = ram_res->start - 1; 1127 } 1128 1129 crash_free_reserved_phys_range(ram_res->start, ram_res->end); 1130 insert_resource(&iomem_resource, ram_res); 1131 1132 return 0; 1133 } 1134
Hi Zhen,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.4-rc3 next-20230525]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20230527123439.772-6-thunder.leizhen%40huawei.com
patch subject: [PATCH 5/6] kexec: add helper __crash_shrink_memory()
config: x86_64-randconfig-s033-20230528 (https://download.01.org/0day-ci/archive/20230528/202305281410.FdGZvhsb-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.4-39-gce1a6720-dirty
# https://github.com/intel-lab-lkp/linux/commit/dea97cef503d26e05d0e11818ae44176056ddf64
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821
git checkout dea97cef503d26e05d0e11818ae44176056ddf64
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 olddefconfig
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202305281410.FdGZvhsb-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> kernel/kexec_core.c:1108:5: sparse: sparse: symbol '__crash_shrink_memory' was not declared. Should it be static?
On 2023/5/28 8:08, kernel test robot wrote: > Hi Zhen, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on akpm-mm/mm-everything] > [also build test WARNING on linus/master v6.4-rc3 next-20230525] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 > base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything > patch link: https://lore.kernel.org/r/20230527123439.772-6-thunder.leizhen%40huawei.com > patch subject: [PATCH 5/6] kexec: add helper __crash_shrink_memory() > config: riscv-randconfig-r042-20230526 (https://download.01.org/0day-ci/archive/20230528/202305280717.Pw06aLkz-lkp@intel.com/config) > compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 4faf3aaf28226a4e950c103a14f6fc1d1fdabb1b) > reproduce (this is a W=1 build): > mkdir -p ~/bin > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # install riscv cross compiling tool for clang build > # apt-get install binutils-riscv64-linux-gnu > # https://github.com/intel-lab-lkp/linux/commit/dea97cef503d26e05d0e11818ae44176056ddf64 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review Zhen-Lei/kexec-fix-a-memory-leak-in-crash_shrink_memory/20230527-203821 > git checkout dea97cef503d26e05d0e11818ae44176056ddf64 > # save the config file > mkdir build_dir && cp config build_dir/.config > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv olddefconfig > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang ~/bin/make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash > > If you fix the issue, kindly add following tag where applicable > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202305280717.Pw06aLkz-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > >>> kernel/kexec_core.c:1108:5: warning: no previous prototype for function '__crash_shrink_memory' [-Wmissing-prototypes] > int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) > ^ > kernel/kexec_core.c:1108:1: note: declare 'static' if the function is not intended to be used outside of this translation unit > int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) > ^ > static > 1 warning generated. Yes, thanks, a 'static' should be added. > > > vim +/__crash_shrink_memory +1108 kernel/kexec_core.c > > 1107 >> 1108 int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) > 1109 { > 1110 struct resource *ram_res; > 1111 > 1112 ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); > 1113 if (!ram_res) > 1114 return -ENOMEM; > 1115 > 1116 ram_res->start = old_res->start + new_size; > 1117 ram_res->end = old_res->end; > 1118 ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; > 1119 ram_res->name = "System RAM"; > 1120 > 1121 if (!new_size) { > 1122 release_resource(old_res); > 1123 old_res->start = 0; > 1124 old_res->end = 0; > 1125 } else { > 1126 crashk_res.end = ram_res->start - 1; > 1127 } > 1128 > 1129 crash_free_reserved_phys_range(ram_res->start, ram_res->end); > 1130 insert_resource(&iomem_resource, ram_res); > 1131 > 1132 return 0; > 1133 } > 1134 >
On 05/27/23 at 08:34pm, Zhen Lei wrote: > No functional change, in preparation for the next patch so that it is > easier to review. > > Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> > --- > kernel/kexec_core.c | 50 +++++++++++++++++++++++++-------------------- > 1 file changed, 28 insertions(+), 22 deletions(-) > > diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c > index 69fe92141b0b62d..e82bc6d6634136a 100644 > --- a/kernel/kexec_core.c > +++ b/kernel/kexec_core.c > @@ -1105,11 +1105,37 @@ ssize_t crash_get_memory_size(void) > return size; > } > > +int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) Other than the missing static, looks good, Acked-by: Baoquan He <bhe@redhat.com> > +{ > + struct resource *ram_res; > + > + ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); > + if (!ram_res) > + return -ENOMEM; > + > + ram_res->start = old_res->start + new_size; > + ram_res->end = old_res->end; > + ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; > + ram_res->name = "System RAM"; > + > + if (!new_size) { > + release_resource(old_res); > + old_res->start = 0; > + old_res->end = 0; > + } else { > + crashk_res.end = ram_res->start - 1; > + } > + > + crash_free_reserved_phys_range(ram_res->start, ram_res->end); > + insert_resource(&iomem_resource, ram_res); > + > + return 0; > +} > + > int crash_shrink_memory(unsigned long new_size) > { > int ret = 0; > unsigned long old_size; > - struct resource *ram_res; > > if (!kexec_trylock()) > return -EBUSY; > @@ -1125,27 +1151,7 @@ int crash_shrink_memory(unsigned long new_size) > goto unlock; > } > > - ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); > - if (!ram_res) { > - ret = -ENOMEM; > - goto unlock; > - } > - > - ram_res->start = crashk_res.start + new_size; > - ram_res->end = crashk_res.end; > - ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; > - ram_res->name = "System RAM"; > - > - if (!new_size) { > - release_resource(&crashk_res); > - crashk_res.start = 0; > - crashk_res.end = 0; > - } else { > - crashk_res.end = ram_res->start - 1; > - } > - > - crash_free_reserved_phys_range(ram_res->start, ram_res->end); > - insert_resource(&iomem_resource, ram_res); > + ret = __crash_shrink_memory(&crashk_res, new_size); > > unlock: > kexec_unlock(); > -- > 2.25.1 >
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index 69fe92141b0b62d..e82bc6d6634136a 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1105,11 +1105,37 @@ ssize_t crash_get_memory_size(void) return size; } +int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) +{ + struct resource *ram_res; + + ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); + if (!ram_res) + return -ENOMEM; + + ram_res->start = old_res->start + new_size; + ram_res->end = old_res->end; + ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; + ram_res->name = "System RAM"; + + if (!new_size) { + release_resource(old_res); + old_res->start = 0; + old_res->end = 0; + } else { + crashk_res.end = ram_res->start - 1; + } + + crash_free_reserved_phys_range(ram_res->start, ram_res->end); + insert_resource(&iomem_resource, ram_res); + + return 0; +} + int crash_shrink_memory(unsigned long new_size) { int ret = 0; unsigned long old_size; - struct resource *ram_res; if (!kexec_trylock()) return -EBUSY; @@ -1125,27 +1151,7 @@ int crash_shrink_memory(unsigned long new_size) goto unlock; } - ram_res = kzalloc(sizeof(*ram_res), GFP_KERNEL); - if (!ram_res) { - ret = -ENOMEM; - goto unlock; - } - - ram_res->start = crashk_res.start + new_size; - ram_res->end = crashk_res.end; - ram_res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; - ram_res->name = "System RAM"; - - if (!new_size) { - release_resource(&crashk_res); - crashk_res.start = 0; - crashk_res.end = 0; - } else { - crashk_res.end = ram_res->start - 1; - } - - crash_free_reserved_phys_range(ram_res->start, ram_res->end); - insert_resource(&iomem_resource, ram_res); + ret = __crash_shrink_memory(&crashk_res, new_size); unlock: kexec_unlock();