Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp817127ybh; Wed, 15 Jul 2020 16:34:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGZfEJfZcVtWAKAfDMDl3mnA2pIPmGpgF/y3wc3c0VfWIuUywLDeGnib3LZUt9qQG+vsIY X-Received: by 2002:a05:6402:1b0e:: with SMTP id by14mr1867959edb.266.1594856051519; Wed, 15 Jul 2020 16:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594856051; cv=none; d=google.com; s=arc-20160816; b=w8eLCwC8lBjoxQ0q81yT/hNFBzXWm2Z/vacT0azfWv1UQ12FJJUsaSAh9Z7CFCWJGk 4OpXrxvKaKHuW3rxpW04dcH/fQGNkO9ftblxWFKZ8giMHLrxRJYJ6LIcSnRCsxmQXIYv TaogS2/8KcW6P8FM+bSFT/eKewgeMxOUA0aNEhE5MGM+muYP0mee3acfZvn/eVW8376U vdX2cfZzfLSmJXjtk1gvkbjCTe02yTV38fT3vakS84HIT6Ng7+WNlZYIvxjOcXj66P+H 6gR2tO/pUMlv9paDxzoU2UHGP0R84ub0+7XhRKT/cT5iEUib1JaawzZ6DIPxizjsYxdv otcA== 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=QaX3hRDJfN5dV2FYOByb1FllyzI/FnYTILiNLc9Poes=; b=Mz8nvEOi02Ex9FqWpjMd6MuRfEFhZlMiuTdK7jQdsaHb42uk0GBxbPM+MYzYzt6Vcm SNotDSgqteZUhvnbgiQDScl8oiGpv+oKILOW3aeZ5qSjJMowmX2GVnkDDWtOLEJVOPY/ CTHsAkygFFxhmayAkMEuVP+6LblehXRBzsj3PXqYem1v4CjXhUGTSCEkz+LL+PmEwcLW Q3R+lAdEk8Bvr7uMc1NGnnsD1HoDYCt2n2Ks9cEjrZHQh9juTLzh1sTilsoD/YYSyYvt HCMSPkmcb0S3w5qIUGqko9Etc2EMug6YZIQigdsMb5jtH3NBpIceiPwBvwa26oS/OHRC 5SWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TsPBifbo; 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 g16si2104626ejo.232.2020.07.15.16.33.48; Wed, 15 Jul 2020 16:34:11 -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=TsPBifbo; 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 S1727086AbgGOXae (ORCPT + 99 others); Wed, 15 Jul 2020 19:30:34 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:49850 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbgGOXae (ORCPT ); Wed, 15 Jul 2020 19:30:34 -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=1594855834; x=1626391834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1WUJsuuWe1ZBua62bFIdOijTgWGShB9OAlNDVmWfFmY=; b=TsPBifboiuVFCCuQ4BhaQF8e9Y9VJxJX1Yem1CL9I6hQt5Mbya3yK4Al eXgL9xTA0mqltFMzsyZaY7jLCqg3kOZT69qTWGo7GcLO4q5/LPTr3iHZC JWIUIyFuRlIr5UQvJp+Lw3EAnHmFDJAF7JD+kJ4ROS5Eg3ZkDFe9RWVwU aNg3CtgIULZCV/aZ369FzYo68OQLUsxUmCu+GCYxyj9brzJ/pbU1nmM4A me+2JyD+JANzpWCkDIShmwlbkH31VRT+umPWsqTP2KUG/iT1q8x5F4Obg 0HgHKnf7/x1cLvEqdR1ScMACS1SNyUabYBpmfNCq6vH1xgNmLft9pYFt9 w==; IronPort-SDR: VRG942NGLmNjMASHaJzkBluPVMBpTqhtym6MtWUapENhFBtqCh+SZU378lH49vFH/Y6XXU1iMV af27qBOz7aHpnfvqPVs/7O8MTCVxemGSmJMx3DeP2/sm9Rq6zq9G3jlJwZhnpLmliRbKfGxCoG TwbCX0p90u0aLJOIVvdmLTRJNnkF+fLccf6VP0tZghpOBjhKGvu4FKYq0vw/r//eKDW/tb4GYv gf6CRKrIdZpVLsqy+XGOZnapxw7UO/AcPqZMlPxCgHlVgGkwlqed7s6KB0bbjGu2CgkTqwBxZA 7Ow= X-IronPort-AV: E=Sophos;i="5.75,357,1589212800"; d="scan'208";a="146868544" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 Jul 2020 07:30:23 +0800 IronPort-SDR: 23mcAq4JMdd+m6NbmF+zNTphh6dgWPkayNMYKsaVJZQmfp0VecHPvIMRxPoWnWL2KcWH5zFsO6 x4yMDcC9NlHxpxJW3S45q/fJkxqKvbRMk= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 16:18:48 -0700 IronPort-SDR: jolcTqH56Kqn7iIi8sFylTtgUKK7/Idjrhr2qok3aASAzRD1+74v7auysvNA/+tadSVs44nyYc W3zYMoqRAm7g== WDCIronportException: Internal Received: from cnf009656.ad.shared (HELO jedi-01.hgst.com) ([10.86.58.5]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Jul 2020 16:30:21 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Anup Patel , Greentime Hu , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Sudeep Holla , Vincent Chen , Zong Li Subject: [PATCH 4/4] riscv: Parse all memory blocks to remove unusable memory Date: Wed, 15 Jul 2020 16:30:09 -0700 Message-Id: <20200715233009.27183-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200715233009.27183-1-atish.patra@wdc.com> References: <20200715233009.27183-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 f818a47a72d1..79e9d55bdf1a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -147,26 +147,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