From patchwork Wed May 8 11:34:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13658598 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 0DF5BC04FFE for ; Wed, 8 May 2024 11:34:46 +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=U1ha1UTRODC1vO8Em6ijDQhcJXrMOPX7+4zCSpgrc8k=; b=yfm2C1aISKxgO7 cYCJN9HhwQF9OJ7ut5rwcsed4rsoTcQYSkucmPDRp4BFRvSrygiznHcmq/W5XfBZgzRZh678LWJPC ndv5CkBjUD9mRfI6OuXHkBvUP+dqWiKoeuD2navylZgQ6msTJOmTt769dKU42qQJsmQ49ofwDyeJR KeRbKD9xmUa2mrzwzn4sox89tPxS5FQzOHakKeV+RPDiYV2krOrM6XpC0iM8K5FAYidifDjIFP8rG c2dEML9+KoQGJafiBQh2URW4m2wUoVytspVL5oYLzEtZ9fzowDLtp2GEyvq1K65doweFTcoens3zU ZnGQnH5PBqwHQ+Ut1A7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4fZ9-0000000FFXy-0QCs; Wed, 08 May 2024 11:34:31 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4fZ5-0000000FFVb-0PR4 for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 11:34:29 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52192578b95so696693e87.2 for ; Wed, 08 May 2024 04:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715168064; x=1715772864; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=eQ0KJYPs0gQAHqctoVvzeqlFxyt4eoi3klcRWGyTeY6GFUovZ1m+C8Pbcc2OIaikN6 18/96R7xwhe0XIsxa1u7FcbnaoJlRxMjSkYtRw+1Z/lxNeNPZBAnOpYG2WEKQCCjzPBZ /1LFRa7iwU78mLw6smz2rMkNH/kabmRK/7OJcxeWd1JSRYVi1UwBgaskYUiLusVwlWlL 8s/yEPqlX6U3Yz4H2mVSWdfozc4nRaZt0mW1Cj0larHmZ8DjagimJZpRpLz6oOU8Epw1 FH47MYT+0mRUXrlKP5wdONsWqng7bOKSVHizsNWpHwYcKgesT8LyPSRR1uGToqOp/l6K Zffw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715168064; x=1715772864; 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=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=P2S84FcJxh2zaTm1gwNY5V5Ly373NSEEcYJvaxx+7tlL6t5fo23v4MthbSXv/hDoAp /HueJR66RZ3A9r3zLckGimW2DdQlAWNK4ihEqw/T8XzgPxXWPyxJzCBUY7uDYgfI3jKM IEqZLFW64p0cml20TiJyJxzJOeIOkgBXqsX3FhA84RavRlViyfEq1GGFgd+rue4gtIBp FDOujUdUEcQCLuOHN2NcOXIOovD+p2ZBzl+sRGez0U/m78/WO3PSdEx5bb6/1Ce2DwsQ YD+Rtnxs4UsVY332hurjzV1DRUaQf04X2wpQnbapANNESl74W2TXTD6/+4D7LxHF09G/ AR3g== X-Forwarded-Encrypted: i=1; AJvYcCXmTJkkKDC0w8vANteGV+xZZpFELODrXPayzqM/gtFOlXBtfiFcycg3n4nq0ROdhqu0DNOlPIhCPhU6B0t2ykuH/cR/w7s7kICnm55lYH6Y+h81U2E= X-Gm-Message-State: AOJu0Yw6aAPKu6GcwyLbLPoP6e35zEv+JTF7u2nWHLP0qETEX9DEUusm buZmIpuM7eWmRCKwfgE70smlHEgb7iridvIhbLpXW0wJ0F0Gjde8hSqnNkAqAhM= X-Google-Smtp-Source: AGHT+IHQ0+1QRr9yi6sWcDZ0EGp5PxgqjX1SIZMCwr+oGXVeU6XovCaKI7Yf+LAxYXYIcWcDnNZqDg== X-Received: by 2002:a05:6512:3493:b0:51d:7d4a:5e6e with SMTP id 2adb3069b0e04-5217c276f94mr1361793e87.3.1715168064446; Wed, 08 May 2024 04:34:24 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id z8-20020a05600c0a0800b00418db9e4228sm2001659wmp.29.2024.05.08.04.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:34:24 -0700 (PDT) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH RESEND v2 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Wed, 8 May 2024 13:34:10 +0200 Message-Id: <20240508113419.18620-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_043427_153406_32BA0F3C X-CRM114-Status: GOOD ( 15.81 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patchset intends to merge the contiguous ptes hugetlbfs implementation of arm64 and riscv. Both arm64 and riscv support the use of contiguous ptes to map pages that are larger than the default page table size, respectively called contpte and svnapot. The riscv implementation differs from the arm64's in that the LSBs of the pfn of a svnapot pte are used to store the size of the mapping, allowing for future sizes to be added (for now only 64KB is supported). That's an issue for the core mm code which expects to find the *real* pfn a pte points to. Patch 1 fixes that by always returning svnapot ptes with the real pfn and restores the size of the mapping when it is written to a page table. The following patches are just merges of the 2 different implementations that currently exist in arm64 and riscv which are very similar. It paves the way to the reuse of the recent contpte THP work by Ryan [1] to avoid reimplementing the same in riscv. This patchset was tested by running the libhugetlbfs testsuite with 64KB and 2MB pages on both architectures (on a 4KB base page size arm64 kernel). [1] https://lore.kernel.org/linux-arm-kernel/20240215103205.2607016-1-ryan.roberts@arm.com/ Changes in v2: - Rebase on top of 6.9-rc3 Alexandre Ghiti (9): riscv: Restore the pfn in a NAPOT pte when manipulated by core mm code riscv: Safely remove huge_pte_offset() when manipulating NAPOT ptes mm: Use common huge_ptep_get() function for riscv/arm64 mm: Use common set_huge_pte_at() function for riscv/arm64 mm: Use common huge_pte_clear() function for riscv/arm64 mm: Use common huge_ptep_get_and_clear() function for riscv/arm64 mm: Use common huge_ptep_set_access_flags() function for riscv/arm64 mm: Use common huge_ptep_set_wrprotect() function for riscv/arm64 mm: Use common huge_ptep_clear_flush() function for riscv/arm64 arch/arm64/Kconfig | 1 + arch/arm64/include/asm/pgtable.h | 56 +++++- arch/arm64/mm/hugetlbpage.c | 291 +--------------------------- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/hugetlb.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 11 ++ arch/riscv/include/asm/pgtable.h | 153 +++++++++++++-- arch/riscv/mm/hugetlbpage.c | 227 ---------------------- arch/riscv/mm/pgtable.c | 6 +- mm/Kconfig | 3 + mm/Makefile | 1 + mm/contpte.c | 272 ++++++++++++++++++++++++++ 12 files changed, 480 insertions(+), 544 deletions(-) create mode 100644 mm/contpte.c