2022-05-20 18:57:27

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCHSET 0/2] Fix splice from random/urandom

On 5/19/22 6:48 PM, Jason A. Donenfeld wrote:
> Hi Jens,
>
> On Thu, May 19, 2022 at 06:02:55PM -0600, Jens Axboe wrote:
>> On 5/19/22 6:00 PM, Jason A. Donenfeld wrote:
>>> Hi Jens,
>>>
>>> On Fri, May 20, 2022 at 1:57 AM Jens Axboe <[email protected]> wrote:
>>>>
>>>> On 5/19/22 5:27 PM, Jason A. Donenfeld wrote:
>>>>> Hi Jens,
>>>>>
>>>>> On Fri, May 20, 2022 at 1:25 AM Jens Axboe <[email protected]> wrote:
>>>>>> I'll leave that to you :-)
>>>>>
>>>>> Alright, I'll have a look. Which one do I want here? This series adds
>>>>> splice_read/splice_write. The new thing would be sendpage? Or
>>>>> copy_file_range? Or something else?
>>>>
>>>> For copying kernel memory? It's really the same thing, you just
>>>> initialize the iter as an ITER_KVEC instead. The nice thing about the
>>>> iov_iter iterator that it then hides that for you, call the same copy
>>>> in/out helpers for it.
>>>
>>> Err, maybe we're talking about different things? I was thinking about
>>> the plumbing to make splice/sendfile work on non-pipes.
>>
>> Ah I see. sendfile() just uses splice() internally, so that'll work
>> (again) with my changes. splice(), by definition, either moves to and
>> from a pipe. Hence one of the fds must be a pipe. Does that answer the
>> question?
>
> sendfile() returns -EINVAL even with your patches. Only splicing to pipes
> seems to work.

Huh, that really should work. Are you trying to sendfile() to random? If
so, you need that last write_iter patch too, and add the splice_write as
I mentioned.

--
Jens Axboe



2022-05-22 23:05:20

by Jason A. Donenfeld

[permalink] [raw]
Subject: Re: [PATCHSET 0/2] Fix splice from random/urandom

Hi Jens,

On Thu, May 19, 2022 at 06:56:12PM -0600, Jens Axboe wrote:
> On 5/19/22 6:48 PM, Jason A. Donenfeld wrote:
> > sendfile() returns -EINVAL even with your patches. Only splicing to pipes
> > seems to work.
>
> Huh, that really should work. Are you trying to sendfile() to random? If
> so, you need that last write_iter patch too, and add the splice_write as
> I mentioned.

No, I've only tried the read side so far. I made a little program:

#include <sys/sendfile.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
ssize_t s = sendfile(1, 0, NULL, 0xffff);
fprintf(stderr, "ret: %zd\n", s);
return 0;
}

Then I ran `./a.out < /dev/urandom > /dev/null`. Fails. OTOH, if I
replace /dev/urandom with an ordinary file, it succeeds.

Jason