Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp147849pxv; Thu, 24 Jun 2021 05:02:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhasQDR5BjHXyEHSU43+O3xPzYTn3P0GV7aZ3qg7in9EYkKTLxZJiGUOfhyFQsRxrl7qd1 X-Received: by 2002:a05:6e02:20c3:: with SMTP id 3mr3254590ilq.131.1624536146821; Thu, 24 Jun 2021 05:02:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624536146; cv=none; d=google.com; s=arc-20160816; b=sFzbjhZ1RK3jheUH2H1eMtJpIKkrmOiVXkjek9Hc2yBf7BU5W4FNLs9pTPAADrM/JM aImW4BEtWiDNZeRFG0q8qhE5mT/jGj7R9lEFhqrwAOWOO6G+J+CXON9Y0qOgXZisx8iu GGncWIeCJVs24TZoneV4R3FxYjgE9b3yQ2h2idvPHxaglXDGvHHPfDRptFEX99NJ0fD3 jWbhrqPgsokfz2E6c9X+uLLdOpnDhA8pU4nBF7bjKjD9Kpo5G8Mb8nDaScuzqUNQHhuI N9jomaSOhwWPDD1TDq1+9fEGpzvlsE7F0bK0G9WIaadeWkxLaq5l+/MowQLhTfGK9AXH S6jw== 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=PJEx8c7POLnrHEfxY9NbEs7UPgPPvPzTe+tBEmarlIw=; b=GIh668ZZWo8dyUsyGqEmAZWimoNJgCoqqgnuuR60S4qG4hMA/donNHcEselgtctSfL pu3wlZJFP7tMwnWFFzAsjuq1BxFjeD3W2VTM5dYjqhw2jQ/R1JIt6ofDu8WzsOQV1GX4 3H+7y9p31+MaSP9jWxclYBi2CsnxPlGairB6hLX4wOEogkrSnFEwSbOPdx3ihLG+As5F C6dELSH1oSZZxMmROrMJ0HpZ/0Rrg85uqvNjhyYJYWmielV0f6HYxTltVo/R8CBcvwKu 1tvbmiyF8YkV8WAlIvHvhkzsKLHIXNfh7o97EYOItRMtUZDq4YEugZKki+igcHNamX4w naMw== 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 q14si2416455ilv.161.2021.06.24.05.02.14; Thu, 24 Jun 2021 05:02: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 S231293AbhFXMDI (ORCPT + 99 others); Thu, 24 Jun 2021 08:03:08 -0400 Received: from relay10.mail.gandi.net ([217.70.178.230]:58127 "EHLO relay10.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230480AbhFXMDF (ORCPT ); Thu, 24 Jun 2021 08:03:05 -0400 Received: (Authenticated sender: alex@ghiti.fr) by relay10.mail.gandi.net (Postfix) with ESMTPSA id A8F47240014; Thu, 24 Jun 2021 12:00:42 +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 v8 0/2] Map the kernel with correct permissions the first time Date: Thu, 24 Jun 2021 14:00:39 +0200 Message-Id: <20210624120041.2786419-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 v8: * Move set_kernel_memory inline function into set_memory.h header as suggested by Jisheng * Make set_kernel_memory arguments name consistent 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 | 24 ++++-- arch/riscv/kernel/setup.c | 12 +-- arch/riscv/mm/init.c | 112 ++++++++++++---------------- 5 files changed, 97 insertions(+), 81 deletions(-) -- 2.30.2