Re: [PATCH 3/4] io_uring: add IORING_OP_READ[WRITE]_SPLICE_BUF

Jens Axboe
2023-02-12T02:43:03Z

On 2/11/23 6:48 PM, Ming Lei wrote:
> On Sat, Feb 11, 2023 at 10:13:37AM -0700, Jens Axboe wrote:
>> On 2/10/23 8:32?AM, Ming Lei wrote:
>>
>> One more comment on this.
>>
>>> +static int __io_prep_rw_splice_buf(struct io_kiocb *req,
>>> + struct io_rw_splice_buf_data *data,
>>> + struct file *splice_f,
>>> + size_t len,
>>> + loff_t splice_off)
>>> +{
>>> + unsigned flags = req->opcode == IORING_OP_READ_SPLICE_BUF ?
>>> + SPLICE_F_KERN_FOR_READ : SPLICE_F_KERN_FOR_WRITE;
>>> + struct splice_desc sd = {
>>> + .total_len = len,
>>> + .flags = flags | SPLICE_F_NONBLOCK | SPLICE_F_KERN_NEED_CONFIRM,
>>> + .pos = splice_off,
>>> + .u.data = data,
>>> + .ignore_sig = true,
>>> + };
>>> +
>>> + return splice_direct_to_actor(splice_f, &sd,
>>> + io_splice_buf_direct_actor);
>>
>> Is this safe? We end up using current->splice_pipe here, which should be
>> fine as long as things are left in a sane state after every operation.
>> Which they should be, just like a syscall would. Just wanted to make
>> sure you've considered that part.
>
> Yeah.
>
> Direct pipe is always left as empty when splice_direct_to_actor()
> returns. Pipe buffers(pages) are produced from ->splice_read()
> called from splice_direct_to_actor(), and consumed by
> io_splice_buf_direct_actor().
>
> If any error is returned, direct pipe is empty too, and we just
> need to drop reference of sliced pages by io_rw_cleanup_splice_buf().

OK thanks for confirming, then that should be fine as we can
obviously not have two syscalls (or sendfile(2) and task_work from
io_uring) running at the same time.

--
Jens Axboe