From patchwork Sat Mar 25 06:56:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187633 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 AAB16C6FD20 for ; Sat, 25 Mar 2023 06:56:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC9A86B007B; Sat, 25 Mar 2023 02:56:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF0EC6B007D; Sat, 25 Mar 2023 02:56:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6C126B007E; Sat, 25 Mar 2023 02:56:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8DDA76B007B for ; Sat, 25 Mar 2023 02:56:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 65E7B140118 for ; Sat, 25 Mar 2023 06:56:27 +0000 (UTC) X-FDA: 80606512014.19.8CFF5B0 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf20.hostedemail.com (Postfix) with ESMTP id C8A101C0004 for ; Sat, 25 Mar 2023 06:56:23 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 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=1679727384; 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=CTODQP17+yRUCuy7LscMLpRRE35AfsF3hB+ofwdVipg=; b=UW3Wy+wlZjP8NPnoXqxR2WKeTWAcO1UkdGqufL/lwpqE1/FASqMufjpXkwP+Votiycx1da AX6LjcNwcbv06JAk33iqk23L3xXx9UQSSFZrNxc12X12GgoH8Hgot2J1pE8srOqKF5av4T 2PKM6W2l2Il0KD/i6zy+cdQbgIqgWas= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.187 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=1679727384; a=rsa-sha256; cv=none; b=odKE7c6pqAj26u7K3zfomM09LNKzagkRlq/7e3I5KGOmDh01QZnQGvXSkYVyarwa/OczXq q/Inoku5hXN/Zpp/ARyaoVvTGjg1oppzm2QyG76MEwXxPzG9ltAfdHTnS+yWiHm++0pD85 xkbrPc/i7Lz93/oKZQR9oPJiBCbjUUw= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8sx1B65znY5G; Sat, 25 Mar 2023 14:53:09 +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; Sat, 25 Mar 2023 14:56:19 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 6/6] userfaultfd: convert __mcopy_atomic() to use a folio Date: Sat, 25 Mar 2023 14:56:08 +0800 Message-ID: <20230325065608.601391-7-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230325065608.601391-1-zhangpeng362@huawei.com> References: <20230325065608.601391-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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 9oue99dobtauotnq34s4q5prgo6fh5st X-Rspamd-Queue-Id: C8A101C0004 X-HE-Tag: 1679727383-902900 X-HE-Meta: U2FsdGVkX1+QLqGBV65g4YgGwQIa7wOW8k5gL6jU1a46ztACEDPG0rW/+FrCfhp1uKzDl6pzubyc7u8jrRZ3yyVh4D1+74ZCryNUsRjllnhtMeKorxPNTzwYSxkglHFEw7psokahyfFVgHmTgHV0pb3Be7y+P7QKBYcr06X/P007LuvoPdeJBYpanBIgN45IHCyULH9K+sLHClAtjjBqIeVCN+bsWQ/jsv1ZuD+j8JosSCe//dYdUpcHDg8pn6umCFQO+OZkesPBDLL/l0/MOOJpKGgDjC0cBUOO9qB0jf5O43rKCFWahGl4lxGZVRjrVAphgGqQwxRG0xUF0aXjvFplkmuGdzqw04pYt8SnQYTbi2vWqP54uYGp0DX1I8ONTzm8QcAOsiKiUH6mOq3/S/UPGuOZNTJop1D444l6O+lO3mx4Z0jtDaYcMwhpE2okKfOfMYX8o4FiABK2eabd1HnQ1FNlcMygffqbTOJf4RJ8rWdhDXwdUQJ8bI4kluxHNkBsowUZM88fLWmV7YhdCIj8xB/bi3YQVDUR5ZJu6fiBzYl4Eaq4MsOAVfc4PUWxr729rRYGJ6fDOZ/2DuiFsGlNk014PZIKmKejT0y7EBw+ecrj7RJBrhz6Qu2m2rNaAFodU3qyICjkj0zRZsEg3pIaazZKGhBLZ42/cMxuRLbXZrhVTxGBg4wjhv8irbjTQ48/OsHl5sSvKTWamy+m1ue6gLpvYLMxsXxhdq5hwG0lEpbd7pilcD0RgDeP/B4F7J7QYjP5h4c1XlSdoIt5unzkSeFW+wLhRZdNpkKjk8AiU1+TxHhGddlBz2TFe1lDDZPVurAZMrg6lKJIqVHd7t/f9kFPJsVy+BEvG+Sc0MttOxRZPYjIfvTmQsF52Kk9sSeuyg+UX2a+3l2QHGngVyzyHYn7Il5nKn7ZYGSSVJehHKyrUsHVB4wd7Cs6WlMfuPwfXBw/T9rWDFNMMn6 FsENtT2e mApk5hA8FQpmnSa3EXENE1TJi1UviPQK4FMCVnSmvbz29XTJ6QoBKz2u13df4WEfmSpNHuERTIkf1n64O904vl0onPftD9UZdSjYmFJMrOKnfAL/bXJlXSozcSzC4SyGeeniryaUu/LBPNSPVvZ8h5Q8oWmzHo9FBZZhOIxBdfEvGonJAlqNP1oTNe4kdIAl1cQnxVhCHgaT66aIujcOkv+KB87qMuaZO+zI+qAI+10ASnJLTPzYHxPjpY/RZEJMFgK8hRomXDbPYlLGaKlCAUvGAVsKNEBLYzO6P 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 take in a folio pointer. Convert __mcopy_atomic() to use a folio. Signed-off-by: ZhangPeng --- include/linux/shmem_fs.h | 2 +- mm/shmem.c | 16 ++++++++-------- mm/userfaultfd.c | 34 +++++++++++++++++----------------- 3 files changed, 26 insertions(+), 26 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..e07e11a5812b 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,9 @@ int shmem_mfill_atomic_pte(struct mm_struct *dst_mm, clear_user_highpage(&folio->page, dst_addr); } } else { - folio = page_folio(*pagep); + folio = *foliop; VM_BUG_ON_FOLIO(folio_test_large(folio), folio); - *pagep = NULL; + *foliop = NULL; } VM_BUG_ON(folio_test_locked(folio)); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index cbcc7eb1d36e..2cecaf507b3f 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,16 @@ 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); + folio = *foliop; VM_BUG_ON_FOLIO(folio_test_large(folio), folio); - *pagep = NULL; + *foliop = NULL; } /* @@ -476,7 +476,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 +500,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 +509,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 +528,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 +544,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 +641,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 +659,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 +679,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);