Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp433999lqo; Wed, 8 May 2024 04:34:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7KxOal+L7TXvdvzaWd2axSFy9E8okW9rY7fzDY7wIIq3rr7M6QPrf9Y6JKmpy8fRk2p5YZyj0qzcghWFkAd6BLn2sRzBf0JN8Jqde3Q== X-Google-Smtp-Source: AGHT+IHBNTw3L3m2gPZGIx1fKMa/JA7hMGJDiH9lwmjgOUTzsFt2/WMmQCCg9Z8f88Mtdivg1/bj X-Received: by 2002:a17:903:245:b0:1ee:a09e:c7af with SMTP id d9443c01a7336-1eeb09a0015mr21555485ad.54.1715168089381; Wed, 08 May 2024 04:34:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715168089; cv=pass; d=google.com; s=arc-20160816; b=cFt+WJ5cp3NFu+HYnr3cH3T1Ynhe83IQsK+Ak9Q3x+zaE4GcL1I3AcUasq6BdF3PW/ PdzcLXIt7qGCmyF+L7P5Pv+gcPfZ5WuwP7BSU42tkfWbFBJgEripJm9hGpZM0NRbvfpx p5eY4VU51zlngNXLhmEfICZK/8E5Nw8FunpAVsHNinYe1loMaWcXTAyEEdBYNay0PBIp u/SDhJgDsr1q3Olyf6cvyOdrDgEmifB9fm0ggDa5tr/8AN7DG1wGBzusYA4N0CM1dxTf IevISaQSRDg/PYurybUL28h/J8TRhOG6frLvgpGOaBu/8nSV3MXA25rQlAUqJATzuv8E 7yIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; fh=yJkoeJ/TVSx5SRqV96OBEIhTnl5XciC8qeot6MEuiAI=; b=HsJ2rkx7U9c/uyP4JsyTgi1f7+rIQPOF/DwAF2mRmYdbXw74Dq5IfipvlcvC4KR3e+ +pl9SG2suln/peHQbPcvi7t7LbWwFYrlHT18posdHh1BMGXv//XX+eqy7mxx67eazpx6 fwKtxaKu+1hRGAP9plFkkpis7XQ+ce7pVGpLf7EeOJtdlc4jwZMMf9jeJ/suWxoamuZJ gnuOP3go6EGdryfOYIxQpgB2tikEr9sIKTL8JCUgo2logl1qf56vFCYMJfzhdOgovssZ 4CPPIvxjp1Z2DmdisHyYb35uxJozwR/BCyqE6bY95frOnZsv74CxWGpudR+slOAl5TNo kpZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=znBmokDd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-173145-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173145-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w17-20020a170902d11100b001e4b20bb0b0si9998051plw.326.2024.05.08.04.34.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173145-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=znBmokDd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-173145-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173145-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7CAF283375 for ; Wed, 8 May 2024 11:34:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15E93823B0; Wed, 8 May 2024 11:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="znBmokDd" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53DBD80C16 for ; Wed, 8 May 2024 11:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168068; cv=none; b=sp0qCjLwb5NYtDZjJoLBiVSKof1iyoZY+7yMep5z60CvSjMgy2W0oXr8vr/99rIFDa/GBHzxepV2MAG/n34FVQkfhVpxXn/yZoQwKgTvJfbSl+qpDnAhA/kDzcjTil7mX3n+jUtMueOpFqAs11PWAa6M4mrxl1nanxzYyJEJerU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168068; c=relaxed/simple; bh=9Tw14u/QjNGtWMQB3QHmKHHHhMzkhGdimGLqtqYRluM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ZwNv21EN6hHVKmRe0PtSGJrgE8YzKSjlOhlUhStJaZi6+R0G3r+SDXP1W3WEYUxwWwye7HGJ0zyDVcwLSyS5q5j7BcOYkmMKAhvrS5Ba6cguAD0FdfuNiciMlJ+k2YiePxmVTX/KmBNUjWB0f6wtoxXI7oSb73aMDFVV4kdvNWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=znBmokDd; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-51f57713684so5324653e87.1 for ; Wed, 08 May 2024 04:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715168064; x=1715772864; darn=vger.kernel.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=znBmokDd2QiiR2G9/fWbwr12/6wd5lpcw95EIiXTk7MvfAmooUgZ5smYB0nzOL62hw wGV8zx05KbFDKYfIraNvg80v3BvnhQpQtHTji/ty/wg8AhCfmXJtPEXCebyUUuvobSse zrxz4z+N10oCZ9Wd8BLCGY2HnJKHwC/5DCK9Dr3N6piFkTM/XHUCln3fmybm7JcgFUQi m4yJn5l747AWh84xMEnQxCyUKTSU9K3PgXJUyC9i1hhQpNxpebVBHfd74HHSVCrK3Q1X IJvWj+ahl70Pcr9J3tiNJrfEONEw64/EoPbtGQNKWljZSxU0qqs5bemUO3+5l6y9/E+V 90WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715168064; x=1715772864; 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=sBEkzZST5r/7DVa1k7yNs8/s/fFfFKCAjPN+xS87iI+2HP26uNMsXoF9DVGugtW+WX IPK+zphjvt4gdCBofsyfaT3vBd61Mr5PB+oVWPAh4+j+LKm/ca+nbIy5owjg9bjXLAXq MMXIQy6DEKq7Vkrap+gj6ObT996VmN3YrK6we1vc6UzH5q20mgIRh2r7aj9v2jWqcF5a UDfQWsSKhFYtTLYu1aIW1zIiZby2c7V5ELN8yfi0L/PlnQunEciqQe8C/hXa9TOE+j1U A8+4rjmJ/yx6emntd1Eqm4Zbuz/IaF2igBxFFqqJY4Zf/QZOKS1YQuQHCswXX/DrLnC7 y3Ow== X-Forwarded-Encrypted: i=1; AJvYcCUOIHsgxBtVzxepRClqxm8A2/tFtNz8nZi1DNZ4VQWvYRFEx82nxPprn1XQA0H5M/hUVNqXgpBB8jvJ+RXd/OkJtX3E83oGNJJpsshF X-Gm-Message-State: AOJu0YxD4elMJ3/4MzYd7qtC9d84Y/Nl3qoDkylAvzTHXtkUiJ/qQ+SD uQWoLucCLNxR/gvlzp7W4xp/pDTCZ7dMIMhsdCrViNF6Dr1Oza79EjXARa7cZSQ= X-Received: by 2002:a05:6512:3493:b0:51d:7d4a:5e6e with SMTP id 2adb3069b0e04-5217c276f94mr1361793e87.3.1715168064446; Wed, 08 May 2024 04:34:24 -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 z8-20020a05600c0a0800b00418db9e4228sm2001659wmp.29.2024.05.08.04.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:34:24 -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 RESEND v2 0/9] Merge arm64/riscv hugetlbfs contpte support Date: Wed, 8 May 2024 13:34:10 +0200 Message-Id: <20240508113419.18620-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 -- 2.39.2