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;