Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp571008pxj; Thu, 17 Jun 2021 08:57:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFxGizeTvd5jRNnon8x90+WfabimUgKXOlq8p6myxP4vH87zPjkA9thvd9Rylm7LbDkHC9 X-Received: by 2002:a5d:83d4:: with SMTP id u20mr4471172ior.199.1623945427400; Thu, 17 Jun 2021 08:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623945427; cv=none; d=google.com; s=arc-20160816; b=DD1WYcF/8KMFTJ4ZfuDc7yHg3HznweGxv/Ucyfovf+WD+hat+PoG625egbSU1nETq9 O4fGhshuBO33yK/nSDKAZjQE4PIoYJkLp5hJaFIPN9E/Jr+z4eiQjjYVMZ9hE7RZ1fup M7HNMmSJDJCCCDngQWGRjWtpB5yoVzXhjxobNWvOq65f6mW5HyjkTy7hoAF3iYf6wud+ hfW558Rwk8YfQtcLZj/RsvA9OTzkFAjaER+6OcPnDqwbqRCaUq35LmE+xzaKN7kNfcVz Fu6MSetYJl4myaiuyOQxgfMxfhCUUlUeXBZWPnCEf4VsJPiyEFvdm9K7naGaEXPuskkC HhTg== 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 :to:subject; bh=sMRtlxzgKciQpefbht+SxdipPmfDWOlUBx6yUEyWo6c=; b=AyAoSU0BDQN8ao1r8P9j1Z+2UdhMGGad2RrQtKnIv648i3DujW9mHFPya0kMDt+S1d t5n+Mnt1SGUNY+ObbcG2Demex5uUzcP2EGFU1hpWWRk8ds12/5BncPPSt7t/Nci+gNfl VkyCa2Kb/zUvP2LFf1xO+VaSBUpxBBDA5tK6oZTWASULy8VADxUwINH9J3ky2OWJmDV7 Jbih+Jyq53NApSMdLcGosAHMh4lJ/0uWDd97Vw0b/u3wtZ4+4/135v4DOM99Yfdj64L5 tFxW5uCjyW2U0pPaYM8a0wV2TsbMJd8fTaogrxtuBbOfnbC+6LtAnkpEnr3zJGcGeZEX Q3Jg== 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 i1si5732390ilq.80.2021.06.17.08.56.54; Thu, 17 Jun 2021 08:57:07 -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 S232704AbhFQMKn (ORCPT + 99 others); Thu, 17 Jun 2021 08:10:43 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:33743 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231299AbhFQMKl (ORCPT ); Thu, 17 Jun 2021 08:10:41 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C9012C0013; Thu, 17 Jun 2021 12:08:28 +0000 (UTC) Subject: Re: [PATCH v5 0/2] riscv: Map the kernel with correct permissions the first time 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 References: <20210617120124.1752541-1-alex@ghiti.fr> From: Alex Ghiti Message-ID: <3dbfd72c-6d51-5ae6-3e91-49ee52eed5bd@ghiti.fr> Date: Thu, 17 Jun 2021 14:08:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210617120124.1752541-1-alex@ghiti.fr> 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 17/06/2021 ? 14:01, Alexandre Ghiti a ?crit?: > 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(-) > @Palmer: I removed the previous patchset (v4) you took in for-next and cherry-picked those 2 while fixing conflicts, so if you do that in that order, you should not have any problem :) Thanks,