Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2507675pxb; Mon, 11 Jan 2021 11:23:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwh+UVVEIy7iJTUw1qAJHRAWSA6NZJvDoEpoCH8baeB7dWOrU8f2ouVs/SUNX7+bErRiHHP X-Received: by 2002:a17:906:74e:: with SMTP id z14mr665784ejb.362.1610393031892; Mon, 11 Jan 2021 11:23:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610393031; cv=none; d=google.com; s=arc-20160816; b=fAmaPYu+M/MgntSWY34E8eghSw8jUKsTj/71QIT96HsR7A/cDhvQYUAPOK5RpcUOFr eJFghModeSAWKRtzuHm0NtCPkIJBmJeXeeD88gSp7vLyxKV7aHB4bK6G3N/7Bj7zZ/kZ ykJKP2t+40lpBdefTFZGf26TPV7BAsP4cd+vW2p0AQCQy4AC3bmtcHP9vYhPaJECIPGB d9zQ4mz79w79Dn7lz3C0XgozVsi/BLhuBn7TAVt1DGy3kjd+92diLvXueXvh4vJtosFt uPW6DEz248W0HjYtihrxcUPiVRESWu2XxhCZQGY1QO49ueVWyiv8d8lIFsxcy5cUCwM2 qzFA== 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=nDbikhMgQRIBAGWvHhwnSOWp+tYdIa1L7HqD2Fuhn5o=; b=BgAihY9XzMoUjwf0sGGKfuIPFN03u1XJXh2BjrEvIzetVkmrz3OESsOakTXCvkxLIA 8QaL+fx8kS9Y6sqioJ1k6nG3pOmJHZb6ewylHJ2pVSiQm9/ULTzRNIvvU6vkczP5v14a UBL0jeN5VfY93eQaY8nxwb5pXqY1FV2u6nsbwBnP36qCO2NiKTNzQGLSOSvcz00WAoWJ FmFme6TaB7HelhNka5xP2wFmiS/KiQ7gm9T3bvuqFrWGLbqNzX62YV4e79Sw6PnjjZ7y H9T75/YE20gZOrKpm+MJ9KQfpY2D1ZaYYHfKGvVnbHw7CSETT164CqCZz+gvzSBExs3M BcFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=TNk8AsQk; 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 h22si138006ejd.179.2021.01.11.11.23.27; Mon, 11 Jan 2021 11:23:51 -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=@atishpatra.org header.s=google header.b=TNk8AsQk; 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 S2403873AbhAKTVO (ORCPT + 99 others); Mon, 11 Jan 2021 14:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403864AbhAKTVN (ORCPT ); Mon, 11 Jan 2021 14:21:13 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 839C6C06138D for ; Mon, 11 Jan 2021 11:20:14 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id h3so265607ils.4 for ; Mon, 11 Jan 2021 11:20:14 -0800 (PST) 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=nDbikhMgQRIBAGWvHhwnSOWp+tYdIa1L7HqD2Fuhn5o=; b=TNk8AsQklmM1D18YtjeuP5msks8k476ei5PZfBL/rN+WUCBbkWH5tSwvzzd5cdrK3z Au896fIPreNaHrPS29rJmrmXO89zRZN+HdhQ2txPclH9RI2uPkuron3RBWCrewyB6oiV 7GbGoIPTWXbxsHAf/Y1gReu0BWWttvce4AbBM= 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=nDbikhMgQRIBAGWvHhwnSOWp+tYdIa1L7HqD2Fuhn5o=; b=Oz6PlXjyTJFyziN4wGcuJJoCl5xZPaHoundK0apDrbxZoWXQpoEMq1uMIujknEOs/G aDRIF4A7ikw/bMntoLqd6KeaB2QvK40L8us8Ydc/nz5m9NoZCBXbc+aa1A09JaFJIDEN n51Z7mx4Eb9VgNix1e+wIA9zSSix5Kd8WBT75S73S3tkm8O7SuIqKD4CEzaa4TydhGRK oSWLxBLwXrMbAR1YdKhfjd9k/FsxKzcXhGNiKnvdMZ5VMoFrFUUUxOYvWyEKgHOhjZ35 wHbgy/+ZVtJ5dIAr0XR7UQtG0y4PYKIJNVTmL8fNtxhwoA9nMFbXuWPYbSRvzM2Mpq8L H+Lg== X-Gm-Message-State: AOAM530yRquaIZbtrqRcxbh/aGEIVQiSyadVk96BFlNCsCtxAVWT8XR2 5h9o8k9ukgVXwUGFBfOTVlqEztiLm74jFmma4orO X-Received: by 2002:a92:512:: with SMTP id q18mr590913ile.147.1610392813919; Mon, 11 Jan 2021 11:20:13 -0800 (PST) MIME-Version: 1.0 References: <20210107092652.3438696-1-atish.patra@wdc.com> <20210107092652.3438696-3-atish.patra@wdc.com> In-Reply-To: From: Atish Patra Date: Mon, 11 Jan 2021 11:20:03 -0800 Message-ID: Subject: Re: [PATCH 2/4] RISC-V: Set current memblock limit To: Anup Patel Cc: Atish Patra , Albert Ou , Anup Patel , "linux-kernel@vger.kernel.org List" , Ard Biesheuvel , Palmer Dabbelt , Paul Walmsley , Nick Kossifidis , linux-riscv , Andrew Morton , Mike Rapoport Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 10, 2021 at 7:59 PM Anup Patel wrote: > > 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. > ok will change it. Thanks for the review. > 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 > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv -- Regards, Atish