From patchwork Wed Sep 20 22:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13393504 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 8DF9DCD13CF for ; Wed, 20 Sep 2023 22:23:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCA986B01B3; Wed, 20 Sep 2023 18:23:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C796C6B01F1; Wed, 20 Sep 2023 18:23:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA5326B01F2; Wed, 20 Sep 2023 18:23:11 -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 8A4516B01B3 for ; Wed, 20 Sep 2023 18:23:11 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5876F120E09 for ; Wed, 20 Sep 2023 22:23:11 +0000 (UTC) X-FDA: 81258402582.28.74F791E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id A03CA40029 for ; Wed, 20 Sep 2023 22:23:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="MGK5r/Fw"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1695248589; 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=OEnm3txfdKWMLGG8rrdFEcQBV2WWgkp8Kq4P7DhBB1I=; b=0WdpmyNy3cow8wgstzdBq/IfpZE+rIOx2nZSC5jNDFTe9yaKDHgR9O8u2osxT308ITV5Ki UwFO9yTLhI9QoSw3SB8dKt6c8ZwuNqwTkKTu2Qi64foLyC/DLOsjpjwh14rK1VoqL6+SJ5 +epz926btba3VVDRSVnjgh8LL/edQ9I= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="MGK5r/Fw"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1695248589; a=rsa-sha256; cv=none; b=obk/YXzdUgQziCRw2jqw7/TRmsZRRDHsdrPSEwmR4b9X/YytEns1ZgDz9PEPd9jQr8zu4/ 17Dx4TuYWjHuLhzkoyk5U82G9RFwzfTMbyhlaYG5rUTIAgYcY9jrIm41YbbAT2rGj2A4TI G2j5F/hAmyQJkdJmKqF+CkB0nguxNMM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695248589; 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=OEnm3txfdKWMLGG8rrdFEcQBV2WWgkp8Kq4P7DhBB1I=; b=MGK5r/Fw68pF3tmnHeiuODdfFY4v8Qc2RuYie/dq+j5+Xra1OtBtqfeQjzRGbjARWqvEt2 NJsx76nZXxf8D2Q30KsKrNvD8SCrn3ATBO8egSKK3+JOq8b8biQlnrOPIwlH/XhSRGRJZt CgQky2vM5boKmmIpGEFSi4r9rPkvRC4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-qZGJ1yNoPOih4A5wVhP7UQ-1; Wed, 20 Sep 2023 18:23:04 -0400 X-MC-Unique: qZGJ1yNoPOih4A5wVhP7UQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 9CC29800883; Wed, 20 Sep 2023 22:23:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 941A0492C37; Wed, 20 Sep 2023 22:23:01 +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, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v5 10/11] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together Date: Wed, 20 Sep 2023 23:22:30 +0100 Message-ID: <20230920222231.686275-11-dhowells@redhat.com> In-Reply-To: <20230920222231.686275-1-dhowells@redhat.com> References: <20230920222231.686275-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: A03CA40029 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: up5yo8yo8asjyzxszzm7rckig6bt8yu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6BxQtpMRc4j4wCnCqoi34k3OBxLUmVkMVNjP0lINNcM+A6XXzrBtdWxGXajghFCu76E1QMb4/bF571qx1r4m+G2dRdeWz3EiqLZYMwDzQGcrdvA4dbW4qV7n9Omh+Pn1x7wWiplrBarlsBxoNuBNkwai+qKQH1HQtBUJ6jyIKAnVD4FegeZoC9Fp/mG3BPOX1Mfs0gB/ITro21r8Ekbh1ZbNdQdyseqZfP9mOTj+EL+t5jRrBwjGS+JHmLqgiCDfnjz2vCGe3QfAUnfcCBZTW/XhA52F2IPSDM+8/NNK6I/DwKKSoRlZNcvKQtH9CINsaC7J12cP3qG50VxJFO75QvpAPqsM1YZxzsU7Y/HshfcwQ5m+puMoC8LhInT/+H2oj8aMSw9CWKoQ/c8R5lP2NZsMEZ/aasqUiBUb6exWXV/EfEIoj5PiAuSIKJAPmUEhk/IkCiJUVd66c7uHYdvULJGKTh3OkcH60Mh+hv0FMrxjnScjwIRZL9nZK2T1NqJmJxrUjVIDPkCOZX13jQlMaiBde7Mv9VptXT1kXG761aaYgZerI0XCqK/iQiUY3pfFmO4AzJy+OtQC1SHx5jx2L0M/7D7u+UJ72yTuRu00oeQhWqKtXV+H 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: Move csum_and_copy_from_iter_full() out of line and then merge csum_and_copy_from_iter() into its only caller. 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: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org cc: netdev@vger.kernel.org --- include/linux/skbuff.h | 19 ++----------------- net/core/datagram.c | 5 +++++ net/core/skbuff.c | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index c81ef5d76953..be402f55f6d6 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3679,23 +3679,8 @@ static inline int __must_check skb_put_padto(struct sk_buff *skb, unsigned int l return __skb_put_padto(skb, len, true); } -struct csum_state { - __wsum csum; - size_t off; -}; - -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); - -static __always_inline __must_check -bool csum_and_copy_from_iter_full(void *addr, size_t bytes, - __wsum *csum, struct iov_iter *i) -{ - size_t copied = csum_and_copy_from_iter(addr, bytes, csum, i); - if (likely(copied == bytes)) - return true; - iov_iter_revert(i, copied); - return false; -} +bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) + __must_check; static inline int skb_add_data(struct sk_buff *skb, struct iov_iter *from, int copy) diff --git a/net/core/datagram.c b/net/core/datagram.c index 452620dd41e4..722311eeee18 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -738,6 +738,11 @@ size_t memcpy_to_iter_csum(void *iter_to, size_t progress, return 0; } +struct csum_state { + __wsum csum; + size_t off; +}; + static size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, struct iov_iter *i) { diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 3efed86321db..2bfa6a7ba244 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6955,13 +6955,19 @@ size_t copy_from_user_iter_csum(void __user *iter_from, size_t progress, return next ? 0 : len; } -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, - struct iov_iter *i) +bool csum_and_copy_from_iter_full(void *addr, size_t bytes, + __wsum *csum, struct iov_iter *i) { + size_t copied; + if (WARN_ON_ONCE(!i->data_source)) - return 0; - return iterate_and_advance2(i, bytes, addr, csum, - copy_from_user_iter_csum, - memcpy_from_iter_csum); + return false; + copied = iterate_and_advance2(i, bytes, addr, csum, + copy_from_user_iter_csum, + memcpy_from_iter_csum); + if (likely(copied == bytes)) + return true; + iov_iter_revert(i, copied); + return false; } -EXPORT_SYMBOL(csum_and_copy_from_iter); +EXPORT_SYMBOL(csum_and_copy_from_iter_full);