Re: [git pull] iov_iter fixes
From: Linus Torvalds
Date: Fri Sep 10 2021 - 12:45:06 EST
On Fri, Sep 10, 2021 at 9:06 AM Jens Axboe <axboe@xxxxxxxxx> wrote:
>
> +static void io_iter_restore(struct iov_iter *iter, struct iov_iter_state *state,
> + ssize_t did_bytes)
> +{
> + iov_iter_restore_state(iter, state);
> + if (did_bytes > 0)
> + iov_iter_advance(iter, did_bytes);
> +}
This approach looks conceptually good to me.
Just name it "iov_iter_restore()", and (together with the actual
iov_iter_restore_state() - I don't think it makes much sense to inline
something like this that is by definition for the slow path when
something failed) move it to lib/iov_iter.c
If this allows us to remove the 'truncated' field from the iov_iter, I
think it's a win overall.
That said, I think your actual implementation of
iov_iter_restore_state() is buggy. It's not just those state bits you
need to restore, you do need to do all the "back out the i->iov/bvec
pointers" games too. All the stuff that iov_iter_revert() does.
Which means that I think your tricks to try to share the 'struct
iov_iter_state' with the 'struct iov_iter' using unions are just ugly
and pointless and make for more complex code. Because you can't just
save/restore the 'state part' of it all, you do have to do more than
that.
So instead of the union, just have the state in some sane (different)
form, and do the revert/advance thing taking different types of
iterators into account. This is not supposed to be
performance-critical code.
Alternatively, you'd need to make the state part be *both* the unions,
and restore the pointers that don't need restoring too. You end up
with pretty much all of iov_iter.
Al, what do you think?
Linus