From patchwork Mon Apr 10 13:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13206369 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 8BE12C77B74 for ; Mon, 10 Apr 2023 13:39:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17FB728001B; Mon, 10 Apr 2023 09:39:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 16FEF28001D; Mon, 10 Apr 2023 09:39:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB1CE28001B; Mon, 10 Apr 2023 09:39:52 -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 B3CE1280002 for ; Mon, 10 Apr 2023 09:39:52 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6B68BABFDC for ; Mon, 10 Apr 2023 13:39:52 +0000 (UTC) X-FDA: 80665589424.05.1863293 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id B765540019 for ; Mon, 10 Apr 2023 13:39:49 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.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=1681133990; 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=VFoMYpFH2wUs0f4x/CnJhQPG8lKfFZPCXDfKFh8biu0=; b=m812Ywg0CwI23gb1+AQwMybbYPWSqC9F27Hp/6vD2UQTh6w4DcCEGPMuxk/mMR+sc9WjHb k/UWitoRXGsLI4mDpZmu4FCS7fLkvyiTUDNeLOU4iKnah0Er7uYeqhuAKH7nsMDAyH42+N fGQK+4NHUkQWcDDb+r2oqsoCZN1E3xc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf04.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=1681133990; a=rsa-sha256; cv=none; b=sOVEIBVHfy4T3bfWhamDfsH/cYQaJh5kABclhO17dspri8AxIVB+ghNmZ1w011FDoEojtl PfNOf9vhkrt8H5hlrdQYxwQs+84gGeIiJkQCNp9WX5NhO7hIlgAc4CMCv1g9cwNsDr//zb xnX+fvNDjpBLlDr+9OgNoaawe43ksa8= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pw94l0JW4zKxpD; Mon, 10 Apr 2023 21:37:11 +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.23; Mon, 10 Apr 2023 21:39:42 +0800 From: Peng Zhang To: , , , , , , CC: , , , ZhangPeng Subject: [PATCH v6 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio Date: Mon, 10 Apr 2023 21:39:30 +0800 Message-ID: <20230410133932.32288-5-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410133932.32288-1-zhangpeng362@huawei.com> References: <20230410133932.32288-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B765540019 X-Stat-Signature: k7ie969r1pcpthp3bwwzk5xgd43ggbgx X-Rspam-User: X-HE-Tag: 1681133989-427800 X-HE-Meta: U2FsdGVkX19xYtAtzykWD/Ezh4xxrcS6f5mBuOaFMXhdQPc76wWw6Udybk5DptisRO/48K3oeGfybHLb+6ip9p4chcaDUdRHRGYzU6yG6JGlAGac00/meVBszaXbptn5AUy0RPwG/87pKd6r0A1A+3U6CEpHMXB7n0B3C7g0tl5th99yNvQU0O6V0RZy2oIVeDjO6IzeCs6H51NA1Ito5FO8cSvqLZNEERId5/jCqN71satUZ9lFoBLMKkACnub+RBIi3yH6ZoObOTDbuPS3BFICmVhhGYN0jhqTK0D/qEAe1R+BLWYaRfdublXnpt587mxGHebk9bVGR+WidQjKWuxTxkZIQyyjunMBtxwImFqmEEDF6I3DoIpDH7s8sbshmk2Fiz73EZkouuMeAID/z/2QzdNDB/6Ua6Skzvei21NzVljcJkBkPnT/Bpj3PF1zKpYcrL/gozctrRr7wRrXuXXsZqSOfYLXFu+cT/up+t9n682RkUaK0hTBYuboRXH4z0vJ0WE6U+ontnQuYPR7uNnZydKxb/j2rRxtouWW9ARZBcvWtcKXqap6fspan6WjJXnWEAUkslFrx0WeAWMt46MiGgfi+LKmTs7Dq+YsYozlN8P6dBnjHI7GqvLGUYCIonJPMMXvE55vk6z/vJTgjhx5YQxY89jhnM3V6wSTE7Law2Tk/4DD53nA5RuTHbUxFlRN0q6TaRVnJwcLRtq8lBP9DY7G9pt5L8Baum/JVrafZLS7SF+0y3gEoR2FU12zGG2xIGxILbJyQWjeTOclDzN1BvvxaB629mF7RPB55pAxYV7J3oC3afrED8pRKug915eBGr2hWOdEDR6RRRlppJMzTzN6FE8ccburFdypx+xb/ELUlz/b815wDEWQ3r4/JNcSfBy8NP7qJmRBd5RhibDKzIqPhb+aMYVFyeaNPTX7IamDfUdYlx2u8PotU2LNiOLnR6gfZ/VKXN12qZ1 RFF4Ggl4 Lx6hJ8bq/Elr/rIPkUWPAbLgJKh+YnyT6yeXclX7pJ/dVws3FO5LLxfouFN4f3oX3FRDCJwe5SiSCZJvaBD4/nezCtmiuu3NBPqrfR2WOJxu1eOg2efVhvEJdVoRmFWhwTsH5uqoU22jGY6vE7ncNrJnI4B6CMlq+KFp1Vks6TjTFTo7jL1M76XSdDN3sPzTxqPWIISlJZEoIuCTfWfPDsuArljyElDB+pmI9nKpDm+N00wiZVpBMlGzKpFT016w6ewXhWe8/PgIPCrMKm6TvNCdw91J9auy3gGsk6OtwEpUJRniWrcAOxYpmiQ== 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 1e7dba6c4c5f..2f263afb823d 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -321,7 +321,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; @@ -341,7 +341,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); /* @@ -410,7 +410,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]); @@ -419,9 +419,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; @@ -432,7 +432,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; @@ -449,8 +449,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);