Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2346566pxk; Mon, 14 Sep 2020 10:50:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIBGnTeSXVAezzGHL3WbdVJqpD8wXlXplOrdj/cKw0aM5OLSKVAJnQYyXlS/ec8DNZWZ3K X-Received: by 2002:a50:fb0e:: with SMTP id d14mr19144756edq.172.1600105834315; Mon, 14 Sep 2020 10:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600105834; cv=none; d=google.com; s=arc-20160816; b=SzY/aPEfDpsTpwDRRgFn5mVqttRlOJyEXwqy9FCiwBK/AxeN84U7XJenWQoKMT7jxr geq6ruUSHqaZyihY0B/kiuJhPr8pRU7OaAuQ4NGjbY3lmAlm3K4koJJ4UgTlKZRNpGmu eS84b9ZgTpw5AqCMF9vm7KMGA2eSR0H0Pk/OVaGoh03v0bXT7Nnc8AiUMoKS+bwd0VSR kOZLS4pgFB7dZzGG+TnXxaRU53CYTAbKrJkknFb8kO/UBWadudQTa8+1kONc6dXzB2T9 ixDJtJE3tzSd+mN8xE58lYbKkDd2DZ48DxUeAuak6rEHdoIroSkySR8i3Wn1LyZCJx6n lY2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PJ7iJNVDDaND4zplndsbl4Uby21iiMEjNanabMHyNa8=; b=N/hebJdbPfqavDAROEttAOaizmGFH+IPt6zqRHAoMow2dAQXBnnd44S4OuC5RCV9IX b7BuZai61sfct2b3Q+DPex3hS7ymjG4HSMurDrXIdEZOWRQxH/GHFxi5H5qzK1OuajAy VXadbTHnhCMOXK9PsPGIrT5/f8R1jyRjb7Ro5tnQRvTs5YccmeUOQ0UMSpx1Pjuvc2TQ qnxHwXelkIfxDobgGDFf4trpDepSteWTYsuaGfvk1AogDY8hUUnmFwjf/bewAro3/Q8h a/yYpsydxkjaY2qZWrmBikBPtG6cq9PtyNVlWXJoT/i/G/hPdGVaaivZsVSeYAyts9qm 876g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=YalQb9qX; 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 m64si8326464ede.91.2020.09.14.10.50.11; Mon, 14 Sep 2020 10:50:34 -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=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=YalQb9qX; 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 S1725967AbgINRtV (ORCPT + 99 others); Mon, 14 Sep 2020 13:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbgINMDl (ORCPT ); Mon, 14 Sep 2020 08:03:41 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8267CC06174A for ; Mon, 14 Sep 2020 04:52:44 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id y15so10953535wmi.0 for ; Mon, 14 Sep 2020 04:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PJ7iJNVDDaND4zplndsbl4Uby21iiMEjNanabMHyNa8=; b=YalQb9qXnij3jA+z9DcxOA6IfyTifBTo3+5ciDzFu0EX8HtYUQWiH1DfbNzkQ5E4Wg n9tEwxvm65+rVwSYeQMc2Aeh/gYDYfUiZN0Pn1sNa+UWyQH3JerLbfdSWlfaqGboTyxk cx3klAP3OoD3zNPoXyDGb7iQc4jb276bpjW/piZZahi+ZdAaHXAPMRzwePA2V73YOOi8 YeF+3dio/BlVTJ9VLcik8+RQmy+l6AQFnUSvJQzDppohujPTTJT+i8wYKFDzOs/x3aQ4 ZCHX3caFgONUgL5jSFttJNsV5c+i+7BQbP92MTWKyiAK/xiitzOqpv0wjUVqqur0EfGU QroQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PJ7iJNVDDaND4zplndsbl4Uby21iiMEjNanabMHyNa8=; b=UbAh6ajpV5V4bqbF2NQcVVKEut5DSfqiPEzU/cz55bh1rPd5vzLlHZ+EFaIPRWtRTN 3rcnolBjuyJ6XvVkktTHNDn0zAokiAlvOT+NBJHTekA20A+u9SRFKymYPQmGbAN1zZBS dHh+B0vRHPW4bbuexmynrPCnjCPLr0adzEvDl05uZ44TWL5xylJTTzPPXpI0GIKdqz1G OHWbATQEbMVIywNVch410TPHzwHL/t7ruPAvreeCgDk8OacDhuFHpfBzJeywPEmidGFd 5l5vP7YZ9U/xhaf/ALLQ0m8/ICGPxsyPr7EJ+wDb3w5/H1pf8tD2YZ0WPmgZTvgnZIQn Drmw== X-Gm-Message-State: AOAM531gRB6zBS63WAgwCBGqcTLcYKxn/1zReJCu4l1wig/Zz0Gn93df LMNMP0sn2GmB6lycirATB6MkO+5Wa6zehaCeP5makg== X-Received: by 2002:a7b:c0c5:: with SMTP id s5mr14501327wmh.152.1600084362966; Mon, 14 Sep 2020 04:52:42 -0700 (PDT) MIME-Version: 1.0 References: <20200912002341.4869-1-atish.patra@wdc.com> <20200912104502.GF2142832@kernel.org> In-Reply-To: From: Anup Patel Date: Mon, 14 Sep 2020 17:22:31 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: Consider sparse memory while removing unusable memory To: Atish Patra Cc: Mike Rapoport , Anup Patel , Atish Patra , Albert Ou , "linux-kernel@vger.kernel.org List" , Palmer Dabbelt , Zong Li , Paul Walmsley , linux-riscv Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 14, 2020 at 5:18 AM Atish Patra wrote: > > On Sat, Sep 12, 2020 at 3:45 AM Mike Rapoport wrote: > > > > Hello Atish, > > > > On Fri, Sep 11, 2020 at 05:23:41PM -0700, Atish Patra wrote: > > > Currently, any usable memory area beyond page_offset is removed by adding the > > > memory sizes from each memblock. That may not work for sparse memory > > > as memory regions can be very far apart resulting incorrect removal of some > > > usable memory. > > > > If I understand correctly, the memory with physical addresses larger > > than (-PAGE_OFFSET) cannot be used. Since it was aready > > memblock_add()'ed during device tree parsing, you need to remove it from > > memblock. > > > > IIRC, the original intention was to fix MAXPHYSMEM_2GB option for RV64 > for the medlow model. > That's why the patch removed any memory beyond -PAGE_OFFSET. > > > For that you can use memblock_enforce_memory_limit(-PAGE_OFFSET). > > > Thanks. I think we can just call memblock_enforce_memory_limit without > tracking the total memory size > and whether maximum memory described in DT is greater than -PAGE_OFFSET. > > @Anup Patel Was there any other reason for this change originally? No other reason. We just wanted to ensure that amount of memory addressable by kernel (i.e. -PAGE_OFFSET) is also considered when removing memblock. Regards, Anup > > > > Just use the start of the first memory block and the end of the last memory > > > block to compute the size of the total memory that can be used. > > > > > > Signed-off-by: Atish Patra > > > --- > > > arch/riscv/mm/init.c | 6 ++---- > > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > > > index 787c75f751a5..188281fc2816 100644 > > > --- a/arch/riscv/mm/init.c > > > +++ b/arch/riscv/mm/init.c > > > @@ -147,7 +147,6 @@ 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,18 +154,17 @@ 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 > > > */ > > > - mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET); > > > + mem_size = min(end - mem_start, (phys_addr_t)-PAGE_OFFSET); > > > if (mem_start + mem_size < end) > > > memblock_remove(mem_start + mem_size, > > > end - mem_start - mem_size); > > > -- > > > 2.24.0 > > > > > > > -- > > Sincerely yours, > > Mike. > > > > _______________________________________________ > > linux-riscv mailing list > > linux-riscv@lists.infradead.org > > http://lists.infradead.org/mailman/listinfo/linux-riscv > > > > -- > Regards, > Atish