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; }