Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2024259pxb; Sat, 21 Nov 2020 06:19:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdayQMfI8KARDovRjVpFBa+3lVKWu8ifghljyIa5tkPUhMS+IOR3xy9vUObOysYhcNWSPS X-Received: by 2002:a17:906:3ac2:: with SMTP id z2mr1592480ejd.26.1605968353690; Sat, 21 Nov 2020 06:19:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605968353; cv=none; d=google.com; s=arc-20160816; b=wLJrSdAsX1RZPIvRY/sbE0s6EqpKfLeeKk8N/mon+ZLrWNDctyHMam0pEe5vZ209gv ub7bRjP17Ph15UDG/R4cx7+zzbk68cBGeV2BRj00z/M65t3NCG3D8BNNcQDGkbxxDy7M 91Y2KZ9F8Ulgybd2arfdHi/Oo1pfW3ZtR53oUqdlocwhGqxGhTq3PICcovjGNb6IvHuZ O5DMN2Zp4bjOoCPQLxyNmGFAxiHxMzA3bQDAYcBB453Snbr1wtv7huNL4ofG9lhxsG48 dygOMWblZ1/vdh3KZ55MLXqopY3QVk1IVlHXMT2dcCz3CS9wiBXvUQG64ueKic6PZjWK 4q3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=lc3ApZ/hH2TB+Llf7riKZKHlOr661a/omnTxq1itTBI=; b=uhPU46iDrF7crkfBrVO7eph4YK6IBIxdgXwTES9Hh9iIyaIZ93rPsAqDZ60axIc1ev bTXZLutWl9xiFROL6vSDnGtWUa63zLEA2v6XOoFzGauzx0rZD8xwus8MKPk7pdgu31Rj YaTU4hqLFdMstcX4H/WNg/6quWEgTeladU0V8wKZ4LUdCtfE/vc0rcoMmP9ZfEdO3UVW gd0Rd7F1S5+0Gd9vzm4qjFiXrEVEY6mweDLt9fM31y9QHXHjv7z8SAcmcSZXiG7gYC1/ WYyIIyRMtEpnSC42VJb6Xd57SMRjiMPbUvnqwkQbT/eHRBH9wIAItJ9MWbNIh7xNi+nN yY/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JNmsN9nZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ot12si3259020ejb.239.2020.11.21.06.18.51; Sat, 21 Nov 2020 06:19:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JNmsN9nZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgKUOQj (ORCPT + 99 others); Sat, 21 Nov 2020 09:16:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48700 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728359AbgKUOQi (ORCPT ); Sat, 21 Nov 2020 09:16:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605968197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lc3ApZ/hH2TB+Llf7riKZKHlOr661a/omnTxq1itTBI=; b=JNmsN9nZxr7pPQ12WRbVQC23vmh8Aa9dUDvVlEYh2J2I9S1K/lVkuC4NovEHGP1u9F6mUb 8qxxNXUYYtctjZfWOuznXkwEsOHTM0P5OF34LMDZDz5/570/VNWhTLyCJHkBXBVI0CPxk5 QQ1692nS8wufqJsXVfkv1FLloVik4sY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-268-oHw2WpuYMEmsy3PV_OL-lA-1; Sat, 21 Nov 2020 09:16:33 -0500 X-MC-Unique: oHw2WpuYMEmsy3PV_OL-lA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4F801842165; Sat, 21 Nov 2020 14:16:31 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-112-246.rdu2.redhat.com [10.10.112.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id 175781975F; Sat, 21 Nov 2020 14:16:29 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 24/29] iov_iter: Split csum_and_copy_from_iter_full() From: David Howells To: Pavel Begunkov , Matthew Wilcox , Jens Axboe , Alexander Viro Cc: dhowells@redhat.com, Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sat, 21 Nov 2020 14:16:29 +0000 Message-ID: <160596818929.154728.728490523100444099.stgit@warthog.procyon.org.uk> In-Reply-To: <160596800145.154728.7192318545120181269.stgit@warthog.procyon.org.uk> References: <160596800145.154728.7192318545120181269.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split csum_and_copy_from_iter_full() by type. Signed-off-by: David Howells --- lib/iov_iter.c | 62 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 1f596cffddf9..8820a9e72815 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1841,20 +1841,16 @@ static size_t no_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, return 0; } -static bool xxx_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, +static bool iovec_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) { char *to = addr; __wsum sum, next; size_t off = 0; sum = *csum; - if (unlikely(iov_iter_is_pipe(i) || iov_iter_is_discard(i))) { - WARN_ON(1); - return false; - } if (unlikely(i->count < bytes)) return false; - iterate_all_kinds(i, bytes, v, ({ + iterate_over_iovec(i, bytes, v, ({ next = csum_and_copy_from_user(v.iov_base, (to += v.iov_len) - v.iov_len, v.iov_len); @@ -1863,25 +1859,61 @@ static bool xxx_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *c sum = csum_block_add(sum, next, off); off += v.iov_len; 0; - }), ({ + })); + *csum = sum; + iov_iter_advance(i, bytes); + return true; +} + +static bool bvec_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + char *to = addr; + __wsum sum; + size_t off = 0; + sum = *csum; + if (unlikely(i->count < bytes)) + return false; + iterate_over_bvec(i, bytes, v, ({ char *p = kmap_atomic(v.bv_page); sum = csum_and_memcpy((to += v.bv_len) - v.bv_len, p + v.bv_offset, v.bv_len, sum, off); kunmap_atomic(p); off += v.bv_len; - }),({ + })); + *csum = sum; + iov_iter_advance(i, bytes); + return true; +} + +static bool kvec_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + char *to = addr; + __wsum sum; + size_t off = 0; + sum = *csum; + if (unlikely(i->count < bytes)) + return false; + iterate_over_kvec(i, bytes, v, ({ sum = csum_and_memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len, sum, off); off += v.iov_len; - }) - ) + })); *csum = sum; iov_iter_advance(i, bytes); return true; } +static bool no_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + WARN_ON(1); + return false; +} + static size_t xxx_csum_and_copy_to_iter(const void *addr, size_t bytes, void *csump, struct iov_iter *i) { @@ -2226,7 +2258,7 @@ static const struct iov_iter_ops iovec_iter_ops = { #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, .csum_and_copy_from_iter = iovec_csum_and_copy_from_iter, - .csum_and_copy_from_iter_full = xxx_csum_and_copy_from_iter_full, + .csum_and_copy_from_iter_full = iovec_csum_and_copy_from_iter_full, .zero = iovec_zero, .alignment = iovec_alignment, @@ -2260,7 +2292,7 @@ static const struct iov_iter_ops kvec_iter_ops = { #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, .csum_and_copy_from_iter = kvec_csum_and_copy_from_iter, - .csum_and_copy_from_iter_full = xxx_csum_and_copy_from_iter_full, + .csum_and_copy_from_iter_full = kvec_csum_and_copy_from_iter_full, .zero = kvec_zero, .alignment = kvec_alignment, @@ -2294,7 +2326,7 @@ static const struct iov_iter_ops bvec_iter_ops = { #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, .csum_and_copy_from_iter = bvec_csum_and_copy_from_iter, - .csum_and_copy_from_iter_full = xxx_csum_and_copy_from_iter_full, + .csum_and_copy_from_iter_full = bvec_csum_and_copy_from_iter_full, .zero = bvec_zero, .alignment = bvec_alignment, @@ -2328,7 +2360,7 @@ static const struct iov_iter_ops pipe_iter_ops = { #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, .csum_and_copy_from_iter = no_csum_and_copy_from_iter, - .csum_and_copy_from_iter_full = xxx_csum_and_copy_from_iter_full, + .csum_and_copy_from_iter_full = no_csum_and_copy_from_iter_full, .zero = pipe_zero, .alignment = pipe_alignment, @@ -2362,7 +2394,7 @@ static const struct iov_iter_ops discard_iter_ops = { #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, .csum_and_copy_from_iter = no_csum_and_copy_from_iter, - .csum_and_copy_from_iter_full = xxx_csum_and_copy_from_iter_full, + .csum_and_copy_from_iter_full = no_csum_and_copy_from_iter_full, .zero = discard_zero, .alignment = no_alignment,