From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2668C47082 for ; Thu, 3 Jun 2021 08:27:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3AF8613DE for ; Thu, 3 Jun 2021 08:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbhFCI3m (ORCPT ); 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 851F9C47096 for ; Thu, 3 Jun 2021 08:28:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 58233613C9 for ; Thu, 3 Jun 2021 08:28:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58233613C9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1N0CcygAQKPwnawQuqsZRGASCJtWuHbHIaAa7xdLLSA=; b=gA5km2Y48uQPzh DKQFyyon+Tk5FOQrY+i5jYVjY5xz/fMDgvVvow/xQH7X98RtNsmGM08M140ORicPz2r7pX0hzAcRF QG+BxDH4e8vg149eslRrLeryg9N9J94zALNIDYkNGMO8MOwt3Z7zU7/Cxfwa3rrHhOBxqT0y5nhEt bvfbNMm+PhIXlI5NEUwoGp3VLWGaArRQHHZIclUxhRXrlHgeRXuRlH0mT4hLD/DuyS44B7nbjSHT+ UOqnGVV/RH3sQHUQDaJvysaZYVeseJFxZxTuA5phBhj16xEa0zo8YxMYJl6rh8ZJ4TYMKHDyUACRi TJ98DuEf1mYe1k29XBzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1loihv-007gsO-Ep; Thu, 03 Jun 2021 08:28:03 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1loihs-007gqm-Di for linux-riscv@lists.infradead.org; Thu, 03 Jun 2021 08:28:01 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210603_012800_630415_A180D84B X-CRM114-Status: GOOD ( 11.66 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv