Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1945546pxy; Sun, 2 May 2021 07:11:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaM19lMlDzdbg9Fw9VE7O69kDDh12JdtmYCr34ItvcfuMO3nPk1Kt0OH6mgJgtHKkokcxf X-Received: by 2002:aa7:dd4d:: with SMTP id o13mr15871372edw.53.1619964693631; Sun, 02 May 2021 07:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619964693; cv=none; d=google.com; s=arc-20160816; b=akyeQXJ7AMngQLyltYJyCQTwUFyYNwsQK0EjyM7Vkg2jKBZ/gZF54Ri3IO1EAXmPU6 I+Ku4BXHvNcOHCtOB4RJjuel+zb3nwyxXZj33H/xYKCV1UIcOrESUJ6bRMN9+14C8CS3 GYhaLUDoT2d/sqgYKMS9ylSWuIHPRZY++c3hv8VKm5ORmfDxRJc9R8yIMb7PYdbdIbpM LeUDIrU1ggngc4j/hmoCXDKoFCcpia+m6pWxtQ6FMU9vlTCvrQSisu/yQSYzgg0PidOl VYxfsQYlm2sZlmuPpgZKRPZstLJy40VxNBzPMX/1DBD6x5fjLVXTRxqxJkA8Vn8KtFrL 4mNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=jAj5esyjALD7HGj9ix0SKK620afFvLfg0lJ8DH4F7hU=; b=Ia9FF1QURe3oVDYCVC63GuHIMp57zMs8CPVGdAtYkz557W+Cvv7RWqeos7dBSuKwZX rvQYvtU4CfU4IQUjALCwNvHhoNvP+6oKSY35k5mUwQxf+lqZsLnV6mgiNikgbfOQf09O 8GG04H4pKg3TH/svmwrQvjv9eJru7BJx5IeNBOmRcpZrduXRxMAGOoTbWLyr8HYTRWD2 wzmScPp/huRMLOyvvYCFlF1vDffjum4LfsXVIN7rSWIlGPe0XgTO22PMdPhySP7sfQKZ wzw4Gcr7sHG8A8vBUVX/SK9OiH/UKidD12duP6PwwlVYRXzz2EwxVwZETlvwxDYFs0EP XUPA== 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 c7si6621943edv.323.2021.05.02.07.11.09; Sun, 02 May 2021 07:11:33 -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 S234191AbhEBOKW (ORCPT + 99 others); Sun, 2 May 2021 10:10:22 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:37723 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbhEBOHZ (ORCPT ); Sun, 2 May 2021 10:07:25 -0400 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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id C457D20002; Sun, 2 May 2021 14:06:29 +0000 (UTC) Subject: Re: [PATCH] riscv: Consistify protect_kernel_linear_mapping_text_rodata() use To: Geert Uytterhoeven , Paul Walmsley , Palmer Dabbelt , Albert Ou , Vitaly Wool Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: From: Alex Ghiti Message-ID: <288c578a-d680-e2e8-33a1-004e11a4f6f0@ghiti.fr> Date: Sun, 2 May 2021 10:06:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 4/29/21 ? 11:10 AM, Geert Uytterhoeven a ?crit?: > The various uses of protect_kernel_linear_mapping_text_rodata() are > not consistent: > - Its definition depends on "64BIT && !XIP_KERNEL", > - Its forward declaration depends on MMU, > - Its single caller depends on "STRICT_KERNEL_RWX && 64BIT && MMU && > !XIP_KERNEL". > > Fix this by settling on the dependencies of the caller, which can be > simplified as STRICT_KERNEL_RWX depends on "MMU && !XIP_KERNEL". > Provide a dummy definition, as the caller is protected by > "IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)" instead of "#ifdef > CONFIG_STRICT_KERNEL_RWX". > > Signed-off-by: Geert Uytterhoeven > --- > Only tested on K210 (SiPeed MAIX BiT). > --- > arch/riscv/include/asm/set_memory.h | 7 ++++++- > arch/riscv/kernel/setup.c | 2 -- > arch/riscv/mm/init.c | 2 +- > 3 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/riscv/include/asm/set_memory.h b/arch/riscv/include/asm/set_memory.h > index a9c56776fa0e74d6..086f757e8ba3cc69 100644 > --- a/arch/riscv/include/asm/set_memory.h > +++ b/arch/riscv/include/asm/set_memory.h > @@ -17,7 +17,6 @@ int set_memory_x(unsigned long addr, int numpages); > int set_memory_nx(unsigned long addr, int numpages); > int set_memory_rw_nx(unsigned long addr, int numpages); > void protect_kernel_text_data(void); > -void protect_kernel_linear_mapping_text_rodata(void); > #else > static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } > static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } > @@ -27,6 +26,12 @@ static inline void protect_kernel_text_data(void) {} > static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0; } > #endif > > +#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) > +void protect_kernel_linear_mapping_text_rodata(void); > +#else > +static inline void protect_kernel_linear_mapping_text_rodata(void) {} > +#endif > + > int set_direct_map_invalid_noflush(struct page *page); > int set_direct_map_default_noflush(struct page *page); > bool kernel_page_present(struct page *page); > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c > index 7b31779101f662e4..03901d3a8b027343 100644 > --- a/arch/riscv/kernel/setup.c > +++ b/arch/riscv/kernel/setup.c > @@ -293,9 +293,7 @@ void __init setup_arch(char **cmdline_p) > > if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) { > protect_kernel_text_data(); > -#if defined(CONFIG_64BIT) && defined(CONFIG_MMU) && !defined(CONFIG_XIP_KERNEL) > protect_kernel_linear_mapping_text_rodata(); > -#endif > } > > #ifdef CONFIG_SWIOTLB > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index 3ebc0f5d2b73b42b..6cc0421a5d0ef4a3 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -646,7 +646,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > #endif > } > > -#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL) > +#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX) > void protect_kernel_linear_mapping_text_rodata(void) > { > unsigned long text_start = (unsigned long)lm_alias(_start); > I tested this on the following configs: - rv32_defconfig (build and valid on qemu) - defconfig (with and without CONFIG_STRICT_KERNEL_RWX) (build and valid on qemu) - xip kernel (build and valid on qemu) - nommu_k210_defconfig (build only) so you can add: Tested-by: Alexandre Ghiti Thank you for the cleanup! Alex