Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2024062pxb; Sat, 21 Nov 2020 06:18:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuBx1wtSv3QMhibKjajZ1SIVWDasKTN+3c73aX3/xfQMu+/KV/JPrnv12RhYuvrgHOcnTz X-Received: by 2002:a17:906:a186:: with SMTP id s6mr38300405ejy.193.1605968334765; Sat, 21 Nov 2020 06:18:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605968334; cv=none; d=google.com; s=arc-20160816; b=z7vD59uOJeZxOxXlfjaoOe9acFBKk5qq1MsSZl5lAjeY3X3YgViYA7XfVL6IjW40qb 6T3/gUTaUrIGZs4dAX6XKgofyE2vHJnboquK7YwWf8C9yIsvb5nGP/8DMHsyi4f5PNKt xNvV8UTVLmzMiiMHaL+Lf1o4xee+LLg+QT11YRnpHzU0vUcIFKQfnBC0TC1m7Iz+cu2D iWWEaL/oIVbtdsq/SImCD69fXIXTFGNgBnwNA2FDHqG+0QJTixu4Ld+rQSKkTZKRfqIg YLrcBDAWLkeFf0flTGW178CEBvNh/2dN+Gpc592/O0EK39YStQnPt+Fgg4JnXZiWeul7 DBVg== 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=O9qDylx4ewpBGOJoY7+LpQLGp85UBysg0NqjPw7tJrk=; b=gcm4/V9wGlv3R76EgSz7ev2vuUUR0Ez+rt+EO0RYagj67NBE1ltYUDs/iZGLjbN5oD qf3H7J0HgvBBn6gSGYHqNGZvw4wqmckAwm1aFqrMH4JS6rANKGtZSkUAdt9bP+JCr62d Jur9JBkN7GHcVE1D/IssVvX1wTI6FIhBFoxLDJ7dGURizefIdRLpthqx7/U1Zh2+yTXN 5zn0NhAg5FdwOUcEOGb3ROd8DQZzuTwQV0orJARVAfTQwb9VCSwDBRDEsUaCAR+gfv+n 4DigJZVKkqNT1DnxvLe8Vj/BhToW25j6msuoqhJGiCFZ9ZecaMmLhNxaXcTTwHIkSVrY iqhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C1H1hKp3; 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 v7si3618106ejg.393.2020.11.21.06.18.32; Sat, 21 Nov 2020 06:18:54 -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=C1H1hKp3; 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 S1728301AbgKUOQH (ORCPT + 99 others); Sat, 21 Nov 2020 09:16:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55417 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728286AbgKUOQF (ORCPT ); Sat, 21 Nov 2020 09:16:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605968164; 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=O9qDylx4ewpBGOJoY7+LpQLGp85UBysg0NqjPw7tJrk=; b=C1H1hKp3zZQ5dY1np7gLhsu5Ogs//nK8TrIOSzeR9gOVHxAgW6G2zhNNjOgxSWvCdm4ueQ YB/VoBtholCMLt3BYbDZKTBjeX1pnxEZN5O0qt5umit8pXwkka84D680ABiO5Z1+c6gUf7 EtK+4lawpHPGRRHAAKnvuTqOAPR4ZU8= 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-426-HeJl7aVjNTez9AGzqE1P7w-1; Sat, 21 Nov 2020 09:16:02 -0500 X-MC-Unique: HeJl7aVjNTez9AGzqE1P7w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 929DB1DDE7; Sat, 21 Nov 2020 14:16:00 +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 F15F55D6BA; Sat, 21 Nov 2020 14:15:58 +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 20/29] iov_iter: Split iov_iter_gap_alignment() 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:15:58 +0000 Message-ID: <160596815823.154728.8595962159705739709.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.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split iov_iter_gap_alignment() by type. Signed-off-by: David Howells --- lib/iov_iter.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index d2a66e951995..5744ddec854f 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1542,27 +1542,45 @@ static unsigned long no_alignment(const struct iov_iter *i) return 0; } -static unsigned long xxx_gap_alignment(const struct iov_iter *i) +static unsigned long iovec_gap_alignment(const struct iov_iter *i) { unsigned long res = 0; size_t size = i->count; - if (unlikely(iov_iter_is_pipe(i) || iov_iter_is_discard(i))) { - WARN_ON(1); - return ~0U; - } - - iterate_all_kinds(i, size, v, + iterate_over_iovec(i, size, v, (res |= (!res ? 0 : (unsigned long)v.iov_base) | - (size != v.iov_len ? size : 0), 0), + (size != v.iov_len ? size : 0), 0)); + return res; +} + +static unsigned long bvec_gap_alignment(const struct iov_iter *i) +{ + unsigned long res = 0; + size_t size = i->count; + + iterate_over_bvec(i, size, v, (res |= (!res ? 0 : (unsigned long)v.bv_offset) | - (size != v.bv_len ? size : 0)), + (size != v.bv_len ? size : 0))); + return res; +} + +static unsigned long kvec_gap_alignment(const struct iov_iter *i) +{ + unsigned long res = 0; + size_t size = i->count; + + iterate_over_kvec(i, size, v, (res |= (!res ? 0 : (unsigned long)v.iov_base) | - (size != v.iov_len ? size : 0)) - ); + (size != v.iov_len ? size : 0))); return res; } +static unsigned long no_gap_alignment(const struct iov_iter *i) +{ + WARN_ON(1); + return ~0U; +} + static inline ssize_t __pipe_get_pages(struct iov_iter *i, size_t maxsize, struct page **pages, @@ -2160,7 +2178,7 @@ static const struct iov_iter_ops iovec_iter_ops = { .zero = iovec_zero, .alignment = iovec_alignment, - .gap_alignment = xxx_gap_alignment, + .gap_alignment = iovec_gap_alignment, .get_pages = xxx_get_pages, .get_pages_alloc = xxx_get_pages_alloc, .npages = xxx_npages, @@ -2194,7 +2212,7 @@ static const struct iov_iter_ops kvec_iter_ops = { .zero = kvec_zero, .alignment = kvec_alignment, - .gap_alignment = xxx_gap_alignment, + .gap_alignment = kvec_gap_alignment, .get_pages = xxx_get_pages, .get_pages_alloc = xxx_get_pages_alloc, .npages = xxx_npages, @@ -2228,7 +2246,7 @@ static const struct iov_iter_ops bvec_iter_ops = { .zero = bvec_zero, .alignment = bvec_alignment, - .gap_alignment = xxx_gap_alignment, + .gap_alignment = bvec_gap_alignment, .get_pages = xxx_get_pages, .get_pages_alloc = xxx_get_pages_alloc, .npages = xxx_npages, @@ -2262,7 +2280,7 @@ static const struct iov_iter_ops pipe_iter_ops = { .zero = pipe_zero, .alignment = pipe_alignment, - .gap_alignment = xxx_gap_alignment, + .gap_alignment = no_gap_alignment, .get_pages = xxx_get_pages, .get_pages_alloc = xxx_get_pages_alloc, .npages = xxx_npages, @@ -2296,7 +2314,7 @@ static const struct iov_iter_ops discard_iter_ops = { .zero = discard_zero, .alignment = no_alignment, - .gap_alignment = xxx_gap_alignment, + .gap_alignment = no_gap_alignment, .get_pages = xxx_get_pages, .get_pages_alloc = xxx_get_pages_alloc, .npages = xxx_npages,