Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1998006pxb; Sun, 10 Jan 2021 20:02:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTleuXnLEuEu2eriwValzOoKoWZMb0kvKVgkIeDhVp2/cAH3GAETFe9DSII5FiPBDx6EjD X-Received: by 2002:a05:6402:5193:: with SMTP id q19mr13007028edd.264.1610337743058; Sun, 10 Jan 2021 20:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610337743; cv=none; d=google.com; s=arc-20160816; b=xHXFx3ID5CEm8zOdk4ERn89bbFxXtM5ZPzL+1irLVwQDeuih//GQMZRJowgmXvYsgO sBDKOXBIdhNhjc5ntC4/VWfIPY0ePNDJymXjRlmUeHBM2tJoYRl4asq8H+JkHYSoTwGM tb4libqkWoIk+B8K348ilLwiZvf+zZDfz7i2sEGbMD+xZsUYY/deUzVUx8CSeOzGc3bV Z9yXr0usKUJ6Ghv0+yLKQe1I2h1Q8bxwY/V/eaV3deFP/s+PnvZfaVXnAW4Ksq3RmkVq THI4Kg6ubxk0oTslzVS+5Sqwsxh3/7SzfVW/jWRHm3fqdxv91bVR0nfeEc+2MThrncLJ uQdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+cAZNgRoYkzoP/BhJ9P6BIGZW8pFnUjY93pDjiW7NME=; b=G+MQaGHTFBk5q/Fl+/mLD6EaRbYI1sG3v6gDWNfdzjhu0y0pVlbD1xi0jowE6fYIaQ 0ybg28pOTkn3bXA+inilShU0RLgFwsiGetDKK9BVG8yo2EsNynyB9r7RZOPLnbsiHoKa U6AWjjbr9EYkg4/jdh2Iv6elHD3rCzonRg6zabGm0JtLLh4GLy2bZRPcS2LlPl5rXMB8 Vr5O6LNh3p9+D7NA+4O87voHHKfq3j0/JH6M9CW9L7BwBmN4LWv355/0lGKFQrD2Ord1 56z0a2U5636BMIiD/7eeFkQvNzpOiQx+k1eh66gVXE+RoH/ZB5Upbe3tcW/hefsbSKJj x8KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=lPp5vs7b; 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 d9si6477655edt.564.2021.01.10.20.01.58; Sun, 10 Jan 2021 20:02:23 -0800 (PST) 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=lPp5vs7b; 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 S1727115AbhAKD7m (ORCPT + 99 others); Sun, 10 Jan 2021 22:59:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727041AbhAKD7l (ORCPT ); Sun, 10 Jan 2021 22:59:41 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55566C061786 for ; Sun, 10 Jan 2021 19:59:01 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id p13so2015313ljg.2 for ; Sun, 10 Jan 2021 19:59:01 -0800 (PST) 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=+cAZNgRoYkzoP/BhJ9P6BIGZW8pFnUjY93pDjiW7NME=; b=lPp5vs7bcac0seBLFXigYh8T8CRIzbqwfqeJQqIY8Zg3c3dsvEecwg3f5K9aG5frIc UgcK38xPhVYBfPmZzr0ilMolRlyXVmPChbHqJZUt5/3GQtCDzaMmbvDR9iUDrQPGnXAO OuDAUJl7+7PQQflYSTa3O9YrmOPFf4DzyL8eR8bF54jYz5dF2R3mMQm1fmzb/fLJ+1zb rU3q2KTVeueNbTnWT9KcA/yu8tSYxIvgMRJppmOuPDmOzxrq63b1sNkntRO2+a6ED3rX JGxs8GiyOADfzzc3FkcmwpHi2KJEJg8KLTeSutGPh6lISKHbqmwLi6qOx8MmA00cVGtR IKvQ== 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=+cAZNgRoYkzoP/BhJ9P6BIGZW8pFnUjY93pDjiW7NME=; b=HRhjUewKb6xdTRLvKulNMTnmjys4CLUxBv8bmAmiP513GhrrkaNN8y3vo2G2rwOo75 HDek4xQ3bosouMyZYqr90xwLCx7wH4a0wZXj/978AdhbBJFuFu/3j0Me8kvA8Ph6iD9t qT/KfzaijVbgULbGMNTfmC+bkeLiHjqV23XQVZsttbp09WUvywuH2x8IpzLpYHAsMG+D 31Naq0cMiUzDL4N4Esh+QsBySMfPjQoj4Ax/5AHHTJ9qJumeqFqG3bAF+GCCcStjTSya zZazJY4oEuPXJSIqLvaZnC1x2Soo8ZHa3Ob6vhbdkSlN8zQxWS15g4fWsYEzROWTiRUk AnZQ== X-Gm-Message-State: AOAM531gtBOJKGaPNO+BfELCG3LhKIMTQ4jTjYMczRLztDF/cH2TlidQ OKmF//LrxpEZ5YAcsBhroqcPdcaaEsIwZgJm2qVgEA== X-Received: by 2002:a2e:8e98:: with SMTP id z24mr6326578ljk.83.1610337539722; Sun, 10 Jan 2021 19:58:59 -0800 (PST) MIME-Version: 1.0 References: <20210107092652.3438696-1-atish.patra@wdc.com> <20210107092652.3438696-3-atish.patra@wdc.com> In-Reply-To: <20210107092652.3438696-3-atish.patra@wdc.com> From: Anup Patel Date: Mon, 11 Jan 2021 09:28:48 +0530 Message-ID: Subject: Re: [PATCH 2/4] RISC-V: Set current memblock limit To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Anup Patel , linux-riscv , Palmer Dabbelt , Paul Walmsley , Nick Kossifidis , Andrew Morton , Ard Biesheuvel , Mike Rapoport Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 7, 2021 at 2:57 PM Atish Patra wrote: > > Currently, linux kernel can not use last 4k bytes of addressable space because > IS_ERR_VALUE macro treats those as an error. This will be an issue for RV32 > as any memblock allocator potentially allocate chunk of memory from the end > of DRAM (2GB) leading bad address error even though the address was technically > valid. > > Fix this issue by limiting the memblock if available memory spans the entire > address space. > > Signed-off-by: Atish Patra > --- > arch/riscv/mm/init.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index bf5379135e39..da53902ef0fc 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -157,9 +157,10 @@ static void __init setup_initrd(void) > void __init setup_bootmem(void) > { > phys_addr_t mem_start = 0; > - phys_addr_t start, end = 0; > + phys_addr_t start, dram_end, end = 0; > phys_addr_t vmlinux_end = __pa_symbol(&_end); > phys_addr_t vmlinux_start = __pa_symbol(&_start); > + phys_addr_t max_mapped_addr = __pa(PHYS_ADDR_MAX); Using PHYS_ADDR_MAX as the max virtual address does not look right. Better use __pa(~(ulong)0) here. Otherwise looks good to me. Reviewed-by: Anup Patel > u64 i; > > /* Find the memory region containing the kernel */ > @@ -181,7 +182,18 @@ void __init setup_bootmem(void) > /* Reserve from the start of the kernel to the end of the kernel */ > memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); > > - max_pfn = PFN_DOWN(memblock_end_of_DRAM()); > + dram_end = memblock_end_of_DRAM(); > + > + /* > + * memblock allocator is not aware of the fact that last 4K bytes of > + * the addressable memory can not be mapped because of IS_ERR_VALUE > + * macro. Make sure that last 4k bytes are not usable by memblock > + * if end of dram is equal to maximum addressable memory. > + */ > + if (max_mapped_addr == (dram_end - 1)) > + memblock_set_current_limit(max_mapped_addr - 4096); > + > + max_pfn = PFN_DOWN(dram_end); > max_low_pfn = max_pfn; > dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn)); > set_max_mapnr(max_low_pfn); > -- > 2.25.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv Regards, Anup