Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2705528ybh; Fri, 24 Jul 2020 22:13:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5CWCIztEPExzvh6NDQJNaQf+W13+Hhwv4LRaUqhm0orrsvvMlm5cssd6eKlDL8uCILU+g X-Received: by 2002:a17:906:3acd:: with SMTP id z13mr12297729ejd.69.1595654036841; Fri, 24 Jul 2020 22:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595654036; cv=none; d=google.com; s=arc-20160816; b=rERX3P87OCeGf1pEkuBoxujf2LcyA7XTCDCVDrsAuY72OyuaTxUomeoNgYgXBDxMZ0 +92Vva4J9W1goeVLlWmN4zbh2P2i9CM24x9qgTgXieN3duE5sj1fybhXX4/z3Yslk5Va uor3Nx499S5i/ANEqBb5TunQswT2AYmFQYnbrvn8Yd7z3UVsUnBkbIGHef6DArhTNXiU Oqm+CXPe1Y+/F2WvJlpjG2BXQGgRmooRlUEJoUUMEYcAqOoPQbXV7tdDBGKEgE9hlrJn qIVmrFEb2MsdwSqmUDKUEIBZ4sDiXUDfbAlpiItenIOghJE0YDv5Ra2x8PoEvwONpvBq +DIg== 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 :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=DrFSqlp6N5hVS2J5LBpv5q3jiLHrhXO1dKkZQLcwDsA=; b=nxD4XwcEAWZ185gbdORe9fym0wzlf2e8zs7mVmM4tRf3A5+RrbFnk0KvYVCpyQRbgr xyMvx12n2JXXWlrxsXZpjCWn1zySL5ro7mpqOu/xILtAuoqEk3zA+mVG2cKS7F1AsCyF xv6bf0KE+I9BlU2Qh7kp9in6/n6el1Fafkvaz6h7atCiNoJrVonZYIkg1ySiw5Y7L6MS LyKn8rSfLiua+qsIFOJMXkJAu7OyxPdJ+qlPjdOB9PPtvVhupVdvVvwwUkmRX13UrLaK zdwWo3LSbGPKz5qrORXFA6aCFF5YSwqkVKeE01GY8OeAhlAS1k7WUCPWubVqfS8gI4j3 Lchw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=ETKHiK8n; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si1887089edt.483.2020.07.24.22.13.34; Fri, 24 Jul 2020 22:13:56 -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=pass header.i=@dabbelt-com.20150623.gappssmtp.com header.s=20150623 header.b=ETKHiK8n; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727087AbgGYFMs (ORCPT + 99 others); Sat, 25 Jul 2020 01:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgGYFMo (ORCPT ); Sat, 25 Jul 2020 01:12:44 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BFBC0619D3 for ; Fri, 24 Jul 2020 22:12:43 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t10so309573plz.10 for ; Fri, 24 Jul 2020 22:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20150623.gappssmtp.com; s=20150623; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=DrFSqlp6N5hVS2J5LBpv5q3jiLHrhXO1dKkZQLcwDsA=; b=ETKHiK8nr+iV+B62aVfQqRgoTi6y+8Nsvrymauknp+n3HnLTwS+VKgHGHraHbeVx4m 0rWCXMn0/E+pyv74rE29/PmaGadbtm1+iCgkOFxW/rfdg5SBLA1Q9yUjg1VbL42DDvtD H07m44nsy9AmpsOQpHrPMlzNxEUizgdmfjGZK3xKPa70ompTgOhdpNSFywA00iHdt6gN FK9QYJ5Rtg+5drnkPizzhIVsPJDXLoUrGee01RRmz5+kKMJCB5n/sWsvCb0XmOpU7iME ACosYF00v1HkwxsZYCaztK5QbANtyoXntqGZg/4COPjOkzMBo0ecF45fubJaq2+gFECi DydQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=DrFSqlp6N5hVS2J5LBpv5q3jiLHrhXO1dKkZQLcwDsA=; b=dHIYpG8kiLiimpdKDgCYOU+wyfwGPvKG/Auzhgh7rrgxVz5IZGFZz2K38Zd9w0Fdr+ aBztLHBKklsbtqobPxAb9XULy+0a+eN4oMAi2R4N14rytYHOUojF3G0mLcF3Y7YnotIF 6ykIcgA9fb7OZBVJtfI4FFT5FXWmpFAjy5yhwhCclou0qqTi2gl7Saem1V0okaBKkhZx 9MRn8crWb2ix9r042dw66n9EjWhm0Adu/YH9oXeutSnPKmZTeKgBJwol3BNONz+OBVid d8tpvSKP9RHikzj+AYoMJOd0ThTAx22G//J+v/SzcgvLry7HEcoXh2zyrJO8DsXddlMT xNlQ== X-Gm-Message-State: AOAM532L79tnuWWJhfwCj2Adz+gcKvBMXef77Dc30Vfls5MOxvs6Ib5B kcHi8OaS4fa/oSSR3URXssnT4SOgYKI= X-Received: by 2002:a17:90a:ce02:: with SMTP id f2mr9091398pju.159.1595653963045; Fri, 24 Jul 2020 22:12:43 -0700 (PDT) Received: from localhost (76-210-143-223.lightspeed.sntcca.sbcglobal.net. [76.210.143.223]) by smtp.gmail.com with ESMTPSA id z2sm7972048pfq.67.2020.07.24.22.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 22:12:42 -0700 (PDT) Date: Fri, 24 Jul 2020 22:12:42 -0700 (PDT) X-Google-Original-Date: Fri, 24 Jul 2020 22:08:22 PDT (-0700) Subject: Re: [PATCH 4/4] riscv: Parse all memory blocks to remove unusable memory In-Reply-To: <20200715233009.27183-5-atish.patra@wdc.com> CC: linux-kernel@vger.kernel.org, Atish Patra , aou@eecs.berkeley.edu, Anup Patel , greentime.hu@sifive.com, linux-riscv@lists.infradead.org, Paul Walmsley , sudeep.holla@arm.com, vincent.chen@sifive.com, zong.li@sifive.com From: Palmer Dabbelt To: Atish Patra Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Jul 2020 16:30:09 PDT (-0700), Atish Patra wrote: > 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); Thanks, this one is also on fixes.