Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp92240pxj; Thu, 3 Jun 2021 01:30:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmrH2YbwsbGiT7HLNNNuHNdmYggJ1jKLQZ767T5SWgGgZyleH0XRcYqlw+7RJOzhKpAT7/ X-Received: by 2002:a17:906:a854:: with SMTP id dx20mr21002461ejb.128.1622709008996; Thu, 03 Jun 2021 01:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622709008; cv=none; d=google.com; s=arc-20160816; b=QcW2pLhBXIdAkGx95/Ivh0mxUeMJgSqiOTl8AuTHzWm0dgcJCUkNlIBVpPtByj4KoF B4LA1sIj6bu9yPx1S2yrZ7xEGF+TQ0F+G2k6HvP+J0WgRI49uUMc8E/a2VlZkYnO6jeg pFwh4hziau9aDtcpoBC5NZc+t/kDiuh+sTBFWPUrD2DDtVMFYElWDP/0fhY2KtG+Ttja K40h/jHcK6vZ3k7kGYdT2BCj00R0D253OX4UvkTkkfBVYrrchAFsqQekQyrQD2SLeCu+ nYNZkTXXWBj6pCovWH0n+YHhkkp2fp8Rdz4DV1ESl+kt3L7KpoZFRDweHenZ3FzQdsv9 s+EA== 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=gC7Li/SnV/rRzbX2BuSQAQZLqrm+MI4Jmo7/0RbWhQY=; b=nCZH0YWYYmuBHDA1zYVvGGIk2W3UaHk9QGpumloa/Kylm54FH2347aRLM8evHUfo2e MlNDYIYZW4bHhoa/f2+v/U/Wr4nBEls7hlKzAzoTjTWwnvnIOTgWfuRz1FQZFnqqB1w8 TJPCmm85oyfv0yVMjWPRCsbeqREjVxZkCK9hXu0dTeByhLWnVjtyzdOgRqzky0LX2HGo 1eLuwjmnvGdpU/vDUd0nXexWFsZvruuTq4hS2TpllSlNtOkcI+Bzpl99cmSdarSpTZU1 IvsaQ5/B01HxDlMIzbayQMT67IOKN8J06YB/uSKLrj3E9846zneQBEm0r7t3SuLHukfQ BgzA== 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 hb18si1780750ejc.159.2021.06.03.01.29.45; Thu, 03 Jun 2021 01:30:08 -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 S229611AbhFCI3m (ORCPT + 99 others); Thu, 3 Jun 2021 04:29:42 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:55591 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhFCI3l (ORCPT ); Thu, 3 Jun 2021 04:29:41 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 30F0D60004; Thu, 3 Jun 2021 08:27:51 +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 v3 0/3] riscv: Map the kernel with correct permissions the first time Date: Thu, 3 Jun 2021 10:27:46 +0200 Message-Id: <20210603082749.1256129-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: fix that by mapping the kernel 'correctly' the first time. Patch 1 is a cleanup patch on which the next patches are based on, not necessary for this patchset though. Patch 2 introduces a new helper to set kernel mapping permissions while avoiding all the casts when using set_memory_* API. Patch 3 is the bulk of this work and deals with mapping the kernel with the right permissions. 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 (3): riscv: Factorize xip and !xip kernel address conversion macros riscv: Introduce set_kernel_memory helper riscv: Map the kernel with correct permissions the first time arch/riscv/include/asm/page.h | 27 ++++---- arch/riscv/include/asm/pgtable.h | 2 + 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 | 102 ++++++++++++---------------- arch/riscv/mm/pageattr.c | 10 +++ 7 files changed, 95 insertions(+), 87 deletions(-) -- 2.30.2