From patchwork Mon Jan 27 09:35:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 13951127 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 BCC06C02190 for ; Mon, 27 Jan 2025 09:39:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A9FE280139; Mon, 27 Jan 2025 04:39:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45AED28012F; Mon, 27 Jan 2025 04:39:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FB67280139; Mon, 27 Jan 2025 04:39:50 -0500 (EST) 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 1114128012F for ; Mon, 27 Jan 2025 04:39:50 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C2984122101 for ; Mon, 27 Jan 2025 09:39:49 +0000 (UTC) X-FDA: 83052734898.14.3F18052 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by imf14.hostedemail.com (Postfix) with ESMTP id CEF93100014 for ; Mon, 27 Jan 2025 09:39:47 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zaAFNvbN; spf=pass (imf14.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.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=1737970787; 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=8mhN3d8PsNley3p53cGFp5ftMvicJk5x5kFgKHD2MsE=; b=wN8v8McnhkTskRAoV7So6QCfCvLg+oMb7E1kg8A9vaBW++Ha5Cdho2VFJDbv82ddrmzxxi FdzE0ILi+x70bBBWcH4rCdyJM4ooMqiemhQx+XqVLQu9uP1anYXHxOSINNslxlwPmWxH+m TJqzymxQJzwGdFUiC7+fEYB8DPo27ac= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=zaAFNvbN; spf=pass (imf14.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737970787; a=rsa-sha256; cv=none; b=bxMczWGepS4Fz+LBYTvh7sUObp3dLGr4cjiARQIihQ/tdJ5bqi9bbTLwBK5xBCf2W8TVrw Rv4g4NSMyPdC8icMSEw7AbAcl9VY/kR/R9XfdS0gepF3pZ5u5YDw5HKp0KpmR3rjgH1uTJ Jn8vX2dhs8m54zeiD6GITtAY+IqLhok= Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4361815b96cso27341565e9.1 for ; Mon, 27 Jan 2025 01:39:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1737970786; x=1738575586; 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=8mhN3d8PsNley3p53cGFp5ftMvicJk5x5kFgKHD2MsE=; b=zaAFNvbNWOffshaNH6a2zpUM+XMi4MpgUpMDNbo4I9ZNuBCXm46SaQYLN6uOXSf5m2 7shVfF6iiCb9PaierSO7NJ5bC7s0zJ6qv4qFVRzP4buC7N666m05I10tVxJvQTHZTMul OvewO/SjFUYWHTl2QNm3FAOlsqcJ7FP2U8goieASnVpUSPuFAqPuciyAvltPIqfdRuaU hL2JDhb7Q6N/g6i6Fyw2MeiTFtZOp5Z1T3TX2N0Kif0YPJm0cYFsn51cgsGwWvT6koox m1YUOTkd+INRLRhej+WqqwzKZBTzB7eZtnrdM3tPmOOo36nInaGCwwzpFe2Wzln+brEw x2Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737970786; x=1738575586; 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=8mhN3d8PsNley3p53cGFp5ftMvicJk5x5kFgKHD2MsE=; b=dVzNUImYCBEscH0hC5rdErXXtB3RZ5htr3lzMYoChRWrvMFNiBiGwfrLKJxSGgvQVB 7uFixC/fCpNg654sVcqK2ixwdwkscJt2I2EOhaNCJ58BR/bs3LAD/lxeCI7tgeRSc9cb WtF5t1Mzqw4PJgaWGoSEwKzV+9+y//8GaYWqR6fFyoyRavNK9+I8jXV3/P1coHmNq1h7 j89DbU7yX2M8B1aRKik/aqqT3vcpBk/1aJZEI3FVUaG8DZPK5zbYvIgRc5jBAhuquEH5 x9W0MaGHWaEOr0KHRndP7oL8endfJ+BeOj0WmhA3ahkEORPq+/Nfa2UggJ3CgkhJ4Xj+ jvmQ== X-Forwarded-Encrypted: i=1; AJvYcCVleHsRR06GNOTT6NT7YGjdQgwaQZXH0rKoHIbIeyu04Kno926p+OAinWQpTciHbQbI6uwT5C7ltw==@kvack.org X-Gm-Message-State: AOJu0Yx10Q/cS17NlhhUzqstGHgGv2DpF+9PxaQvJ0tGjqoQDOl+y3Ji j9P70EuVmedGyvdbMSoTtlUfNkmJkfLRF1/FGDKq8i/9WH+FqIOJvhWp1GwmTVA= X-Gm-Gg: ASbGncttUFldFuLtes8+tPqsQ2jZYMbqqKxuEIYzhhD6O2+4oyd+nmZzchyP2jLnjrl xMXjRlQ7aEgm+Q39yInRaD9PF8Di7dMNIPF5YNfrQMcb4Li5LbEDmg6suUVwlhe006hr6SyvCId Xdi5nRLQL+Rb7RKa3lJr5TLxMZAGBivTryo18PT6rrFqFBYWv7aeiF7xhkzHIqPmYp6Lu8zXLQ/ EKkEAkHX5oO+3asFxXBSL6tGf9yzIfUDZKGOoNxMbtLrjuDMFAjDY/kdvxGdLODR4YBSgJx4DG5 YULHmYJfh2O5FHExXQa14yLeoFmEvPM= X-Google-Smtp-Source: AGHT+IFb60eslNQdePOaLfXv36Z0OpFdyDEXUXYChc5sJwAPhp8i6cvPTkFCm9BP5tmum6xqjAkWnA== X-Received: by 2002:a05:6000:4022:b0:385:e013:73f6 with SMTP id ffacd0b85a97d-38bf59eff21mr37315469f8f.50.1737970786287; Mon, 27 Jan 2025 01:39:46 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com ([2001:861:3382:ef90:3e22:3e78:ce5a:32c3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38c2a1bb040sm10590537f8f.67.2025.01.27.01.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2025 01:39:46 -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 4/9] mm: Use common set_huge_pte_at() function for riscv/arm64 Date: Mon, 27 Jan 2025 10:35:25 +0100 Message-Id: <20250127093530.19548-5-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-Server: rspam02 X-Rspamd-Queue-Id: CEF93100014 X-Stat-Signature: xz9fk5igod4nfp7o4gbrt66qpythgmdt X-Rspam-User: X-HE-Tag: 1737970787-579782 X-HE-Meta: U2FsdGVkX18DEKz0F2POj4u/tK3ENlah8GvFXDIbACAxxm49ylPDoWIDbd4mNWO+HLgj7GzuztASHL/qhSy7Z3LcaOn/dTobZhz6COfB9KrKKHbWa/8Wdyqhi75HC6faH0eu8+YAWL4nacVp2GDLlYE+klXZAxcygnCmeguMUIgKBgWhry9x4B3bAmkNXl7RHEMy9i8L3dldoM2CXBpxv8X5kStH1sjSuC/73pCaz+Bgh7I2sh/lDHyTsIxycbrLNWYiQz6ugsWYKUjMY8SjJKEu4l+Lka+Lv/9ney/UwyYGuP2MOBX3DJZ8csBImVFiIhWv4WUGFQVfqKyAawIUY4xpBKuKCrQ527w3C23JJ31aOWM0thQ5J7dwgHqqubzO8ZH7gzIV2dtNe+M1xJa3Pc+G1Q5GHRUS8V4ZvjOGNL8QEsFso3khrEjWKbBaEgi2ltNAuPgfYi5pC6vp2Ujh9lmoFNmU9bbAhWWx8LK51oKpw6TuIaBERCqIDTqTqvZhYfxKgATQIl8jslN837/tNBedJXdPxEOSJZAsSags6nxIGk26c9CFRbzK2XPV36olLCDQQ1kf9ok4BqHcmDNH/bewbVt79Ov+cOjvqb9GMX7Pmr9tY20n++rqTY26Z1JBujrGFx9tRYeLLzyPx8DnsdvQZ+NWG4KGMfH+EQP20uKBLxqSKmbHIOJyI/Q7qCHGe1UsgbxcaZjrgKx0g9wkQTQcwoERNg9TLS8pnsNIo7wlorNwFNjYHQU9nm7tREgeXQbTLiwUFCr/M6D5MF9GMLwA3raLB1JmvLR2aMn0RcRPL6CMXO8erfRHKBxu9KDa+G2ic+3KsJT4ajQ59RSpZWL7pRnoXZ3I2fiq77Lvc8/SDgQ6q5fli/jEFYEvACvq2vLimhutdf/dxJI5QRXP+3+vUFfCsR9LWgi+3ctMJzmg1i6v7Zmg/O8k95P3BKiGnnjYLMv4MaP9tianl/z Yn1v14J/ jm396gpl/XY/JnOzjkS3icyojDVdTECruYz9FGpNhm3PhSOMaPPbumBfF9TCqpmTWHPqu0I+amblWDE7jbz/Hpevs84GYJ8nUAT+e8SQfw0dPQ7BoJFVT+mZDBzgfRat+Vms2UCO5sjlb/DAXh/YBwaXiP92s6oqnMaTesjH92ibv55GMd75xcURYasO5MZuRUvP0RsDUXvIGLDXhO3H3TjEszNVaNxt3vLwVuTtVDVDFiszHrUNJVaK0+zwIb2IsuML9ljkwr2dbrWQo1pAq4h5+ciXNnCdcNm5dmifMEyxo/BZZEA5WKJ6uFPj49hGT9gdoxKBqcLxbaBsOtYv9jZrSCKO4zZOyPwnpukLA380JsmChuNEN3b3JZ3O7DgbdiPrQzWygkmvn3ca77Vcc19JIMALwUSX+4oPlz7+Ci21M0i82E0huS6lPNLbYIZ+1l+OQORaxQCrMTcdOWODIvqbd/A== 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 | 56 ----------------------------- arch/riscv/include/asm/hugetlb.h | 5 --- arch/riscv/include/asm/pgtable.h | 8 +++-- arch/riscv/mm/hugetlbpage.c | 62 -------------------------------- include/linux/hugetlb_contpte.h | 5 +++ mm/hugetlb_contpte.c | 59 ++++++++++++++++++++++++++++++ 7 files changed, 69 insertions(+), 129 deletions(-) diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h index 27d7f4bdd724..40d87a563093 100644 --- a/arch/arm64/include/asm/hugetlb.h +++ b/arch/arm64/include/asm/hugetlb.h @@ -35,9 +35,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_SET_HUGE_PTE_AT -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_PTEP_SET_ACCESS_FLAGS extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 3458461adb90..02de680a6a0d 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -145,62 +145,6 @@ static pte_t get_clear_contig_flush(struct mm_struct *mm, return orig_pte; } -/* - * 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 for use cases where the - * original pte is not needed. - */ -static void clear_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - unsigned long i, saddr = addr; - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) - __ptep_get_and_clear(mm, addr, ptep); - - flush_tlb_range(&vma, saddr, addr); -} - -void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pte, unsigned long sz) -{ - size_t pgsize; - int i; - int ncontig; - unsigned long pfn, dpfn; - pgprot_t hugeprot; - - ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); - - if (!pte_present(pte)) { - for (i = 0; i < ncontig; i++, ptep++, addr += pgsize) - __set_ptes(mm, addr, ptep, pte, 1); - return; - } - - if (!pte_cont(pte)) { - __set_ptes(mm, addr, ptep, pte, 1); - return; - } - - pfn = pte_pfn(pte); - dpfn = pgsize >> PAGE_SHIFT; - hugeprot = pte_pgprot(pte); - - clear_flush(mm, addr, ptep, pgsize, ncontig); - - for (i = 0; i < ncontig; i++, ptep++, addr += pgsize, pfn += dpfn) - __set_ptes(mm, addr, ptep, pfn_pte(pfn, hugeprot), 1); -} - pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz) { diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h index d9f9bfb84908..28cbf5d761e1 100644 --- a/arch/riscv/include/asm/hugetlb.h +++ b/arch/riscv/include/asm/hugetlb.h @@ -24,11 +24,6 @@ bool arch_hugetlb_migration_supported(struct hstate *h); void huge_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned long sz); -#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT -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_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 d4e6427b8ca9..74d29d0af172 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -634,9 +634,8 @@ extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addre extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); -#define __HAVE_ARCH_PTEP_GET_AND_CLEAR -static inline pte_t ptep_get_and_clear(struct mm_struct *mm, - unsigned long address, pte_t *ptep) +static inline pte_t __ptep_get_and_clear(struct mm_struct *mm, + unsigned long address, pte_t *ptep) { pte_t pte = __pte(atomic_long_xchg((atomic_long_t *)ptep, 0)); @@ -736,6 +735,9 @@ static inline pte_t ptep_get(pte_t *ptep) #define ptep_get __ptep_get #endif /* CONFIG_RISCV_ISA_SVNAPOT */ +#define __HAVE_ARCH_PTEP_GET_AND_CLEAR +#define ptep_get_and_clear __ptep_get_and_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 d51863824540..0ecb2846c3f0 100644 --- a/arch/riscv/mm/hugetlbpage.c +++ b/arch/riscv/mm/hugetlbpage.c @@ -173,68 +173,6 @@ pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) return entry; } -static void clear_flush(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - unsigned long pgsize, - unsigned long ncontig) -{ - struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); - unsigned long i, saddr = addr; - - for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) - ptep_get_and_clear(mm, addr, ptep); - - flush_tlb_range(&vma, saddr, addr); -} - -/* - * When dealing with NAPOT mappings, the privileged specification indicates that - * "if an update needs to be made, the OS generally should first mark all of the - * PTEs invalid, then issue SFENCE.VMA instruction(s) covering all 4 KiB regions - * within the range, [...] then update the PTE(s), as described in Section - * 4.2.1.". That's the equivalent of the Break-Before-Make approach used by - * arm64. - */ -void set_huge_pte_at(struct mm_struct *mm, - unsigned long addr, - pte_t *ptep, - pte_t pte, - unsigned long sz) -{ - unsigned long hugepage_shift, pgsize; - int i, pte_num; - - if (sz >= PGDIR_SIZE) - hugepage_shift = PGDIR_SHIFT; - else if (sz >= P4D_SIZE) - hugepage_shift = P4D_SHIFT; - else if (sz >= PUD_SIZE) - hugepage_shift = PUD_SHIFT; - else if (sz >= PMD_SIZE) - hugepage_shift = PMD_SHIFT; - else - hugepage_shift = PAGE_SHIFT; - - pte_num = sz >> hugepage_shift; - pgsize = 1 << hugepage_shift; - - if (!pte_present(pte)) { - for (i = 0; i < pte_num; i++, ptep++, addr += pgsize) - set_ptes(mm, addr, ptep, pte, 1); - return; - } - - if (!pte_napot(pte)) { - set_ptes(mm, addr, ptep, pte, 1); - return; - } - - clear_flush(mm, addr, ptep, pgsize, pte_num); - - set_ptes(mm, addr, ptep, pte, pte_num); -} - int huge_ptep_set_access_flags(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, diff --git a/include/linux/hugetlb_contpte.h b/include/linux/hugetlb_contpte.h index ec4189cd65b8..7acd734a75e8 100644 --- a/include/linux/hugetlb_contpte.h +++ b/include/linux/hugetlb_contpte.h @@ -9,4 +9,9 @@ #define __HAVE_ARCH_HUGE_PTEP_GET extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); +#define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT +extern void set_huge_pte_at(struct mm_struct *mm, + unsigned long addr, pte_t *ptep, pte_t pte, + unsigned long sz); + #endif /* _LINUX_HUGETLB_CONTPTE_H */ diff --git a/mm/hugetlb_contpte.c b/mm/hugetlb_contpte.c index a03e91d3efb1..677d714fd10d 100644 --- a/mm/hugetlb_contpte.c +++ b/mm/hugetlb_contpte.c @@ -10,6 +10,8 @@ /* * Any arch that wants to use that needs to define: * - __ptep_get() + * - __set_ptes() + * - __ptep_get_and_clear() * - pte_cont() * - arch_contpte_get_num_contig() */ @@ -17,6 +19,7 @@ /* * This file implements the following contpte aware API: * - huge_ptep_get() + * - set_huge_pte_at() */ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) @@ -42,3 +45,59 @@ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) } return orig_pte; } + +/* + * ARM64: 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. + * + * RISCV: When dealing with NAPOT mappings, the privileged specification + * indicates that "if an update needs to be made, the OS generally should first + * mark all of the PTEs invalid, then issue SFENCE.VMA instruction(s) covering + * all 4 KiB regions within the range, [...] then update the PTE(s), as + * described in Section 4.2.1.". That's the equivalent of the Break-Before-Make + * approach used by arm64. + * + * This helper performs the break step for use cases where the + * original pte is not needed. + */ +static void clear_flush(struct mm_struct *mm, + unsigned long addr, + pte_t *ptep, + unsigned long pgsize, + unsigned long ncontig) +{ + struct vm_area_struct vma = TLB_FLUSH_VMA(mm, 0); + unsigned long i, saddr = addr; + + for (i = 0; i < ncontig; i++, addr += pgsize, ptep++) + __ptep_get_and_clear(mm, addr, ptep); + + flush_tlb_range(&vma, saddr, addr); +} + +void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned long sz) +{ + size_t pgsize; + int i; + int ncontig; + + ncontig = arch_contpte_get_num_contig(ptep, sz, &pgsize); + + if (!pte_present(pte)) { + for (i = 0; i < ncontig; i++, ptep++, addr += pgsize) + __set_ptes(mm, addr, ptep, pte, 1); + return; + } + + if (!pte_cont(pte)) { + __set_ptes(mm, addr, ptep, pte, 1); + return; + } + + clear_flush(mm, addr, ptep, pgsize, ncontig); + + set_contptes(mm, addr, ptep, pte, ncontig, pgsize); +}