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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D70CCC36000 for ; Fri, 21 Mar 2025 13:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24B9F280003; Fri, 21 Mar 2025 09:06:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D704280001; Fri, 21 Mar 2025 09:06:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07693280003; Fri, 21 Mar 2025 09:06:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE7E0280001 for ; Fri, 21 Mar 2025 09:06:43 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 35EAC810B4 for ; Fri, 21 Mar 2025 13:06:44 +0000 (UTC) X-FDA: 83245582728.04.105B991 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf03.hostedemail.com (Postfix) with ESMTP id D230D20019 for ; Fri, 21 Mar 2025 13:06:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Z50Tsdhq; dmarc=none; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742562401; 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=NoPNTj3V5YtvLo2U0JoAwgjQlQPlLdtIAiFjHR9ruWQ=; b=8EVG3xvdBOlQQfvH2U6/Ea+b0DWvufVLwuTvrDpa5T1qBRznzeAZoicGyudfyif3n0nwiT l7vhYv8a3/POsx8lYc1kpXpH67g3ZkGsVDVzvLOEIGlicqLv3xZH3FhyNwiZRwAsm212EY dHSGoJ65dgvNzsnzMSgzF5EsbHqG/6U= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Z50Tsdhq; dmarc=none; spf=pass (imf03.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742562401; a=rsa-sha256; cv=none; b=5YAUN+cvQaeASBuT5MUQmahixlZV+HqM7V3S0FrSxYf2N0Id8W1+FCGkiTW6U6CXUpYTFL 2lojwMRCnxazxipo8iesCv4NSQ8XBolWqUzjRQhxZaX5gpMyaCezUkdst8mJv3edrn6TiB RGkO9eEY6Ra9qj7MDfjKPBFBmaQgtGs= Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3913d129c1aso1412099f8f.0 for ; Fri, 21 Mar 2025 06:06:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1742562399; x=1743167199; 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=NoPNTj3V5YtvLo2U0JoAwgjQlQPlLdtIAiFjHR9ruWQ=; b=Z50TsdhqLmxVFOq/iwXFi1ieNVAzff+07aMZ65XtaJrTFutanqYdalnBX5eHR8TOf9 hWmAaEsm+QcVWyDCN/BlOqp/V58VyPjRpgiWzGNUkkilkQedlPvlVLsFeKAetXNlM8Hb bkO8KeG0rFOOsm1GVQUsxSbgBPVOGz2KlCfWR/4OUKMdPiwauYGdxTPZ05e9wgd4cj0b 2ib3l61UuqXtaFMQ0aBZxz0hn9Ls4aCAP1en3eOhseokP6nXiRDctxXdluF2ML8xJw+4 8JWjvCsWuMvsZ888Gw68f5JKM3RpZemkq0Te3mABL5YMpikd/lxL+z06KklLwzg0bucF c7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742562399; x=1743167199; 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=NoPNTj3V5YtvLo2U0JoAwgjQlQPlLdtIAiFjHR9ruWQ=; b=movzdzpkj2Pt0+jT5S6J/oTqsHKnjwQpHfhnOVnlpCutpyQPz816akjdVZpo15z6ue iiD6EiXaoQT3HyRHw74lMLm10X74EC6A/LrJpaAJiuliJkzG4MVdXBnD6XeJIw1/a3HO Rr90GK7PCHsiHs+dGJCxHnQFafdaNW+TYbSLx2A1kmqhV4hU5b82O6V9fcRvNmNBqMo8 aoGyyyxL36RfGtJ4K33HkciwsWHmnP1dEghL9ebGX/tM/Rx21ZDO3be32ymIPWReBTz3 JZ179yki/tf91oTeQX/lGg+bNLv9s0dmI3/6L6FtWOrgvK9iUl2G0F0af64z2ECZI3Yt TINg== X-Forwarded-Encrypted: i=1; AJvYcCU+2q8l+uylVL5me5GAFQmpRG4wvN2+GGQJ1H9weWoIOTRRVJMdcqmUjj0woZNlbY/RiK0bx3OWdQ==@kvack.org X-Gm-Message-State: AOJu0Yz6W3J6uMrHq6CScTg0Ty8pvRTZVAcI2pyBzXaRixYWFHQouq91 O0ENnuAzyMDywVJ0LM3oWHT+31cQqvubKTyFwmViuSMX07qvoIWbiEgAb9NHpLw= X-Gm-Gg: ASbGncvyWYVMSxRvQAi9CvXc1Vg3JVd//f63K9ptcbbd0qj/cSZJM9Aig1aGo9TSeN0 W4FBpHqLm0vMlVsC92Lj0WzPKS5C1Ewu3nlkr/GZ6KkKvD0mGqLk+CplP52dRpdppvjjQ0xVZa5 EytKgAneT6lfB4+3pwBdXQYhqsoFznNSK+a8uHz9U4vDft2/EDhIG3Xv7cg+tISLUsmu2bVpR82 Q+cNmIKZim8POF8ZdP9RfQ2su/bp/0ltd9HLncxhOtooeUmQeV1OvXZIk4iou65rmzRipKWwbSd 38k6zBj72tM61V+NVtog7Ouk3GWQR7oXH8p1Ikm2Ry2WSIsKnRH6qvbkogmG7AitVT9UHw== X-Google-Smtp-Source: AGHT+IEOpmQu3vdRTdoPK4Nh9YP5qAW7X5GoPVuQLhck+hEVtrUjAV5TX9kBkzKS3ZyCGSIbxUt4SQ== X-Received: by 2002:a5d:6c6a:0:b0:390:f5c8:1079 with SMTP id ffacd0b85a97d-3997959cde3mr6694234f8f.24.1742562398418; Fri, 21 Mar 2025 06:06:38 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com ([2001:861:3382:ef90:3d12:52fe:c1cc:c94]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3997f9b5b8dsm2363992f8f.59.2025.03.21.06.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 06:06:37 -0700 (PDT) From: Alexandre Ghiti To: Catalin Marinas , Will Deacon , Ryan Roberts , Mark Rutland , Matthew Wilcox , Paul Walmsley , Palmer Dabbelt , Alexandre Ghiti , 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 v5 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Fri, 21 Mar 2025 14:06:26 +0100 Message-Id: <20250321130635.227011-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam01 X-Stat-Signature: bgkqbefozmoz1hx3abuhraty6u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egmbNOR/BWpAaKaNJM3ER+2b9dNSayvgH0JvutbaqJaXTIkngM 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/ v4: https://lore.kernel.org/linux-riscv/20250127093530.19548-1-alexghiti@rivosinc.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 v5: - Fix "int i" unused variable in patch 2 (as reported by PW) - Fix !svnapot build - Fix arch_make_huge_pte() which returned a real napot pte - Make __ptep_get(), ptep_get_and_clear() and __set_ptes() napot aware to avoid leaking real napot pfns to core mm - Fix arch_contpte_get_num_contig() that used to always try to get the mapping size from the ptep, which does not work if the ptep comes the core mm - Rebase on top of 6.14-rc7 + fix for huge_ptep_get_and_clear()/huge_pte_clear() https://lore.kernel.org/linux-riscv/20250317072551.572169-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 | 68 ++++++- arch/arm64/mm/hugetlbpage.c | 294 +--------------------------- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/hugetlb.h | 36 +--- arch/riscv/include/asm/pgtable-64.h | 11 ++ arch/riscv/include/asm/pgtable.h | 222 ++++++++++++++++++--- arch/riscv/mm/hugetlbpage.c | 243 +---------------------- arch/riscv/mm/pgtable.c | 6 +- include/linux/hugetlb_contpte.h | 39 ++++ mm/Kconfig | 3 + mm/Makefile | 1 + mm/hugetlb_contpte.c | 258 ++++++++++++++++++++++++ 14 files changed, 583 insertions(+), 622 deletions(-) create mode 100644 include/linux/hugetlb_contpte.h create mode 100644 mm/hugetlb_contpte.c -- 2.39.2