From patchwork Fri Mar 31 09:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13195697 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 15676C6FD18 for ; Fri, 31 Mar 2023 09:42:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90CFC6B0075; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FBDF6B007E; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 478D96B0075; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1ED516B0075 for ; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CE006A0BF3 for ; Fri, 31 Mar 2023 09:41:57 +0000 (UTC) X-FDA: 80628701874.25.8B88EB6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id 3D58AA0006 for ; Fri, 31 Mar 2023 09:41:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680255716; 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=wjM9v9DmPjqcb1rvsoROD4mNe+7gy3iYv0sgFdjl6Tc=; b=ml9IBSGYX5IvzQ/CrR2L0SNwKRE8+Tdv4xUSv5cSdEPNqvr1wms7OWOJgWYEUqeXRu+dd/ BnUyoV50I6vtFsB1Xclw1o9ySZNfrcyERNXBcC9/i7PrkbXAVej81vpuuUK6WyUXDHTwig rKMywaTm7LnJUD4c6i0wlQFdOtvaixM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680255716; a=rsa-sha256; cv=none; b=D85E5/vS4uJpYWl0JLTIPQTAX/h55N236ju1idDfRRs7+elyyPC3sGtvzyqQ5EoxMMQxU3 9WLlJpHBdn8jEGmcBQQ3eMw4mhD7WtUNKKpDrgh8/tlEETV2xym5D0F5oGLOrtugqgCKwZ NzsQKy+YdLpYftfMm/TUGLsIR4F7g/o= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PnwFd1ww7zSpwm; Fri, 31 Mar 2023 17:38:13 +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; Fri, 31 Mar 2023 17:41:51 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio Date: Fri, 31 Mar 2023 17:39:35 +0800 Message-ID: <20230331093937.945725-5-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230331093937.945725-1-zhangpeng362@huawei.com> References: <20230331093937.945725-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3D58AA0006 X-Stat-Signature: qwec5jakqquc463fwfpobxoiefqkosk3 X-Rspam-User: X-HE-Tag: 1680255714-231813 X-HE-Meta: U2FsdGVkX183xcg5Qnn+Bx1M5kCGKGYGvSuRkOsCdrMgGF9HPT7n1h6GRhgzZ1o7D9nsCtZUDVwd6MWDcUcA0tfg9vtC1MZIE9TM2drEA73BVZbB+DZ4WMa8R1Mta1MUMwqz9hQf8bzA0bn+VXt85NAYzwKjKzphrRXade73lOpg10sv/bKs/Qu6d8s3CQ2VaMYn0pm+al6g15coz2nzWKF5kpMthNFGsT7+yzSloRZnMjpcj4pWoIXJGKqP1YLFUmt52fM7XYX35TSLEBlkbs9xSYCbLjy6M1bHX6jR26JOa/8S8UWBlltulX2+inN16ufhF2HIgDTsMEQeN9ak6McB804j1FvSlVxF9z3FTaMRTGHr/pfUQdJDOXbb6TSHL3DXGEwvNCeijCRSp2Z15ohBhiuVG9kEBKFGVXfWvHheQW9cVcHG5jaRjmUJ6sB3h/OISJwGLAFeb5Nh76i0UjIOpjWuxrJwoGUyFmVyMUbi6bCI5fzGaZuASob3hs9ke+bA2h68SyqOP3fuyjRrdvY2IuGuZxqUxFMR214UlpG5HdbxZrfABASM5RddQ2u9q+g+vyPIcxXV1G0uBMV7UWwlojMcT5mkga/wBijECL3hP22kJ9NddgaSK3fzXb5Iq8LR3W6r+Bo//D7/m2OXh5cnHyJI3OprnwEbQgMV9qfwVVnXjuuR1C7Lhoq8CdMGWV0pbhi0gpZ9mB1rffqMiPu8C2yg1rcwKMT3DanJr1kdB23E8i3wMnCNLvswA8BEN7u+VJ/GMJ1/dRu/N/lvz6/LqNejSY7jLRYfEqcVuLNT9fzhVKDuXqS+cJ79j0wO90OC8/NEuoU/o5cYnJ93eE58ZgMpezQy9AubuV72LGbBoZmEZ1SU1rTxRGtQ84hjDV5b4+/ADZdZ+pmRO/eoA7VyIHAg+qRrPUCGJTexvY/NB53KgDhTg09A1gsT/KTzJnRyMNmVdP0Eo+s8l4v g5ndDGgs pzMqkWU3WvnPRw+i7oEsiGfBfgDalEuRqsL0yiTSwcJRtK12SH4yJsYKtsNapmTnJB2Z4nFIlvcE52zxeTr0j75bgoblJcAVxP+MsI/cvrboUS2oCN0LPV9m76u5qWjabfcInbCOmit3SWBC84zVelaPO8iHv9w81sKwxUau913/uuKFJdyUb7yjq4fq6ARQZeJCBewWvr70tpz6cs0ZxKnT2iaKP3Vv8MlMUosNsGjjuV7l417VTqIufjZiNJaw8/6zR6sDL5sSstLx8276L4772SvxbPHP+btXgCV6UaOGbx+w63XpwzKZYKA== 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 Reviewed-by: Mike Kravetz --- 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 78fed9003cf7..f9ebaa079a6a 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);