* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
@ 2023-04-07 18:51 ` Keith Busch
2023-04-11 12:22 ` Breno Leitao
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Keith Busch @ 2023-04-07 18:51 UTC (permalink / raw)
To: dccp
On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
> Currently uring CMD operation relies on having large SQEs, but future
> operations might want to use normal SQE.
>
> The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
> but, for commands that use normal SQE size, it might be necessary to
> access the initial SQE fields outside of the payload/cmd block. So,
> saves the whole SQE other than just the pdu.
>
> This changes slighlty how the io_uring_cmd works, since the cmd
> structures and callbacks are not opaque to io_uring anymore. I.e, the
> callbacks can look at the SQE entries, not only, in the cmd structure.
>
> The main advantage is that we don't need to create custom structures for
> simple commands.
This looks good to me. The only disadvantage I can see is that the async
fallback allocates just a tiny bit more data than before, but no biggie.
Reviewed-by: Keith Busch <kbusch@kernel.org>
> @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> int io_uring_cmd_prep_async(struct io_kiocb *req)
> {
> struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> - size_t cmd_size;
> + size_t size = sizeof(struct io_uring_sqe);
>
> BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
One minor suggestion. The above is the only user of uring_cmd_pdu_size() now,
which is kind of a convoluted way to enfoce the offset of the 'cmd' field. It
may be more clear to replace these with:
BUILD_BUG_ON(offsetof(struct io_uring_sqe, cmd) = 48);
> - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
> + if (req->ctx->flags & IORING_SETUP_SQE128)
> + size <<= 1;
>
> - memcpy(req->async_data, ioucmd->cmd, cmd_size);
> + memcpy(req->async_data, ioucmd->sqe, size);
> return 0;
> }
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
2023-04-07 18:51 ` Keith Busch
@ 2023-04-11 12:22 ` Breno Leitao
2023-04-11 12:39 ` Pavel Begunkov
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Breno Leitao @ 2023-04-11 12:22 UTC (permalink / raw)
To: dccp
On Fri, Apr 07, 2023 at 12:51:44PM -0600, Keith Busch wrote:
> > @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> > int io_uring_cmd_prep_async(struct io_kiocb *req)
> > {
> > struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> > - size_t cmd_size;
> > + size_t size = sizeof(struct io_uring_sqe);
> >
> > BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> > BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
>
> One minor suggestion. The above is the only user of uring_cmd_pdu_size() now,
> which is kind of a convoluted way to enfoce the offset of the 'cmd' field. It
> may be more clear to replace these with:
I agree with you here. Basically it is a bug if the payload (pdu) size is
is different than 16 for single SQE or != 80 for extended SQE.
So, basically it is checking for two things:
* the cmd offset is 48
* the io_uring_sqe struct is 64
Since this is a uapi, I am not confidence that they will change at all.
I can replace the code with your suggestion.
> BUILD_BUG_ON(offsetof(struct io_uring_sqe, cmd) = 48);
It should be "offset(struct io_uring_sqe, cmd) != 48)", right?
Thanks for the review!
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
2023-04-07 18:51 ` Keith Busch
2023-04-11 12:22 ` Breno Leitao
@ 2023-04-11 12:39 ` Pavel Begunkov
2023-04-13 2:56 ` Ming Lei
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pavel Begunkov @ 2023-04-11 12:39 UTC (permalink / raw)
To: dccp
On 4/11/23 13:22, Breno Leitao wrote:
> On Fri, Apr 07, 2023 at 12:51:44PM -0600, Keith Busch wrote:
>>> @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
>>> int io_uring_cmd_prep_async(struct io_kiocb *req)
>>> {
>>> struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
>>> - size_t cmd_size;
>>> + size_t size = sizeof(struct io_uring_sqe);
>>>
>>> BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
>>> BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
>>
>> One minor suggestion. The above is the only user of uring_cmd_pdu_size() now,
>> which is kind of a convoluted way to enfoce the offset of the 'cmd' field. It
>> may be more clear to replace these with:
>
> I agree with you here. Basically it is a bug if the payload (pdu) size is
> is different than 16 for single SQE or != 80 for extended SQE.
>
> So, basically it is checking for two things:
> * the cmd offset is 48
> * the io_uring_sqe struct is 64
>
> Since this is a uapi, I am not confidence that they will change at all.
> I can replace the code with your suggestion.
>
>> BUILD_BUG_ON(offsetof(struct io_uring_sqe, cmd) = 48);
>
> It should be "offset(struct io_uring_sqe, cmd) != 48)", right?
Which is already checked, see io_uring_init()
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (2 preceding siblings ...)
2023-04-11 12:39 ` Pavel Begunkov
@ 2023-04-13 2:56 ` Ming Lei
2023-04-13 16:47 ` Breno Leitao
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ming Lei @ 2023-04-13 2:56 UTC (permalink / raw)
To: dccp
On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
> Currently uring CMD operation relies on having large SQEs, but future
> operations might want to use normal SQE.
>
> The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
> but, for commands that use normal SQE size, it might be necessary to
> access the initial SQE fields outside of the payload/cmd block. So,
> saves the whole SQE other than just the pdu.
>
> This changes slighlty how the io_uring_cmd works, since the cmd
> structures and callbacks are not opaque to io_uring anymore. I.e, the
> callbacks can look at the SQE entries, not only, in the cmd structure.
>
> The main advantage is that we don't need to create custom structures for
> simple commands.
>
> Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
...
> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> index 2e4c483075d3..9648134ccae1 100644
> --- a/io_uring/uring_cmd.c
> +++ b/io_uring/uring_cmd.c
> @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> int io_uring_cmd_prep_async(struct io_kiocb *req)
> {
> struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> - size_t cmd_size;
> + size_t size = sizeof(struct io_uring_sqe);
>
> BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
>
> - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
> + if (req->ctx->flags & IORING_SETUP_SQE128)
> + size <<= 1;
>
> - memcpy(req->async_data, ioucmd->cmd, cmd_size);
> + memcpy(req->async_data, ioucmd->sqe, size);
The copy will make some fields of sqe become READ TWICE, and driver may see
different sqe field value compared with the one observed in io_init_req().
Can this kind of inconsistency cause trouble to driver?
If it isn't one problem, this patch looks fine.
But I guess any access on cmd->sqe in driver may have to be careful for dealing
with potential post-sqe-update.
Thanks,
Ming
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (3 preceding siblings ...)
2023-04-13 2:56 ` Ming Lei
@ 2023-04-13 16:47 ` Breno Leitao
2023-04-14 2:12 ` Ming Lei
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Breno Leitao @ 2023-04-13 16:47 UTC (permalink / raw)
To: dccp
Hello Ming,
On Thu, Apr 13, 2023 at 10:56:49AM +0800, Ming Lei wrote:
> On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
> > Currently uring CMD operation relies on having large SQEs, but future
> > operations might want to use normal SQE.
> >
> > The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
> > but, for commands that use normal SQE size, it might be necessary to
> > access the initial SQE fields outside of the payload/cmd block. So,
> > saves the whole SQE other than just the pdu.
> >
> > This changes slighlty how the io_uring_cmd works, since the cmd
> > structures and callbacks are not opaque to io_uring anymore. I.e, the
> > callbacks can look at the SQE entries, not only, in the cmd structure.
> >
> > The main advantage is that we don't need to create custom structures for
> > simple commands.
> >
> > Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
>
> ...
>
> > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> > index 2e4c483075d3..9648134ccae1 100644
> > --- a/io_uring/uring_cmd.c
> > +++ b/io_uring/uring_cmd.c
> > @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> > int io_uring_cmd_prep_async(struct io_kiocb *req)
> > {
> > struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> > - size_t cmd_size;
> > + size_t size = sizeof(struct io_uring_sqe);
> >
> > BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> > BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
> >
> > - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
> > + if (req->ctx->flags & IORING_SETUP_SQE128)
> > + size <<= 1;
> >
> > - memcpy(req->async_data, ioucmd->cmd, cmd_size);
> > + memcpy(req->async_data, ioucmd->sqe, size);
>
> The copy will make some fields of sqe become READ TWICE, and driver may see
> different sqe field value compared with the one observed in io_init_req().
This copy only happens if the operation goes to the async path
(calling io_uring_cmd_prep_async()). This only happens if
f_op->uring_cmd() returns -EAGAIN.
ret = file->f_op->uring_cmd(ioucmd, issue_flags);
if (ret = -EAGAIN) {
if (!req_has_async_data(req)) {
if (io_alloc_async_data(req))
return -ENOMEM;
io_uring_cmd_prep_async(req);
}
return -EAGAIN;
}
Are you saying that after this copy, the operation is still reading from
sqe instead of req->async_data?
If you have an example of the two copes flow, that would be great.
Thanks for the review,
Breno
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (4 preceding siblings ...)
2023-04-13 16:47 ` Breno Leitao
@ 2023-04-14 2:12 ` Ming Lei
2023-04-14 13:12 ` Pavel Begunkov
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Ming Lei @ 2023-04-14 2:12 UTC (permalink / raw)
To: dccp
On Thu, Apr 13, 2023 at 09:47:56AM -0700, Breno Leitao wrote:
> Hello Ming,
>
> On Thu, Apr 13, 2023 at 10:56:49AM +0800, Ming Lei wrote:
> > On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
> > > Currently uring CMD operation relies on having large SQEs, but future
> > > operations might want to use normal SQE.
> > >
> > > The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
> > > but, for commands that use normal SQE size, it might be necessary to
> > > access the initial SQE fields outside of the payload/cmd block. So,
> > > saves the whole SQE other than just the pdu.
> > >
> > > This changes slighlty how the io_uring_cmd works, since the cmd
> > > structures and callbacks are not opaque to io_uring anymore. I.e, the
> > > callbacks can look at the SQE entries, not only, in the cmd structure.
> > >
> > > The main advantage is that we don't need to create custom structures for
> > > simple commands.
> > >
> > > Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
> > > Signed-off-by: Breno Leitao <leitao@debian.org>
> > > ---
> >
> > ...
> >
> > > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> > > index 2e4c483075d3..9648134ccae1 100644
> > > --- a/io_uring/uring_cmd.c
> > > +++ b/io_uring/uring_cmd.c
> > > @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> > > int io_uring_cmd_prep_async(struct io_kiocb *req)
> > > {
> > > struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> > > - size_t cmd_size;
> > > + size_t size = sizeof(struct io_uring_sqe);
> > >
> > > BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> > > BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
> > >
> > > - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
> > > + if (req->ctx->flags & IORING_SETUP_SQE128)
> > > + size <<= 1;
> > >
> > > - memcpy(req->async_data, ioucmd->cmd, cmd_size);
> > > + memcpy(req->async_data, ioucmd->sqe, size);
> >
> > The copy will make some fields of sqe become READ TWICE, and driver may see
> > different sqe field value compared with the one observed in io_init_req().
>
> This copy only happens if the operation goes to the async path
> (calling io_uring_cmd_prep_async()). This only happens if
> f_op->uring_cmd() returns -EAGAIN.
>
> ret = file->f_op->uring_cmd(ioucmd, issue_flags);
> if (ret = -EAGAIN) {
> if (!req_has_async_data(req)) {
> if (io_alloc_async_data(req))
> return -ENOMEM;
> io_uring_cmd_prep_async(req);
> }
> return -EAGAIN;
> }
>
> Are you saying that after this copy, the operation is still reading from
> sqe instead of req->async_data?
I meant that the 2nd read is on the sqe copy(req->aync_data), but same
fields can become different between the two READs(first is done on original
SQE during io_init_req(), and second is done on sqe copy in driver).
Will this kind of inconsistency cause trouble for driver? Cause READ
TWICE becomes possible with this patch.
>
> If you have an example of the two copes flow, that would be great.
Not any example yet, but also not see any access on cmd->sqe(except for cmd_op)
in your patches too.
Thanks,
Ming
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (5 preceding siblings ...)
2023-04-14 2:12 ` Ming Lei
@ 2023-04-14 13:12 ` Pavel Begunkov
2023-04-14 13:59 ` Ming Lei
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pavel Begunkov @ 2023-04-14 13:12 UTC (permalink / raw)
To: dccp
On 4/14/23 03:12, Ming Lei wrote:
> On Thu, Apr 13, 2023 at 09:47:56AM -0700, Breno Leitao wrote:
>> Hello Ming,
>>
>> On Thu, Apr 13, 2023 at 10:56:49AM +0800, Ming Lei wrote:
>>> On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
>>>> Currently uring CMD operation relies on having large SQEs, but future
>>>> operations might want to use normal SQE.
>>>>
>>>> The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
>>>> but, for commands that use normal SQE size, it might be necessary to
>>>> access the initial SQE fields outside of the payload/cmd block. So,
>>>> saves the whole SQE other than just the pdu.
>>>>
>>>> This changes slighlty how the io_uring_cmd works, since the cmd
>>>> structures and callbacks are not opaque to io_uring anymore. I.e, the
>>>> callbacks can look at the SQE entries, not only, in the cmd structure.
>>>>
>>>> The main advantage is that we don't need to create custom structures for
>>>> simple commands.
>>>>
>>>> Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
>>>> Signed-off-by: Breno Leitao <leitao@debian.org>
>>>> ---
>>>
>>> ...
>>>
>>>> diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
>>>> index 2e4c483075d3..9648134ccae1 100644
>>>> --- a/io_uring/uring_cmd.c
>>>> +++ b/io_uring/uring_cmd.c
>>>> @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
>>>> int io_uring_cmd_prep_async(struct io_kiocb *req)
>>>> {
>>>> struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
>>>> - size_t cmd_size;
>>>> + size_t size = sizeof(struct io_uring_sqe);
>>>>
>>>> BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
>>>> BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
>>>>
>>>> - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
>>>> + if (req->ctx->flags & IORING_SETUP_SQE128)
>>>> + size <<= 1;
>>>>
>>>> - memcpy(req->async_data, ioucmd->cmd, cmd_size);
>>>> + memcpy(req->async_data, ioucmd->sqe, size);
>>>
>>> The copy will make some fields of sqe become READ TWICE, and driver may see
>>> different sqe field value compared with the one observed in io_init_req().
>>
>> This copy only happens if the operation goes to the async path
>> (calling io_uring_cmd_prep_async()). This only happens if
>> f_op->uring_cmd() returns -EAGAIN.
>>
>> ret = file->f_op->uring_cmd(ioucmd, issue_flags);
>> if (ret = -EAGAIN) {
>> if (!req_has_async_data(req)) {
>> if (io_alloc_async_data(req))
>> return -ENOMEM;
>> io_uring_cmd_prep_async(req);
>> }
>> return -EAGAIN;
>> }
>>
>> Are you saying that after this copy, the operation is still reading from
>> sqe instead of req->async_data?
>
> I meant that the 2nd read is on the sqe copy(req->aync_data), but same
> fields can become different between the two READs(first is done on original
> SQE during io_init_req(), and second is done on sqe copy in driver).
>
> Will this kind of inconsistency cause trouble for driver? Cause READ
> TWICE becomes possible with this patch.
Right it might happen, and I was keeping that in mind, but it's not
specific to this patch. It won't reload core io_uring bits, and all
fields cmds use already have this problem.
Unless there is a better option, the direction we'll be moving in is
adding a preparation step that should read and stash parts of SQE
it cares about, which should also make full SQE copy not
needed / optional.
>> If you have an example of the two copes flow, that would be great.
>
> Not any example yet, but also not see any access on cmd->sqe(except for cmd_op)
> in your patches too.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (6 preceding siblings ...)
2023-04-14 13:12 ` Pavel Begunkov
@ 2023-04-14 13:59 ` Ming Lei
2023-04-14 14:56 ` Pavel Begunkov
2023-04-16 9:51 ` Ming Lei
9 siblings, 0 replies; 11+ messages in thread
From: Ming Lei @ 2023-04-14 13:59 UTC (permalink / raw)
To: dccp
On Fri, Apr 14, 2023 at 02:12:10PM +0100, Pavel Begunkov wrote:
> On 4/14/23 03:12, Ming Lei wrote:
> > On Thu, Apr 13, 2023 at 09:47:56AM -0700, Breno Leitao wrote:
> > > Hello Ming,
> > >
> > > On Thu, Apr 13, 2023 at 10:56:49AM +0800, Ming Lei wrote:
> > > > On Thu, Apr 06, 2023 at 09:57:05AM -0700, Breno Leitao wrote:
> > > > > Currently uring CMD operation relies on having large SQEs, but future
> > > > > operations might want to use normal SQE.
> > > > >
> > > > > The io_uring_cmd currently only saves the payload (cmd) part of the SQE,
> > > > > but, for commands that use normal SQE size, it might be necessary to
> > > > > access the initial SQE fields outside of the payload/cmd block. So,
> > > > > saves the whole SQE other than just the pdu.
> > > > >
> > > > > This changes slighlty how the io_uring_cmd works, since the cmd
> > > > > structures and callbacks are not opaque to io_uring anymore. I.e, the
> > > > > callbacks can look at the SQE entries, not only, in the cmd structure.
> > > > >
> > > > > The main advantage is that we don't need to create custom structures for
> > > > > simple commands.
> > > > >
> > > > > Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
> > > > > Signed-off-by: Breno Leitao <leitao@debian.org>
> > > > > ---
> > > >
> > > > ...
> > > >
> > > > > diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
> > > > > index 2e4c483075d3..9648134ccae1 100644
> > > > > --- a/io_uring/uring_cmd.c
> > > > > +++ b/io_uring/uring_cmd.c
> > > > > @@ -63,14 +63,15 @@ EXPORT_SYMBOL_GPL(io_uring_cmd_done);
> > > > > int io_uring_cmd_prep_async(struct io_kiocb *req)
> > > > > {
> > > > > struct io_uring_cmd *ioucmd = io_kiocb_to_cmd(req, struct io_uring_cmd);
> > > > > - size_t cmd_size;
> > > > > + size_t size = sizeof(struct io_uring_sqe);
> > > > > BUILD_BUG_ON(uring_cmd_pdu_size(0) != 16);
> > > > > BUILD_BUG_ON(uring_cmd_pdu_size(1) != 80);
> > > > > - cmd_size = uring_cmd_pdu_size(req->ctx->flags & IORING_SETUP_SQE128);
> > > > > + if (req->ctx->flags & IORING_SETUP_SQE128)
> > > > > + size <<= 1;
> > > > > - memcpy(req->async_data, ioucmd->cmd, cmd_size);
> > > > > + memcpy(req->async_data, ioucmd->sqe, size);
> > > >
> > > > The copy will make some fields of sqe become READ TWICE, and driver may see
> > > > different sqe field value compared with the one observed in io_init_req().
> > >
> > > This copy only happens if the operation goes to the async path
> > > (calling io_uring_cmd_prep_async()). This only happens if
> > > f_op->uring_cmd() returns -EAGAIN.
> > >
> > > ret = file->f_op->uring_cmd(ioucmd, issue_flags);
> > > if (ret = -EAGAIN) {
> > > if (!req_has_async_data(req)) {
> > > if (io_alloc_async_data(req))
> > > return -ENOMEM;
> > > io_uring_cmd_prep_async(req);
> > > }
> > > return -EAGAIN;
> > > }
> > >
> > > Are you saying that after this copy, the operation is still reading from
> > > sqe instead of req->async_data?
> >
> > I meant that the 2nd read is on the sqe copy(req->aync_data), but same
> > fields can become different between the two READs(first is done on original
> > SQE during io_init_req(), and second is done on sqe copy in driver).
> >
> > Will this kind of inconsistency cause trouble for driver? Cause READ
> > TWICE becomes possible with this patch.
>
> Right it might happen, and I was keeping that in mind, but it's not
> specific to this patch. It won't reload core io_uring bits, and all
It depends if driver reloads core bits or not, anyway the patch exports
all fields and opens the window.
> fields cmds use already have this problem.
driver is supposed to load cmds field just once too, right?
>
> Unless there is a better option, the direction we'll be moving in is
> adding a preparation step that should read and stash parts of SQE
> it cares about, which should also make full SQE copy not
> needed / optional.
Sounds good.
Thanks,
Ming
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (7 preceding siblings ...)
2023-04-14 13:59 ` Ming Lei
@ 2023-04-14 14:56 ` Pavel Begunkov
2023-04-16 9:51 ` Ming Lei
9 siblings, 0 replies; 11+ messages in thread
From: Pavel Begunkov @ 2023-04-14 14:56 UTC (permalink / raw)
To: dccp
On 4/14/23 14:59, Ming Lei wrote:
[...]
>>> Will this kind of inconsistency cause trouble for driver? Cause READ
>>> TWICE becomes possible with this patch.
>>
>> Right it might happen, and I was keeping that in mind, but it's not
>> specific to this patch. It won't reload core io_uring bits, and all
>
> It depends if driver reloads core bits or not, anyway the patch exports
> all fields and opens the window.
If a driver tries to reload core bits and even worse modify io_uring
request without proper helpers, it should be rooted out and thrown
into a bin. In any case cmds are expected to exercise cautiousness
while working with SQEs as they may change. I'd even argue that
hiding it as void *cmd makes it much less obvious.
>> fields cmds use already have this problem.
>
> driver is supposed to load cmds field just once too, right?
Ideally they shouldn't, but it's fine to reload as long as
the cmd can handle it. And it should always be READ_ONCE()
and so.
>> Unless there is a better option, the direction we'll be moving in is
>> adding a preparation step that should read and stash parts of SQE
>> it cares about, which should also make full SQE copy not
>> needed / optional.
>
> Sounds good.
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH RFC] io_uring: Pass whole sqe to commands
2023-04-06 16:57 [PATCH RFC] io_uring: Pass whole sqe to commands Breno Leitao
` (8 preceding siblings ...)
2023-04-14 14:56 ` Pavel Begunkov
@ 2023-04-16 9:51 ` Ming Lei
9 siblings, 0 replies; 11+ messages in thread
From: Ming Lei @ 2023-04-16 9:51 UTC (permalink / raw)
To: dccp
On Fri, Apr 14, 2023 at 03:56:47PM +0100, Pavel Begunkov wrote:
> On 4/14/23 14:59, Ming Lei wrote:
> [...]
> > > > Will this kind of inconsistency cause trouble for driver? Cause READ
> > > > TWICE becomes possible with this patch.
> > >
> > > Right it might happen, and I was keeping that in mind, but it's not
> > > specific to this patch. It won't reload core io_uring bits, and all
> >
> > It depends if driver reloads core bits or not, anyway the patch exports
> > all fields and opens the window.
>
> If a driver tries to reload core bits and even worse modify io_uring
> request without proper helpers, it should be rooted out and thrown
> into a bin. In any case cmds are expected to exercise cautiousness
> while working with SQEs as they may change. I'd even argue that
> hiding it as void *cmd makes it much less obvious.
Fair enough, if it is well documented, then people will know these
problems and any change in this area can get careful review.
Thanks,
Ming
^ permalink raw reply [flat|nested] 11+ messages in thread