From patchwork Fri Aug 2 15:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13751613 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 2A85CC3DA4A for ; Fri, 2 Aug 2024 15:14:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 862616B007B; Fri, 2 Aug 2024 11:14:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EAE66B0083; Fri, 2 Aug 2024 11:14:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 664516B0089; Fri, 2 Aug 2024 11:14:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 464866B007B for ; Fri, 2 Aug 2024 11:14:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 02C7EA114A for ; Fri, 2 Aug 2024 15:14:36 +0000 (UTC) X-FDA: 82407652194.08.7046C93 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf21.hostedemail.com (Postfix) with ESMTP id 115711C001D for ; Fri, 2 Aug 2024 15:14:34 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uxpm7oq8; spf=pass (imf21.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.52 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=1722611617; 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=hBY2jE6SQVLEJ2rTtvFkGo52n+rOy9A54yoDBcuOdIo=; b=oh9iigvgBaPiotdGtQTV2K8AIARADOkcMM6OxiFidNv1PJY41n7kAFLbJh6CU1bR56MbmG r1eyXPhxqRHSo7aSorXu/WmPh/pZlpLO5/a0HPbtdPYiTaBVOLzdTzasalyy67iwvJDDPv C3U7SNsMQ130SIup1o9u8d8Xoq8TvpY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722611617; a=rsa-sha256; cv=none; b=3uxaR/UHekdqmxxvUPDDYmtGXNZnEmq91wIrEoAKVhidMteSUcdL2nsMO+pkNOD2CDKctF DhGRjfc5GDhCcUp8F1d5SeLZWv2NMWNmZ27O3ucWyW/UnfrdX1a1FXyDJNnRQ81hIbk14Z 2GpM+tBW+QwvQeVz/hMI+ITUKsA/xVw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uxpm7oq8; spf=pass (imf21.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-428243f928fso46797865e9.0 for ; Fri, 02 Aug 2024 08:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722611673; x=1723216473; 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=hBY2jE6SQVLEJ2rTtvFkGo52n+rOy9A54yoDBcuOdIo=; b=uxpm7oq8K8M4tZceawk2LnZz/2mbOFIMKhAjp2COsmzaIY8R+nJP9Jc6TLeRiedxRa vEIKXZIda6/nzKCjL5z/cEJUEALOmrKZ3jV4tB8g2G4KWSZOmli+HncKZkrHVNgyy2lq kIWFG+556XhqCXCJxdhrVMcxM0PaSVmHPh1iwy+Hudm7fWgE0RlLCGeSUYDYdU8/6g9I lPrk9ku0MS+E0KrrD7Nd2/zeC2sheeGqt/fOgokExWj1up2T96pyE4d4hAkqZCuSLs4o +a4Mr8qaIl1lgd6c6Ixp765GrwkihK6KM8Ph2ozMrqMstq5LCAqJXF4DXMNEmT/dfs8A nacA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722611673; x=1723216473; 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=hBY2jE6SQVLEJ2rTtvFkGo52n+rOy9A54yoDBcuOdIo=; b=VtVuNsY0blz7LHDdOa/s5hDC6JR8JpdTYYuz/SkNy0gMib7wQhLHsmrdpkjXM6fU5C FiVc7fhNAcPTrvA7qVQk7N3jkCO823yXcyx5Frk6okiHa5Sz5kSB4V3E1e95nzogS6tE iuoNz9mP3BHzxLQILeJvbuNdYlNc6dCQ0+A3RyLU/mSce6CzP6KLhofr7CvGYZ1NC2SW 7WrSqzdcr2RnxJcm914zI/R+3TEUQWtuFt0LQ3yCTtH0umd2k/V1/jAcqa6s7dLCRoOy RewWeV1HU19LcCghCgGmBd9jSGqupQitce1mzl1/irTht+Q1zhgBnnXnEbwgVwcrTmYZ ljOQ== X-Forwarded-Encrypted: i=1; AJvYcCWXByWgEhvgLg5cCWs4YR04UUmeGjXyoLBQeq2f8JvsPWcQPz3w/+fdmaOUleqgjUp3vDtZSufwugMVoWLLAiUmvp0= X-Gm-Message-State: AOJu0YxoE3Lob+YyT+ppMw0gWeuCAZWvJiVtPCF6byw2U7XEU4uhvFwK +vMJKL0egVlARLAK09lv7EcuEBBZM8tPe2Al5hsbUlX1tFEd99YP1GC54jNyoPY= X-Google-Smtp-Source: AGHT+IH4oAftIk88ByazbNx7M8aEqytLa2lIWzUyzNWyKW+yeSfszojodoNPHEIHeKtlRo8S+0ksYw== X-Received: by 2002:a05:600c:3c84:b0:426:6ee7:d594 with SMTP id 5b1f17b1804b1-428e6af2443mr32146155e9.7.1722611673233; Fri, 02 Aug 2024 08:14:33 -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 5b1f17b1804b1-4282b8ad7f4sm98898355e9.11.2024.08.02.08.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 08:14:32 -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 v3 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Fri, 2 Aug 2024 17:14:21 +0200 Message-Id: <20240802151430.99114-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 115711C001D X-Stat-Signature: xnsfuc5bqdjeq69wdsn66kkn4zfw5jm5 X-HE-Tag: 1722611674-745440 X-HE-Meta: U2FsdGVkX18YWhOvetgc/A3Ez/Ei5TMI3ebQwaueGUo+kmwNl63IVwt/L+SWKyWVeDorkAL9DCsQHqrY7zMePCipvmHy5ZkW6U88zV/chK3TDGxDka3/6spQ/5IaVbMu/QKtiQlIsbhq8mtcH7rDq3RVVrgD2qQoYoWSvlwSCUvJSWOoGDWfW+6n1JKDsGegRMIcaiQGSOJwEuQ9w2b/FdudrIWyYRTR0x/62vRmvtkPob89tkXnC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5x7DVruso3Q+ghIudoMua/Ftoa5+iS+zvXxl1gJW1YYHr9Yp+nyUpU14KWaOIzS8repPRrfyCGSlw7gBPHtLYjiLy5NaGnXHOyE9dcNWGcdXEzWWHCguCdmEihp2fXZgISzCw== 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/ 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 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