From patchwork Mon Sep 25 12:03:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13397696 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 E88A6CE7A95 for ; Mon, 25 Sep 2023 12:03:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EC276B015A; Mon, 25 Sep 2023 08:03:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 273CB6B015B; Mon, 25 Sep 2023 08:03:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A11E6B015D; Mon, 25 Sep 2023 08:03:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E38FA6B015A for ; Mon, 25 Sep 2023 08:03:51 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B547280BDF for ; Mon, 25 Sep 2023 12:03:51 +0000 (UTC) X-FDA: 81274985862.14.5A3A218 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id E0965A003B for ; Mon, 25 Sep 2023 12:03:49 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AO4QXmlj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1695643429; 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=WfjYCuOX2Z28jicqNKmGQIaN50ZYoK3TVD/TZFf/3XgBQInbPiJJZOYkkLPKEhRbn1JsW8 +KLFxzIB0QpNR9xpyFy+PMTpKGsNWz5NuFay6I3GV4ILpjvYBt+gTsD7PVeUTMrjqQM5vt 2PjqaIZ4ZOjryS7Pji3ENKmOsAxoyWc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AO4QXmlj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1695643429; a=rsa-sha256; cv=none; b=W4+RrMs56CY0W+nVtI0SH05EUtv1BXfkWxBLyqidJhs4hxgh3uocwnwlihsDLZsn4fOrKg tsX9n9CYXTfi4ZfXzBHkpHsjMbQW9kAMPo6Vuz4myUL3x++cwXK3YAt8GI7P8OG5GRLTlW xRiyXIfvmtjdzS6he8xNlekk9yL6Fv4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695643429; 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=AO4QXmljmMm1oYlOmwydO0HuSLhvXrgsEqpY+tD8m9jmdW8pbPd1L5N9qXK538hVM8j6cF enpWQ/FSKVMOzg0ZCAsLR5Y3Zcq0Cq81ABZu5hL43s/hEz2CCxgofgxuGG0eqagIpFJqu1 4ZaHnjMfjyAIQyFtt/XPMsCp5hANVbk= 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-436-X-q17QG2OBu5zjjUIF3oyA-1; Mon, 25 Sep 2023 08:03:47 -0400 X-MC-Unique: X-q17QG2OBu5zjjUIF3oyA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 3C1CD811E93; Mon, 25 Sep 2023 12:03:46 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 337AD40C6EA8; Mon, 25 Sep 2023 12:03:44 +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 v7 11/12] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together Date: Mon, 25 Sep 2023 13:03:08 +0100 Message-ID: <20230925120309.1731676-12-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.2 X-Rspamd-Queue-Id: E0965A003B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cabac5sypkmu3ryykzy4mmm9r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actSjAPG4qhQ5EM6nJfXpzLO5udCecUCqRbBIFFI7yl+NLRN4MszrrNTI417WjxHDx3mVuYcRtLYdwc3MTB7lIi4sg7fUnGSMR1yE4t+pU5Ylrsfc+4MutenB3dkFU/VDA9pHdASRdkzjsIUsuEeX2ydFnZ+2aOibNyqlgG4tVjaVZzJGrf/pkOejJqp1pZHAdbojLfCUAnHCT+QICmlT/r8BLUcfvsZfhCwOoqz7WiRP5ZF45ufwvPpEJPryynCks0/uljBfSg3mCibgdfEn2PyZLQU/xzTDMrftBtn3YYyLgWgCuiq9z7K59dQKWPyApuOGhuqx4wRDS+cQxKR2elBHjnw3Ce+yZyBZuBwKyDfw64U7XTWaW3iO4jH+RzuM7FM6umiD3/oILVvdP+CwcsBxe43IyLtBUsNOZvzElGove/yuaSbPhE9luPA+w0IY9GLnt/cwoHPF2RZ1hkqSS9mu/NL7s6OuRLUlkM6qkFU6t3dMY6BLmH8mx4i6389xLGbUBZ7ffF0lMDRTW73/b3sX/HFrPwPyg1BKOlX+jQv6K14VYrvlOrZGfvTSu9OkP0GFPkNRaRoTFvmrDQYN52jsjkZ58N4LT3Yhp62BYZk 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);