From mboxrd@z Thu Jan 1 00:00:00 1970 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 8BA53C021AB for ; Wed, 19 Feb 2025 08:29:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC72A440149; Wed, 19 Feb 2025 03:29:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D4F3B280205; Wed, 19 Feb 2025 03:29:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA1C6440149; Wed, 19 Feb 2025 03:29:07 -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 92A31280205 for ; Wed, 19 Feb 2025 03:29:07 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4A0EA161206 for ; Wed, 19 Feb 2025 08:29:07 +0000 (UTC) X-FDA: 83136019134.01.EFD74B6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf23.hostedemail.com (Postfix) with ESMTP id 7EC8C140004 for ; Wed, 19 Feb 2025 08:29:05 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf23.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739953745; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqOEdoMjqUVACmbrh7dj8v+t19JY7clqp3raTUKooGM=; b=1r0E/0h9b/ympeoQFIlYj95ajsx/HZLVKg/tpijSgsoi3cyy/vPEe5oo8xJs0U9Bekrc03 9DgkzDr9jT80ceqyQYBBkxQ8cClOcBQrjhu8iBAi4Nz59XhVXCdz4TFcSppZF84YF22Iad l5m0jwA9YEAlfM0gcpmyiHbOZiEDwC0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf23.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739953745; a=rsa-sha256; cv=none; b=zZaRXqHj8gpFF9XEumBI/EFpanp/ZkcwivqRcpi9G+TrVFJCA2rM6NLhZuoEPlpdwx4dBq 7NcW8xw/SRcwNV//AFGXEtZYvTmP9t8nVZv+l20MweZ1DB4fwSeze7uj6lVfUVvcVq1WBS U995TDubitSNMhSl7O3ekN61DVm0CjU= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0329A1682; Wed, 19 Feb 2025 00:29:23 -0800 (PST) Received: from [10.162.42.6] (unknown [10.162.42.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DF78B3F5A1; Wed, 19 Feb 2025 00:28:51 -0800 (PST) Message-ID: <01358598-c359-4dd8-bfa5-50483b427c03@arm.com> Date: Wed, 19 Feb 2025 13:58:48 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/4] mm: hugetlb: Add huge page size param to huge_ptep_get_and_clear() To: Ryan Roberts , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Andreas Larsson , Arnd Bergmann , Muchun Song , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , David Hildenbrand , "Matthew Wilcox (Oracle)" , Mark Rutland , Dev Jain , Kevin Brodsky , Alexandre Ghiti Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20250217140419.1702389-1-ryan.roberts@arm.com> <20250217140419.1702389-2-ryan.roberts@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250217140419.1702389-2-ryan.roberts@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: gsqaphp9dawjb57yi7fndpatcx55us5q X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7EC8C140004 X-HE-Tag: 1739953745-58098 X-HE-Meta: U2FsdGVkX19Fmtp1l5i909rkcYMbpuAl9ZYc1ut98OT5N4krWXtdBkvr8uIKKcN6Vf8IQzciuTdBH+zXf2KdxZWDPa7ppkrwgRiLW87DxOos/nhbQf5PhCSgKxyQSkVf71YqCc/2LIwTkkgMjN+Fue0fP0s1iakpZbN3CXeJfStThrnyKXgY8lDOUrKMK+0zbgE3isiejtb1B627+LNMt6/mDsl7lBkO8UwterzWgkGcGs5+m9GcVzEAnaBXegVf+PTjSunJpbJUzBx83qCSmOvisTLKtx87XfjJXyth9+fcdJcLzN0prpUsBAVX34zisZJXFUHjPt2MLwTl475d7yazyEzdkiH4w/gViVF5CGGYVUrtWeIt7rrKw1zpM4P1QYkDVIEK8wscKD/sZMQndw9If1mvcdFblkBswTzMYOR/jedU3ilLw7+ky47F6J5vGHWO6JEnNYdFi0ByZG9QPl1dBixVVJfy1QhuPEjbRwXgkjbzxdiOH2nnBRLGyTZqNBbSic6eMqGgw91adIV5IKTb0QQcBSGILFcT8Wrw5L5GwUHKo8xycgW0XM0N5vmZHSMYa3wAoUP1kZ2dN1By8tctsYoaIRUOH7pLU5QEBRjEXhHTZ3nS0YDgv1hmZhGlECI2aRdzPBQ5r3QpR3WrWjHXpeBzHV+W/6zOidcYWykC6oN6FVCW/5yEB4lan/cTxq1liHaWkuvltzQGiqNOx7lDSK5lu1dEjCioceDOWi9jz6lYtK4yCrynM4lMDrljrlk55dSsn37J7XPpt4MI+tXmbmtqx0QY+Saeb2IZTPVhG0I0h2uTS+x3eEcuexD7x44onHHr/ebMR2zok+zJyrvvp2wOm6BY/sPglu5ofYMCUtnE0TZEyvR6X0GSWIuwx6VO4sP4rZnVlvNFpaF8lxZz8rmdBlWOMGoWxf9Dno4cJJg+DXoUx+EyKnGOdn7SzPvra2zZlA1nxq9hfh5 ZgZ88St2 S4SXY0V19VsbK0Te2P8/B4APMwybnpJ5oE3zqvMMCbgKL5ke5O79HNV3oN7SMSJuBTUL1IYfVf31A/v2WIqllY5IBOAMseIAK54nJ/6dalfOdYQlbk+9ndFXRGjFGNMVkw5AmPjuoyR3wN26SQnlM5WPg4SKzK4mcNI2HjuuqMj2E62y6GP20wq/xFBi+58Hu8im3QjZT27rUmoulWu75nw+dIZwRIHn6yceRAx8uvLsM1SEncNDdC0NO/Na6f1lLqBTHfBjvcyNuepg5Nc+bISvpKA== 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: On 2/17/25 19:34, Ryan Roberts wrote: > In order to fix a bug, arm64 needs to be told the size of the huge page > for which the huge_pte is being set in huge_ptep_get_and_clear(). > Provide for this by adding an `unsigned long sz` parameter to the > function. This follows the same pattern as huge_pte_clear() and > set_huge_pte_at(). > > This commit makes the required interface modifications to the core mm as > well as all arches that implement this function (arm64, loongarch, mips, > parisc, powerpc, riscv, s390, sparc). The actual arm64 bug will be fixed > in a separate commit. > > Cc: stable@vger.kernel.org > Fixes: 66b3923a1a0f ("arm64: hugetlb: add support for PTE contiguous bit") > Signed-off-by: Ryan Roberts LGTM Reviewed-by: Anshuman Khandual > --- > arch/arm64/include/asm/hugetlb.h | 4 ++-- > arch/arm64/mm/hugetlbpage.c | 8 +++++--- > arch/loongarch/include/asm/hugetlb.h | 6 ++++-- > arch/mips/include/asm/hugetlb.h | 6 ++++-- > arch/parisc/include/asm/hugetlb.h | 2 +- > arch/parisc/mm/hugetlbpage.c | 2 +- > arch/powerpc/include/asm/hugetlb.h | 6 ++++-- > arch/riscv/include/asm/hugetlb.h | 3 ++- > arch/riscv/mm/hugetlbpage.c | 2 +- > arch/s390/include/asm/hugetlb.h | 12 ++++++++---- > arch/s390/mm/hugetlbpage.c | 10 ++++++++-- > arch/sparc/include/asm/hugetlb.h | 2 +- > arch/sparc/mm/hugetlbpage.c | 2 +- > include/asm-generic/hugetlb.h | 2 +- > include/linux/hugetlb.h | 4 +++- > mm/hugetlb.c | 4 ++-- > 16 files changed, 48 insertions(+), 27 deletions(-) > > diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h > index c6dff3e69539..03db9cb21ace 100644 > --- a/arch/arm64/include/asm/hugetlb.h > +++ b/arch/arm64/include/asm/hugetlb.h > @@ -42,8 +42,8 @@ extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, > unsigned long addr, pte_t *ptep, > pte_t pte, int dirty); > #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR > -extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep); > +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, > + pte_t *ptep, unsigned long sz); > #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT > extern void huge_ptep_set_wrprotect(struct mm_struct *mm, > unsigned long addr, pte_t *ptep); > diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c > index 98a2a0e64e25..06db4649af91 100644 > --- a/arch/arm64/mm/hugetlbpage.c > +++ b/arch/arm64/mm/hugetlbpage.c > @@ -396,8 +396,8 @@ void huge_pte_clear(struct mm_struct *mm, unsigned long addr, > __pte_clear(mm, addr, ptep); > } > > -pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > +pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, > + pte_t *ptep, unsigned long sz) > { > int ncontig; > size_t pgsize; > @@ -549,6 +549,8 @@ bool __init arch_hugetlb_valid_size(unsigned long size) > > pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) > { > + unsigned long psize = huge_page_size(hstate_vma(vma)); > + > if (alternative_has_cap_unlikely(ARM64_WORKAROUND_2645198)) { > /* > * Break-before-make (BBM) is required for all user space mappings > @@ -558,7 +560,7 @@ pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, unsigned long addr > if (pte_user_exec(__ptep_get(ptep))) > return huge_ptep_clear_flush(vma, addr, ptep); > } > - return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, psize); > } > > void huge_ptep_modify_prot_commit(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, > diff --git a/arch/loongarch/include/asm/hugetlb.h b/arch/loongarch/include/asm/hugetlb.h > index c8e4057734d0..4dc4b3e04225 100644 > --- a/arch/loongarch/include/asm/hugetlb.h > +++ b/arch/loongarch/include/asm/hugetlb.h > @@ -36,7 +36,8 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, > > #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR > static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > + unsigned long addr, pte_t *ptep, > + unsigned long sz) > { > pte_t clear; > pte_t pte = ptep_get(ptep); > @@ -51,8 +52,9 @@ static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > unsigned long addr, pte_t *ptep) > { > pte_t pte; > + unsigned long sz = huge_page_size(hstate_vma(vma)); > > - pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, sz); > flush_tlb_page(vma, addr); > return pte; > } > diff --git a/arch/mips/include/asm/hugetlb.h b/arch/mips/include/asm/hugetlb.h > index d0a86ce83de9..fbc71ddcf0f6 100644 > --- a/arch/mips/include/asm/hugetlb.h > +++ b/arch/mips/include/asm/hugetlb.h > @@ -27,7 +27,8 @@ static inline int prepare_hugepage_range(struct file *file, > > #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR > static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > + unsigned long addr, pte_t *ptep, > + unsigned long sz) > { > pte_t clear; > pte_t pte = *ptep; > @@ -42,13 +43,14 @@ static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > unsigned long addr, pte_t *ptep) > { > pte_t pte; > + unsigned long sz = huge_page_size(hstate_vma(vma)); > > /* > * clear the huge pte entry firstly, so that the other smp threads will > * not get old pte entry after finishing flush_tlb_page and before > * setting new huge pte entry > */ > - pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, sz); > flush_tlb_page(vma, addr); > return pte; > } > diff --git a/arch/parisc/include/asm/hugetlb.h b/arch/parisc/include/asm/hugetlb.h > index 5b3a5429f71b..21e9ace17739 100644 > --- a/arch/parisc/include/asm/hugetlb.h > +++ b/arch/parisc/include/asm/hugetlb.h > @@ -10,7 +10,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > > #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); > + pte_t *ptep, unsigned long sz); > > #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH > static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > diff --git a/arch/parisc/mm/hugetlbpage.c b/arch/parisc/mm/hugetlbpage.c > index e9d18cf25b79..a94fe546d434 100644 > --- a/arch/parisc/mm/hugetlbpage.c > +++ b/arch/parisc/mm/hugetlbpage.c > @@ -126,7 +126,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > > > pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, > - pte_t *ptep) > + pte_t *ptep, unsigned long sz) > { > pte_t entry; > > diff --git a/arch/powerpc/include/asm/hugetlb.h b/arch/powerpc/include/asm/hugetlb.h > index dad2e7980f24..86326587e58d 100644 > --- a/arch/powerpc/include/asm/hugetlb.h > +++ b/arch/powerpc/include/asm/hugetlb.h > @@ -45,7 +45,8 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, > > #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR > static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > + unsigned long addr, pte_t *ptep, > + unsigned long sz) > { > return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1)); > } > @@ -55,8 +56,9 @@ static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > unsigned long addr, pte_t *ptep) > { > pte_t pte; > + unsigned long sz = huge_page_size(hstate_vma(vma)); > > - pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, sz); > flush_hugetlb_page(vma, addr); > return pte; > } > diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h > index faf3624d8057..446126497768 100644 > --- a/arch/riscv/include/asm/hugetlb.h > +++ b/arch/riscv/include/asm/hugetlb.h > @@ -28,7 +28,8 @@ void set_huge_pte_at(struct mm_struct *mm, > > #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); > + unsigned long addr, pte_t *ptep, > + unsigned long sz); > > #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH > pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c > index 42314f093922..b4a78a4b35cf 100644 > --- a/arch/riscv/mm/hugetlbpage.c > +++ b/arch/riscv/mm/hugetlbpage.c > @@ -293,7 +293,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, > > pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > unsigned long addr, > - pte_t *ptep) > + pte_t *ptep, unsigned long sz) > { > pte_t orig_pte = ptep_get(ptep); > int pte_num; > diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h > index 7c52acaf9f82..420c74306779 100644 > --- a/arch/s390/include/asm/hugetlb.h > +++ b/arch/s390/include/asm/hugetlb.h > @@ -26,7 +26,11 @@ void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); > > #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); > +pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > + unsigned long addr, pte_t *ptep, > + unsigned long sz); > +pte_t __huge_ptep_get_and_clear(struct mm_struct *mm, > + unsigned long addr, pte_t *ptep); > > static inline void arch_clear_hugetlb_flags(struct folio *folio) > { > @@ -48,7 +52,7 @@ static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, > static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > unsigned long address, pte_t *ptep) > { > - return huge_ptep_get_and_clear(vma->vm_mm, address, ptep); > + return __huge_ptep_get_and_clear(vma->vm_mm, address, ptep); > } > > #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS > @@ -59,7 +63,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, > int changed = !pte_same(huge_ptep_get(vma->vm_mm, addr, ptep), pte); > > if (changed) { > - huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + __huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); > } > return changed; > @@ -69,7 +73,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, > static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, > unsigned long addr, pte_t *ptep) > { > - pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep); > + pte_t pte = __huge_ptep_get_and_clear(mm, addr, ptep); > > __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); > } > diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c > index d9ce199953de..52ee8e854195 100644 > --- a/arch/s390/mm/hugetlbpage.c > +++ b/arch/s390/mm/hugetlbpage.c > @@ -188,8 +188,8 @@ pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep) > return __rste_to_pte(pte_val(*ptep)); > } > > -pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > +pte_t __huge_ptep_get_and_clear(struct mm_struct *mm, > + unsigned long addr, pte_t *ptep) > { > pte_t pte = huge_ptep_get(mm, addr, ptep); > pmd_t *pmdp = (pmd_t *) ptep; > @@ -202,6 +202,12 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > return pte; > } > > +pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > + unsigned long addr, pte_t *ptep, unsigned long sz) > +{ > + return __huge_ptep_get_and_clear(mm, addr, ptep); > +} > + > pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, > unsigned long addr, unsigned long sz) > { > diff --git a/arch/sparc/include/asm/hugetlb.h b/arch/sparc/include/asm/hugetlb.h > index c714ca6a05aa..e7a9cdd498dc 100644 > --- a/arch/sparc/include/asm/hugetlb.h > +++ b/arch/sparc/include/asm/hugetlb.h > @@ -20,7 +20,7 @@ void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > > #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); > + pte_t *ptep, unsigned long sz); > > #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH > static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, > diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c > index eee601a0d2cf..80504148d8a5 100644 > --- a/arch/sparc/mm/hugetlbpage.c > +++ b/arch/sparc/mm/hugetlbpage.c > @@ -260,7 +260,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > } > > pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, > - pte_t *ptep) > + pte_t *ptep, unsigned long sz) > { > unsigned int i, nptes, orig_shift, shift; > unsigned long size; > diff --git a/include/asm-generic/hugetlb.h b/include/asm-generic/hugetlb.h > index f42133dae68e..2afc95bf1655 100644 > --- a/include/asm-generic/hugetlb.h > +++ b/include/asm-generic/hugetlb.h > @@ -90,7 +90,7 @@ static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, > > #ifndef __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR > static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, > - unsigned long addr, pte_t *ptep) > + unsigned long addr, pte_t *ptep, unsigned long sz) > { > return ptep_get_and_clear(mm, addr, ptep); > } > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index ec8c0ccc8f95..bf5f7256bd28 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -1004,7 +1004,9 @@ static inline void hugetlb_count_sub(long l, struct mm_struct *mm) > static inline pte_t huge_ptep_modify_prot_start(struct vm_area_struct *vma, > unsigned long addr, pte_t *ptep) > { > - return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); > + unsigned long psize = huge_page_size(hstate_vma(vma)); > + > + return huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, psize); > } > #endif > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 65068671e460..de9d49e521c1 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5447,7 +5447,7 @@ static void move_huge_pte(struct vm_area_struct *vma, unsigned long old_addr, > if (src_ptl != dst_ptl) > spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING); > > - pte = huge_ptep_get_and_clear(mm, old_addr, src_pte); > + pte = huge_ptep_get_and_clear(mm, old_addr, src_pte, sz); > > if (need_clear_uffd_wp && pte_marker_uffd_wp(pte)) > huge_pte_clear(mm, new_addr, dst_pte, sz); > @@ -5622,7 +5622,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, > set_vma_resv_flags(vma, HPAGE_RESV_UNMAPPED); > } > > - pte = huge_ptep_get_and_clear(mm, address, ptep); > + pte = huge_ptep_get_and_clear(mm, address, ptep, sz); > tlb_remove_huge_tlb_entry(h, tlb, ptep, address); > if (huge_pte_dirty(pte)) > set_page_dirty(page);