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 <[email protected]>
cc: Alexander Viro <[email protected]>
cc: Jens Axboe <[email protected]>
cc: Christoph Hellwig <[email protected]>
cc: Christian Brauner <[email protected]>
cc: Matthew Wilcox <[email protected]>
cc: Linus Torvalds <[email protected]>
cc: David Laight <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
---
include/linux/iov_iter.h | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h
index 270454a6703d..a94d605d7386 100644
--- a/include/linux/iov_iter.h
+++ b/include/linux/iov_iter.h
@@ -271,4 +271,35 @@ 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.
+ * @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 */
On Wed, Sep 20, 2023 at 11:22:27PM +0100, David Howells wrote:
> 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 <[email protected]>
> cc: Alexander Viro <[email protected]>
> cc: Jens Axboe <[email protected]>
> cc: Christoph Hellwig <[email protected]>
> cc: Christian Brauner <[email protected]>
> cc: Matthew Wilcox <[email protected]>
> cc: Linus Torvalds <[email protected]>
> cc: David Laight <[email protected]>
> cc: [email protected]
> cc: [email protected]
> cc: [email protected]
> ---
> include/linux/iov_iter.h | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h
> index 270454a6703d..a94d605d7386 100644
> --- a/include/linux/iov_iter.h
> +++ b/include/linux/iov_iter.h
> @@ -271,4 +271,35 @@ 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.
nit: an entry for @priv2 belongs here
> + * @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)
> +{
...