From patchwork Fri Sep 22 12:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395711 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 A1463CD4F5B for ; Fri, 22 Sep 2023 12:03:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 894E66B02D6; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7E76B02D9; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 647496B02D6; Fri, 22 Sep 2023 08:03:12 -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 415EA6B02D8 for ; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 160A11CAE9F for ; Fri, 22 Sep 2023 12:03:12 +0000 (UTC) X-FDA: 81264097824.11.5C72487 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 4CF9D20024 for ; Fri, 22 Sep 2023 12:03:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IXIMVSUD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695384188; 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=6N+Ph3QMrWe4qaRl/OHSGwibv9/K2tq1VuzcqrtQ8oZR1yzpd7deVF9WyhSz3zy4SQdVYz Zq0RZdkAX2xwvJr9+bi3V5gJ/TnvWKb4ZDwk2WgoWckLEGP7quzWsIj1rIyowzzGe+WSVG OHFT45VjvkMFhyzZtjjXyAhRRMR8UZY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IXIMVSUD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.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=1695384188; a=rsa-sha256; cv=none; b=UVU/r18AIXHzfD0QO3y7Wwuq3rNlXMaMQKH/X1tcZ6xwzF1cLfp6xqNKZJlfqJOLkhorJO 3OOzdu1C4vVhjccGYq84HwhBC3k4pdvpPf5oCrVSoSksjAXF7OKCK76owcXJCByay95Xg8 U6OfohsGrYzuQIFZxYj+GlRlea0z1c8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384187; 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=IXIMVSUDFrWuBSDNg9ygs40Tv+ZwasQ4bnB0bPWIZONC356y+HjwrX2kGswWYjCY5kt8C6 o8M243ii48K6pScGx2kHFSRtcnzi92ZIVH5WM5al5t2dcRFcAoxiTXGgOzdpOucKZs8zCj SOjATEw+p8R+5XPbKm7tlNAcLhI9Svw= 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-342-_gvf6TzuMjGxNRBZi_i66w-1; Fri, 22 Sep 2023 08:03:03 -0400 X-MC-Unique: _gvf6TzuMjGxNRBZi_i66w-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 6BC2B185A790; Fri, 22 Sep 2023 12:03:02 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A4EC20268D7; Fri, 22 Sep 2023 12:03:00 +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 v6 12/13] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together Date: Fri, 22 Sep 2023 13:02:26 +0100 Message-ID: <20230922120227.1173720-13-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-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: 4CF9D20024 X-Stat-Signature: k44bub6a7phnx8hseihzigfkhz1bqrjf X-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EqYwqSs2xWgYCoFH/Xc59nW2bgDdw53qXjz2rFvuX4NGjuBGHAIbKFwcxbDl2TfH/mroErhbb2y+aEG7mx6Iw+PqpDcAFUg1pfUaRiQNAHX6G1L1/XpgI+peL7hY/qrQ6EezMp4VZoalorpsOmBKvvnq6A8pObiyuK80Xm8Dj1JwyCNXoSIcXXDAflsY8osbope1bNS4HdEHGjPsTkpEPxKStKedJDOHZMXFFL1ZHLK3JgiNmQGomhOjF3aVbW2LpN1olNTUtMCBl87jxJ32TUq/dgh49xjdFrBtciG4LmWqRqZ25NSIkBuoFtoYas36HBFGx8L/PPtZTO6SyPXIW4v58ity7zcm/6eJz1hx0MZc9MCJgCmvTtBdrICjjE5ya7s97SrQ3luaJD0UfV4kxKfLgSZ4AVznShuOn7jSl+8daUxSrkNtcosRIafzTNb9U8hiKWjqE1Ct/N3o/fZVBftC05XRigIa3x3jkIXDxdLcUXzFFViRBAVpR1pJK8+tH6eX7eEE5b+PpPAHetQi1fTb8dCSpsM6ztsYPsMxf3XrY5d5qNWXxkLKbxN+KnN8TSwbmwX4L7pSx3/96qMCKbBnYJ3P7DQgG05mVxW8ymS0JlJ1+XAUDHc/cUnnR 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);