Re: [RFC][PATCHSET] iov_iter work

From: Linus Torvalds
Date: Mon Jun 07 2021 - 19:36:22 EST


On Mon, Jun 7, 2021 at 3:01 PM Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> (b) on all the common non-SET_FS architectures, kernel threads using
> iov_iter_init() wouldn't work anyway, because on those architectures
> it would always fill the thing in with an iov, not a kvec.

Thinking more about this thing, I think it means that what we *should*
do is simply just

void iov_iter_init(struct iov_iter *i, unsigned int direction,
const struct iovec *iov, unsigned long nr_segs,
size_t count)
{
WARN_ON_ONCE(direction & ~(READ | WRITE));
iWARN_ON_ONCE(uaccess_kernel());
*i = (struct iov_iter) {
.iter_type = ITER_IOVEC,
.data_source = direction,
.iov = iov,
.nr_segs = nr_segs,
.iov_offset = 0,
.count = count
};
}

because filling it with a kvec is simply wrong. It's wrong exactly due
to the fact that *if* we have a kernel thread, all the modern
non-SET_FS architectures will just ignore that entirely, and always
use the iov meaning.

So just do that WARN_ON_ONCE() to show that something is wrong (the
exact same way that the direction thing needs to be proper), and then
just fill it in as an ITER_IOVEC.

Because handling that legacy KERNEL_DS case as a KVEC is actively not
right anyway and doesn't match what a kernel thread would do on x86 or
arm64, so don't even try.

Linus