From patchwork Wed May 8 11:34:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13658595 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 53DF3C04FFE for ; Wed, 8 May 2024 11:34:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD3DE6B014A; Wed, 8 May 2024 07:34:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D85096B014B; Wed, 8 May 2024 07:34:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4B676B014C; Wed, 8 May 2024 07:34:28 -0400 (EDT) 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 A8E0C6B014A for ; Wed, 8 May 2024 07:34:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3BB0D121476 for ; Wed, 8 May 2024 11:34:28 +0000 (UTC) X-FDA: 82095020616.17.11E385A Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) by imf02.hostedemail.com (Postfix) with ESMTP id 58A7080007 for ; Wed, 8 May 2024 11:34:25 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fbc+SxXj; spf=pass (imf02.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.167.44 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=1715168066; 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=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=DS5uno+YOOmvF4mAdtLbD9g3xauHLeaYIfIfjiTI4Ufbgi5itBCacFzL+5GZWAMRXKJc82 0qEqMGJTPw+nTZ4MEYWFeNVnpZm/aD1LD56O9a26lE7J3RJhucrKW8FyIxgcgFhxxnufjj YCHcnGfVsFrNnlUUwEtPLMdF/QKfFhs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fbc+SxXj; spf=pass (imf02.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.167.44 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715168066; a=rsa-sha256; cv=none; b=t5CxlcuUIHzDXZ2pEuQ6/Zi+hxr5Xxb5T782hHhmQrdHZ2qqEALX1QJ8GotKe8GW5mufkL Mme6mbjXuP1jj38+YYvFeyWKEL6zDAjozaL1mpv4asmy0TzFxIcornpl3eLi2MDepFkX64 Da5wfQQPHP8nnT+VpAs+UKgU6MTJJ0Q= Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-51f57713684so5324652e87.1 for ; Wed, 08 May 2024 04:34:25 -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=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=7s2Jc0w0RwoJia0FRkNkBXydPtaseE14QqCOpfNooII=; b=fbc+SxXj0VL8/MrFqbyDTfc8QjYjNOq6dCwSmxv58M8TEkGji3zXv2wr5yhs7nWUBo ujFJ6r4cjkxfJUVRg65aYjOiGfQ/QYU6MYI9wp5K5SjpI8eWIxsBoZwOBHC0BdeYmi1q 1Tjdu3b3ApEOGWNclr6GnBmESIf+1ANYPa+CrPp0mtKwADmrnczyiPSFJa4R2YtNzQxN hEh6YXgj1Ut5mWRQmwU8rM4LOniXGuQgOvhd1XQaL26G/fNJGBnjatppaA9KNHQMi5eo Lv/3YEzIt2Gt88pTU/5xfryV3chtdS1/Z3GJHBSjZvJEbmhUYBImfrlHqfZDKpX/+lqO acJA== 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=U75w/kUe9MOJ8h4+mbm+mBX6PLFvAR+QfpT8Am+yrxI68sGAKIwnX6twMmBw/FDBTr d4t4Q/wOQJ1bmTqU8o9A3fI11XQV9M6yrVoB5WZA4lkP6deyBPSHE++YD37L5Uzk1E0n l0gXeAY8C/IASgwU3tVBigZw8nM5by3QJCoVXqdg1Tclx86hnVU1kMdorrOZf9XuRRR0 r+WLhnW7amzwgXy5bhk48110wW+YMqaA9l2oUqIFS4CIopf9JF8rR37MAp2IIJz/0sbc 7xKoAxyzRqS/7mLlDpqVTGfxsTHX7lKr0OTluCMZGfVspeR1B9yLbAuJCxwZq1DZbCf7 P1Lw== X-Forwarded-Encrypted: i=1; AJvYcCX2oF7ai80plvAdwErtTgHlroQxRH8T/4wiu35kcIFaP7QZuijfGQvLPN73N+Us+ne5D27pgs4Xdt/A+Pu0UD7TMUc= X-Gm-Message-State: AOJu0Yyuvn+zDFbdE+kS+H4p+olR+E9Oc1HfDUhtDN2DYdoExbo0V7Jv zFLicJZf+6AxdVO6XJPXN5MW8shUNZCBDpxCsEQ7hTB3+BG7HSPojr7Tm9Hz6Z8= X-Google-Smtp-Source: AGHT+IHQ0+1QRr9yi6sWcDZ0EGp5PxgqjX1SIZMCwr+oGXVeU6XovCaKI7Yf+LAxYXYIcWcDnNZqDg== 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 58A7080007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: dk15dchsctxds1z3wunciwda9orjf6it X-HE-Tag: 1715168065-315297 X-HE-Meta: U2FsdGVkX18eNo1BXEBlOc0qIiEhmhPQF/Gdkmbf/ytQv7IdBaxQNf79M4HDSeSSjJqrwt+KchZtU3R9kOg6WDtgwNVTifKzua7EiWpWHLUPrCIW1swcve03FLxPCiyS8Az2GMmV0CvAwCovWJtwoJ6ile1jAND0kBNDDXYmjZ0tK9Lgkb34NcRharCN5wkogEjzhEtUz2bJv8884ta5vftPw4uLNMxzeCL8uPq1nsDnktANEZUvko5fcdsNARjv/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XaNf50mfy6SbEpL5Hd1qvwRjwS+HzCBuqtc+FDcbfENGHplPiAd7LifJhN9kOZ5w2yGOYjBSfRt9aXoHy9Tlu4KLxgCz88+g3DxSLH8l33x5J3T8/YfNqi/37B2sYXMpsbkD3UqfFoKHIGdeXFnilTZxr1pTtZqeqx6zahRpid1uIog 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/ 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