From patchwork Fri Dec 3 05:03:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12654283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20FD2C433FE for ; Fri, 3 Dec 2021 05:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V9puU65Ok444ZRmCIJ9mVXTQ2pYR3N/uy8BuAZZ6AVE=; b=4cogiOE3rnQrHu SctCF0zo8LZRM464LgN7XLvmbz+XHw+D24zjNN+abERL78+m7gPMc6EJlzabbFE4LR98+c19nTUAP mz0H/gwyiNZfwkW4+Dpsrn0tqpLOwgaBvjIU8BgF05yvi/8v66+3g8m1XbEBF/+LdBrhpS8C663ze UL4V/jAtrzzOd8T8sovjzbTQGJdq4u13gq5kRjKt9aRYYYfgc5dbMxWoVfcwNwQLi8kPJ+rKFkah2 Mhekykh7DpPCo49Wp3uArZD+eu7QBRgcvRWuBnCzIeE1AKihPx3C5OsNPU848ihCazrSVaDa6eCfe 480K4eQ5ojpCjgCc8zqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qD-00EKXa-5c; Fri, 03 Dec 2021 05:10:37 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0q9-00EKW6-Ov for linux-riscv@lists.infradead.org; Fri, 03 Dec 2021 05:10:35 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5995562945; Fri, 3 Dec 2021 05:10:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26A01C53FAD; Fri, 3 Dec 2021 05:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638508231; bh=wLyXrGyMh/xyPpvoTxp6H3MxZHIYwAnCnaLXA4jnF9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uqNMSnrDTGrcmtr8IHC95HsIFwNSqly0CyFS545X9YL2brKGOTnngM9u3Q/HxQScv 5FarSpg1+rmVsvh6UZ0J91dgpPUUFnx0VCs5/ewvCENGtTVJcDEtjUwWoQJVfjPCa9 lyYyakwky+J626KhimtR6qj02rHA7U3MMPW1/LExRft7obRuZocuwz1Ak6wiN0s/Xc pESAx4fDdmRKO0aDnyLCvyBlSz+CdWteYMHqV/oks63CE4ioh7eelzPfRxia/bnG5a I6RZOcD4T84bMYogORfOuNU9YVAimRsazktgurHOdvipiZOS+ohVBJXFvvW3tBeo+I hClQGX/iQW1SQ== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] riscv: mm: init: remove unnecessary "#ifdef CONFIG_CRASH_DUMP" Date: Fri, 3 Dec 2021 13:03:13 +0800 Message-Id: <20211203050317.2102-2-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211203050317.2102-1-jszhang@kernel.org> References: <20211203050317.2102-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_211033_870416_38376779 X-CRM114-Status: GOOD ( 10.17 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The is_kdump_kernel() returns false for !CRASH_DUMP case, so we don't need the #ifdef CONFIG_CRASH_DUMP for is_kdump_kernel() checking. Signed-off-by: Jisheng Zhang Reviewed-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 3c0649dba4ff..745f26a3b02e 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -790,12 +790,10 @@ static void __init reserve_crashkernel(void) * since it doesn't make much sense and we have limited memory * resources. */ -#ifdef CONFIG_CRASH_DUMP if (is_kdump_kernel()) { pr_info("crashkernel: ignoring reservation request\n"); return; } -#endif ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(), &crash_size, &crash_base); From patchwork Fri Dec 3 05:03:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12654285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88B63C433EF for ; Fri, 3 Dec 2021 05:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DSfchkk6O28DCmDA+bSqj6pM0vpH2XiPhiwKDhAUO6s=; b=PJpNAEUOYfctQj +mTxQlft3mQnG/pK82fCnCiQsRlWB+H2csAyQ9sqFFQDsbuKkazCQeHlrVDmjcjWHqTZqnAHxn7vF iJuKPhIUBGfGAn1dXQmi05L4oftosp/VYauh/y5LUACs/G9hOGsqOfw/AKORyqEoaH6QOrtcB+dUs 73Yb4NxEodxFgSt8BY4dr7G9v+/RwQ6VjMUNNDk5/9FdN+56tjj+iG86szJy20H2b9Jd0pOKsR+wq 14IlPWHKcLBJ+mZ9nY9+GKY0t/jryzrlEZG3t0ey4MvsoP6n2x0aPiIJmHJZ6Da7FGp/ZGaBJI4hx QTTRLOKyz9kFnsTRX2sQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qG-00EKZF-8S; Fri, 03 Dec 2021 05:10:40 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qC-00EKWq-C2 for linux-riscv@lists.infradead.org; Fri, 03 Dec 2021 05:10:38 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 26EB0B825BC; Fri, 3 Dec 2021 05:10:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FFE0C53FC7; Fri, 3 Dec 2021 05:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638508233; bh=GRUArS/X3eAh9AGo4JeyzRPeIZX+Cg5bYN3qsljQ9hM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OhGkOhGQd7bLfaV35RgDZP6VwmyrAy/yABZAM1nq71EohUpE0VWdDL9Zn9+4FV2P+ nowc0UGeb32pfWjLEvInSGeCV8TKsvo+rAWKLtqbyS4m/hmEpJZckK3QZMo05t4rvU Eo3f9G76GEAUUDu3UbeDFbDp9vuZAqaS/Nyw2T9bhscvtXZD0XlWnSPx/g/Agou/Oy 2304C6fYYxU2rp8C/d6OGW5i63nxjNTCwDw/1dzfIkfiwW7YEol9ext0fzVcWjJ32p lGMaoDBaZAO6esJX+VoyX3AjW8f9nM4xPhH7CbWc5BfKpHUcQ5FRLKbH2RF4ffjPFM SIWfvFSgc+Mag== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] riscv: mm: init: try best to IS_ENABLED(CONFIG_64BIT) instead of #ifdef Date: Fri, 3 Dec 2021 13:03:14 +0800 Message-Id: <20211203050317.2102-3-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211203050317.2102-1-jszhang@kernel.org> References: <20211203050317.2102-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_211036_717648_7C1A0CE7 X-CRM114-Status: GOOD ( 18.81 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Try our best to replace the conditional compilation using "#ifdef CONFIG_64BIT" by a check for "IS_ENABLED(CONFIG_64BIT)", to simplify the code and to increase compile coverage. Signed-off-by: Jisheng Zhang --- arch/riscv/mm/init.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 745f26a3b02e..bd445ac778a8 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -102,10 +102,9 @@ static void __init print_vm_layout(void) (unsigned long)VMALLOC_END); print_mlm("lowmem", (unsigned long)PAGE_OFFSET, (unsigned long)high_memory); -#ifdef CONFIG_64BIT - print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR, - (unsigned long)ADDRESS_SPACE_END); -#endif + if (IS_ENABLED(CONFIG_64BIT)) + print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR, + (unsigned long)ADDRESS_SPACE_END); } #else static void print_vm_layout(void) { } @@ -172,17 +171,16 @@ static void __init setup_bootmem(void) memblock_enforce_memory_limit(memory_limit); - /* - * Reserve from the start of the kernel to the end of the kernel - */ -#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) /* * Make sure we align the reservation on PMD_SIZE since we will * map the kernel in the linear mapping as read-only: we do not want * any allocation to happen between _end and the next pmd aligned page. */ - vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK; -#endif + if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) + vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK; + /* + * Reserve from the start of the kernel to the end of the kernel + */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); @@ -190,7 +188,6 @@ static void __init setup_bootmem(void) #ifndef CONFIG_XIP_KERNEL phys_ram_base = memblock_start_of_DRAM(); #endif -#ifndef CONFIG_64BIT /* * 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 @@ -200,10 +197,11 @@ static void __init setup_bootmem(void) * address space is occupied by the kernel mapping then this check must * be done as soon as the kernel mapping base address is determined. */ - max_mapped_addr = __pa(~(ulong)0); - if (max_mapped_addr == (phys_ram_end - 1)) - memblock_set_current_limit(max_mapped_addr - 4096); -#endif + if (!IS_ENABLED(CONFIG_64BIT)) { + max_mapped_addr = __pa(~(ulong)0); + if (max_mapped_addr == (phys_ram_end - 1)) + memblock_set_current_limit(max_mapped_addr - 4096); + } min_low_pfn = PFN_UP(phys_ram_base); max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end); @@ -616,13 +614,12 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0); -#ifdef CONFIG_64BIT /* * The last 4K bytes of the addressable memory can not be mapped because * of IS_ERR_VALUE macro. */ - BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K); -#endif + if (IS_ENABLED(CONFIG_64BIT)) + BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K); pt_ops.alloc_pte = alloc_pte_early; pt_ops.get_pte_virt = get_pte_virt_early; @@ -735,10 +732,9 @@ static void __init setup_vm_final(void) } } -#ifdef CONFIG_64BIT /* Map the kernel */ - create_kernel_page_table(swapper_pg_dir, false); -#endif + if (IS_ENABLED(CONFIG_64BIT)) + create_kernel_page_table(swapper_pg_dir, false); /* Clear fixmap PTE and PMD mappings */ clear_fixmap(FIX_PTE); From patchwork Fri Dec 3 05:03:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12654287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0FA9C433F5 for ; Fri, 3 Dec 2021 05:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ScsdENxZ6IDOUDaB3rd8mK8WQiE2cMyVp8srVbGSEhg=; b=qq0kJ9al7CJFrd GZjiAexiXb4ykg6fEdue49ssvkJ79GgsCXizwm2bzSUasKL04dUyjbEszApNsafcqkPX4hsmsyBTS gQcsFJ5Nge7pk+FXiFN34l6I3UmXI0XFiZLWtZWjYNL/N/uZSHhzBkFsSbifnCNJmiVNXtSzm2zdo CzeiYKAuAgI9GeYifuRNByJI+/BRL82v3FuQ2O+snVQBGLdW5uDChQDIZ1zqZkH396przmIP1Go2e tV2beGbZELFy6rAeUM1J4xAqRRpvXSFrE+rYiSV7S4flbgUB4ajZDrSVrY39xXf6/ey9gIR1OG6o9 deHYvr4Sku/PoLaFqvnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qI-00EKaV-BU; Fri, 03 Dec 2021 05:10:42 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qE-00EKXr-Fe for linux-riscv@lists.infradead.org; Fri, 03 Dec 2021 05:10:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3A728B81C9D; Fri, 3 Dec 2021 05:10:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C3BCC53FAD; Fri, 3 Dec 2021 05:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638508236; bh=Z9O0bsmRr34zqnd3Uvp4s5rM+blcuSgXDGFFVFUQkew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mr8jPQDEGXl+QN1k4OfnoglcVkDl2396AfCef8Jh2ewQWSdAg9Z7TRd9Tk1RZ8UnU EMyg9YIbn8xq7RapjYOw9sOyUfhffUG6DI6RmFkzPPR6dEiCiA2XkZtFAiQr8Mx9+k qQgnAHE5qPyVSfrt/mCW4IctFnd4eNH/gC6XW59lKLuIoS7V0R6RD8JPNX4mwyo1di fk1XWRg2MJ7vFQMp6+kFTNF8Ynk6FkcXdgLcOgPpjqE9vyAub2wUXLJgje40Pp1lwQ IaEY5uoWja9oar1QWrzVMjtl7TVd/Jb2vCwjltneZdVD9hGRjPwZoZk783qJeGZF8J WXDPZcq95/BJA== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] riscv: mm: init: remove _pt_ops and use pt_ops directly Date: Fri, 3 Dec 2021 13:03:15 +0800 Message-Id: <20211203050317.2102-4-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211203050317.2102-1-jszhang@kernel.org> References: <20211203050317.2102-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_211038_702404_57A469EE X-CRM114-Status: GOOD ( 10.52 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Except "pt_ops", other global vars when CONFIG_XIP_KERNEL=y is defined as below: |foo_type foo; |#ifdef CONFIG_XIP_KERNEL |#define foo (*(foo_type *)XIP_FIXUP(&foo)) |#endif Follow the same way for pt_ops to unify the style and to simplify code. Signed-off-by: Jisheng Zhang --- 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 bd445ac778a8..4d4fcd7ef1a9 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -227,12 +227,10 @@ static void __init setup_bootmem(void) } #ifdef CONFIG_MMU -static struct pt_alloc_ops _pt_ops __initdata; +static struct pt_alloc_ops pt_ops __initdata; #ifdef CONFIG_XIP_KERNEL -#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&_pt_ops)) -#else -#define pt_ops _pt_ops +#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops)) #endif unsigned long riscv_pfn_base __ro_after_init; From patchwork Fri Dec 3 05:03:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12654291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A487C4332F for ; Fri, 3 Dec 2021 05:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BBQ/1CdRFZZ424+cAPZSQiG7exHDhVd3c/WUYKmMK3Y=; b=WKoN75R3/HHgyx hS5otQ4x7mTwu4Pb5znQo/pYTbEVHDiDD5NEHm8Mii16aI+ZH6DRiZQw2lTCrC4dEQneAIZA0zu0Z 9udRyWq6g4HErA4AOx4XKmRQMHyA+rZivvO8w+YwJk2MebErN2CM+rRvXjeoTX8Kjjsyy3QkdPx0E vhrzAllkGT00Mw2D9lHRlyxJi/jcl+onNx6l3EUhfhOhtTLXA05mcV63MShLER2wNbtpqeyKS2d7C g/wbt9fgX1WNzQ/bOk2zavMdEbkzQgXylx7FirwMKT4UPgn3tQeoAwxEfV1/Q2dq6Am711GjSVQ48 6oAr4yeOepu77J1LMIBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qK-00EKcZ-Ti; Fri, 03 Dec 2021 05:10:44 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qE-00EKY3-Or for linux-riscv@lists.infradead.org; Fri, 03 Dec 2021 05:10:40 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 44A206295C; Fri, 3 Dec 2021 05:10:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78123C53FCE; Fri, 3 Dec 2021 05:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638508238; bh=B/zsYpq5+A4GvqC7QPKWBXDoi6KpkUlp/0uSJZbfvns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WD6Qtv0Sh02axx6BSHidc9fhCdMLUOK4Lec+xUPnxJ7D3vjMjl2Ryx+w3uazem6OL 6gB+d1URWrUBOBChJJdRbgDne9TOQMftsvmYyedqO6lv7WC6SxsB222hc2dk3W1Jv0 ZZE74zGZnewmIwTeAoqSLV3E43RRcevXkl93u/RK+VMj6O/e+A3Eu81HjL9/CaKVzo WRMBRO3yUp21rVVbpsgDea1jGM90d0lopTSi0CHHmzgHcJQlwFAE5jPqoZ6FvVzPOU fjxQ2Eyvq0VMZPj53GsOi43Q89K+VXG7rCc4WHQRX52O7cqozUyfFZ168oCojUr/G1 eRveUrGvgdt9Q== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] riscv: mm: init: try IS_ENABLED(CONFIG_XIP_KERNEL) instead of #ifdef Date: Fri, 3 Dec 2021 13:03:16 +0800 Message-Id: <20211203050317.2102-5-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211203050317.2102-1-jszhang@kernel.org> References: <20211203050317.2102-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_211038_881494_B2AC9DD3 X-CRM114-Status: GOOD ( 12.55 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Try our best to replace the conditional compilation using "#ifdef CONFIG_XIP_KERNEL" with "IS_ENABLED(CONFIG_XIP_KERNEL)", to simplify the code and to increase compile coverage. Signed-off-by: Jisheng Zhang Reviewed-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4d4fcd7ef1a9..4a9e3f429042 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -161,13 +161,13 @@ early_param("mem", early_mem); static void __init setup_bootmem(void) { phys_addr_t vmlinux_end = __pa_symbol(&_end); - phys_addr_t vmlinux_start = __pa_symbol(&_start); phys_addr_t __maybe_unused max_mapped_addr; - phys_addr_t phys_ram_end; + phys_addr_t phys_ram_end, vmlinux_start; -#ifdef CONFIG_XIP_KERNEL - vmlinux_start = __pa_symbol(&_sdata); -#endif + if (IS_ENABLED(CONFIG_XIP_KERNEL)) + vmlinux_start = __pa_symbol(&_sdata); + else + vmlinux_start = __pa_symbol(&_start); memblock_enforce_memory_limit(memory_limit); @@ -183,11 +183,9 @@ static void __init setup_bootmem(void) */ memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); - phys_ram_end = memblock_end_of_DRAM(); -#ifndef CONFIG_XIP_KERNEL - phys_ram_base = memblock_start_of_DRAM(); -#endif + if (!IS_ENABLED(CONFIG_XIP_KERNEL)) + phys_ram_base = memblock_start_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 From patchwork Fri Dec 3 05:03:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12654289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5621C433FE for ; Fri, 3 Dec 2021 05:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=POHCxCGRriX8pjhgNlZG/ZLGTke+KyPe0JV6B/07UUk=; b=lxq8Qo+BjzWUmb If2CYw8colbGYKa4JsiLabkPVIqFWPHZKVAD8wW+MiBkK/uS6MxW+bhb2EbXL1UwEPDc06w5/tCzh 0fBMs1UauSTyy1srxlW0FN02mQQBGnQXm5fWrZZuNPabSGQqis/hbSSUROgUvEfK4s/7CEBDJ7ajl xae74jdeFn7o493Em+C327Yt0P3WmbkJ8pxw90TK306v2b28heyGQaP7TgqCN21/PgckXmzZoGyH1 w4U6uS2uHEKO+inGwtYOevznB+hqPYF/VwLYASBO+SOeyb34KiWwSSzJFFRKKxED3zgalhEAb9drP zJYrGCxGeO2TPlJnbYRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qN-00EKeU-3b; Fri, 03 Dec 2021 05:10:47 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mt0qI-00EKZv-8T for linux-riscv@lists.infradead.org; Fri, 03 Dec 2021 05:10:44 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E3327B825BF; Fri, 3 Dec 2021 05:10:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FF8FC53FD0; Fri, 3 Dec 2021 05:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638508240; bh=j6qwodVLZiWt9IpyiJJj3SUWjAMFCthwug2fOloP0/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CqTIyc9z96ALtOxRoJnCEOlxP/ZL6Xw7Hd/QCgWp405EdVaBoz5JiQiQ6i/vxp+Xj a3VtlCHlDgGwxs207HoKWG/Fc//q5xMzzCPzT2z0lKwKRPRyH4BHA+dGY6v389JdDr utTefIz+iBFD6vIUOvfWMvmojVZGvNcKYLBxzRZEg8nBlP1/43/7VdOqZ23BAyAxGL YP93jM4gn3zOfky/azAZ+8EClmQF7sSAdosN+8HIHIuxFP/NBAccQW+jojXMaf40Fa mqb/7Wrq0CyDbxfC2qOTKzDOTV8gyKuKOvtEB+tAp8e55VJ9qayW+H+pw87bKds3xk XfEUG0IFq3DNw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] riscv: mm: init: try best to remove #ifdef CONFIG_XIP_KERNEL usage Date: Fri, 3 Dec 2021 13:03:17 +0800 Message-Id: <20211203050317.2102-6-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211203050317.2102-1-jszhang@kernel.org> References: <20211203050317.2102-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_211042_484334_42FA6833 X-CRM114-Status: GOOD ( 13.58 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, the #ifdef CONFIG_XIP_KERNEL usage can be divided into the following three types: The first one is for functions/declarations only used in XIP case. The second one is for XIP_FIXUP case. Something as below: |foo_type foo; |#ifdef CONFIG_XIP_KERNEL |#define foo (*(foo_type *)XIP_FIXUP(&foo)) |#endif Usually, it's better to let the foo macro sit with the foo var together. But if various foos are defined adjacently, we can save some #ifdef CONFIG_XIP_KERNEL usage by grouping them together. The third one is for different implementations for XIP, usually, this is a #ifdef...#else...#endif case. This patch moves the pt_ops macro to adjacent #ifdef CONFIG_XIP_KERNEL and group first usage case into one. Signed-off-by: Jisheng Zhang Reviewed-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4a9e3f429042..aeae7d6b2fee 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -40,10 +40,6 @@ EXPORT_SYMBOL(kernel_map); phys_addr_t phys_ram_base __ro_after_init; EXPORT_SYMBOL(phys_ram_base); -#ifdef CONFIG_XIP_KERNEL -extern char _xiprom[], _exiprom[], __data_loc; -#endif - unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; EXPORT_SYMBOL(empty_zero_page); @@ -227,10 +223,6 @@ static void __init setup_bootmem(void) #ifdef CONFIG_MMU static struct pt_alloc_ops pt_ops __initdata; -#ifdef CONFIG_XIP_KERNEL -#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops)) -#endif - unsigned long riscv_pfn_base __ro_after_init; EXPORT_SYMBOL(riscv_pfn_base); @@ -242,6 +234,7 @@ pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE); static pmd_t __maybe_unused early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE); #ifdef CONFIG_XIP_KERNEL +#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&pt_ops)) #define trampoline_pg_dir ((pgd_t *)XIP_FIXUP(trampoline_pg_dir)) #define fixmap_pte ((pte_t *)XIP_FIXUP(fixmap_pte)) #define early_pg_dir ((pgd_t *)XIP_FIXUP(early_pg_dir)) @@ -445,6 +438,8 @@ static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) } #ifdef CONFIG_XIP_KERNEL +extern char _xiprom[], _exiprom[], __data_loc; + /* called from head.S with MMU off */ asmlinkage void __init __copy_data(void) {