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=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 60D6FC2B9F4 for ; Thu, 17 Jun 2021 12:01:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37FA960240 for ; Thu, 17 Jun 2021 12:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232646AbhFQMDl (ORCPT ); Thu, 17 Jun 2021 08:03:41 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:49909 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbhFQMDi (ORCPT ); Thu, 17 Jun 2021 08:03:38 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id EA9E86000F; Thu, 17 Jun 2021 12:01:25 +0000 (UTC) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH v5 0/2] riscv: Map the kernel with correct permissions the first time Date: Thu, 17 Jun 2021 14:01:22 +0200 Message-Id: <20210617120124.1752541-1-alex@ghiti.fr> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel permissions are fixed after the kernel page table is created: avoid that by mapping the kernel 'correctly' the first time. Patch 1 introduces a new helper to set kernel mapping permissions while avoiding all the casts when using set_memory_* API. Patch 2 is the bulk of this work and deals with mapping the kernel with the right permissions. Changes in v5: * Remove non-relevant commits to this patchset that raised issues * Make load_sz non-static as it is used in kernel address conversions macros * Rebased on top for-next Changes in v4: * Add patch 1 as noted by Jisheng * Changes patch 2 title as suggested by Anup * Add Reviewed-by from Anup Changes in v3: * Add a patch that factorizes kernel address conversions * Add a helper called set_kernel_memory in its own patch, as suggested by Christoph * Prefer IS_ENABLED over #ifdef, as suggested by Christoph * Split overly long lines, as suggested by Christoph * Simplify kernel mapping by mapping ALL text as readonly and taking advantage of already present code that enables write for init text before free_initmem_default. Changes in v2: * Rebased on top of for-next (and "riscv: mm: fix build errors caused by mk_pmd()") * Get rid of protect_kernel_linear_mapping_text_rodata as suggested by Jisheng * Improve code in general compared to previous RFC Alexandre Ghiti (2): riscv: Introduce set_kernel_memory helper riscv: Map the kernel with correct permissions the first time arch/riscv/include/asm/page.h | 13 +++- arch/riscv/include/asm/sections.h | 17 +++++ arch/riscv/include/asm/set_memory.h | 13 ++-- arch/riscv/kernel/setup.c | 11 +-- arch/riscv/mm/init.c | 108 ++++++++++++---------------- arch/riscv/mm/pageattr.c | 10 +++ 6 files changed, 91 insertions(+), 81 deletions(-) -- 2.30.2