From patchwork Sat Mar 25 06:56:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187630 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 C9490C6FD20 for ; Sat, 25 Mar 2023 06:56:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 404566B0074; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 38D356B0075; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22E226B0078; Sat, 25 Mar 2023 02:56:25 -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 138A46B0074 for ; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DB53C12011B for ; Sat, 25 Mar 2023 06:56:24 +0000 (UTC) X-FDA: 80606511888.21.7B2BE76 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf10.hostedemail.com (Postfix) with ESMTP id 5EA76C0003 for ; Sat, 25 Mar 2023 06:56:21 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.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=1679727382; 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=nbkREkUXjavMZLWrcbnXqcI0k9zEMdNai8bCnP1WlF0=; b=GQwdWpSclPS1s8RNlEMYqE3oN6a3B2kKuGOIR5+Y6zs+fLD1Y+RazrVZBLDI4tAtlh4LWa 9BYhfKegZu5wZ0SkhLy+sWdJRcb/YmckCNYmycfaxo2pKG3arbxgUWAnq3iXe7sQWrsDev UxGZscv4KUKdcB3kqNATCy5wRvAdVkU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf10.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=1679727382; a=rsa-sha256; cv=none; b=P1Hlc+7ma3J78jcmeD9+eH0/zgSmwGkCNtAmNMJ/rqfD0DiMcdsSCGpMJoJTEVf1DnE+/G hx4p+uiaZ63EQMIGPU4+C8JayBdP2fGHP6RqWtwqY8WGw27/Gb3gTlMGFF4A9Q46lMSvod eOqzlevqhjHkmq99WEWsTPrNu1SIAus= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8ss0DHYznY5p; Sat, 25 Mar 2023 14:53:05 +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:15 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 1/6] userfaultfd: convert mcopy_atomic_pte() to use a folio Date: Sat, 25 Mar 2023 14:56:03 +0800 Message-ID: <20230325065608.601391-2-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: rspam02 X-Rspamd-Queue-Id: 5EA76C0003 X-Stat-Signature: bggh1e85zzqqqzi5a4ddqw9a58tmsge1 X-HE-Tag: 1679727381-31655 X-HE-Meta: U2FsdGVkX18F/sycxw9mA9s4zwzEUL2Mx3FB1aRbgvdRY/6CAWHDdiR36C952obPweHDVwwLQ1FqWb2fmeGek9XwdM438qXMqEtbzYpkgEqkqa5ZZCuJ3MGacZE9bExwCgaJjDu3THumVO31ZOjZLnwnYRsCdg2qtuPXB9EeOOIPWeFI9LJkh9rdBJ+y2QQZW3CMVpet+cCrTpLTLydUkeUxlc7FCkGMZbvsqK8DhE8ewKnJG7h7w5qyGR7fdDOkPTbL6iq2i9qsU7kxJ4cjQS7tWDvOYCgIXluMtSB+mXUaJwfTjoRS/jKxBf4KEZw2CBDNIR9Skb76I5OPx/EReJtSy/Dvz6PsTySh++eXFX1Mv11QFs52E5h7qSPmAVDTdzigzWyh1MIc55kOAIDn3TscyAXLYzX5oCydXpa+TXogiaLaOl/UFMblwS8u4SBjT756qoDtRQeJN08cXtmwdcmAQFNqltuHTkDf0VvjxEMS4vrurT/9SCgdQM41qcWQvY2F7iUMg63H4AGde7OfT2v7OEWvWNaVrU2zDQh+4eG9SBiKag5tA+Pb5fMm0ednf0cevDTG4bThiHFvgIjNuLTKKNcxZnRxhFG65/qhNfW7IC53EWvP/AsvU1as6qVHIc29bR+rAGJKHgj/7Cv4vI9AyicC5T65MEs8xhMFxrLbs5eTM5wOVZzaZe4i58HCgRP49dK6C0GMcMp0BVymtarypuZY+WmKWe34QqN8Vj442G29dkXTgKot7MjEk5FzZA57kqRiL44tR65hf/pr2tjPf83Vtxgs32WC2mQwmXi1pYo/gn2BK5V6t9B/HiKxzdBFHr+6OTODX68Atri1ihoIBMS666syKy7VdV5qNNyBtO/jozlODTY680B9TYXYWt3iBvUV+tct/a2jEHw0nAbbf34FGnmOUZNa0jy6o7zfFsz/5hs6Nv4rTn6WGnDhKY/i9TZkVWzi8vgs49L RDMrrvRy L+SRogxImsZpkoFhCsKb+6MTrNS1MXnT9/FG1VVd64uJPffjXrSfiTk/PrOKPk2DwXq2pGJymfRM8puzdC92yRuxxEh0+NRZhAkMy7zUz/22Ko5Y/eozraGoO0eAfCazTqMjugUEJY/Q0A+5v8ZtnPR9OR/n1Do33o9G+o/Rn9vKIWfd+M409N7QximedJazUpw060WFvgkPVyYKhTNzNKF4uJwUqRGywpl0CiaQfsDJheXY6Dc/r4IvA7H0E2e5GiUKXyjKbQ4VKloLqMsEX54T8ag== 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(). Add an assertion that this is a single-page folio and removes several calls to compound_head(). Signed-off-by: ZhangPeng --- mm/userfaultfd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 53c3d916ff66..263191c37fb5 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -137,15 +137,15 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, { void *page_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); + 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 @@ -171,36 +171,37 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm, /* 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_mm, GFP_KERNEL)) + if (mem_cgroup_charge(folio, dst_mm, GFP_KERNEL)) goto out_release; ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, - page, true, wp_copy); + &folio->page, true, wp_copy); if (ret) goto out_release; out: return ret; out_release: - put_page(page); + folio_put(folio); goto out; } From patchwork Sat Mar 25 06:56:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187631 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 9F79CC77B60 for ; Sat, 25 Mar 2023 06:56:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 084656B0078; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F287F6B0075; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF0D96B007D; Sat, 25 Mar 2023 02:56:25 -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 ABC326B0075 for ; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7B9ADC0121 for ; Sat, 25 Mar 2023 06:56:25 +0000 (UTC) X-FDA: 80606511930.24.86451B8 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id D6091C0014 for ; Sat, 25 Mar 2023 06:56:21 +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.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=1679727383; 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=kHAvzVHI6LRMiiNYBPBqlBYP1x/JpIh+mHHtGaE3lL4=; b=FSWu/3ndVVLctUb+jZf9kn//tn8t9/v8qHN4BcPheaH+eeB1QQ/ihH44oZxTGE1uDpgCBq 0umfnIapn2t4MddP8RO6e//00jS6fNCapzUsYE5l0YLa5ncWVzf20Zm5TS/b8vaX5g5U7w Gqfy+SimV/C6pmPIqd4744PQVbyAp10= 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.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679727383; a=rsa-sha256; cv=none; b=bOMygpMsF0J0J5FjephQ2HmAgJQxxnkXkJPCv6a96ih+9h5t+dQ4+dO/G19Sq39rLXiM0A 5OWWxtGpUsRmtPJu2Zqrm263n+TqxBYkKkc36r3tK+Ud31erQKQYPrYoJc32KbSI32bKoD IgafS9vIdFBSiNQN6LvGGPDHxGMu7lY= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pk8sW1n6VzSnxP; Sat, 25 Mar 2023 14:52:47 +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:15 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 2/6] userfaultfd: use kmap_local_page() in copy_huge_page_from_user() Date: Sat, 25 Mar 2023 14:56:04 +0800 Message-ID: <20230325065608.601391-3-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D6091C0014 X-Rspam-User: X-Stat-Signature: zihe9ocwksxmdskiw6d1f9wrc7hrjoxd X-HE-Tag: 1679727381-924151 X-HE-Meta: U2FsdGVkX19+qTb9wsYM9vdg2KD2AExfYeTqKad3dyM0Bn82OagYEGwlRhRUyQT2RosHE7pJkm19id9qy1WacOUQRtfUMxRxOehN8LxjVYYmw5BZBUBXf5yMXyyJcN2C9g1P8ft6Efer1qKfQIEtNYxUhbOeaZEqk0IkulxEStld4Sv0E7JFU3b4JWZCLeoRuCZtBMHVWWnI6dRiRcSR/+EzFt3mw0uIiFBYDSpXAcX02Qlg8HVVPq9m4oIAbwKnUrBfphSgTzCYJDIfrujx/n3e7Qu4EGb0bif7U2vpy305Ry6OXjZsv+Io7naVQCwzaZenKSe6Pb5p9rUSPjBlcE1+eutympGNdMnqNRDnyW0FLziU2RXGZd0b1jYRo4ADoFWtqzCtgfpJ5w4hsRWiXaksBsgzu/HwYuY9G1laT3fLSMqi5tZW+HjIe7RKyZV4sZzi1nQkAYyP4u1H8NLNRwWjhXVy4nU1SjZEAtt65+o+snEtQIKu7EYW1TLxPhmPlzh0oQW0KDndUFEHl6UhSTXWkpAZmS1zTmhU1VVjjikAC/gM6b+cTs7WElVbtu3BUAGsj1jVmk/sbNTQLbZ8rAioH9egnFhztGAD6g4JTHaUr4AgzsnfmbbxThCN6XUiU0w/1RYdu4oVL5ar7zq+hRRmEv9+osNqJBHI9broQcpEvwYBtdE5MYx+6SptgOBswgNyukmkpwE6zEleCL9JN7QVw7lsMqNCGG7AjAlHQ8PyBk4fi4oqRa9WSXNkEJ2MBiE7IAtIJKx1B8qet+oDptYFDX3S5x9xcEpH9AZoPPCLWTYi463NpiNHGbzm/fDGbKaOIp/06sR7zIrUDLiUfoDm+SRB7UW+zmSoteuJCzmixsxm20+gy207flJ6Ktlk05vznsUZNf3ZqDwtBVN5rHz68l2XgFZFG/eGZAPBX+OysbG43jk30DLIcjQS5B1uByU0Nw63bTLdxp5t0fg bEkvu3fW J8+4+WFVI4Xo9+iYR9EKhm7kMD3QDmQ85l/ZH2QgXetRJqBIpgdMl8AejFNUGbpw+/guStgrfqKrPnHRlLsyx+iYwxGVdEwf2KuuAbWmx4wRpnvdOeBugzZ4CbwufPoewbNJK6BOfdxFBj/Bc3ATp5JW6DOlNpVdcs7mGCmyOwUFQbGMZ+Yl/2B45H+lltsn3dnnbFxfidO3dhZocI4AqunqMNTxqJmDf1HGkhsUNb4VeR76otNYnhkqEqHJDcDYf7TlVtcsS5WsVf3mg5HRgUey7Q8ssRzvIQkusR7G0isYhCBLvjXYoVVo8YgYbXZo6i48wn1A5Ky0BOja4C+63Xbm9ymflSngFO5b0iYdJzK/5Hbo= 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 --- mm/memory.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index f456f3b5049c..062bd215bea8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5781,16 +5781,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 Sat Mar 25 06:56:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187635 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 D621CC6FD1C for ; Sat, 25 Mar 2023 06:56:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7390F6B007E; Sat, 25 Mar 2023 02:56:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69AAB6B0080; Sat, 25 Mar 2023 02:56:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53E5B6B0081; Sat, 25 Mar 2023 02:56:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 35F3B6B007E for ; Sat, 25 Mar 2023 02:56:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D0AAE1C10DA for ; Sat, 25 Mar 2023 06:56:31 +0000 (UTC) X-FDA: 80606512182.20.F816679 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf24.hostedemail.com (Postfix) with ESMTP id 4B70F180008 for ; Sat, 25 Mar 2023 06:56:28 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1679727390; a=rsa-sha256; cv=none; b=4nFd6eI/1xJdQqgwEIaMrVMiKvZCRc94CmCcah5pk1fj1OIivaHEAiino45E9UQ3KRcI+1 VHqBZeAKJe2+foDaeS7TgJ1Zlw8Vwop20Q3LysNsJomzOEYf/KJvYg8cbfUouR4xwM2Hq0 LAeEqCWKVWV+qXikcAt9FaKoFcOvTzg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1679727390; 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=Vc01FOOpAzZh5sKuP8DnATSeigO098ACIAN0Z0DRydI=; b=qvbQwJhu+aZ4nYDKs5KYu/eq1Mw5U1Q+oI9i1bZMPech/ECY8/oozitvOtVIpBqO7a5RDd 5q02E3hCRjLZIWF9gWc6tidYCk/1U5vXVWCFcFtqWIEFLNPg4nB8DZiHQ5rRW0/T+HA1/M X5PmNC5c7YAzB4SlPYO+Wf2oCdGMGf4= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pk8wK2wMczrSbW; Sat, 25 Mar 2023 14:55: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; Sat, 25 Mar 2023 14:56:16 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 3/6] userfaultfd: convert copy_huge_page_from_user() to copy_folio_from_user() Date: Sat, 25 Mar 2023 14:56:05 +0800 Message-ID: <20230325065608.601391-4-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-Queue-Id: 4B70F180008 X-Rspamd-Server: rspam01 X-Stat-Signature: dw5fiuqd5dh4fb69oeq1pbc3y1d4xi8t X-HE-Tag: 1679727388-552728 X-HE-Meta: U2FsdGVkX1+RlpuncLafkcmZBYJZfxO0HKjKNChYF1wcT5RwaD9kvL/rQf3a1n/IjeX7/fkplxsBWA23168UK/o3rzwb75+oc1aUacM+jFFGj2ioOr2w0KYkYRvUNMYk5/9MpB4wqN/B4PNW2nRDcEEs78UqK1DhmhF0R9VyG1GGwwCqpxDpe+UpTTsJ8RkO3Z0ubsx9xWE4o6mnAIYSKw9QzGY32YuToJo4Asb9wcXu3qAWOwa1qAucpzyIpVgrJpyyOci6UBrc/8655pt4o8NYQgDAEDmGIjwWoK7n/mjZT5nk7FpeQ+60rzvAB+C/NJUigi+xEJ9Lv1Zb7kxJMEDMyg3Z2LUegBIiZ3TQCA+LTH6XPf5nT2oUz9xyvrc/qmMs3xKnpNeUl50GTDdllgXe7t/d6wvGK3JFRxyYO2PUPC/IeT63j00PUbefVHb1EuoJnY/4dAOyHyBwNkGwCRfE970y7vLUyxqMAwMqsqG0xBhHWgI/lgCSw5EmW3kbdii2k+DEWhwN8x5dC+up+Wgey6ozxl+W53fHV7WKbA9Z+Zi7mWH+TaFoPqxmkQoVWyQ50suegQ4j0TZjKiHhxmkN2Z/dSadvpsy37Zi4g3/d2UnT3d2ZfExzVLUJK1/KkIXLb4YwQhnh0W04sxj0i70OF+oauwK0Nu2rPa3XZYBnhqnOj3Iv+rXs5/qiMHV2iYOXiJ/QPC1U99IQ/oj2PPZNsQRaJrm6suk1nqqSolxYGwJpdQVVJ0DUufwRwusw0VaHNW/iKg+oFMvnqTEPFGynDxT43CPajfgiGU5duAASy/kE0nodi3Jxp3k1lBy3cC4nvyQcp5qjgvwLRWx71667l5ynAMCtsJB0I1eAAIap3RmMRY7DPOHemWin+sTDOHw3FUnhklKwaCnH2sUi8R7oVIM+3pRKwHQG4ZCvBMyVnmtMCCTZrdVLpAJnaH54IwnG9l5+O4MCOoNuDPl sKdE1/ww vEWiQEofIB+vhgfH4EMZvgaDm/R7HNQLS7eXvR8/+QKfa7a3Ki0VqMdHDm+SUtHXQG3Ox6/+9pG9Ux1WSJ284oBRb6q9gBt8WQY0gvwRDDMumyOVNRjcTamA/xK4atBxv2WW0ovkFVqIT2oppqeIkok6aRgld35RLP0QJnSSt3AEp3o2mFIR1Y/7Fo/fnLwG1PYJdEfllSkM7NvswjwlQbKz87qNijG0UCxo87gMXtVnaOsaevMh7iEmYy1p9eauArXUziFE7BnI9+Dhweam7EbknjeRNj3DP8Xf9 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 --- 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 1f79667824eb..69dfadee23e8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3546,10 +3546,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 07abcb6eb203..29ac064f69d6 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6201,9 +6201,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, 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 062bd215bea8..faf79742e0b6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5769,35 +5769,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 263191c37fb5..7b660bc07d71 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -425,10 +425,8 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, 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 Sat Mar 25 06:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187632 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 3D3AAC6FD1F for ; Sat, 25 Mar 2023 06:56:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30FD36B0075; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AD596B007E; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9106B007B; Sat, 25 Mar 2023 02:56:25 -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 AD1AE6B0078 for ; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BD42C0122 for ; Sat, 25 Mar 2023 06:56:25 +0000 (UTC) X-FDA: 80606511930.20.0A90D46 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf07.hostedemail.com (Postfix) with ESMTP id 7465540004 for ; Sat, 25 Mar 2023 06:56:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.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=1679727383; 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=oRwz+xRX6Nfd05rCK+Do5Pxu6vZ3cCmcUgEyPcDoL14=; b=d7Xnpf0xY1/AuMepVbI3nSezIQFYImzdPUl7uxjjnO+S7TuqQMynsRyQ7yYSIzti85j9Lx 1AbBrttbHoFpgGrWhFi6CV5BIYw99e7BCWPQV/Zz7Wr1NuAudqPplZ4KCKJ1ugdghlgkqR mW3IB7B93q3mXuVaAeBg70lo0Wka6yA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.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=1679727383; a=rsa-sha256; cv=none; b=CL4olg9DhJm1oSCrrZ3LPFU9T3WuiJtFfwHUmo9PNgSBkj9Ubc9u6Iey0MnASe5A9kjgBf e92vwX8QB+5wUAHGOORJkQcZEn/Dc5biYIMiKlH9kU1JiZsX04muJPvgVqd3i40roPczI2 pvJScGd5MFJGKG1g45LPXvahUHCE/L0= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pk8x53K6NzKnd5; Sat, 25 Mar 2023 14:55:53 +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:17 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 4/6] userfaultfd: convert __mcopy_atomic_hugetlb() to use a folio Date: Sat, 25 Mar 2023 14:56:06 +0800 Message-ID: <20230325065608.601391-5-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-Rspamd-Queue-Id: 7465540004 X-Stat-Signature: hbje7k48356i8114ydqzr5n8395c6b1e X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679727382-542441 X-HE-Meta: U2FsdGVkX1/kTI0wNxvLo0Kmn8d7RMb6IVS+I/9sB7UTjqi6GKHznlvfA6TfaDbPoyiqqz80b0hnww+jVZrnN0dmsY60uGqtgCvfBAB0b3Hd11eluZ1rqw+Lorp8osQTiAXbtgRObS8/NCnUP6C5ia/hN6+4FsduEfTr9XgHZvZ7/BhD7Hgu/xFUT1LexQOJ30P8QZt2YlQ5/l4C134LtCY8WTqNEHiDEUuKgJrmDFLhIA9kTCuE/hYEi+s8MXNrhMqAxh4m3MCZijDaTJsPMPTI4NSbXsHoDonKELpaOFOFA1+VE8bSgC3HZkC5in5vqpSTCvM51BZZPkIlWeNjxOv+uaubVPuCUZ3Ga+p4UxXE5NFi2YAaJPhKQkaOGwGMTbKvAjg5wkd6Gp5qmnlFWFGlDSX+TpfN+F/XeLoXA358ETEDGfVanxS7c8d/2jlkV5wZ6KSX9ADHk9Cw3pzfLYSknGUX83mnnT+gJgvbzYmuaC9uqzYgwKmUMJltf6LqzMzECXz0BtqBpoajVwDJoOQV9mU5hESIWAfk3ZbEwwA19F5T7+J6T4qM3pSZjhAmDT5Hupa/Ng1R4o5Kg7zj8waSTj+HzQjZjoiq6If2sH8K9xvwusi/8b7bRkYjQPZzCzAITImIvasvY7tTDzBJ8Q8UNVxfSPQKeyn8kz42eDhQNkl1/6ZBzx+4OOd7U+ZafZv/bJVnjQSKd0DthbTzqNnhp/m2jEHVuEYD3fInWxwH2YzW+DeN5pHFem5zNxf2nVOSbAcBemeBiMh+ZU7LTs5G7IGeoA+SwLcvwbq1pmoRmaf7RBL3TWKE/4UfSpoCXmwO3TyJ+jg8ELaridYjyPM2UeIjdO9untqjcsTDgPRzlGTSgF1IWhiQeLc3eKkvs2e4Y2rXnsw+lG+pke4StRGEAv+bEdeJIJh58G40oNSVgI1Tgm5FRBPAYVXJo5U1+r8Wr3KgtgNVe3MtQj3 307dtrby c8Lui3Q6n4YBImc5szm+6i7aUdM7UL6VB5b9ImoeRFf369y+CHhm+503WAgndh0PwwQrRZuJwY0zwP4BPPAL0Ev3q5pTDvjNGceVsNvsZEhzKyUBDgwYVvtmEdOo7ZBGPUvOOeED3ZjG7NOKcJJcO9irlU3T0KiXkYnLAfqjWSL1ddKainzHY9gbm+IbjQevpCbpIDgiAkkmqL2FbNEiqD+fve3uVjblYIFgffYdcGoxT/zFkHOkcSJOlkaXz4ofUpaNnG+bTycJRL4Dx2xGkmKTB6qsAg9qwtbEx 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_mcopy_atomic_pte() to take in a folio pointer instead of a page pointer. Convert __mcopy_atomic_hugetlb() to use a folio. Signed-off-by: ZhangPeng --- 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 7c977d234aba..030252ce51bd 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -163,7 +163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy); #endif /* CONFIG_USERFAULTFD */ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, @@ -399,7 +399,7 @@ static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { BUG(); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 29ac064f69d6..1cfd20e5fe8b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6163,7 +6163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { bool is_continue = (mode == MCOPY_ATOMIC_CONTINUE); @@ -6185,8 +6185,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, if (!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 && @@ -6221,33 +6221,33 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, 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 7b660bc07d71..cbcc7eb1d36e 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -324,7 +324,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, 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; @@ -344,7 +344,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, src_addr = src_start; dst_addr = dst_start; copied = 0; - page = NULL; + folio = NULL; vma_hpagesize = vma_kernel_pagesize(dst_vma); /* @@ -413,7 +413,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, } err = hugetlb_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, - dst_addr, src_addr, mode, &page, + dst_addr, src_addr, mode, &folio, wp_copy); hugetlb_vma_unlock_read(dst_vma); @@ -423,9 +423,9 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, 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; @@ -436,7 +436,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, dst_vma = NULL; goto retry; } else - BUG_ON(page); + BUG_ON(folio); if (!err) { dst_addr += vma_hpagesize; @@ -453,8 +453,8 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(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); From patchwork Sat Mar 25 06:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187634 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 8E4B7C6FD1F for ; Sat, 25 Mar 2023 06:56:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A1836B007D; Sat, 25 Mar 2023 02:56:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 42A096B007E; Sat, 25 Mar 2023 02:56:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28A456B0080; Sat, 25 Mar 2023 02:56:28 -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 0B5336B007D for ; Sat, 25 Mar 2023 02:56:28 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D1B0340100 for ; Sat, 25 Mar 2023 06:56:27 +0000 (UTC) X-FDA: 80606512014.10.E241894 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf01.hostedemail.com (Postfix) with ESMTP id 20E0140005 for ; Sat, 25 Mar 2023 06:56:24 +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=1679727386; 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=UwL4Bg0Qw6pK4CYuFcUzzrHTyPhckBc2IsYO9PPGgXs=; b=krpjoIDHwf8NhO4Bq9mNbLRsyx0hm1FyX+tWKW3FgRV97WQ7CszKltGhgNXB+pSZOGWyuQ i1/YycvSfEK+RnvgejlKe2lqmnCYXcKgSj8pREp7UhU6As/gFlxB9+JY6hcyWgx+Z2JaOZ 5PNIXxpPAkLg9iNGkTuCnhpL0mpf+wc= 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=1679727386; a=rsa-sha256; cv=none; b=Bd4zWtih/xVuoQ7UN/DVChjUEVXDZUVeP3P46UFs+nJRibONmIyMkj8ya5Wf84O1IbrhZv HTcDYNSG+oEGcv25vreslAYqAaHC7VoxZOJOSWU1C8ciQnbnk3wSuwqNF8+pdMI0OI1Wyw LEMIsXCrvfI5mBV8K9OilqTLZtQ8q/M= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Pk8sx0rzjz17NfJ; 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:18 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 5/6] mm: convert copy_user_huge_page() to copy_user_folio() Date: Sat, 25 Mar 2023 14:56:07 +0800 Message-ID: <20230325065608.601391-6-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-Stat-Signature: bnjzo9sqmyfcj69y3ui91zijmhktmyqy X-Rspam-User: X-Rspamd-Queue-Id: 20E0140005 X-Rspamd-Server: rspam06 X-HE-Tag: 1679727384-45073 X-HE-Meta: U2FsdGVkX18cW59sbbj9qVFoLi9YoAAZmnyDxfekKh8eaGVRV8DFp4LvzUQAtkgv/ZjFlOo8HZkPyJlVrK11/B5Ye3b0KNrn1mLijhqR/Snsw+Ba2EXLe/eD2Dq7+d2/0BY/jQyZSY9K2J0G3rBqyMY1P9hQ0wkRZqlhizAxWTiklUu0iuJD6A2/ZG5eeJ2e31unlVmVQ0nimzKFmJt7UquW2sPs2J2OMyPEXS03Lsc00JVDrGg6YQZTirLUuJmF/pDbWq5Z8Vl75x+Yiio/X9Sj52DDl737j2OfShvynDSdEYUUK4bcjxwWomLNzO5WJPxGXZbmdqOhuLlMizJurO3FDEPpMNb+5ot3dEjd44FCX6L4M8ND2X/xxHzyAzerPaj5WjzqzegxzSc+H+Thdx2h5qOW7+rK8urn5iTbFr4WBXuU1OHZPgeiMOG9/WUFUVDb/Lhcaj727XFGJXgH4E95OLYptrPMHCQ/OXn8WWcBowRlMfhxpBCllQziC2b2B0YrRNep+DGDxV9LlCWIu7mL8erSGN0Rd7zkCNDKAAfZwpKGPHDpmUjdenSwdHs2WFwZgPCg1J0L03taSqKscoZ2kKuidR8u9kSznLDd4CYzweoiK463Vf1y2lI9YiIWn1WxZD5E/qoCTa6XbiUpEKfXjzgCgHqF32eRYWfxlY+pABNHQVj4tKio8HkC9Km5y20ZVCBoi1hG9nDwDT0T+wBAnvi8dN16p1+k25NSCM+0LcI8dQo6qeV2ucQasa/7zAWJC7qa8Q5r0UGmRgvkj4xUiza9hvM8isc0RJZlt7at2GsbzO9512IB+vmMA05l3VwGtEX+MoBP0gNI8Qc7Dx6tlTXDAAxt+tSVD3S5tlTx6IIhAhGY9x7HLx7dKjE0sn/tOan+Mqee2qN1fBW3HR/oul9Yon1NfgPZDJWmSUKqhDZFL6w/q6CKSJ0B4o+aSU4YQzsY8ATWOrQfpw6 atW6Aabs znwjI8jNC2Z9TK9qjH3VjsirTZFoS05eQrkIYwB0YLxPaXpMBWfEnR9B+wCdw5WVgJ3AXU6sPoOa4fLTS9oTWAAb7+vMODgMBR0bGfbBaioHdXMLkZ/zxaKuLNkSpR6Xhou9p2jUIkmzEuBcjJz9RnPt2ZI6I6TjWDPxFqv8JC/Z9E8ftinJRIV3/37RzAOI6f8Tkwszy/r6jKquW2TGYjvJF2TOyY24ljWj/tpLpCpfBqEcIYAeWXPD3b1RN7kL5s7tpL91VyYbB2tkQN+Ufhxl/pQ== 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. Signed-off-by: ZhangPeng --- include/linux/mm.h | 8 ++++---- mm/hugetlb.c | 12 ++++++------ mm/memory.c | 28 ++++++++++++++-------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 69dfadee23e8..6a787fe66ea1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3542,10 +3542,10 @@ 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, + unsigned int pages_per_huge_page); 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 1cfd20e5fe8b..85657f9007ee 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5093,8 +5093,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, + npages); put_page(ptepage); /* Install the new hugetlb folio if src pte stable */ @@ -5602,8 +5602,8 @@ 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, + pages_per_huge_page(h)); __folio_mark_uptodate(new_folio); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, haddr, @@ -6244,8 +6244,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, *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, + pages_per_huge_page(h)); folio_put(*foliop); *foliop = NULL; } diff --git a/mm/memory.c b/mm/memory.c index faf79742e0b6..4752f0e829b6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5716,21 +5716,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); } } @@ -5748,15 +5748,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) { 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 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);