From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 04649C433B4 for ; Thu, 15 Apr 2021 04:54:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0282D61152 for ; Thu, 15 Apr 2021 04:54:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0282D61152 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 891936B0036; Thu, 15 Apr 2021 00:54:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81A476B006C; Thu, 15 Apr 2021 00:54:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66D1D6B0070; Thu, 15 Apr 2021 00:54:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 421206B0036 for ; Thu, 15 Apr 2021 00:54:35 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F0AD6180ACF6C for ; Thu, 15 Apr 2021 04:54:34 +0000 (UTC) X-FDA: 78033385668.27.CD9EAE9 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by imf07.hostedemail.com (Postfix) with ESMTP id 9857BA0000FF for ; Thu, 15 Apr 2021 04:54:33 +0000 (UTC) X-Originating-IP: 2.7.49.219 Received: from [192.168.1.100] (lfbn-lyo-1-457-219.w2-7.abo.wanadoo.fr [2.7.49.219]) (Authenticated sender: alex@ghiti.fr) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 4BBB7E0002; Thu, 15 Apr 2021 04:54:25 +0000 (UTC) Subject: Re: [PATCH v5 1/3] riscv: Move kernel mapping outside of linear mapping To: Palmer Dabbelt Cc: corbet@lwn.net, Paul Walmsley , aou@eecs.berkeley.edu, Arnd Bergmann , aryabinin@virtuozzo.com, glider@google.com, dvyukov@google.com, linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-mm@kvack.org References: From: Alex Ghiti Message-ID: <76353fc0-f734-db47-0d0c-f0f379763aa0@ghiti.fr> Date: Thu, 15 Apr 2021 00:54:25 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9857BA0000FF X-Stat-Signature: nnkwtaeru9tgt7brk6a11kf9cg9m7b7j Received-SPF: none (ghiti.fr>: No applicable sender policy available) receiver=imf07; identity=mailfrom; envelope-from=""; helo=relay4-d.mail.gandi.net; client-ip=217.70.183.196 X-HE-DKIM-Result: none/none X-HE-Tag: 1618462473-63542 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Le 4/15/21 =C3=A0 12:20 AM, Palmer Dabbelt a =C3=A9crit=C2=A0: > On Sun, 11 Apr 2021 09:41:44 PDT (-0700), alex@ghiti.fr wrote: >> This is a preparatory patch for relocatable kernel and sv48 support. >> >> The kernel used to be linked at PAGE_OFFSET address therefore we could= =20 >> use >> the linear mapping for the kernel mapping. But the relocated kernel ba= se >> address will be different from PAGE_OFFSET and since in the linear=20 >> mapping, >> two different virtual addresses cannot point to the same physical=20 >> address, >> the kernel mapping needs to lie outside the linear mapping so that we=20 >> don't >> have to copy it at the same physical offset. >> >> The kernel mapping is moved to the last 2GB of the address space, BPF >> is now always after the kernel and modules use the 2GB memory range ri= ght >> before the kernel, so BPF and modules regions do not overlap. KASLR >> implementation will simply have to move the kernel in the last 2GB ran= ge >> and just take care of leaving enough space for BPF. >> >> In addition, by moving the kernel to the end of the address space, bot= h >> sv39 and sv48 kernels will be exactly the same without needing to be >> relocated at runtime. >> >> Suggested-by: Arnd Bergmann >> Signed-off-by: Alexandre Ghiti >> --- >> =C2=A0arch/riscv/boot/loader.lds.S=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 |=C2=A0 3 +- >> =C2=A0arch/riscv/include/asm/page.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= | 17 +++++- >> =C2=A0arch/riscv/include/asm/pgtable.h=C2=A0=C2=A0=C2=A0 | 37 ++++++++= ---- >> =C2=A0arch/riscv/include/asm/set_memory.h |=C2=A0 1 + >> =C2=A0arch/riscv/kernel/head.S=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 3 +- >> =C2=A0arch/riscv/kernel/module.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0 6 +- >> =C2=A0arch/riscv/kernel/setup.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0 5 ++ >> =C2=A0arch/riscv/kernel/vmlinux.lds.S=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 = 3 +- >> =C2=A0arch/riscv/mm/fault.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 13 +++++ >> =C2=A0arch/riscv/mm/init.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 87 ++++++++++++++++++++++= ------- >> =C2=A0arch/riscv/mm/kasan_init.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0 9 +++ >> =C2=A0arch/riscv/mm/physaddr.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 +- >> =C2=A012 files changed, 146 insertions(+), 40 deletions(-) >> >> diff --git a/arch/riscv/boot/loader.lds.S b/arch/riscv/boot/loader.lds= .S >> index 47a5003c2e28..62d94696a19c 100644 >> --- a/arch/riscv/boot/loader.lds.S >> +++ b/arch/riscv/boot/loader.lds.S >> @@ -1,13 +1,14 @@ >> =C2=A0/* SPDX-License-Identifier: GPL-2.0 */ >> >> =C2=A0#include >> +#include >> >> =C2=A0OUTPUT_ARCH(riscv) >> =C2=A0ENTRY(_start) >> >> =C2=A0SECTIONS >> =C2=A0{ >> -=C2=A0=C2=A0=C2=A0 . =3D PAGE_OFFSET; >> +=C2=A0=C2=A0=C2=A0 . =3D KERNEL_LINK_ADDR; >> >> =C2=A0=C2=A0=C2=A0=C2=A0 .payload : { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *(.payload) >> diff --git a/arch/riscv/include/asm/page.h=20 >> b/arch/riscv/include/asm/page.h >> index adc9d26f3d75..22cfb2be60dc 100644 >> --- a/arch/riscv/include/asm/page.h >> +++ b/arch/riscv/include/asm/page.h >> @@ -90,15 +90,28 @@ typedef struct page *pgtable_t; >> >> =C2=A0#ifdef CONFIG_MMU >> =C2=A0extern unsigned long va_pa_offset; >> +extern unsigned long va_kernel_pa_offset; >> =C2=A0extern unsigned long pfn_base; >> =C2=A0#define ARCH_PFN_OFFSET=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (pfn_base) >> =C2=A0#else >> =C2=A0#define va_pa_offset=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0 >> +#define va_kernel_pa_offset=C2=A0=C2=A0=C2=A0 0 >> =C2=A0#define ARCH_PFN_OFFSET=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (PAGE_OFFSET >> PAGE_SHIFT) >> =C2=A0#endif /* CONFIG_MMU */ >> >> -#define __pa_to_va_nodebug(x)=C2=A0=C2=A0=C2=A0 ((void *)((unsigned l= ong) (x) +=20 >> va_pa_offset)) >> -#define __va_to_pa_nodebug(x)=C2=A0=C2=A0=C2=A0 ((unsigned long)(x) -= va_pa_offset) >> +extern unsigned long kernel_virt_addr; >> + >> +#define linear_mapping_pa_to_va(x)=C2=A0=C2=A0=C2=A0 ((void *)((unsig= ned long)(x) +=20 >> va_pa_offset)) >> +#define kernel_mapping_pa_to_va(x)=C2=A0=C2=A0=C2=A0 ((void *)((unsig= ned long)(x) +=20 >> va_kernel_pa_offset)) >> +#define __pa_to_va_nodebug(x)=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= linear_mapping_pa_to_va(x) >> + >> +#define linear_mapping_va_to_pa(x)=C2=A0=C2=A0=C2=A0 ((unsigned long)= (x) -=20 >> va_pa_offset) >> +#define kernel_mapping_va_to_pa(x)=C2=A0=C2=A0=C2=A0 ((unsigned long)= (x) -=20 >> va_kernel_pa_offset) >> +#define __va_to_pa_nodebug(x)=C2=A0=C2=A0=C2=A0 ({=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0 unsigned long _x =3D x;=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0 (_x < kernel_virt_addr) ?=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 linear_mapping_va_to_pa(_x= ) : kernel_mapping_va_to_pa(_x);=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0 }) >> >> =C2=A0#ifdef CONFIG_DEBUG_VIRTUAL >> =C2=A0extern phys_addr_t __virt_to_phys(unsigned long x); >> diff --git a/arch/riscv/include/asm/pgtable.h=20 >> b/arch/riscv/include/asm/pgtable.h >> index ebf817c1bdf4..80e63a93e903 100644 >> --- a/arch/riscv/include/asm/pgtable.h >> +++ b/arch/riscv/include/asm/pgtable.h >> @@ -11,23 +11,30 @@ >> >> =C2=A0#include >> >> -#ifndef __ASSEMBLY__ >> - >> -/* Page Upper Directory not used in RISC-V */ >> -#include >> -#include >> -#include >> -#include >> +#ifndef CONFIG_MMU >> +#define KERNEL_LINK_ADDR=C2=A0=C2=A0=C2=A0 PAGE_OFFSET >> +#else >> >> -#ifdef CONFIG_MMU >> +#define ADDRESS_SPACE_END=C2=A0=C2=A0=C2=A0 (UL(-1)) >> +/* >> + * Leave 2GB for kernel and BPF at the end of the address space >> + */ >> +#define KERNEL_LINK_ADDR=C2=A0=C2=A0=C2=A0 (ADDRESS_SPACE_END - SZ_2G= + 1) >> >> =C2=A0#define VMALLOC_SIZE=C2=A0=C2=A0=C2=A0=C2=A0 (KERN_VIRT_SIZE >> = 1) >> =C2=A0#define VMALLOC_END=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (PAGE_OFFSET -= 1) >> =C2=A0#define VMALLOC_START=C2=A0=C2=A0=C2=A0 (PAGE_OFFSET - VMALLOC_S= IZE) >> >> +/* KASLR should leave at least 128MB for BPF after the kernel */ >> =C2=A0#define BPF_JIT_REGION_SIZE=C2=A0=C2=A0=C2=A0 (SZ_128M) >> -#define BPF_JIT_REGION_START=C2=A0=C2=A0=C2=A0 (PAGE_OFFSET - BPF_JIT= _REGION_SIZE) >> -#define BPF_JIT_REGION_END=C2=A0=C2=A0=C2=A0 (VMALLOC_END) >> +#define BPF_JIT_REGION_START=C2=A0=C2=A0=C2=A0 PFN_ALIGN((unsigned lo= ng)&_end) >> +#define BPF_JIT_REGION_END=C2=A0=C2=A0=C2=A0 (BPF_JIT_REGION_START +=20 >> BPF_JIT_REGION_SIZE) >> + >> +/* Modules always live before the kernel */ >> +#ifdef CONFIG_64BIT >> +#define MODULES_VADDR=C2=A0=C2=A0=C2=A0 (PFN_ALIGN((unsigned long)&_e= nd) - SZ_2G) >> +#define MODULES_END=C2=A0=C2=A0=C2=A0 (PFN_ALIGN((unsigned long)&_sta= rt)) >> +#endif >> >> =C2=A0/* >> =C2=A0 * Roughly size the vmemmap space to be large enough to fit enou= gh >> @@ -57,9 +64,16 @@ >> =C2=A0#define FIXADDR_SIZE=C2=A0=C2=A0=C2=A0=C2=A0 PGDIR_SIZE >> =C2=A0#endif >> =C2=A0#define FIXADDR_START=C2=A0=C2=A0=C2=A0 (FIXADDR_TOP - FIXADDR_S= IZE) >> - >> =C2=A0#endif >> >> +#ifndef __ASSEMBLY__ >> + >> +/* Page Upper Directory not used in RISC-V */ >> +#include >> +#include >> +#include >> +#include >> + >> =C2=A0#ifdef CONFIG_64BIT >> =C2=A0#include >> =C2=A0#else >> @@ -484,6 +498,7 @@ static inline int ptep_clear_flush_young(struct=20 >> vm_area_struct *vma, >> >> =C2=A0#define kern_addr_valid(addr)=C2=A0=C2=A0 (1) /* FIXME */ >> >> +extern char _start[]; >> =C2=A0extern void *dtb_early_va; >> =C2=A0extern uintptr_t dtb_early_pa; >> =C2=A0void setup_bootmem(void); >> diff --git a/arch/riscv/include/asm/set_memory.h=20 >> b/arch/riscv/include/asm/set_memory.h >> index 6887b3d9f371..a9c56776fa0e 100644 >> --- a/arch/riscv/include/asm/set_memory.h >> +++ b/arch/riscv/include/asm/set_memory.h >> @@ -17,6 +17,7 @@ int set_memory_x(unsigned long addr, int numpages); >> =C2=A0int set_memory_nx(unsigned long addr, int numpages); >> =C2=A0int set_memory_rw_nx(unsigned long addr, int numpages); >> =C2=A0void protect_kernel_text_data(void); >> +void protect_kernel_linear_mapping_text_rodata(void); >> =C2=A0#else >> =C2=A0static inline int set_memory_ro(unsigned long addr, int numpages= ) {=20 >> return 0; } >> =C2=A0static inline int set_memory_rw(unsigned long addr, int numpages= ) {=20 >> return 0; } >> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S >> index f5a9bad86e58..6cb05f22e52a 100644 >> --- a/arch/riscv/kernel/head.S >> +++ b/arch/riscv/kernel/head.S >> @@ -69,7 +69,8 @@ pe_head_start: >> =C2=A0#ifdef CONFIG_MMU >> =C2=A0relocate: >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Relocate return address */ >> -=C2=A0=C2=A0=C2=A0 li a1, PAGE_OFFSET >> +=C2=A0=C2=A0=C2=A0 la a1, kernel_virt_addr >> +=C2=A0=C2=A0=C2=A0 REG_L a1, 0(a1) >> =C2=A0=C2=A0=C2=A0=C2=A0 la a2, _start >> =C2=A0=C2=A0=C2=A0=C2=A0 sub a1, a1, a2 >> =C2=A0=C2=A0=C2=A0=C2=A0 add ra, ra, a1 >> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c >> index 104fba889cf7..ce153771e5e9 100644 >> --- a/arch/riscv/kernel/module.c >> +++ b/arch/riscv/kernel/module.c >> @@ -408,12 +408,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const=20 >> char *strtab, >> =C2=A0} >> >> =C2=A0#if defined(CONFIG_MMU) && defined(CONFIG_64BIT) >> -#define VMALLOC_MODULE_START \ >> -=C2=A0=C2=A0=C2=A0=C2=A0 max(PFN_ALIGN((unsigned long)&_end - SZ_2G),= VMALLOC_START) >> =C2=A0void *module_alloc(unsigned long size) >> =C2=A0{ >> -=C2=A0=C2=A0=C2=A0 return __vmalloc_node_range(size, 1, VMALLOC_MODUL= E_START, >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 VMALLOC_END, GFP_KERNEL, >> +=C2=A0=C2=A0=C2=A0 return __vmalloc_node_range(size, 1, MODULES_VADDR= , >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 MODULES_END, GFP_KERNEL, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PAGE_KERNEL_EXEC, 0, NUM= A_NO_NODE, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 __builtin_return_address= (0)); >> =C2=A0} >> diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c >> index e85bacff1b50..30e4af0fd50c 100644 >> --- a/arch/riscv/kernel/setup.c >> +++ b/arch/riscv/kernel/setup.c >> @@ -265,6 +265,11 @@ void __init setup_arch(char **cmdline_p) >> >> =C2=A0=C2=A0=C2=A0=C2=A0 if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 protect_kernel_text_d= ata(); >> + >> +#if defined(CONFIG_64BIT) && defined(CONFIG_MMU) >> +=C2=A0=C2=A0=C2=A0 protect_kernel_linear_mapping_text_rodata(); >> +#endif >> + >> =C2=A0#ifdef CONFIG_SWIOTLB >> =C2=A0=C2=A0=C2=A0=C2=A0 swiotlb_init(1); >> =C2=A0#endif >> diff --git a/arch/riscv/kernel/vmlinux.lds.S=20 >> b/arch/riscv/kernel/vmlinux.lds.S >> index de03cb22d0e9..0726c05e0336 100644 >> --- a/arch/riscv/kernel/vmlinux.lds.S >> +++ b/arch/riscv/kernel/vmlinux.lds.S >> @@ -4,7 +4,8 @@ >> =C2=A0 * Copyright (C) 2017 SiFive >> =C2=A0 */ >> >> -#define LOAD_OFFSET PAGE_OFFSET >> +#include >> +#define LOAD_OFFSET KERNEL_LINK_ADDR >> =C2=A0#include >> =C2=A0#include >> =C2=A0#include >> diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c >> index 8f17519208c7..1b14d523a95c 100644 >> --- a/arch/riscv/mm/fault.c >> +++ b/arch/riscv/mm/fault.c >> @@ -231,6 +231,19 @@ asmlinkage void do_page_fault(struct pt_regs *reg= s) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return; >> =C2=A0=C2=A0=C2=A0=C2=A0 } >> >> +#ifdef CONFIG_64BIT >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * Modules in 64bit kernels lie in their own = virtual region which=20 >> is not >> +=C2=A0=C2=A0=C2=A0=C2=A0 * in the vmalloc region, but dealing with pa= ge faults in this=20 >> region >> +=C2=A0=C2=A0=C2=A0=C2=A0 * or the vmalloc region amounts to doing the= same thing:=20 >> checking that >> +=C2=A0=C2=A0=C2=A0=C2=A0 * the mapping exists in init_mm.pgd and upda= ting user page=20 >> table, so >> +=C2=A0=C2=A0=C2=A0=C2=A0 * just use vmalloc_fault. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0 if (unlikely(addr >=3D MODULES_VADDR && addr < MOD= ULES_END)) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 vmalloc_fault(regs, code, = addr); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return; >> +=C2=A0=C2=A0=C2=A0 } >> +#endif >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Enable interrupts if they were enabled in = the parent context. */ >> =C2=A0=C2=A0=C2=A0=C2=A0 if (likely(regs->status & SR_PIE)) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local_irq_enable(); >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index 7f5036fbee8c..093f3a96ecfc 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -25,6 +25,9 @@ >> >> =C2=A0#include "../kernel/head.h" >> >> +unsigned long kernel_virt_addr =3D KERNEL_LINK_ADDR; >> +EXPORT_SYMBOL(kernel_virt_addr); >> + >> =C2=A0unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 __page_aligned_bss; >> =C2=A0EXPORT_SYMBOL(empty_zero_page); >> @@ -88,6 +91,8 @@ static void print_vm_layout(void) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (unsigned= long)VMALLOC_END); >> =C2=A0=C2=A0=C2=A0=C2=A0 print_mlm("lowmem", (unsigned long)PAGE_OFFSE= T, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (unsigned= long)high_memory); >> +=C2=A0=C2=A0=C2=A0 print_mlm("kernel", (unsigned long)KERNEL_LINK_ADD= R, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (unsigned long= )ADDRESS_SPACE_END); >> =C2=A0} >> =C2=A0#else >> =C2=A0static void print_vm_layout(void) { } >> @@ -116,8 +121,13 @@ void __init setup_bootmem(void) >> =C2=A0=C2=A0=C2=A0=C2=A0 /* The maximal physical memory size is -PAGE_= OFFSET. */ >> =C2=A0=C2=A0=C2=A0=C2=A0 memblock_enforce_memory_limit(-PAGE_OFFSET); >> >> -=C2=A0=C2=A0=C2=A0 /* Reserve from the start of the kernel to the end= of the kernel */ >> -=C2=A0=C2=A0=C2=A0 memblock_reserve(vmlinux_start, vmlinux_end - vmli= nux_start); >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * Reserve from the start of the kernel to th= e end of the kernel >> +=C2=A0=C2=A0=C2=A0=C2=A0 * and make sure we align the reservation on = PMD_SIZE since we will >> +=C2=A0=C2=A0=C2=A0=C2=A0 * map the kernel in the linear mapping as re= ad-only: we do not want >> +=C2=A0=C2=A0=C2=A0=C2=A0 * any allocation to happen between _end and = the next pmd aligned=20 >> page. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0 memblock_reserve(vmlinux_start, (vmlinux_end - vml= inux_start +=20 >> PMD_SIZE - 1) & PMD_MASK); >> >> =C2=A0=C2=A0=C2=A0=C2=A0 /* >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * memblock allocator is not aware of th= e fact that last 4K bytes of >> @@ -152,8 +162,12 @@ void __init setup_bootmem(void) >> =C2=A0#ifdef CONFIG_MMU >> =C2=A0static struct pt_alloc_ops pt_ops; >> >> +/* Offset between linear mapping virtual address and kernel load=20 >> address */ >> =C2=A0unsigned long va_pa_offset; >> =C2=A0EXPORT_SYMBOL(va_pa_offset); >> +/* Offset between kernel mapping virtual address and kernel load=20 >> address */ >> +unsigned long va_kernel_pa_offset; >> +EXPORT_SYMBOL(va_kernel_pa_offset); >> =C2=A0unsigned long pfn_base; >> =C2=A0EXPORT_SYMBOL(pfn_base); >> >> @@ -257,7 +271,7 @@ static pmd_t *get_pmd_virt_late(phys_addr_t pa) >> >> =C2=A0static phys_addr_t __init alloc_pmd_early(uintptr_t va) >> =C2=A0{ >> -=C2=A0=C2=A0=C2=A0 BUG_ON((va - PAGE_OFFSET) >> PGDIR_SHIFT); >> +=C2=A0=C2=A0=C2=A0 BUG_ON((va - kernel_virt_addr) >> PGDIR_SHIFT); >> >> =C2=A0=C2=A0=C2=A0=C2=A0 return (uintptr_t)early_pmd; >> =C2=A0} >> @@ -372,17 +386,32 @@ static uintptr_t __init=20 >> best_map_size(phys_addr_t base, phys_addr_t size) >> =C2=A0#error "setup_vm() is called from head.S before relocate so it s= hould=20 >> not use absolute addressing." >> =C2=A0#endif >> >> +uintptr_t load_pa, load_sz; >> + >> +static void __init create_kernel_page_table(pgd_t *pgdir, uintptr_t=20 >> map_size) >> +{ >> +=C2=A0=C2=A0=C2=A0 uintptr_t va, end_va; >> + >> +=C2=A0=C2=A0=C2=A0 end_va =3D kernel_virt_addr + load_sz; >> +=C2=A0=C2=A0=C2=A0 for (va =3D kernel_virt_addr; va < end_va; va +=3D= map_size) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 create_pgd_mapping(pgdir, = va, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 load_pa + (va - kernel_virt_addr)= , >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 map_size, PAGE_KERNEL_EXEC); >> +} >> + >> =C2=A0asmlinkage void __init setup_vm(uintptr_t dtb_pa) >> =C2=A0{ >> -=C2=A0=C2=A0=C2=A0 uintptr_t va, pa, end_va; >> -=C2=A0=C2=A0=C2=A0 uintptr_t load_pa =3D (uintptr_t)(&_start); >> -=C2=A0=C2=A0=C2=A0 uintptr_t load_sz =3D (uintptr_t)(&_end) - load_pa= ; >> +=C2=A0=C2=A0=C2=A0 uintptr_t pa; >> =C2=A0=C2=A0=C2=A0=C2=A0 uintptr_t map_size; >> =C2=A0#ifndef __PAGETABLE_PMD_FOLDED >> =C2=A0=C2=A0=C2=A0=C2=A0 pmd_t fix_bmap_spmd, fix_bmap_epmd; >> =C2=A0#endif >> +=C2=A0=C2=A0=C2=A0 load_pa =3D (uintptr_t)(&_start); >> +=C2=A0=C2=A0=C2=A0 load_sz =3D (uintptr_t)(&_end) - load_pa; >> >> =C2=A0=C2=A0=C2=A0=C2=A0 va_pa_offset =3D PAGE_OFFSET - load_pa; >> +=C2=A0=C2=A0=C2=A0 va_kernel_pa_offset =3D kernel_virt_addr - load_pa= ; >> + >> =C2=A0=C2=A0=C2=A0=C2=A0 pfn_base =3D PFN_DOWN(load_pa); >> >> =C2=A0=C2=A0=C2=A0=C2=A0 /* >> @@ -410,26 +439,22 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa= ) >> =C2=A0=C2=A0=C2=A0=C2=A0 create_pmd_mapping(fixmap_pmd, FIXADDR_START, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (uintptr_t)fixmap_pte, PMD_SIZE, PAGE_TABLE); >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Setup trampoline PGD and PMD */ >> -=C2=A0=C2=A0=C2=A0 create_pgd_mapping(trampoline_pg_dir, PAGE_OFFSET, >> +=C2=A0=C2=A0=C2=A0 create_pgd_mapping(trampoline_pg_dir, kernel_virt_= addr, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (uintptr_t)trampoline_pmd, PGDIR_SIZE, PAGE_TABLE); >> -=C2=A0=C2=A0=C2=A0 create_pmd_mapping(trampoline_pmd, PAGE_OFFSET, >> +=C2=A0=C2=A0=C2=A0 create_pmd_mapping(trampoline_pmd, kernel_virt_add= r, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 load_pa, PMD_SIZE, PAGE_KERNEL_EXEC); >> =C2=A0#else >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Setup trampoline PGD */ >> -=C2=A0=C2=A0=C2=A0 create_pgd_mapping(trampoline_pg_dir, PAGE_OFFSET, >> +=C2=A0=C2=A0=C2=A0 create_pgd_mapping(trampoline_pg_dir, kernel_virt_= addr, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 load_pa, PGDIR_SIZE, PAGE_KERNEL_EXEC); >> =C2=A0#endif >> >> =C2=A0=C2=A0=C2=A0=C2=A0 /* >> -=C2=A0=C2=A0=C2=A0=C2=A0 * Setup early PGD covering entire kernel whi= ch will allows >> +=C2=A0=C2=A0=C2=A0=C2=A0 * Setup early PGD covering entire kernel whi= ch will allow >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * us to reach paging_init(). We map all= memory banks later >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * in setup_vm_final() below. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >> -=C2=A0=C2=A0=C2=A0 end_va =3D PAGE_OFFSET + load_sz; >> -=C2=A0=C2=A0=C2=A0 for (va =3D PAGE_OFFSET; va < end_va; va +=3D map_= size) >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 create_pgd_mapping(early_p= g_dir, va, >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 load_pa + (va - PAGE_OFFSET), >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 map_size, PAGE_KERNEL_EXEC); >> +=C2=A0=C2=A0=C2=A0 create_kernel_page_table(early_pg_dir, map_size); >> >> =C2=A0#ifndef __PAGETABLE_PMD_FOLDED >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Setup early PMD for DTB */ >> @@ -444,7 +469,12 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL); >> =C2=A0=C2=A0=C2=A0=C2=A0 dtb_early_va =3D (void *)DTB_EARLY_BASE_VA + = (dtb_pa & (PMD_SIZE -=20 >> 1)); >> =C2=A0#else /* CONFIG_BUILTIN_DTB */ >> -=C2=A0=C2=A0=C2=A0 dtb_early_va =3D __va(dtb_pa); >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * __va can't be used since it would return a= linear mapping address >> +=C2=A0=C2=A0=C2=A0=C2=A0 * whereas dtb_early_va will be used before s= etup_vm_final installs >> +=C2=A0=C2=A0=C2=A0=C2=A0 * the linear mapping. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0 dtb_early_va =3D kernel_mapping_pa_to_va(dtb_pa); >> =C2=A0#endif /* CONFIG_BUILTIN_DTB */ >> =C2=A0#else >> =C2=A0#ifndef CONFIG_BUILTIN_DTB >> @@ -456,7 +486,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL); >> =C2=A0=C2=A0=C2=A0=C2=A0 dtb_early_va =3D (void *)DTB_EARLY_BASE_VA + = (dtb_pa & (PGDIR_SIZE=20 >> - 1)); >> =C2=A0#else /* CONFIG_BUILTIN_DTB */ >> -=C2=A0=C2=A0=C2=A0 dtb_early_va =3D __va(dtb_pa); >> +=C2=A0=C2=A0=C2=A0 dtb_early_va =3D kernel_mapping_pa_to_va(dtb_pa); >> =C2=A0#endif /* CONFIG_BUILTIN_DTB */ >> =C2=A0#endif >> =C2=A0=C2=A0=C2=A0=C2=A0 dtb_early_pa =3D dtb_pa; >> @@ -492,6 +522,22 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) >> =C2=A0#endif >> =C2=A0} >> >> +#ifdef CONFIG_64BIT >> +void protect_kernel_linear_mapping_text_rodata(void) >> +{ >> +=C2=A0=C2=A0=C2=A0 unsigned long text_start =3D (unsigned long)lm_ali= as(_start); >> +=C2=A0=C2=A0=C2=A0 unsigned long init_text_start =3D (unsigned=20 >> long)lm_alias(__init_text_begin); >> +=C2=A0=C2=A0=C2=A0 unsigned long rodata_start =3D (unsigned=20 >> long)lm_alias(__start_rodata); >> +=C2=A0=C2=A0=C2=A0 unsigned long data_start =3D (unsigned long)lm_ali= as(_data); >> + >> +=C2=A0=C2=A0=C2=A0 set_memory_ro(text_start, (init_text_start - text_= start) >>=20 >> PAGE_SHIFT); >> +=C2=A0=C2=A0=C2=A0 set_memory_nx(text_start, (init_text_start - text_= start) >>=20 >> PAGE_SHIFT); >> + >> +=C2=A0=C2=A0=C2=A0 set_memory_ro(rodata_start, (data_start - rodata_s= tart) >>=20 >> PAGE_SHIFT); >> +=C2=A0=C2=A0=C2=A0 set_memory_nx(rodata_start, (data_start - rodata_s= tart) >>=20 >> PAGE_SHIFT); >> +} >> +#endif >> + >> =C2=A0static void __init setup_vm_final(void) >> =C2=A0{ >> =C2=A0=C2=A0=C2=A0=C2=A0 uintptr_t va, map_size; >> @@ -513,7 +559,7 @@ static void __init setup_vm_final(void) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 __pa_symbol(fixmap_pgd_next), >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 PGDIR_SIZE, PAGE_TABLE); >> >> -=C2=A0=C2=A0=C2=A0 /* Map all memory banks */ >> +=C2=A0=C2=A0=C2=A0 /* Map all memory banks in the linear mapping */ >> =C2=A0=C2=A0=C2=A0=C2=A0 for_each_mem_range(i, &start, &end) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (start >=3D end) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= break; >> @@ -525,10 +571,13 @@ static void __init setup_vm_final(void) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (pa =3D start; pa= < end; pa +=3D map_size) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= va =3D (uintptr_t)__va(pa); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= create_pgd_mapping(swapper_pg_dir, va, pa, >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 map_size,= PAGE_KERNEL_EXEC); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 map_size,= PAGE_KERNEL); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0 } >> >> +=C2=A0=C2=A0=C2=A0 /* Map the kernel */ >> +=C2=A0=C2=A0=C2=A0 create_kernel_page_table(swapper_pg_dir, PMD_SIZE)= ; >> + >> =C2=A0=C2=A0=C2=A0=C2=A0 /* Clear fixmap PTE and PMD mappings */ >> =C2=A0=C2=A0=C2=A0=C2=A0 clear_fixmap(FIX_PTE); >> =C2=A0=C2=A0=C2=A0=C2=A0 clear_fixmap(FIX_PMD); >> diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c >> index 2c39f0386673..28f4d52cf17e 100644 >> --- a/arch/riscv/mm/kasan_init.c >> +++ b/arch/riscv/mm/kasan_init.c >> @@ -171,6 +171,10 @@ void __init kasan_init(void) >> =C2=A0=C2=A0=C2=A0=C2=A0 phys_addr_t _start, _end; >> =C2=A0=C2=A0=C2=A0=C2=A0 u64 i; >> >> +=C2=A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0 * Populate all kernel virtual address space = with=20 >> kasan_early_shadow_page >> +=C2=A0=C2=A0=C2=A0=C2=A0 * except for the linear mapping and the modu= les/kernel/BPF mapping. >> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >> =C2=A0=C2=A0=C2=A0=C2=A0 kasan_populate_early_shadow((void *)KASAN_SHA= DOW_START, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (void *)kasan_mem_to_sha= dow((void *) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 VMEMMAP_END)); >> @@ -183,6 +187,7 @@ void __init kasan_init(void) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (void *)kasan_mem_to_shadow((void *)VMALLOC_START), >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (void *)kasan_mem_to_shadow((void *)VMALLOC_END)); >> >> +=C2=A0=C2=A0=C2=A0 /* Populate the linear mapping */ >> =C2=A0=C2=A0=C2=A0=C2=A0 for_each_mem_range(i, &_start, &_end) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 void *start =3D (void= *)__va(_start); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 void *end =3D (void *= )__va(_end); >> @@ -193,6 +198,10 @@ void __init kasan_init(void) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 kasan_populate(kasan_= mem_to_shadow(start),=20 >> kasan_mem_to_shadow(end)); >> =C2=A0=C2=A0=C2=A0=C2=A0 }; >> >> +=C2=A0=C2=A0=C2=A0 /* Populate kernel, BPF, modules mapping */ >> +=C2=A0=C2=A0=C2=A0 kasan_populate(kasan_mem_to_shadow((const void *)M= ODULES_VADDR), >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 kasan_mem_to_shadow((const void *)BPF_JIT_REGION_END)); >> + >> =C2=A0=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < PTRS_PER_PTE; i++) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 set_pte(&kasan_early_= shadow_pte[i], >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= mk_pte(virt_to_page(kasan_early_shadow_page), >> diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c >> index e8e4dcd39fed..35703d5ef5fd 100644 >> --- a/arch/riscv/mm/physaddr.c >> +++ b/arch/riscv/mm/physaddr.c >> @@ -23,7 +23,7 @@ EXPORT_SYMBOL(__virt_to_phys); >> >> =C2=A0phys_addr_t __phys_addr_symbol(unsigned long x) >> =C2=A0{ >> -=C2=A0=C2=A0=C2=A0 unsigned long kernel_start =3D (unsigned long)PAGE= _OFFSET; >> +=C2=A0=C2=A0=C2=A0 unsigned long kernel_start =3D (unsigned long)kern= el_virt_addr; >> =C2=A0=C2=A0=C2=A0=C2=A0 unsigned long kernel_end =3D (unsigned long)_= end; >> >> =C2=A0=C2=A0=C2=A0=C2=A0 /* >=20 > This is breaking boot for me with CONFIG_STRICT_KERNEL_RWX=3Dn.=C2=A0 I= 'm not=20 > even really convinced that's a useful config to support, but it's=20 > currently optional and I'd prefer to avoid breaking it if possible. >=20 > I can't quite figure out what's going on here and I'm pretty much tired= =20 > out for tonight.=C2=A0 LMK if you don't have time to look at it and I'l= l try=20 > to give it another shot. I'm taking a look at that. Thanks, Alex