From patchwork Tue Apr 23 22:47:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 10913809 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F77414DB for ; Tue, 23 Apr 2019 22:50:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00D31288A6 for ; Tue, 23 Apr 2019 22:50:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8CE5289A3; Tue, 23 Apr 2019 22:50:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C95288A6 for ; Tue, 23 Apr 2019 22:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728603AbfDWWtc (ORCPT ); Tue, 23 Apr 2019 18:49:32 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:40414 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728350AbfDWWta (ORCPT ); Tue, 23 Apr 2019 18:49:30 -0400 Received: by mail-lj1-f195.google.com with SMTP id q66so14984975ljq.7; Tue, 23 Apr 2019 15:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kL5scIjwN0bnNKZh/MvkqfH0S+/rftNhOfsf9udhKXo=; b=RL7nJj2AP0HIjtqrrU7fZT1SPPW3Q7aOlP+LazRT5TRh7JlanscVoo3IB8u1my4em0 3wHtkzlNbjMCiZ/ROm9mg2ShF/y+1S/UdZzCD66KhP5V9aKJ6DyZP+LPJZVrzy7UHTrd 3qBdEQFqteAoeefh4HtRRW91SMHlshy4Up23Zi891elRwf2sfU6gqFu/NVfFfdBVe0N/ 24olgUFdAofsNaO2cg4ZqeTewGCp/PHoN0eieY0W1CiskXLfi9/zF3pCZO/ieiwxRr+u FGD83jHs+iQvA64j3I4QajnwaC/B88ZJqV2XedGoN9TndOARXHGFMe5tN5nBVHwmNaYM 3Idg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kL5scIjwN0bnNKZh/MvkqfH0S+/rftNhOfsf9udhKXo=; b=n/lc6o+y4wQ5EiE6SaAWhxxUKM4CcTGbhV1GJsYe8TC0V9bZM43ce2+b/QUT2ppEP6 qoil68389EhgvWMNC8Zste4H7B79+xviqHMZF0VC/0CkMtDLNBXypMoxuTTUY4Of7NiI Itdwm/wfmML1z22XWSlwGN9pf3MUKjKh9CAQqAckZ6fB2pbTi0bIIuKt56jS2nBcHMJO sCVqG9hmP1lBsIHlJ72yzoI/ti2XtlNJbnhzGkmp96/528Od91GRTvkfvKRgrBJej/fk pFlIjE6/6/TaiFX96/bhb7XhfLLhyOcJ497i79oY3NTyVjxQw3B4xAReaTlsj/3+AZUK Smww== X-Gm-Message-State: APjAAAVJvBHtZEN5Qdj3a4KxqOdHbJBFl0gKx7nQJkr8V5w3a2tvXZ6C 4o94xggEAD8mK8GTn7N09Cg= X-Google-Smtp-Source: APXvYqyHxLB2YUcQTKUlMkatOsiRjG5aj7qenaEg42Q+Vt1Mc0MuOkVgotaJK5cYFdfXlOG5eCNVTw== X-Received: by 2002:a2e:93d0:: with SMTP id p16mr14767084ljh.197.1556059768630; Tue, 23 Apr 2019 15:49:28 -0700 (PDT) Received: from localhost.localdomain ([5.164.240.123]) by smtp.gmail.com with ESMTPSA id w2sm4904722lfa.63.2019.04.23.15.49.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 15:49:27 -0700 (PDT) From: Serge Semin To: Ralf Baechle , Paul Burton , James Hogan , Matt Redfearn , Mike Rapoport , Andrew Morton , Michal Hocko , Greg Kroah-Hartman , Thomas Bogendoerfer , Huacai Chen , Stefan Agner , Stephen Rothwell , Alexandre Belloni , Juergen Gross Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Serge Semin Subject: [PATCH 04/12] mips: Reserve memory for the kernel image resources Date: Wed, 24 Apr 2019 01:47:40 +0300 Message-Id: <20190423224748.3765-5-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423224748.3765-1-fancer.lancer@gmail.com> References: <20190423224748.3765-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The reserved_end variable had been used by the bootmem_init() code to find a lowest limit of memory available for memmap blob. The original code just tried to find a free memory space higher than kernel was placed. This limitation seems justified for the memmap ragion search process, but I can't see any obvious reason to reserve the unused space below kernel seeing some platforms place it much higher than standard 1MB. Moreover the RELOCATION config enables it to be loaded at any memory address. So lets reserve the memory occupied by the kernel only, leaving the region below being free for allocations. After doing this we can now discard the code freeing a space between kernel _text and VMLINUX_LOAD_ADDRESS symbols since it's going to be free anyway (unless marked as reserved by platforms). Signed-off-by: Serge Semin --- arch/mips/kernel/setup.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 185e0e42e009..f71a7d32a687 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -371,7 +371,6 @@ static void __init bootmem_init(void) static void __init bootmem_init(void) { - unsigned long reserved_end; phys_addr_t ramstart = PHYS_ADDR_MAX; int i; @@ -382,10 +381,10 @@ static void __init bootmem_init(void) * will reserve the area used for the initrd. */ init_initrd(); - reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end)); - memblock_reserve(PHYS_OFFSET, - (reserved_end << PAGE_SHIFT) - PHYS_OFFSET); + /* Reserve memory occupied by kernel. */ + memblock_reserve(__pa_symbol(&_text), + __pa_symbol(&_end) - __pa_symbol(&_text)); /* * max_low_pfn is not a number of pages. The number of pages @@ -501,29 +500,6 @@ static void __init bootmem_init(void) memory_present(0, start, end); } -#ifdef CONFIG_RELOCATABLE - /* - * The kernel reserves all memory below its _end symbol as bootmem, - * but the kernel may now be at a much higher address. The memory - * between the original and new locations may be returned to the system. - */ - if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) { - unsigned long offset; - extern void show_kernel_relocation(const char *level); - - offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS); - memblock_free(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset); - -#if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO) - /* - * This information is necessary when debugging the kernel - * But is a security vulnerability otherwise! - */ - show_kernel_relocation(KERN_INFO); -#endif - } -#endif - /* * Reserve initrd memory if needed. */