From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D6E8C43461 for ; Mon, 14 Sep 2020 17:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5910A214F1 for ; Mon, 14 Sep 2020 17:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=atishpatra.org header.i=@atishpatra.org header.b="LSYBezCb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726110AbgINRxc (ORCPT ); Mon, 14 Sep 2020 13:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725997AbgINRxO (ORCPT ); Mon, 14 Sep 2020 13:53:14 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AACBBC06174A for ; Mon, 14 Sep 2020 10:53:13 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id q9so879219wmj.2 for ; Mon, 14 Sep 2020 10:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZKhv5rTCRwwZYJ4fJZiFA0QJHdmQ369d7Ye56iqS39I=; b=LSYBezCbF3qD2J1/hnvedLtI3NNJxjkCI3H7K3OpFvBX9JZU0AhCfLK8/EptPQIA1x AzWCI/TnXymeOP930uBLk0o6wdCrYsuqj1ik1lCEEVx3QSZI4XJkHJ61lRT4e5wbGq9z hlCIWs01gU+mS+7JoC9yORjrjQkPCTlgo2oho= 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=ZKhv5rTCRwwZYJ4fJZiFA0QJHdmQ369d7Ye56iqS39I=; b=oq4lbHsgm8cq32u/wZF0v0a/mBn9LxvDebQi31+ZU0HLvs9y0SlWaf6xpVk4t+XvwR SKa8YTMtgsQIANud7tP8AmGMzPN1wv2eiNp0GOjaIhYKnU1MLMlv3iJTmJ12VDv3DsPF DvC/TF2yVhKGSOwsZtLBHIx7q1pCdfGyMQA8szECEkGfgKNn8cIYmMdr9INpbSEtxFlH ZjENjzBG0oiPQiqdbzxip/imXEhB9FYZfuHp/ORKKx4DGArUHRsbnvyHvpLrQcZM7C4s PyBAhhvn49VVm3QXy9mdxMuywzmTR0fC/nREPTH2z1MGtGnu+LP4dma2+ve2qB9HVKeg fD3Q== X-Gm-Message-State: AOAM531ctUZ46Hv8FnTKc6tD2t8BmWgmtY5iWFN7PMrjlo2xJSket+jy 9EkGlcNKf3zCmWi3kN2vOhj9ekXpXSYU+HV9IGp+ X-Google-Smtp-Source: ABdhPJxw1Qpj5A7GWHWLHZ09ZPMi/B/UvNz/rjGtLMnwaH4Nhx+vHKTB51J5Q9V4CbzLicMUN+/4uZ5UPpaX2uHHBfE= X-Received: by 2002:a05:600c:2215:: with SMTP id z21mr531634wml.176.1600105992277; Mon, 14 Sep 2020 10:53:12 -0700 (PDT) MIME-Version: 1.0 References: <20200912002341.4869-1-atish.patra@wdc.com> <20200912104502.GF2142832@kernel.org> In-Reply-To: From: Atish Patra Date: Mon, 14 Sep 2020 10:53:00 -0700 Message-ID: Subject: Re: [PATCH] RISC-V: Consider sparse memory while removing unusable memory To: Anup Patel 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 4:52 AM Anup Patel wrote: > > 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. > It looks like we have an agreement here then. I will update the patch to directly call memblock_enforce_memory_limit as suggested by Mike. > 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 -- Regards, Atish