From nobody Mon Feb 9 16:16:52 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 28606C77B7E for ; Sat, 27 May 2023 12:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232658AbjE0Mg2 (ORCPT ); Sat, 27 May 2023 08:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232557AbjE0MgM (ORCPT ); Sat, 27 May 2023 08:36:12 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AE29124 for ; Sat, 27 May 2023 05:35:52 -0700 (PDT) Received: from dggpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QT1Nz25QszqScm; Sat, 27 May 2023 20:31:15 +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:48 +0800 From: Zhen Lei To: Eric Biederman , Baoquan He , , CC: Zhen Lei , Michael Holzheu , Andrew Morton , Amerigo Wang Subject: [PATCH 4/6] kexec: improve the readability of crash_shrink_memory() Date: Sat, 27 May 2023 20:34:37 +0800 Message-ID: <20230527123439.772-5-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" The major adjustments are: 1. end =3D start + new_size. The 'end' here is not an accurate representation, because it is not the new end of crashk_res, but the start of ram_res, difference 1. So eliminate it and replace it with ram_res->start. 2. Use 'ram_res->start' and 'ram_res->end' as arguments to crash_free_reserved_phys_range() to indicate that the memory covered by 'ram_res' is released from the crashk. And keep it close to insert_resource(). 3. Replace 'if (start =3D=3D end)' with 'if (!new_size)', clear indication = that all crashk memory will be shrunken. No functional change. Signed-off-by: Zhen Lei Acked-by: Baoquan He --- kernel/kexec_core.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c index bcc86a250ab3bf9..69fe92141b0b62d 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -1108,7 +1108,6 @@ ssize_t crash_get_memory_size(void) int crash_shrink_memory(unsigned long new_size) { int ret =3D 0; - unsigned long start, end; unsigned long old_size; struct resource *ram_res; =20 @@ -1119,9 +1118,7 @@ int crash_shrink_memory(unsigned long new_size) ret =3D -ENOENT; goto unlock; } - start =3D crashk_res.start; - end =3D crashk_res.end; - old_size =3D (end =3D=3D 0) ? 0 : end - start + 1; + old_size =3D !crashk_res.end ? 0 : resource_size(&crashk_res); new_size =3D roundup(new_size, KEXEC_CRASH_MEM_ALIGN); if (new_size >=3D old_size) { ret =3D (new_size =3D=3D old_size) ? 0 : -EINVAL; @@ -1134,22 +1131,20 @@ int crash_shrink_memory(unsigned long new_size) goto unlock; } =20 - end =3D start + new_size; - crash_free_reserved_phys_range(end, crashk_res.end); - - ram_res->start =3D end; + 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"; =20 - if (start =3D=3D end) { + if (!new_size) { release_resource(&crashk_res); crashk_res.start =3D 0; crashk_res.end =3D 0; } else { - crashk_res.end =3D end - 1; + crashk_res.end =3D ram_res->start - 1; } =20 + crash_free_reserved_phys_range(ram_res->start, ram_res->end); insert_resource(&iomem_resource, ram_res); =20 unlock: --=20 2.25.1