From patchwork Mon Dec 6 15:03:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12658695 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 8EAF7C433F5 for ; Mon, 6 Dec 2021 15:11:40 +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=ifyRSxFfAqEo79AExPGG4DLRFQo/rimurM93w8B7EX8=; b=3/h2B/vBRC/U4h foLRKXr/25oUfk/XSsnn75zAhFKGJ2Rc5uHdoQtl1ttqtdm60sCKYlCfnTOQA79mvjJ5DFlF67SGO 7gOptRWFlJ7uL4Xji2+Mj/iuurQFwW8yeb5BqG/qlMAl2QxEIGUMCxR/Enx4/AQhlQ0LzQQPdZCjV /4ML4m3/I6C3HwjmJkxxxx/RGlWTAgXtScPb/QA92v3vyzFE1XKUvaQRwEvftpdRT8Mh85YvLBDFU 30q2zG7hWWoS/gF2PS2T12RFk3vPjYnZrkQnkq3owQxWdHwTmpuzxPtEBfXPmafvXpAsj87E+GJxz KC/anzK7hMJAH1gTnzVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muFeP-004PwD-6U; Mon, 06 Dec 2021 15:11:33 +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 1muFe0-004Ply-GI for linux-riscv@lists.infradead.org; Mon, 06 Dec 2021 15:11:09 +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 C721D61333; Mon, 6 Dec 2021 15:11:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF9BAC341C2; Mon, 6 Dec 2021 15:11:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638803467; bh=U/XXFOPv34D0TreArL806EvYm/WhdZkqjsAHo+8vbsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBppVPtQwwPnjYq9/6k76KsKhYGK5RsaltsWG1YuSDnb7xcbYZbfQ5XzxyNhKDHqa fmCyFVFCpPtaV10H4fZ8c/FpDQWseyd2lMLsvQyBICW9MQ2757wa9EeZkujWDrJmCg EcqlKVctM3diiIjRJ6thMJf7bT3QPXsNGwhD299Xhn0/xqn0J8cYJxbFabx8SrsYad PSn+9AHoGImkjMbVZOT345oy2WPGJneTdrSGxTSYkz0IlX40nVoa0uzeK9yOP/ODa+ swlP6vu6ma/Vm27tTxf2wdDpn8EecfM3YxTQkvG4a1hDS0s5BM49OLxQ//O03VzCuf q4KGrMxjH6eRA== 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 v2 1/5] riscv: mm: init: remove unnecessary "#ifdef CONFIG_CRASH_DUMP" Date: Mon, 6 Dec 2021 23:03:49 +0800 Message-Id: <20211206150353.731-2-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206150353.731-1-jszhang@kernel.org> References: <20211206150353.731-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_071108_681585_FB723FB7 X-CRM114-Status: UNSURE ( 9.67 ) X-CRM114-Notice: Please train this message. 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 Mon Dec 6 15:03:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12658697 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 00BA6C433EF for ; Mon, 6 Dec 2021 15:11: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=XDcXJBdaAYYOdF8TGr0gkF9Ii9lZsutbQZhUc6xmV5Q=; b=XbEYWUv1oWfyTP XOho9gX9D2/anMY2LRzlYrNBW14YfPtXqLfAVLeLm3m7h4TLi6Y+fvDs+WOT/QhIZ5845D7Heyb2f v5rsQwAfFrXYbf8Umw/LPH/5Ipsd8GlaUKmNB5uWRaCYbXkhc4ItJPQqT7gfCjYZZD8c/Q9/IBbqO UNgcrIj/5vZDqzUWK+rRZzHzeMV6XW5zgs7REvgBv/JMnmLPtKxDqyyeYFM1ok1ykBGPe/V5xUGNb LyByTCGj5Hcn3uLpj1aLCOH6htlTQ3ertvMfjL6eI9byK24H3vMrefFiSjSQp15siKOm9EeuqUSfq VmNjDePDQDDzRrl1U8ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muFec-004Q0l-6W; Mon, 06 Dec 2021 15:11:46 +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 1muFe3-004PnQ-77 for linux-riscv@lists.infradead.org; Mon, 06 Dec 2021 15:11:13 +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 66A5661350; Mon, 6 Dec 2021 15:11:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89399C341C7; Mon, 6 Dec 2021 15:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638803470; bh=PMuqe3y8e62TGMx9fT9SI7a0texE/fpdhxmGzV4QNBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=adb9B8P7wG+P4wrqu85rqV3GqjOBN8bzPVgty4k6NmTXbBHxMV9CQaR3HT1c+L9g2 FExw9UOrsJz9gL9MWTPkfliKJQyC51LMWZwCSR9eotpseIT6FS5mWeMPfXEPCDF/vx lrU75KGKtHjSuxYFJ2HPJeGOYH7U0CLMDKEL9o91BL3HuNa8opE42mj1moMN1x+FKR Y/cabVcsmWcODaqMCbcwXlKkPZ/dZ1Rg+iaXp/kjk/ojSFj9ZdXa6MIiAisYG2YW3l TxXVrHUHofZ1M4+dmn3inRZLcB3hEnuzX47njpV3XBW8tPrNeXS/VRPx1aOE6D/3hy 10TMMYcFxfJMg== 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 v2 2/5] riscv: mm: init: try best to use IS_ENABLED(CONFIG_64BIT) instead of #ifdef Date: Mon, 6 Dec 2021 23:03:50 +0800 Message-Id: <20211206150353.731-3-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206150353.731-1-jszhang@kernel.org> References: <20211206150353.731-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_071111_451762_378F8477 X-CRM114-Status: GOOD ( 19.41 ) 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. Now we can also remove the __maybe_unused used in max_mapped_addr declaration. We also remove the BUG_ON check of mapping the last 4K bytes of the addressable memory since this is always true for every kernel actually. Signed-off-by: Jisheng Zhang Reviewed-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 745f26a3b02e..4edf5600bea9 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) { } @@ -163,7 +162,7 @@ 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 max_mapped_addr; phys_addr_t phys_ram_end; #ifdef CONFIG_XIP_KERNEL @@ -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,14 +614,6 @@ 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 - pt_ops.alloc_pte = alloc_pte_early; pt_ops.get_pte_virt = get_pte_virt_early; #ifndef __PAGETABLE_PMD_FOLDED @@ -735,10 +725,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 Mon Dec 6 15:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12658699 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 F0F6BC433F5 for ; Mon, 6 Dec 2021 15:12:03 +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=Fu7wOzzgDh1etw0YcDm7rAt3dQaGVmrOfms6clcLi24=; b=10w4layFcKiUdH IiZhr15iOfATXEy9vkeWPjFv8w6uF7M02ePXw0JloUZcaFR96/wiL5RgiXY4hSR83+QDbdkoX12et MBTqZqHqh7pp9k7PkVpzbuDv7PhOZjJ5+p5jzwHdi1p8JphwRRymeKKPobg+0j6NR/XVJPbIcyHn4 1LBke6NIC2r/mXY/azbMOdiF9q9PowFkQa2ZDyqw2SzQd6KgmO4XFr9SkARKopxf8B3cISKJaj5TG hKXcnM34IWRf8Pd6pp4G5cf0E/FmNAJMLLD5YDNaHd3mDUo7qssYVcF7813LyNL6vTl3XalxbZ9bq Qg1MxeLQuJriAZaps8CA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muFem-004Q4o-57; Mon, 06 Dec 2021 15:11:56 +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 1muFe6-004Pon-10 for linux-riscv@lists.infradead.org; Mon, 06 Dec 2021 15:11:15 +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 6542A6132C; Mon, 6 Dec 2021 15:11:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B38DDC341C9; Mon, 6 Dec 2021 15:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638803472; bh=X4sDq1AysZLgZ/CXaf2/6j6xZAfoF8ID51G9Lzvmb9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ehl/4Ziqd/eXWLxbnMmRqC7wPoiimhuy5+C1OlIZYMrvbQEUQ9k3uPtTyR1WfEvXj 59UcE96mzT0QQJFHqgXKLfnUcjCUUzrytNmULKwayMyL+gjUB/IPD5/26O+zu3iUl4 ueDPkGzfs7v7NxcABOsM0atdwNdH9RrY65sHfIFy/eWcuLenwYGWiIKOmvG7CHut5Q lYGq7vdyPSM7ByTpCHgoa7mlt7Yf2VRAF613/48JRgTA6qWFGyXXVUGFEiH1SsDCzf d76TmMHRrjRcfyP12p8WOTf3JvM8g3WuvesC3kLwfmSvIw9gJx4R59M4UoNuGIQ6UE Olx3rUcwrl63w== 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 v2 3/5] riscv: mm: init: remove _pt_ops and use pt_ops directly Date: Mon, 6 Dec 2021 23:03:51 +0800 Message-Id: <20211206150353.731-4-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206150353.731-1-jszhang@kernel.org> References: <20211206150353.731-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_071114_138101_BEA22892 X-CRM114-Status: GOOD ( 10.03 ) 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 Reviewed-by: Alexandre Ghiti --- 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 4edf5600bea9..9c5816971f40 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 Mon Dec 6 15:03:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12658701 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 4512FC433F5 for ; Mon, 6 Dec 2021 15:12:12 +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=EIL9lEq6a4qf9k8uyA9eiFrcWL6IXa6VsxDcgqFnFeA=; b=xwZIvo3oN/0ANa n+RAGbsEKKsgO5U9o6JvWpEKye0FjNm1IY+z6aQl075m6NHMa8wUDv+yrLfiLOOoX+643MC3FGDbi OPFMzhGJVSWixJFpKnsS/ihMG+GmQJEpKkKVhxUnkolD2vAA4iHE0qZwYj9ezWhZIe21CxN0D6Pl+ fVSeU7xi5ovblXgAWGUCeUOOtMEZiawDn0w/Z9nP5ij2VeQBVswtVNKF/NH602qrghJJXSU/G9A5r jlVh9fgXK1n1baoUrU/8SUjorVRQk/n9c51f2vcyed5p8USjYGaBjKODz0tSqH+hX7PLjzZXvoM5c BoeJTxqaQtKhLXJzOXzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muFeu-004QA1-TA; Mon, 06 Dec 2021 15:12:05 +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 1muFeA-004Pq5-Bm for linux-riscv@lists.infradead.org; Mon, 06 Dec 2021 15:11:19 +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 068E3B81018; Mon, 6 Dec 2021 15:11:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52BE1C341C2; Mon, 6 Dec 2021 15:11:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638803475; bh=YYjWVRV3U9MP8993oG6RsEXcX9rrLfWp3/tBMtaj+kw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kIPOtVJ0TSZca6iqQIoXetm9b3tQgBOJ5YUXwqPlmAPyNrZT7HEZwm9bl0I3smvuI FqdymKoWkb5iTU9ivhoCw+iwYMewOQd52G+Md5X9QZA37EmKoGFVTUPLhMY1aiM8d0 QbNbX8nWAz9dq+rUNmp5Odsocjgc3dOFLvIQxh43coEiSV7kB3gdHAtp8H6/wqsAZ5 1J7tgKWUs6t0HmBcmCiCCTurvZdu+2CvfTyUtH5m9kH831G2wT8YcFGzXF6XfO+lzb rxfUlBVC/+aBLf4vObDPFSIghnXYN78GJwZA/KMrcMqPZBY2ntihl7O3fzLc9+Rktk zLTIhH/2mynaw== 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 v2 4/5] riscv: mm: init: try IS_ENABLED(CONFIG_XIP_KERNEL) instead of #ifdef Date: Mon, 6 Dec 2021 23:03:52 +0800 Message-Id: <20211206150353.731-5-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206150353.731-1-jszhang@kernel.org> References: <20211206150353.731-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_071118_581891_9ECDB7A2 X-CRM114-Status: GOOD ( 11.92 ) 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 9c5816971f40..5e979fe06054 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 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 Mon Dec 6 15:03:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12658703 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 2F305C433F5 for ; Mon, 6 Dec 2021 15:12:19 +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=5WIstfTUXMVQ1uBCcYq0RfGDkfuHIDO48eCenIrrpIY=; b=20JnVhEXZPq1jY qvAERtMuApBhC6+DLGTMVvo1vjCsvZVnrUfve25YsmPe2vMZAnM7zyEd4Z8iluQKEFtgd2A1REWSy avC+SAj//y9blInWBG9pdc5JTn/R3f5U5c4dokBlNC+dqiaM5bD9S55hvo+aWV01UM9urYeWqJu+D voVTMxm/6L3aC06CMbddvHaj0ERQP/MqjDfUybSW8krpf6uB0+OuEXVC136mAlTRCMM6I1WRNdqHE OErgOVWFD3hapR1u41mZUOPfwvJ8xou1El6URbse16qaYsU/uGTyRc3WnE6Gb5yBjEEJSpU6fe5cT 7oPhM7a0PDXawE7eEfyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muFf1-004QEc-6I; Mon, 06 Dec 2021 15:12:11 +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 1muFeA-004Pqi-US for linux-riscv@lists.infradead.org; Mon, 06 Dec 2021 15:11:20 +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 7FFB3612D3; Mon, 6 Dec 2021 15:11:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 489E6C341C1; Mon, 6 Dec 2021 15:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1638803477; bh=cID293rOgxjQk8NRLMzApK7etdJF34/NNMH4sm9IXMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fWu8/JMImZoyUJs6SiSezgHt3fJjx8j+QwkTcrH+qv5XYo1Tp1aRa2ow/SGdQ1G26 g+jHZ/q6QQjZPvvWbCUlBXjZ60egZbb4Yb2aXl3afUegX/qC7f7FNIFkn1M+KlHgIc I3ATyqm/DcCf0Y7ix4xEP8RvCZ0+SC+3MEMDwau2l9wuWrnWs7onUDHOGnhwv2r3GG Rj4qKGwov368I4/KNuAEeMHyfT+VnoPU4BRsRNFNW4IasebXlje/xdWOCxmoBj2f0T oHViHwfTSQ8KbBX8LtnbRG9H5uDrsAPHaOOKTSWUsyacvfh8zX+p95RzUHd/OfcdMT wCZpJ3H52p7UQ== 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 v2 5/5] riscv: mm: init: try best to remove #ifdef CONFIG_XIP_KERNEL usage Date: Mon, 6 Dec 2021 23:03:53 +0800 Message-Id: <20211206150353.731-6-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206150353.731-1-jszhang@kernel.org> References: <20211206150353.731-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211206_071119_085910_9098EF9A X-CRM114-Status: GOOD ( 13.08 ) 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 type usage cases 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 5e979fe06054..a15640eeb334 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) {