Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1493428pxy; Thu, 29 Apr 2021 08:11:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvhbb/k5I2G8Twpm9GtgVVpxzOrvNtibUFxJXhs32JjOYoS1nkJRb+UDSXWrNwkiWNilQW X-Received: by 2002:a17:90b:310c:: with SMTP id gc12mr281733pjb.217.1619709091053; Thu, 29 Apr 2021 08:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619709091; cv=none; d=google.com; s=arc-20160816; b=uV9epZRG5lRby2w9RTbzbJCnbABmEsXUT+x0blAkbmR9K/TWlKnoLd875Uxy9hYH1m IjEYFsI4SarDeBWQRLz8Y0IbroX9l4h90wN/xKbLCjRmAzRmOoiaY4X3WLprmhYaSg3B y14TH++wQveTcXiY68mENor0SRCNFffvPocTA4Q16sXd1FIWSo1Nklm/JscIcAEByWPG 8A7vkyDO36Bqa8HLs2g6II3oRmONLkQInjfDUOsUP0Hkn6IFmRSqNRaBFhyMEDXQzcm3 neR7q9DHyn3mxJUej3p6EwfePrlPJTq4JqCm1tpCTVRzb1u0xviLILq9zb9vG8NwEEHV qjnQ== 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 :message-id:date:subject:cc:to:from; bh=TKUKg5w8ha65td2l7eEuAAY266Y4z37siNIzDYX4QsA=; b=fNi7B0bfahIwVJgnCpEPTWuRNWG13N6fJpG3xfrDe3Wh5hkvUOosWSgT+H3pvNbbqO +7V0RUQO+GobAygMoXuL8/jokUksYvSi+CZMaKIgckf0nSJNMJt13L0ajK2xth02le/j jOvVFUkwMRjjBKfIiYcpc8nYRO025BsoJmqzByf2+61fiEpeWtNWhBB7sXth7vx1Gq+t Rbw1PG1FUfGBMtZhfGBikiUdoUNqOIazn7I7gC5IVW/G48AdJdUvn/UFd1FByabN9W8t ohWFAAwZqFO5XAWtRQHZm4DFlrLHqlIT1tOAgxV1vpi1Sz2EUYSPLuD0U66sm6O1dUuD b4pQ== 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 o4si3766630pjg.78.2021.04.29.08.11.18; Thu, 29 Apr 2021 08:11:31 -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 S237396AbhD2PK5 (ORCPT + 99 others); Thu, 29 Apr 2021 11:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233480AbhD2PK5 (ORCPT ); Thu, 29 Apr 2021 11:10:57 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CDE6C06138B for ; Thu, 29 Apr 2021 08:10:10 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:d4dd:70b4:3264:8d97]) by laurent.telenet-ops.be with bizsmtp id yfA6240094p6Y3801fA6tY; Thu, 29 Apr 2021 17:10:08 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lc8In-001HmU-J3; Thu, 29 Apr 2021 17:10:05 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1lc8In-009dGx-34; Thu, 29 Apr 2021 17:10:05 +0200 From: Geert Uytterhoeven To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Vitaly Wool , Alex Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] riscv: Consistify protect_kernel_linear_mapping_text_rodata() use Date: Thu, 29 Apr 2021 17:10:04 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.25.1