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=-13.0 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,USER_AGENT_GIT autolearn=ham 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 A5A1BC433E0 for ; Mon, 3 Aug 2020 12:26:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 853FD204EC for ; Mon, 3 Aug 2020 12:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457575; bh=f5pWZnTXWdMeH/r/P/ygyxFUvVXk7VoBwu1GlAY/Sms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iawxUunHhXQpc5BD4KavYPD7ckzzo9Ynss4Qteti9t+xJMSVQFZLa3Y2gxA9Mh4as Zl35S8T7kj4rzB4OQKb/hAMcYLnLvhlUj7BSQ8S6Rb+b5Kbh/MbP0UJzmPJms4BrLa etKQeBqm7nnPkHI2cIlbXmpCZAhfvQ4n+JX6puM8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbgHCM0P (ORCPT ); Mon, 3 Aug 2020 08:26:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:51430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728324AbgHCM0O (ORCPT ); Mon, 3 Aug 2020 08:26:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A5D4207DF; Mon, 3 Aug 2020 12:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457572; bh=f5pWZnTXWdMeH/r/P/ygyxFUvVXk7VoBwu1GlAY/Sms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vqTLOlzT5axqMTXb2L7NpVvNMba8LbJ1h5zYrO/AquN5vEtRwyl2pvOT1P1eE/L6a QxUFVTI8xrggToIZqGvtuEFtoyChmoK2b6fO2RmwRrtRG2XTu0L72kerOuqkWQJKT2 8kwqOuqCMoK7PF97ijd1IruMe+aJK69FbA6LkqBk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Atish Patra , Palmer Dabbelt , Sasha Levin Subject: [PATCH 5.7 116/120] riscv: Parse all memory blocks to remove unusable memory Date: Mon, 3 Aug 2020 14:19:34 +0200 Message-Id: <20200803121908.549697771@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121902.860751811@linuxfoundation.org> References: <20200803121902.860751811@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Atish Patra [ Upstream commit fa5a198359053c8e21dcc2b39c0e13871059bc9f ] Currently, maximum physical memory allowed is equal to -PAGE_OFFSET. That's why we remove any memory blocks spanning beyond that size. However, it is done only for memblock containing linux kernel which will not work if there are multiple memblocks. Process all memory blocks to figure out how much memory needs to be removed and remove at the end instead of updating the memblock list in place. Signed-off-by: Atish Patra Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/mm/init.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index af8926777567f..115fb9245f160 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -146,26 +146,29 @@ void __init setup_bootmem(void) { struct memblock_region *reg; phys_addr_t mem_size = 0; + phys_addr_t total_mem = 0; + phys_addr_t mem_start, end = 0; phys_addr_t vmlinux_end = __pa_symbol(&_end); phys_addr_t vmlinux_start = __pa_symbol(&_start); /* Find the memory region containing the kernel */ for_each_memblock(memory, reg) { - phys_addr_t end = reg->base + reg->size; - - if (reg->base <= vmlinux_start && vmlinux_end <= end) { - mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET); - - /* - * Remove memblock from the end of usable area to the - * end of region - */ - if (reg->base + mem_size < end) - memblock_remove(reg->base + mem_size, - end - reg->base - mem_size); - } + end = reg->base + reg->size; + if (!total_mem) + mem_start = reg->base; + if (reg->base <= vmlinux_start && vmlinux_end <= end) + BUG_ON(reg->size == 0); + total_mem = total_mem + reg->size; } - BUG_ON(mem_size == 0); + + /* + * Remove memblock from the end of usable area to the + * end of region + */ + mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET); + if (mem_start + mem_size < end) + memblock_remove(mem_start + mem_size, + end - mem_start - mem_size); /* Reserve from the start of the kernel to the end of the kernel */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); -- 2.25.1