From patchwork Fri Mar 31 09:39: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: 13195695 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 4D426C77B6E for ; Fri, 31 Mar 2023 09:41:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C91A96B0074; Fri, 31 Mar 2023 05:41:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C17166B0075; Fri, 31 Mar 2023 05:41:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 958F36B0078; Fri, 31 Mar 2023 05:41:57 -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 877B46B0074 for ; Fri, 31 Mar 2023 05:41:57 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3C0F2160CE3 for ; Fri, 31 Mar 2023 09:41:57 +0000 (UTC) X-FDA: 80628701874.30.364D8C7 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id 70AB1140009 for ; Fri, 31 Mar 2023 09:41:52 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.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=1680255715; 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=vGD0nkxvtr99jSaSIwmjjGcqN9n2wK7ScX8t40F0ACo=; b=pvfN7+4QhSXvcIXcLZ5ySsYwwEABQLJ7VeD4VzYkqi7AROlg0x/wEIUUTcx4VyIdkVBh+Q IzlLNR3ndQRbi74eySAqKomVBLThTm/A0nc1lJSDxNb9g+86UeMj1vUoeSRNwGVEua/q1R Dvi3eCSJrZQdVNCxBoOvpnqKHOOi8K0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.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=1680255715; a=rsa-sha256; cv=none; b=yOKszAuniFTL0P3jl9Wf4q20Y0avoZmSgo+jB9As68d5pH89MSAM+oulcGKZQnZ9mS7wnD 4kCGyR7Y5y4M2GlOpW0tOfL5gYbIItEaSnQhJDm8UuhHJxqVx6c/Gw4IwRX9EOFXnSt7G2 eI5NBLvI/vBfi3LyXbESjYS6Rdm3Qo8= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PnwJQ5znfzrYkH; Fri, 31 Mar 2023 17:40:38 +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:48 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 1/6] userfaultfd: convert mfill_atomic_pte_copy() to use a folio Date: Fri, 31 Mar 2023 17:39:32 +0800 Message-ID: <20230331093937.945725-2-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 70AB1140009 X-Stat-Signature: zqchz5im6iagoixi3cp9oui5y5eryizp X-Rspam-User: X-HE-Tag: 1680255712-920379 X-HE-Meta: U2FsdGVkX18Iai4bb0lnRGOyoWkx0ZMwXubTbthGoFY0oTWqvzNihvTbb1+eY3uwGqwHaqAO1pWgIAtPMRTpdZjPAfY0ISYrj/ZkzCPN/iCOqtq5cZ0TF/XAI6dSaLKNEnN5wg8QTweqKY7r0KAiAL08QcYH5DDG7XP0FVGJxTDKUM+kB6lAe6m+Wh+wEEiFKpdd6OQGvV7zwoW7ZoE1hneGWYs/Ea2Z/u1jnnHTcxURfRbKJtIvJ9YTjVzQzyE0cS50lB3FkcCGMk2qBWDMFWI5glyw0tH028XVtNGNZE3ij7FkH3W5iCy7DzP6uiFv1mwAw1VLPOIx3/UOLTMPcVgfeI+fxhI6wcykAzGIQzR+LJ8H88OQvz5S4Ci2QU761Wei9rHpPF7/tdwbK3LagPJXQRBbrIWD877KBuYmxhrcZQdPjqLHyRJdwnyG5KzInKH9XruoONgexhKgX0+S0FdcvjS2HKtn/CP5x/YGdI37gNcRQUCdUy+F8N6WLRLk4qFxJX4WgiUIZduAFBbMNZlVeTZA2BoYy2NmJ0BmNzBh4/CVTFNZE6fhwdZF0rd8VDI5JrazUsptXI1ZJyuDKmbzFVFloUu6bxwXK+iXo9wOrZwPNeEnT7ZC4+DHLF0+92HtZyWmuW6GNDoka5FgMc4CIfU0273LXoGAiLH42jsRazKtOFlt6Cbf/NEpJTTbX+z7RLeuJXG73QFCmE+RgMh5jf4elfEjMWKPByPC7nMho/rIsnKYCRW6NHRUSYQUd/5PQBuLO/YhC1zcy60aammXNm85vZgydo4d9i7YoOTEAmtUG2JbxLST3iy89DimIggzp1xZhRj7p0CphLwEwaPrLmFz9+5Td4fg1z4CDlfZccuu3DYh4a6OjF0z/Cmf6ow2yr52NxAFMeK7Og9lN5xh15ybcOewGf6lkZZVLA8KolYnTp95p0yQWOTUwPQ0Dv5i5+Q6aSGpFyHLXIP fV3rvrId 6/JjYsCchhqWhfBD6ipsBsszymFlnqciU+ATy6qJ/N5Fvyq40S5MlNK7Z3pnOyIFooC3hc92OxaW50vU4sEt0i3rmsDouthbPVSbsuEq8zmn1w6Lgr7uWbH4dxii0h+04fzM/JgV/QB1GHEPTych+Cw9IhJwAvRL95EEnDfxxzWzvbJAdh6N6ImglMKAG8xoOvVYRL/8Tcjb5B5b+hoI955MBSvTPQ0jZtOatbU1JSgnowTUL1bFqOiyd33idIr0cd4yJTeTblz0lBHD1MioSKnnrZB6HUJrzZTomQ8teSiFKvERO8jAMgKVY+A== 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() and convert page_kaddr to kaddr in mfill_atomic_pte_copy(). Removes several calls to compound_head(). Signed-off-by: ZhangPeng Reviewed-by: Sidhartha Kumar Reviewed-by: Mike Kravetz --- mm/userfaultfd.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 7f1b5f8b712c..24d6ed7ff302 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -135,17 +135,18 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, uffd_flags_t flags, struct page **pagep) { - void *page_kaddr; + void *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); + kaddr = kmap_local_folio(folio, 0); /* * The read mmap_lock is held here. Despite the * mmap_lock being read recursive a deadlock is still @@ -162,45 +163,45 @@ static int mfill_atomic_pte_copy(pmd_t *dst_pmd, * and retry the copy outside the mmap_lock. */ pagefault_disable(); - ret = copy_from_user(page_kaddr, - (const void __user *) src_addr, + ret = copy_from_user(kaddr, (const void __user *) src_addr, PAGE_SIZE); pagefault_enable(); - kunmap_local(page_kaddr); + kunmap_local(kaddr); /* 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_vma->vm_mm, GFP_KERNEL)) + if (mem_cgroup_charge(folio, dst_vma->vm_mm, GFP_KERNEL)) goto out_release; ret = mfill_atomic_install_pte(dst_pmd, dst_vma, dst_addr, - page, true, flags); + &folio->page, true, flags); if (ret) goto out_release; out: return ret; out_release: - put_page(page); + folio_put(folio); goto out; }