Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp336905ybt; Mon, 6 Jul 2020 10:27:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKEVXvuHELYuvJ9WCl2ZP2b0nxq+u2NAe7n8/CUD8gzS0twki/HfEjX0plwS4P+DxHN/xF X-Received: by 2002:aa7:c606:: with SMTP id h6mr55946244edq.363.1594056460841; Mon, 06 Jul 2020 10:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594056460; cv=none; d=google.com; s=arc-20160816; b=qCnCjUyz52x0fwlQf93GxQXL7iBywS+1PF3rcHq1hO1U9cQJbNve5JUZgi+aGJUUZz 80ibDz1D91ngRWy2bnrJCwExd0NrwVY/IIJ8SZc1Ql7PqqpvSr+6D1bNGB+vy3rG3AY9 1j9Rx6z8ZTwxCtvMLsRa+BkeGEVW0Ll08Y3pr229LW6sdKiygwrAYJuV0H9qICsF2Hp9 d05Xev5w/YMfep4Bk2XLniYcDgGrBAWpcDr6CgbdcJf5FOewhp9WjDJ9M54Th3mhxd1X lB4dU2tJ9AncpRNLwJ5bV23wScpCOONyNhrX7dcdGy08P/A9tMkJ1Z+pvWevaC2Se+4O lHkg== 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 :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=49EdjkCvb380zb7CbF7o50DwXj/Sb5IRqiijJ1TFaAM=; b=hTvaJ4B40TUnUERVSktq0MkP5M1iJvRPRMWlZGMKG324+PUZx8J+Q2QH17NNdWzwQE ByN0swYGTjcriL9l1rBvIcEPl6lNuFEujG9RlcqhykdnjUdGvcCspNqQqVpX9drN5uMY 42nPCx0cF0cA0ge5wAIi0mUgxCyarrrtgPtENjnxJwjNUWBi9P+qCoNLLadl5EzjVytp izFC3oujIeEccgr+nv4d1Vt+vBEHbJxz56KFZlFprsPZaG2EQFuiVM7/pfIT9YgGkWEa NRoeBl1vq/hd9P+Tf274H2cgDpTz5szfOq6FRywjTFFFGQjjVO6pTfVqyEeivWGEf/3+ Nt3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PFGewPP7; 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=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si14594408edx.125.2020.07.06.10.27.18; Mon, 06 Jul 2020 10:27:40 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PFGewPP7; 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=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729786AbgGFR07 (ORCPT + 99 others); Mon, 6 Jul 2020 13:26:59 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:41526 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729720AbgGFR0i (ORCPT ); Mon, 6 Jul 2020 13:26:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1594056424; x=1625592424; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YBy5J4GUHkZ0slWQ+5rpmDzLOi4g2OFkey3S0ni3vEo=; b=PFGewPP7ayoTZyE4jgdS85bAEMPqajiUUT5aqmngXuqhP73K7Lo+dX74 KEDIL+jT0p51kjR0TAacBnO4S5+4HnQai70Nxsr+EFX+pjNeucHDB/HsT TAvnVaT4pJgj4iV30/IjOmpL2zxRID2rHTHDOxGijgsc/6e4Ow0oBs3it jt0/FNsAA+rJS3fpsNZIp25OF6Q4qQaM2AixCZU4SCfX/BRwr0LPKJnq0 RXsaEilvUgsFFhf2fvynABe/ln7fPga7njSduK7XGHC51hWkfOsOTQGmM H2F7Vr/57qWiYyxkpesT9V/zq/FK5wvhmYRbkOdtJ1eHlNCutnEQ0lFc0 g==; IronPort-SDR: BJa7zV3zaBNC/5tE1BxfVhQBAQOPVYz52vGWH1VBP1Fczb+ydz+bnIhioklrvyz3pez2T58Pn4 Ip/7UPOOanVF5EK+GZ77/oJ8p9CZ4ElyMfZ2V4Tx9QBc3Zmrkb/st1cwlc7IY/D21Oasch6G1c 6QZSdywM7JjEzi/lPmwzc5Dhmi3S51Y89WncKaXMGmBFsN8SDsCMBZOsntupnTF2mZuJ8pINm0 0qWXWZsSrgmu4li7EMEE4A7fB5s8m8YSudca4+EYvcQkaGXz+pD0k0n6IxK2WzIPyQz7TEgsIQ G9g= X-IronPort-AV: E=Sophos;i="5.75,320,1589212800"; d="scan'208";a="244770185" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Jul 2020 01:26:54 +0800 IronPort-SDR: 3dWBVWhmKn9GXS7z1KhDUQVzrJ9RDwMH6Yt0WKbEHyx4NSKPLShyCDXJECj23AmqyEZaOkb+d6 q/xEJsc+Sle5rcSVuSZ9WHSGsRqdnEMeE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2020 10:14:40 -0700 IronPort-SDR: VTlm1Z5/SAZEFPfrVJo8CE7qDDYpBSCOWNrJGIMyzYAvnvv9cofETJc83FHruK4hWLEkD67X8x qpNsYOLyOR6A== WDCIronportException: Internal Received: from 6hj08h2.ad.shared (HELO jedi-01.hgst.com) ([10.86.57.161]) by uls-op-cesaip01.wdc.com with ESMTP; 06 Jul 2020 10:26:31 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Ard Biesheuvel , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, Masahiro Yamada , Palmer Dabbelt , Heinrich Schuchardt Subject: [RFC PATCH v2 06/11] riscv: Parse all memory blocks to remove unusable memory Date: Mon, 6 Jul 2020 10:26:04 -0700 Message-Id: <20200706172609.25965-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200706172609.25965-1-atish.patra@wdc.com> References: <20200706172609.25965-1-atish.patra@wdc.com> 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 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 --- 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 4021706aef81..c5268fe6e6de 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -123,26 +123,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.24.0