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;