Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4497510pxj; Tue, 22 Jun 2021 01:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk12h2d+oU42saHuj+y0MxwrfwvegL/RqytwnABt6CMu+5DvIgF5+rMDAMQ0PcErI5Q5g6 X-Received: by 2002:a92:d601:: with SMTP id w1mr1823570ilm.1.1624350143058; Tue, 22 Jun 2021 01:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624350143; cv=none; d=google.com; s=arc-20160816; b=iv4QyQXXEhBBD6C19bzSzm0+5B6bXIkNTvUOJN0eDsqn/F0lFUgmN1Xe07ej9SzAHJ ablFwPhmSZSYCaqN1UYHIe4Q1T3o958zl99WNdyGg7wDG//grsMs46eJp17Yrak6Hccf z7IvghFWFBywORSDfZ1x5gR6Pm6QWIn/TR81+Td2e8FFiz7BSaOFDbKMm2eoKBtV4fOd onIrIBbHFn3IRa8mMotgoMz10AvLFvXhTlb9ax38vflEf4s/Uzrf4iJ4cmGmuqES9uvB jsPZ7eKa2hfNYnJC0CWCLYvloq4BkseSYwNAHxvK9fBwA8k0IHrWFlcOipU6Eldu7071 ikjA== 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=j1eHf7NiB4kNh+OOZxvibObLdFXuo0za4Uc4LfeUK3g=; b=bHkxR27nMF5kxV18cWqVHyUwYiV76Eugq+7edZe3c8FeISJFVorboTU3KzKXUiBNnK uC7okyAAP7+OCfFURjBLtbc5e71fFyj1UIDa9h5NrZcGCtSg5auOWm4mf2hSqLfguotx V5VCJ30fTCfwKkFPcYTHc7Q2g2vgVeQ/v4Zy01pCV6OMo+AURkodKRlVNzueXKGWQ1Xt CeDydaznUaVbNi+OFO9rGBwkC34dIoB8ciZx6xDINtolcXU0mzIFN6PuZitzc9xP6k9d 9/U927ns471llWlpaNMQU+6ZC3KDmO6UkoAZ6yY+4N4sJm6RmHDL7r8ZBTEQOGndSFwr BlBg== 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 u6si15505215ilq.55.2021.06.22.01.22.11; Tue, 22 Jun 2021 01:22:23 -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 S230439AbhFVIX4 (ORCPT + 99 others); Tue, 22 Jun 2021 04:23:56 -0400 Received: from relay2-d.mail.gandi.net ([217.70.183.194]:58725 "EHLO relay2-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbhFVIXy (ORCPT ); Tue, 22 Jun 2021 04:23:54 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 4AF6840010; Tue, 22 Jun 2021 08:21:36 +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 v7 0/2] Map the kernel with correct permissions the first time Date: Tue, 22 Jun 2021 10:21:32 +0200 Message-Id: <20210622082134.2404162-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 v7: * Split long lines and reintroduce parameters names of set_kernel_memory callback, as suggested by Christoph * Make set_kernel_memory __always_inline as suggested by Christoph * Change 64b spelling into 64-bit, as suggested by Christoph Changes in v6: * load_sz was placed in init section but is now used in kernel address conversions macros, so remove this attribute. 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 | 16 ++-- arch/riscv/kernel/setup.c | 12 +-- arch/riscv/mm/init.c | 112 ++++++++++++---------------- arch/riscv/mm/pageattr.c | 11 +++ 6 files changed, 100 insertions(+), 81 deletions(-) -- 2.30.2