[RFC PATCH v4 03/16] mm: Provide mm_struct and address to huge_ptep_get()

2024-05-27 Thread Christophe Leroy
On powerpc 8xx huge_ptep_get() will need to know whether the given
ptep is a PTE entry or a PMD entry. This cannot be known with the
PMD entry itself because there is no easy way to know it from the
content of the entry.

So huge_ptep_get() will need to know either the size of the page
or get the pmd.

In order to be consistent with huge_ptep_get_and_clear(), give
mm and address to huge_ptep_get().

Signed-off-by: Christophe Leroy 
---
v2: Add missing changes in arch implementations
v3: Fixed a comment in ARM and missing changes in S390
v4: Fix missing or bad changes in mm/hugetlb.c and rebased on v6.10-rc1
---
 arch/arm/include/asm/hugetlb-3level.h |  4 +--
 arch/arm64/include/asm/hugetlb.h  |  2 +-
 arch/arm64/mm/hugetlbpage.c   |  2 +-
 arch/riscv/include/asm/hugetlb.h  |  2 +-
 arch/riscv/mm/hugetlbpage.c   |  2 +-
 arch/s390/include/asm/hugetlb.h   |  4 +--
 arch/s390/mm/hugetlbpage.c|  4 +--
 fs/hugetlbfs/inode.c  |  2 +-
 fs/proc/task_mmu.c| 10 +++---
 fs/userfaultfd.c  |  2 +-
 include/asm-generic/hugetlb.h |  2 +-
 include/linux/swapops.h   |  4 +--
 mm/damon/vaddr.c  |  6 ++--
 mm/gup.c  |  2 +-
 mm/hmm.c  |  2 +-
 mm/hugetlb.c  | 44 +--
 mm/memory-failure.c   |  2 +-
 mm/mempolicy.c|  2 +-
 mm/migrate.c  |  4 +--
 mm/mincore.c  |  2 +-
 mm/userfaultfd.c  |  2 +-
 21 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/arch/arm/include/asm/hugetlb-3level.h 
b/arch/arm/include/asm/hugetlb-3level.h
index a30be5505793..87d48e2d90ad 100644
--- a/arch/arm/include/asm/hugetlb-3level.h
+++ b/arch/arm/include/asm/hugetlb-3level.h
@@ -13,12 +13,12 @@
 
 /*
  * If our huge pte is non-zero then mark the valid bit.
- * This allows pte_present(huge_ptep_get(ptep)) to return true for non-zero
+ * This allows pte_present(huge_ptep_get(mm,addr,ptep)) to return true for 
non-zero
  * ptes.
  * (The valid bit is automatically cleared by set_pte_at for PROT_NONE ptes).
  */
 #define __HAVE_ARCH_HUGE_PTEP_GET
-static inline pte_t huge_ptep_get(pte_t *ptep)
+static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, 
pte_t *ptep)
 {
pte_t retval = *ptep;
if (pte_val(retval))
diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h
index 3954cbd2ff56..293f880865e8 100644
--- a/arch/arm64/include/asm/hugetlb.h
+++ b/arch/arm64/include/asm/hugetlb.h
@@ -46,7 +46,7 @@ extern pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
 extern void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
   pte_t *ptep, unsigned long sz);
 #define __HAVE_ARCH_HUGE_PTEP_GET
-extern pte_t huge_ptep_get(pte_t *ptep);
+extern pte_t huge_ptep_get(struct mm_struct *mm, 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 3f09ac73cce3..5f1e2103888b 100644
--- a/arch/arm64/mm/hugetlbpage.c
+++ b/arch/arm64/mm/hugetlbpage.c
@@ -127,7 +127,7 @@ static inline int num_contig_ptes(unsigned long size, 
size_t *pgsize)
return contig_ptes;
 }
 
-pte_t huge_ptep_get(pte_t *ptep)
+pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 {
int ncontig, i;
size_t pgsize;
diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h
index b1ce97a9dbfc..faf3624d8057 100644
--- a/arch/riscv/include/asm/hugetlb.h
+++ b/arch/riscv/include/asm/hugetlb.h
@@ -44,7 +44,7 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma,
   pte_t pte, int dirty);
 
 #define __HAVE_ARCH_HUGE_PTEP_GET
-pte_t huge_ptep_get(pte_t *ptep);
+pte_t huge_ptep_get(struct mm_struct *mm, 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
diff --git a/arch/riscv/mm/hugetlbpage.c b/arch/riscv/mm/hugetlbpage.c
index 0ebd968b33c9..42314f093922 100644
--- a/arch/riscv/mm/hugetlbpage.c
+++ b/arch/riscv/mm/hugetlbpage.c
@@ -3,7 +3,7 @@
 #include 
 
 #ifdef CONFIG_RISCV_ISA_SVNAPOT
-pte_t huge_ptep_get(pte_t *ptep)
+pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
 {
unsigned long pte_num;
int i;
diff --git a/arch/s390/include/asm/hugetlb.h b/arch/s390/include/asm/hugetlb.h
index ce5f4fe8be4d..cf1b5d6fb1a6 100644
--- a/arch/s390/include/asm/hugetlb.h
+++ b/arch/s390/include/asm/hugetlb.h
@@ -19,7 +19,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 pte_t *ptep, pte_t pte, unsigned long sz);
 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
   

Re: [RFC PATCH v4 03/16] mm: Provide mm_struct and address to huge_ptep_get()

2024-05-27 Thread Oscar Salvador
On Mon, May 27, 2024 at 03:30:01PM +0200, Christophe Leroy wrote:
> On powerpc 8xx huge_ptep_get() will need to know whether the given
> ptep is a PTE entry or a PMD entry. This cannot be known with the
> PMD entry itself because there is no easy way to know it from the
> content of the entry.
> 
> So huge_ptep_get() will need to know either the size of the page
> or get the pmd.
> 
> In order to be consistent with huge_ptep_get_and_clear(), give
> mm and address to huge_ptep_get().
> 
> Signed-off-by: Christophe Leroy 

Reviewed-by: Oscar Salvador 

 

-- 
Oscar Salvador
SUSE Labs


Re: [RFC PATCH v4 03/16] mm: Provide mm_struct and address to huge_ptep_get()

2024-05-27 Thread Oscar Salvador
On Mon, May 27, 2024 at 03:30:01PM +0200, Christophe Leroy wrote:
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -547,7 +547,7 @@ static int gup_hugepte(struct vm_area_struct *vma, pte_t 
> *ptep, unsigned long sz
>   if (pte_end < end)
>   end = pte_end;
>  
> - pte = huge_ptep_get(ptep);
> + pte = huge_ptep_get(vma->mm, addr, ptep);

I looked again and I stumbled upon this.
It should have been "vma->vm_mm".

 

-- 
Oscar Salvador
SUSE Labs


Re: [RFC PATCH v4 03/16] mm: Provide mm_struct and address to huge_ptep_get()

2024-05-28 Thread Christophe Leroy


Le 28/05/2024 à 07:41, Oscar Salvador a écrit :
> On Mon, May 27, 2024 at 03:30:01PM +0200, Christophe Leroy wrote:
>> --- a/mm/gup.c
>> +++ b/mm/gup.c
>> @@ -547,7 +547,7 @@ static int gup_hugepte(struct vm_area_struct *vma, pte_t 
>> *ptep, unsigned long sz
>>  if (pte_end < end)
>>  end = pte_end;
>>   
>> -pte = huge_ptep_get(ptep);
>> +pte = huge_ptep_get(vma->mm, addr, ptep);
> 
> I looked again and I stumbled upon this.
> It should have been "vma->vm_mm".

Oops ... Thanks for seeing that. As it goes away at the end it went 
unnoticed by builds.

Christophe