From patchwork Thu Mar 30 13:40:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13194195 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 BA491C761A6 for ; Thu, 30 Mar 2023 13:41:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28237900002; Thu, 30 Mar 2023 09:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B913280001; Thu, 30 Mar 2023 09:41:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7B17900002; Thu, 30 Mar 2023 09:41:43 -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 BF481900005 for ; Thu, 30 Mar 2023 09:41:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9434A1209C8 for ; Thu, 30 Mar 2023 13:41:43 +0000 (UTC) X-FDA: 80625677286.12.02F01F3 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 0016AC001B for ; Thu, 30 Mar 2023 13:41:40 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.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=1680183701; 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=ahDIrwpjV7IDBnWOTGVf77qmCasBuiHazajE/lFOPL0=; b=7APXX9A6cZsYlO+Tqnk6Iazdo2IwP0qm2ng7jSEbjwzv3SDq2AzevB+E4eAA3LDYqV2A3F yKj5ESlyoZsLsLdkO076Z4S0e7MU7Tr23HsghqXJYCR0TDtSo4+NgMOqSWjwC61QJBKKtz TWWXX/tMF9Mc/T1l1jpCicaenJDdQ8I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.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=1680183701; a=rsa-sha256; cv=none; b=SVK/ggtawWj19KKRTrCMGMVoGA1ez3TKMf3zMSo668D/HKV6q5lHE6CUm9/ImTA+0mGlyM sKL2sffRI8bHjSV6yXyWTAW88tq+WnaozyKDXw00bKjHVCvTto+PWrOmNww0BpRGcUgH30 BfuD0fDuIS/zPFnoPS4q3AlJHbR5iVM= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PnPd413YbzgZhs; Thu, 30 Mar 2023 21:38:16 +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; Thu, 30 Mar 2023 21:41:33 +0800 From: Peng Zhang To: , , , , CC: , , , , , ZhangPeng Subject: [PATCH v4 6/6] userfaultfd: convert mfill_atomic() to use a folio Date: Thu, 30 Mar 2023 21:40:45 +0800 Message-ID: <20230330134045.375163-7-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330134045.375163-1-zhangpeng362@huawei.com> References: <20230330134045.375163-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0016AC001B X-Rspam-User: X-Stat-Signature: m8a1yss6tm5a5cbbsc43cor3j8qekeiu X-HE-Tag: 1680183700-871311 X-HE-Meta: U2FsdGVkX1+qGIyJmVg9b+ijYMsAUSnyT8sOAkBaOj8K7P4lXoiiI4OcSz9cv5V5C8Itsyhwj4badXHtgaTVp9occkFqcUUSSebSxvNU9CB9CPc5HTXSTe7U5UphmnYR8sQHmBLg80zLA8UFWM82uuZhvaVsjvE6zUX8X+CGHGXEGrevlaeYH4E3aMmQ6S+F5UHz8f1pBZyQcXx6qasSFdfenugefZzCu+KmzxSG9EuCLHnne78+fMdSFAUsY6WTNWzAXja1gdea6/VhdpsBcQLbFtbn+G2FaakWgTk7HelqydbaPZJyGzfeTgxo9iPNAAD555tAFTe+mLKudjXHf/fkoDAhRD+072ZXUYeXUQ1MBBmFvH+sCtS4gL9EsmgSUoKwblRshSjctRyZEkQv5vIvDE2CZFjtuSLbqULbTOHX++tuNQNBjl6isxRGaY8RBQfNJQfdfrS457FIlkPjv+dJA4bYd2U+bsvcOJyfayUpLfAMAPGu9ldxNK+Ug5hb6wxZPk/lkO8PjxM80Ko0z1rYgVNSD4cap3EdeegA8xVdY6XQwvkbKpTvUoazrPE0dptacsc3L80K4blp3cumMvwZw3ijvaC/Lwl1B0bQRMi5TtVnTKFUbbN6PerAeb4L6YsR0LDR/Kww1MN1sAcigjBt/W110SwoGfQsfupxPfmkd8ki/M/TaxyLX8NMKJr0C0kXKHGMApUlMC/iX670kQBwC+rt3XgDrSuiwusfUygukrX591rvXbvBN8i1CAFdya4jHwobTKCGotUNthhLy8PbP1V9670fzkudAXSwcKwvr1cLLn6s+tm2AKKgNBhgtxTdTpbx8qRnLMROvSGW1s9pqSJ3NVEPpoxGG8oJ6RDznls+sK2dHcpedZr8+kYezvC1b7wDa6LRv2gllmUntnhmDuUZgG/8ssnwN2WwMOYtqdRv3E18Hxs01vmGfXRVkF3PAZ6kcGAxy/7qaCS dt1VjmPR asgzhj6qNdCUqjB7Ow/3VVgiwFXiDzaWIeqDoadT5E+EIxnTTEqg8S4kJkC66p+sz1Ye8L0z639eNPK4le0hKCU2pspbnxfdNrQhkvhGoJErMoDZh6ldjgfi4yYg8HlqyOGZ6ItSioF2gFIAtzSChJ8GZr4TWmTaByXo+v14ogVV78A/VhWKuKE2eA/PbjNU9p37PlgxzzOyJ2UOvKludry1AVfd1pvDM7H2SZX8fSmMPno3GszYvBCUA545G+wkvgzSExvEMHYNDqSgUox+jVObX6Iedy4v0nrRq 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. Signed-off-by: ZhangPeng --- include/linux/shmem_fs.h | 4 ++-- mm/shmem.c | 16 ++++++++-------- mm/userfaultfd.c | 34 +++++++++++++++++----------------- 3 files changed, 27 insertions(+), 27 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 9e95af5ce2dd..74b122887901 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 *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 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,16 +630,16 @@ 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; 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); @@ -648,10 +648,10 @@ static __always_inline ssize_t mfill_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; @@ -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);