From patchwork Tue Feb 28 15:46:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13155046 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 67A3FC64ED6 for ; Tue, 28 Feb 2023 15:46:49 +0000 (UTC) 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=1aLv0C214V2rRIs5tGyyW7LXS5ABWam6q6h0yD9A/lk=; b=0JMfcbZNGJAaT9 ATrtdv8Cd5/5h/snHLLpjCk350OXyznBEm1lS6YYAKUdeFBmrEtevA/0UG2nGdEQSrrKHSkQSH+Hh 4k9GVE5wwDYzbPljyaqousmuV0y1Cc++oQf5eZKtcexxik237DT79z5MaA7YCdKCpISbC2eDQ7ZlO CzGmDvEblIa1k2WhLB8d5ZuvTP1nbEv2TCU42quR958M5a72ElXnFw1wywH+Wj9iFJtoheXUcrjwG jD25xeLCdMXWG88D18p4wMokirnGKwDxyeL0uqzBu/M3fV5ymd0s/OzUg9f7DffCYfII/PN5pAxY6 fiMtyO0hX5UieQZ/64VA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX2Bb-00DfvT-2u; Tue, 28 Feb 2023 15:46:39 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX2BY-00DfuG-7w for linux-riscv@lists.infradead.org; Tue, 28 Feb 2023 15:46:38 +0000 Received: by mail-wr1-x432.google.com with SMTP id t15so10243314wrz.7 for ; Tue, 28 Feb 2023 07:46:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1677599193; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UoR1tCMqBp+csZse58QFeQTl6XiwfpRChiE77LfzzYo=; b=yVJiteKDOKx05exhBTQfkblzBUFYBV3RpEh+t371JH9Huxj90BDLY3pgO6oCDUt197 Xs+BgPVxxh80ZymxFXB1moFb8j8LT3tgjv69XJdDbLKNi/o2Mt/cYEK/rWElTEpqTyE7 APoBkOHpaTb0w9nMY3rlg6SgNf2f27WlvinT/x3If0c5gq6dMYf4e+OtXlgwFAfQCOt4 S3kK3mFZdbnvlt8uxBfWhqLu3eV9TnsMwtX9Yeb13iIu6qp1pANC3A6yRct7k2xmBE3o dlyqutgCzf4bMuUG9eJ7AK0JT2oZxYSNE2o54sZVm7t3318xqY3VYDBLNP3AFSQujlyV rSpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677599193; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UoR1tCMqBp+csZse58QFeQTl6XiwfpRChiE77LfzzYo=; b=vL9pp1e+rd0g8/49EaTIS4vyB6dKkI3SYLVJj3kv9VqsrKuZcJYzQqK/BowIw9UcT7 FlD5/VCCr3HF+3I3hOkA9HgQINn2WwUfZMS5pqkSdbjcVOyUdywRnqFoeb7NgU1Sm2aA Yb3nW3fSlVMszT+zWxt9ajmaBX1eFz6TIwlXm85/idUXMBrEvO2okcamTDRPrs6ex0X5 ZkY6Od7H/ZipQAmZgClqlShG+vbWW/S/p2lnT4+qzypufujv7Vd4Q8iDIXrNzr+X3SDx CicmG3Zeaf5odUWZ53oybqMJnHt/R73F7NAktJMrGHQlXWLMCbC42cYRUsmEPf38YO5X vvgA== X-Gm-Message-State: AO0yUKUDQHw4LGJh18jkxGpCfhIJVB1QcNH55EHZqUVNvXzZoGLfzMST JLXS+J6pq4sMI4ZdCD40PW7vGQ== X-Google-Smtp-Source: AK7set9VVCtNON7BjfYFEn4DTD0yqlg1psIpUaMtYWkHZHahodZ1gU0u3rTiKHVc8V7atr0Iv41aKQ== X-Received: by 2002:adf:fe8b:0:b0:2cc:3308:514f with SMTP id l11-20020adffe8b000000b002cc3308514fmr2142195wrr.57.1677599193296; Tue, 28 Feb 2023 07:46:33 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (lfbn-gre-1-235-32.w90-112.abo.wanadoo.fr. [90.112.194.32]) by smtp.gmail.com with ESMTPSA id c4-20020adffb04000000b002c70bfe505esm10122806wrr.82.2023.02.28.07.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 07:46:32 -0800 (PST) From: Alexandre Ghiti To: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Ard Biesheuvel , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: Alexandre Ghiti Subject: [PATCH v8 0/1] riscv: Allow to downgrade paging mode from the command line Date: Tue, 28 Feb 2023 16:46:28 +0100 Message-Id: <20230228154629.240541-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230228_074636_498651_DB3D89CC X-CRM114-Status: GOOD ( 17.04 ) 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: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This new version gets rid of the limitation that prevented KASAN kernels to use the newly introduced parameters. While looking into KASLR, I fell onto commit aacd149b6238 ("arm64: head: avoid relocating the kernel twice for KASLR"): it allows to use the fdt functions very early in the boot process with KASAN enabled by simply compiling a new version of those functions without instrumentation. I had to change the handling of the command line parsing to make the code self-contained in kernel/pi/cmd_early.c to avoid calling too many __pi prefixed functions from outside this file. I'll use this approach like arm64 to handle the extraction of the random seedi from the device tree for KASLR. base-commit: eb9be8310c58 ("RISC-V: add a spin_shadow_stack declaration") v8: - Fix LLVM ld warning by moving the section .init.sdata from kernel/pi/string.c into the newly created section .init.pidata v7: - Rebased on top of for-next which introduces lots of errors (thanks to the patchwork CI) - Add __NO_FORTIFY to avoid undefined __pi_fortify_panic - Add an alias to our newly introduced strlen - Remove __init as sections are already prefixed in the Makefile - Introduce new section for kernel/pi/string.c to quiet the following warnings (once we have all the string functions, we'll be able to get rid of this): warning: orphan section `.init__bug_table' from `arch/riscv/kernel/pi/string.pi.o' being placed in section `.init__bug_table' warning: orphan section `.init.srodata.cst8' from `arch/riscv/kernel/pi/string.pi.o' being placed in section `.init.srodata.cst8' v6: - Fix llvm warning by forward declaring set_satp_mode_from_cmdline v5: - Handle null command line, Thanks Björn! - Add RB/TB from Björn v4: - Introduce pi/ for KASAN to work v3: - Massage commit log to make no4lvl clearer, as asked by Conor - Add a note to kernel-parameters.txt regarding the impossibility to use those parameters when KASAN is enabled, as suggested by Conor - Add RB from Björn v2: - Honor CMDLINE_EXTEND and CMDLINE_FORCE as noticed by Björn Alexandre Ghiti (1): riscv: Allow to downgrade paging mode from the command line .../admin-guide/kernel-parameters.txt | 5 +- arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/pi/Makefile | 37 +++++++++++ arch/riscv/kernel/pi/cmdline_early.c | 62 +++++++++++++++++++ arch/riscv/kernel/vmlinux.lds.S | 8 +++ arch/riscv/lib/memcpy.S | 2 + arch/riscv/lib/memmove.S | 2 + arch/riscv/lib/strlen.S | 1 + arch/riscv/mm/init.c | 36 +++++++++-- 9 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 arch/riscv/kernel/pi/Makefile create mode 100644 arch/riscv/kernel/pi/cmdline_early.c