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; } From patchwork Fri Mar 31 09:39: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: 13195694 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 E008DC77B60 for ; Fri, 31 Mar 2023 09:41:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C89C6B0072; Fri, 31 Mar 2023 05:41:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DA5B6B0074; 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 22D3C6B0075; Fri, 31 Mar 2023 05:41:57 -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 146D76B0072 for ; Fri, 31 Mar 2023 05:41:57 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A5AA18020A for ; Fri, 31 Mar 2023 09:41:56 +0000 (UTC) X-FDA: 80628701832.06.05E4BED Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf06.hostedemail.com (Postfix) with ESMTP id 3C18918000D for ; Fri, 31 Mar 2023 09:41:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 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=1680255714; 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=7+RH9TcIYYo1sM7Vbhyc7P+DtGtLtOcBhUXSJ4uLsFY=; b=5iZ+PHmn9d8eAziUDBPefnBt6KASKVHlmjJARuktSpbJ8fFRElV2y/WW0ydCiubcgk04t8 bXlM84hMH6249isjAH/FGdY7P/1IY+FgSWgjcItwbXhH7B+aeUnhIaircIuUagwjmpdQ3F bju3XFgXaoGJkkjOhBLJ9a8r184obsM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680255714; a=rsa-sha256; cv=none; b=CsvlKb+6F2G4p6I2iAZTEsd0UqdM9z+9kevZ07HnZYCI0+Y+tUf/Gcr4cQ2aWW9bfksbb/ 8FN86NPgqr8LJ/2Qof7OFb6j3UYL78DcL0eJUgVFEG1BK4f4lCLQNF44/ZtJaV7VJEE4j5 PR2HsjlEsEQeGJ6PSOKjXzAv7oXu2EY= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4PnwKB5zpyzKpll; Fri, 31 Mar 2023 17:41:18 +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:49 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Date: Fri, 31 Mar 2023 17:39:33 +0800 Message-ID: <20230331093937.945725-3-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: rspam07 X-Rspamd-Queue-Id: 3C18918000D X-Rspam-User: X-Stat-Signature: p6o8p78es6856ocbhbppssxsyshgcyrr X-HE-Tag: 1680255713-501520 X-HE-Meta: U2FsdGVkX19wXVsHOl1BfgT6eINbQxWZyVM6GjQ/zhx5JespYksUKhaRh8NkOMkWTpgeq464EmaLgvccQbSo/UxXyhbArfRbRbQVcwXP6ur1ZbwtMawOwl14tTt6GqHtuLAVBH1VBQMKd+M1dfLIqgfYSBfq3gxVzDYFHHlVBHMiaz82frLRo9oukW9G/z81SY/+rIz0NIPw+F79L9LfKgq6nSQenOXdJCwQzbpbRbk7GDtfZvXMETc5t0mgIGg8VSb7fu+Czh9FUuwjx5rBLL4XHsczQOxP8doYLAB7JHxRKt8XeP8nz5NdS1ayE3ivel/G1o7gQy5a9pCAXxy9Vb/fm3FPm3gd1bXLbbSfezATywgg5W2rF8acXogqGTWOV50UExWWUo/wjflOcJ6weNu7nPn88t2Q6rAPYy72giDkcoVi02HC85w6afboVeFlEZ6D1xKeKYHS2pwh0P5iu+FCa78GACA8+ZFpB7A5Wp21Lc0mfG3F39iA/3zwigEHbYfr3rjc0xy+v7ESSFplW3B757tfi/B3F3dEPSEPcMgtXdyqeIPlA5hkM+ciQSo7fL/powfE4z3cGQJh5sWqzIcDel9fPHM1EG79qrTo6z+kaHoTdgL0Jmn3L5UcD3i7qO5YmcSctCAm0d0rBmmaVmxSu8zpY4iJmstLjmH47h/9EQLTOnttZ+KFPp42Re1CGtSdACDaadPPdFgtFUKMOrV4nu6hy1cI63tvp2dUQ3KNWnxtfI+KRtt7uBLZCoQ8x8XMKiYl8vxBfz+Tc8JyP3SHarQ+rdxVykyLouMM5vsmODVzlHpIH6vfa8mkqvTeaF6WkHv3b461ilWh2M18vQvpyfYQMZkwhTIlwqO9UOD2ipqW99VtfgkMY4DPyvNSbcQ3l/mA0tDvkM1IrqWa2z1Rjed5zxc8j84H0f6NXTCNh/WU8SNUO05B1lp5fVXiyTbJSIQJVrGAAJVDboD pqcy32hI ZNYErfEfR3gkvmlzqIdCiQc8EX+6NatnuUSuxMF1ZZs04gFV5enE3WhVT+nIJXhf1F9fshPfL7U1TSzt5+UErOW4X1BZakwGy/7e7kM8cyUp+N16aXWu6FN6ZWhSWfLJwXa3ioR8k/RETpf8x4m/eVjsjpygbWAQX1xVmpE4dECmiK7RkNwzf9lzI3K/bg9D7L2sUmJzj29Mj7OeXpb4yDbjEuufDROsAUQUSRisq6aRGPsW3hqKXJdfaCkIehHmCtJbat7sW8JPAJk6/SyXj6w/xNxG2tIk52Gkx/z2o2uBH/sCNnZbv9IdjM4zQTXkchXahMDEopHV7IvciZZiVcklNNDbjhaZPfTlSyN/GNnxucyE= 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 kmap() and kmap_atomic() are being deprecated in favor of kmap_local_page() which is appropriate for any thread local context.[1] Let's replace the kmap() and kmap_atomic() with kmap_local_page() in copy_huge_page_from_user(). When allow_pagefault is false, disable page faults to prevent potential deadlock.[2] [1] https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/ [2] https://lkml.kernel.org/r/20221025220136.2366143-1-ira.weiny@intel.com Signed-off-by: ZhangPeng Reviewed-by: Mike Kravetz --- mm/memory.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 387226d6094d..808f354bce65 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5880,16 +5880,14 @@ long copy_huge_page_from_user(struct page *dst_page, for (i = 0; i < pages_per_huge_page; i++) { subpage = nth_page(dst_page, i); - if (allow_pagefault) - page_kaddr = kmap(subpage); - else - page_kaddr = kmap_atomic(subpage); + page_kaddr = kmap_local_page(subpage); + if (!allow_pagefault) + pagefault_disable(); rc = copy_from_user(page_kaddr, usr_src + i * PAGE_SIZE, PAGE_SIZE); - if (allow_pagefault) - kunmap(subpage); - else - kunmap_atomic(page_kaddr); + if (!allow_pagefault) + pagefault_enable(); + kunmap_local(page_kaddr); ret_val -= (PAGE_SIZE - rc); if (rc) From patchwork Fri Mar 31 09:39: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: 13195696 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 9D0CDC76196 for ; Fri, 31 Mar 2023 09:42:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47B366B007D; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DC9D6B0080; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DEEC6B007D; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0B5216B0075 for ; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9B354A0BDC for ; Fri, 31 Mar 2023 09:41:57 +0000 (UTC) X-FDA: 80628701874.23.E644AB0 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf29.hostedemail.com (Postfix) with ESMTP id 268FF120013 for ; Fri, 31 Mar 2023 09:41:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=1680255715; a=rsa-sha256; cv=none; b=tftx3Zz9+19hRwaQZ7jFYpNY/gZQJ3GPGFAOT9/0Jc2QX8bNeyN/EcItS1LbpR1VtryWB4 bhAAAxY1X5U2ca6htXArwhN3o4pW4AnI4EyGIgCQhkZgQfSqQ4W7P12SWwc7tWsyGh0LYS SmagmDm/H5Pu1xe/BiSFD2VXRPT9k1c= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=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=fqkWa+Mw6JLS01xlkHtx9MWECuVMXXQLSUTfZwPbV/Q=; b=uZnKwFv/8/uqSOMc+MZEYA8aRY/JkZ26HAaFkxuEStjmPc+mz5Y/2UbtJDfPon1KK9shnF FqWdzY1qGcHfwavKO25doM0IeGJ7sS0NH1XplO1nPDk2AyjFPw0UUd6MqkozUq5OFNLtkG 5OWvqdFvNHga64WceOdpK/gOnH2z8ko= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PnwG062bdz17QSJ; Fri, 31 Mar 2023 17:38:32 +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:50 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 3/6] userfaultfd: convert copy_huge_page_from_user() to copy_folio_from_user() Date: Fri, 31 Mar 2023 17:39:34 +0800 Message-ID: <20230331093937.945725-4-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-Queue-Id: 268FF120013 X-Rspamd-Server: rspam01 X-Stat-Signature: ynz36bxz8gzy3wgy4ww8bqmp1z9rmu61 X-HE-Tag: 1680255714-304635 X-HE-Meta: U2FsdGVkX1/gYj/whPKDE6m5sSeexPB3dSzrtrv4GRZIGIV6uInFrqUtOCeaP6v9YEppCwhQF62+ugKXgXArO0YvQUuwqjcOcv6UXqiWR/crsTH3eKUFm9q4VCO4r/A0aKrjg3IRCkP/U4PGtQDtz68pgKfAOnfPVXHfW4DLfpdE2t18TPN02KEnfu8eK8UgDxJp+IyRc1NJ3OoaqjlOYs1tV9zGwtAgoyi6kkZWdk60gTlimFSTMW0DKSBK//YBvAt5HKvChGKBSOA3+rRJllvloC40vnTkamw8APX+e3H+qkahJKvXl90S4s40LHcuSX1PmAeGbA7GlMovHnAakY1kqveO6L6xpDdoRpmA2mxwrzgE7vJWAue/KdZchpHp4PRPCyCxMfNvxsaw1tZrF1tNYX1hzAq8cjox2PH0teLKDgcoXQR1ivW1pzKdV63Mv77CJlNZNFZpYgl3MCfwwEuuUpeRX5eMpCsDxvmpKzj/f6+dB6OkeS73kG7R/W25rjXkR8znpTT1iONIP75xegebnLY5Fn7YvcBeAJYJ7vurDqbmCJL17WOeNoSm2VI20a93lXBfIWipGycr/6EuLh9Q3ox6aWcjXKwpQXdzRj9qpx8rI1W4ZYZEP07IzQlWkB1QP2ZR6IXLd7cL22JsKBNisRwtvcDRekuBQ39hGt8gfddXG8hLF8mQn6SdBQ6U2+HSTl08l1DLuXth/GbooGsPpB2epO3RigaJqayhxF0DpXul/q0EPAr4F5xpXWpGecK+hDEgcpgFn3Xd6u2u8iEOIrVvPPvpeeLDDvaYNdyu4Nk7KeBoaMW7GVGPtaQXU6TccUXWBMZEWccBvnLDwpL7mbdK+PdsSNgYHOBGgvhvSzILBITyOACAgzkeWRVkM9rWg3/nVosr2PV6UBy5+JN/v5PruVXK487T1SeKmpNEBXjMhtErQPA8MoJqUWGaEHHpt7fccMUSERBXDMU 1tn3wuBI 2oiftTpb/kfbZztrtLXu+nabY+K5wFlwhMqLvp8gBkUzkPI02wsQSZQYNal1uzJ5fvxrqOsS6VZiwT7PknQMPTGVT6814rmdp0mi5yd0ywUfxU7tmF8lCLSTpLa5/Ln5TquEdWPXEWGkAam8bYWF5Z1HwknIJh2Pt+AHpG2Qh36Disp6MDuvzSneyv+LQHzHyvDoF724qL9OjDvQY9T3GcWEtWGG8wUnJH1yvHsr44dn/hiuyxqs/7RSvjmbB4QLN5Ukv57LGwyhBfWHhES+CLnzn4B8FxlBFeLZ8tJuoLqRDiZs= 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 Replace copy_huge_page_from_user() with copy_folio_from_user(). copy_folio_from_user() does the same as copy_huge_page_from_user(), but takes in a folio instead of a page. Convert page_kaddr to kaddr in copy_folio_from_user() to do indenting cleanup. Signed-off-by: ZhangPeng Reviewed-by: Sidhartha Kumar Reviewed-by: Mike Kravetz --- include/linux/mm.h | 7 +++---- mm/hugetlb.c | 5 ++--- mm/memory.c | 26 ++++++++++++-------------- mm/userfaultfd.c | 6 ++---- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index e249208f8fbe..cf4d773ca506 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3682,10 +3682,9 @@ 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, - const void __user *usr_src, - unsigned int pages_per_huge_page, - bool allow_pagefault); +long copy_folio_from_user(struct folio *dst_folio, + const void __user *usr_src, + bool allow_pagefault); /** * vma_is_special_huge - Are transhuge page-table entries considered special? diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7e4a80769c9e..aade1b513474 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6217,9 +6217,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, goto out; } - ret = copy_huge_page_from_user(&folio->page, - (const void __user *) src_addr, - pages_per_huge_page(h), false); + ret = copy_folio_from_user(folio, (const void __user *) src_addr, + false); /* fallback to copy_from_user outside mmap_lock */ if (unlikely(ret)) { diff --git a/mm/memory.c b/mm/memory.c index 808f354bce65..4976422b6979 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5868,35 +5868,33 @@ 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, - const void __user *usr_src, - unsigned int pages_per_huge_page, - bool allow_pagefault) +long copy_folio_from_user(struct folio *dst_folio, + const void __user *usr_src, + bool allow_pagefault) { - void *page_kaddr; + void *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; - for (i = 0; i < pages_per_huge_page; i++) { - subpage = nth_page(dst_page, i); - page_kaddr = kmap_local_page(subpage); + for (i = 0; i < nr_pages; i++) { + subpage = folio_page(dst_folio, i); + kaddr = kmap_local_page(subpage); if (!allow_pagefault) pagefault_disable(); - rc = copy_from_user(page_kaddr, - usr_src + i * PAGE_SIZE, PAGE_SIZE); + rc = copy_from_user(kaddr, usr_src + i * PAGE_SIZE, PAGE_SIZE); if (!allow_pagefault) pagefault_enable(); - kunmap_local(page_kaddr); + kunmap_local(kaddr); ret_val -= (PAGE_SIZE - rc); if (rc) break; - flush_dcache_page(subpage); - cond_resched(); } + flush_dcache_folio(dst_folio); return ret_val; } #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 24d6ed7ff302..78fed9003cf7 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -422,10 +422,8 @@ static __always_inline ssize_t mfill_atomic_hugetlb( mmap_read_unlock(dst_mm); BUG_ON(!page); - err = copy_huge_page_from_user(page, - (const void __user *)src_addr, - vma_hpagesize / PAGE_SIZE, - true); + err = copy_folio_from_user(page_folio(page), + (const void __user *)src_addr, true); if (unlikely(err)) { err = -EFAULT; goto out; From patchwork Fri Mar 31 09:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13195697 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 15676C6FD18 for ; Fri, 31 Mar 2023 09:42:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90CFC6B0075; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FBDF6B007E; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 478D96B0075; Fri, 31 Mar 2023 05:41:58 -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 1ED516B0075 for ; Fri, 31 Mar 2023 05:41:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CE006A0BF3 for ; Fri, 31 Mar 2023 09:41:57 +0000 (UTC) X-FDA: 80628701874.25.8B88EB6 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id 3D58AA0006 for ; Fri, 31 Mar 2023 09:41:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1680255716; 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=wjM9v9DmPjqcb1rvsoROD4mNe+7gy3iYv0sgFdjl6Tc=; b=ml9IBSGYX5IvzQ/CrR2L0SNwKRE8+Tdv4xUSv5cSdEPNqvr1wms7OWOJgWYEUqeXRu+dd/ BnUyoV50I6vtFsB1Xclw1o9ySZNfrcyERNXBcC9/i7PrkbXAVej81vpuuUK6WyUXDHTwig rKMywaTm7LnJUD4c6i0wlQFdOtvaixM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.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=1680255716; a=rsa-sha256; cv=none; b=D85E5/vS4uJpYWl0JLTIPQTAX/h55N236ju1idDfRRs7+elyyPC3sGtvzyqQ5EoxMMQxU3 9WLlJpHBdn8jEGmcBQQ3eMw4mhD7WtUNKKpDrgh8/tlEETV2xym5D0F5oGLOrtugqgCKwZ NzsQKy+YdLpYftfMm/TUGLsIR4F7g/o= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PnwFd1ww7zSpwm; Fri, 31 Mar 2023 17:38:13 +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:51 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 4/6] userfaultfd: convert mfill_atomic_hugetlb() to use a folio Date: Fri, 31 Mar 2023 17:39:35 +0800 Message-ID: <20230331093937.945725-5-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: 3D58AA0006 X-Stat-Signature: qwec5jakqquc463fwfpobxoiefqkosk3 X-Rspam-User: X-HE-Tag: 1680255714-231813 X-HE-Meta: U2FsdGVkX183xcg5Qnn+Bx1M5kCGKGYGvSuRkOsCdrMgGF9HPT7n1h6GRhgzZ1o7D9nsCtZUDVwd6MWDcUcA0tfg9vtC1MZIE9TM2drEA73BVZbB+DZ4WMa8R1Mta1MUMwqz9hQf8bzA0bn+VXt85NAYzwKjKzphrRXade73lOpg10sv/bKs/Qu6d8s3CQ2VaMYn0pm+al6g15coz2nzWKF5kpMthNFGsT7+yzSloRZnMjpcj4pWoIXJGKqP1YLFUmt52fM7XYX35TSLEBlkbs9xSYCbLjy6M1bHX6jR26JOa/8S8UWBlltulX2+inN16ufhF2HIgDTsMEQeN9ak6McB804j1FvSlVxF9z3FTaMRTGHr/pfUQdJDOXbb6TSHL3DXGEwvNCeijCRSp2Z15ohBhiuVG9kEBKFGVXfWvHheQW9cVcHG5jaRjmUJ6sB3h/OISJwGLAFeb5Nh76i0UjIOpjWuxrJwoGUyFmVyMUbi6bCI5fzGaZuASob3hs9ke+bA2h68SyqOP3fuyjRrdvY2IuGuZxqUxFMR214UlpG5HdbxZrfABASM5RddQ2u9q+g+vyPIcxXV1G0uBMV7UWwlojMcT5mkga/wBijECL3hP22kJ9NddgaSK3fzXb5Iq8LR3W6r+Bo//D7/m2OXh5cnHyJI3OprnwEbQgMV9qfwVVnXjuuR1C7Lhoq8CdMGWV0pbhi0gpZ9mB1rffqMiPu8C2yg1rcwKMT3DanJr1kdB23E8i3wMnCNLvswA8BEN7u+VJ/GMJ1/dRu/N/lvz6/LqNejSY7jLRYfEqcVuLNT9fzhVKDuXqS+cJ79j0wO90OC8/NEuoU/o5cYnJ93eE58ZgMpezQy9AubuV72LGbBoZmEZ1SU1rTxRGtQ84hjDV5b4+/ADZdZ+pmRO/eoA7VyIHAg+qRrPUCGJTexvY/NB53KgDhTg09A1gsT/KTzJnRyMNmVdP0Eo+s8l4v g5ndDGgs pzMqkWU3WvnPRw+i7oEsiGfBfgDalEuRqsL0yiTSwcJRtK12SH4yJsYKtsNapmTnJB2Z4nFIlvcE52zxeTr0j75bgoblJcAVxP+MsI/cvrboUS2oCN0LPV9m76u5qWjabfcInbCOmit3SWBC84zVelaPO8iHv9w81sKwxUau913/uuKFJdyUb7yjq4fq6ARQZeJCBewWvr70tpz6cs0ZxKnT2iaKP3Vv8MlMUosNsGjjuV7l417VTqIufjZiNJaw8/6zR6sDL5sSstLx8276L4772SvxbPHP+btXgCV6UaOGbx+w63XpwzKZYKA== 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 hugetlb_mfill_atomic_pte() to take in a folio pointer instead of a page pointer. Convert mfill_atomic_hugetlb() to use a folio. Signed-off-by: ZhangPeng Reviewed-by: Sidhartha Kumar Reviewed-by: Mike Kravetz --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 26 +++++++++++++------------- mm/userfaultfd.c | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 2a758bcd6719..28703fe22386 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -163,7 +163,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep); + struct folio **foliop); #endif /* CONFIG_USERFAULTFD */ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, struct vm_area_struct *vma, @@ -397,7 +397,7 @@ static inline int hugetlb_mfill_atomic_pte(pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep) + struct folio **foliop) { BUG(); return 0; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index aade1b513474..c88f856ec2e2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6178,7 +6178,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, uffd_flags_t flags, - struct page **pagep) + struct folio **foliop) { struct mm_struct *dst_mm = dst_vma->vm_mm; bool is_continue = uffd_flags_mode_is(flags, MFILL_ATOMIC_CONTINUE); @@ -6201,8 +6201,8 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, if (IS_ERR(folio)) goto out; folio_in_pagecache = true; - } else if (!*pagep) { - /* If a page already exists, then it's UFFDIO_COPY for + } else if (!*foliop) { + /* If a folio already exists, then it's UFFDIO_COPY for * a non-missing case. Return -EEXIST. */ if (vm_shared && @@ -6237,33 +6237,33 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, ret = -ENOMEM; goto out; } - *pagep = &folio->page; - /* Set the outparam pagep and return to the caller to + *foliop = folio; + /* Set the outparam foliop and return to the caller to * copy the contents outside the lock. Don't free the - * page. + * folio. */ goto out; } } 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/userfaultfd.c b/mm/userfaultfd.c index 78fed9003cf7..f9ebaa079a6a 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -322,7 +322,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( 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; @@ -342,7 +342,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( src_addr = src_start; dst_addr = dst_start; copied = 0; - page = NULL; + folio = NULL; vma_hpagesize = vma_kernel_pagesize(dst_vma); /* @@ -411,7 +411,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( } err = hugetlb_mfill_atomic_pte(dst_pte, dst_vma, dst_addr, - src_addr, flags, &page); + src_addr, flags, &folio); hugetlb_vma_unlock_read(dst_vma); mutex_unlock(&hugetlb_fault_mutex_table[hash]); @@ -420,9 +420,9 @@ static __always_inline ssize_t mfill_atomic_hugetlb( if (unlikely(err == -ENOENT)) { mmap_read_unlock(dst_mm); - BUG_ON(!page); + BUG_ON(!folio); - err = copy_folio_from_user(page_folio(page), + err = copy_folio_from_user(folio, (const void __user *)src_addr, true); if (unlikely(err)) { err = -EFAULT; @@ -433,7 +433,7 @@ static __always_inline ssize_t mfill_atomic_hugetlb( dst_vma = NULL; goto retry; } else - BUG_ON(page); + BUG_ON(folio); if (!err) { dst_addr += vma_hpagesize; @@ -450,8 +450,8 @@ static __always_inline ssize_t mfill_atomic_hugetlb( 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 Fri Mar 31 09:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13195698 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 8DB54C77B62 for ; Fri, 31 Mar 2023 09:42:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58B5A6B0078; Fri, 31 Mar 2023 05:41:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EFA66B007E; Fri, 31 Mar 2023 05:41:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A2FF6B0080; Fri, 31 Mar 2023 05:41:59 -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 0E8466B0078 for ; Fri, 31 Mar 2023 05:41:59 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DF8FE1A0BF9 for ; Fri, 31 Mar 2023 09:41:58 +0000 (UTC) X-FDA: 80628701916.15.0735D5A Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf01.hostedemail.com (Postfix) with ESMTP id 6E7664000D for ; Fri, 31 Mar 2023 09:41:56 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=1680255717; 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=qy4t3Bl+06JFzUuNl0JyheFOKRrvnzWEBhKrgFbkbZk=; b=J1Eig0cG78XGU+Z3T89I171xv60LImZumR+qx3QXhb1iKjOnsE85+NZRJyRsJjrcACiUOG bM8cmakEtSuMZCop8bjJhtW+7254st6cFthw4vBpyKZVSrySKb6vjWHURjy/+ElEK1HjXe /XcvPNZRT4Nn/TTw7NkzPACTIK4C8ok= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=1680255717; a=rsa-sha256; cv=none; b=IMdJlOncQ12WZSWyk/C965SBnqjjQh5WUI/y372i3KYU1j4lFTEmAyfbixsbvAF7KQZBzZ cCraxir6hBSpkFyet8X2ui6MVYuDpJpJ4sHVs7ZCi/M4YyrkAIML/qXzhhjVRwCRlvqXxI VfhnF2znpSCp+3YPpOvhjufCGx1A7T4= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PnwG23pwfz17QVK; Fri, 31 Mar 2023 17:38:34 +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:51 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng Subject: [PATCH v5 5/6] mm: convert copy_user_huge_page() to copy_user_folio() Date: Fri, 31 Mar 2023 17:39:36 +0800 Message-ID: <20230331093937.945725-6-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: iii6ods5bdgkt167o9z1kea6mqwhx6k7 X-Rspamd-Queue-Id: 6E7664000D X-HE-Tag: 1680255716-784278 X-HE-Meta: U2FsdGVkX19hv0BoJwCqFh4IgBM9/YTCFo5XmxF8J9c6NB5Q1AuNWqZ4LNtah5VSG8lE5yZDi9F0PmvLec5fQG4sX1axQ2BLNEsDP9Xxn/ZnGqL4zx2I4Xd2smeETpwx3H+GFnRgLh1boBC6KlfAOUU+gNwgGh1hfWHRx9XOwEGBpP2eSWU/g9QwJLgrbRRWh4Pb1VXOPS8LYH/SSZo6L8A9oLVUEDnBWJrsTk8vnW2hVR7+pHxQCzencAfYVbIY9Hr9TXdvRD6vfS/Nrvf7ACLOwkJqCs7h+H28DGxIy9j6v47kpE3JeU5mUNUigwU49dQ9m0JHpp6zmHQE9qqUpuYmtjioNkF0yW6hlJoVlCSPHGs2qviTqyYZM4USqg7WzB34v7UGshDhgIxwMh3M8CuN9v55S9jzLE/sO+I30NEv9EX27Tt5GO0JfeUEOd4iJ9dB4PPtwjmppnIAjP1H5HLcWupR8Gzt8KqfIbqIAyNfsLZTpvz9PLMN3b3JpSGPH2Uk5WnFsLXQPr0JHQz2CIEBBaz1s5tX1ppQs6vA1ulsvK48cyO4N/uEifbV0rRXDNNgiq7WtnsCsqBISra91YJYQrdY2GrBFaB4AzR1RjpvIsHFbdwxJ1WJj5iHPDrxchd+J1lxWHkfjpaERH4YLFLN9QOiLvB7j16hTAdmiO6UIkKkmPAESkbPN0v8y7iX6yHI+1ilJXhc+KjXBOzVxZGZ9EWZQda+yygFCuyBtOJiOlXT787tIKnVn3Slx+DUdMeGqg0Fxgb9B8XmNWFvh43eA06CFrPtWr5RnqfP31TJuzykjh7XwgDS2e3T64S5mbtLuyD9tad79jv7b4dxx+kucpCIJIzbbKM8REBMPSDYeUm1v8cXm4KHGHmSx7+NjV3IYKks6tpt01TpMqQ2qERbcBjuzDhDgZQkaQE6Nc8TWBRfnlKLjBmWZEt8gzK5SGg9+c5JEd9JGUGof0y d0LoiuRD W2lVC2bN7+G7dwGgTZEBfRjtC1QrKNbYMiaJTCOP72ISN1a7uaoFuAF9afh6Majs5ILLyABQYyF3+oILDMfSx4kfncKxSf4HHWKbfFDZvUbuqdwOONoSP46sjNJXVrcff05rFLRHimqghwNUFZct42HRFUSVTxMiZEtlnvEP3xFcpicAY5SvLc/H4ig05P64B+A4HJxHNDAm+/sHyIS3cQLUINOJ6UckgIZ3hWq0VArCi3xRKmLtaTNIh/Hii0mODDyBeHtJ6XOOo0h/k25+deYEs4Q== 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 Replace copy_user_huge_page() with copy_user_folio(). copy_user_folio() does the same as copy_user_huge_page(), but takes in folios instead of pages. Convert copy_user_gigantic_page() to take in folios. Remove pages_per_huge_page from copy_user_folio(), because we can get that from folio_nr_pages(dst). Signed-off-by: ZhangPeng --- include/linux/mm.h | 7 +++---- mm/hugetlb.c | 10 ++++------ mm/memory.c | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index cf4d773ca506..898ece0a3802 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3678,10 +3678,9 @@ extern const struct attribute_group memory_failure_attr_group; extern void clear_huge_page(struct page *page, unsigned long addr_hint, unsigned int pages_per_huge_page); -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); +void copy_user_folio(struct folio *dst, struct folio *src, + unsigned long addr_hint, + struct vm_area_struct *vma); long copy_folio_from_user(struct folio *dst_folio, const void __user *usr_src, bool allow_pagefault); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c88f856ec2e2..a7ed17cbc84e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5097,8 +5097,8 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, ret = PTR_ERR(new_folio); break; } - copy_user_huge_page(&new_folio->page, ptepage, addr, dst_vma, - npages); + copy_user_folio(new_folio, page_folio(ptepage), + addr, dst_vma); put_page(ptepage); /* Install the new hugetlb folio if src pte stable */ @@ -5616,8 +5616,7 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma, goto out_release_all; } - copy_user_huge_page(&new_folio->page, old_page, address, vma, - pages_per_huge_page(h)); + copy_user_folio(new_folio, page_folio(old_page), address, vma); __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, haddr, @@ -6260,8 +6259,7 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, *foliop = NULL; goto out; } - copy_user_huge_page(&folio->page, &(*foliop)->page, dst_addr, dst_vma, - pages_per_huge_page(h)); + copy_user_folio(folio, *foliop, dst_addr, dst_vma); folio_put(*foliop); *foliop = NULL; } diff --git a/mm/memory.c b/mm/memory.c index 4976422b6979..0a5cefea9774 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5815,21 +5815,21 @@ void clear_huge_page(struct page *page, process_huge_page(addr_hint, pages_per_huge_page, clear_subpage, page); } -static void copy_user_gigantic_page(struct page *dst, struct page *src, - unsigned long addr, - struct vm_area_struct *vma, - unsigned int pages_per_huge_page) +static void copy_user_gigantic_page(struct folio *dst, struct folio *src, + unsigned long addr, + struct vm_area_struct *vma, + unsigned int pages_per_huge_page) { int i; - struct page *dst_base = dst; - struct page *src_base = src; + struct page *dst_page; + struct page *src_page; for (i = 0; i < pages_per_huge_page; i++) { - dst = nth_page(dst_base, i); - src = nth_page(src_base, i); + dst_page = folio_page(dst, i); + src_page = folio_page(src, i); cond_resched(); - copy_user_highpage(dst, src, addr + i*PAGE_SIZE, vma); + copy_user_highpage(dst_page, src_page, addr + i*PAGE_SIZE, vma); } } @@ -5847,15 +5847,15 @@ static void copy_subpage(unsigned long addr, int idx, void *arg) addr, copy_arg->vma); } -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) +void copy_user_folio(struct folio *dst, struct folio *src, + unsigned long addr_hint, struct vm_area_struct *vma) { + unsigned int pages_per_huge_page = folio_nr_pages(dst); unsigned long addr = addr_hint & ~(((unsigned long)pages_per_huge_page << PAGE_SHIFT) - 1); struct copy_subpage_arg arg = { - .dst = dst, - .src = src, + .dst = &dst->page, + .src = &src->page, .vma = vma, }; 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);