Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp721607pxk; Thu, 1 Oct 2020 12:09:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRh6IzAe38atFxbgGa7Ysdc0QMYD0nAS+UHVitcA2s/twnkDLIbaUj6R+3IWuP7xHPBdkz X-Received: by 2002:a05:6402:3c8:: with SMTP id t8mr9534638edw.266.1601579351750; Thu, 01 Oct 2020 12:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601579351; cv=none; d=google.com; s=arc-20160816; b=IT/cs/ugyrhwS9kbVpUyGdjDYg9dYOHkmzEPEm7BWYn1Qgkx9QoDfbpJY6l9N0XUeF pWarWUIFmNqv6BeeiJeDHmz7v7qV5hkOBnIwSCWsugWaiZ1ojm9UTiCiY0Il3WuMTDmU e4yOaR/FpB5Eq61u6YIINgad0oXmzKyX4M6/7nftrlzB9f1vUvDl1IiylAEHco6dBHvA WS6tgwMVf712UyRR/rTaLGW1IULOyqCOYHRERdSKvZnRaP1NDlP+MCS0hPZjfxLfK3cU LiYc5vZW9T4KjOn6QuKrIdcmcV8d+aq5gw5vkx6uebKXFIblQrMPkNjny6W4fb/6mxdG Spuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:wdcironportexception :ironport-sdr:ironport-sdr:ironport-sdr:dkim-signature; bh=DH6NGsReCIz45Uq0ZLAtdADnM58Evddfvs0nkBSBU3c=; b=hFMZQ6OEzWsB1TJRlsMbFcKLIuO/IkqEgqSZlE5N0K6t5hhOT8pyDOfHuHf5hLBcdo 3Ki0T5EyzfnYmzl47zpxO0rRQxdbYOvp1ghAe/YPN8Nsu3MQ1UIBJzRO63JUBmoufZHM vVXJ+QlXmG+PguXMwUwIG+BnLLB2xXK53lVWqqj74HOIxn00mxreKas5GoJOxQSJZwUb TXIgqsPBC2qwRZ6rOP0lu1x8ja+tjxkVtT1x+jfZQoY4o7hoM1AAz1TT67tFgyYI6Hny PhR4qgouXI2//Vxnl86CJLVxPO0EwJz3H0okeZbsNqpNAyF92MSwY3r+VXyxlURd4oHW aYNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hh4DGE0H; 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 ci27si4752556ejc.373.2020.10.01.12.08.48; Thu, 01 Oct 2020 12:09: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=hh4DGE0H; 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 S1732984AbgJATGJ (ORCPT + 99 others); Thu, 1 Oct 2020 15:06:09 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:19201 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732981AbgJATGI (ORCPT ); Thu, 1 Oct 2020 15:06:08 -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=1601579168; x=1633115168; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ulQnabrQ3jIylqco3wGP6BdFDL6aVGXR3PWdQHcEP2w=; b=hh4DGE0HNqjV+I15ClShmzNjjRZRID9mt9l3uUxIcsFHfC9CR+IuNzIB 1Rjn7Z+pHiRhLzck5CAx2hY+mpI+tXIHOnNvnwliGMJbyYqeLduT3durL QpuCtUp+v42I53TtkVheRK7avPso2czUDyU8na5SMsqoXl7gDbisdOXe9 GrNKAESoxl74yXoVyRIKMoFzQhwPkzAsg7SKBv/yr3TKB1N+DkapNfNW3 RyzlyyHegm07Vm4a7Hfb4HOVoHZh6bXOLyDdFW4hCkX7GeT46WYXGlAmC fRlhwSlHX7nmNRkchw2/i0vah4QCVQhPv4hcBvjkurTUa9a2EunEbD8Ej w==; IronPort-SDR: nRW10HwRqpy34LWFKHb630lU+QeYe4O/8qM8RVYNHlCwFeAVtlOZppVdoXkpneA+13OI5KSfxX s3SFebRGaYIrDxnzQmMWPtwXlVTUmgxbUVoWtE0UKCB0ZdOqLi1O1QXB9SIWpXpWFJfucth+v5 fXcSOdqMMq+nMV8ASeKBra3c/hBo3JuiUFA2DmsxW/Unn3mbbfqcQnFUcDjO4iMtJqTKvm3F2g 7MwqBoImLSgj5aedLvqtSWDI2iDJMHSpcZ+rvIJvP+8TIADj7DVkbkaB0IY4wItvJTvs15QwCH 7uA= X-IronPort-AV: E=Sophos;i="5.77,324,1596470400"; d="scan'208";a="148739978" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 02 Oct 2020 03:06:00 +0800 IronPort-SDR: w1iQ4dMUuLMnOsuu8PwCTrOmadLwkRLA+zrLjj0MatJyH8oFFGWt2xXOoMACmLNtql/iavrhUW j1oJdcPpF3pw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 11:51:57 -0700 IronPort-SDR: mvbPBDuJNTR0nqO9Lt8qZ/T52jy0A+M4P5lzYhD22tEfN/14+jnWpZRem5hTJzK89KUjTP6zXy 4Tdxnni4PDFQ== WDCIronportException: Internal Received: from 30tyk72.ad.shared (HELO jedi-01.hgst.com) ([10.86.59.249]) by uls-op-cesaip02.wdc.com with ESMTP; 01 Oct 2020 12:05:59 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Mike Rapoport , Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Zong Li Subject: [PATCH v3] RISC-V: Remove any memblock representing unusable memory area Date: Thu, 1 Oct 2020 12:05:57 -0700 Message-Id: <20201001190557.2860741-1-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org RISC-V limits the physical memory size by -PAGE_OFFSET. Any memory beyond that size from DRAM start is unusable. Just remove any memblock pointing to those memory region without worrying about computing the maximum size. Signed-off-by: Atish Patra Reviewed-by: Mike Rapoport --- Changes from v2->v3 Updated comment as per Mike's suggestion. --- arch/riscv/mm/init.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index ca03762a3733..564e0be677b7 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -146,8 +146,6 @@ static phys_addr_t dtb_early_pa __initdata; 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); @@ -155,21 +153,18 @@ void __init setup_bootmem(void) /* Find the memory region containing the kernel */ for_each_memblock(memory, reg) { end = reg->base + reg->size; - if (!total_mem) + if (!mem_start) mem_start = reg->base; if (reg->base <= vmlinux_start && vmlinux_end <= end) BUG_ON(reg->size == 0); - total_mem = total_mem + reg->size; } /* - * Remove memblock from the end of usable area to the - * end of region + * The maximal physical memory size is -PAGE_OFFSET. + * Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed + * as it is unusable by kernel. */ - 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); + memblock_enforce_memory_limit(mem_start - PAGE_OFFSET); /* Reserve from the start of the kernel to the end of the kernel */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); -- 2.25.1