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 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 2FB09C4332F for ; Wed, 21 Dec 2022 22:27:43 +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-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yYkWbtCpFGlWBVrly4rrvWVz5AXjQYpJKUK3ylqt7CI=; b=xPVZfHtOnD7Ip4Ljk1+AXI9dWK dopo0x7t7TiV2FiexHhqPQE6sg0O9inROYNl37C4MnQ9pkdug5VxyZSlxEx7n53OMDbIw0SxKlcsJ f/FvP9WQFpePYb7vydf41zkevQZkPdJ+XBnzCKtvSDJElv55FkwRj5fFF4I0LQXz8RALICzlPwF0E o3s4bgyKRG1xprbF6kAqpx99RdQQWS8Hc1q1NiBSgU4TbNOXyRR/Y2GqwwqHxw/AJCJiKRc/PzW2T iLH9sSCTEXCQmbyoY+a/C/4T+6sVbDqVubynb1+yiA/oy/X+BS8vNPSVr2Bl5RuSkwpUc61Ftn+sv 5kuqBt5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p87Yd-0036cJ-0f; Wed, 21 Dec 2022 22:27:27 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p87YZ-0036ZW-60 for linux-riscv@lists.infradead.org; Wed, 21 Dec 2022 22:27:25 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EC187B81BA5; Wed, 21 Dec 2022 22:27:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8FAEC433D2; Wed, 21 Dec 2022 22:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671661639; bh=DeE701axTftUD20gtPeSs1lKxbAiPCgvCwAGUnPUotc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oED22h9AA7zhPbiAm+t/bfkORPfkBBplYle9i80ogu2iI0R0hSCNlbuuUrJQXglJq VbhwcTVRv0/TUUVp+a9nD7aM1WR0EDmhcJJ4edq/R6SFJf3U/vEQRdvi91VDfygIQy 1lUJex0/ja206oOC1Pljtm2j+7wOSwuO5HyJ8swczrpICErAPymSVuFIX0/BQngPzO DPvnJTgLTl74oraEzLJr7bomNkZfoiFXZBSTYXcrVPDzEj7oeSjAsvv8o/CiOOrjUH ZvKS19BjRlb1BNlsP0qaxcVhcT4z28rF6ndGQxQ5iWyZ4Ap4wYr+0LUR3zGkm4H8Qi kZ56BRxVt4TOw== Date: Wed, 21 Dec 2022 22:27:15 +0000 From: Conor Dooley To: Alexandre Ghiti Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v2] riscv: Allow to downgrade paging mode from the command line Message-ID: References: <20221215081948.1256610-1-alexghiti@rivosinc.com> MIME-Version: 1.0 In-Reply-To: <20221215081948.1256610-1-alexghiti@rivosinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221221_142723_585711_D14F21EC X-CRM114-Status: GOOD ( 37.91 ) 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: multipart/mixed; boundary="===============4418537111362693064==" Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org --===============4418537111362693064== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2CgsAwd7ZL+qgvLr" Content-Disposition: inline --2CgsAwd7ZL+qgvLr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Alex, On Thu, Dec 15, 2022 at 09:19:48AM +0100, Alexandre Ghiti wrote: > Add 2 early command line parameters called "no5lvl" and "no4lvl" (using > the same naming as x86) to allow a user to downgrade from sv57 (the > default mode if the hardware supports it) to sv48 or sv39. Pardon my innocence here, but does the "no4lvl" option not also allow downgrading from sv48 to sv39? If that's the case, I assume the message could be amended on application. > Note that going through the device tree to get the kernel command line > works with ACPI too since the efi stub creates a device tree anyway with > the command line. >=20 > Also, as those params are treated very early in the boot process and we > use standard device tree functions that may be kasan instrumented, we > only enable them for !KASAN configurations. I don't have a suggestion for you, so I am just airing my thoughts really - are we likely to end up confusing people as it's not immediately obvious that these options do not work if KASAN is enabled? I know KASAN really isn't something you want in a production kernel, but should we be flagging the incompatibility somewhere that "users" would see? kernel-parameters.txt does usually seem to mention config options where relevant, and in the case of iommu.strict also mentions some arch specific behaviour. Should we mention it there then? Thanks, Conor. > Signed-off-by: Alexandre Ghiti > --- >=20 > v2: > - Honor CMDLINE_EXTEND and CMDLINE_FORCE as noticed by Bj=F6rn >=20 > .../admin-guide/kernel-parameters.txt | 5 +- > arch/riscv/mm/init.c | 72 +++++++++++++++++-- > 2 files changed, 70 insertions(+), 7 deletions(-) >=20 > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentat= ion/admin-guide/kernel-parameters.txt > index a465d5242774..6741524aa980 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -3548,7 +3548,10 @@ > emulation library even if a 387 maths coprocessor > is present. > =20 > - no5lvl [X86-64] Disable 5-level paging mode. Forces > + no4lvl [RISCV] Disable 4-level paging mode. Forces > + kernel to use 3-level paging instead. > + > + no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces > kernel to use 4-level paging instead. > =20 > nofsgsbase [X86] Disables FSGSBASE instructions. > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..d90fbe9ad494 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -746,17 +746,77 @@ static void __init disable_pgtable_l4(void) > satp_mode =3D SATP_MODE_39; > } > =20 > +#ifndef CONFIG_KASAN > +static __init bool match_noXlvl(const char *cmdline) > +{ > + if (strstr(cmdline, "no5lvl")) { > + disable_pgtable_l5(); > + } else if (strstr(cmdline, "no4lvl")) { > + disable_pgtable_l5(); > + disable_pgtable_l4(); > + return true; > + } > + > + return false; > +} > + > +static int __init print_no4lvl(char *p) > +{ > + pr_info("Disabled 4-level and 5-level paging"); > + return 0; > +} > +early_param("no4lvl", print_no4lvl); > + > +static int __init print_no5lvl(char *p) > +{ > + pr_info("Disabled 5-level paging"); > + return 0; > +} > +early_param("no5lvl", print_no5lvl); > +#endif > + > /* > * There is a simple way to determine if 4-level is supported by the > * underlying hardware: establish 1:1 mapping in 4-level page table mode > * then read SATP to see if the configuration was taken into account > * meaning sv48 is supported. > */ > -static __init void set_satp_mode(void) > +static __init void set_satp_mode(uintptr_t dtb_pa) > { > u64 identity_satp, hw_satp; > uintptr_t set_satp_mode_pmd =3D ((unsigned long)set_satp_mode) & PMD_MA= SK; > - bool check_l4 =3D false; > + > +#ifndef CONFIG_KASAN > + /* > + * The below fdt functions are kasan instrumented, since at this point > + * there is no mapping for the kasan shadow memory, this can't be used > + * when kasan is enabled. > + */ > + int chosen_node; > + unsigned int fdt_cmdline_size =3D 0; > + > + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { > + chosen_node =3D fdt_path_offset((void *)dtb_pa, "/chosen"); > + if (chosen_node >=3D 0) { > + const char *fdt_cmdline; > + > + fdt_cmdline =3D fdt_getprop((void *)dtb_pa, chosen_node, > + "bootargs", NULL); > + if (fdt_cmdline) { > + if (match_noXlvl(fdt_cmdline)) > + return; > + fdt_cmdline_size =3D strlen(fdt_cmdline); > + } > + } > + } > + > + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || > + IS_ENABLED(CONFIG_CMDLINE_FORCE) || > + fdt_cmdline_size =3D=3D 0 /* CONFIG_CMDLINE_FALLBACK */) { > + if (match_noXlvl(CONFIG_CMDLINE)) > + return; > + } > +#endif > =20 > create_p4d_mapping(early_p4d, > set_satp_mode_pmd, (uintptr_t)early_pud, > @@ -775,7 +835,8 @@ static __init void set_satp_mode(void) > retry: > create_pgd_mapping(early_pg_dir, > set_satp_mode_pmd, > - check_l4 ? (uintptr_t)early_pud : (uintptr_t)early_p4d, > + pgtable_l5_enabled ? > + (uintptr_t)early_p4d : (uintptr_t)early_pud, > PGDIR_SIZE, PAGE_TABLE); > =20 > identity_satp =3D PFN_DOWN((uintptr_t)&early_pg_dir) | satp_mode; > @@ -786,9 +847,8 @@ static __init void set_satp_mode(void) > local_flush_tlb_all(); > =20 > if (hw_satp !=3D identity_satp) { > - if (!check_l4) { > + if (pgtable_l5_enabled) { > disable_pgtable_l5(); > - check_l4 =3D true; > memset(early_pg_dir, 0, PAGE_SIZE); > goto retry; > } > @@ -979,7 +1039,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > #endif > =20 > #if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL) > - set_satp_mode(); > + set_satp_mode(dtb_pa); > #endif > =20 > kernel_map.va_pa_offset =3D PAGE_OFFSET - kernel_map.phys_addr; > --=20 > 2.37.2 >=20 >=20 --2CgsAwd7ZL+qgvLr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCY6OIQwAKCRB4tDGHoIJi 0l9pAQD5X/kxAPfoDuAklRSqKRdq2/SSSr4DNDtuvpbT6yKVZQD/eHjqmn5HHG1P B58VNpyWRtwZkIRPH/BfDEJGzdpAigs= =usPd -----END PGP SIGNATURE----- --2CgsAwd7ZL+qgvLr-- --===============4418537111362693064== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv --===============4418537111362693064==-- 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 163CEC4332F for ; Wed, 21 Dec 2022 22:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235093AbiLUWaM (ORCPT ); Wed, 21 Dec 2022 17:30:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235081AbiLUW3q (ORCPT ); Wed, 21 Dec 2022 17:29:46 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A277427B0D; Wed, 21 Dec 2022 14:28:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1788BB81C3B; Wed, 21 Dec 2022 22:27:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8FAEC433D2; Wed, 21 Dec 2022 22:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671661639; bh=DeE701axTftUD20gtPeSs1lKxbAiPCgvCwAGUnPUotc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oED22h9AA7zhPbiAm+t/bfkORPfkBBplYle9i80ogu2iI0R0hSCNlbuuUrJQXglJq VbhwcTVRv0/TUUVp+a9nD7aM1WR0EDmhcJJ4edq/R6SFJf3U/vEQRdvi91VDfygIQy 1lUJex0/ja206oOC1Pljtm2j+7wOSwuO5HyJ8swczrpICErAPymSVuFIX0/BQngPzO DPvnJTgLTl74oraEzLJr7bomNkZfoiFXZBSTYXcrVPDzEj7oeSjAsvv8o/CiOOrjUH ZvKS19BjRlb1BNlsP0qaxcVhcT4z28rF6ndGQxQ5iWyZ4Ap4wYr+0LUR3zGkm4H8Qi kZ56BRxVt4TOw== Date: Wed, 21 Dec 2022 22:27:15 +0000 From: Conor Dooley To: Alexandre Ghiti Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v2] riscv: Allow to downgrade paging mode from the command line Message-ID: References: <20221215081948.1256610-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2CgsAwd7ZL+qgvLr" Content-Disposition: inline In-Reply-To: <20221215081948.1256610-1-alexghiti@rivosinc.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --2CgsAwd7ZL+qgvLr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hey Alex, On Thu, Dec 15, 2022 at 09:19:48AM +0100, Alexandre Ghiti wrote: > Add 2 early command line parameters called "no5lvl" and "no4lvl" (using > the same naming as x86) to allow a user to downgrade from sv57 (the > default mode if the hardware supports it) to sv48 or sv39. Pardon my innocence here, but does the "no4lvl" option not also allow downgrading from sv48 to sv39? If that's the case, I assume the message could be amended on application. > Note that going through the device tree to get the kernel command line > works with ACPI too since the efi stub creates a device tree anyway with > the command line. >=20 > Also, as those params are treated very early in the boot process and we > use standard device tree functions that may be kasan instrumented, we > only enable them for !KASAN configurations. I don't have a suggestion for you, so I am just airing my thoughts really - are we likely to end up confusing people as it's not immediately obvious that these options do not work if KASAN is enabled? I know KASAN really isn't something you want in a production kernel, but should we be flagging the incompatibility somewhere that "users" would see? kernel-parameters.txt does usually seem to mention config options where relevant, and in the case of iommu.strict also mentions some arch specific behaviour. Should we mention it there then? Thanks, Conor. > Signed-off-by: Alexandre Ghiti > --- >=20 > v2: > - Honor CMDLINE_EXTEND and CMDLINE_FORCE as noticed by Bj=F6rn >=20 > .../admin-guide/kernel-parameters.txt | 5 +- > arch/riscv/mm/init.c | 72 +++++++++++++++++-- > 2 files changed, 70 insertions(+), 7 deletions(-) >=20 > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentat= ion/admin-guide/kernel-parameters.txt > index a465d5242774..6741524aa980 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -3548,7 +3548,10 @@ > emulation library even if a 387 maths coprocessor > is present. > =20 > - no5lvl [X86-64] Disable 5-level paging mode. Forces > + no4lvl [RISCV] Disable 4-level paging mode. Forces > + kernel to use 3-level paging instead. > + > + no5lvl [X86-64,RISCV] Disable 5-level paging mode. Forces > kernel to use 4-level paging instead. > =20 > nofsgsbase [X86] Disables FSGSBASE instructions. > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..d90fbe9ad494 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -746,17 +746,77 @@ static void __init disable_pgtable_l4(void) > satp_mode =3D SATP_MODE_39; > } > =20 > +#ifndef CONFIG_KASAN > +static __init bool match_noXlvl(const char *cmdline) > +{ > + if (strstr(cmdline, "no5lvl")) { > + disable_pgtable_l5(); > + } else if (strstr(cmdline, "no4lvl")) { > + disable_pgtable_l5(); > + disable_pgtable_l4(); > + return true; > + } > + > + return false; > +} > + > +static int __init print_no4lvl(char *p) > +{ > + pr_info("Disabled 4-level and 5-level paging"); > + return 0; > +} > +early_param("no4lvl", print_no4lvl); > + > +static int __init print_no5lvl(char *p) > +{ > + pr_info("Disabled 5-level paging"); > + return 0; > +} > +early_param("no5lvl", print_no5lvl); > +#endif > + > /* > * There is a simple way to determine if 4-level is supported by the > * underlying hardware: establish 1:1 mapping in 4-level page table mode > * then read SATP to see if the configuration was taken into account > * meaning sv48 is supported. > */ > -static __init void set_satp_mode(void) > +static __init void set_satp_mode(uintptr_t dtb_pa) > { > u64 identity_satp, hw_satp; > uintptr_t set_satp_mode_pmd =3D ((unsigned long)set_satp_mode) & PMD_MA= SK; > - bool check_l4 =3D false; > + > +#ifndef CONFIG_KASAN > + /* > + * The below fdt functions are kasan instrumented, since at this point > + * there is no mapping for the kasan shadow memory, this can't be used > + * when kasan is enabled. > + */ > + int chosen_node; > + unsigned int fdt_cmdline_size =3D 0; > + > + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { > + chosen_node =3D fdt_path_offset((void *)dtb_pa, "/chosen"); > + if (chosen_node >=3D 0) { > + const char *fdt_cmdline; > + > + fdt_cmdline =3D fdt_getprop((void *)dtb_pa, chosen_node, > + "bootargs", NULL); > + if (fdt_cmdline) { > + if (match_noXlvl(fdt_cmdline)) > + return; > + fdt_cmdline_size =3D strlen(fdt_cmdline); > + } > + } > + } > + > + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || > + IS_ENABLED(CONFIG_CMDLINE_FORCE) || > + fdt_cmdline_size =3D=3D 0 /* CONFIG_CMDLINE_FALLBACK */) { > + if (match_noXlvl(CONFIG_CMDLINE)) > + return; > + } > +#endif > =20 > create_p4d_mapping(early_p4d, > set_satp_mode_pmd, (uintptr_t)early_pud, > @@ -775,7 +835,8 @@ static __init void set_satp_mode(void) > retry: > create_pgd_mapping(early_pg_dir, > set_satp_mode_pmd, > - check_l4 ? (uintptr_t)early_pud : (uintptr_t)early_p4d, > + pgtable_l5_enabled ? > + (uintptr_t)early_p4d : (uintptr_t)early_pud, > PGDIR_SIZE, PAGE_TABLE); > =20 > identity_satp =3D PFN_DOWN((uintptr_t)&early_pg_dir) | satp_mode; > @@ -786,9 +847,8 @@ static __init void set_satp_mode(void) > local_flush_tlb_all(); > =20 > if (hw_satp !=3D identity_satp) { > - if (!check_l4) { > + if (pgtable_l5_enabled) { > disable_pgtable_l5(); > - check_l4 =3D true; > memset(early_pg_dir, 0, PAGE_SIZE); > goto retry; > } > @@ -979,7 +1039,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) > #endif > =20 > #if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL) > - set_satp_mode(); > + set_satp_mode(dtb_pa); > #endif > =20 > kernel_map.va_pa_offset =3D PAGE_OFFSET - kernel_map.phys_addr; > --=20 > 2.37.2 >=20 >=20 --2CgsAwd7ZL+qgvLr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCY6OIQwAKCRB4tDGHoIJi 0l9pAQD5X/kxAPfoDuAklRSqKRdq2/SSSr4DNDtuvpbT6yKVZQD/eHjqmn5HHG1P B58VNpyWRtwZkIRPH/BfDEJGzdpAigs= =usPd -----END PGP SIGNATURE----- --2CgsAwd7ZL+qgvLr--