From patchwork Fri Sep 22 12:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395707 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 1786BC04AAB for ; Fri, 22 Sep 2023 12:03:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD9CD6B02D2; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C89066B02D3; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B50226B02D4; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A254B6B02D2 for ; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7C0AE1208FA for ; Fri, 22 Sep 2023 12:03:02 +0000 (UTC) X-FDA: 81264097404.13.E868035 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id BE14A1C003F for ; Fri, 22 Sep 2023 12:03:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ze64qI14; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384180; 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=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; b=n+QaYk8qhsBj0jd1R2IgZS0oySst0RxQ6sXjZoNGbjrafVdpPvRVXPbbsZiFriLWdA/aMj Bkx9BWirHT/xUJZbx/FzUZFS1I0wISPsGwYY7+0kKn5PHAHuCWEv7qyWxoVNhsYn9brWro d8ko2c1e7r2ULLHnrmvNT7O3G9pUPwc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384180; a=rsa-sha256; cv=none; b=OsXXmcikzl9+sbOKMY7pUgTwQOSnhP9IQnZFoEw7gSFjKZJ6/2/dRChIQkdz1yMbIzirM6 E0TjCSnBqz+8b0v4KESJB/bIYfCUVcn0zJUWYETAZE+4jWkI+XXLirpyxID6ze6lvCYA4e Cw0IN7QvRUOFtP85d9p7R96uqR0dj5M= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ze64qI14; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384180; 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=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; b=Ze64qI14DzFauZjffgCEL9ceUbC2jVZ4UCR2qkzRndrUDAOevJlV+WlbBotlXBY1SHd5sL FzufHUtDHN1V6X613UnEK4lZf0Q+tprSgkoKgvlXpzUxsmPAIuLwydwRjahi6rgO7C9nQ2 s6Q8gCy94m54x7nWUpLLbFnSWvF6Sn8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-ZTcYAYuYMcqv6NQGNev8hg-1; Fri, 22 Sep 2023 08:02:55 -0400 X-MC-Unique: ZTcYAYuYMcqv6NQGNev8hg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 9DF423816C89; Fri, 22 Sep 2023 12:02:54 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFD0D711282; Fri, 22 Sep 2023 12:02:52 +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 Subject: [PATCH v6 09/13] iov_iter: Add a kernel-type iterator-only iteration function Date: Fri, 22 Sep 2023 13:02:23 +0100 Message-ID: <20230922120227.1173720-10-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.9 X-Stat-Signature: 3bxxnt7s6ggs57gjtj4e7pjzq3o1i7z7 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BE14A1C003F X-Rspam-User: X-HE-Tag: 1695384180-659036 X-HE-Meta: U2FsdGVkX1/HkTjK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qhQwcH2HvAlv3G8x0KN0vliYlMcogUzz2FqXv+Yl24JGYUkq+Lh1FAK+TD8hZrGkOSz/zJdRHC5FsOsHvTHcbzMlcVr2QvFrXtS8qj/b1C98YdwfLjjK2z3fA0i6F4VWXoHZkzUiypUNkLfV7h3zCj/Ge3Oz/9P9yWGwztRMkwzqgBJffTRnpsv76lIYavqXBs7uUhSgPfB43c4to6tpupYsQC3ziPkdtmAlNHPnvrfsoY648x2lxomQEXbS0EarwV1mHCqUx1JRYWYX61c2o8sC9d/BZ2eLD8ghGWpbJIGyTObu2Kw+XmRbK/Zc5PdaCyvFHWeg8KceNOtxP/D9b2nINE2rs/yxtK6rclYH+8fHIAOoYNzgtFwL4c1+H+mvJuaCQR23L0uXvHxky8Nmmv93B1h/voO6wbNnXSenHMuAbhzMDfvB0SVQ9Al7ozlkpSBCS6i9VQgpU+I+Tb84+cHT/Pa6d6lUA57FJiBRg= 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: Add an iteration function that can only iterate over kernel internal-type iterators (ie. BVEC, KVEC, XARRAY) and not user-backed iterators (ie. UBUF and IOVEC). This allows for smaller iterators to be built when it is known the caller won't have a user-backed iterator. 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: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- Notes: Changes ======= ver #6) - Document the priv2 arg of iterate_and_advance_kernel(). include/linux/iov_iter.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h index 270454a6703d..d8733dc22b54 100644 --- a/include/linux/iov_iter.h +++ b/include/linux/iov_iter.h @@ -271,4 +271,36 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv, return iterate_and_advance2(iter, len, priv, NULL, ustep, step); } +/** + * iterate_and_advance_kernel - Iterate over a kernel iterator + * @iter: The iterator to iterate over. + * @len: The amount to iterate over. + * @priv: Data for the step functions. + * @priv2: More data for the step functions. + * @step: Processing function; given kernel addresses. + * + * Like iterate_and_advance2(), but rejected UBUF and IOVEC iterators and does + * not take a user-step function. + */ +static __always_inline +size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv, + void *priv2, iov_step_f step) +{ + if (unlikely(iter->count < len)) + len = iter->count; + if (unlikely(!len)) + return 0; + + if (iov_iter_is_bvec(iter)) + return iterate_bvec(iter, len, priv, priv2, step); + if (iov_iter_is_kvec(iter)) + return iterate_kvec(iter, len, priv, priv2, step); + if (iov_iter_is_xarray(iter)) + return iterate_xarray(iter, len, priv, priv2, step); + if (iov_iter_is_discard(iter)) + return iterate_discard(iter, len, priv, priv2, step); + WARN_ON_ONCE(1); + return 0; +} + #endif /* _LINUX_IOV_ITER_H */