On 12/05/2023 18:29, Kevin Brodsky wrote:
I can see this comes from __iov_iter_get_pages_alloc, but it still gives me a headache figuring out why it it like this...
I am there with you. I personally don't understand it either. I was indeed hoping that somebody would shed some light on it.
That one made me twitch too. Took me a while to figure it out, but in fact it makes perfect sense, if you think about it from the right angle! iov_iter_rw() returns the direction of *data_source*. What the iterator does is on the other side, hence the direction is reversed. Take for instance this line in new_sync_read():
iov_iter_ubuf(&iter, READ, buf, len);
Here READ means "we're reading a file", and as a consequence we are *writing* to the specified buffer. For that reason even simple syscalls like read/write are confusing in terms of data direction...
FWIW we're not the only ones getting confused by all this, in the meantime a patch by Al Viro [1] renaming all such uses of READ/WRITE to ITER_{DEST,SOURCE} appeared in mainline. The discussion with Torvalds under that patch is worth a glance.
It might make sense to cherry-pick that patch as part of this series, to avoid having to replace all the READ/WRITE in your changes next time we rebase.
Kevin
[1] https://lore.kernel.org/all/20221028023352.3532080-12-viro@zeniv.linux.org.u...