From patchwork Tue Mar 14 13:13:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13174411 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 168FBC6FD1D for ; Tue, 14 Mar 2023 13:15:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E81888E0001; Tue, 14 Mar 2023 09:15:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E30F76B0075; Tue, 14 Mar 2023 09:15:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF9628E0001; Tue, 14 Mar 2023 09:15:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AA8006B0074 for ; Tue, 14 Mar 2023 09:15:38 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4E5E6A0BFD for ; Tue, 14 Mar 2023 13:15:38 +0000 (UTC) X-FDA: 80567550756.25.C70E26F Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf01.hostedemail.com (Postfix) with ESMTP id DF2AD40026 for ; Tue, 14 Mar 2023 13:15:33 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 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=1678799734; 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=D09GM7QbtBqbnekr7jAo+m9CKvn2vy59GY40fyJclAB3O5IG/rOhfY2PpLsNqx7ng0xrJ5 DoAx0SnsQCc9VBIt6GR7mJ7KkyQN48aaFozC+i/52prh+moTS4trhnJzvqqxNI/GZ7Yidn R/CX4Fcmbb14oxAn8Ri9o5qFHuzOhFs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 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=1678799734; a=rsa-sha256; cv=none; b=QNVVNvsYKpjsbki6lxQdjsDI1CX0kKM+rsN+NwLa2a7Io2kEJDPbkgqXEC4XLMmbqxNl3g gDRrwCw++S5GHWqttV4oCDzJmzLYC1eDXLx8EiTqRUDpX9gcd2RvB1PmQxOtnXctDJiaAW qCseZRwVw+Hr7dVKs0f+h38yl6LMKes= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4PbYsv3jx7zKmjN; Tue, 14 Mar 2023 21:15:15 +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; Tue, 14 Mar 2023 21:15:28 +0800 From: Peng Zhang To: , , CC: , , , , , , ZhangPeng Subject: [PATCH v2 1/3] userfaultfd: convert mcopy_atomic_pte() to use a folio Date: Tue, 14 Mar 2023 13:13:48 +0000 Message-ID: <20230314131350.924377-2-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314131350.924377-1-zhangpeng362@huawei.com> References: <20230314131350.924377-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: 8yp1t441rtyqazjdwaca9shb6zsfb5mf X-Rspam-User: X-Rspamd-Queue-Id: DF2AD40026 X-Rspamd-Server: rspam06 X-HE-Tag: 1678799733-52398 X-HE-Meta: U2FsdGVkX1/77A/RY5kXumRGIAjB9aw87JcpXkI8zvx2GHxnd4hfxkydsmN07ZpgC4RAC8Ua+c0Z6glcxp+OTlXOcO1p3EpZh6woytC+0JFA8bNxzwAkYI94kfrkHpB/CeL6k7Q/PNZkYJt71nnu/Jlt4J1u/0GUTWUWsJ1gYGidg+EhdorY+fjqBad342rdVbJGPnHTlWWiPpTHk/UclW33MJ9nPABzKzls4AOgJRiRen0L0YJmZ/GfMNn1x4ccFVC5r32RiTnC5fV8Y99wJcLuHH/fXGgVyWUIqyXy/0401RDqyGrasQPNNXqEkPaek5mVMnE7IyLi5jy15dTOcJsiIuVdDr4zsxMy8IpvWmbwbY6x1SlQqIuBsvoSLRqc8fru9uF78gtv6S/def8is77UJSBBzoKCENTCgcV0/FEFJaSRgEkcJ4C/WITJWvvT6RS+IzHYyXKff0HIbdebEL3Y656YdZqBfgs4YDRn9CEcJ7Ctd6En3tvJwUI/PRNujMFRhY4YYItN4Y70lL2faHhHzY41VXx8J72x9GFTdqGdiuk/lu1BlUP84yTHW9/i7f0+Rf3xHJs0H/cUvAMvKJwn0+2WCrR5jHSvHB99zkJcJkRTwcBo58yPgo0ONft1Zb/G+oMEEShRYEkHPKD+ewRTjiPszpZhW5qwfkJov3dvNUMBpJ+1mU63rotn6gAL7NYoANq8s71u/kkAuj+Kg+Te8n1qLw55amgrOv+ll6lWG7Z7rKcYjKvLc5BU492xd1tjh4AA/JmixT2pdSuNjeHCqqNGBy0QYDkjeZbTSjtPGzlttlXiVAmWhZGDV+p8LQYtMYDPa6A/Mkam5IGapoUxiVeEPcBjEyMVkszNOrursD0OBGmEtGIKlttsFNegQYx381llL6B1dEUpKQv3SzGZ7BS96DiywZkao10eQi7cN+QGDtV6mFGTXPdFgMWmq57Ot92IzfhJ0ZYHmLx Y5KSde8j mUx0zKUhlzP2mOnMzRBEEn5P39stVAqRrh35GGidyXpiJVYZWTp0SmgoM/omtdlwvu1/v6qrxqSnKaKEAGkXfaLWoXQJTxS13ReyeHHKnjJ2rbroh/g7237ypObIQ/Qf50ifOwlecYkTUEoLqS+wPUpYT0bMlQ3Yn+YfNeu+HEZBrKFWynHMJ8lLuvra8f0Io5dJ303wt46FGrSmN4f7oVsTR62z2vr2UtCBTzIvL+zhUKxTSqQHJT40CEHtGkDfgK1N0/7N+t5AHU6SD5TjC6kyoFA== 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; }