Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1497823pxa; Sun, 2 Aug 2020 09:39:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkrLyjYC1LcOTqzWKt1riXDdFECLd1Hpo0CvkBBr+N/JGbFnSGJvuBr60WAHUrLkFcCjdF X-Received: by 2002:a17:906:3cc:: with SMTP id c12mr12534219eja.222.1596386383826; Sun, 02 Aug 2020 09:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596386383; cv=none; d=google.com; s=arc-20160816; b=k3N24+G69HoBL/esDnurgG3SmxHwwkvPbneGd4xKusJ9TM9vXNSwAtKGYsalV0y+ga hPvxEtT0k2tgZO9yomL9x2yk1GbLD7a1mw2aX5/DKXVfa0w3WWRJu8AedjPKlfp1BnSR xUtjN927Wyyy/Y/nGj4o/PQggOq6kfUanHbHYJul0K+6f/MuFXg0N/Rvw/cT5lcxkhTV JY/vkU1w0RtIwAYCboiu+haGqPRfcYH1COSYTFOm9EOau+VHf0yBkWf8aWZW00TIQDdM PTg3Iop/VtmzjMxlXeesFmz0BZ6i5/KXLoHwmyIjjaAia3iSBIbttnHCMMr/sEu/7w8c vEZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7fsGtuNSzDIPFW7rJp3izB7BdpJmbfxMkLlwxxnZMyA=; b=JTQNQuyhhPPE4iClS4WIFGWU7npNXB9Jxi15MOcPoE+tV1L4nHhkoOZUyJE8y2awQe tZyRoFrQN8WPfilKVg6gs6HRI0YxS0ZXF3gKsEXCcTHY3iCT3xSn5XikzJokcQCRTbPj L50RXr8yWM4xhECJka8dqvG1a+8OdM5qhobOfWYO4jykORwTdYlaBDPLiXgcmRNGHgnw lK+K7pO6y8tTbQP67TpLaEWap5hbtwHbbgdNb4dz6Mv8r59gpMqmbvvEBijFMBHOfUit Y0dmjXuHKimB2oC5bhwYh4JD2R++5h9BvRWQ1q/iADoIOaMNNwkb0pfWCJzfXbdyPlAP sI5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rad8TiDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox17si8745286ejb.241.2020.08.02.09.39.22; Sun, 02 Aug 2020 09:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rad8TiDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727897AbgHBQiu (ORCPT + 99 others); Sun, 2 Aug 2020 12:38:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:48720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgHBQit (ORCPT ); Sun, 2 Aug 2020 12:38:49 -0400 Received: from aquarius.haifa.ibm.com (nesher1.haifa.il.ibm.com [195.110.40.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B572220829; Sun, 2 Aug 2020 16:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596386329; bh=owq9p+k/C9/dpSukqR8EwL4hnjKsMj+76UiJMdPJ/fA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rad8TiDptD9dxrBr88aLuHRAT2BqJnMfW2NRDjy71NJ6blsuHzH1615u85QXsH4wj E16+uJggojjz9XGF2WAQ9EoCro0yddSG/vgRc632ePGXFN2VBqVIRyZVPfPYidDOrb SMLSTJg8sBnzC+58NQK2lydD29xR2vaGVr/X5nGA= From: Mike Rapoport To: Andrew Morton Cc: Andy Lutomirski , Baoquan He , Benjamin Herrenschmidt , Borislav Petkov , Catalin Marinas , Christoph Hellwig , Dave Hansen , Emil Renner Berthing , Ingo Molnar , Hari Bathini , Marek Szyprowski , Max Filippov , Michael Ellerman , Michal Simek , Mike Rapoport , Mike Rapoport , Palmer Dabbelt , Paul Mackerras , Paul Walmsley , Peter Zijlstra , Russell King , Stafford Horne , Thomas Gleixner , Will Deacon , Yoshinori Sato , clang-built-linux@googlegroups.com, iommu@lists.linux-foundation.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-c6x-dev@linux-c6x.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, linuxppc-dev@lists.ozlabs.org, openrisc@lists.librecores.org, sparclinux@vger.kernel.org, uclinux-h8-devel@lists.sourceforge.jp, x86@kernel.org Subject: [PATCH v2 14/17] x86/setup: simplify reserve_crashkernel() Date: Sun, 2 Aug 2020 19:35:58 +0300 Message-Id: <20200802163601.8189-15-rppt@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200802163601.8189-1-rppt@kernel.org> References: <20200802163601.8189-1-rppt@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Rapoport * Replace magic numbers with defines * Replace memblock_find_in_range() + memblock_reserve() with memblock_phys_alloc_range() * Stop checking for low memory size in reserve_crashkernel_low(). The allocation from limited range will anyway fail if there is no enough memory, so there is no need for extra traversal of memblock.memory Signed-off-by: Mike Rapoport --- arch/x86/kernel/setup.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index d8de4053c5e8..d7ced6982524 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -419,13 +419,13 @@ static int __init reserve_crashkernel_low(void) { #ifdef CONFIG_X86_64 unsigned long long base, low_base = 0, low_size = 0; - unsigned long total_low_mem; + unsigned long low_mem_limit; int ret; - total_low_mem = memblock_mem_size(1UL << (32 - PAGE_SHIFT)); + low_mem_limit = min(memblock_phys_mem_size(), CRASH_ADDR_LOW_MAX); /* crashkernel=Y,low */ - ret = parse_crashkernel_low(boot_command_line, total_low_mem, &low_size, &base); + ret = parse_crashkernel_low(boot_command_line, low_mem_limit, &low_size, &base); if (ret) { /* * two parts from kernel/dma/swiotlb.c: @@ -443,23 +443,17 @@ static int __init reserve_crashkernel_low(void) return 0; } - low_base = memblock_find_in_range(0, 1ULL << 32, low_size, CRASH_ALIGN); + low_base = memblock_phys_alloc_range(low_size, CRASH_ALIGN, 0, CRASH_ADDR_LOW_MAX); if (!low_base) { pr_err("Cannot reserve %ldMB crashkernel low memory, please try smaller size.\n", (unsigned long)(low_size >> 20)); return -ENOMEM; } - ret = memblock_reserve(low_base, low_size); - if (ret) { - pr_err("%s: Error reserving crashkernel low memblock.\n", __func__); - return ret; - } - - pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (System low RAM: %ldMB)\n", + pr_info("Reserving %ldMB of low memory at %ldMB for crashkernel (low RAM limit: %ldMB)\n", (unsigned long)(low_size >> 20), (unsigned long)(low_base >> 20), - (unsigned long)(total_low_mem >> 20)); + (unsigned long)(low_mem_limit >> 20)); crashk_low_res.start = low_base; crashk_low_res.end = low_base + low_size - 1; @@ -503,13 +497,13 @@ static void __init reserve_crashkernel(void) * unless "crashkernel=size[KMG],high" is specified. */ if (!high) - crash_base = memblock_find_in_range(CRASH_ALIGN, - CRASH_ADDR_LOW_MAX, - crash_size, CRASH_ALIGN); + crash_base = memblock_phys_alloc_range(crash_size, + CRASH_ALIGN, CRASH_ALIGN, + CRASH_ADDR_LOW_MAX); if (!crash_base) - crash_base = memblock_find_in_range(CRASH_ALIGN, - CRASH_ADDR_HIGH_MAX, - crash_size, CRASH_ALIGN); + crash_base = memblock_phys_alloc_range(crash_size, + CRASH_ALIGN, CRASH_ALIGN, + CRASH_ADDR_HIGH_MAX); if (!crash_base) { pr_info("crashkernel reservation failed - No suitable area found.\n"); return; @@ -517,19 +511,13 @@ static void __init reserve_crashkernel(void) } else { unsigned long long start; - start = memblock_find_in_range(crash_base, - crash_base + crash_size, - crash_size, 1 << 20); + start = memblock_phys_alloc_range(crash_size, SZ_1M, crash_base, + crash_base + crash_size); if (start != crash_base) { pr_info("crashkernel reservation failed - memory is in use.\n"); return; } } - ret = memblock_reserve(crash_base, crash_size); - if (ret) { - pr_err("%s: Error reserving crashkernel memblock.\n", __func__); - return; - } if (crash_base >= (1ULL << 32) && reserve_crashkernel_low()) { memblock_free(crash_base, crash_size); -- 2.26.2