From patchwork Thu Mar 30 13:40:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13194193 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 B7769C6FD1D for ; Thu, 30 Mar 2023 13:41:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25893900004; Thu, 30 Mar 2023 09:41:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 209B7900002; Thu, 30 Mar 2023 09:41:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05BF7900004; Thu, 30 Mar 2023 09:41:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D8B8F900002 for ; Thu, 30 Mar 2023 09:41:41 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AE2D740F3F for ; Thu, 30 Mar 2023 13:41:41 +0000 (UTC) X-FDA: 80625677202.02.5859ECA Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf20.hostedemail.com (Postfix) with ESMTP id C8A051C001A for ; Thu, 30 Mar 2023 13:41:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680183699; 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=CZNHzSt0tHTjqMCHSS9dyn9pURJtyKXkj/QjHG9AFDE=; b=jALVhDYCEcnUqdEEDbQqAlXInsFBicKBNsWQ2cMKnlkwCA9g5Uz4rmTBt0szQm5HU5M0W/ HWJzNPWoer6qW6stiwIafY9eOikHJIqUIy+qSU3a96aHE/hYf8jX2Xb533uVjVWhwL9tcM TMKIBji0O0B4BYbULDvcUcyTPwTFLTo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680183699; a=rsa-sha256; cv=none; b=BTGR6BApSIOpuESJJ3ogWmPRLeYsuvK1ZGbepwjECtaYoBluA4pV2hsT2IbzNe3/Q6aCSS WOupA4QqlfDBYjr5fjykvoeZJCZ1fpXC9Ut27LbbuyyBd3k/Asv60zvi3undateKuhbCH+ ukgSLVMEwJVIPO+XiN9j+F99JWRARl8= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PnPf41JkyzKwBL; Thu, 30 Mar 2023 21:39:08 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 21:41:31 +0800 From: Peng Zhang To: , , , , CC: , , , , , ZhangPeng Subject: [PATCH v4 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio Date: Thu, 30 Mar 2023 21:40:43 +0800 Message-ID: <20230330134045.375163-5-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330134045.375163-1-zhangpeng362@huawei.com> References: <20230330134045.375163-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Stat-Signature: fu8b4uyh88j9zs3tqaiqkh4oeoti4uam X-Rspam-User: X-Rspamd-Queue-Id: C8A051C001A X-Rspamd-Server: rspam06 X-HE-Tag: 1680183698-593148 X-HE-Meta: U2FsdGVkX1+GIVGep+JJE9O67cz5krNI14gMo+MFBZF9V5s2H89dR/F9ekII2jDYBU0vKTRVLqaDvs5O2wyQKSTxkgGLfiiKwoqv1+NTDvK2F+G3UW7RQt3PBY82bmq3KAbfmYJ2jXrgx0KR9lNMPprQpuMyMqb5RQOo1oZ7IgkzaN6LRIf3Yp+JjrqGvcBSWzXub7h/u9JUQ5S2rDrH9TvOjWpiPfFgjR3HtI940dI21+AG20u1cHF9fUxPpuUoObC4+hNb4KoHgCmuncXOS0bs4O/BmZciQ8fAq0HwgkaO20MWdnT2v3Ptkky6jIpm9l7iX5W5/62nfC2OwAcy2V74VfVLR81qiIleW2jMeYhor/Os3i6HTdKJdUnMz88l27Cao4/m+YK2992OXtcgxZEg08FNDoAe9EJ1h/KcfdPPaBrNtOjMdJ4PwblYVJDnx8BQc3wu/JnWPPDNd+ENMRHl/9Zer7glEgYGBonhO9g9s3AJUKXL9HoHjP6IaSqFwJkRDLghtY0A/IhZlAXaNznEjYTr//020jRIsSwjG75spuGgYMM8wXUVk4sXSv7ZLrQbp4ySJACLOQw0lm5SO3VvRf5wD/PiF4Qan6o5qwnc9P2eqTt9KFtGrt7ZsCBxLZbOqFRrApC9W2q3V4PeTTrrxLZN4erLywHdg5cyTu9UhWHXrlcE4u9gkiRDq1VsCByr1TnudF2qXio1kK1hRoGxMOXdohQPZkePnKUboNdbJPy4wEt4ooGy9WaR5uSB/QXaqknCcm+mLEBkZ3FxOPIZGWo6G5Zm3FKFxLaCabDmpd3kP35mkRlRkeNYvFJtVht1JDBH5e1BGRYhRX6G/+EDhViz81HgaDzdvJg64o5HNwnjbgEya7I8A+PvymhC3TD9yRJvXDIPaNPZOERhGxz3xJB0TYPVjVVeDnqFQNkT1cLR85joSRxs/i6pgdwMCEmwu5WM60Dhf0UwQQh 0PEnfrMI THCis3G2mXIDHcHu6d2U6Li0eSN7NtwAmTfKcCp/sEUPNHIVugh/tYEpdDBNlpeBrC+rf3R58YcgXdVhfTzmczDbT1Zy+LD36TGFf227O8SLpdhHyxn522Wva2+G7Zws8VFa1r47xG9E0El3gmevAJ2b8RJ+MSHYj+7cFdnDRE6gqYvdDHE8BZqkct50pIBluiU0fwINLjFUNlexKk/ogBqEQDFNAzebC/WfEN0d6H/LbDbPOT4N46uwqiuk+IoV+nRw4rCoBCiGNLPeBebeAJweqQiEOQdnixwtm 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: From: ZhangPeng 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 Reviewed-by: Sidhartha Kumar --- 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);