From patchwork Tue Mar 14 03:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13173596 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 C2553C7618B for ; Tue, 14 Mar 2023 03:38:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DB346B0074; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73D6E6B0075; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5419C6B0078; Mon, 13 Mar 2023 23:38:32 -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 357696B0074 for ; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8752B1C65A1 for ; Tue, 14 Mar 2023 03:38:31 +0000 (UTC) X-FDA: 80566096422.11.B3E4505 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf09.hostedemail.com (Postfix) with ESMTP id 5725A140013 for ; Tue, 14 Mar 2023 03:38:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 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=1678765108; 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=nbkREkUXjavMZLWrcbnXqcI0k9zEMdNai8bCnP1WlF0=; b=6oJMzVG7P+5+cxUdC4PKSyl6xRdo3Fq/TYwlZgYEA8rD9saJ1ui9dkHz+eoYcrrjcM7MmR LT7ghXzGa+3hBkrLPT3UhkhFTnX0LaBLmS41BkEsAng0silUtp/CMTZy2GzfX8kl3Z9mRU eNf/o5GYars4gn1TrWdSqdIg0G6cyFU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678765108; a=rsa-sha256; cv=none; b=VaWGYLWQojSCGlDQla8li6nbjpqW7/dRtvlB1qVtni68mF8Fr3DGZPiBMg/Jt+aZ/DXr2M 9/Z394CxdZYEcwN1tF0Mk+2zFPnQ2Yf4oGcM4W+t7s4yr2NBTkbeyiqctKVx+ZHx3Ci/Op PBsli7KS+UstW7DJ2b+wNKn7+7QDLJM= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PbK0r66w0znXQk; Tue, 14 Mar 2023 11:35:24 +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; Tue, 14 Mar 2023 11:38:20 +0800 From: Peng Zhang To: , CC: , , , , , , , ZhangPeng Subject: [PATCH 1/3] userfaultfd: convert mcopy_atomic_pte() to use a folio Date: Tue, 14 Mar 2023 03:37:32 +0000 Message-ID: <20230314033734.481904-2-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314033734.481904-1-zhangpeng362@huawei.com> References: <20230314033734.481904-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 5725A140013 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 47dcg3iyitsq6bijpe7ygnr5kuo4a4f4 X-HE-Tag: 1678765106-135382 X-HE-Meta: U2FsdGVkX1/5cZMmXlYfpyJdp2zvSa/gDvj+baWptJSuKt4fPrntwU2hXW18JSQfasyia/nChV0M39atO0zPKJKuZW9EI9K0wQIqvw52kcyGFBT43pY03salgxhBftZVrDhH5lSo7efwSNEHwreo4KBnCBpuVomKv22BQSCvO5+2vk1gdBEemB8PZUTM9LnW6PTofkdMAHyDXSfcH697VyF6BSZkmXUzvLoHMY2T7c24dBLQnFPuG3BWYy5AJSFUGvZP3ELWHAEFlICWM4NH9IfeVMEJzrbqXG1HgrrZZPr6HHRiri33HVlzwaaGqDaXKO8DR5WXFDVgmnaRcATMthiK0/YwwQthNOsY4ernt34uj3841ML/Bnk22LSdwJK/KygkhEYi/Ay7yKigvXkQoVQSYnuj0wRajd5Q/3ct0J9/EB+MNgPcFUNHtkbx68sljw8/vclggNfIECuyq5qo8iS/4RMv1GsnIoB4mZtEfWr+sqMtyeips65hjYuhdP7AlBUJUr9f30Sirz+FYt8Lrf1GBbxJ1JnIiGA4M3KfYaMAgrnUek2JKgdjNJh18E9bswQ+SF7l9YLC8QxK75s8aCXGxC38xVDlIs83BaDRMCQzIKjKMc1USsn1WwswKlt1zfMRF4mJTOlRAfVjo3pR10+Se7HeL7a9mxpAYhSGDAsLdYZ5+M08somRJCHuNF6qdtkad26C/XPlbRoP4PaVNvhcPvMMjLDJ0Blz8waSt90INFxe81qgE9vaGnX6N9R0sE31fkXLTjk4SbNwIo9w9YBF45c+samCYTOSi/0ro4qemqTE6zb1KFjhPyR1G7REO+dx7q/LDuiygd7nkad9Bs4lEx7wDNRCzUmVNRLe83eGKOt7dkiUv9+r+yX8+w9wL8tSL5JwYyXNu4dYohviRhXCdLfBGUmauk4owrMrqIKEWGU4oFLegaOpJSIbVub1wXswHs2KazNhn7V1/xs DBAbLzcf ZbF/kMzfEj0jgy8FT1i3ISEG5+0zOaLCXOpAqlZOfZwT6W4+oVg8USkh7Im85sL2fR26+zJiBp3DhvlI40yAivsQFWYDPK6WHAJKyTO0+iVGb0weUiPQ/e4NZrln8rnpDRa+8Ch704uAxvh75WZmLJZnr0MJMO5WMTU1s8svb9fPU/iS9BPnPbANkP3CtVs84EGXXfGQebn3DSc6vfnicPHGcLJwX9+i2pDX9O4LsD8t3fxODSm1KfCLCRz5O9ii+wT7N1VZ7fcBPBHY31Namcl0kxw== 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 Call vma_alloc_folio() directly instead of alloc_page_vma(). Add an assertion that this is a single-page folio and removes several calls to compound_head(). Signed-off-by: ZhangPeng --- mm/userfaultfd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 53c3d916ff66..263191c37fb5 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -137,15 +137,15 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, { void *page_kaddr; int ret; - struct page *page; + struct folio *folio; if (!*pagep) { ret = -ENOMEM; - page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, dst_vma, dst_addr); - if (!page) + folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, dst_vma, dst_addr, false); + if (!folio) goto out; - page_kaddr = kmap_local_page(page); + page_kaddr = kmap_local_folio(folio, 0); /* * The read mmap_lock is held here. Despite the * mmap_lock being read recursive a deadlock is still @@ -171,36 +171,37 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, /* fallback to copy_from_user outside mmap_lock */ if (unlikely(ret)) { ret = -ENOENT; - *pagep = page; + *pagep = &folio->page; /* don't free the page */ goto out; } - flush_dcache_page(page); + flush_dcache_folio(folio); } else { - page = *pagep; + folio = page_folio(*pagep); + VM_BUG_ON_FOLIO(folio_test_large(folio), folio); *pagep = NULL; } /* - * The memory barrier inside __SetPageUptodate makes sure that + * The memory barrier inside __folio_mark_uptodate makes sure that * preceding stores to the page contents become visible before * the set_pte_at() write. */ - __SetPageUptodate(page); + __folio_mark_uptodate(folio); ret = -ENOMEM; - if (mem_cgroup_charge(page_folio(page), dst_mm, GFP_KERNEL)) + if (mem_cgroup_charge(folio, dst_mm, GFP_KERNEL)) goto out_release; ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, - page, true, wp_copy); + &folio->page, true, wp_copy); if (ret) goto out_release; out: return ret; out_release: - put_page(page); + folio_put(folio); goto out; } From patchwork Tue Mar 14 03:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13173595 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 CD487C74A5B for ; Tue, 14 Mar 2023 03:38:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AF6A6B0072; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9385E6B0075; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62B876B0074; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 48EEF6B0072 for ; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 08596120C98 for ; Tue, 14 Mar 2023 03:38:31 +0000 (UTC) X-FDA: 80566096422.07.A40853D Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id 880DB40004 for ; Tue, 14 Mar 2023 03:38:28 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1678765109; 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=yWY1QIytE+V7prnHucih0lXV3rPUi7yY/plyFQgEOmw=; b=qASwiFbMj8mYBXuadaufSojjGtENJFFjoA7MfJNvYT1BwoFU9AWZD9cbg31kP6Odvi7qzY dlUNjYA6VWYszBSIgCrKoX3u8ZcX2/xuerZ4+PVQk+r9PKcZVcwq2JcjU7HIO0I74EoEJB W48N988FviU9uem/8RiPyrMFEomU7UE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1678765109; a=rsa-sha256; cv=none; b=bGusWm0y2rs0ujJb6CdDI+YiRaTSavGYVsCl5aFRXwoyqx9SGbchFIsLD4zGeHo8q4yqwa FfGj/0yvBZySkWUmiUg3BHkMtHu+yXUhs/YI+7NCfMwasfz6TrrJ2lOkUm1LTiVdGFeOcN rtqMP4L9e6WpAiv7hllNRI91pcfGRuE= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PbK1l5Yc8zHx5T; Tue, 14 Mar 2023 11:36: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.21; Tue, 14 Mar 2023 11:38:21 +0800 From: Peng Zhang To: , CC: , , , , , , , ZhangPeng Subject: [PATCH 2/3] userfaultfd: convert __mcopy_atomic_hugetlb() to use a folio Date: Tue, 14 Mar 2023 03:37:33 +0000 Message-ID: <20230314033734.481904-3-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314033734.481904-1-zhangpeng362@huawei.com> References: <20230314033734.481904-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 880DB40004 X-Stat-Signature: j33owmxfkcd4jaaupz1rsyy8xpi1pdyo X-Rspam-User: X-HE-Tag: 1678765108-568897 X-HE-Meta: U2FsdGVkX1+pb0JgFHpXfgCHGT3Sz2SXCjuWrdq+LKvdgHVpVEIX600cRXexNQyUTE02hzf+vfWTtVxLhD8Lu9ItSfv2YvqFAlNg4+ikPJ2puizhUJOecfSM1TOQ0CwZZerCNmxLfJcws5Y9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QD3CDGdq5yqaq7C7vtSPOTWTRLR+oeU1Q5Lxk0oWFxy59MAHaE3P5Wl 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 Change copy_huge_page_from_user() to copy_large_folio_from_user(). Convert hugetlb_mcopy_atomic_pte() and __mcopy_atomic_hugetlb() to use a folio. Signed-off-by: ZhangPeng --- include/linux/hugetlb.h | 4 ++-- include/linux/mm.h | 3 +-- mm/hugetlb.c | 25 ++++++++++++------------- mm/memory.c | 18 ++++++++++-------- mm/userfaultfd.c | 20 +++++++++----------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 7c977d234aba..030252ce51bd 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -163,7 +163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy); #endif /* CONFIG_USERFAULTFD */ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, @@ -399,7 +399,7 @@ static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { BUG(); diff --git a/include/linux/mm.h b/include/linux/mm.h index 1f79667824eb..5eff770adbaa 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3546,9 +3546,8 @@ 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); -extern long copy_huge_page_from_user(struct page *dst_page, +extern long copy_large_folio_from_user(struct folio *dst_folio, const void __user *usr_src, - unsigned int pages_per_huge_page, bool allow_pagefault); /** diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 07abcb6eb203..20ce2b4e32b1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6163,7 +6163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { bool is_continue = (mode == MCOPY_ATOMIC_CONTINUE); @@ -6185,7 +6185,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, if (!folio) goto out; folio_in_pagecache = true; - } else if (!*pagep) { + } else if (!*foliop) { /* If a page already exists, then it's UFFDIO_COPY for * a non-missing case. Return -EEXIST. */ @@ -6201,9 +6201,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out; } - ret = copy_huge_page_from_user(&folio->page, - (const void __user *) src_addr, - pages_per_huge_page(h), false); + ret = copy_large_folio_from_user(folio, + (const void __user *) src_addr, false); /* fallback to copy_from_user outside mmap_lock */ if (unlikely(ret)) { @@ -6222,7 +6221,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, ret = -ENOMEM; goto out; } - *pagep = &folio->page; + *foliop = folio; /* Set the outparam pagep and return to the caller to * copy the contents outside the lock. Don't free the * page. @@ -6232,23 +6231,23 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, } 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/memory.c b/mm/memory.c index f456f3b5049c..737794b7a19f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5769,26 +5769,28 @@ void copy_user_huge_page(struct page *dst, struct page *src, process_huge_page(addr_hint, pages_per_huge_page, copy_subpage, &arg); } -long copy_huge_page_from_user(struct page *dst_page, +long copy_large_folio_from_user(struct folio *dst_folio, const void __user *usr_src, - unsigned int pages_per_huge_page, bool allow_pagefault) { void *page_kaddr; unsigned long i, rc = 0; - unsigned long ret_val = pages_per_huge_page * PAGE_SIZE; + unsigned int nr_pages = folio_nr_pages(dst_folio); + unsigned long ret_val = nr_pages * PAGE_SIZE; struct page *subpage; + struct folio *inner_folio; - for (i = 0; i < pages_per_huge_page; i++) { - subpage = nth_page(dst_page, i); + for (i = 0; i < nr_pages; i++) { + subpage = folio_page(dst_folio, i); + inner_folio = page_folio(subpage); if (allow_pagefault) - page_kaddr = kmap(subpage); + page_kaddr = kmap_local_folio(inner_folio, 0); else page_kaddr = kmap_atomic(subpage); rc = copy_from_user(page_kaddr, usr_src + i * PAGE_SIZE, PAGE_SIZE); if (allow_pagefault) - kunmap(subpage); + kunmap_local(page_kaddr); else kunmap_atomic(page_kaddr); @@ -5796,7 +5798,7 @@ long copy_huge_page_from_user(struct page *dst_page, if (rc) break; - flush_dcache_page(subpage); + flush_dcache_folio(inner_folio); cond_resched(); } diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 263191c37fb5..d7435a1a9d4b 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -324,7 +324,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, 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; @@ -344,7 +344,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, src_addr = src_start; dst_addr = dst_start; copied = 0; - page = NULL; + folio = NULL; vma_hpagesize = vma_kernel_pagesize(dst_vma); /* @@ -413,7 +413,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, } err = hugetlb_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, - dst_addr, src_addr, mode, &page, + dst_addr, src_addr, mode, &folio, wp_copy); hugetlb_vma_unlock_read(dst_vma); @@ -423,12 +423,10 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, if (unlikely(err == -ENOENT)) { mmap_read_unlock(dst_mm); - BUG_ON(!page); + BUG_ON(!folio); - err = copy_huge_page_from_user(page, - (const void __user *)src_addr, - vma_hpagesize / PAGE_SIZE, - true); + err = copy_large_folio_from_user(folio, + (const void __user *) src_addr, true); if (unlikely(err)) { err = -EFAULT; goto out; @@ -438,7 +436,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, dst_vma = NULL; goto retry; } else - BUG_ON(page); + BUG_ON(folio); if (!err) { dst_addr += vma_hpagesize; @@ -455,8 +453,8 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, 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); From patchwork Tue Mar 14 03:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13173594 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 48D61C74A44 for ; Tue, 14 Mar 2023 03:38:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 631FD6B007B; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B6DB6B0078; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 455C86B0075; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2F0546B0072 for ; Mon, 13 Mar 2023 23:38:31 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E9A691A12E7 for ; Tue, 14 Mar 2023 03:38:30 +0000 (UTC) X-FDA: 80566096380.07.B81239C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id 64AFC40019 for ; Tue, 14 Mar 2023 03:38:27 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1678765108; a=rsa-sha256; cv=none; b=6tFCJod9TDESMD8FZ0oPgdarnb8mCxL+jVevVydF1Y7q+LKs/yuCBnhfqylALbgEHw+Ohm 9jtmk7jZUpsm09WbdFQRlG2FauC231qwKgsBQ5MznrVPE/Ncj8vn6rE41O04ImWtH5a4u7 N1A+izJWsE/kkICQcdBD4u8TjR1FwQw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1678765108; 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=Y0jL8isLmjDxrA8Kj1NaLXESzut98tu/Hc87/oxOPW4=; b=IxUrIC0ronj287XmjEdioxn/Ys5+zf8ECBTdsJ4H3mLVvWh3Nj77p7yco5oKYLM7zuBjHN U5skMN+XU7SWUQIM/zv7IHvmSm4thams4HdpEe/zOvy3KmpATn3HWF0Apdz8EERZwTG+6j DnNFpFh9yW4jx3o4iaWgPB7dedFPQ5E= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PbK1m3bc9zHx5R; Tue, 14 Mar 2023 11:36:12 +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; Tue, 14 Mar 2023 11:38:21 +0800 From: Peng Zhang To: , CC: , , , , , , , ZhangPeng Subject: [PATCH 3/3] userfaultfd: convert __mcopy_atomic() to use a folio Date: Tue, 14 Mar 2023 03:37:34 +0000 Message-ID: <20230314033734.481904-4-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314033734.481904-1-zhangpeng362@huawei.com> References: <20230314033734.481904-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 64AFC40019 X-Rspamd-Server: rspam01 X-Stat-Signature: 8tk8tfye341814x8eprt15785r5axaqu X-HE-Tag: 1678765107-144032 X-HE-Meta: U2FsdGVkX1++a0qS9c2pWZpOcCr5SJkjeDQ+46Cf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u/wjPzLd+rkNJ0isyrQELy8qx5vn5WjZ9pdhaInrfgWvE1Fq4VA14MfwvY1cHk2nEAiX6aGD/9yd6KV+1uTTSJWbjw7c6pQIZEnYPrxbjRZ0r7U+C5a7pbDL2WtqeQWywL6XHbiDI6HCMmlQmn0 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 mcopy_atomic_pte(), shmem_mfill_atomic_pte() and mfill_atomic_pte() to pass in a folio pointer. Convert __mcopy_atomic() to use a folio. Signed-off-by: ZhangPeng --- include/linux/shmem_fs.h | 2 +- mm/shmem.c | 17 ++++++++--------- mm/userfaultfd.c | 35 +++++++++++++++++------------------ 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 103d1000a5a2..580af0e3bf02 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -156,7 +156,7 @@ extern int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, pmd_t *dst_pmd, unsigned long dst_addr, unsigned long src_addr, bool zeropage, bool wp_copy, - struct page **pagep); + struct folio **foliop); #else /* !CONFIG_SHMEM */ #define shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, \ src_addr, zeropage, wp_copy, pagep) ({ BUG(); 0; }) diff --git a/mm/shmem.c b/mm/shmem.c index 448f393d8ab2..986267bf34ef 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2421,7 +2421,7 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, bool zeropage, bool wp_copy, - struct page **pagep) + struct folio **foliop) { struct inode *inode = file_inode(dst_vma->vm_file); struct shmem_inode_info *info = SHMEM_I(inode); @@ -2439,14 +2439,14 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, * and now we find ourselves with -ENOMEM. Release the page, to * avoid a BUG_ON in our caller. */ - if (unlikely(*pagep)) { - put_page(*pagep); - *pagep = NULL; + if (unlikely(*foliop)) { + folio_put(*foliop); + *foliop = NULL; } return -ENOMEM; } - if (!*pagep) { + if (!*foliop) { ret = -ENOMEM; folio = shmem_alloc_folio(gfp, info, pgoff); if (!folio) @@ -2478,7 +2478,7 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, /* fallback to copy_from_user outside mmap_lock */ if (unlikely(ret)) { - *pagep = &folio->page; + *foliop = folio; ret = -ENOENT; /* don't free the page */ goto out_unacct_blocks; @@ -2489,9 +2489,8 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, clear_user_highpage(&folio->page, dst_addr); } } else { - folio = page_folio(*pagep); - VM_BUG_ON_FOLIO(folio_test_large(folio), folio); - *pagep = NULL; + VM_BUG_ON_FOLIO(folio_test_large(*foliop), folio); + *foliop = NULL; } VM_BUG_ON(folio_test_locked(folio)); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index d7435a1a9d4b..3d08a1e3cbe7 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -132,14 +132,14 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, - struct page **pagep, + struct folio **foliop, bool wp_copy) { void *page_kaddr; int ret; struct folio *folio; - if (!*pagep) { + if (!*foliop) { ret = -ENOMEM; folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, dst_vma, dst_addr, false); if (!folio) @@ -171,16 +171,15 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, /* fallback to copy_from_user outside mmap_lock */ if (unlikely(ret)) { ret = -ENOENT; - *pagep = &folio->page; + *foliop = folio; /* don't free the page */ goto out; } flush_dcache_folio(folio); } else { - folio = page_folio(*pagep); - VM_BUG_ON_FOLIO(folio_test_large(folio), folio); - *pagep = NULL; + VM_BUG_ON_FOLIO(folio_test_large(*foliop), folio); + *foliop = NULL; } /* @@ -476,7 +475,7 @@ static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, struct vm_area_struct *dst_vma, unsigned long dst_addr, unsigned long src_addr, - struct page **page, + struct folio **foliop, enum mcopy_atomic_mode mode, bool wp_copy) { @@ -500,7 +499,7 @@ static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, if (!(dst_vma->vm_flags & VM_SHARED)) { if (mode == MCOPY_ATOMIC_NORMAL) err = mcopy_atomic_pte(dst_mm, dst_pmd, dst_vma, - dst_addr, src_addr, page, + dst_addr, src_addr, foliop, wp_copy); else err = mfill_zeropage_pte(dst_mm, dst_pmd, @@ -509,7 +508,7 @@ static __always_inline ssize_t mfill_atomic_pte(struct mm_struct *dst_mm, err = shmem_mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, src_addr, mode != MCOPY_ATOMIC_NORMAL, - wp_copy, page); + wp_copy, foliop); } return err; @@ -528,7 +527,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, pmd_t *dst_pmd; unsigned long src_addr, dst_addr; long copied; - struct page *page; + struct folio *folio; bool wp_copy; /* @@ -544,7 +543,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, src_addr = src_start; dst_addr = dst_start; copied = 0; - page = NULL; + folio = NULL; retry: mmap_read_lock(dst_mm); @@ -641,16 +640,16 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, BUG_ON(pmd_trans_huge(*dst_pmd)); err = mfill_atomic_pte(dst_mm, dst_pmd, dst_vma, dst_addr, - src_addr, &page, mcopy_mode, wp_copy); + src_addr, &folio, mcopy_mode, wp_copy); cond_resched(); if (unlikely(err == -ENOENT)) { void *page_kaddr; mmap_read_unlock(dst_mm); - BUG_ON(!page); + BUG_ON(!folio); - page_kaddr = kmap_local_page(page); + page_kaddr = kmap_local_folio(folio, 0); err = copy_from_user(page_kaddr, (const void __user *) src_addr, PAGE_SIZE); @@ -659,10 +658,10 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, err = -EFAULT; goto out; } - flush_dcache_page(page); + flush_dcache_folio(folio); goto retry; } else - BUG_ON(page); + BUG_ON(folio); if (!err) { dst_addr += PAGE_SIZE; @@ -679,8 +678,8 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, 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);