Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2025398pxb; Sat, 21 Nov 2020 06:21:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJy0QDPMebAqJbLEsItt+B3oDMs2GXxF7m8kBIiozXvHsb0ZosE+b+s9fFnijo/YPqR8YyRC X-Received: by 2002:a17:906:f8c5:: with SMTP id lh5mr39185650ejb.77.1605968469397; Sat, 21 Nov 2020 06:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605968469; cv=none; d=google.com; s=arc-20160816; b=i265Elx1APAzTLq4k24YjS2TZ04imtKyMGlQXC9jlS6vah6jPYCq6103AC4QXagJ89 9RS1xs9VZVTVE8VfWLOHlwz7sHq0+r9t0QovhOCRwYTDdjJB7JQ5JNB3IKc8cZEF+qMa arqNlVUOLWztgGAWYxcSkKKdzNjJ4ivhkJ98yYHePixjjjYAwZ5SYAixyFJ/Sw5gDAjB IOAkpWAg7UhkhQdcMEZj8nVeLyeo4ZF/Mo/ghghKgPZkp71Bx1axbqJT86CyoQaTtvWX 8JmTDrl39yoa8EP81SMXIEOuHydcsMGBQqYBJl4ACoCQqHYZHZW9gjZpUPH5GhQ1D1oK hvJg== 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=hvV2XUFZAv7awKYqds0unEsSCOnFk/jwB0nBnZEA1To=; b=DFvAGFaL3uHP7c94/9bpLSFNFTM/W2PT/WRj2McKYPHigRFoZBVjUfpCQqxyvB7Yg0 beHFXOpTunIbiC5i2iqB/w7CK3f1c/16dR3YfU0PS0qkCns+vZ8aqbltC0CZ/Y11SaQI gZO9JrEg7HzYNZK4EVwJHhmE7mlythy1/URGG+hWxCbYv0AWGDqHBhvppAmKIZ/MVi84 XmRhQYw2CvQ2kqq9OMjtomrUAOC7g4QCQefCxKT+2YRd7IaatWyvL70/ZNM1+XB5cEr7 Q+tMcynK3o85/hARBkzXqkhGP50CaU4IaMGnyQ0aqbYeVZGoIATqyCTMfln+vTR/YDm1 KMZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cMRRYFVC; 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 qh16si3552410ejb.677.2020.11.21.06.20.46; Sat, 21 Nov 2020 06:21:09 -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=cMRRYFVC; 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 S1728348AbgKUOQa (ORCPT + 99 others); Sat, 21 Nov 2020 09:16:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60309 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728328AbgKUOQ3 (ORCPT ); Sat, 21 Nov 2020 09:16:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605968187; 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=hvV2XUFZAv7awKYqds0unEsSCOnFk/jwB0nBnZEA1To=; b=cMRRYFVCvMn5UJNegckwMIYjrGTyaYGepe5TWUQU7zkg/x62MCyeg3pZbcrqYYMavrwm/n p46kK8+l7BxFnC3uJo9PldRu5quWfozP2C9nJGbYnHAJWu9UoyeYA528tI0YmA/mQJeCXW e00fdP/RRqFfoQ3uYHbEpJ377/E44nU= 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-503-v2QWFXBSP2q7L4tE7stg2w-1; Sat, 21 Nov 2020 09:16:25 -0500 X-MC-Unique: v2QWFXBSP2q7L4tE7stg2w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10F6C1005D65; Sat, 21 Nov 2020 14:16:24 +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 3B6A15D9D7; Sat, 21 Nov 2020 14:16:22 +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 23/29] iov_iter: Split csum_and_copy_from_iter() 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:21 +0000 Message-ID: <160596818140.154728.302284980617377681.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.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split csum_and_copy_from_iter() by type. Signed-off-by: David Howells --- lib/iov_iter.c | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index a038bfbbbd53..1f596cffddf9 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1777,18 +1777,14 @@ static ssize_t no_get_pages_alloc(struct iov_iter *i, return -EFAULT; } -static size_t xxx_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, +static size_t iovec_csum_and_copy_from_iter(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 0; - } - iterate_and_advance(i, bytes, v, ({ + iterate_and_advance_iovec(i, bytes, v, ({ next = csum_and_copy_from_user(v.iov_base, (to += v.iov_len) - v.iov_len, v.iov_len); @@ -1797,24 +1793,54 @@ static size_t xxx_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum off += v.iov_len; } next ? 0 : v.iov_len; - }), ({ + })); + *csum = sum; + return bytes; +} + +static size_t bvec_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + char *to = addr; + __wsum sum; + size_t off = 0; + sum = *csum; + iterate_and_advance_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; + return bytes; +} + +static size_t kvec_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + char *to = addr; + __wsum sum; + size_t off = 0; + sum = *csum; + iterate_and_advance_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; return bytes; } +static size_t no_csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + WARN_ON(1); + return 0; +} + static bool xxx_csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) { @@ -2199,7 +2225,7 @@ static const struct iov_iter_ops iovec_iter_ops = { .copy_mc_to_iter = iovec_copy_mc_to_iter, #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, - .csum_and_copy_from_iter = xxx_csum_and_copy_from_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, .zero = iovec_zero, @@ -2233,7 +2259,7 @@ static const struct iov_iter_ops kvec_iter_ops = { .copy_mc_to_iter = kvec_copy_mc_to_iter, #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, - .csum_and_copy_from_iter = xxx_csum_and_copy_from_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, .zero = kvec_zero, @@ -2267,7 +2293,7 @@ static const struct iov_iter_ops bvec_iter_ops = { .copy_mc_to_iter = bvec_copy_mc_to_iter, #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, - .csum_and_copy_from_iter = xxx_csum_and_copy_from_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, .zero = bvec_zero, @@ -2301,7 +2327,7 @@ static const struct iov_iter_ops pipe_iter_ops = { .copy_mc_to_iter = pipe_copy_mc_to_iter, #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, - .csum_and_copy_from_iter = xxx_csum_and_copy_from_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, .zero = pipe_zero, @@ -2335,7 +2361,7 @@ static const struct iov_iter_ops discard_iter_ops = { .copy_mc_to_iter = discard_copy_to_iter, #endif .csum_and_copy_to_iter = xxx_csum_and_copy_to_iter, - .csum_and_copy_from_iter = xxx_csum_and_copy_from_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, .zero = discard_zero,