From nobody Mon Feb 9 17:35:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8B01C77B7C for ; Sat, 27 May 2023 12:36:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbjE0MgW (ORCPT ); Sat, 27 May 2023 08:36:22 -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 ); 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 ; 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 To: Eric Biederman , Baoquan He , , CC: Zhen Lei , Michael Holzheu , Andrew Morton , Amerigo Wang 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: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" No functional change, in preparation for the next patch so that it is easier to review. Signed-off-by: Zhen Lei Acked-by: Baoquan He --- 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; } =20 +int __crash_shrink_memory(struct resource *old_res, unsigned long new_size) +{ + struct resource *ram_res; + + ram_res =3D kzalloc(sizeof(*ram_res), GFP_KERNEL); + if (!ram_res) + return -ENOMEM; + + ram_res->start =3D old_res->start + new_size; + ram_res->end =3D old_res->end; + ram_res->flags =3D IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; + ram_res->name =3D "System RAM"; + + if (!new_size) { + release_resource(old_res); + old_res->start =3D 0; + old_res->end =3D 0; + } else { + crashk_res.end =3D 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 =3D 0; unsigned long old_size; - struct resource *ram_res; =20 if (!kexec_trylock()) return -EBUSY; @@ -1125,27 +1151,7 @@ int crash_shrink_memory(unsigned long new_size) goto unlock; } =20 - ram_res =3D kzalloc(sizeof(*ram_res), GFP_KERNEL); - if (!ram_res) { - ret =3D -ENOMEM; - goto unlock; - } - - ram_res->start =3D crashk_res.start + new_size; - ram_res->end =3D crashk_res.end; - ram_res->flags =3D IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; - ram_res->name =3D "System RAM"; - - if (!new_size) { - release_resource(&crashk_res); - crashk_res.start =3D 0; - crashk_res.end =3D 0; - } else { - crashk_res.end =3D ram_res->start - 1; - } - - crash_free_reserved_phys_range(ram_res->start, ram_res->end); - insert_resource(&iomem_resource, ram_res); + ret =3D __crash_shrink_memory(&crashk_res, new_size); =20 unlock: kexec_unlock(); --=20 2.25.1