public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Pavel Begunkov <asml.silence@gmail.com>, io-uring@vger.kernel.org
Subject: Re: [PATCH v4 2/6] io_uring/mock: add cmd using vectored regbufs
Date: Fri, 30 May 2025 09:34:14 -0600	[thread overview]
Message-ID: <0742c127-9991-4181-af67-1efaab9e12b3@kernel.dk> (raw)
In-Reply-To: <4e5e0207-9749-4d49-8d55-9710c972b673@gmail.com>

On 5/30/25 8:53 AM, Pavel Begunkov wrote:
> On 5/30/25 15:37, Jens Axboe wrote:
>> On 5/30/25 7:40 AM, Pavel Begunkov wrote:
>>> On 5/30/25 14:25, Jens Axboe wrote:
>>>> On 5/30/25 6:51 AM, Pavel Begunkov wrote:
>>>>> +static int io_copy_regbuf(struct iov_iter *reg_iter, void __user *ubuf)
>>>>> +{
>>>>> +    size_t ret, copied = 0;
>>>>> +    size_t buflen = PAGE_SIZE;
>>>>> +    void *tmp_buf;
>>>>> +
>>>>> +    tmp_buf = kzalloc(buflen, GFP_KERNEL);
>>>>> +    if (!tmp_buf)
>>>>> +        return -ENOMEM;
>>>>> +
>>>>> +    while (iov_iter_count(reg_iter)) {
>>>>> +        size_t len = min(iov_iter_count(reg_iter), buflen);
>>>>> +
>>>>> +        if (iov_iter_rw(reg_iter) == ITER_SOURCE) {
>>>>> +            ret = copy_from_iter(tmp_buf, len, reg_iter);
>>>>> +            if (ret <= 0)
>>>>> +                break;
>>>>> +            if (copy_to_user(ubuf, tmp_buf, ret))
>>>>> +                break;
>>>>> +        } else {
>>>>> +            if (copy_from_user(tmp_buf, ubuf, len))
>>>>> +                break;
>>>>> +            ret = copy_to_iter(tmp_buf, len, reg_iter);
>>>>> +            if (ret <= 0)
>>>>> +                break;
>>>>> +        }
>>>>
>>>> Do copy_{to,from}_iter() not follow the same "bytes not copied" return
>>>> value that the copy_{to,from}_user() do? From a quick look, looks like
>>>> they do.
>>>>
>>>> Minor thing, no need for a respin just for that.
>>>
>>> One returns 0 on success the other the number of processed bytes.
>>
>> copy_{to,from}_user() returns bytes NOT processed, and I guess the iter
> 
> Sure, it doesn't contradict it, they follow different semantics.
> 
>> versions return bytes processed. Guess the code is fine, it's more so
>> the API that's a bit wonky on the copy/iter side.
> 
> Which API? This command or copy helpers? copy_{to,from}_user are used
> here in the way they're always used in the kernel, and that's fine,
> they're not supposed to fail for valid input. That's unlike iter
> helpers, which may return a partial result.

Not this command, the copy helpers in the kernel.

-- 
Jens Axboe

  reply	other threads:[~2025-05-30 15:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 12:51 [PATCH v4 0/6] io_uring/mock: add basic infra for test mock files Pavel Begunkov
2025-05-30 12:51 ` [PATCH v4 1/6] " Pavel Begunkov
2025-05-30 13:28   ` Jens Axboe
2025-05-30 13:57     ` Pavel Begunkov
2025-05-30 14:36       ` Jens Axboe
2025-05-30 14:09     ` Pavel Begunkov
2025-05-30 14:12       ` Pavel Begunkov
2025-05-30 14:26         ` Pavel Begunkov
2025-05-30 14:41           ` Jens Axboe
2025-05-30 15:11             ` Pavel Begunkov
2025-05-30 15:30               ` Jens Axboe
2025-05-30 18:14                 ` Pavel Begunkov
2025-06-02 15:19                   ` Jens Axboe
2025-06-02 15:31                     ` Pavel Begunkov
2025-06-02 15:41                       ` Jens Axboe
2025-05-30 18:04   ` Keith Busch
2025-05-30 18:21     ` Pavel Begunkov
2025-06-02 13:44       ` Jens Axboe
2025-05-30 12:51 ` [PATCH v4 2/6] io_uring/mock: add cmd using vectored regbufs Pavel Begunkov
2025-05-30 13:25   ` Jens Axboe
2025-05-30 13:40     ` Pavel Begunkov
2025-05-30 14:37       ` Jens Axboe
2025-05-30 14:53         ` Pavel Begunkov
2025-05-30 15:34           ` Jens Axboe [this message]
2025-05-30 12:52 ` [PATCH v4 3/6] io_uring/mock: add sync read/write Pavel Begunkov
2025-05-30 12:52 ` [PATCH v4 4/6] io_uring/mock: allow to choose FMODE_NOWAIT Pavel Begunkov
2025-05-30 12:52 ` [PATCH v4 5/6] io_uring/mock: support for async read/write Pavel Begunkov
2025-05-30 13:27   ` Jens Axboe
2025-05-30 13:49     ` Pavel Begunkov
2025-05-30 14:38       ` Jens Axboe
2025-05-30 12:52 ` [PATCH v4 6/6] io_uring/mock: add trivial poll handler Pavel Begunkov

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=0742c127-9991-4181-af67-1efaab9e12b3@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=asml.silence@gmail.com \
    --cc=io-uring@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox