From patchwork Wed Sep 13 16:56:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13383574 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 356DAEE01E0 for ; Wed, 13 Sep 2023 16:57:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 869726B0203; Wed, 13 Sep 2023 12:57:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 816A46B0204; Wed, 13 Sep 2023 12:57:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6652D6B0205; Wed, 13 Sep 2023 12:57:27 -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 4E3046B0203 for ; Wed, 13 Sep 2023 12:57:27 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2F61A80BA8 for ; Wed, 13 Sep 2023 16:57:27 +0000 (UTC) X-FDA: 81232180134.03.615A1A3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 742A018002B for ; Wed, 13 Sep 2023 16:57:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KAOSma6p; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1694624245; 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=BrSgt+wgkjJ1FtWT9vuKKBW4xgmNtnQDDI55tAQ8/R7hgxh8p3lP6YAnQDWGfkvWCdHXZu ChdKKNX3Xlr2ahCL+s3YMKf8z9dVn70er0/R2lLtBE2nzTGdkQVf7Ta2TaP8cRv0y0e1lC N73vFh3eTjZLQPy/MWvJ91JbK9BIvZY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KAOSma6p; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf06.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=1694624245; a=rsa-sha256; cv=none; b=BEAFNAl/+nXPKB5J3PMVwzfZjFWQqs+mpmHhAGgBgkKa8fMRX7o392Hr8yv8M7p3AFYIGx nHrHR6RLRw/rYXqR2DBbTpvvUIzxD7EZisEDCLTJtguspGw7nSDU5ci6TPCFEUoZSTR/C3 q07vUdgUnde4svOae0XfjJ8/hgVjgwI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694624244; 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=KAOSma6pM5lmy2GZIiOA5owQ26thITzEZfnHcNb/4i97I4hymihXQtNu/E/wF0HRTzjd9p VVp8E8x7ZdLxERI9jRo3K82fLEHxiEyUG+7e19JuX9HH+a7nWbRSxHvfM9HSjhL6YN1zl9 eIYHzyFEKNO7Nv+6UwDmvWeC3LnHrec= 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-60-yGDwbzOOMhetGn8REiVGKQ-1; Wed, 13 Sep 2023 12:57:21 -0400 X-MC-Unique: yGDwbzOOMhetGn8REiVGKQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 32F07185A79B; Wed, 13 Sep 2023 16:57:20 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D8792026D4B; Wed, 13 Sep 2023 16:57:18 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , 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 v4 11/13] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together Date: Wed, 13 Sep 2023 17:56:46 +0100 Message-ID: <20230913165648.2570623-12-dhowells@redhat.com> In-Reply-To: <20230913165648.2570623-1-dhowells@redhat.com> References: <20230913165648.2570623-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 742A018002B X-Stat-Signature: wrz5qyt3hfociiwykaxx9dcsqw7k5nqq X-Rspam-User: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IpRKNVf9xzjmtapURLHAUhr3b2kTCRYkEl1KrJvYLPP6mVPMuVGTk3Zl7SCwvdRC2+A+sRek0sFjqlGonKrh7fNA8GivmF1Od0gUGRSgsptKARwgydlcP1Jq9uYe44s1ykM3Qzxi5SEOfMm+YVSvaJUKOsvfLhiqpCen/ZQrtYdRtK7Qd7iyJp5mYUpitZCdAu74Bwl4dxqvVxvM6r6nkWSOJuZg+EN0eEHh7cdWL61/+Fasj68PLYY1CCvJrHxRDu4CUa6Qq+fGzojkrelvHBtpeCTg/sgZRWuZS6WFkyGju45ySz8oufnwpyfVES2AECgVF//BRS42UYYTvZzI+G+hIGhhun+S9Vny2Yv5VH/Gu8oXUo1oQT6HGHbwmidsxbfzr0mkyi6/FboZn2y7UpSDPD80nQIYxB8qvQ5lHL1SpXwruaV3B/D3pjN7xiSFvYFp7i6k5nAdKQKfr7mBSK4JR7co4QVPDAP34XtV0hzQi87E6mj0ziVztLMgk6WPEUsBc85hMKKNetXRkLRbqrigDNZuKFJpexEURTRqdg6WGo5IZdJTK5rIl4dwdUoATL3v5BRmtxe2YexHTdowAP6VezLpuRH4876hfa60kYOWjT1vteys7Uu97dsrGI/C 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);