From patchwork Wed May 8 11:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13658567 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 66B70C19F4F for ; Wed, 8 May 2024 11:18:59 +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=U1ha1UTRODC1vO8Em6ijDQhcJXrMOPX7+4zCSpgrc8k=; b=pfxuT5u7swqwe6 OjTU+KWlWKRLOnFaTu6jQ+YvK5e9Ihi76wAnGqbGD4Jfj3Y2Wy/R5xChP/jtGD4BR1WxsonZJs4xe mNcnlWiLv12Fn7+tBwunkspe5CKFewKA9gRbWibWatQIll3qudSg7JhzXHpLFZ1xXBALbNYsbZavt 844ReCFlGMQ0fOpd1RhsvwV00zz4fhc2PGalmIDf4InG+rXJg/FgpFUsNIsUrx2+q40FSS/1o9xFv vpheOYnH5UQ7v2CUGg4bdMA/o8NjdMwv068gXeuxAa7jjJtpDdCt1NrLKeo3AwEfzA3xEN4rrIkq8 nqCPsmaqeHdjoiQxT16g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4fJt-0000000FAYz-2hx5; Wed, 08 May 2024 11:18:45 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4fJq-0000000FAVx-3xKM for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 11:18:44 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2dcc8d10d39so48020451fa.3 for ; Wed, 08 May 2024 04:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715167117; x=1715771917; 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=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=jjrQbhmu1atsqbOEx6YG5Xyx8B2dFyWMghnyl400/e4zWSGfJDAOAOIIMutxLY46Jp QbtnXAFMNkoVx3LGUXlDp+1kjCprMFhMoSCoPEVVXD6FbMtQzGJxsAGBo4N2+NVqwwwS JOQ3xPEv5YLNgZlLgsBhmBPUeTRxjgGPQIX69KoPqxBt+RTumkRGUOb5ivhPGFf4GrSq hcEd2amm7maV6kmpNrZcAKl7KGmquHjZdGewVVPvRPPC4OZ06CZAK94ntvYyJCSHGmbq AZjojWsW9wE9sPpd7fBbD7nBKGfrInUtPJRVOYOQdEpQBvqRk6zt2nrHZBcIS1gqTnzK NTfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715167117; x=1715771917; 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=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=qU3f2KKVJWY03MAHvBOaYCReRqVbKZ/fUJ3GieP2a4612PXowzX2B6uQYb2zd/XK+w kLvZxxSyZEYDiKLiISS2Kl/ljYbcFAnzBZMHB7eBKWwvpwCblcrbCFy0QFZBMpd1uLK6 Dq3pVxT56ftQax7XByvszvAY0SSkKiLSGtWINN7ursnO/2Jpg3oaT6Tv0EDwI1Vt3oPQ mrZGXxleBQvBuQicZcbYSta8vNERbGzsae8jiz0zuKKLDQ1BWQJ1kmRWRO5LZV7ZAm+5 svJZurpSA/IOFH2e8ziRjJzKpArhrAzwhXyHixDY33hJVHGz6g1W3Ex+s/1CATcaS1t9 Zsog== X-Forwarded-Encrypted: i=1; AJvYcCXn9DK73SeNugipY0VFMIsX6IUz9OQoJ2A5i4MzOh8Mo8sLvzPzy5Htp/CsFu+5Z/hZuqremIDOUrkbSIR0HD5Nlp3e5hsrXfz9gzOw19ramh/mdpI= X-Gm-Message-State: AOJu0YzahkhCGNuIKPzORmJtGdYvb1v76kldCNHPBsaEO/vbCg9g6jpA fYcGiFdLm5Pv7tINDJdjBGDEt8gjGvesUC60lYHNPpa7CnmdIPwPONVaG0ujV5o= X-Google-Smtp-Source: AGHT+IE4qIFoqxTdkb49q/bY17UwLRoTIUg63kSAW3jbHy8RJOOcZA258spjIObf7gc4cKs2O6G04w== X-Received: by 2002:a2e:4602:0:b0:2e0:3132:94d4 with SMTP id 38308e7fff4ca-2e446f7c72amr11638751fa.16.1715167116751; Wed, 08 May 2024 04:18:36 -0700 (PDT) Received: from localhost.localdomain (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id f21-20020a2ea0d5000000b002e123933dcbsm2422820ljm.120.2024.05.08.04.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:18:36 -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 v2 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Wed, 8 May 2024 13:18:20 +0200 Message-Id: <20240508111829.16891-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-20240508_041843_060491_43AD02D6 X-CRM114-Status: GOOD ( 16.06 ) 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/ Changes in v2: - Rebase on top of 6.9-rc3 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 | 56 +++++- 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 | 153 +++++++++++++-- arch/riscv/mm/hugetlbpage.c | 227 ---------------------- arch/riscv/mm/pgtable.c | 6 +- mm/Kconfig | 3 + mm/Makefile | 1 + mm/contpte.c | 272 ++++++++++++++++++++++++++ 12 files changed, 480 insertions(+), 544 deletions(-) create mode 100644 mm/contpte.c