Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2348966pxk; Mon, 14 Sep 2020 10:54:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzRCyfQA1U/UEhUrQwtTshNjFAmyK7KoUbh8gvRU03SUiY3EPo7EUfVaBcLln686rV/k+W X-Received: by 2002:a17:906:8289:: with SMTP id h9mr15814033ejx.45.1600106070922; Mon, 14 Sep 2020 10:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600106070; cv=none; d=google.com; s=arc-20160816; b=k3eGaty58OdTkS6MTN9ckLPxAFI5mrE7qwXp6tztW6hOsSVmAEDr5Hi/Oe646nrekH Jks81U+J2t9gk8z60o/vQglwXkvOAtwG+DoOsUfPHgC/Yoim98xzyZvShfbdYX1tSoYW kzUbE7rDxymDyYgLmrCnGJhcVK4STLWWohTRSAQdgPqBXmjszTrAXRqHpCWEuBk0Baba /EHVVo/ytAh2q7FLSkMNoMgC2+cYDc2uINLU9VxLj5Zi3GhJghQ8B4e1Djt6VZ0u02LC 4FWzGc3zeNCYUt4ILCBO6CfK1Fwl4da9Hu/VP+V8JnN7B2dXYPK7w204hK5ZGnG0lLQc N7qQ== 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=ZKhv5rTCRwwZYJ4fJZiFA0QJHdmQ369d7Ye56iqS39I=; b=uaIimhYnQ/uDAhby3lNd0Xex+/umBmZFzgYUooDOJXBHTfWW7mB1rJ/RfdXKQmdikP QygYokhoCLnKKhasZYeCs10S1jgw8P7eGC6kXlLQ00jBkimjbY96AuyMK8gN8jiaOlB+ y9U5txQm5V4mEv2r5syYG4C2Z0Yng8QGHB4RGpTBug/fd+cizdjgDWbPBxYeWku2XUFb 0lVdKxaj/6Flrna5jb1Hu3UB8FkV14vzDCLtfjsatSUnZH/QXB2+wp7vR6r6joq35Vd2 YTnjAmREtNiR5UW/3HkD5CH0kJhW0VFunbm2XJneQkTMBqA6+ByQpuzk40I0PBaXxEc5 PGsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=LSYBezCb; 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 a1si7732388ejk.68.2020.09.14.10.54.08; Mon, 14 Sep 2020 10:54:30 -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=@atishpatra.org header.s=google header.b=LSYBezCb; 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 S1726089AbgINRxc (ORCPT + 99 others); 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-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