From patchwork Mon Jan 27 09:35:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13951128 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 8FEC7C0218C for ; Mon, 27 Jan 2025 09:40:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D70D28013B; Mon, 27 Jan 2025 04:40:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 286A628012F; Mon, 27 Jan 2025 04:40:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14EEB28013B; Mon, 27 Jan 2025 04:40:52 -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 ED50628012F for ; Mon, 27 Jan 2025 04:40:51 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7C129820D9 for ; Mon, 27 Jan 2025 09:40:51 +0000 (UTC) X-FDA: 83052737502.24.343CDAE Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by imf18.hostedemail.com (Postfix) with ESMTP id 79D0C1C0005 for ; Mon, 27 Jan 2025 09:40:49 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FdddVpqS; spf=pass (imf18.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.46 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=1737970849; 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:in-reply-to:references:references:dkim-signature; bh=WRFnXJIF4/2q4SeWU0XB4ffUEopf6Q+wLHMkPdh3cGw=; b=yKMl6Gbx03+Ia2lHp9hvAs3dtfKPG6w2ESZtJzEdsu1vt3DKGJjyet54kqHTGIr16tqA0s tGr9dI79Q9pGSiSvhed3Q1w3o2FcoHalyRVYnWF5jQP3D+N4mR9OZGeD83wUvurnFyoohO Rgzzg3U1Ryf9DITl1+EYl4jauLuW+nM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=FdddVpqS; spf=pass (imf18.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737970849; a=rsa-sha256; cv=none; b=RE+G3CcOv0LV9qrs5RT8YxS26LiilfntLgUsoT31VeDM3UZll5G9QfORclRYi3C6gSOnAf /TzWEwHWtxvVXpYX2YrZc9hrUq9oFTYGY5FFBzNoxvtOof9RUDNW/kYK3uz3OtPII+W+hr jxLhqScFkquUSs4aTZyuWbqaMMEOqng= Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-43634b570c1so29153615e9.0 for ; Mon, 27 Jan 2025 01:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1737970848; x=1738575648; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WRFnXJIF4/2q4SeWU0XB4ffUEopf6Q+wLHMkPdh3cGw=; b=FdddVpqSMjW0QAkn8DKmT3Uiw5+bC7JVULvPAU197Z+CuR3npGIg5i8T6RdS8kZ0pG ov7c/xa7zBaJKYskgNw4lhZlhxchzPSxOTDwZLJtnrbXhG6zFcQxb1E7/hE72VNJKasJ tTvT6uJD8bxrX6jhpdqxqn2q2c5zm0PeptwpzwqTXtNN/XMYyuBFPYmBh6q/L6JCUA8i 8ve0sJsN4prCHOcMBP2Yqt5w16ygJFkxDs3mepv1X75R5NSmjhnKAC0rIVWCUQ1jO8or dtBqUsaTnHkJ0eZP5D+qn70k3H+ISQO9Jz93CYA4cPRxYRh8qKPC3s6xuV9QUgDnG5ah QFQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737970848; x=1738575648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WRFnXJIF4/2q4SeWU0XB4ffUEopf6Q+wLHMkPdh3cGw=; b=AmxPxmmzj7ulqJnGBQk64NTe1mcOXche4JW0vzh7wlqd3CN3/4uivkOIVBBSdLeOfS IiiKAGN3Yns0Ec4qVf6XQEFJ3iB44XuWcgMvAam/s28f/DHWpOhF4pSNPmmuQ9YXiw/g 65uuqGRHyQyhLMY+eu5wacFlomINYz7aalI7ClvvFbCWypgAXwPIAms0D6tIkoVxPPAn npeuvfWpBfYCx1jicPFYU+H8u+soffZcxlDHu7vImV+zTEi9MT62Dqg8NKns35vNJn7I J9HfdY90yhjCipHi5tpLstc5HaD92owkmjADiooLBBE/Cde3/UlumfICnrSjceYqKzt8 lqvg== X-Forwarded-Encrypted: i=1; AJvYcCXWDDvjXicvwU+vLX4tT5nveUNkDFUlLMtwk3JGV3q8i0THqT5naXwh6L5rUCPqHHKQwnDVfEuMbg==@kvack.org X-Gm-Message-State: AOJu0YxU3YV0aDjev5yZBwLSaJ4p8Hr73rnv17OFtqM+MMU4p5Xm2RpJ 4w+rdoOXGxTyt8YJtFuwDESRST3/z/MB/xmqppL5l2aXCP9uq3Oqvo6WhXYBPjQ= X-Gm-Gg: ASbGnctys0TOIar5QSzTpGBxbhxFEDyjyeplBoiuKXTlYD9D4RSi/z4eggzzFS9MwtY +EIFkqeQiLelLgzb6hk38THeT+DhO/UMX32NzL4FSOxZ7dWG0UKulbSZdCp639B1Shz60QJDPZ+ exUbRJ+NffWNak02VJRkMERwvYeC3rDqauy+5rXC+eSOUxrHqfY5kWdqtOAMNk8z68P37NOMAbC xhzc2v8pj9zthinS2N1J8yuQnnLcZCUMle5QUu4r40XsN6KylMOFziHo1kdzu3RJoKmznvi/fKG AmOIDsToQnkxC/VeKQc1CwLvYHrODDQ= X-Google-Smtp-Source: AGHT+IHaxudRMH2a6X9Kau2FejbNNa+aNZH7OQ4Z4KpCCzwiphcNEJX34OXuuFlJfN/dPYRcVT3pPw== X-Received: by 2002:a05:600c:6c9a:b0:438:a240:c54 with SMTP id 5b1f17b1804b1-438a2400d95mr279659705e9.9.1737970847952; Mon, 27 Jan 2025 01:40:47 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com ([2001:861:3382:ef90:3e22:3e78:ce5a:32c3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd57517fsm122917795e9.38.2025.01.27.01.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 01:40:47 -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 v4 5/9] mm: Use common huge_pte_clear() function for riscv/arm64 Date: Mon, 27 Jan 2025 10:35:26 +0100 Message-Id: <20250127093530.19548-6-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250127093530.19548-1-alexghiti@rivosinc.com> References: <20250127093530.19548-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 79D0C1C0005 X-Stat-Signature: 3ej9yhyq5r5wdc4juh5eq4qj4jyxcneu X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737970849-807954 X-HE-Meta: U2FsdGVkX19DgTgrFdA8QjOt0vTzmqBj3iainT57dqTEykeoT96Xf8gAJzT+dztHj5SC4xLQE+KY49PEFK24r0gkBrMCws8QNyPVstoANTAXPxW5ZqkcIdkvc8PTIUmRmxkEE4levHsgbTW7Z2rGEanrIo/fKx/jmnWAfvwNhPgAFOtYN64sipq8Yp16tvQ6A8d5XQVqshHrg4rkzl9ZOgs8KBJ3MLx0bakkJPXnfhW1g87RUejlmOLpaqEOZEPt0RUkCHTHFu98Ce5lsxSAE9ZiTjB2MYfFbsVwdU69qU1LiWuOTPJRFGGuQEYgERmLhCXNGinSrlZv1Mun+zFcPKkkRlwnZdIPRWNMgKNg6YrpNqT/SlN+8caKwGLcN0B9m76FIyN9RVeqCY2++bf1+ieN67HuTfHEGKJcDEecl22i012Q9+FYCCCOle3LN+jEaWxIJQREHlRAzDMrGOVXgFRxNgMLmXLmpKuNUu+aZqkSZrxeIvSofU+nePQZmkM+Tda3NGkrrx5E/No9lyGClWotXLVCpXUXVRUYcftUMVQI1M4KSmzxeonRX8SWAFFTo/kElXEmMcLDq7JtjcDtEEavmAdS6sPC0/uI+74db0oM9TP7q91p1dcoFD7eEdTICWzed/xuIMVvDI2lhlvs7Bl6M/JqGJAKyU2FDpqTG23Fij/Y4wkGYxxyU3pe0rGYyUlRXmlwPNQJRqe9m12jt1LdVjdtCMVi4KM8dss0ea4fcejc8Vd2dwUOYuCDokfc2ft7FTQB4KUzJ77p/9h39K9fjFcOJgEsXrv11POlinH2wUAEWPwMFthtG9+wBFjes3qc+VQtKo/KDSNjUMt5iyJfcEDKl+GPjTRUVAxsNCQ8K2qR78k2IktaeR1n0EZE4dx2hq9aZyT8fxSFteykB9oH386Jcz96Z9b4gIQaZOmY++qEG3HlbcZiGoG1pEqr9sGXjLT0Uy2TNpeqBPT 1zsPLomE 45F4xA+IdPCLCXDnrslClGxx8PTAhnVju0GlKkLkF/Oq6Mx0maLEhZx0WtavSNDmpw87sWFu29tdXKUzqehg3Kq38ZBQgB72eEo/rKrWXkgFwrADKqI3s/MQ3PwnCBybyLFuu5vqL6/AMMOjKl1uGZTWjkZ/tIEI4+Aqrr4+jwau004IG6zvX7XZEiHKEE5nRH5OStbGVp3zq53JEWgzgrz2ROjOjZm5CiTX+eDZiSqV9h02CW0Wxm5CcnhkjZ5IlsnqvODXHolEUuovD/cKgdfMwcja4zEvgE8q2/kvVW4B43xBZH7WV+krXgQuyHGX1yKW4MAb5hbFdycELc5eHEMDPqkfkDqHgQH0c77Rl12npkG+f2iMEQ3RazAGU5T9YyEWuDLQOOkLErRALP3X4a/3uync3HSomMUhc0CSdSB6PL//Y2t7Qh3t91Xg0fcIeddbCDWEQQpxnjjjyRPGS5svjlg== 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: Both architectures have the same implementation so move it to generic code. Signed-off-by: Alexandre Ghiti --- arch/arm64/include/asm/hugetlb.h | 3 --- arch/arm64/mm/hugetlbpage.c | 12 ------------ arch/riscv/include/asm/hugetlb.h | 4 ---- arch/riscv/include/asm/pgtable.h | 5 +++-- arch/riscv/mm/hugetlbpage.c | 19 ------------------- include/linux/hugetlb_contpte.h | 4 ++++ mm/hugetlb_contpte.c | 14 ++++++++++++++ 7 files changed, 21 insertions(+), 40 deletions(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 40d87a563093..e4acaedea149 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -48,9 +48,6 @@ extern void huge_ptep_set_wrprotect(struct mm_struct *mm, #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep); -#define __HAVE_ARCH_HUGE_PTE_CLEAR -extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, unsigned long sz); void __init arm64_hugetlb_cma_reserve(void); diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 02de680a6a0d..541358f50b64 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -277,18 +277,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -void huge_pte_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, unsigned long sz) -{ - int i, ncontig; - size_t pgsize; - - ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) - __pte_clear(mm, addr, ptep); -} - pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index 28cbf5d761e1..ca9930cdf2e6 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -20,10 +20,6 @@ bool arch_hugetlb_migration_supported(struct hstate *h); #endif #ifdef CONFIG_RISCV_ISA_SVNAPOT -#define __HAVE_ARCH_HUGE_PTE_CLEAR -void huge_pte_clear(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, unsigned long sz); - #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep); diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 74d29d0af172..08b24c0a579b 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -621,8 +621,8 @@ static inline int arch_contpte_get_num_contig(pte_t *ptep, unsigned long size, } #endif -static inline void pte_clear(struct mm_struct *mm, - unsigned long addr, pte_t *ptep) +static inline void __pte_clear(struct mm_struct *mm, + unsigned long addr, pte_t *ptep) { __set_pte_at(mm, ptep, __pte(0)); } @@ -737,6 +737,7 @@ static inline pte_t ptep_get(pte_t *ptep) #define __HAVE_ARCH_PTEP_GET_AND_CLEAR #define ptep_get_and_clear __ptep_get_and_clear +#define pte_clear __pte_clear #define pgprot_nx pgprot_nx static inline pgprot_t pgprot_nx(pgprot_t _prot) diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index 0ecb2846c3f0..e2093e7266a5 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -251,25 +251,6 @@ pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num); } -void huge_pte_clear(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long sz) -{ - size_t pgsize; - pte_t pte = ptep_get(ptep); - int i, pte_num; - - if (!pte_napot(pte)) { - pte_clear(mm, addr, ptep); - return; - } - - pte_num = arch_contpte_get_num_contig(ptep, sz, &pgsize); - for (i = 0; i < pte_num; i++, addr += pgsize, ptep++) - pte_clear(mm, addr, ptep); -} - static bool is_napot_size(unsigned long size) { unsigned long order; diff --git a/include/linux/hugetlb_contpte.h b/include/linux/hugetlb_contpte.h index 7acd734a75e8..d9892a047b2b 100644 --- a/include/linux/hugetlb_contpte.h +++ b/include/linux/hugetlb_contpte.h @@ -14,4 +14,8 @@ extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte, unsigned long sz); +#define __HAVE_ARCH_HUGE_PTE_CLEAR +extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, unsigned long sz); + #endif /* _LINUX_HUGETLB_CONTPTE_H */ diff --git a/mm/hugetlb_contpte.c b/mm/hugetlb_contpte.c index 677d714fd10d..c76d6b3d0121 100644 --- a/mm/hugetlb_contpte.c +++ b/mm/hugetlb_contpte.c @@ -12,6 +12,7 @@ * - __ptep_get() * - __set_ptes() * - __ptep_get_and_clear() + * - __pte_clear() * - pte_cont() * - arch_contpte_get_num_contig() */ @@ -20,6 +21,7 @@ * This file implements the following contpte aware API: * - huge_ptep_get() * - set_huge_pte_at() + * - huge_pte_clear() */ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) @@ -101,3 +103,15 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, set_contptes(mm, addr, ptep, pte, ncontig, pgsize); } + +void huge_pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, unsigned long sz) +{ + int i, ncontig; + size_t pgsize; + + ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); + + for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) + __pte_clear(mm, addr, ptep); +}