From patchwork Mon Jan 27 09:35:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13951116 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C081C0218C for ; Mon, 27 Jan 2025 09:35:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8298F280135; Mon, 27 Jan 2025 04:35:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D9E128012F; Mon, 27 Jan 2025 04:35:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A0B3280135; Mon, 27 Jan 2025 04:35:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4B96F28012F for ; Mon, 27 Jan 2025 04:35:40 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C11B316215B for ; Mon, 27 Jan 2025 09:35:39 +0000 (UTC) X-FDA: 83052724398.15.01E8BD4 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf07.hostedemail.com (Postfix) with ESMTP id CBC6140007 for ; Mon, 27 Jan 2025 09:35:37 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mAkgJZ1x; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737970538; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=99dsnhY1LzkcB+OE/DdpiYwFKW0qeZkpr6pPy+o2sR0=; b=UuqXHnmrD/VMSOfRrQs74RnDupCRuPQdNd//mPtk9KNsWphqX7mQXrjroLHIpC4LXQ30XZ yrrh1qxG1ercptTs0x1uXZgnq7/4t/R3e3mWEFCgue15kE3WygoiFzhefqs8+A+yZqbMv5 q+Tpgxrgngb2ZrpHyg7tbd0MSf9Hv/o= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=mAkgJZ1x; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737970538; a=rsa-sha256; cv=none; b=K9M0qLJoeus27NhVig/0py42XQ+BeldhEhA56BBU9V3mMlRbWwxqsRHXBsrsyIIx8UMbHd TrmlgrJmM72VhSrignYNlgAsLy9xYlD2/SghucNle5vhodEjPG/fBioEwZnfEPVv8hWDq2 z/PiScqiDxdabx39NjxRkimYDHcr7qk= Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-38633b5dbcfso4689758f8f.2 for ; Mon, 27 Jan 2025 01:35:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1737970536; x=1738575336; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=99dsnhY1LzkcB+OE/DdpiYwFKW0qeZkpr6pPy+o2sR0=; b=mAkgJZ1xNOAoXB0PHp79HZmoFE2JlBBg6Jl4W9GmRwhsNSpuxSDEnGCqIJTZMKQHf/ wkgA+d7qMFmqWQrkyZu0VVlvQhxOrfUXKIQXFrsH8HutE07JKGWRDsHrzZWOzcEU5/uT /1z4UhiUocnT2+xi1y1H+vgYq3Ow3Ls4yczR3MyrudFra+vv7ls9Vj0rHEfb1BfpQBnr V+4lRBij0ASVh00BsJBN77jkjJ82RAw3WLtn9gZsCb4gD1go4YjPbn3LrorDj2uZbvnN hsRQ58iCmiIlc7xlvpVUgKwz3GtXjMyvPUP8h9e68AKJooHDkxxPt9ZfknYitZSNGT3x INVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737970536; x=1738575336; 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=99dsnhY1LzkcB+OE/DdpiYwFKW0qeZkpr6pPy+o2sR0=; b=Ybky3iEPcfNk3OE25L1sOUEea2f+m4APaUB1NL6xxv6ky33Grj+nTpSoy5T5gbMyBE HZH0XYbt6ezjDPtv3rfOan/9opStXM4wZ54k3wLGUpF3qD7+yTcWvoLc/DEuAk/CQLZe 5ksOLjQQRZ8jb2ovowAephmZH4vN7Gxq9yQlbZbc1oVKXGUcg/EAve6CowedWSlx7DrU YGejqrKDsr9bXvMiE3tUXZsTLaLqoB7f1GLpkfqndh+6bVa5AqoyQGMjPzgb9ClbsilU OSWwQI4S++nGYcDoHR/MjVrn1aPyE3L5S04AETjOyO0MOFbrSFrhM0t24IhMvfCvhPUF wvbA== X-Forwarded-Encrypted: i=1; AJvYcCVPgRjPf+V5ZAHm0p5Hxf6b8oEqYwCYqa6GppJQbZ3iTeKk6XZ4ghsDGzOw+OSXFnaL02sH7iqMyw==@kvack.org X-Gm-Message-State: AOJu0YzUA2QMpCqhh5QedooetoVe1yRnXGB2TfcBVKe1uA5nPTWX8MsF UbjwdvLQJCfA77PYeOQVpuv4f5Hyi75S4N1/XsQmSF5giBLK8hu3TRMwm1NympI= X-Gm-Gg: ASbGncvuVpxoI5jEWBBECuUOGfMw25QJYO26Kplw4H4d+1WR3bp7RXZGg7m5rs5WcYr bDztpLKfJy/b2bjtvFGN2Scm3RKQ5wBcG/qieqT+3y5380TQsOLzgK/cBKQ14KUHXuMwYQaJQtq ozz3lpO3xk09HF+kF64m+Rqn7R3L/ihedWqN6UJz1eNQraEvjmbh64SwxX4F3oV/MqpAJhtMmiN 7dVxL3y5kj9YGPWNeyNcF3DHY3I5hJd0lylHqrR3vtLG0QB250qWAc6LdWKMsUsoApORlVqQw2g UMMxra8T26ULZQCGx06tYlJQVuso2Jo= X-Google-Smtp-Source: AGHT+IHetBDsQbvMNN5ryrSs+8A3PKMdEXMucor5Vs6JNUiGjFQ98aWxPnKL2bmORICT+TKVgyvyDg== X-Received: by 2002:a05:6000:1786:b0:385:d7f9:f16c with SMTP id ffacd0b85a97d-38bf57be11bmr40573775f8f.46.1737970536102; Mon, 27 Jan 2025 01:35:36 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com ([2001:861:3382:ef90:3e22:3e78:ce5a:32c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a188a77sm10736513f8f.51.2025.01.27.01.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 01:35:35 -0800 (PST) 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 v4 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Mon, 27 Jan 2025 10:35:21 +0100 Message-Id: <20250127093530.19548-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CBC6140007 X-Stat-Signature: 54c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YUzL1QK0GrB7dx2uGl7mK1PvKQaOZYtVc3y1FjRLIIWzKna7sja9kK7IWQCHauBeTcijoY7kcdVeLjJKufpTI1prtrH/5yhvfqGk1n0xHlUEZshptcMjPi6ciaDZz12IUtlj2GPsltYzHz8b0dlRxxWcbd4tizQq9hrzpV6KFB/QYUYqE8mhhGYZvjAou6J7x0J24TctRNQSOQ8rQNmgtLVMQ6gb4Kda7DynLr6pGJqPP4m5v0ryXYkDXCiazPCeap2HU7MwTmAsyOvbJNYOwBJgZWAQGgCRJt4Mj/BlSttBgSOV5SJBH52CuE1HHQz/lI2mcv7Q1YrRIS3aImN68D0kdiZnddEoqRVMx2XBThYFVgWBEn7zCDFFP7nhamSgZTHRKwifCZSQbeS0lJM8qqs4eegqSRCZVztgmXtoBclAaVVzpiHM3qTX9C6j5+wlN9C3ryQdC8Z1Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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/ v3: https://lore.kernel.org/all/20240802151430.99114-1-alexghiti@rivosinc.com/ v2: https://lore.kernel.org/linux-riscv/20240508113419.18620-1-alexghiti@rivosinc.com/ v1: https://lore.kernel.org/linux-riscv/20240301091455.246686-1-alexghiti@rivosinc.com/ Changes in v4: - Rebase on top of 6.13 Changes in v3: - Split set_ptes and ptep_get into internal and external API (Ryan) - Rename ARCH_HAS_CONTPTE into ARCH_WANT_GENERAL_HUGETLB_CONTPTE so that we split hugetlb functions from contpte functions (actually riscv contpte functions to support THP will come into another series) (Ryan) - Rebase on top of 6.11-rc1 Changes in v2: - Rebase on top of 6.9-rc3 Alexandre Ghiti (9): riscv: Safely remove huge_pte_offset() when manipulating NAPOT ptes riscv: Restore the pfn in a NAPOT pte when manipulated by core mm code 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/hugetlb.h | 22 +-- arch/arm64/include/asm/pgtable.h | 59 +++++- arch/arm64/mm/hugetlbpage.c | 291 +--------------------------- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/hugetlb.h | 35 +--- arch/riscv/include/asm/pgtable-64.h | 11 ++ arch/riscv/include/asm/pgtable.h | 156 +++++++++++++-- arch/riscv/mm/hugetlbpage.c | 227 ---------------------- arch/riscv/mm/pgtable.c | 6 +- include/linux/hugetlb_contpte.h | 38 ++++ mm/Kconfig | 3 + mm/Makefile | 1 + mm/hugetlb_contpte.c | 271 ++++++++++++++++++++++++++ 14 files changed, 527 insertions(+), 595 deletions(-) create mode 100644 include/linux/hugetlb_contpte.h create mode 100644 mm/hugetlb_contpte.c