From patchwork Thu Mar 30 13:40:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13194194 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 5EC24C761AF for ; Thu, 30 Mar 2023 13:41:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F06AA900006; Thu, 30 Mar 2023 09:41:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8C24900005; Thu, 30 Mar 2023 09:41:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C927F900006; Thu, 30 Mar 2023 09:41:43 -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 AD7C2900002 for ; Thu, 30 Mar 2023 09:41:43 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E879F1C6629 for ; Thu, 30 Mar 2023 13:41:40 +0000 (UTC) X-FDA: 80625677160.08.F17904A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf14.hostedemail.com (Postfix) with ESMTP id B42CE100003 for ; Thu, 30 Mar 2023 13:41:37 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1680183699; 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=ECjVASrWJxczVOli1Z/HrBt3MPaQ/5CFM40MrwtxHk4=; b=skqneaL6BCsXMZFX77FzLIV7+TY1Q3PiUKL0Juob26WoLqwKhimCeCtnXa95Nb7kxT11eC VFoCxYMQV7p4S1Bk+Y3aGmXeKQHKefJln9kGqgxBV9dkJ5sUidXp6eMSgtkNdM1bCPtEQu XNM55b3EovH6lCtAs6fYbWxRqwtPmFk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1680183699; a=rsa-sha256; cv=none; b=IPwQCux9hr5Ci6dch/wS8qJCcHGxd3+6vWTjxwy+/0kQhsW1TdVmv6dLB53wtLbC/s3U5z rwLj17NzUCgvoXEzvU+MvmHK0JHS9FV45jfYVrrD0W1QY+nSRj70Vv4sEzIckPq+jfo0tu j+ZFq3QAsA+AG8Uv3OttksDhdgC8CO0= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PnPgT5JJhzrYdQ; Thu, 30 Mar 2023 21:40:21 +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; Thu, 30 Mar 2023 21:41:30 +0800 From: Peng Zhang To: , , , , CC: , , , , , ZhangPeng Subject: [PATCH v4 3/6] userfaultfd: convert copy_huge_page_from_user() to copy_folio_from_user() Date: Thu, 30 Mar 2023 21:40:42 +0800 Message-ID: <20230330134045.375163-4-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330134045.375163-1-zhangpeng362@huawei.com> References: <20230330134045.375163-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-Rspamd-Queue-Id: B42CE100003 X-Stat-Signature: jhaeoqsaaeryforbykqkethe4ehqz7nm X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680183697-948648 X-HE-Meta: U2FsdGVkX1/FOGZvG3NyUQb5/WZfXjFesTa3rjx6V0j6f1ZV502bOZ9kssfexlvXaoPFi1JJS8rhZv+G4ruVobx1OjTKp24ivzINnhB8zbY1wOTR/ELoVrO3feIIo3qWQh8shkSOJb2smhshdIGUGY97YCxZG20tsNfZ5SYR1cd0tPlnrErod/hllVfBINs6kblxg5j5N6gtNoC+l9pXm49ZXpatTSZPFSFFSYdEfYo/rheQHelDsj42vHsxbruJATYPs+CsDGUoxrb/aaY29BZOamCYczYDV+hi8x4mTM9J7KSNY1Cu3DOU74+XegjGAYmTt6K/UNj3RhAfoDH4s4kZOnnBsdu1JEcEfIly6vuUm+pzioor56rcs/9X6IEhIqVpxqPltcxTSZelW/a5PAWqHcWvP5zLRg+gz1eForF+lADlc1Tg79+KIA17E+ymQdsh1O6EcaIEdCWaa4qigHUUcFJN+b+rJN2BDvDJu5qW+E4Ius/Xfvyf2HAf4cPeyjUQ7BQlj7SktvfVZYLZUri9tn2yLFMmgi4dtPW/Oreo+QrQ3pCCgQ/nsYpLRQYI2Klu3uz2xdA2BHNWm56XnPXkT/MVInegcfueU9Bh1h4gSE25qk2pNldfSViOOPyKal8JodII+4MjhKEoWa59Hk/F4qnY8YNsOjW9rbbdskeSJSEyjiToZw3924geO1TL2vCCCbu74oDcHWFPrsz2fRhuQnyfo02i7TrJhItEtGg24Ml09IezvbpS8RcsL88bLyjhqBfjYM4a6wPCreIx9wi9ElsU8z15H57CBp416HcWKU3K6tJBbpNgDoCGH1cQlHCp0L9YKbemNpW6QL5RS5t+06QeZPncVmhhmUnZtRiGXHhzaaS55XQy9ya6AvOL8oGoKfaOG2nJObHI2mPu5Tz26RwzgMyfdNQclY5QPUica4XqJU3H8kZa66E8/0u6r+n0HRhgXtQIj30dZjX 4w5ScY2u uZ8pFVIMci9DkzdGiOEEReohs+jLjtPIe1C/6sl0tjgDz2i/qAQctNO8zUf450CirUxQ8pvR7eVmO6PN5f/8JBu7CnGt6R6bHBir7XERXeD3DvtZHRdvkMlz3ef3WjSL3jAE5bnPuzMhdKhJc+6rVS6j+GvI+MfZRvYvEtI37XnFrdRx0tkmlTCSJLgIMn+YflIq2js8OaYgY3HPhPkTWF+iKQDAlwX419hXe3wQG0oBGcF7+/zRD+yKkJzDkYKibzzZLl9y4sITkZgJ12Bccw7OC6yKC5EMVsvhZ 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 --- 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 c47b8991410a..9d59dad319b3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5854,35 +5854,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 efa9e1d681ee..b453a4d2a0d3 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;