From: Sidhartha Kumar <sidhartha.kumar@oracle.com>
To: Peng Zhang <zhangpeng362@huawei.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
akpm@linux-foundation.org, willy@infradead.org,
mike.kravetz@oracle.com
Cc: vishal.moola@gmail.com, muchun.song@linux.dev,
wangkefeng.wang@huawei.com, sunnanyong@huawei.com
Subject: Re: [PATCH v4 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio
Date: Thu, 30 Mar 2023 10:29:12 -0700 [thread overview]
Message-ID: <b61bcd10-df14-ff01-bae1-f4b99a8b97e2@oracle.com> (raw)
In-Reply-To: <20230330134045.375163-5-zhangpeng362@huawei.com>
On 3/30/23 6:40 AM, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
>
> Convert hugetlb_mfill_atomic_pte() to take in a folio pointer instead of
> a page pointer. Convert mfill_atomic_hugetlb() to use a folio.
>
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
> ---
> include/linux/hugetlb.h | 4 ++--
> mm/hugetlb.c | 26 +++++++++++++-------------
> mm/userfaultfd.c | 16 ++++++++--------
> 3 files changed, 23 insertions(+), 23 deletions(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 2a758bcd6719..28703fe22386 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -163,7 +163,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
> unsigned long dst_addr,
> unsigned long src_addr,
> uffd_flags_t flags,
> - struct page **pagep);
> + struct folio **foliop);
> #endif /* CONFIG_USERFAULTFD */
> bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
> struct vm_area_struct *vma,
> @@ -397,7 +397,7 @@ static inline int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
> unsigned long dst_addr,
> unsigned long src_addr,
> uffd_flags_t flags,
> - struct page **pagep)
> + struct folio **foliop)
> {
> BUG();
> return 0;
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index aade1b513474..c88f856ec2e2 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6178,7 +6178,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
> unsigned long dst_addr,
> unsigned long src_addr,
> uffd_flags_t flags,
> - struct page **pagep)
> + struct folio **foliop)
> {
> struct mm_struct *dst_mm = dst_vma->vm_mm;
> bool is_continue = uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE);
> @@ -6201,8 +6201,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
> if (IS_ERR(folio))
> goto out;
> folio_in_pagecache = true;
> - } else if (!*pagep) {
> - /* If a page already exists, then it's UFFDIO_COPY for
> + } else if (!*foliop) {
> + /* If a folio already exists, then it's UFFDIO_COPY for
> * a non-missing case. Return -EEXIST.
> */
> if (vm_shared &&
> @@ -6237,33 +6237,33 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte,
> ret = -ENOMEM;
> goto out;
> }
> - *pagep = &folio->page;
> - /* Set the outparam pagep and return to the caller to
> + *foliop = folio;
> + /* Set the outparam foliop and return to the caller to
> * copy the contents outside the lock. Don't free the
> - * page.
> + * folio.
> */
> goto out;
> }
> } else {
> if (vm_shared &&
> hugetlbfs_pagecache_present(h, dst_vma, dst_addr)) {
> - put_page(*pagep);
> + folio_put(*foliop);
> ret = -EEXIST;
> - *pagep = NULL;
> + *foliop = NULL;
> goto out;
> }
>
> folio = alloc_hugetlb_folio(dst_vma, dst_addr, 0);
> if (IS_ERR(folio)) {
> - put_page(*pagep);
> + folio_put(*foliop);
> ret = -ENOMEM;
> - *pagep = NULL;
> + *foliop = NULL;
> goto out;
> }
> - copy_user_huge_page(&folio->page, *pagep, dst_addr, dst_vma,
> + copy_user_huge_page(&folio->page, &(*foliop)->page, dst_addr, dst_vma,
> pages_per_huge_page(h));
> - put_page(*pagep);
> - *pagep = NULL;
> + folio_put(*foliop);
> + *foliop = NULL;
> }
>
> /*
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index b453a4d2a0d3..9e95af5ce2dd 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -322,7 +322,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
> pte_t *dst_pte;
> unsigned long src_addr, dst_addr;
> long copied;
> - struct page *page;
> + struct folio *folio;
> unsigned long vma_hpagesize;
> pgoff_t idx;
> u32 hash;
> @@ -342,7 +342,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
> src_addr = src_start;
> dst_addr = dst_start;
> copied = 0;
> - page = NULL;
> + folio = NULL;
> vma_hpagesize = vma_kernel_pagesize(dst_vma);
>
> /*
> @@ -411,7 +411,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
> }
>
> err = hugetlb_mfill_atomic_pte(dst_pte, dst_vma, dst_addr,
> - src_addr, flags, &page);
> + src_addr, flags, &folio);
>
> hugetlb_vma_unlock_read(dst_vma);
> mutex_unlock(&hugetlb_fault_mutex_table[hash]);
> @@ -420,9 +420,9 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
>
> if (unlikely(err == -ENOENT)) {
> mmap_read_unlock(dst_mm);
> - BUG_ON(!page);
> + BUG_ON(!folio);
>
> - err = copy_folio_from_user(page_folio(page),
> + err = copy_folio_from_user(folio,
> (const void __user *)src_addr, true);
> if (unlikely(err)) {
> err = -EFAULT;
> @@ -433,7 +433,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
> dst_vma = NULL;
> goto retry;
> } else
> - BUG_ON(page);
> + BUG_ON(folio);
>
> if (!err) {
> dst_addr += vma_hpagesize;
> @@ -450,8 +450,8 @@ static __always_inline ssize_t mfill_atomic_hugetlb(
> out_unlock:
> mmap_read_unlock(dst_mm);
> out:
> - if (page)
> - put_page(page);
> + if (folio)
> + folio_put(folio);
> BUG_ON(copied < 0);
> BUG_ON(err > 0);
> BUG_ON(!copied && !err);
Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
next prev parent reply other threads:[~2023-03-30 17:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 13:40 [PATCH v4 0/6] userfaultfd: convert userfaultfd functions to use folios Peng Zhang
2023-03-30 13:40 ` [PATCH v4 1/6] userfaultfd: convert mfill_atomic_pte_copy() to use a folio Peng Zhang
2023-03-30 17:02 ` Sidhartha Kumar
2023-03-30 18:02 ` Matthew Wilcox
2023-03-31 9:38 ` zhangpeng (AS)
2023-04-06 21:28 ` Mike Kravetz
2023-03-30 13:40 ` [PATCH v4 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Peng Zhang
2023-03-30 13:40 ` [PATCH v4 3/6] userfaultfd: convert copy_huge_page_from_user() to copy_folio_from_user() Peng Zhang
2023-03-30 17:18 ` Sidhartha Kumar
2023-03-30 13:40 ` [PATCH v4 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio Peng Zhang
2023-03-30 17:29 ` Sidhartha Kumar [this message]
2023-03-30 13:40 ` [PATCH v4 5/6] mm: convert copy_user_huge_page() to copy_user_folio() Peng Zhang
2023-03-30 18:15 ` Matthew Wilcox
2023-03-31 9:38 ` zhangpeng (AS)
2023-03-30 13:40 ` [PATCH v4 6/6] userfaultfd: convert mfill_atomic() to use a folio Peng Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b61bcd10-df14-ff01-bae1-f4b99a8b97e2@oracle.com \
--to=sidhartha.kumar@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=sunnanyong@huawei.com \
--cc=vishal.moola@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=zhangpeng362@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox