From nobody Wed Feb 11 06:50:22 2026 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 B0DFAEB64DC for ; Sun, 25 Jun 2023 14:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbjFYOK5 (ORCPT ); Sun, 25 Jun 2023 10:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbjFYOKx (ORCPT ); Sun, 25 Jun 2023 10:10:53 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 119E9E43 for ; Sun, 25 Jun 2023 07:10:51 -0700 (PDT) X-QQ-mid: bizesmtp73t1687702214tvcj0zr9 Received: from localhost.localdomain ( [112.2.230.41]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 25 Jun 2023 22:10:11 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: lm7sZZPcOdayF/iPi2BR4TEQZ9thVeHoHrWDwBsJL4ncQ7c+lAS11zf54xTy3 Fo3M0/o47zsFTuHKr0OZtWzSNREVR8bTElBgt+LPq2dRqUYvWaBDaY7slSNJw+xNRpQWEA+ Rjv+tFEu+l41GgNbJ595Tpfo1ghEl1eY2WMgh2qBvy0mSydhFy6oAbkbAVm1bZzrsEpYThM wNZ8EOsZjsJoW9egl0Ac058twNt2/hFuBOikHE40Oz6wyQzk44N8LcxXwoDcmzlKWZUWryH FH200fkpS3gW0ZRaqqxfSyg8II+IuY93paiLI5RgaoFXH0rFo3Iaj/JntyYdOJtBftM01yq CGxtWz18la1yzqzwCO2TF510Ar3DePwU1NY0qSz X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3093032413490913072 From: Song Shuai To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, frowand.list@gmail.com, ajones@ventanamicro.com, alexghiti@rivosinc.com, mpe@ellerman.id.au, arnd@arndb.de, songshuaishuai@tinylab.org, rppt@kernel.org, samuel@sholland.org, panqinglin2020@iscas.ac.cn, conor.dooley@microchip.com, anup@brainfault.org, xianting.tian@linux.alibaba.com, anshuman.khandual@arm.com, heiko@sntech.de Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH V1 2/3] Revert "riscv: Check the virtual alignment before choosing a map size" Date: Sun, 25 Jun 2023 22:09:30 +0800 Message-Id: <20230625140931.1266216-3-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230625140931.1266216-1-songshuaishuai@tinylab.org> References: <20230625140931.1266216-1-songshuaishuai@tinylab.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This reverts commit 49a0a3731596fc004db6eec3fc674d92a09ef383. With the commit 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping") reverted, best_map_size() only uses PMD_SIZE or PAGE_SIZE for linear mapping and the phys_ram_base that va_pa_offset is based on points the kernel load address which is 2M-aligned for rv64. So no need to check the virtual alignment before choosing a map size. Signed-off-by: Song Shuai --- arch/riscv/mm/init.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 4fa420faa780..38c4b4d6b64f 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -660,19 +660,18 @@ void __init create_pgd_mapping(pgd_t *pgdp, create_pgd_next_mapping(nextp, va, pa, sz, prot); } =20 -static uintptr_t __init best_map_size(phys_addr_t pa, uintptr_t va, - phys_addr_t size) +static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) { - if (!(pa & (PGDIR_SIZE - 1)) && !(va & (PGDIR_SIZE - 1)) && size >=3D PGD= IR_SIZE) + if (!(base & (PGDIR_SIZE - 1)) && size >=3D PGDIR_SIZE) return PGDIR_SIZE; =20 - if (!(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >=3D P4D_SIZ= E) + if (!(base & (P4D_SIZE - 1)) && size >=3D P4D_SIZE) return P4D_SIZE; =20 - if (!(pa & (PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >=3D PUD_SIZ= E) + if (!(base & (PUD_SIZE - 1)) && size >=3D PUD_SIZE) return PUD_SIZE; =20 - if (!(pa & (PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >=3D PMD_SIZ= E) + if (!(base & (PMD_SIZE - 1)) && size >=3D PMD_SIZE) return PMD_SIZE; =20 return PAGE_SIZE; @@ -1178,7 +1177,7 @@ static void __init create_linear_mapping_range(phys_a= ddr_t start, for (pa =3D start; pa < end; pa +=3D map_size) { va =3D (uintptr_t)__va(pa); map_size =3D fixed_map_size ? fixed_map_size : - best_map_size(pa, va, end - pa); + best_map_size(pa, end - pa); =20 create_pgd_mapping(swapper_pg_dir, va, pa, map_size, pgprot_from_va(va)); --=20 2.20.1