From patchwork Fri Apr 14 13:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13211463 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 B2F11C77B72 for ; Fri, 14 Apr 2023 13:03:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB8CF280002; Fri, 14 Apr 2023 09:03:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A42F5280001; Fri, 14 Apr 2023 09:03:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BBA1280002; Fri, 14 Apr 2023 09:03:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6E980280001 for ; Fri, 14 Apr 2023 09:03:35 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CD98880282 for ; Fri, 14 Apr 2023 13:03:34 +0000 (UTC) X-FDA: 80680013148.27.57C4156 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf21.hostedemail.com (Postfix) with ESMTP id D67C91C000E for ; Fri, 14 Apr 2023 13:03:32 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681477413; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmVsoaJZusWox27eQw7cLPcmlW527fQj6sB0NN1MuqM=; b=FhwS/dhcJmKLO+e5sfnmTDRBoFlUw8RNZwD7ucRYSC+kIPW+H/Kb1KPqZpdyb2vxAAZ10a YFQOhCweoef05/ZuwG5XTPY/sJxDF9G5bufmpjpX7fqslyAm778c0SUS0JR6pRsLG3pkyW xaawZKUSnHGXbcajHmOCNN6qPwRdiq8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681477413; a=rsa-sha256; cv=none; b=BKs7MQuLw4X3gUB92cnMSA7go2p5XOep7RbE0cg17pShKcMtEyskLAOzYktkRQmGHR5jL9 xL7NfJhqN7pn/iAXMmX90VOH585o35wRBoMG9HWtW/lK1dFJEtkmJEQjoHWb34zLazj1r/ 5T/Tg+xKZVtZGC+49CIt6vYIo7LjXGM= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE8F04B3; Fri, 14 Apr 2023 06:04:16 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 661D03F6C4; Fri, 14 Apr 2023 06:03:31 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao , "Yin, Fengwei" Cc: Ryan Roberts , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v2 PATCH 11/17] mm: Split __wp_page_copy_user() into 2 variants Date: Fri, 14 Apr 2023 14:02:57 +0100 Message-Id: <20230414130303.2345383-12-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230414130303.2345383-1-ryan.roberts@arm.com> References: <20230414130303.2345383-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 9u8w3m46qcti3fcgdcctgrq84cfi7fnf X-Rspamd-Queue-Id: D67C91C000E X-HE-Tag: 1681477412-869745 X-HE-Meta: U2FsdGVkX1/vcbS6jzhioF6AlfWrlD+0HiLCqAZkhOILGpY63sUDkGm0cw+Jg6PiOV91hwx35tWSjFp8faZQnvB9u1m+nvK7hPSVXXVYHG/nozPIEY9/lgzgUmX24aRMEnahK/vzNykQSJwdFQj/y8f2gvOh+kQwwO1bvz2pFEXHrs5MrNSlNar3cvxIYZz1z3flRJmC+CYC7+2iHblMCzjuM0mXX3NtfMRanSeQ6qJipHdbd7q9Zst7KK+ZdhaFIP+qpCal5RBx7K2PU0B56sGe+j7jiMaDO08nre97nUo4EgI9eS5YW3k3jGOlUC+mh0DOA4sH0zxxpIhF9x8tb3oO0XtVYyiV5RCbeUByWo+wT+jbquip9URJe1JCCn19vzr2BZa84Ty86KESAHCgH0KzEVHN8rt0THuQpXCFnyYGKNKZ3RMf4usYJR8WqKes2q/RmABae3QCelTpOLDLqw/ofaILtWX19I4MuWJ36uf9pzUej8mr3hDUfjMUSgDX5sXVNLIjhtQUEvmXQv5wrHdgDEeIIWR0/xk/f21uiG5yfo5tDk84PL4XnbQGRiYMGyVIhQktymOaVAoaIbO2dZef0CvhVh7JE2rbiheZPHnvx+o4p61QSgh2l4tV2b3+KvfZPLltwriqXBi4DfdTxdOgwexVwnj3UzJPJK1/7d7zG8eCwYfREkNm1c4YHzm3jia6FJfiC/DG0UIsaxV8/a2XVy0Scpg9RmUvRZVl+BzAXnEjRz4lVqOSnSrcDTRzUjozfQZZsvnUjYOgUQe23dJM/fjT/lG/aandHmFsubkXtNNFnKcmQliCBttS90mZiDYBjCzIx7Xh0I6nyklksCYhDb3Z/X14MtutYDQixT7Iyb57TPvTSVSULAc2SFyKuHe2L/CPHGj2e+XQ4pHvwtFmLOWjVEiuZdRXlNLD6+p0Dd74BlNoACGrGofqMn6cE45WGUzziMS5BN7ai1z AkAxAzDr WuBWBq0Mlv/eKf8ylqYanb9/4gD9l2HabIeXh6Ajk7GOby6m85UGqAb+1rRwDP33zEROqThWhg8t9tvqIdoomdCDYjNPKCNtGP+xVIIZLtFqHixOvZ7VDLwisL8d51DLzh1euLv27uS73QsBxE0CRF8IfKXDi+j78LA7g51YhDMQFqCXLdmwVM9uahlCZ0BFEs1XSp9Jx47GrSXTRBB9o2Hw1DGSGJnIMtwrb 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: We will soon support CoWing large folios, so will need support for copying a contiguous range of pages in the case where there is a source folio. Therefore, split __wp_page_copy_user() into 2 variants: __wp_page_copy_user_pfn() copies a single pfn to a destination page. This is used when CoWing from a source without a folio, and is always only a single page copy. __wp_page_copy_user_range() copies a range of pages from source to destination and is used when the source has an underlying folio. For now it is only used to copy a single page, but this will change in a future commit. In both cases, kmsan_copy_page_meta() is moved into these helper functions so that the caller does not need to be concerned with calling it multiple times for the range case. No functional changes intended. Signed-off-by: Ryan Roberts --- mm/memory.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/mm/memory.c b/mm/memory.c index 7e2af54fe2e0..f2b7cfb2efc0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2786,14 +2786,34 @@ static inline int pte_unmap_same(struct vm_fault *vmf) return same; } +/* + * Return: + * 0: copied succeeded + * -EHWPOISON: copy failed due to hwpoison in source page + */ +static inline int __wp_page_copy_user_range(struct page *dst, struct page *src, + int nr, unsigned long addr, + struct vm_area_struct *vma) +{ + for (; nr != 0; nr--, dst++, src++, addr += PAGE_SIZE) { + if (copy_mc_user_highpage(dst, src, addr, vma)) { + memory_failure_queue(page_to_pfn(src), 0); + return -EHWPOISON; + } + kmsan_copy_page_meta(dst, src); + } + + return 0; +} + /* * Return: * 0: copied succeeded * -EHWPOISON: copy failed due to hwpoison in source page * -EAGAIN: copied failed (some other reason) */ -static inline int __wp_page_copy_user(struct page *dst, struct page *src, - struct vm_fault *vmf) +static inline int __wp_page_copy_user_pfn(struct page *dst, + struct vm_fault *vmf) { int ret; void *kaddr; @@ -2803,14 +2823,6 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, struct mm_struct *mm = vma->vm_mm; unsigned long addr = vmf->address; - if (likely(src)) { - if (copy_mc_user_highpage(dst, src, addr, vma)) { - memory_failure_queue(page_to_pfn(src), 0); - return -EHWPOISON; - } - return 0; - } - /* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by @@ -2879,6 +2891,7 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, } } + kmsan_copy_page_meta(dst, NULL); ret = 0; pte_unlock: @@ -3372,7 +3385,12 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) if (!new_folio) goto oom; - ret = __wp_page_copy_user(&new_folio->page, vmf->page, vmf); + if (likely(old_folio)) + ret = __wp_page_copy_user_range(&new_folio->page, + vmf->page, + 1, vmf->address, vma); + else + ret = __wp_page_copy_user_pfn(&new_folio->page, vmf); if (ret) { /* * COW failed, if the fault was solved by other, @@ -3388,7 +3406,6 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) delayacct_wpcopy_end(); return ret == -EHWPOISON ? VM_FAULT_HWPOISON : 0; } - kmsan_copy_page_meta(&new_folio->page, vmf->page); } if (mem_cgroup_charge(new_folio, mm, GFP_KERNEL))