From patchwork Tue Mar 14 03:37: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: 13173596 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 C2553C7618B for ; Tue, 14 Mar 2023 03:38:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DB346B0074; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73D6E6B0075; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5419C6B0078; Mon, 13 Mar 2023 23:38:32 -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 357696B0074 for ; Mon, 13 Mar 2023 23:38:32 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8752B1C65A1 for ; Tue, 14 Mar 2023 03:38:31 +0000 (UTC) X-FDA: 80566096422.11.B3E4505 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf09.hostedemail.com (Postfix) with ESMTP id 5725A140013 for ; Tue, 14 Mar 2023 03:38:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.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=1678765108; 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=6oJMzVG7P+5+cxUdC4PKSyl6xRdo3Fq/TYwlZgYEA8rD9saJ1ui9dkHz+eoYcrrjcM7MmR LT7ghXzGa+3hBkrLPT3UhkhFTnX0LaBLmS41BkEsAng0silUtp/CMTZy2GzfX8kl3Z9mRU eNf/o5GYars4gn1TrWdSqdIg0G6cyFU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.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=1678765108; a=rsa-sha256; cv=none; b=VaWGYLWQojSCGlDQla8li6nbjpqW7/dRtvlB1qVtni68mF8Fr3DGZPiBMg/Jt+aZ/DXr2M 9/Z394CxdZYEcwN1tF0Mk+2zFPnQ2Yf4oGcM4W+t7s4yr2NBTkbeyiqctKVx+ZHx3Ci/Op PBsli7KS+UstW7DJ2b+wNKn7+7QDLJM= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PbK0r66w0znXQk; Tue, 14 Mar 2023 11:35:24 +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 11:38:20 +0800 From: Peng Zhang To: , CC: , , , , , , , ZhangPeng Subject: [PATCH 1/3] userfaultfd: convert mcopy_atomic_pte() to use a folio Date: Tue, 14 Mar 2023 03:37:32 +0000 Message-ID: <20230314033734.481904-2-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230314033734.481904-1-zhangpeng362@huawei.com> References: <20230314033734.481904-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 5725A140013 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 47dcg3iyitsq6bijpe7ygnr5kuo4a4f4 X-HE-Tag: 1678765106-135382 X-HE-Meta: U2FsdGVkX1/5cZMmXlYfpyJdp2zvSa/gDvj+baWptJSuKt4fPrntwU2hXW18JSQfasyia/nChV0M39atO0zPKJKuZW9EI9K0wQIqvw52kcyGFBT43pY03salgxhBftZVrDhH5lSo7efwSNEHwreo4KBnCBpuVomKv22BQSCvO5+2vk1gdBEemB8PZUTM9LnW6PTofkdMAHyDXSfcH697VyF6BSZkmXUzvLoHMY2T7c24dBLQnFPuG3BWYy5AJSFUGvZP3ELWHAEFlICWM4NH9IfeVMEJzrbqXG1HgrrZZPr6HHRiri33HVlzwaaGqDaXKO8DR5WXFDVgmnaRcATMthiK0/YwwQthNOsY4ernt34uj3841ML/Bnk22LSdwJK/KygkhEYi/Ay7yKigvXkQoVQSYnuj0wRajd5Q/3ct0J9/EB+MNgPcFUNHtkbx68sljw8/vclggNfIECuyq5qo8iS/4RMv1GsnIoB4mZtEfWr+sqMtyeips65hjYuhdP7AlBUJUr9f30Sirz+FYt8Lrf1GBbxJ1JnIiGA4M3KfYaMAgrnUek2JKgdjNJh18E9bswQ+SF7l9YLC8QxK75s8aCXGxC38xVDlIs83BaDRMCQzIKjKMc1USsn1WwswKlt1zfMRF4mJTOlRAfVjo3pR10+Se7HeL7a9mxpAYhSGDAsLdYZ5+M08somRJCHuNF6qdtkad26C/XPlbRoP4PaVNvhcPvMMjLDJ0Blz8waSt90INFxe81qgE9vaGnX6N9R0sE31fkXLTjk4SbNwIo9w9YBF45c+samCYTOSi/0ro4qemqTE6zb1KFjhPyR1G7REO+dx7q/LDuiygd7nkad9Bs4lEx7wDNRCzUmVNRLe83eGKOt7dkiUv9+r+yX8+w9wL8tSL5JwYyXNu4dYohviRhXCdLfBGUmauk4owrMrqIKEWGU4oFLegaOpJSIbVub1wXswHs2KazNhn7V1/xs DBAbLzcf ZbF/kMzfEj0jgy8FT1i3ISEG5+0zOaLCXOpAqlZOfZwT6W4+oVg8USkh7Im85sL2fR26+zJiBp3DhvlI40yAivsQFWYDPK6WHAJKyTO0+iVGb0weUiPQ/e4NZrln8rnpDRa+8Ch704uAxvh75WZmLJZnr0MJMO5WMTU1s8svb9fPU/iS9BPnPbANkP3CtVs84EGXXfGQebn3DSc6vfnicPHGcLJwX9+i2pDX9O4LsD8t3fxODSm1KfCLCRz5O9ii+wT7N1VZ7fcBPBHY31Namcl0kxw== 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; }