From patchwork Mon Apr 10 13:39:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13206373 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 D3ED6C77B73 for ; Mon, 10 Apr 2023 13:40:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 204D328001D; Mon, 10 Apr 2023 09:39:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1670E28001E; Mon, 10 Apr 2023 09:39:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F220A28001D; Mon, 10 Apr 2023 09:39:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D700528001E for ; Mon, 10 Apr 2023 09:39:53 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B7492C0291 for ; Mon, 10 Apr 2023 13:39:53 +0000 (UTC) X-FDA: 80665589466.20.FC58F09 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf29.hostedemail.com (Postfix) with ESMTP id 239A9120014 for ; Mon, 10 Apr 2023 13:39:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 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=1681133992; 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=eno+lvlVBcbmVoJeIgVpKFLX7MHDI7aFgQ3DXfqcW0Q=; b=XDy8yXm6IqfFxJs0wiS9FocBTckrbCbOq47i32+j4u9KXE56UzK3B1C24EVj8iXtEygJP6 4cgkxVbC7V9/lNE2Hsp/1ixRvVr7IJgf0Nv8HjuvDmggbo6vOmeHCDiHIXOMqvVRL+R3wy m78nKj9j2LH177P5xy8SBsYUmY4/5BA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 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=1681133992; a=rsa-sha256; cv=none; b=AExwJLl5IDrB15Gm3IxDVx7V5dI7DFF0xB0uuRzPIMaMz36u9B3wzwwYFXn++/wo3u8A6Y I3rlacrXdQcV/ANEg0qr3N8pqhMtxnGMIVUg9Ww2z1VjnBW6Cf2Jm9Q59i5W12finnU4/b rsW1KjnN5we3+YaQQskSk6/Y50ZWmzc= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pw94k2nk6zKxnl; Mon, 10 Apr 2023 21:37:10 +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.23; Mon, 10 Apr 2023 21:39:41 +0800 From: Peng Zhang To: , , , , , , CC: , , , ZhangPeng Subject: [PATCH v6 3/6] userfaultfd: convert copy_huge_page_from_user() to copy_folio_from_user() Date: Mon, 10 Apr 2023 21:39:29 +0800 Message-ID: <20230410133932.32288-4-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230410133932.32288-1-zhangpeng362@huawei.com> References: <20230410133932.32288-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 58gg8r7f41cayoux311emciph47c9hkj X-Rspamd-Queue-Id: 239A9120014 X-HE-Tag: 1681133990-337332 X-HE-Meta: U2FsdGVkX18MOsI60FLn6BGxPPYJ+Se1pvSaiUYNNRRMtpWpdEYT/GVHOJc+KyWB3/ZYwojEWaEFdUiVq8P6cYXgB9TT05vb7JCqEMKMPkaerXKcoFpyuKRtyMkBKPLJ+0aXaXHgZbxUTxhhMHnZz0PEjnZoFJ0geg/I2PmYoXh8SEBEVUyRdVe1O2uQbnnZlkO33iWH9oHj+ptknMttCD9Zy5Igf3sSHPDs/b4l1h2OoPiHkaGsLA4EW3SsuXL5huyDA9HZjJgeOPU33yqgZfSJtw/XFY0RenWaJkgIpZGcCARvcZ6yjFh806wFQrFTWGSCJeHx38/K/HEw0O9ThajS3ozC5PycgvBfAcCi7MHcojMgyearw8U+19vc/dCZOsNee7frD/1QdPQmB9/WAWdDLLBLwWI8jpQPeNizgd5FodQ8tfb+9yHTpCsDxyyOcawgg2HkRrtKeINEozbjlxV/pt/xZg79ji4WYIfGdTU+5ohdW4y7AshYUzD7TAU0WvpwMHmvAqnapEy0U6dAEx2nX0xU0i2VbJGukU+zyuXae6qk/362uSKLICl4wxHeSJ/y8qp1SqUmRHTnq1pF+RHUpHYJmJA3LTxJwTivlCfdjwMcpvhhUdZl5KReiJGMZT6SA9XV7rAv1rdNlEoziaRgIOy0UQD09fPhr6zgI1m1fXQI5SPpdzpVmHehZuCOEj9pH8gO4qrOT1QBja5XQnMMD7VGhUeeCpCXUjF3Ukp73Bl6WaFR7rIH5RYc5Rq/2W8YLcp0FjgGRizIYSFHobRs7z7uaFobhic0fenOVZD1rSTkZOJiG3ER5Ei9gn5+2ZeQGaxDgs5i4mJ1CDoGZjHSISoHbv3QAiV/prxGyabWBFkcQofi/dKDiS0IsQbWbBo1rqDYOr1G9eEvsaWJAy2b7wmAuWXeGVj60nZsB0MXMAiWGIUCWRBpXumV7HS56YQX6kWeDyFlYlJ8v6+ 7F6D4CGw 6yIATFyZ9lv4Hc5MtHXhVDMiaRwqz5JdmnWp3Qzii4ZAtHpBIFB3ouINTKStJlbwpNQ+zSWj+ZC2nA4p+6IP9oX8DWGiv6ZE6tUF35Zt0/OyvtWUy7BM3Yik0yhY9jt70fzmOpOpbJKDqes3jBk3VgqhY8PJHK83Ro4jP+pDKJODQtmqsrPuQle6xvutKppF0dJftNA2qQTPwSyjw7gqA0+eyXai4UDTWSnkfynP/lQ9uPoJ0VJwPWwpyA23q3o2/jtb+ZzIaPO5/yN/XSKobIP6fK8uRlDtk3t/pPjTaXlpkbPgnW4c8p3iasQ== 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 | 23 +++++++++++------------ mm/userfaultfd.c | 6 ++---- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 243bfba378c5..a978413b40a4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3698,10 +3698,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..021cab989703 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5868,26 +5868,25 @@ 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) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 313bc683c2b6..1e7dba6c4c5f 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -421,10 +421,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;