From patchwork Mon Sep 25 12:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13397694 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 4E923CE7A96 for ; Mon, 25 Sep 2023 12:03:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66C8B6B014C; Mon, 25 Sep 2023 08:03:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F6126B0150; Mon, 25 Sep 2023 08:03:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 470156B0153; Mon, 25 Sep 2023 08:03:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2D1C36B014C for ; Mon, 25 Sep 2023 08:03:45 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 043D41CA844 for ; Mon, 25 Sep 2023 12:03:44 +0000 (UTC) X-FDA: 81274985610.13.19B2E34 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id DA7B4C0029 for ; Mon, 25 Sep 2023 12:03:42 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BFEkW4ct; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695643422; 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:dkim-signature; bh=ENB7CtH73xnlPC5Szfr84FelPyw0n3TXhDinmckBTOE=; b=4BhuUAuZVoLHOGL86KSBKU39RcRgy/BEm7jtYsUcKoDnDzkevPhJxM1YF9bTLhJ42C7fCQ CvLdxM7lZgFYUsX6xT+L7jLr4fkJvrNdyPsZxhbPI9uM35DohqUJuG066dMQfwvnwug+3x ROswAoLJE+LP48UfqzJyRxmnR3Lcp9w= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BFEkW4ct; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695643422; a=rsa-sha256; cv=none; b=TvInITNsH6kXjmQb5LOJmL35qktAQSKKRvtqQ5f9fSR65M3sRc38yqoGmQalF4hhIZgW+1 qTvEohC07NYpzpadpNRJuf3JaWkgCWxKUpIAcwOo7j/EY8JL3CfiYZ33/R9ZDvoZmNkme5 Da3tSFRfGmwhRCWS0+E79NzH5RF3UyA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695643422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ENB7CtH73xnlPC5Szfr84FelPyw0n3TXhDinmckBTOE=; b=BFEkW4ctiMudCUG7eqS9vzak+AUlX6zdsBmIB562G2KuwUA8w2PZwznuV8WyY3rJHYR8gF DiPBJPRzEs7abTu8fBL4DhgI39QxCsavzMUVpcEALrT2wCn+IEP1ILVoZZGaMPdYQ+gLs4 aRL1bwbLHOKPJFBk4WtfVFhkdADp2qY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-638-Tspro7EYNxWz9xyR8d5l5A-1; Mon, 25 Sep 2023 08:03:38 -0400 X-MC-Unique: Tspro7EYNxWz9xyR8d5l5A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07FBD3C1E9D8; Mon, 25 Sep 2023 12:03:38 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609BB14171B6; Mon, 25 Sep 2023 12:03:36 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 08/12] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() Date: Mon, 25 Sep 2023 13:03:05 +0100 Message-ID: <20230925120309.1731676-9-dhowells@redhat.com> In-Reply-To: <20230925120309.1731676-1-dhowells@redhat.com> References: <20230925120309.1731676-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Queue-Id: DA7B4C0029 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 5o5n61dg81pydncqt7pc88ypaugwezik X-HE-Tag: 1695643422-725366 X-HE-Meta: U2FsdGVkX1+RugM/AEzcZJn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rJruTuHGZKxmeM5jtoyoLbIXZRj1ZJIFMYN40PDrKR8VOIBYMqD+x0UmQixwPDES5QYeFlIfGKUXZxusMfB1BQjt6Nxx4PeWujkpL6ddojQYK/wqcU6DYbC8ahl6laGMNHoS8F79oSFWd5fGhwfBIxtO6TKGtTlsJqA+pnf3g0iwZAGzRlhkfJd/31JFISlW2WzKWK7+reWLyQ4w9AplLjcndMzXxYM3+6bXd7p6mD/snJCznxfZ7rY1zf+iP8BFeGqKjD24NCTRiNCyzQKtbOYRPUBuqdbGbCa7RQiTjEMI7+ubi+qZ5FnUiUZK7r4dT85XUn3nyUOzRd2bv12/OL7EvtUxHctkSjfwCUbK8SKTPY+/dzdhLHKoEqwTx5npI8nqUhg9m6Z0naoITLPRH/1r86aHBxwnOTbWu/GlV/vhStSXIKi9GPAxuMgJvr9dgpCs0ScOu/kcFp961Mg= 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: iter->copy_mc is only used with a bvec iterator and only by dump_emit_page() in fs/coredump.c so rather than handle this in memcpy_from_iter_mc() where it is checked repeatedly by _copy_from_iter() and copy_page_from_iter_atomic(), Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- lib/iov_iter.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 65374ee91ecd..943aa3cfd7b3 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -253,14 +253,33 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) EXPORT_SYMBOL_GPL(_copy_mc_to_iter); #endif /* CONFIG_ARCH_HAS_COPY_MC */ -static size_t memcpy_from_iter_mc(void *iter_from, size_t progress, - size_t len, void *to, void *priv2) +static __always_inline +size_t memcpy_from_iter_mc(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + return copy_mc_to_kernel(to + progress, iter_from, len); +} + +static size_t __copy_from_iter_mc(void *addr, size_t bytes, struct iov_iter *i) { - struct iov_iter *iter = priv2; + size_t progress; - if (iov_iter_is_copy_mc(iter)) - return copy_mc_to_kernel(to + progress, iter_from, len); - return memcpy_from_iter(iter_from, progress, len, to, priv2); + if (unlikely(i->count < bytes)) + bytes = i->count; + if (unlikely(!bytes)) + return 0; + progress = iterate_bvec(i, bytes, addr, NULL, memcpy_from_iter_mc); + i->count -= progress; + return progress; +} + +static __always_inline +size_t __copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) +{ + if (unlikely(iov_iter_is_copy_mc(i))) + return __copy_from_iter_mc(addr, bytes, i); + return iterate_and_advance(i, bytes, addr, + copy_from_user_iter, memcpy_from_iter); } size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) @@ -270,9 +289,7 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) if (user_backed_iter(i)) might_fault(); - return iterate_and_advance2(i, bytes, addr, i, - copy_from_user_iter, - memcpy_from_iter_mc); + return __copy_from_iter(addr, bytes, i); } EXPORT_SYMBOL(_copy_from_iter); @@ -493,9 +510,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, } p = kmap_atomic(page) + offset; - n = iterate_and_advance2(i, n, p, i, - copy_from_user_iter, - memcpy_from_iter_mc); + __copy_from_iter(p, n, i); kunmap_atomic(p); copied += n; offset += n;