RE: [PATCH 002/437] fs: add generic read/write iterator helpers
From: David Laight
Date: Tue Apr 16 2024 - 16:15:25 EST
From: Al Viro
> Sent: 15 April 2024 20:55
>
> On Thu, Apr 11, 2024 at 09:12:22AM -0600, Jens Axboe wrote:
>
> > +/* generic read side helper for drivers converting to ->read_iter() */
> > +ssize_t vfs_read_iter(struct kiocb *iocb, struct iov_iter *to,
> > + ssize_t (*read)(struct file *, char __user *,
> > + size_t, loff_t *))
> > +{
> > + return do_loop_readv(iocb->ki_filp, to, &iocb->ki_pos, 0, read);
> > +}
> > +EXPORT_SYMBOL(vfs_read_iter);
> > +
> > +/* generic write side helper for drivers converting to ->write_iter() */
> > +ssize_t vfs_write_iter(struct kiocb *iocb, struct iov_iter *from,
> > + ssize_t (*write)(struct file *, const char __user *,
> > + size_t, loff_t *))
> > +{
> > + return do_loop_writev(iocb->ki_filp, from, &iocb->ki_pos, 0, write);
> > +}
> > +EXPORT_SYMBOL(vfs_write_iter);
>
> Wait a minute; just what do you expect to happen if that ever gets called
> for ITER_BVEC or ITER_XARRAY?
The extra indirect call is also going to be noticeable.
You need a code loop with a direct call.
That probably requires the loop to be a #define.
I was also thinking about drivers that only handle 'user' buffers and
where there really isn't a requirement to do anything else.
I've a driver that basically does:
if (!access_ok(....))
return -EFAULT;
for (off = 0; off < len; off += 8) {
if (__put_user(readq(io_addr + off), uaddr + off))
return -EFAULT;
}
Any non-trivial change requires a function that return the first/only
user buffer address/length and an error for a non-user address.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)