Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp762222rwd; Sat, 27 May 2023 06:10:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OexXo/AKxa6Q9nsH5/BeIg2AlwMfJ8DiMOPanplrzq4FFw/T0RvulG9gStp1yAAAURSU6 X-Received: by 2002:a05:6a00:1488:b0:64d:2ea4:937a with SMTP id v8-20020a056a00148800b0064d2ea4937amr8294667pfu.7.1685193017593; Sat, 27 May 2023 06:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685193017; cv=none; d=google.com; s=arc-20160816; b=VSVLHiRmw5eQG3wTpomsqPQ3+kyW2VnABCI2ylX3IThYbGkmDpPI8K7TAmQSBzRR4i Fx1nx7gD89H1hHUCqi+hg9gtsffxgP8OlPULTFY76cl1JEiSJf2yUZcfR+wDpFqPFRka a0UhHAud4VRMNMiiNmGlKCjXjUuz+TzrAGXAERFUoQKCwqqwYMw5yrVimoicZbU23wKm 0Cw9b0KTMfWiYshLVPkF86CNMKARj0wil6LfVzW3H4AVeXa9ZJp6cV8QjWzPLE3vSTLR cXjVMgIz5zbQvLOa2lOI+HFDVYmBYvIzotDOf82Thb0GQ0Hu8SsPm5J7nO8ZAWqbrI3y 7Vhg== 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=zoZDW8j78Zltgn1TT57fuVmEGjU4SumTDXXKeLqj1PY=; b=th5ExD+6eiXPRdRmuBjEh4DzyhUydeDouofJwdWFSvnNUxGH59Fea9RSF/6ZIuSgtG VQKFZ3eaQCZYgtBRC2hzQj75TUpqW3w0gsKtjQqqJ8FfKpfDhlqWKCMlTXD2RZYJa322 KUA5I5m5baNzv2q4UDxHiPqZPwZjoxBL2zqNZkaHhtklKp2jDINKk1RBi5ZZKkQfB6Fl sHMzuBP2bxXyJEMgURF0rt/cBDl/BL+DIRemvpCp3AQ0p9RoG0CXjZbFIvq15nrCKhov WdB9WTDVdJqWNyHVqZpc6cF4YhXlaLgHcUsp710dd+4r9lxnDIDVAvIMMcsgUREl0sbR NxDA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a633850000000b0053477896e81si6029742pgn.187.2023.05.27.06.10.04; Sat, 27 May 2023 06:10:17 -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 S232624AbjE0Mg1 (ORCPT + 99 others); Sat, 27 May 2023 08:36:27 -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: 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: X-Mailing-List: linux-kernel@vger.kernel.org The major adjustments are: 1. end = 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 == end)' with 'if (!new_size)', clear indication that all crashk memory will be shrunken. No functional change. Signed-off-by: Zhen Lei --- 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 = 0; - unsigned long start, end; unsigned long old_size; struct resource *ram_res; @@ -1119,9 +1118,7 @@ int crash_shrink_memory(unsigned long new_size) ret = -ENOENT; goto unlock; } - start = crashk_res.start; - end = crashk_res.end; - old_size = (end == 0) ? 0 : end - start + 1; + old_size = !crashk_res.end ? 0 : resource_size(&crashk_res); new_size = roundup(new_size, KEXEC_CRASH_MEM_ALIGN); if (new_size >= old_size) { ret = (new_size == old_size) ? 0 : -EINVAL; @@ -1134,22 +1131,20 @@ int crash_shrink_memory(unsigned long new_size) goto unlock; } - end = start + new_size; - crash_free_reserved_phys_range(end, crashk_res.end); - - ram_res->start = end; + 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 (start == end) { + if (!new_size) { release_resource(&crashk_res); crashk_res.start = 0; crashk_res.end = 0; } else { - crashk_res.end = end - 1; + crashk_res.end = ram_res->start - 1; } + crash_free_reserved_phys_range(ram_res->start, ram_res->end); insert_resource(&iomem_resource, ram_res); unlock: -- 2.25.1