From patchwork Fri Mar 31 09:39:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13195699 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 11A35C6FD18 for ; Fri, 31 Mar 2023 09:42:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 823DE6B007E; Fri, 31 Mar 2023 05:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7ABA56B0080; Fri, 31 Mar 2023 05:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D95E6B0081; Fri, 31 Mar 2023 05:42:01 -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 389F96B007E for ; Fri, 31 Mar 2023 05:42:01 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D8DB6160CB9 for ; Fri, 31 Mar 2023 09:42:00 +0000 (UTC) X-FDA: 80628702000.30.3AEF0B6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf30.hostedemail.com (Postfix) with ESMTP id 6635080015 for ; Fri, 31 Mar 2023 09:41:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1680255719; 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=uVbcfMPM8yRnivOD+vLRf5MR4eRifRwWXAGE9kPjmAM=; b=wpX4vEPscVzeLCBkg43Exer3Ufbyjy3qfH+1uIageCGxFX3xm0v2pKg4HZp3KCd0XIGGIo 6APD/VO3ZXtqAcqOWFrfPx/cjNLRoA5nbBbZJQG2G95aZYe0Un6buTGYsyPepbk+EUS0uM jZLmsYWMTGDkiP+Q2q2aBpEXKm8NMTA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1680255719; a=rsa-sha256; cv=none; b=rN/wHZdIO063k2Esn408gEYytXNuHvd8rfY7wNbO2A7D5SyigGMPQh6Bu5cP50QNa7SkZW nuLifC+KmxlbkXZwZ9AvvahhZLl2lof3yps5TcJ46KVEHycLZZZNzRxUE6DZUt6c3QORaF 3vudpM9yYbqpxTWblx9N1dzLcP77nu8= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PnwH62rXZzKwCC; Fri, 31 Mar 2023 17:39:30 +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:52 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 6/6] userfaultfd: convert mfill_atomic() to use a folio Date: Fri, 31 Mar 2023 17:39:37 +0800 Message-ID: <20230331093937.945725-7-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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: dwg8ktybgxfqxt1443b85optcjyenz6w X-Rspamd-Queue-Id: 6635080015 X-HE-Tag: 1680255718-457436 X-HE-Meta: U2FsdGVkX1+gNuQODmTNoi/VAsiaWnitlFn/b8w+aNHlQXLB3xga4yxlQaHzXWFR2A+1ulBLuYVADzjwdeLz7R4vLqpxpXitYB+jFLnT2VcWBDEDVJwYrCasmwjaoqeQtBSnIRzxrvrVBSyLr16krOV6qO2ukrFOh4QOa78Y4LwCHXXKhM0+PCbfkF2ERD+KlIBnhLZvX7n0biuLEWv5/5wI0Vw6j6ypmvGMIVQmBTLdDdCor2Ei5xxt8/wCi4w7mbEkzRmN+L2qG8RSYX9Zxw6rf7I9Tiqjzl2U7TSlPigl7h8pcr9dCzCyq8RLAnfSZmXXygCXOo3OcDjqvJu+MICAMELNDRENa+4oUjMXcBWX1tF5O9bekEnVBEt68yQpiDLwyf1TPdSIc6YN8PIuBw8R6I2tXJv7RFlo6NxPZLIKaNcsutO4Fn+ZA51Jo9deH8OWf9TPCviizwf+t85WoepeN33MrBTxnBTWc/1AAcmVCs9kb+BGSgzfrMHrbOGipF5yShv9oZup3ThtiIZ/jK5ZwQZp+4kJ3hJ0ux6mAp1uErq2a6kt5HVsUz1F6gDfutOvonE5y+2qHIS78zAQ8WGhFgRqKCbtKslrNOw1CFry1d0+xakymh0rqjA6mBjeTpChXONClGnfSTVON5b8YJxPLhxbs+pa0//sZh0VsoyqxoPHQs+Jv4lYhsOVSXZbk81kfLgAwKSgIR6/AmjCOVCmgolLs1C2JRscWD47QDszFvFm5YvRnuTd3qdcszlieqsDS+kZyIEnhvIXgA2DTBMhW3hyAaFOPLjeR+IkKS7IRuQBPG+3EbGFZeaHb3zP8tjIGGQChG/vMpHA3YNqumj2TBkU8P7DOlP/6PyKacSa0A7vg02UQljifi8NgHtDZLbq5VqG9wpsDa9L1IpU7XZWNpLPitar/VFSCyThQeJ4U4Bur6TMPJbuu9UVZoDN81ueIjtKTD4Ql4l0Qzh ds6A8jr4 MnYSCzeaUD3Kr2uSaSQmgLvRM3JDHlN7XYkdaIUzcYzOZcfEmYqgDSQYvsj4FHRFIRM70gNthxoYs/EHRp7tw9RQRbM4YK5aT8WqBKZL4fh52u4G3FouHZZmmrb6Y7/vuQQ00Ksedee9KCNLVTxS47pc8S2lQkT/8iXxEVdTYg0lYMEc+VokZAYuDrWp+82SeKwmonF32rf2Gfpshb0s8oCMA5GjxPPk5lqlI5hy0k1oljNrE2CDY8vJziCxPTpILMmMF97j8yMtaIS28bJomyKmIhPwbQI/74ojk 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 mfill_atomic_pte_copy(), shmem_mfill_atomic_pte() and mfill_atomic_pte() to take in a folio pointer. Convert mfill_atomic() to use a folio. Convert page_kaddr to kaddr in mfill_atomic(). Signed-off-by: ZhangPeng Reviewed-by: Mike Kravetz --- include/linux/shmem_fs.h | 4 ++-- mm/shmem.c | 16 ++++++++-------- mm/userfaultfd.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 3bb8d21edbb3..9e151ba45068 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -158,10 +158,10 @@ extern int shmem_mfill_atomic_pte(pmd_t *dst_pmd, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep); + struct folio **foliop); #else /* !CONFIG_SHMEM */ #define shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, \ - src_addr, flags, pagep) ({ BUG(); 0; }) + src_addr, flags, foliop) ({ BUG(); 0; }) #endif /* CONFIG_SHMEM */ #endif /* CONFIG_USERFAULTFD */ diff --git a/mm/shmem.c b/mm/shmem.c index 6c08f5a75d3a..9218c955f482 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2548,7 +2548,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep) + struct folio **foliop) { struct inode *inode = file_inode(dst_vma->vm_file); struct shmem_inode_info *info = SHMEM_I(inode); @@ -2566,14 +2566,14 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, * 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) @@ -2605,7 +2605,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, /* 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; @@ -2616,9 +2616,9 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, 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 f9ebaa079a6a..be423189120d 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -133,13 +133,13 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep) + struct folio **foliop) { void *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); @@ -171,16 +171,16 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, /* 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; } /* @@ -471,7 +471,7 @@ static __always_inline ssize_t mfill_atomic_pte(pmd_t *dst_pmd, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep) + struct folio **foliop) { ssize_t err; @@ -494,14 +494,14 @@ static __always_inline ssize_t mfill_atomic_pte(pmd_t *dst_pmd, if (uffd_flags_mode_is(flags, MFILL_ATOMIC_COPY)) err = mfill_atomic_pte_copy(dst_pmd, dst_vma, dst_addr, src_addr, - flags, pagep); + flags, foliop); else err = mfill_atomic_pte_zeropage(dst_pmd, dst_vma, dst_addr); } else { err = shmem_mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, src_addr, - flags, pagep); + flags, foliop); } return err; @@ -519,7 +519,7 @@ static __always_inline ssize_t mfill_atomic(struct mm_struct *dst_mm, pmd_t *dst_pmd; unsigned long src_addr, dst_addr; long copied; - struct page *page; + struct folio *folio; /* * Sanitize the command parameters: @@ -534,7 +534,7 @@ static __always_inline ssize_t mfill_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); @@ -630,28 +630,28 @@ static __always_inline ssize_t mfill_atomic(struct mm_struct *dst_mm, BUG_ON(pmd_trans_huge(*dst_pmd)); err = mfill_atomic_pte(dst_pmd, dst_vma, dst_addr, - src_addr, flags, &page); + src_addr, flags, &folio); cond_resched(); if (unlikely(err == -ENOENT)) { - void *page_kaddr; + void *kaddr; mmap_read_unlock(dst_mm); - BUG_ON(!page); + BUG_ON(!folio); - page_kaddr = kmap_local_page(page); - err = copy_from_user(page_kaddr, + kaddr = kmap_local_folio(folio, 0); + err = copy_from_user(kaddr, (const void __user *) src_addr, PAGE_SIZE); - kunmap_local(page_kaddr); + kunmap_local(kaddr); if (unlikely(err)) { 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; @@ -668,8 +668,8 @@ static __always_inline ssize_t mfill_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);