From patchwork Wed May 8 19:19:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13659078 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 49876C04FFE for ; Wed, 8 May 2024 19:19:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E3246B0083; Wed, 8 May 2024 15:19:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9923F6B008C; Wed, 8 May 2024 15:19:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 881756B0085; Wed, 8 May 2024 15:19:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A5636B008C for ; Wed, 8 May 2024 15:19:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 15D14140CFD for ; Wed, 8 May 2024 19:19:37 +0000 (UTC) X-FDA: 82096192794.22.C40D5B9 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by imf08.hostedemail.com (Postfix) with ESMTP id 2E44A160012 for ; Wed, 8 May 2024 19:19:34 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tC9j33Tg; dmarc=none; spf=pass (imf08.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715195975; 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=K1uKlYjMTe4xfHBkLhM4fwrAS4H0Wd2FQ2UyNN+YPgM=; b=lOU/FWFWppiawg/1ktVTYSaRqPYAh7bGsVaJgYIKvDV+aB/5E9qoaGbWFFlOC5fOJb/7/r gfelfXf7tIVncZ9qWaIZqIZsCFDw7F4lHrrGB4b4OfY1ByzIs88ZcWFxGVCQSuE29vVuXJ mHYz2grIcnxxyIdIDEzKD+ZIRGjBp5U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715195975; a=rsa-sha256; cv=none; b=tB1NDXYs88P8X6chNfKqX1uzNFgM7q0bSJg0okU/c7f2xatitJuvfz19yp2erBm1csPepT wAd0NJ5Up3UXVbj/W+s09yr9/lLYYS8gm9+vRzSI97H2SIYbSRTr2W6RnAA6ZH980le/SB KeEl6frFjuqh8yh0+GOIXtOB0KtjR38= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=tC9j33Tg; dmarc=none; spf=pass (imf08.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2e3e18c24c1so1208371fa.1 for ; Wed, 08 May 2024 12:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715195973; x=1715800773; 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=K1uKlYjMTe4xfHBkLhM4fwrAS4H0Wd2FQ2UyNN+YPgM=; b=tC9j33TgLCyVBQQRlhgwmmJM2atm5y17iAVd5lXGldqw9Xwc3HXj3O7ss9XDXHMvto eycTSuqcZbVj9CZxl1Kvvq9D8MwtHwAMiHlhmSbhnzVmWeccBD2tR6KRfA8rMJDa5OhE a+/0vx8sgHnnnOdFRYNFcrG2q6JGvUn+5CEWs3lVCE2JxCPPHynYHPS/9BHiiRjgvApn 0KYEkqCnDSSWpqcfbSIgv4Oy9rz9ex3ptbJvN7Y0SuFFmoSODjwaedhKdEjNjmlXXjFx sMvqh4HLL/H6bMG/ZaN6RwkeRGU8qEWX1PAVwXuYLNhN+aBCXaPIoHvTo3oXII/RV+BQ uBJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715195973; x=1715800773; 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=K1uKlYjMTe4xfHBkLhM4fwrAS4H0Wd2FQ2UyNN+YPgM=; b=a7lYWTRYE6+bVHq++sTtg1YccwXUEkXy+2uPyn9XP6zf8FqL9bgI0LRWOIaS36l8Hj Vz9+NTYWJzQX0Zst75pjRDgf60gfThuC54veDnrheAi3D7K8QcCDupaHhToP3y/FoQbS WrONS+jkGfjxXdykDGdHElAYkucP6NSkikOfP5+RXbUBjhJZW/3873ATueq6PZNpgaUu mRr+WxAgwhqeIgiqUKBnKXfgCeMy6saoyIN4DViweTih4RAZ+By3b16M3dGcJOCAT+dv Tn+iRMf7/tpykP9KZUSoQUFFLj2eTDCWOQbrBVHuv6jbkJY7BnhAuB/NWrmuIcFPSZ0j GucA== X-Forwarded-Encrypted: i=1; AJvYcCUa/Oi4b03TGQYclU68I9bE2S3TboGGl2jQkxV5fyIe7v6Abn8ObBAiSc3exJSD42bIYIv7eUOP/nzdX5BXIBIs18I= X-Gm-Message-State: AOJu0Ywk/fAhjVslOjeYMOQGw5mQD8KO95v0ZTjibhLZtzVQpQFPeubZ Kcc5yqwBk6gxXParYcv52JMFjPcBUXjDQRD7jPauF28t74GORxaCFsPeRPF0fqQ= X-Google-Smtp-Source: AGHT+IHeP5I15KzeyyHS9QyEylQJKB8BxwDLerdVkeWn4X1OoVdiknVfTODJicHq4kG+uWiKxO6g7A== X-Received: by 2002:a2e:81a:0:b0:2e0:12f1:f827 with SMTP id 38308e7fff4ca-2e4479a2ca4mr23591601fa.43.1715195973157; Wed, 08 May 2024 12:19:33 -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 5b1f17b1804b1-41f88110f3esm32622515e9.29.2024.05.08.12.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 12:19:32 -0700 (PDT) From: Alexandre Ghiti To: Ryan Roberts , Catalin Marinas , Will Deacon , Alexander Potapenko , Marco Elver , Dmitry Vyukov , Paul Walmsley , Palmer Dabbelt , Albert Ou , Ard Biesheuvel , Anup Patel , Atish Patra , Andrey Ryabinin , Andrey Konovalov , Vincenzo Frascino , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH 00/12] Make riscv use THP contpte support for arm64 Date: Wed, 8 May 2024 21:19:19 +0200 Message-Id: <20240508191931.46060-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2E44A160012 X-Stat-Signature: ihtosom5kaqbjro6kurnzp5b8tk4amwc X-Rspam-User: X-HE-Tag: 1715195974-89944 X-HE-Meta: U2FsdGVkX19xth5+8g10FHiIZ7fj2k9y2R4j63uadlBnu2obZikOi9NabFqGtBDspAh8xHvAE/Lq5Qh2nfLFVRERargo1eRXNs0RbZR3btVmU0XwZqpB16wkBQox0zy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Odz6VPgYadE6ZTJ0IPm5olUE8ZNS4+uFP+PdgzLncZxHhM5dtehsBvbtKaE7fuzLi43BSBxkCqNbcPoH1E7TSmgtCcmw+OaqAD6bagjM8dIPj0Unxg/Yl/70oDO4wGOIGCHe6TlxgU9ulPt+CLhk8QziHzbKTQU/SwvqhxC2c59OZUzg7vuN5j95UPpfaSg7V0C2aEqys3IQnqiM0xE5iXlXiC6pqNaMaQgVX6uaXCQ7M= 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 allows riscv to support napot (riscv equivalent to contpte) THPs by moving arm64 contpte support into mm, the previous series [1] only merging riscv and arm64 implementations of hugetlbfs contpte. riscv contpte specification allows for different contpte sizes, although only 64KB is supported for now. So in this patchset is implemented the support of multiple contpte sizes, which introduces a few arch specific helpers to determine what sizes are supported. Even though only one size is supported on riscv, the implementation of the multi size support is to show what it will look like when we support other sizes, and make sure it does not regress arm64. I tested arm64 using the cow kselftest and a kernel build with 4KB base page size and 64KB contpte. riscv was tested with the same tests on *all* contpte sizes that fit in the last page table level (support for PMD sizes is not present here). Both arch were only tested on qemu. Alexandre Ghiti (12): mm, arm64: Rename ARM64_CONTPTE to THP_CONTPTE mm, riscv, arm64: Use common ptep_get() function mm, riscv, arm64: Use common set_ptes() function mm, riscv, arm64: Use common ptep_get_lockless() function mm, riscv, arm64: Use common set_pte() function mm, riscv, arm64: Use common pte_clear() function mm, riscv, arm64: Use common ptep_get_and_clear() function mm, riscv, arm64: Use common ptep_test_and_clear_young() function mm, riscv, arm64: Use common ptep_clear_flush_young() function mm, riscv, arm64: Use common ptep_set_access_flags() function mm, riscv, arm64: Use common ptep_set_wrprotect()/wrprotect_ptes() functions mm, riscv, arm64: Use common get_and_clear_full_ptes()/clear_full_ptes() functions arch/arm64/Kconfig | 9 - arch/arm64/include/asm/pgtable.h | 318 +++++--------- arch/arm64/mm/Makefile | 1 - arch/arm64/mm/contpte.c | 408 ------------------ arch/arm64/mm/hugetlbpage.c | 6 +- arch/arm64/mm/mmu.c | 2 +- arch/riscv/include/asm/kfence.h | 4 +- arch/riscv/include/asm/pgtable.h | 206 +++++++++- arch/riscv/kernel/efi.c | 4 +- arch/riscv/kernel/hibernate.c | 2 +- arch/riscv/kvm/mmu.c | 26 +- arch/riscv/mm/fault.c | 2 +- arch/riscv/mm/init.c | 4 +- arch/riscv/mm/kasan_init.c | 16 +- arch/riscv/mm/pageattr.c | 8 +- arch/riscv/mm/pgtable.c | 6 +- include/linux/contpte.h | 37 ++ mm/Kconfig | 9 + mm/contpte.c | 685 ++++++++++++++++++++++++++++++- 19 files changed, 1056 insertions(+), 697 deletions(-) delete mode 100644 arch/arm64/mm/contpte.c create mode 100644 include/linux/contpte.h