Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4383758ybl; Tue, 21 Jan 2020 19:24:12 -0800 (PST) X-Google-Smtp-Source: APXvYqz9zUNEsv85ru26cI2CaFs+vDqWvMcMrdlP4BZgPg4JLYltgrjsgEONpD5X2o7KAytb3cjn X-Received: by 2002:aca:ea43:: with SMTP id i64mr5540379oih.30.1579663452759; Tue, 21 Jan 2020 19:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579663452; cv=none; d=google.com; s=arc-20160816; b=gzpMiTniNc7wcD4FB91coruWsg+svYMJX3/dl9hJniEPLTuJWgbAC6TElNy8+6CQYj xwKyft4ffle5fYazJgw742Fq94uVQZ2y2eNIunci/nq1I7A3Bv2WNhFC8+rDk/rdTDLZ j4pwi3XgYFihBo73ekVqNf+sC7F+vuSSu/XJbNXMWd5tRzvnNafhXEkpL6D3LiqOQKc0 zwh4HtkcFN0js322G7wvAhq/+bX5gL27Qg3KprECXA2E1fnEU2wnC2W6ucLgxtwcMWRl L0pNbmNgJMrhpQrVgCKwRfyGH3+HSo88RfIx/Rl/wXSoAFKGeRmXpKbYb5q6jdQwn/h5 P6Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=WzWlqSAwBUYEHp474vY25WNq5cVSn3o2GyR5izuQQ6I=; b=qVB2xBhHpM0u/rAcmi+8rmdFrju2ajXEkaKYyKZ8W8we4lALHDlAOUnBTlR1QVF37/ fzEMvPoVrarLWhNxrob+WkFV2JIeEUpgI+Hf5eckVN7Z/5fYvQNpAKAyy3Inj0TZbMLX q3Vz5CiwYwE3IZswLFEWCQg+pKYwHo83/bACSIdDxbSUoo81wnH+IV29vFfR6XrnZzaX YERfMRcYPYayepcQN9G4DvrOALg8ZNhEtWuX2tWU9eceDcjjZRQOZoyfEzMV9dsNGBLx Q9K4bkQ0JrOS5a4VCA88UBof9zIDmm8l9bnAqSVzV+bDiCPDnt94eYHaulFs1rj0NWBQ aIEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=WqqDeek7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o66si19586387oig.193.2020.01.21.19.24.00; Tue, 21 Jan 2020 19:24:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=WqqDeek7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729224AbgAVDXD (ORCPT + 99 others); Tue, 21 Jan 2020 22:23:03 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44238 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729093AbgAVDXD (ORCPT ); Tue, 21 Jan 2020 22:23:03 -0500 Received: by mail-pl1-f195.google.com with SMTP id d9so2290086plo.11 for ; Tue, 21 Jan 2020 19:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=WzWlqSAwBUYEHp474vY25WNq5cVSn3o2GyR5izuQQ6I=; b=WqqDeek7IOETWuK4uyhivNNdGgPsGTJ+LQ4rSmigeF5wvVloRRnW12aj64MLBWr6jj /ESnNSbAnL/NKNkcNYKOUoj4VKBb/N2QWdU/ZQIHt89BWLB7lLagV1EMWo00XgtcP+Rm 0obLYR61L1gI1UB9v0WOJgixa+wrnRME/jorMM3AtfVfL1xLSVWLr5WUv4sbYuHwzKI0 5WOBxlpUzIWV2u26LJoUn/7WsbyEyY9HMt80MIOfexO/ibceakxxAGnNAoksNRFvmleF ndamVdEYFdkDsEoPm26uKMK8EC+AvcwbvKiuI3PfcsgEeHM7dxRWrk7K05HgZ5y18Nn0 CBWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WzWlqSAwBUYEHp474vY25WNq5cVSn3o2GyR5izuQQ6I=; b=QGSn/ffWmU/pkpvMWkoVIbQdwh6CKBt13h1wA8Wr/Xu6Auq3qafQDyC60TD9uOgS4J Ext0+NwoVkYZPY0BYKYaaiLiU0xdShnNffpLEC3F1WyM4/9080hqr2sHloU2wKe/TE5D KKMyV0EF1RbJ1/AqLjO6Tm3qovLxkp7wWvACSlIpOLFfvUDbYLNuMuUWTuT60+yAarCI SJFOpvfKtJN37dOPXnpF0iYtqGGWzHSJA7x6YwG2tS50Qa1lrT3wxNviEHqf8uq9D1y4 UUTU3m9P1xnvwzVn4x7+mFUWXppvc8mdcIbUb+IP60P0qLaNGyqtTiz4BOlBHKi2Yibk 7D/g== X-Gm-Message-State: APjAAAXfTnsCm4Db5MPXGgtSuNDrEZR3Em8vp7ymevQAQ4PUASD4PcVB eOzmBOMl4hktAnq78eZ4RGToHw== X-Received: by 2002:a17:90b:8b:: with SMTP id bb11mr567939pjb.27.1579663381129; Tue, 21 Jan 2020 19:23:01 -0800 (PST) Received: from [192.168.1.188] ([66.219.217.145]) by smtp.gmail.com with ESMTPSA id w4sm830441pjt.23.2020.01.21.19.23.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2020 19:23:00 -0800 (PST) Subject: Re: [PATCH 3/3] io_uring: add splice(2) support To: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Alexander Viro References: <8bfd9a57bf42cfc10ee7195969058d6da277deed.1579649589.git.asml.silence@gmail.com> <6d43b9d7-209a-2bbf-e2c2-e125e84b46ab@kernel.dk> <14499431-0409-5d57-9b08-aff95b9d2160@gmail.com> <578003e9-1af2-4df6-d9e1-cdbbbb701bf7@gmail.com> From: Jens Axboe Message-ID: <60459de4-3497-0226-127a-e748486852c6@kernel.dk> Date: Tue, 21 Jan 2020 20:22:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <578003e9-1af2-4df6-d9e1-cdbbbb701bf7@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/21/20 8:16 PM, Pavel Begunkov wrote: > On 22/01/2020 05:47, Jens Axboe wrote: >> On 1/21/20 7:40 PM, Pavel Begunkov wrote: >>>>> @@ -719,6 +730,11 @@ static const struct io_op_def io_op_defs[] = { >>>>> .needs_file = 1, >>>>> .fd_non_neg = 1, >>>>> }, >>>>> + [IORING_OP_SPLICE] = { >>>>> + .needs_file = 1, >>>>> + .hash_reg_file = 1, >>>>> + .unbound_nonreg_file = 1, >>>>> + } >>>>> }; >>>>> >>>>> static void io_wq_submit_work(struct io_wq_work **workptr); >>>> >>>> I probably want to queue up a reservation for the EPOLL_CTL that I >>>> haven't included yet, but which has been tested. But that's easily >>>> manageable, so no biggy on my end. >>> >>> I didn't quite get it. Do you mean collision of opcode numbers? >> >> Yeah that's all I meant, sorry wasn't too clear. But you can disregard, >> I'll just pop a reservation in front if/when this is ready to go in if >> it's before EPOLL_CTL op. >> >>>>> diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h >>>>> index 57d05cc5e271..f234b13e7ed3 100644 >>>>> --- a/include/uapi/linux/io_uring.h >>>>> +++ b/include/uapi/linux/io_uring.h >>>>> @@ -23,8 +23,14 @@ struct io_uring_sqe { >>>>> __u64 off; /* offset into file */ >>>>> __u64 addr2; >>>>> }; >>>>> - __u64 addr; /* pointer to buffer or iovecs */ >>>>> - __u32 len; /* buffer size or number of iovecs */ >>>>> + union { >>>>> + __u64 addr; /* pointer to buffer or iovecs */ >>>>> + __u64 off_out; >>>>> + }; >>>>> + union { >>>>> + __u32 len; /* buffer size or number of iovecs */ >>>>> + __s32 fd_out; >>>>> + }; >>>>> union { >>>>> __kernel_rwf_t rw_flags; >>>>> __u32 fsync_flags; >>>>> @@ -37,10 +43,12 @@ struct io_uring_sqe { >>>>> __u32 open_flags; >>>>> __u32 statx_flags; >>>>> __u32 fadvise_advice; >>>>> + __u32 splice_flags; >>>>> }; >>>>> __u64 user_data; /* data to be passed back at completion time */ >>>>> union { >>>>> __u16 buf_index; /* index into fixed buffers, if used */ >>>>> + __u64 splice_len; >>>>> __u64 __pad2[3]; >>>>> }; >>>>> }; >>>> >>>> Not a huge fan of this, also mean splice can't ever used fixed buffers. >>>> Hmm... >>> >>> But it's not like splice() ever uses user buffers. Isn't it? vmsplice >>> does, but that's another opcode. >> >> I guess that's true, I had vmsplice on my mind for this as well. But >> won't be a problem there, since it doesn't take 6 arguments like splice >> does. >> >> Another option is to do an indirect for splice, stuff the arguments in a >> struct that's passed in as a pointer in ->addr. A bit slower, but >> probably not a huge deal. >> >>>>> @@ -67,6 +75,9 @@ enum { >>>>> /* always go async */ >>>>> #define IOSQE_ASYNC (1U << IOSQE_ASYNC_BIT) >>>>> >>>>> +/* op custom flags */ >>>>> +#define IOSQE_SPLICE_FIXED_OUT (1U << 16) >>>>> + >>>> >>>> I don't think it's unreasonable to say that if you specify >>>> IOSQE_FIXED_FILE, then both are fixed. If not, then none of them are. >>>> What do you think? >>>> >>> >>> It's plausible to register only one end for splicing, e.g. splice from >>> short-lived sockets to pre-registered buffers-pipes. And it's clearer >>> do it now. >> >> You're probably right, though it's a bit nasty to add an unrelated flag >> in the splice flag space... We should probably reserve it in splice >> instead, and just not have it available from the regular system call. >> > Agree, it looks bad. I don't want to add it into sqe->splice_flags to > not clash with splice(2) in the future, but could have a separate > field in @sqe... or can leave in in sqe->flags, as it's done in the > patch, but that's like a portion of bits would be opcode specific and > we would need to set rules for their use. It won't clash with splice(2), just make that flag illegal if done through splice(2) directly. Honestly I think that's (by FAR) the best way to do it, having a private io_uring flag that acts as a splice flag is really confusing and prone to breakage. Not that it's a huge issue with splice as the flags have been stable for years, so don't really see a high risk of collision. But we should still do it right, which means adding SPLICE_F_OUT_FIXED or whatever you want to call it. Do that as a prep patch, make do_splice() into __do_splice(), and have io_uring call __do_splice(). Currently splice(2) is permissive in terms of flags, so maybe just mask it in do_splice() to be on the safe side. Then we know only internal users will set SPLICE_F_OUT_FIXED, and we'll never run into the risk of having a collision as it's part of the flag space anyway. The sqe->flags space is very tight, so adding a splice specific opcode there would be bad. -- Jens Axboe