From patchwork Fri Aug 2 15:14:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13751654 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 079E7C52D6F for ; Fri, 2 Aug 2024 15:23:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DE236B009B; Fri, 2 Aug 2024 11:23:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88DE86B009C; Fri, 2 Aug 2024 11:23:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72F3F6B009D; Fri, 2 Aug 2024 11:23:50 -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 55E896B009B for ; Fri, 2 Aug 2024 11:23:50 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 05ADAA6163 for ; Fri, 2 Aug 2024 15:23:50 +0000 (UTC) X-FDA: 82407675420.27.190CBBE Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf07.hostedemail.com (Postfix) with ESMTP id 11A0D40037 for ; Fri, 2 Aug 2024 15:23:47 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=IGk0kobg; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.43 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=1722612151; 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=vQeh/2IBWHHfu2c6+4XfBIZxNp4bqCqqEIWNYF9wjYg=; b=24xx4eTHfUecPPReu2D+1I3MTwcUbiEKZK9G+yQl2GQQ6/xzlv8din8UGSm9NjivQlcoq/ rUQSRUcEGgoInHrLvb+O8cyuPU5Zp4gWxZl6zE78k23f4Q6h7odJjYsFufGLf5X2tC60Kx 5U8a7YRq/5Qju5yJi9VCYyI14CjxmQk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=IGk0kobg; spf=pass (imf07.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722612151; a=rsa-sha256; cv=none; b=gIZ+NddGrMkR+HQNA0cKFcCZ7gbmWkiD5CSnOY+LCS3KuNzWwDnAqquzpEtfjsFBQMO8VE S+uo651qn7ep+zPGh3sSqS0c6xHzFNGNj1mGcYoo0vKs+GrzhYYHpg4FWIwdmcB5+TGE/u EA+KVZRihWTAV1oSL5IkrIujT6P+6p0= Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3683178b226so4012844f8f.1 for ; Fri, 02 Aug 2024 08:23:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1722612227; x=1723217027; 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=vQeh/2IBWHHfu2c6+4XfBIZxNp4bqCqqEIWNYF9wjYg=; b=IGk0kobg5sD+TL0w2aXIEunCV5+CuL2QThEXTpxqhxqpTpxOHAifcgzDG4RqkegVjt T7uJijQHp7b7Aydrdr+shoqoMJF05ohP3cIrGfGPLgKuUWcGqAgwh01NvBrFEzGaUCBX 8OiF+06eRYMbUUp130Aw1se3KXW4+PDDpQDuB3hg9eUfsbtoMP/gf1KRxeN2Z3xrpyHN 7rQsJLFVT1pcaXrhOVy9jWi8/9p3tKi2lfOvPE6ODzcKanv+hgLkKNyLggfnRVkMZ/A5 ktMblZznxyyk3xeqKstDejbAqnOg32f2eIaiSx9g1DJdprv6hc0eEGKH77EfUm50j93z tKsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722612227; x=1723217027; 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=vQeh/2IBWHHfu2c6+4XfBIZxNp4bqCqqEIWNYF9wjYg=; b=OIfhPRRzF7fuU2GrHW/w2HwGIL180PDVWvGDbAyJqOvDa0yko4lo4oqX+SOuodOXgN 3aeR+2zbLDpiHiTDwHwJ6MZnHgwDhKYtzzDtXfiMwRl9cC6K26HNF55G+Ayx4N5Z3PK6 7o9+umX392/ML57ed7S7lT+nTBCzENgqWmsn2XUxnqEjgf9wsElIY7pGNLCBYNdJ7T6m ad0wXWEaDctCbzJkiJsQ2ZnjdyD9mqov44/VOtCLgMqyRalCJM8YYeiFn5bIsNNDunov 4VshiOEuXAzTMbELUGEr395KCCT3itZN6MZWGw7WTmOxDUGB+HYjEwmx2C07VOEUE9Bx zqjw== X-Forwarded-Encrypted: i=1; AJvYcCVlSpeXN/IMzXiYf2wQxubDEyt8YepWaGt/fB9Kp7gihuNUPRHwHUk0SoDAd5TV/AJ+eodYncC05cwsvv7yP1ZknL0= X-Gm-Message-State: AOJu0YyzcDbbjaoyIoRndNWc6shx4uhCByhj/Rh+hdSw9bgIzRZ44Gah Zkvi+IHB64DG7c7/3DR2RCl/RabJQ2QL9n7IVPz3bZq4LUxChz9egexOdE5vb8U= X-Google-Smtp-Source: AGHT+IHTN3sk4f5D6D5TLgsFPV/oHaKP/CTwEIdjag4arFIbTitJxkFdq6uXQ6FKZRCqULys8NHSbg== X-Received: by 2002:a5d:5c87:0:b0:368:460d:d942 with SMTP id ffacd0b85a97d-36bc5a007bamr859962f8f.24.1722612226380; Fri, 02 Aug 2024 08:23:46 -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 ffacd0b85a97d-36bbd01efb1sm2194291f8f.52.2024.08.02.08.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 08:23:46 -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 9/9] mm: Use common huge_ptep_clear_flush() function for riscv/arm64 Date: Fri, 2 Aug 2024 17:14:30 +0200 Message-Id: <20240802151430.99114-10-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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 11A0D40037 X-Stat-Signature: 9cify8zu7jptegpfta7yczdomderbssz X-Rspam-User: X-HE-Tag: 1722612227-190982 X-HE-Meta: U2FsdGVkX190z5gYbphiFe20KWAqhC7QPuqQsHKWudDEOpspWM8gqX3tc0g84DbXcHDi53lltnU4CGmc/njt3nJpcQazKL7uy+HQPWAneoPKCpAmK2TaE979g2gtIPHQKsdm6EHntU9LAV4e3WWQk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PIw43PyzceEIrFpuZPAb4LY3pPzAR5q++Sc9HUdKd9LPg5S0L897M3hH66PeqXHW0LDdAdDQdqX2LaSZhiwWxaaVZbDfoJeXoawPRPs5QY4a2PS6Xw8C0+9gZmBizUtyv1GHn1Hwy1uClc2sUvsirI+lhg== 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: After some adjustments, both architectures have the same implementation so move it to the generic code. Signed-off-by: Alexandre Ghiti --- arch/arm64/include/asm/hugetlb.h | 3 -- arch/arm64/mm/hugetlbpage.c | 61 -------------------------------- arch/riscv/include/asm/hugetlb.h | 7 +--- arch/riscv/mm/hugetlbpage.c | 51 -------------------------- include/linux/hugetlb_contpte.h | 4 +++ mm/hugetlb_contpte.c | 15 ++++++++ 6 files changed, 20 insertions(+), 121 deletions(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 4ceb6cb1bec5..93c44a76c994 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -27,9 +27,6 @@ static inline void arch_clear_hugetlb_flags(struct folio *folio) pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags); #define arch_make_huge_pte arch_make_huge_pte -#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); void __init arm64_hugetlb_cma_reserve(void); diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 8d271e175848..ad04641261dc 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -98,53 +98,6 @@ int find_num_contig(struct mm_struct *mm, unsigned long addr, return CONT_PTES; } -/* - * Changing some bits of contiguous entries requires us to follow a - * Break-Before-Make approach, breaking the whole contiguous set - * before we can change any entries. See ARM DDI 0487A.k_iss10775, - * "Misprogramming of the Contiguous bit", page D4-1762. - * - * This helper performs the break step. - */ -static pte_t get_clear_contig(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - pte_t orig_pte = __ptep_get(ptep); - unsigned long i; - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) { - pte_t pte = __ptep_get_and_clear(mm, addr, ptep); - - /* - * If HW_AFDBM is enabled, then the HW could turn on - * the dirty or accessed bit for any page in the set, - * so check them all. - */ - if (pte_dirty(pte)) - orig_pte = pte_mkdirty(orig_pte); - - if (pte_young(pte)) - orig_pte = pte_mkyoung(orig_pte); - } - return orig_pte; -} - -static pte_t get_clear_contig_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - pte_t orig_pte = get_clear_contig(mm, addr, ptep, pgsize, ncontig); - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - - flush_tlb_range(&vma, addr, addr + (pgsize * ncontig)); - return orig_pte; -} - pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz) { @@ -266,20 +219,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) -{ - struct mm_struct *mm = vma->vm_mm; - size_t pgsize; - int ncontig; - - if (!pte_cont(__ptep_get(ptep))) - return ptep_clear_flush(vma, addr, ptep); - - ncontig = find_num_contig(mm, addr, ptep, &pgsize); - return get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); -} - static int __init hugetlbpage_init(void) { if (pud_sect_supported()) diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index 4c692dd82779..63c7e4fa342a 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -20,14 +20,9 @@ bool arch_hugetlb_migration_supported(struct hstate *h); #endif #ifdef CONFIG_RISCV_ISA_SVNAPOT -#define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH -pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep); - pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags); #define arch_make_huge_pte arch_make_huge_pte - -#endif /*CONFIG_RISCV_ISA_SVNAPOT*/ +#endif /* CONFIG_RISCV_ISA_SVNAPOT */ #include diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c index 8963a4e77742..ea1ae3a43d45 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -121,42 +121,6 @@ unsigned long hugetlb_mask_last_page(struct hstate *h) return 0UL; } -static pte_t get_clear_contig(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pte_num) -{ - pte_t orig_pte = ptep_get(ptep); - unsigned long i; - - for (i = 0; i < pte_num; i++, addr += PAGE_SIZE, ptep++) { - pte_t pte = ptep_get_and_clear(mm, addr, ptep); - - if (pte_dirty(pte)) - orig_pte = pte_mkdirty(orig_pte); - - if (pte_young(pte)) - orig_pte = pte_mkyoung(orig_pte); - } - - return orig_pte; -} - -static pte_t get_clear_contig_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pte_num) -{ - pte_t orig_pte = get_clear_contig(mm, addr, ptep, pte_num); - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - bool valid = !pte_none(orig_pte); - - if (valid) - flush_tlb_range(&vma, addr, addr + (PAGE_SIZE * pte_num)); - - return orig_pte; -} - pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) { unsigned long order; @@ -173,21 +137,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, - unsigned long addr, - pte_t *ptep) -{ - pte_t pte = ptep_get(ptep); - int pte_num; - - if (!pte_napot(pte)) - return ptep_clear_flush(vma, addr, ptep); - - pte_num = arch_contpte_get_num_contig(vma->vm_mm, addr, ptep, 0, NULL); - - return get_clear_contig_flush(vma->vm_mm, addr, ptep, pte_num); -} - 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 02bce0ed93d8..911b9cd4aa4d 100644 --- a/include/linux/hugetlb_contpte.h +++ b/include/linux/hugetlb_contpte.h @@ -31,4 +31,8 @@ extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, extern void huge_ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep); +#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); + #endif /* _LINUX_HUGETLB_CONTPTE_H */ diff --git a/mm/hugetlb_contpte.c b/mm/hugetlb_contpte.c index b00bbcc2d939..c8ea81883184 100644 --- a/mm/hugetlb_contpte.c +++ b/mm/hugetlb_contpte.c @@ -27,6 +27,7 @@ * - huge_ptep_get_and_clear() * - huge_ptep_set_access_flags() * - huge_ptep_set_wrprotect() + * - huge_ptep_clear_flush() */ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) @@ -254,3 +255,17 @@ void huge_ptep_set_wrprotect(struct mm_struct *mm, set_contptes(mm, addr, ptep, pte, ncontig, pgsize); } + +pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep) +{ + struct mm_struct *mm = vma->vm_mm; + size_t pgsize; + int ncontig; + + if (!pte_cont(__ptep_get(ptep))) + return ptep_clear_flush(vma, addr, ptep); + + ncontig = arch_contpte_get_num_contig(mm, addr, ptep, 0, &pgsize); + return get_clear_contig_flush(mm, addr, ptep, pgsize, ncontig); +}