Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp733795rwd; Sat, 27 May 2023 05:47:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pisMctT6cWJB7gpCkkmUwrOk07NCA+fX8Du99jTNvx7drw/ihMj/ijFVZ2GtMlACxmgVQ X-Received: by 2002:a05:6a21:32a8:b0:10b:ca02:1a5e with SMTP id yt40-20020a056a2132a800b0010bca021a5emr2848180pzb.55.1685191637350; Sat, 27 May 2023 05:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685191637; cv=none; d=google.com; s=arc-20160816; b=YHfijQKKQYoaSYp+6I9IRN4meu8S29OEG1XhbYVX7OZbaiuevtbimN52kBoqOX4wHQ jCfjK4cCoAKUoZ8NxUa5y9czcSROGhpfB0rPpIqyv1cnWc51omsCeOFb7g1oRNUf936N SrdcrxYRe7O5wCIzYBf+VpLs4D84JIv7L9vdjye17cQbbzgMgiA9m4mYr4BjtFnNe/O/ IoNhJWQShefjyVjf2fc5cUDiaAJr7Y25fYn/rILW2DSJddMZoLibFxWvpyUj0GVpYABx eiCeDaYl5CPq2gYO17sL/Bgy/XIdN3g5qfYnlp1sJLsNmi5ca5MWiTb0Ra3EAaxMhUph AL1Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p2-20020a637402000000b0053efcd2001dsi6026165pgc.422.2023.05.27.05.47.02; Sat, 27 May 2023 05:47: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 S232598AbjE0MgV (ORCPT + 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 ); 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: 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 No functional change, in preparation for the next patch so that it is easier to review. Signed-off-by: Zhen Lei --- 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) +{ + 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