From patchwork Sat Mar 25 06:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13187632 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 3D3AAC6FD1F for ; Sat, 25 Mar 2023 06:56:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 30FD36B0075; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AD596B007E; Sat, 25 Mar 2023 02:56:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9106B007B; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AD1AE6B0078 for ; Sat, 25 Mar 2023 02:56:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8BD42C0122 for ; Sat, 25 Mar 2023 06:56:25 +0000 (UTC) X-FDA: 80606511930.20.0A90D46 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf07.hostedemail.com (Postfix) with ESMTP id 7465540004 for ; Sat, 25 Mar 2023 06:56:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 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=1679727383; 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=oRwz+xRX6Nfd05rCK+Do5Pxu6vZ3cCmcUgEyPcDoL14=; b=d7Xnpf0xY1/AuMepVbI3nSezIQFYImzdPUl7uxjjnO+S7TuqQMynsRyQ7yYSIzti85j9Lx 1AbBrttbHoFpgGrWhFi6CV5BIYw99e7BCWPQV/Zz7Wr1NuAudqPplZ4KCKJ1ugdghlgkqR mW3IB7B93q3mXuVaAeBg70lo0Wka6yA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679727383; a=rsa-sha256; cv=none; b=CL4olg9DhJm1oSCrrZ3LPFU9T3WuiJtFfwHUmo9PNgSBkj9Ubc9u6Iey0MnASe5A9kjgBf e92vwX8QB+5wUAHGOORJkQcZEn/Dc5biYIMiKlH9kU1JiZsX04muJPvgVqd3i40roPczI2 pvJScGd5MFJGKG1g45LPXvahUHCE/L0= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pk8x53K6NzKnd5; Sat, 25 Mar 2023 14:55:53 +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:17 +0800 From: Peng Zhang To: , , , CC: , , , , , , ZhangPeng Subject: [PATCH v3 4/6] userfaultfd: convert __mcopy_atomic_hugetlb() to use a folio Date: Sat, 25 Mar 2023 14:56:06 +0800 Message-ID: <20230325065608.601391-5-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-Rspamd-Queue-Id: 7465540004 X-Stat-Signature: hbje7k48356i8114ydqzr5n8395c6b1e X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679727382-542441 X-HE-Meta: U2FsdGVkX1/kTI0wNxvLo0Kmn8d7RMb6IVS+I/9sB7UTjqi6GKHznlvfA6TfaDbPoyiqqz80b0hnww+jVZrnN0dmsY60uGqtgCvfBAB0b3Hd11eluZ1rqw+Lorp8osQTiAXbtgRObS8/NCnUP6C5ia/hN6+4FsduEfTr9XgHZvZ7/BhD7Hgu/xFUT1LexQOJ30P8QZt2YlQ5/l4C134LtCY8WTqNEHiDEUuKgJrmDFLhIA9kTCuE/hYEi+s8MXNrhMqAxh4m3MCZijDaTJsPMPTI4NSbXsHoDonKELpaOFOFA1+VE8bSgC3HZkC5in5vqpSTCvM51BZZPkIlWeNjxOv+uaubVPuCUZ3Ga+p4UxXE5NFi2YAaJPhKQkaOGwGMTbKvAjg5wkd6Gp5qmnlFWFGlDSX+TpfN+F/XeLoXA358ETEDGfVanxS7c8d/2jlkV5wZ6KSX9ADHk9Cw3pzfLYSknGUX83mnnT+gJgvbzYmuaC9uqzYgwKmUMJltf6LqzMzECXz0BtqBpoajVwDJoOQV9mU5hESIWAfk3ZbEwwA19F5T7+J6T4qM3pSZjhAmDT5Hupa/Ng1R4o5Kg7zj8waSTj+HzQjZjoiq6If2sH8K9xvwusi/8b7bRkYjQPZzCzAITImIvasvY7tTDzBJ8Q8UNVxfSPQKeyn8kz42eDhQNkl1/6ZBzx+4OOd7U+ZafZv/bJVnjQSKd0DthbTzqNnhp/m2jEHVuEYD3fInWxwH2YzW+DeN5pHFem5zNxf2nVOSbAcBemeBiMh+ZU7LTs5G7IGeoA+SwLcvwbq1pmoRmaf7RBL3TWKE/4UfSpoCXmwO3TyJ+jg8ELaridYjyPM2UeIjdO9untqjcsTDgPRzlGTSgF1IWhiQeLc3eKkvs2e4Y2rXnsw+lG+pke4StRGEAv+bEdeJIJh58G40oNSVgI1Tgm5FRBPAYVXJo5U1+r8Wr3KgtgNVe3MtQj3 307dtrby c8Lui3Q6n4YBImc5szm+6i7aUdM7UL6VB5b9ImoeRFf369y+CHhm+503WAgndh0PwwQrRZuJwY0zwP4BPPAL0Ev3q5pTDvjNGceVsNvsZEhzKyUBDgwYVvtmEdOo7ZBGPUvOOeED3ZjG7NOKcJJcO9irlU3T0KiXkYnLAfqjWSL1ddKainzHY9gbm+IbjQevpCbpIDgiAkkmqL2FbNEiqD+fve3uVjblYIFgffYdcGoxT/zFkHOkcSJOlkaXz4ofUpaNnG+bTycJRL4Dx2xGkmKTB6qsAg9qwtbEx 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 Convert hugetlb_mcopy_atomic_pte() to take in a folio pointer instead of a page pointer. Convert __mcopy_atomic_hugetlb() to use a folio. Signed-off-by: ZhangPeng --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 26 +++++++++++++------------- mm/userfaultfd.c | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 7c977d234aba..030252ce51bd 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -163,7 +163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, pte_t *dst_pte, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy); #endif /* CONFIG_USERFAULTFD */ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, @@ -399,7 +399,7 @@ static inline int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { BUG(); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 29ac064f69d6..1cfd20e5fe8b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6163,7 +6163,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, unsigned long dst_addr, unsigned long src_addr, enum mcopy_atomic_mode mode, - struct page **pagep, + struct folio **foliop, bool wp_copy) { bool is_continue = (mode == MCOPY_ATOMIC_CONTINUE); @@ -6185,8 +6185,8 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, if (!folio) goto out; folio_in_pagecache = true; - } else if (!*pagep) { - /* If a page already exists, then it's UFFDIO_COPY for + } else if (!*foliop) { + /* If a folio already exists, then it's UFFDIO_COPY for * a non-missing case. Return -EEXIST. */ if (vm_shared && @@ -6221,33 +6221,33 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, ret = -ENOMEM; goto out; } - *pagep = &folio->page; - /* Set the outparam pagep and return to the caller to + *foliop = folio; + /* Set the outparam foliop and return to the caller to * copy the contents outside the lock. Don't free the - * page. + * folio. */ goto out; } } else { if (vm_shared && hugetlbfs_pagecache_present(h, dst_vma, dst_addr)) { - put_page(*pagep); + folio_put(*foliop); ret = -EEXIST; - *pagep = NULL; + *foliop = NULL; goto out; } folio = alloc_hugetlb_folio(dst_vma, dst_addr, 0); if (IS_ERR(folio)) { - put_page(*pagep); + folio_put(*foliop); ret = -ENOMEM; - *pagep = NULL; + *foliop = NULL; goto out; } - copy_user_huge_page(&folio->page, *pagep, dst_addr, dst_vma, + copy_user_huge_page(&folio->page, &(*foliop)->page, dst_addr, dst_vma, pages_per_huge_page(h)); - put_page(*pagep); - *pagep = NULL; + folio_put(*foliop); + *foliop = NULL; } /* diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 7b660bc07d71..cbcc7eb1d36e 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -324,7 +324,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, pte_t *dst_pte; unsigned long src_addr, dst_addr; long copied; - struct page *page; + struct folio *folio; unsigned long vma_hpagesize; pgoff_t idx; u32 hash; @@ -344,7 +344,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, src_addr = src_start; dst_addr = dst_start; copied = 0; - page = NULL; + folio = NULL; vma_hpagesize = vma_kernel_pagesize(dst_vma); /* @@ -413,7 +413,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, } err = hugetlb_mcopy_atomic_pte(dst_mm, dst_pte, dst_vma, - dst_addr, src_addr, mode, &page, + dst_addr, src_addr, mode, &folio, wp_copy); hugetlb_vma_unlock_read(dst_vma); @@ -423,9 +423,9 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, if (unlikely(err == -ENOENT)) { mmap_read_unlock(dst_mm); - BUG_ON(!page); + BUG_ON(!folio); - err = copy_folio_from_user(page_folio(page), + err = copy_folio_from_user(folio, (const void __user *)src_addr, true); if (unlikely(err)) { err = -EFAULT; @@ -436,7 +436,7 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, dst_vma = NULL; goto retry; } else - BUG_ON(page); + BUG_ON(folio); if (!err) { dst_addr += vma_hpagesize; @@ -453,8 +453,8 @@ static __always_inline ssize_t __mcopy_atomic_hugetlb(struct mm_struct *dst_mm, out_unlock: mmap_read_unlock(dst_mm); out: - if (page) - put_page(page); + if (folio) + folio_put(folio); BUG_ON(copied < 0); BUG_ON(err > 0); BUG_ON(!copied && !err);