From patchwork Mon Jan 11 23:45:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 12011759 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 348CDC433DB for ; Mon, 11 Jan 2021 23:45:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE8BC22D08 for ; Mon, 11 Jan 2021 23:45:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE8BC22D08 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ycmZBkuqJypR4s8T0u0eQC6/xr0pFhIpmOUuX2SfU/Y=; b=FFvcfgoNSX0W+Z/LVo5SUZiKx PPO4k+/oMuLCDQHMODVdhPTqJFGgNP0Sz4O5wQilxYQvhM/rW5rwh7jgXQ5cbPv5ZcslgOsC4hEkC RGvxWw8xCdnx2PDcd9WFd+kBr/T/gdSdxefzxsH6RYhYFXANaoa1HnLw84TvEVmhsiZXLIdnc/Tat VkCgLbNGEmxZxg1k/YFtfbQOwWWVPcRrHilYopz2NJMlMsFxHhDChZbntKfXV23fNVBx43rBkxe9d cLNlwrY1wU9y1Pd707M45U5gsPbnpbTqoZ1rqztreI8kQIxzpe3+kWZ/2QLQhv3YQvpny5GdHVpTz /jQeHldlA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sN-0002N2-PH; Mon, 11 Jan 2021 23:45:31 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sH-0002IU-KN for linux-riscv@lists.infradead.org; Mon, 11 Jan 2021 23:45:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610408725; x=1641944725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oZ32JyRr/0hov1ExpFgrBbBCQ8Msd+e4ScJeLBVGhAo=; b=bWLhagMdZ6z3gdV/oW0snC5NJTTfxdjvbDcUMsJATUaIa6G7Ry6Qmr2S 1JNNQfiHMXVfHcgy4DAFIQmtjyzYXWRm9o+ugKJS8Mb57pGDTMqlqJJPc CKg/khOfV3s3TQH9OAggut7OlftSaDtioHfCZf+Ogw6caexWFBALRx9s2 a260XDX65lPVnmOqR91eWpc9U7SShYeDrLyGUnTs3EmJDDEXPee2LEDQk FfFYy77JzILqflhIJOCy4PKp+z7hYBqL39T5EfTlrE7tFUlzcxamZoy/2 WJw1zBjZJEC65c+UlmEzdDU0w8ONURLglmMuOHI4m0MF3bZEli2Lttk5j Q==; IronPort-SDR: K0huab3E6cxbo2aB5jMNaF2YHjIqWTWywICU4+aejYyf/7rZkFjw2eY3NqfkpDR2S8Fwo687AN uGdayMIvIX+dnLlywefu3xQkmeV0rX6ZM1UYBbGVTImOMNUcJAp1J22SFBipx0XO0Ltq2r6+/7 dRic0fYpK6NTaM9+KfCsQS0OQQ1Ngvg8zaHyRvfNt7OscOYUBBULOBDStdBF3sYtaX4c3U0CSX iOe+vlTY4FC4tab9eExP7wlOdjY5Jrt137ORrH0K3FNi1bu4vkz2uOsHtVaeNyXAxHTnDIpRGa Duc= X-IronPort-AV: E=Sophos;i="5.79,339,1602518400"; d="scan'208";a="161629286" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 07:45:20 +0800 IronPort-SDR: NH7GM9D+ZJAn9hPasKtHn4D/11hsaCF1xh47fQFJutwB60Akr8nNvEyXLAdHWc3BNZ5wctLZRN QDzzr/5F9oHlfXStOCpTcu/pnZkx468WYsUkJPRoRzyIrajaslFNXBz62yYnH4gcWF91LUNB3s 9qipYGFfYyqFnepwqxObhGxFH0m3raraqYk4KCH2N7rbZMEiLhbsjA1Gnl9zt+YBglEXxFsBZU QhT5wJlXjVGrBqMp5eitjgBkE5vZcvl465j1p36Dg3HLC/k0NRxXG5FeMYIvr/4NecRGjNxUL2 0TQc0+pLYIXtDxY3w455+mlk Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 15:30:06 -0800 IronPort-SDR: JGAiHmoKynGPRy8l4SeqkvGkhiqKA9dy8OgqjlzdySKCZqlN+fM35WStMKIu/dQcHvAYEBREKx vrrLSQEwSqCV1oG1Ga+TJiuHFmBK8gv2uCTC4MRL4c7R6PjsJGRhDosYmDStYKfzH0oiSXV1Dw 3DrShXs2GtwtlCOBk/fC6zHdqnPtXapj4pdfCaIDHSITwRLVHnhDja3zu8QLqYzcnCXSk+evex qNi5d4QynM9trXGsrADNHKZyJWUiTpOb0AxYLTJw6ee3OYgzmMLF5ap0TfphnjpN82/9l1VpA2 trY= WDCIronportException: Internal Received: from usa002483.ad.shared (HELO jedi-01.hgst.com) ([10.86.62.194]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 15:45:20 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] RISC-V: Do not allocate memblock while iterating reserved memblocks Date: Mon, 11 Jan 2021 15:45:01 -0800 Message-Id: <20210111234504.3782179-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210111234504.3782179-1-atish.patra@wdc.com> References: <20210111234504.3782179-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_184525_825682_45C26A2D X-CRM114-Status: GOOD ( 18.43 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Geert Uytterhoeven , Paul Walmsley , Palmer Dabbelt , Andrew Morton , Ard Biesheuvel , Mike Rapoport Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, resource tree allocates memory blocks while iterating on the list. It leads to following kernel warning because memblock allocation also invokes memory block reservation API. [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at kernel/resource.c:795 __insert_resource+0x8e/0xd0 [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.10.0-00022-ge20097fb37e2-dirty #549 [ 0.000000] epc: c00125c2 ra : c001262c sp : c1c01f50 [ 0.000000] gp : c1d456e0 tp : c1c0a980 t0 : ffffcf20 [ 0.000000] t1 : 00000000 t2 : 00000000 s0 : c1c01f60 [ 0.000000] s1 : ffffcf00 a0 : ffffff00 a1 : c1c0c0c4 [ 0.000000] a2 : 80c12b15 a3 : 80402000 a4 : 80402000 [ 0.000000] a5 : c1c0c0c4 a6 : 80c12b15 a7 : f5faf600 [ 0.000000] s2 : c1c0c0c4 s3 : c1c0e000 s4 : c1009a80 [ 0.000000] s5 : c1c0c000 s6 : c1d48000 s7 : c1613b4c [ 0.000000] s8 : 00000fff s9 : 80000200 s10: c1613b40 [ 0.000000] s11: 00000000 t3 : c1d4a000 t4 : ffffffff This is also unnecessary as we can pre-compute the total memblocks required for each memory region and allocate it before the loop. It save precious boot time not going through memblock allocation code every time. Fixes: 00ab027a3b82 ("RISC-V: Add kernel image sections to the resource tree") Reviewed-by: Anup Patel Tested-by: Geert Uytterhoeven Signed-off-by: Atish Patra --- arch/riscv/kernel/setup.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index 1d85e9bf783c..3fa3f26dde85 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -127,7 +127,9 @@ static void __init init_resources(void) { struct memblock_region *region = NULL; struct resource *res = NULL; - int ret = 0; + struct resource *mem_res = NULL; + size_t mem_res_sz = 0; + int ret = 0, i = 0; code_res.start = __pa_symbol(_text); code_res.end = __pa_symbol(_etext) - 1; @@ -145,16 +147,17 @@ static void __init init_resources(void) bss_res.end = __pa_symbol(__bss_stop) - 1; bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * sizeof(*mem_res); + mem_res = memblock_alloc(mem_res_sz, SMP_CACHE_BYTES); + if (!mem_res) + panic("%s: Failed to allocate %zu bytes\n", __func__, mem_res_sz); /* * Start by adding the reserved regions, if they overlap * with /memory regions, insert_resource later on will take * care of it. */ for_each_reserved_mem_region(region) { - res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES); - if (!res) - panic("%s: Failed to allocate %zu bytes\n", __func__, - sizeof(struct resource)); + res = &mem_res[i++]; res->name = "Reserved"; res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; @@ -171,8 +174,10 @@ static void __init init_resources(void) * Ignore any other reserved regions within * system memory. */ - if (memblock_is_memory(res->start)) + if (memblock_is_memory(res->start)) { + memblock_free((phys_addr_t) res, sizeof(struct resource)); continue; + } ret = add_resource(&iomem_resource, res); if (ret < 0) @@ -181,10 +186,7 @@ static void __init init_resources(void) /* Add /memory regions to the resource tree */ for_each_mem_region(region) { - res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES); - if (!res) - panic("%s: Failed to allocate %zu bytes\n", __func__, - sizeof(struct resource)); + res = &mem_res[i++]; if (unlikely(memblock_is_nomap(region))) { res->name = "Reserved"; @@ -205,9 +207,9 @@ static void __init init_resources(void) return; error: - memblock_free((phys_addr_t) res, sizeof(struct resource)); /* Better an empty resource tree than an inconsistent one */ release_child_resources(&iomem_resource); + memblock_free((phys_addr_t) mem_res, mem_res_sz); } From patchwork Mon Jan 11 23:45:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 12011761 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 7B031C433E6 for ; Mon, 11 Jan 2021 23:45:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3151322D0B for ; Mon, 11 Jan 2021 23:45:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3151322D0B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8UM4XB29gbYuHUbLpaKcw2dZqOaHCkV9YnEw7hW4e9o=; b=ppoLUtpRysTP79kFN4J38QQF9 pheBAxrTpH+SaCezgzrXoG/UWRDNG+/XopFU0ATaY44sMTPIhFUiPjDlF4Mqpe0U6uVphvah1xx70 /xcoG2AX79hBbQfXeFjaepru6UjvA8ZaBEuuGt8h8BGh33tX0hlqkIuB14SfxHrnFzHg27SMcglZ/ x+UbUWvC9l5Z1GYHETtPATC34pqIAUdbPkOksgv64QSaDkBv0+/EZsV0FMh+NvysB+ZBiVoaYI1TF DgqCH2bQBElrhn6bQe1zLThkb+cwR91ZSMGvGo9nenLvCENIb63f+jHL9wdsA9/LIcaDTh/6cijNx C4A3+ehoA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sO-0002NS-D7; Mon, 11 Jan 2021 23:45:32 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sI-0002KC-6X for linux-riscv@lists.infradead.org; Mon, 11 Jan 2021 23:45:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610408726; x=1641944726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Io1Pp7bw+RC8AMMDpe1YABzZYAEHgEO0leECzsL7CUo=; b=Qdi/y0RW1ZJ8cRcCwC93rUrShTvJFYcSuGgCeMQles8u4TFvmpHAjvWH stfznQF6AmjUZhvysze9ZX1VEr9WGg+n7Yd465J9Qe+hQPU1YJew2T6HE bAiMB0OGrbetZxDufMNdf+giuNI1nRG312pndQzcSJT2cHWC1h8eVVQLV 33SbAYWehGW6Y+7o2d12N9iY8FGxBsSuW0FXmUm6VSizI+ahPNdcZV/zd Pg7mxCZz3V5mpoJkDrlCdIv/fY/qFW+X9Vf9vnWFw0gq1gqZIY4dsrZ+u ruqcyT+AqbwqDA8Zq5afmJidVdOAxu+kDY1+VZcWzfjD7t4U7qBDSUwYW A==; IronPort-SDR: 90oDX7/ov4pgOTZ+tq93OdfzTrMrQXWbDXpCi04Z0yCJihvNgYxqAYn+femwfNi+wGD5QctzZm kYJ9wNPkXNhZw9dkYpFB3DXjnFF8D+2wpcaZctg038DUi7begzXlE5CvfCKlZrzG6a04xEHPHr bKlcs6wkDALAfBxbHd9lYkUo0sUgXSClPLd55AhbtJ6+ZRjKqO83D1Dy2qf80CyvFMcogsWaSD A8sAQJnXN5MjJTSKO31mOk4eaUYyu5Em7U3LJlrCOiVq/UgS+gpvqWY5CpKU64u6uRdLVbkQkh 8+0= X-IronPort-AV: E=Sophos;i="5.79,339,1602518400"; d="scan'208";a="161629289" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 07:45:20 +0800 IronPort-SDR: O9WdicAzbw0SKhu8RLpYpaUzTZv0PyOIDm/G7HLVbHp5Gb9EDvGlcnOGM7k/RrEFkVPTISGt+I MwtoM0RwgHD4YgL2oMEVKOXhMxBCkuI749MBTFVuLvB2g+r27WWyJJRM3u6ro5bAmHhjCfHJXv FHUxOcCZd7Qi8VArQLSJzicS9hZ2j2njIKB1KN7rmazj9hiVskGJHLBpUmoliNybnZdK4apEpz UiUL5Pg/AEhodYH4NnGbhh1BTeEYByBg+gZTmqCdtTtkUzdkoSePZi31R00fRzNe0taDtPmm/l b86ziH9l0wQm4ESWDv1Pb3s9 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 15:30:06 -0800 IronPort-SDR: ox38t4igJU0HZ0yuKw/XhjcfplepASAM4Swjrpnp6n6vw7ZypirIWOtHz0UmDIdPF9RtAITyO8 +hBx6NYdR/CaTPR+Gi11KbHw+YZQVRLWaKSeqGuFNX1YVm8W83SIb+sqUEEInb0H0nD/HoecjS MTEYF2NATdI4+nLTlJ2MC3WJprR4XaR7eYkiHc6zB2UsP/WdwzKhFTW99qt7w/4uXOX6gdewmG XuDPYwEfN7zQw1X5o2WM1P8ofysAfLWfH6GJKsBBpIbSWBLCDgzsZdWfJv+ohqqh8wHzXY2VwG W/Y= WDCIronportException: Internal Received: from usa002483.ad.shared (HELO jedi-01.hgst.com) ([10.86.62.194]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 15:45:20 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] RISC-V: Set current memblock limit Date: Mon, 11 Jan 2021 15:45:02 -0800 Message-Id: <20210111234504.3782179-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210111234504.3782179-1-atish.patra@wdc.com> References: <20210111234504.3782179-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_184526_387538_DFD02BE7 X-CRM114-Status: GOOD ( 16.12 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andrew Morton , Ard Biesheuvel , Mike Rapoport Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. Reviewed-by: Anup Patel 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..7cd4993f4ff2 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(~(ulong)0); 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); From patchwork Mon Jan 11 23:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 12011763 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 9A50CC433E0 for ; Mon, 11 Jan 2021 23:45:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 57CA022D08 for ; Mon, 11 Jan 2021 23:45:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57CA022D08 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tIoURQEik4PWfmwotpha84YnR5yjzVQJLqUy6Rwp398=; b=PYtUT+y4OFQ16mmphY/zZOynY tq8bPtILnPLSDDahPnbvIheh2c1vKZ9yhQQzGIQEfHmKC9yLcmfOWm/pWG6HtVp5IJm3O/YMugSMI rRukZG8cRXXMAs3A4nDbvNHeLwPcTCDDRHTuZg6Yjn1dximpepDLKLSMC33LKPfFOzi/6/n19qtGr GrKjbmKsSQ/NOWgH8Uh42vaSDc0w/E2hkQSJlEogZmMGQvTLcpIeJOEd9/ibpXGom4ha/FYCv8D8J MsrR00tI/Ov3v8Zy12GRrjbgTSvOXPc1Q4LVVS0nQ86WkQxviGH4BhEjYTQSbpuhAPzXHN1wtssmD caAHAD1Og==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sP-0002O3-Hl; Mon, 11 Jan 2021 23:45:33 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sI-0002IU-Tv for linux-riscv@lists.infradead.org; Mon, 11 Jan 2021 23:45:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610408726; x=1641944726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RNOH9gvngKv4PYnI6ojB0jPRmrRFh5gcDLRyBhBMMTY=; b=CmvOE1bRJ2hIuchpI8E5SPFXZyiI3NvNvLoWl+NPp69Y3aRJlzOd7fa9 XrxhFuLpAB7vaEymwkGFFobWcVlbIf3+CO4ZXS8Qj8buOPNwkg10N9fDE CldbW0lm1ELK7y41MkeCn+VOd6x32vrGWzdnbLbQdZf1tNTYXeKnlGHgB W+JKdip6gvVPo2f5ahih41qu4W2PKmtFhL3/NfMqIhwUTpd9kD8NCVbMr YlyXtyiGt8bzm/onp0xX2b2b+QG+LEJjN06j1XV6bEblqL3zo2a8Bf8H9 X6OsdFOAX2NEYT2CZkCzClR09577PHbbNcHjK1DBCx7ZIXhKA4Ammh420 w==; IronPort-SDR: +rd9AA2lqMQTGiRNAtwwE5ykpJNLTLyKfot/jl+UnV8v2by9zhylHgtQsP88tgqQjjp/QiXKp0 +tG1AOc6IS35glcJrT+MH/cGwdA7EQ6Sp+JMCsW9hv7Ufhp2XXWbUqjARPiOZm8yt/izK1tZi6 /xViZue3eZYQQe3lhU7j15WXwL+D7JD6epz3lXjUmVDp607RffvR96+DPnyTMoDwoiN8jPfSwh AGIrWxzL4FQuBPZrEHDAQp04lT7bKip8LsfHgD651KO2v163CgOkrwFaQRBZmkQAOsK2uCR0FG qqo= X-IronPort-AV: E=Sophos;i="5.79,339,1602518400"; d="scan'208";a="161629292" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 07:45:20 +0800 IronPort-SDR: hg/JWht7DY9TqWUKItEcVJEp/+bKIWB7BWO+Tc0BP7l6XYkNYTYYkw/KCHLYE0ZwrDq7qEZUuX 36OQJYK5KmRhQ19syHJm3JjrOUfrurrTJ5vvuJKiEvsYDtNBHlg3FRLninVYWHkCZvAEellU2W sY/j2RKv4e99Id4dxpflybZ/fBe2oS/DK+f/h9HXmcn+4IKFcJebQ1mXPni01BMDWE8n9V3kHa kEseaevswQ1JzvOd2izaqbGNmKA6pBN5E0PHu8y8Dq/gheBgd0aYRjZYkIBPAZ2RysltyLoRoo 8VHfwY8+ueAprWNVSvFLV2Df Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 15:30:06 -0800 IronPort-SDR: S4/lzpttx6/ZOnuXtMd2AXORHB8tLqvAqVfTYA8r+mdnyUCj7ItefrtrKECOgJE02m8nayn5A6 CoVXlHknaU3TfcNc2Uwee8WCnSvWmEpd5tkfUQ3TEA+uIGX6197ACGDOBZkKGdI39K4Oi/0Por UgnAQY6aaf9JjD83vanUpc2jsIUtaElnPKvWUN8WujGXNRDtUUybiUa/b42T7LSb5TPIn/VFEZ /kqrRJVFAxSyq60AiEaVu8jxdvKhccWAJDDroZZMKRxusckMqvhm0DW29VLl65CpImj5UVpZ5t +rE= WDCIronportException: Internal Received: from usa002483.ad.shared (HELO jedi-01.hgst.com) ([10.86.62.194]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 15:45:20 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] RISC-V: Fix L1_CACHE_BYTES for RV32 Date: Mon, 11 Jan 2021 15:45:03 -0800 Message-Id: <20210111234504.3782179-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210111234504.3782179-1-atish.patra@wdc.com> References: <20210111234504.3782179-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_184527_202297_15E68916 X-CRM114-Status: GOOD ( 10.08 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Geert Uytterhoeven , Paul Walmsley , Palmer Dabbelt , Andrew Morton , Ard Biesheuvel , Mike Rapoport Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org SMP_CACHE_BYTES/L1_CACHE_BYTES should be defined as 32 instead of 64 for RV32. Otherwise, there will be hole of 32 bytes with each memblock allocation if it is requested to be aligned with SMP_CACHE_BYTES. Reviewed-by: Anup Patel Tested-by: Geert Uytterhoeven (on vexriscv) Signed-off-by: Atish Patra --- arch/riscv/include/asm/cache.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/riscv/include/asm/cache.h b/arch/riscv/include/asm/cache.h index 9b58b104559e..c9c669ea2fe6 100644 --- a/arch/riscv/include/asm/cache.h +++ b/arch/riscv/include/asm/cache.h @@ -7,7 +7,11 @@ #ifndef _ASM_RISCV_CACHE_H #define _ASM_RISCV_CACHE_H +#ifdef CONFIG_64BIT #define L1_CACHE_SHIFT 6 +#else +#define L1_CACHE_SHIFT 5 +#endif #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) From patchwork Mon Jan 11 23:45:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 12011765 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 23E07C433DB for ; Mon, 11 Jan 2021 23:45:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C878D22D00 for ; Mon, 11 Jan 2021 23:45:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C878D22D00 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wahHBOYfIViNkpmTxTb7EsC2tGhJBZYaKIgx5PHWQ2U=; b=RDqAY9AE7YVnBNe7vztF3akmi Qazao25zVWVbHX+ZocMQzPP2Zh+yq0xM1K22ty53Tid/us1w9pOyaALrW1yQ2urQ0aNY/j137/YeZ snHD/Ybw2vxb9JIQr+BdUn6wvfYAJ9bplxqqupVqmvFicuDOBa6rFFnrOXSMv8vr2Gx8BfzgtmlrA 2zS3soVgMJWSZV/pjl518G/lOgtf2HqL5AJD3du7T3YDtCCFfpamCZA+Cvebb5kSnqPzrye/dqoJe MkM3uPAXZLmn2kVD9RuI8d9ZnAxSZAlVO2UrYveLHkqCRnJ/tOcrOoaWKrp1/1iD2+6STbp4MvtG9 xN/0+5AlQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sR-0002Oh-0v; Mon, 11 Jan 2021 23:45:35 +0000 Received: from esa3.hgst.iphmx.com ([216.71.153.141]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kz6sJ-0002L1-FW for linux-riscv@lists.infradead.org; Mon, 11 Jan 2021 23:45:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610408727; x=1641944727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+/8BmP8C7btVepEdnOtx9sho7KAoL9aXx1ciJIHqe4c=; b=CJtkK8YSiMLa1uXDAbcjlgIkMH96oxmqJZfFVKMkJYHcu6UFhAaq7F2J vYW7HzeIjNB8mS1H3oJbLvJH+qNoQ0QnRufxRvBT4XRPMIcdVdrkN32ke Lm+nortISb08y9wl/zxMTEms+OjXTbqE++FR82Vid0UAcwd4nPqg2WOO+ um8DXq+ewoAk42oXDLOY96vAwpvSkmGcbbM5TsBdqM1lazR/nLdz5i5KL nxfixOS1UGjrOaRK3AW7NxHp4gGyLBqXW4wle9uVw4kvBzRTgbAbzi5dN 3q1LtjD1w5clE0VjTOgDgbmQ/+82/Tv99dx7xSekUsz9uUCL+BhmG7EDN A==; IronPort-SDR: qEY8ixB9a6Mo+KPT5TKUxu8iCqkdUo3gyRHpXcSLQHvyWU3RL5qLv/V0k+EwxS0zWwtIg9XBMm RDUVWkuvuktJfYoS0VWHBdg9jfCuyo9zT3W8oFXayhuYAzKZAoJci6/kde5RdCmg72W505x3ll AyPPzlJAkMkI7JA+XJgyuGXACbUEOiKAMGcWon9gATV0/ec6JCX+ni+K+5OSEOOBI9fqiVBNrD 27HNenVjncaww5TJhc8GKFlpGur2Yno/aof//dPhBO2LdnvdyuzHQNuBxS6l52hkXKRlRduARP yvY= X-IronPort-AV: E=Sophos;i="5.79,339,1602518400"; d="scan'208";a="161629294" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 07:45:21 +0800 IronPort-SDR: ak3VxDn+ntEkblC/4kJpxTIC21vdjyXmGdIt/9dM7WvY3WrvrLTRMeo2LUrfCvhbBqiFqOzLMm hcoU8sMmGyL8ik19kdV2NzjtXGcOjoLwwI2JKq5J1tsxGTlms91FeYELmfDybQlzKN3luKLspH VLui4PCzD2q30lz4Ei8kOXtAEyG/zRDwY7ikCB1Wa8I1Dbma07E6qwzIfpu1gW9tfuNAk6kYcr rml2h915VzVmV0ZZXtAV6hf4ZFHJ7pDxM29+K1In3y2BdoVyOk+jJR/KLPW/LQ2It5X6ap7eQJ XI0C6rskKBZ86cXVHtMrGo6o Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 15:30:07 -0800 IronPort-SDR: zFde0dV1F7ht98QYkLAXJBORMAjs7tHP3IEAYTIWsA4CUz13AiLqT4r5/9B7sGzVCQj6Arl1F+ BOv2cKIrsO9wh6aJHd+ew9712SjYCDn0RdQBli4/sR3xKuEMybGbGBoNnXV/664RTCo8k/cbjq 5D3ZdxYmNucNrCFlp7lNQR6mloDBG1f0AsjygumfCSo3sF5hl289xRO2iMVxG4Q2lqSvnxNboa YVd7oah5XAGLjlXnEhZl//krMn/kjLrO9ITDtYEn7cQKOTlKylcAgNuWteZ85PO9NI5iFkHLlo DrY= WDCIronportException: Internal Received: from usa002483.ad.shared (HELO jedi-01.hgst.com) ([10.86.62.194]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 15:45:21 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] RISC-V: Fix maximum allowed phsyical memory for RV32 Date: Mon, 11 Jan 2021 15:45:04 -0800 Message-Id: <20210111234504.3782179-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210111234504.3782179-1-atish.patra@wdc.com> References: <20210111234504.3782179-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210111_184527_694140_B98E7198 X-CRM114-Status: GOOD ( 12.93 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Albert Ou , Anup Patel , linux-riscv@lists.infradead.org, Atish Patra , Palmer Dabbelt , Paul Walmsley , Andrew Morton , Ard Biesheuvel , Mike Rapoport Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Linux kernel can only map 1GB of address space for RV32 as the page offset is set to 0xC0000000. The current description in the Kconfig is confusing as it indicates that RV32 can support 2GB of physical memory. That is simply not true for current kernel. In future, a 2GB split support can be added to allow 2GB physical address space. Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- arch/riscv/Kconfig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 81b76d44725d..e9e2c1f0a690 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -137,7 +137,7 @@ config PA_BITS config PAGE_OFFSET hex - default 0xC0000000 if 32BIT && MAXPHYSMEM_2GB + default 0xC0000000 if 32BIT && MAXPHYSMEM_1GB default 0x80000000 if 64BIT && !MMU default 0xffffffff80000000 if 64BIT && MAXPHYSMEM_2GB default 0xffffffe000000000 if 64BIT && MAXPHYSMEM_128GB @@ -247,10 +247,12 @@ config MODULE_SECTIONS choice prompt "Maximum Physical Memory" - default MAXPHYSMEM_2GB if 32BIT + default MAXPHYSMEM_1GB if 32BIT default MAXPHYSMEM_2GB if 64BIT && CMODEL_MEDLOW default MAXPHYSMEM_128GB if 64BIT && CMODEL_MEDANY + config MAXPHYSMEM_1GB + bool "1GiB" config MAXPHYSMEM_2GB bool "2GiB" config MAXPHYSMEM_128GB