From mboxrd@z Thu Jan 1 00:00:00 1970 From: Baoquan He Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Date: Wed, 5 Aug 2020 12:20:24 +0800 Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+glpr-linux-riscv=m.gmane-mx.org@lists.infradead.org To: Mike Rapoport Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michael Ellerman , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , ucli List-Id: linux-arch.vger.kernel.org On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F57AC433E1 for ; Wed, 5 Aug 2020 04:20:45 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E4AF42177B for ; Wed, 5 Aug 2020 04:20:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E4AF42177B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 9FC08204FE; Wed, 5 Aug 2020 04:20:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id coveoc3saD0h; Wed, 5 Aug 2020 04:20:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 525AE204F8; Wed, 5 Aug 2020 04:20:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 38794C0050; Wed, 5 Aug 2020 04:20:42 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 48B22C004C for ; Wed, 5 Aug 2020 04:20:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3053185EF1 for ; Wed, 5 Aug 2020 04:20:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2zkUYSJLdWiF for ; Wed, 5 Aug 2020 04:20:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 3643785E95 for ; Wed, 5 Aug 2020 04:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pdUQtGUaN4iDPq52ne80Vw-1; Wed, 05 Aug 2020 00:20:34 -0400 X-MC-Unique: pdUQtGUaN4iDPq52ne80Vw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B26651009600; Wed, 5 Aug 2020 04:20:29 +0000 (UTC) Received: from localhost (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C71071765; Wed, 5 Aug 2020 04:20:27 +0000 (UTC) Date: Wed, 5 Aug 2020 12:20:24 +0800 From: Baoquan He To: Mike Rapoport Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michael Ellerman , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , uclinux-h8-devel@lists.sourceforge.jp, linux-xtensa@linux-xtensa.org, openrisc@lists.librecores.org, Borislav Petkov , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Hari Bathini , Michal Simek , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Palmer Dabbelt , Andrew Morton , Christoph Hellwig X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC50DC433E1 for ; Wed, 5 Aug 2020 04:20:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DB1E22CA0 for ; Wed, 5 Aug 2020 04:20:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725920AbgHEEUj (ORCPT ); Wed, 5 Aug 2020 00:20:39 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23271 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbgHEEUj (ORCPT ); Wed, 5 Aug 2020 00:20:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pdUQtGUaN4iDPq52ne80Vw-1; Wed, 05 Aug 2020 00:20:34 -0400 X-MC-Unique: pdUQtGUaN4iDPq52ne80Vw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B26651009600; Wed, 5 Aug 2020 04:20:29 +0000 (UTC) Received: from localhost (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C71071765; Wed, 5 Aug 2020 04:20:27 +0000 (UTC) Date: Wed, 5 Aug 2020 12:20:24 +0800 From: Baoquan He To: Mike Rapoport Cc: Andrew Morton , Andy Lutomirski , 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 , 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: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B71EC433DF for ; Wed, 5 Aug 2020 04:20:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C34C2177B for ; Wed, 5 Aug 2020 04:20:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IyUqzCza"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C34C2177B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=F2gYIRBZjNLsR43qpQj1ePDzjUFFSgCkqv1DMeCTy5Y=; b=IyUqzCzaiymzKJV7K/rCdXNxu GdeDklQPcJStggM7O3fsht1dz9B5Pu0q4DXpe4CBokZJTksAYQfZrh7GQX6OugwTe69pXeH7CuTs9 5WxSL8ekYHBTdWIeyUB57/tRcA0aojJlcIc4egEoRVkKeEhWVpzGryVyd8I0YjuGpHuYRK5TDwLiw I0sL6iaq6mFp88sgP/X3QXx1xuTwWa15jde5LK3XG1QJ5SKnKdVpWKLQZraGUdwoamq9HPTYO3s9m gx2xiT0fXkSABkf8AKxAQ4GUL7MjgVgNdyGBR/CdPhyEuKAgZqS9B0A/OpLJ/migVYvO3A1ggAtVQ 4d4BIuIbQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Auv-0006uM-Eb; Wed, 05 Aug 2020 04:20:41 +0000 Received: from us-smtp-1.mimecast.com ([205.139.110.61]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Aus-0006t0-AK for linux-riscv@lists.infradead.org; Wed, 05 Aug 2020 04:20:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pdUQtGUaN4iDPq52ne80Vw-1; Wed, 05 Aug 2020 00:20:34 -0400 X-MC-Unique: pdUQtGUaN4iDPq52ne80Vw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B26651009600; Wed, 5 Aug 2020 04:20:29 +0000 (UTC) Received: from localhost (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C71071765; Wed, 5 Aug 2020 04:20:27 +0000 (UTC) Date: Wed, 5 Aug 2020 12:20:24 +0800 From: Baoquan He To: Mike Rapoport Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200805_002038_484752_8A9A057F X-CRM114-Status: GOOD ( 26.19 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michael Ellerman , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , uclinux-h8-devel@lists.sourceforge.jp, linux-xtensa@linux-xtensa.org, openrisc@lists.librecores.org, Borislav Petkov , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Hari Bathini , Michal Simek , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Palmer Dabbelt , Andrew Morton , Christoph Hellwig Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 From: Baoquan He Date: Wed, 05 Aug 2020 04:20:24 +0000 Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-Id: <20200805042024.GT10792@MiWiFi-R3L-srv> List-Id: References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Mike Rapoport Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michael Ellerman , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , ucli On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Baoquan He Date: Wed, 5 Aug 2020 12:20:24 +0800 Subject: [OpenRISC] [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: openrisc@lists.librecores.org On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE027C433DF for ; Wed, 5 Aug 2020 04:22:46 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 28EB32177B for ; Wed, 5 Aug 2020 04:22:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28EB32177B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4BLz4N10y6zDqfJ for ; Wed, 5 Aug 2020 14:22:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=205.139.110.61; helo=us-smtp-1.mimecast.com; envelope-from=bhe@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RhB7tJrW; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RhB7tJrW; dkim-atps=neutral Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4BLz206zJ6zDqPF for ; Wed, 5 Aug 2020 14:20:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pdUQtGUaN4iDPq52ne80Vw-1; Wed, 05 Aug 2020 00:20:34 -0400 X-MC-Unique: pdUQtGUaN4iDPq52ne80Vw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B26651009600; Wed, 5 Aug 2020 04:20:29 +0000 (UTC) Received: from localhost (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C71071765; Wed, 5 Aug 2020 04:20:27 +0000 (UTC) Date: Wed, 5 Aug 2020 12:20:24 +0800 From: Baoquan He To: Mike Rapoport Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , uclinux-h8-devel@lists.sourceforge.jp, linux-xtensa@linux-xtensa.org, openrisc@lists.librecores.org, Borislav Petkov , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Hari Bathini , Michal Simek , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Palmer Dabbelt , Andrew Morton , Christoph Hellwig Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2628C433E0 for ; Wed, 5 Aug 2020 04:22:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C56F92177B for ; Wed, 5 Aug 2020 04:22:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZWhmOyaL"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhB7tJrW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C56F92177B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BuZ/lgz5cUsl4RCwvWmsqKYhsSPPb4A0YlQFfuB81s8=; b=ZWhmOyaLGPgDhrOAvWhrTEFEK geLYmHaC0lJ2UjczldLv0KzyZLx1OVqwWmtQ1LaDuTjz2A3l+rhaVyZbbi88zeQkPBhNiXl6PDEa3 6nbgxUeB8iZ336VPaGntRQGbIkO9+bFc923vaMAbelipRaY1t0isk0JZJRecNNkYfgkO3jRS4Puwh 1VFjYtvppB1mH2SoG/c6kvcXHkJbKtB6AwQaMMYMGtcfnRqMehDIfj2sSHWnnahwq2e3DfgiCddVQ iJuxsDq4k6hVcoF7MyAmYrRxpzyGnlA+IanZJiadvDSuIdWcRdNbdPwyMcNXc+K3I+0KQwqDcHnMN P++1a16Uw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Auw-0006uX-E5; Wed, 05 Aug 2020 04:20:42 +0000 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Aus-0006t1-AL for linux-arm-kernel@lists.infradead.org; Wed, 05 Aug 2020 04:20:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596601237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=twertatwzUrM7ldiTnLyq8dIY3NouOKQbE23vgZibYc=; b=RhB7tJrWsV46yFoehAYmxLRKZCWlHdsxIYJKxQV1BjXImPnPGbcPU6V368xtzPpT8l+y2N KOIzb3ETxq+JUYWFHDfnWn7ZFyX7kyfYNAjP/tGJCSGm5VxuDZQnRtGjoaDq+EoKLy2dTo aEXBlqjVykf8BUIRQmUAnBKVDoaGdv8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-14-pdUQtGUaN4iDPq52ne80Vw-1; Wed, 05 Aug 2020 00:20:34 -0400 X-MC-Unique: pdUQtGUaN4iDPq52ne80Vw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B26651009600; Wed, 5 Aug 2020 04:20:29 +0000 (UTC) Received: from localhost (ovpn-12-71.pek2.redhat.com [10.72.12.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C71071765; Wed, 5 Aug 2020 04:20:27 +0000 (UTC) Date: Wed, 5 Aug 2020 12:20:24 +0800 From: Baoquan He To: Mike Rapoport Subject: Re: [PATCH v2 13/17] x86/setup: simplify initrd relocation and reservation Message-ID: <20200805042024.GT10792@MiWiFi-R3L-srv> References: <20200802163601.8189-1-rppt@kernel.org> <20200802163601.8189-14-rppt@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200802163601.8189-14-rppt@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200805_002038_503503_A2120D2E X-CRM114-Status: GOOD ( 27.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emil Renner Berthing , linux-sh@vger.kernel.org, Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , linux-mips@vger.kernel.org, Max Filippov , Paul Mackerras , sparclinux@vger.kernel.org, linux-riscv@lists.infradead.org, Will Deacon , Stafford Horne , Marek Szyprowski , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Michael Ellerman , x86@kernel.org, Russell King , Mike Rapoport , clang-built-linux@googlegroups.com, Ingo Molnar , linux-arm-kernel@lists.infradead.org, Catalin Marinas , uclinux-h8-devel@lists.sourceforge.jp, linux-xtensa@linux-xtensa.org, openrisc@lists.librecores.org, Borislav Petkov , Andy Lutomirski , Paul Walmsley , Thomas Gleixner , Hari Bathini , Michal Simek , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Palmer Dabbelt , Andrew Morton , Christoph Hellwig Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 08/02/20 at 07:35pm, Mike Rapoport wrote: > 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 ~ then? > 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); Reviewed-by: Baoquan He > - > printk(KERN_INFO "RAMDISK: [mem %#010llx-%#010llx]\n", ramdisk_image, > ramdisk_end - 1); > > -- > 2.26.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel