diff mbox series

[v4,5/6] mm: convert copy_user_huge_page() to copy_user_folio()

Message ID 20230330134045.375163-6-zhangpeng362@huawei.com (mailing list archive)
State New
Headers show
Series userfaultfd: convert userfaultfd functions to use folios | expand

Commit Message

Peng Zhang March 30, 2023, 1:40 p.m. UTC
From: ZhangPeng <zhangpeng362@huawei.com>

Replace copy_user_huge_page() with copy_user_folio(). copy_user_folio()
does the same as copy_user_huge_page(), but takes in folios instead of
pages. Convert copy_user_gigantic_page() to take in folios.

Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
 include/linux/mm.h |  8 ++++----
 mm/hugetlb.c       | 12 ++++++------
 mm/memory.c        | 28 ++++++++++++++--------------
 3 files changed, 24 insertions(+), 24 deletions(-)

Comments

Matthew Wilcox (Oracle) March 30, 2023, 6:15 p.m. UTC | #1
On Thu, Mar 30, 2023 at 09:40:44PM +0800, Peng Zhang wrote:
> +void copy_user_folio(struct folio *dst, struct folio *src,
> +		      unsigned long addr_hint,
> +		      struct vm_area_struct *vma,
> +		      unsigned int pages_per_huge_page);

Do we really want to pass in pages_per_huge_page here?  We can get
that from folio_nr_pages(dst).

> +++ b/mm/hugetlb.c
> @@ -5097,8 +5097,8 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
>  					ret = PTR_ERR(new_folio);
>  					break;
>  				}
> -				copy_user_huge_page(&new_folio->page, ptepage, addr, dst_vma,
> -						    npages);
> +				copy_user_folio(new_folio, page_folio(ptepage), addr, dst_vma,
> +						npages);
>  				put_page(ptepage);

This function should be converted to s/ptepage/pte_folio/, but that's
not for this patch series.

> -	copy_user_huge_page(&new_folio->page, old_page, address, vma,
> -			    pages_per_huge_page(h));
> +	copy_user_folio(new_folio, page_folio(old_page), address, vma,
> +			pages_per_huge_page(h));

Likewise for s/old_page/old_folio/
Peng Zhang March 31, 2023, 9:38 a.m. UTC | #2
On 2023/3/31 2:15, Matthew Wilcox wrote:

> On Thu, Mar 30, 2023 at 09:40:44PM +0800, Peng Zhang wrote:
>> +void copy_user_folio(struct folio *dst, struct folio *src,
>> +		      unsigned long addr_hint,
>> +		      struct vm_area_struct *vma,
>> +		      unsigned int pages_per_huge_page);
> Do we really want to pass in pages_per_huge_page here?  We can get
> that from folio_nr_pages(dst).

Agreed. It's not necessary to pass in pages_per_huge_page. I'll remove
it in a v5.

>> +++ b/mm/hugetlb.c
>> @@ -5097,8 +5097,8 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
>>   					ret = PTR_ERR(new_folio);
>>   					break;
>>   				}
>> -				copy_user_huge_page(&new_folio->page, ptepage, addr, dst_vma,
>> -						    npages);
>> +				copy_user_folio(new_folio, page_folio(ptepage), addr, dst_vma,
>> +						npages);
>>   				put_page(ptepage);
> This function should be converted to s/ptepage/pte_folio/, but that's
> not for this patch series.

Appreciate your suggestion. I'll convert this function in a future patch
set.

>> -	copy_user_huge_page(&new_folio->page, old_page, address, vma,
>> -			    pages_per_huge_page(h));
>> +	copy_user_folio(new_folio, page_folio(old_page), address, vma,
>> +			pages_per_huge_page(h));
> Likewise for s/old_page/old_folio/

Will also convert this.

Best Regards,
Peng
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index cf4d773ca506..7b8fb88fb14d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3678,10 +3678,10 @@  extern const struct attribute_group memory_failure_attr_group;
 extern void clear_huge_page(struct page *page,
 			    unsigned long addr_hint,
 			    unsigned int pages_per_huge_page);
-extern void copy_user_huge_page(struct page *dst, struct page *src,
-				unsigned long addr_hint,
-				struct vm_area_struct *vma,
-				unsigned int pages_per_huge_page);
+void copy_user_folio(struct folio *dst, struct folio *src,
+		      unsigned long addr_hint,
+		      struct vm_area_struct *vma,
+		      unsigned int pages_per_huge_page);
 long copy_folio_from_user(struct folio *dst_folio,
 			   const void __user *usr_src,
 			   bool allow_pagefault);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c88f856ec2e2..fc3017a6a818 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5097,8 +5097,8 @@  int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,
 					ret = PTR_ERR(new_folio);
 					break;
 				}
-				copy_user_huge_page(&new_folio->page, ptepage, addr, dst_vma,
-						    npages);
+				copy_user_folio(new_folio, page_folio(ptepage), addr, dst_vma,
+						npages);
 				put_page(ptepage);
 
 				/* Install the new hugetlb folio if src pte stable */
@@ -5616,8 +5616,8 @@  static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma,
 		goto out_release_all;
 	}
 
-	copy_user_huge_page(&new_folio->page, old_page, address, vma,
-			    pages_per_huge_page(h));
+	copy_user_folio(new_folio, page_folio(old_page), address, vma,
+			pages_per_huge_page(h));
 	__folio_mark_uptodate(new_folio);
 
 	mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, haddr,
@@ -6260,8 +6260,8 @@  int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
 			*foliop = NULL;
 			goto out;
 		}
-		copy_user_huge_page(&folio->page, &(*foliop)->page, dst_addr, dst_vma,
-				    pages_per_huge_page(h));
+		copy_user_folio(folio, *foliop, dst_addr, dst_vma,
+				pages_per_huge_page(h));
 		folio_put(*foliop);
 		*foliop = NULL;
 	}
diff --git a/mm/memory.c b/mm/memory.c
index 9d59dad319b3..8bddbb927806 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -5801,21 +5801,21 @@  void clear_huge_page(struct page *page,
 	process_huge_page(addr_hint, pages_per_huge_page, clear_subpage, page);
 }
 
-static void copy_user_gigantic_page(struct page *dst, struct page *src,
-				    unsigned long addr,
-				    struct vm_area_struct *vma,
-				    unsigned int pages_per_huge_page)
+static void copy_user_gigantic_page(struct folio *dst, struct folio *src,
+				     unsigned long addr,
+				     struct vm_area_struct *vma,
+				     unsigned int pages_per_huge_page)
 {
 	int i;
-	struct page *dst_base = dst;
-	struct page *src_base = src;
+	struct page *dst_page;
+	struct page *src_page;
 
 	for (i = 0; i < pages_per_huge_page; i++) {
-		dst = nth_page(dst_base, i);
-		src = nth_page(src_base, i);
+		dst_page = folio_page(dst, i);
+		src_page = folio_page(src, i);
 
 		cond_resched();
-		copy_user_highpage(dst, src, addr + i*PAGE_SIZE, vma);
+		copy_user_highpage(dst_page, src_page, addr + i*PAGE_SIZE, vma);
 	}
 }
 
@@ -5833,15 +5833,15 @@  static void copy_subpage(unsigned long addr, int idx, void *arg)
 			   addr, copy_arg->vma);
 }
 
-void copy_user_huge_page(struct page *dst, struct page *src,
-			 unsigned long addr_hint, struct vm_area_struct *vma,
-			 unsigned int pages_per_huge_page)
+void copy_user_folio(struct folio *dst, struct folio *src,
+		      unsigned long addr_hint, struct vm_area_struct *vma,
+		      unsigned int pages_per_huge_page)
 {
 	unsigned long addr = addr_hint &
 		~(((unsigned long)pages_per_huge_page << PAGE_SHIFT) - 1);
 	struct copy_subpage_arg arg = {
-		.dst = dst,
-		.src = src,
+		.dst = &dst->page,
+		.src = &src->page,
 		.vma = vma,
 	};