Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1497781pxa; Sun, 2 Aug 2020 09:39:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY3lCAdmdZAsyUOuMOhJPnpS+SKlZTRcl8RTKzVF8klbAFbup9D8mBGHHJHDsjYhvCxAzI X-Received: by 2002:a05:6402:17f7:: with SMTP id t23mr12484162edy.301.1596386378394; Sun, 02 Aug 2020 09:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596386378; cv=none; d=google.com; s=arc-20160816; b=1H8pebptqIPuChaABPUmjD22Abq7NaxlI/pT+1wRVu4PRRG1CrbM5nM6oehtbQ0sJn CofX/Q2RIAIoYAR1JigQF948q90hhB4EoD5NBkCpCX7Quz1f8GaUF9gG9HDN0hmxot7e kXmMFzRVo47gdsBa1gm0baeHvHRot3Ei+abqpXRQ2LkOy9btJo3YnbUkT8GwVNptYXR5 O9VsY73GTRYZYOV9A9HQ/j/W5hvdQNUlmsctDHj6Y80v8i4kfFmMwafU/d+l4tGdX7Q4 /pbJsqn8DXOnGBEOzsGNg7skzFObZU7zMvWvZVyVMev1H1GvfZ2sBXIomi7YarcZCcyF ST4Q== 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=Wu8MKRa/f//09WHB2jjh5NjApKjrv6YPTayXBr79zH0=; b=fE9d4/BtdsN8YC78qbn5XQnUBg1DmaZs2cRu7zvdDqSVXbbuGQKSlLDmD4hu64s4lE t8nAEZPPqfOXT0p0SIVX+dO6A/uPJjMzt97WXqgGtSn5ByH6n0EcN/VUteMl2zAAgxKs boGUod9qzfUT+g5t/3BYg0xybx+B68f8xZvFUfIeWQcPCZ6i/dSLf8C9aIMqgyYLUd91 mrD6QfTMrsTYf6fS384Hr4MGIt8zBwNOu9nyCg2nYF9gX1lrsbqjI2RvqOV6IyiX8syQ lkkhKGquW7sAz1zdeXNjWRSZMAR/RKwe7UuFvWNja1+6qvwkbFMbGMf3LRcEv6WFFLxc OlKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QgzlknYs; 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 a18si4237373ejr.184.2020.08.02.09.39.16; Sun, 02 Aug 2020 09:39:38 -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=QgzlknYs; 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 S1727888AbgHBQik (ORCPT + 99 others); Sun, 2 Aug 2020 12:38:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:48470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgHBQij (ORCPT ); Sun, 2 Aug 2020 12:38:39 -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 D797220759; Sun, 2 Aug 2020 16:38:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596386318; bh=o8aZbB2pKDQsqUqKMBDH2F8svHn12mD34Nb+72y2BZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QgzlknYsb9NiWB8c/Yeh/cISQPrZRFom46AMdT7FrT79j0mzUH6ggsWMbDZWlX4P8 UyQ3srMeb9iG6KtyQNKoy0bv4eQadT2brjYzvyX1yGh7qES1VdDGGb7RMSiDH9JBdG DZDhRIfp4FkpXhluwKfMBKUj7+OCDBbjLlDEZLbY= 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 13/17] x86/setup: simplify initrd relocation and reservation Date: Sun, 2 Aug 2020 19:35:57 +0300 Message-Id: <20200802163601.8189-14-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 Currently, initrd image is reserved very early during setup and then it might be relocated and re-reserved after the initial physical memory mapping is created. The "late" reservation of memblock verifies that mapped memory size exceeds the size of initrd, the checks whether the relocation required and, if yes, relocates inirtd to a new memory allocated from memblock and frees the old location. The check for memory size is excessive as memblock allocation will anyway fail if there is not enough memory. Besides, there is no point to allocate memory from memblock using memblock_find_in_range() + memblock_reserve() when there exists memblock_phys_alloc_range() with required functionality. Remove the redundant check and simplify memblock allocation. Signed-off-by: Mike Rapoport --- arch/x86/kernel/setup.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index a3767e74c758..d8de4053c5e8 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -262,16 +262,12 @@ static void __init relocate_initrd(void) u64 area_size = PAGE_ALIGN(ramdisk_size); /* We need to move the initrd down into directly mapped mem */ - relocated_ramdisk = memblock_find_in_range(0, PFN_PHYS(max_pfn_mapped), - area_size, PAGE_SIZE); - + relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0, + PFN_PHYS(max_pfn_mapped)); if (!relocated_ramdisk) panic("Cannot find place for new RAMDISK of size %lld\n", ramdisk_size); - /* Note: this includes all the mem currently occupied by - the initrd, we rely on that fact to keep the data intact. */ - memblock_reserve(relocated_ramdisk, area_size); initrd_start = relocated_ramdisk + PAGE_OFFSET; initrd_end = initrd_start + ramdisk_size; printk(KERN_INFO "Allocated new RAMDISK: [mem %#010llx-%#010llx]\n", @@ -298,13 +294,13 @@ static void __init early_reserve_initrd(void) memblock_reserve(ramdisk_image, ramdisk_end - ramdisk_image); } + static void __init reserve_initrd(void) { /* Assume only end is not page aligned */ u64 ramdisk_image = get_ramdisk_image(); u64 ramdisk_size = get_ramdisk_size(); u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size); - u64 mapped_size; if (!boot_params.hdr.type_of_loader || !ramdisk_image || !ramdisk_size) @@ -312,12 +308,6 @@ static void __init reserve_initrd(void) initrd_start = 0; - mapped_size = memblock_mem_size(max_pfn_mapped); - if (ramdisk_size >= (mapped_size>>1)) - panic("initrd too large to handle, " - "disabling initrd (%lld needed, %lld available)\n", - ramdisk_size, mapped_size>>1); - printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, ramdisk_end - 1); -- 2.26.2