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: 13578178 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 901B8C5475B for ; Fri, 1 Mar 2024 09:15:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 188EE6B0092; Fri, 1 Mar 2024 04:15:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 139466B0093; Fri, 1 Mar 2024 04:15:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 001A86B0095; Fri, 1 Mar 2024 04:15:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E3AF96B0092 for ; Fri, 1 Mar 2024 04:15:15 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ACD6914097D for ; Fri, 1 Mar 2024 09:15:15 +0000 (UTC) X-FDA: 81847911390.27.804F656 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by imf09.hostedemail.com (Postfix) with ESMTP id D3FF4140017 for ; Fri, 1 Mar 2024 09:15:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YQCkq5ir; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.50 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=1709284514; 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=yprVHevcC7ppzCMdOTaT3VuCvD5AQnHTkhMmW9/Yos8=; b=YUbSJztlQprBbCM4naJUTa1vgfxxnw+GnWdUYlBoCmNJs644k+pnzi+/FDdcZidV5PWoyF xragdM6Qy3KhStSxJqjUsoTZ2I70JWTsue4ThMhHAIlkmZ+q+GVLwpNpw43xCYyUKrIDZA DQup7hujFd5xJFCIu5D952Rdap85SDg= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YQCkq5ir; spf=pass (imf09.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.50 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709284514; a=rsa-sha256; cv=none; b=O0mYzBv7Z/a2AIosk/aSBn11iJqgh2TlQf35zfKa20pyy3JYaiqJ/MWaxUvNYkJXKYfw/9 cbXj6emD/3j1QQt5yAMA9Rnb0QAwwCw578al89Srjo6rELRSIeBhrotPSUs9bIvZ2JzHUP cTnXnVWhHaPhZnZgTFKyYa3sOXz3em8= Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-412b83cfb44so12306135e9.3 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=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=yprVHevcC7ppzCMdOTaT3VuCvD5AQnHTkhMmW9/Yos8=; b=YQCkq5irFlLGcYLwmNNfsuYJeXLdn8CBHfuOCmySJX1Bf0uJ5pHjvYWOkCfdSNlBCd 570fQ66rYzudK9xe/A4SsvEzrAeQV20pn2DXRokXDgR+Wtab4j7q1K5cR0Wh4whEOtyB Mpq9mQxLmqXoxUYTjvdol6uWf/g6OpS22qvWmIkTzfJRbb+Qwid1NgsWuGO0Jo0tcnN8 bQIqRl0w3JMqhFzcW/cGVIhMjFM5C8rGVgEpKJwrw7CUWknK1AVn2J/WXuZdoQ+njHJS rYNA5T9Pt9CtDzIO1utaghJd83K7+ebNsKUSiwxiTZK5ykwvIR1HxRYb03HmfFoWQrSY jGYg== 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=lpK3oCL8EoS5X8Jlf9HouzVBXc4H/ub9SwaeB8NqIAK0X+wVdq/C9fUrJpEKm2lqdF 1AYzbe3oW8FMxezdzfnPW+yFwkRgKacbPoOZt6+nvGciu3+QiUH1JPFxz0659BkMbUQc OeUUlff7jqf5oF0PLKUlrmZkI5ngaZONijSWjh52e2lKK0Daytydk/JvikhjSoH9NdYH /MK4LMviltIjp2uf2tdrD8XDkY8F6IBxm95CeK59v+yHK0RqCvONHNdlMYTsaC7FQna7 AvSP6EjvnXbzALQ6nRcpKxEL+rWTtyILtJ8QVK9fjVz1XOWdOryCSs3TvRCWZNnyl6+v 4iaA== X-Forwarded-Encrypted: i=1; AJvYcCUrH+Bm/s0IHyRvyQLxiwP1mkQd4wIfr3DlJOPZK95Q3k+3oyTyQdX49nQpmpNuhXf34bXEw4IfCsYs733dK+mEXTs= X-Gm-Message-State: AOJu0Yx57XWaC77Y9so+dMkAIPEPQZeUHgCxJvXU/Absf0vDBKL93eo9 Vs0SqPwE9rwmWoWyBwZjaOdWTkApj6VspsQCtGRmZF55Mw+fCJnYBuaH6SvktEE= 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-Rspamd-Queue-Id: D3FF4140017 X-Rspam-User: X-Stat-Signature: yhsf9ixrnjgq5a3ke5336gspfuhe41gb X-Rspamd-Server: rspam01 X-HE-Tag: 1709284513-733893 X-HE-Meta: U2FsdGVkX1+ACo8kWaQKTUPiu4GbkNBD5ZdBEhP0M/sPT44jebCq/sZSg0OMvtpiH9y0EjnildB56MZDP7XB7MItLe3gjf1pBpMii2UxgDXm7DteyjtSHaVqZme2MGxQL6AY4ndqUdlUisoEqizRrfgS5WS7u3CQHoQFIvxCyi5EQ3LDifQ8xD2Wyib5abYZYqNcUfra//ShvBMLxACIqVzjiVcWubnGCjnEBTRE3bNvcm/LLkbIbUH5DWtyDryDJTvawcVt133l58r/kQdAzZhCIBg1y3++gqQsDqmn9BcED+cszpUi4xeJNndNHV+7VuCGdmZy/O9uUKcnY6fCRxT6tRNEzNFN8v8ijSLUHfJ9vPml5gMjPIi/pDdgjeGfDcbHtS3ffiJ0RCG/8vfqGnxPbyRvioIe9sfiyQBMllMMTYSOQUxENBeNNRTo6q2ScE3HY2VMCAJJ29SnGBhcfqqhyQ5/smqa6D98EReC9nX7zU18S9Wxf9hMorQJiHu7j2vQCU0DIrrL0z2MPFxiAfl4WSJzvQLPter7WHzK9A2ytho9AfCBbnlKYiww/gUvdG8kiZDQLXQmE+MTvlPZNZBF+UyTjOw5iJGH7rvOMiIDGuMJUVUeXAng4zIaDIKhm/KSEuc+XyF0o01b8Asixde885JpnSplADoM31uVc2cFMcnTCZVjwAmeejCEdiVK2HOSv57huPIgv+oq/1+s7w3GDPS7MqY7UZCWZzZZvTnR9jKHp48edLWcWCjc2FHOZj+SSY19BcEak8BSQt8Q3e/lbEdiXnDS+CSUrWRBtzZalE5NKuJUO79MDbOPMZ8+hfgpu9PBulElE2XISWHrJeZLepKwt+finB49sgPLIYKgfk7OhBQYI+CNqHC74UalQzI76VJebPQ49uSGyHUf5lMuXdsaAt1nzcW9U75aRlN1xxxyzgHT1JdRuZaQAZJskYzr7H/7MMAVcQIfVD3 6omRBZgb u0mdzsozFX8c+ERGm4ZdL5DIUucx8uxx/JMq+tMA3M+Pv78JaAB4oggPPcb8nMBLhYg5VhlVCeS135Fe4HGxgiMdFfWic9LioXwEsXHbiSXTpNj6i8G0EWSWAKo14CmFO814ntVOrjxGdW78Nm8kOimL2Bh6PWa9E1+2x 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/ 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