Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1042860pxj; Fri, 4 Jun 2021 04:51:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1cYiSm5FCyc9XQYlwX99qv1+CkhB1U+GQyHKpC8LbA08MM7hCqRNVlclggErFz3NtoRot X-Received: by 2002:aa7:cdc5:: with SMTP id h5mr4147558edw.217.1622807486369; Fri, 04 Jun 2021 04:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622807486; cv=none; d=google.com; s=arc-20160816; b=H7LDQVPEWfuP4k+vdsSAxHKqPYIVxYOFkJ4FJO+R8HN1kaS4mtZbZMf6Y+0CsHhR9A 9TEQHT0cU+bJzL2HKGubtEDPHtLwQUTxq54iRZ8haepSXbPsQybcZ/6F3cyYyWFf+stf qm+ex10+0N3ZJLPj6/ciMXHkxKlg0u/pkKmayNJI7DhNoK+ODRIerdKqvpnqhlEKa7YI 2ku5cuNPC3nK7EnHx6cCvI+k+ji/VP6bZ4fxTycbgn4HjYwrLmpthV4OOypwHvLwnZzW aAGswvLapK/WvTM3nxOD4m9+nB7iL2RQhzLZPp01o/y902SncziuN+dYgqVTWBfZrMj4 XHIg== 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=FtEx7N9/vcp27i6t/kA+pIXNS3ThKLZtRsknLBL+FCU=; b=Xd7YgGk95ISKgxMrZ1t4S37lHTZht++G1O/Uqybf9KX+38OokwjGDpi9NGHl6ayLgQ FTrrMoOjA/pYlDNcYFKss3P1JOYlL77X81pQZV0UX+4KZPcCtJZhoxBT8DyaISwNPFoB wJ34CO0Kj5IMMfLtKnKx61ms71D9psDJoqQIM2lVo2EsyfO36g2a5SXjcVENrXhIkoyf HqE4KqGL7I7NCYMa+V/z1Tjiqh15uRwrHrjLIazEflkXeqKT89Zeynm5mg22J4uVHW3j /xD6z0x+4sK7xRu/BvfXgtWKANOkbaUILxvE95EdLptNNpmcqpmh86DH/vmiXb7WsZ54 YCGA== 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 m29si4686335ejn.735.2021.06.04.04.51.03; Fri, 04 Jun 2021 04:51:26 -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 S230108AbhFDLvm (ORCPT + 99 others); Fri, 4 Jun 2021 07:51:42 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:53753 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbhFDLvm (ORCPT ); Fri, 4 Jun 2021 07:51:42 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 393C2200007; Fri, 4 Jun 2021 11:49: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 v4 0/4] riscv: Map the kernel with correct permissions the first time Date: Fri, 4 Jun 2021 13:49:46 +0200 Message-Id: <20210604114950.1446390-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 2 is a cleanup patch on which the next patches are based on, not necessary for this patchset though and relies on patch 1. Patch 3 introduces a new helper to set kernel mapping permissions while avoiding all the casts when using set_memory_* API. Patch 4 is the bulk of this work and deals with mapping the kernel with the right permissions. 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 (4): riscv: Remove CONFIG_PHYS_RAM_BASE_FIXED riscv: Simplify 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/Kconfig | 6 -- 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 +++ 8 files changed, 95 insertions(+), 93 deletions(-) -- 2.30.2