From patchwork Fri Aug 2 15:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13751627 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 28B8DC3DA4A for ; Fri, 2 Aug 2024 15:19:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B75D96B008A; Fri, 2 Aug 2024 11:19:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B239B6B0095; Fri, 2 Aug 2024 11:19:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C42F6B0096; Fri, 2 Aug 2024 11:19:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7CFE76B008A for ; Fri, 2 Aug 2024 11:19:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EA0CC80BD4 for ; Fri, 2 Aug 2024 15:19:44 +0000 (UTC) X-FDA: 82407665088.12.5147D74 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by imf22.hostedemail.com (Postfix) with ESMTP id 09381C0005 for ; Fri, 2 Aug 2024 15:19:42 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=0R7WXPJ8; spf=pass (imf22.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722611953; a=rsa-sha256; cv=none; b=sC1TKj4ilSQ8gdKYYAKJtpSlLIBHuzxVTgh3AkTi1DGngpByO8gD+jZKlIojaevgAb5Kad 8CUzH32PF6etnmynLdfuxuNVIjf2SpMKZO2GMNu4rKnVSAeWZ7AupIpP5zoHFjr521uNg8 e2JBxOOdcvS1wnrLG2/A1FliF0rLZh4= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=0R7WXPJ8; spf=pass (imf22.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.174 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=1722611953; 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=hgy6e6djKCEiajpx++weOAekuViyBMKy0O9RS2EJI5E=; b=IhYQcGHMSPDvzVjCpEygjuVR5RiNrcrBz7MSWkLqPyiGstpb9RO72a5xkV74vg9+r3808D lthpK0wNp7wldN5pg/M8PC9Vnj9KPaR7JSNYtg7eDziuhCf0jRUUg1iwNvjVTUwylgLldN r/Xu6bmOwfa2fR6wdgTn8iVgKmHFRvU= Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2f032cb782dso88021281fa.3 for ; Fri, 02 Aug 2024 08:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722611981; x=1723216781; 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=hgy6e6djKCEiajpx++weOAekuViyBMKy0O9RS2EJI5E=; b=0R7WXPJ8lN515k1b0pHmllf43v7BTzmhyb4uREV63fRnlLc7D3mIbot3OSAIZNtpGr C1tFGw+Dg6biu2Hu6NKWErg+qc6BAL88FmBfS7L/2PXfNzQR7Jli8iOli3V+l8gcKiTL nhvFVX7uv14ZTx7grZRm7w/nGpXnJOWP6EgCgqpkEtoCZj4dkJsB8hA8osPDMybizVRE on7IB+tRpV8N+E/vc1cr4V5sx5jBo8ZA/e00Rj/+1IZO0sTCdV0wxTS61hFcaDy/NhUj Htayn1ME4+26lmgjBhQP3dPtopob0MuM6vbn61ja0PqzXNuLc1y88ELrOMu18tIPu7+k GhSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722611981; x=1723216781; 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=hgy6e6djKCEiajpx++weOAekuViyBMKy0O9RS2EJI5E=; b=wz0wVQvh6x5TTpZTlylZY3fRUe/ujvyDAWJgo0s8v7l+hpFqhsdxZX2TLOC7+i8UJA suiKVFTJlvcCKuNVm5ltVE0qTnGSEsvmDRJ1f+NeCga6Q9dgiDeg72E/CWVfAzmzLf4T kIED1txvcTNmQPuRol67itbriGgQFIFBvW80H+Ms3F4lsijaN2VdNSjdNXIwEt4HHHLF G66g1XP/IIOMvoVigTL3GTSNAk71C7YjgGnw0XMCqZDoSj9i7T56w7UOxjIpGk/r0Mys gr64oJnTWzHiK4Q0dX1iVJgJHaB4E+nebbFNkYSbiA6Gf4qZ/t+/X/l/LpiI41uJq8E/ qftQ== X-Forwarded-Encrypted: i=1; AJvYcCW3+z/9jOoLUD0u83oX5qAW/Rsw4GhDtuZr5Vu50DAfx//cYIjJVl9LS1bEi2lXcrFEnTdF3Fj/gvAHjUZnDy+5kwc= X-Gm-Message-State: AOJu0Yx3whKFZPqbBVFpV4xMAj9cq3Quh8H+tbCzE9/fMjo9eqFhE4GU tXIMERMgQC/KvNDY+xsLVPwCnP3hxA6ykjvZ9fUYxD8bVYjJDUmhSYjNb5MGEMI= X-Google-Smtp-Source: AGHT+IEILpnFvb14vizaqdHNCAsEefKY8W5fJrghMGpJs4NQI541WsQVt7UAPN57wbPSjoIKa73jbQ== X-Received: by 2002:a05:651c:b06:b0:2f1:6a30:6754 with SMTP id 38308e7fff4ca-2f16a3067dbmr1525221fa.12.1722611981105; Fri, 02 Aug 2024 08:19:41 -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 38308e7fff4ca-2f15e17e840sm1828141fa.12.2024.08.02.08.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 08:19:40 -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 v3 5/9] mm: Use common huge_pte_clear() function for riscv/arm64 Date: Fri, 2 Aug 2024 17:14:26 +0200 Message-Id: <20240802151430.99114-6-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240802151430.99114-1-alexghiti@rivosinc.com> References: <20240802151430.99114-1-alexghiti@rivosinc.com> MIME-Version: 1.0 X-Stat-Signature: c8ytk9kg439c41q555hmqcr947uuhifm X-Rspamd-Queue-Id: 09381C0005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722611982-307504 X-HE-Meta: U2FsdGVkX1+PDZBV7Zq4t1EMyk9GToQemRZohAsPLQsrygQj+5jr/9WaQdNiYs4ET1u7I09rkDQ0qnQim1wy8ZiCOL4xlv/T1ZUlzvY+lglGu/Y3e9/N7MQe9fwomLGZJPVRwZCIxx0EGFz8Q83hRMz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2w1WKN4sWIcRJ56JMAIx/ZutATa0czE2qSr4HdzYlkY6nOHbo07UVS129jGtJDM7abRoCWb7bqowXNrnt03CQxsVmGDh6tRjx2bXh57FJl9SCeyiekBw22Z4xyQnr5YGoZAtklqfYGAVryzWrStSStzzEVWn/BpOniWcy2og== 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 d35093b7ab59..fab0afbe4eea 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -40,9 +40,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 c7130d1f07c4..495f706e0170 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -266,18 +266,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 46b409e558b3..5ab0559b0bd2 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -615,8 +615,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)); } @@ -731,6 +731,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 9a3a376784b0..b9634ffa1bad 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); +}