Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5267052pxv; Wed, 21 Jul 2021 01:04:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0la6xRhVN5y43Kq4AicK197d/RF7Jh97/A++tiQmkLVGVLjJMtqLmmZz3IucJJg6nBBpC X-Received: by 2002:a92:b111:: with SMTP id t17mr24421989ilh.208.1626854662485; Wed, 21 Jul 2021 01:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626854662; cv=none; d=google.com; s=arc-20160816; b=PX3EvrJNxJzpuYmfahx3C+TUIFAhcbwjz+KJoeBxuT2GH9qHnqKRo3ETf52ZTYH6Ar NnYM7LSQ8RG+owJ/Eg7BJ9+GkjBg+Vwy6CN3t4pW2LyZpoa3ct72gUN7GPQ/aqeIJgVS WmIfXzLE55t2ElQR3RfIc5zZfccwFwMdHYWCzVF9H62Z4yDF7HyVlipW3enC1V92fuoX QGvdkVvK2RDoi6EmW5hZ36uo1xhSTGA6dhdqBoiEPfgZVLbRppbBKW5CxhT6bw+xXaMW Q+RAi4NmMGVGWLrYCHfSn8t25NNJtlk+j2xbjM7KJcMXcecCpCMCMUOy/h8fvABpRhAF qkag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vP7kxhx8qZAtYbaNxImypFQV8Th1Pr6gcmYfFrfONSU=; b=WlDH9Pe70ypAqYZSRL6ExGrRqz8kb4CwGdb2+aEqGg8spfSF92qTMTn8cqJ3brsbbR SZI7mwxG40+ScBoCbTaZtcneY75mOivSm4JhKjR3VO8qjwkhf+E655LbRrlcPR8taYhC tMFa/XJSqTBAGOOrLYAa/OUiKIKckse2tbrPpbsISSIbGNyjKbwKN30xI99faFJWoL5F BunuSzdKdanS2/fpuweweJDtk7lJGP9RzAsVzxLwAOaoiUNN28AmVKbDH+Lw6cZ0FnDK /FJPgFeFan8dIzBtOZIygZZWxCMCWDyaM6KW3EoYN3H03XqmmFYcgFlulo1HwI+1/Evw R3bw== ARC-Authentication-Results: i=1; mx.google.com; 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 l3si16394172iln.90.2021.07.21.01.04.10; Wed, 21 Jul 2021 01:04:22 -0700 (PDT) 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; 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 S234859AbhGUHVF (ORCPT + 99 others); Wed, 21 Jul 2021 03:21:05 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:60763 "EHLO relay4-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbhGUHUR (ORCPT ); Wed, 21 Jul 2021 03:20:17 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 02675E0005; Wed, 21 Jul 2021 08:00:44 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH -fixes 1/3] riscv: Get rid of CONFIG_PHYS_RAM_BASE in kernel physical address conversion Date: Wed, 21 Jul 2021 09:59:35 +0200 Message-Id: <20210721075937.696811-2-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210721075937.696811-1-alex@ghiti.fr> References: <20210721075937.696811-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The usage of CONFIG_PHYS_RAM_BASE for all kernel types was a mistake: this value is implementation-specific and this breaks the genericity of the RISC-V kernel. Fix this by introducing a new variable phys_ram_base that holds this value at runtime and use it in the kernel physical address conversion macro. Since this value is used only for XIP kernels, evaluate it only if CONFIG_XIP_KERNEL is set which in addition optimizes this macro for standard kernels at compile-time. Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/page.h | 7 ++++--- arch/riscv/mm/init.c | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index cca8764aed83..b0ca5058e7ae 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -103,6 +103,7 @@ struct kernel_mapping { }; extern struct kernel_mapping kernel_map; +extern phys_addr_t phys_ram_base; #ifdef CONFIG_64BIT #define is_kernel_mapping(x) \ @@ -113,9 +114,9 @@ extern struct kernel_mapping kernel_map; #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset)) #define kernel_mapping_pa_to_va(y) ({ \ unsigned long _y = y; \ - (_y >= CONFIG_PHYS_RAM_BASE) ? \ - (void *)((unsigned long)(_y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET) : \ - (void *)((unsigned long)(_y) + kernel_map.va_kernel_xip_pa_offset); \ + (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \ + (void *)((unsigned long)(_y) + kernel_map.va_kernel_xip_pa_offset) : \ + (void *)((unsigned long)(_y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \ }) #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 269fc648ef3d..4ebe7e19c2b8 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -36,6 +36,9 @@ EXPORT_SYMBOL(kernel_map); #define kernel_map (*(struct kernel_mapping *)XIP_FIXUP(&kernel_map)) #endif +phys_addr_t phys_ram_base __ro_after_init; +EXPORT_SYMBOL(phys_ram_base); + #ifdef CONFIG_XIP_KERNEL extern char _xiprom[], _exiprom[]; #endif @@ -153,7 +156,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 max_mapped_addr = __pa(~(ulong)0); - phys_addr_t dram_end; + phys_addr_t phys_ram_end; #ifdef CONFIG_XIP_KERNEL vmlinux_start = __pa_symbol(&_sdata); @@ -174,18 +177,21 @@ static void __init setup_bootmem(void) #endif memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); - dram_end = memblock_end_of_DRAM(); +#ifndef CONFIG_XIP_KERNEL + phys_ram_base = memblock_start_of_DRAM(); +#endif + phys_ram_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)) + if (max_mapped_addr == (phys_ram_end - 1)) memblock_set_current_limit(max_mapped_addr - 4096); - min_low_pfn = PFN_UP(memblock_start_of_DRAM()); - max_low_pfn = max_pfn = PFN_DOWN(dram_end); + min_low_pfn = PFN_UP(phys_ram_base); + max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end); dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn)); set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET); @@ -544,6 +550,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) kernel_map.xiprom = (uintptr_t)CONFIG_XIP_PHYS_ADDR; kernel_map.xiprom_sz = (uintptr_t)(&_exiprom) - (uintptr_t)(&_xiprom); + phys_ram_base = CONFIG_PHYS_RAM_BASE; kernel_map.phys_addr = (uintptr_t)CONFIG_PHYS_RAM_BASE; kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_sdata); -- 2.30.2