From patchwork Fri Mar 1 09:14:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13578189 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 E1E72C5478C for ; Fri, 1 Mar 2024 09:15:29 +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=zcggUC23k/HJ/g/BKz1FqjOneagGFvG1u0su6kfSGcE=; b=nh8lFGNOho7kfG Du+SyhuHfQp/7tn1hv+2W2lL4afGzWHxyUFdesTQZrl5WHqzYpxHyL4l5bMlYHS0xmiU84fREx0xS FeQ1X4Z7nCju8RgYhTn/8z1riG/M7rmcEYx3R3tzxHVZ426/k3Z+KkN4fkKEL0SYKIhHwtYVMqKrI CDp/+pcd7Umq4IGxv9j8XeVll8+vw4DY7mXYd2k6JoHuu/zccfboyvOykjuPlqTpmZmZ8GUmV9mcd NBU+Cc2cxGPdU+5f9ScNts5KZbXxXO786w/GlgFec6r5+HoCq18TKgH7aWLsM/OcLD8UX7fjrVHbt HyzOeoTUfYP65wWLhvfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfyz7-0000000H57p-3KG4; Fri, 01 Mar 2024 09:15:17 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfyz4-0000000H54V-3KHq for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2024 09:15:16 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33d2b354c72so1370895f8f.1 for ; Fri, 01 Mar 2024 01:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1709284512; x=1709889312; 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=yprVHevcC7ppzCMdOTaT3VuCvD5AQnHTkhMmW9/Yos8=; b=XAaao3i5ojjx6RUuUu5N6zX5ZYoZibYubkbXuF2XLlUrMvI3ODJc7E65ZABV3khYnA ZBFYyxPedOnQcazLBNmj62TFEN6eunI3/J5CgplEW88MQzmfVjow6TV86H+OZd1h6ByT E8fKyBmnh19fd4wAcQbo3u20cHPA4VTZYisP+6AlYyPDeQBOcaKXsDZnQVp/49qIL+6Q hh6isWzlRf+/uXwAhdcdjY7KXc1jidh+Bnya5fVYjyUHGFmMZhI9yIayDa/4LG0mx9Pp RyU+0KcK/8UKdY5nwPBA97qXv3ItJOcLhKOi3eU+ENqdvI81y3YXkS0wBWuWGZKoIshT /5Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709284512; x=1709889312; 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=yprVHevcC7ppzCMdOTaT3VuCvD5AQnHTkhMmW9/Yos8=; b=IfAUQHmWLuexJ0pEEXgpPQhGs3p7iQtiInW0/02xwcfGXnUoT8CdqIhvzqVSXH+KpC xQ8maa8V5nEEZnROCxqzizHbL4pH1nMHvBoAtW3Hd+OhG5p/E51Dw4RcNwDRsvrmaIcq +DLtGQnRJBJlqZ+I3IlAjNAgjNHq7OjS8lQwoM8bBqUd2XqJwFrbRPmqniXDY89ihZrz O4+cj/7C8YndaZ7uHHVqT2JgBg2nybxNL9/Cp8HpYcG+1uh5Q2xnaMXMlz5608JpWelo U4wyyykaou0ZXsmIht8odAP8rWDoqglU6hCJ6vXNiGtt8QC63Mi6B+dPfAvdolg5xgX6 Z6Dw== X-Forwarded-Encrypted: i=1; AJvYcCVQBrvvH0Vco5dJM+uhvpsijz5kylbQvX4AL9PDexII3yLiYfvQjnLjIQwWHx6WWb25NGvjyE7PRvPbmJN/ltneSfOTjB2iKD3zivv1mHvvKP1fFn4= X-Gm-Message-State: AOJu0Yy1MVm0MjVp0BgYhN9hjMw2qyPztc8mCebdPm925eKfNUKiBoMS Nh0B+h0U5mW2bsmvH15VFVPUh83uTMGb5vh6/EdsmNZrPHKY7rpzMdCImxZNngpBDbeKUQJg03X F X-Google-Smtp-Source: AGHT+IHOEB7Wl0w/DP1jjp+wZ9IsZZPSGTyde6CCE7SA3irG+PXIOR/BUSU4UaYePPTrZ+YxqlSQWA== X-Received: by 2002:a5d:5284:0:b0:33e:d27:2e40 with SMTP id c4-20020a5d5284000000b0033e0d272e40mr820688wrv.11.1709284512017; Fri, 01 Mar 2024 01:15:12 -0800 (PST) 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 b3-20020a5d5503000000b0033dabeacab2sm4022712wrv.39.2024.03.01.01.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 01:15:11 -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 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Fri, 1 Mar 2024 10:14:46 +0100 Message-Id: <20240301091455.246686-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-20240301_011514_864413_D5D847F4 X-CRM114-Status: GOOD ( 15.09 ) 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/ 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 | 59 +++++- 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 | 120 +++++++++++- arch/riscv/mm/hugetlbpage.c | 227 ---------------------- mm/Kconfig | 3 + mm/Makefile | 1 + mm/contpte.c | 268 +++++++++++++++++++++++++ 11 files changed, 456 insertions(+), 528 deletions(-) create mode 100644 mm/contpte.c Acked-by: Palmer Dabbelt