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: 13751615 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 61BE4C3DA4A for ; Fri, 2 Aug 2024 15:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=hBY2jE6SQVLEJ2rTtvFkGo52n+rOy9A54yoDBcuOdIo=; b=OIbwNMNvFafKNg5G86uFkULDbR ZjObF15Pk5MXC1s98m9HJqtvdCo5jXQs5i4WtETb1fwVPXGbH4I0xiEjorpC2hBTjCaAiIzGiuuFM SV/vaKWbuQNcwc9vwnkpOopCl7C2erJyCNCZ9agVPfxZWL3Ne9Qy1naZV/85HPjh3fVZlLc1ih6T6 j1d+BRpQlStEKrZJSQArJdb0CAyIrXOWWbsAGzof5WcJo1ifC+tRQ8CaI+mvI7PLWNqxL2PiYLQCX 9ir4eTggG19Y+psGGdbNX9+l69z5iAldcO3AsQhZd9nKKM8bJ4w1+r1FuG1w50jLvMoTJcaSGhm/h dngNJiuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZtzn-00000009Can-0xnk; Fri, 02 Aug 2024 15:15:07 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZtzH-00000009CRq-2rCH for linux-arm-kernel@lists.infradead.org; Fri, 02 Aug 2024 15:14:37 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-42803bbf842so73464425e9.1 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=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=hBY2jE6SQVLEJ2rTtvFkGo52n+rOy9A54yoDBcuOdIo=; b=FFxyleHzfUnhX9Kph/72mhsLWlhweAZSCmlInNvitXzzQ3qsJTNrXt3UO53xgFqj/b qkDcOgvE1NsbZ8+UtW2G/lrHCtSgMStHt7MuLslwc9RE6dr3G0UVub8adHQvLqPD8p4b T6CIzc8Y/STy6p7l+Ropz19gHPDfRLbgF1ApSca9YQIufG6mYJ93tG/xtNM/KQfSW4a0 2ZpXIH1sc6FJOISFeXbcAOu3/zlbXfpO/rcUt1tT8OTd5lhyMyVJNrVzHYTRkBT8OYsh ZQ/XvxRMNN2/lLRX2Cxq1dUUaynBGgGEzLTm04vcPAML91Er84GGGZZPfyNkESoyRrW7 JvcA== 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=K4YjX1f49AgbA7ss5v0fCgKhtQymuOt0uqnZTAJXBjb322aJDQZ+p5JvYZvjJXitat AxrUpEXW97GJsrZWuAqPTyCrh3y8UFzCyJQswRCcbyS5wgrbzy443/fI6DHRnpWfs2Sc efkiSgCAHM9VibEoavBRBA8S2wjJGxGsj9+e1/Y8FEi8DwLIN7fVW11jjNtw6/X/nqWc tg69tP8AKpb9V7l528QfuSyOvwpHNhbubnhiZVmuk9IKDh7mArJxwngDHwWZVBfSreGT 3WOYx/rnpOddRpRP6gKFko+Q1yBmhQ4Ir5JrneZBoGzK0amUBVl+qyQFUk/IZN18eQvD eEOQ== X-Forwarded-Encrypted: i=1; AJvYcCXC4G75fKxiAiiYY0lPBH2m9M+bZi52JDGdy42lPkv67mcKyF5mmhufnQI2OnZCalP6SrKZblULKbWexzF+eOnedh25M6z1afRXlZS6jgiZIHhoY78= X-Gm-Message-State: AOJu0YwKh1BeeYQvhCaM3/nhpgYtfgfSLBjE4gO37fehb101FDGRekYi 6rtIoYRZd5ygtGNo4lhhexVfsFr1/GHkzUDvZoONaGQAWoLuYD2sT6JMqjlvl4U= 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240802_081435_750415_1A15A716 X-CRM114-Status: GOOD ( 16.73 ) 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/ 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