From: Jens Axboe <axboe@kernel.dk>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] random: convert to using fops->write_iter()
Date: Thu, 19 May 2022 21:25:30 -0600 [thread overview]
Message-ID: <e70dfd3b-c2a6-d830-e3a0-6a25f0da9256@kernel.dk> (raw)
In-Reply-To: <YocEddeThi8VUcKb@zeniv-ca.linux.org.uk>
On 5/19/22 9:01 PM, Al Viro wrote:
> On Thu, May 19, 2022 at 05:43:15PM -0600, Jens Axboe wrote:
>
>> -static int write_pool(const char __user *ubuf, size_t len)
>> +static size_t write_pool(struct iov_iter *iter)
>> {
>> size_t block_len;
>> int ret = 0;
>>
>> - while (len) {
>> - block_len = min(len, sizeof(block));
>> - if (copy_from_user(block, ubuf, block_len)) {
>> - ret = -EFAULT;
>> + while (iov_iter_count(iter)) {
>> + block_len = min(iov_iter_count(iter), sizeof(block));
>> + if (!copy_from_iter(block, block_len, iter)) {
>> + if (!ret)
>> + ret = -EFAULT;
>> goto out;
>> }
>
> Feed it a buffer with only 1 byte mapped, watch it'll pass to mix_pool_bytes().
> And see how much of 'block' has been used uninitialized...
I don't follow? Buffer with 1 byte, iter setup with 1 byte. We copy 1 byte,
and we pass 1 byte to mix_pool_bytes(). What am I missing?
> And why bother with that min thing, anyway?
>
> ssize_t ret = 0;
>
> while (iov_iter_count(iter)) {
> u8 block[BLAKE2S_BLOCK_SIZE];
> size_t copied = copy_from_iter(block, sizeof(block), iter);
> if (!copied) {
> if (!ret)
> ret = -EFAULT;
> break;
> }
> mix_pool_bytes(block, copied);
> ret += copied;
> }
> return ret;
>
> and be done with that...
Agree, that does look better, the min() part could've been killed with
the conversion indeed.
>> @@ -1382,11 +1378,16 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>> return -EINVAL;
>> if (get_user(size, p++))
>> return -EFAULT;
>> - retval = write_pool((const char __user *)p, size);
>> +
>> + iov.iov_base = p;
>> + iov.iov_len = size;
>> + iov_iter_init(&iter, WRITE, &iov, 1, size);
>
> That'd be
> import_single_range(WRITE, p, size, &iov, &iter);
Yep that'd be a simpler equivalent.
--
Jens Axboe
next prev parent reply other threads:[~2022-05-20 3:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-19 23:43 [PATCH] random: convert to using fops->write_iter() Jens Axboe
2022-05-19 23:52 ` Jens Axboe
2022-05-20 0:08 ` Jason A. Donenfeld
2022-05-20 0:32 ` Jens Axboe
2022-05-20 0:18 ` Jason A. Donenfeld
2022-05-20 0:32 ` Jens Axboe
2022-05-20 3:01 ` Al Viro
2022-05-20 3:25 ` Jens Axboe [this message]
2022-05-20 3:31 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e70dfd3b-c2a6-d830-e3a0-6a25f0da9256@kernel.dk \
--to=axboe@kernel.dk \
--cc=Jason@zx2c4.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.