Subject: Re: [PATCH v5 05/11] iov_iter: Convert iterate*() to inline funcs

From: Simon Horman <[email-masked]>
Date: Fri, 22 Sep 2023 10:32:27 +0100

On Wed, Sep 20, 2023 at 11:22:25PM +0100, David Howells wrote:

...

> @@ -312,23 +192,29 @@ size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i)
>  		return 0;
>  	if (user_backed_iter(i))
>  		might_fault();
> -	iterate_and_advance(i, bytes, base, len, off,
> -		copyout(base, addr + off, len),
> -		memcpy(base, addr + off, len)
> -	)
> -
> -	return bytes;
> +	return iterate_and_advance(i, bytes, (void *)addr,
> +				   copy_to_user_iter, memcpy_to_iter);
>  }
>  EXPORT_SYMBOL(_copy_to_iter);
>  
>  #ifdef CONFIG_ARCH_HAS_COPY_MC
> -static int copyout_mc(void __user *to, const void *from, size_t n)
> -{
> -	if (access_ok(to, n)) {
> -		instrument_copy_to_user(to, from, n);
> -		n = copy_mc_to_user((__force void *) to, from, n);
> +static __always_inline
> +size_t copy_to_user_iter_mc(void __user *iter_to, size_t progress,
> +			    size_t len, void *from, void *priv2)
> +{
> +	if (access_ok(iter_to, len)) {
> +		from += progress;
> +		instrument_copy_to_user(iter_to, from, len);
> +		len = copy_mc_to_user(iter_to, from, len);

Hi David,

Sparse complains a bit about the line above, perhaps the '(__force void *)'
should be retained from the old code?

 lib/iov_iter.c:208:39: warning: incorrect type in argument 1 (different address spaces)
 lib/iov_iter.c:208:39:    expected void *to
 lib/iov_iter.c:208:39:    got void [noderef] __user *iter_to

>  	}
> -	return n;
> +	return len;
> +}
> +
> +static __always_inline
> +size_t memcpy_to_iter_mc(void *iter_to, size_t progress,
> +			 size_t len, void *from, void *priv2)
> +{
> +	return copy_mc_to_kernel(iter_to, from + progress, len);
>  }
>  
>  /**

...