Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1791948pxk; Sun, 13 Sep 2020 16:49:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwT/9Jw4MvpQ/0sQTe3uGIXsgkL+g1hs91buqrN1du5wdw0uIEOyWqhe5WFowkp9BZeHAw7 X-Received: by 2002:a17:906:1a4b:: with SMTP id j11mr11660640ejf.97.1600040993695; Sun, 13 Sep 2020 16:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600040993; cv=none; d=google.com; s=arc-20160816; b=nURGrWQUVaHBQ5dbiO4V1GD92i/lNOKR7jJXquvkXSJBe2xOlMP5+GD5ve/Sc4a5mE QjvarD5Tlpj77pgKUphOgLlUisIBTFOadKeCxPlFE2nD8pjMB53HLrOQ5plM9KS7uh/A FfHmpat2IK4eQskmS0DnnjSn0V0KnctLW8IyJM6xRPIwaFS1AV5UEnUzje1ZWqXbksJW CO/gQ+4ProJhTdJzWTYdUXxqwSfdRkCpXvK3OZtBzjRWUgzpZ5spjzk8AORl3zd6oZsJ Ktn8SLxrM87NNchVJWffcv4tWIn+hXCO1QxoLAHLefExzeaIMDiicWvkjBN+Nh9DwtjK BDWQ== 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=fzb4SDNhfhKuOAH2aTFB3ctXAAaT+cISGh+UPXFnYd4=; b=KF5VDmBiFEZsjDw6itqGmzFGS5HsS16usDm+l+MpIuQUA7Z5l2Amg4+x5cZxZA45qX 5PLdJL8HTqI3QcgzbdJYceSLkXXwo7NYMpr8fdTx9jG+6o7Z1tdZd2aSuALfj1sck7JA 7yos8eelc0bO9gyfzdeLlUk+03HtH3mtEkHLDhHXAC6RYwZMQoZFhHM2JfH0m/YjqXN9 FQg99J5GYBoYds+zm571Ld33AigX+hfe2z6KDx5ZCVu5BZYSxn7qtniBJK1626XbDiR1 G2IJWrDUBFd2CeC7WAUowLmu4xgKzz1iWEeOV+Ov2xEj2w9eBaz+0g3Dasq39HHgWWAM rHPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=iIKSQgHr; 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 j24si5867026edt.105.2020.09.13.16.49.30; Sun, 13 Sep 2020 16:49:53 -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=iIKSQgHr; 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 S1725989AbgIMXsG (ORCPT + 99 others); Sun, 13 Sep 2020 19:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbgIMXsE (ORCPT ); Sun, 13 Sep 2020 19:48:04 -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 82256C06174A for ; Sun, 13 Sep 2020 16:48:03 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id d4so3626422wmd.5 for ; Sun, 13 Sep 2020 16:48:03 -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=fzb4SDNhfhKuOAH2aTFB3ctXAAaT+cISGh+UPXFnYd4=; b=iIKSQgHrnqvxkICTPyxQchFi/Ywy8k/fbBjQkBw7PIqw9AwjZVzB6N5B+qqiud8is/ G+tIlUHrDTIcu2hZitlR871CfiKHd2wHX4C0sMwttj0JmIfa53b2B2t3MpwoXr0VX5ZN Qij8W+M6S9SAtx1bwaQsTYErc5/ZWc7FuBPO0= 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=fzb4SDNhfhKuOAH2aTFB3ctXAAaT+cISGh+UPXFnYd4=; b=A8Jv2n6/CwRt1aycNqh6dHL2Mh4BYtIoE/JrUrH9W0+xiPU8QkWoNlJ+Mj7jY7CMSa JBoK1WSUrGe87WO72z+mD3P+5qCqdQr6SYu5Pe2MnU58GCAXJ3ptqSUIPOxY2D8pqU/R I9FKNo3eFOVgldxyP2P48289aDHq0T+9SQyQ3+PDQNPFA65kPO3CnbT7tEMxozyNi12d 0N//2jl9559ZujSk3vch0CW87by8faOD1X34RsTC5USI2KluECbIiDaJQWeSpj18t34h DRvyo4/JmAY01mPXFVLJz9Ov2iWKaTKv6X39tT9ax4QfnSE7KwAjvsqnHqaOt7LE0e9v KGTQ== X-Gm-Message-State: AOAM5330738OlDgqvYjU5i3GF500eQAJ38Ock1ogXntAwWJ85Bm0cADC sVf2P5Hvd/w7cdQAXRvbNxXTd70iMkF8lmun8QC2 X-Received: by 2002:a05:600c:2cc1:: with SMTP id l1mr12074737wmc.78.1600040882110; Sun, 13 Sep 2020 16:48:02 -0700 (PDT) MIME-Version: 1.0 References: <20200912002341.4869-1-atish.patra@wdc.com> <20200912104502.GF2142832@kernel.org> In-Reply-To: <20200912104502.GF2142832@kernel.org> From: Atish Patra Date: Sun, 13 Sep 2020 16:47:50 -0700 Message-ID: Subject: Re: [PATCH] RISC-V: Consider sparse memory while removing unusable memory To: Mike Rapoport , Anup Patel , Anup Patel Cc: 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 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? > > 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