From patchwork Sun Jun 25 14:09:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 112600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6943515vqr; Sun, 25 Jun 2023 07:28:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Gd0vaUIgBhwWA5SApCld1DrRX7tt9OsoBHbTU9qzvrIp92OF+sZnadgq4o4rwG/uGQDq1 X-Received: by 2002:a17:903:2281:b0:1b3:cdfc:3e28 with SMTP id b1-20020a170903228100b001b3cdfc3e28mr6058133plh.23.1687703292489; Sun, 25 Jun 2023 07:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687703292; cv=none; d=google.com; s=arc-20160816; b=TrjbhtZL+k13NxWsEkwuZ5EwzEs8nRimRPAItkA/H58AKgQ6JS8eeFrEzhOEto8081 2a8N8WSqir1lZ1kuq2CXCbtCAt6neUILuWu3n5C0oaWO34uOEWmxGEQ1DxL+fj++SWl6 xRh+AbXXxQQrcz7mLLTKAMlyIciqCXmtt9L8HBtUCOHSgxL4R0f+5s1LLFelFZRGnBwS x1yja5g4NwvY4sC6qvtwrUJzIjyNy3uoXmVLiAO7ct3p7NTY3fN7WfZknCFCUtstQmhl t5GtouKe4dPeQYYRGY+pwRnkvgMiFJYD8YpdOiEqcWp5jz7ypIdmHQ9rarKBqHu9Aa+B F9hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=uw/MMc9dI4/TphiYskMVOaRlwby86KHhQkWS00kK2oE=; fh=2/EbjHRE7EKafzAkxWdKfWLNh6seQ7/0UQ7OzUYTgxI=; b=n/gR/Z/lSc9JyfGppqhrpgpXVJCvTzDF3je/QzSE/rnawAD9BxmpnenHUjy5kmgVkc UqLijGr8gD9t9P+hm9pa0BsHLAr5NqvSCZnjHyoW2ll/oxU6aeAizd8y364ipMBhRl1I Oki5IbrV2lqV1KT4rtTSM5apJgAjtmL918PYKs5E7ftWgUaGF+Jd6WKGyS9Ofn2adlDl FCTP4Yaj98iAQhYBvJL7S9RORYDKqtLoXEM6Pa+S69om/zODFW/t2FzN9rGuVcBAevqK FpVom4/XylUfYtgtejdwQrNRpYOSwO/w/QI4waYxvwtNFsQc+6Ces0mBb1xL8nJXYN0e whkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a170902ab8f00b001a6e719421asi2933607plr.366.2023.06.25.07.27.58; Sun, 25 Jun 2023 07:28:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjFYOK4 (ORCPT + 99 others); Sun, 25 Jun 2023 10:10:56 -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 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769685167686701193?= X-GMAIL-MSGID: =?utf-8?q?1769685167686701193?= 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); } -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 >= PGDIR_SIZE) + if (!(base & (PGDIR_SIZE - 1)) && size >= PGDIR_SIZE) return PGDIR_SIZE; - if (!(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE) + if (!(base & (P4D_SIZE - 1)) && size >= P4D_SIZE) return P4D_SIZE; - if (!(pa & (PUD_SIZE - 1)) && !(va & (PUD_SIZE - 1)) && size >= PUD_SIZE) + if (!(base & (PUD_SIZE - 1)) && size >= PUD_SIZE) return PUD_SIZE; - if (!(pa & (PMD_SIZE - 1)) && !(va & (PMD_SIZE - 1)) && size >= PMD_SIZE) + if (!(base & (PMD_SIZE - 1)) && size >= PMD_SIZE) return PMD_SIZE; return PAGE_SIZE; @@ -1178,7 +1177,7 @@ static void __init create_linear_mapping_range(phys_addr_t start, for (pa = start; pa < end; pa += map_size) { va = (uintptr_t)__va(pa); map_size = fixed_map_size ? fixed_map_size : - best_map_size(pa, va, end - pa); + best_map_size(pa, end - pa); create_pgd_mapping(swapper_pg_dir, va, pa, map_size, pgprot_from_va(va));