* [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
@ 2020-12-20 6:50 noah
2020-12-20 15:18 ` Pavel Begunkov
0 siblings, 1 reply; 8+ messages in thread
From: noah @ 2020-12-20 6:50 UTC (permalink / raw)
Cc: goldstein.w.n, noah, Jens Axboe, Alexander Viro, io-uring,
linux-fsdevel, linux-kernel
From: noah <[email protected]>
This patch makes it so that specify a file descriptor value of -2 will
skip updating the corresponding fixed file index.
This will allow for users to reduce the number of syscalls necessary
to update a sparse file range when using the fixed file option.
Signed-off-by: noah <[email protected]>
---
fs/io_uring.c | 72 ++++++++++++++++++++++++++-------------------------
1 file changed, 37 insertions(+), 35 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 6f9392c35eef..43ab2b7a87d4 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7876,42 +7876,44 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
err = -EFAULT;
break;
}
- i = array_index_nospec(up->offset, ctx->nr_user_files);
- table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
- index = i & IORING_FILE_TABLE_MASK;
- if (table->files[index]) {
- file = table->files[index];
- err = io_queue_file_removal(data, file);
- if (err)
- break;
- table->files[index] = NULL;
- needs_switch = true;
- }
- if (fd != -1) {
- file = fget(fd);
- if (!file) {
- err = -EBADF;
- break;
- }
- /*
- * Don't allow io_uring instances to be registered. If
- * UNIX isn't enabled, then this causes a reference
- * cycle and this instance can never get freed. If UNIX
- * is enabled we'll handle it just fine, but there's
- * still no point in allowing a ring fd as it doesn't
- * support regular read/write anyway.
- */
- if (file->f_op == &io_uring_fops) {
- fput(file);
- err = -EBADF;
- break;
- }
- table->files[index] = file;
- err = io_sqe_file_register(ctx, file, i);
- if (err) {
+ if (fd != -2) {
+ i = array_index_nospec(up->offset, ctx->nr_user_files);
+ table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
+ index = i & IORING_FILE_TABLE_MASK;
+ if (table->files[index]) {
+ file = table->files[index];
+ err = io_queue_file_removal(data, file);
+ if (err)
+ break;
table->files[index] = NULL;
- fput(file);
- break;
+ needs_switch = true;
+ }
+ if (fd != -1) {
+ file = fget(fd);
+ if (!file) {
+ err = -EBADF;
+ break;
+ }
+ /*
+ * Don't allow io_uring instances to be registered. If
+ * UNIX isn't enabled, then this causes a reference
+ * cycle and this instance can never get freed. If UNIX
+ * is enabled we'll handle it just fine, but there's
+ * still no point in allowing a ring fd as it doesn't
+ * support regular read/write anyway.
+ */
+ if (file->f_op == &io_uring_fops) {
+ fput(file);
+ err = -EBADF;
+ break;
+ }
+ table->files[index] = file;
+ err = io_sqe_file_register(ctx, file, i);
+ if (err) {
+ table->files[index] = NULL;
+ fput(file);
+ break;
+ }
}
}
nr_args--;
--
2.29.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2020-12-20 6:50 [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update noah
@ 2020-12-20 15:18 ` Pavel Begunkov
2020-12-22 2:10 ` Noah Goldstein
0 siblings, 1 reply; 8+ messages in thread
From: Pavel Begunkov @ 2020-12-20 15:18 UTC (permalink / raw)
To: noah
Cc: noah, Jens Axboe, Alexander Viro, io-uring, linux-fsdevel,
linux-kernel
On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
>
> This patch makes it so that specify a file descriptor value of -2 will
> skip updating the corresponding fixed file index.
>
> This will allow for users to reduce the number of syscalls necessary
> to update a sparse file range when using the fixed file option.
Answering the github thread -- it's indeed a simple change, I had it the
same day you posted the issue. See below it's a bit cleaner. However, I
want to first review "io_uring: buffer registration enhancements", and
if it's good, for easier merging/etc I'd rather prefer to let it go
first (even if partially).
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 941fe9b64fd9..b3ae9d5da17e 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -7847,9 +7847,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
if (IS_ERR(ref_node))
return PTR_ERR(ref_node);
- done = 0;
fds = u64_to_user_ptr(up->fds);
- while (nr_args) {
+ for (done = 0; done < nr_args; done++) {
struct fixed_file_table *table;
unsigned index;
@@ -7858,7 +7857,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
err = -EFAULT;
break;
}
- i = array_index_nospec(up->offset, ctx->nr_user_files);
+ if (fd == IORING_REGISTER_FILES_SKIP)
+ continue;
+
+ i = array_index_nospec(up->offset + done, ctx->nr_user_files);
table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
index = i & IORING_FILE_TABLE_MASK;
if (table->files[index]) {
@@ -7896,9 +7898,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
break;
}
}
- nr_args--;
- done++;
- up->offset++;
}
if (needs_switch) {
--
Pavel Begunkov
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2020-12-20 15:18 ` Pavel Begunkov
@ 2020-12-22 2:10 ` Noah Goldstein
2021-01-26 12:26 ` Pavel Begunkov
0 siblings, 1 reply; 8+ messages in thread
From: Noah Goldstein @ 2020-12-22 2:10 UTC (permalink / raw)
To: Pavel Begunkov
Cc: noah, Jens Axboe, Alexander Viro, io-uring, linux-fsdevel,
linux-kernel
On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
> >
> > This patch makes it so that specify a file descriptor value of -2 will
> > skip updating the corresponding fixed file index.
> >
> > This will allow for users to reduce the number of syscalls necessary
> > to update a sparse file range when using the fixed file option.
>
> Answering the github thread -- it's indeed a simple change, I had it the
> same day you posted the issue. See below it's a bit cleaner. However, I
> want to first review "io_uring: buffer registration enhancements", and
> if it's good, for easier merging/etc I'd rather prefer to let it go
> first (even if partially).
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 941fe9b64fd9..b3ae9d5da17e 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -7847,9 +7847,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> if (IS_ERR(ref_node))
> return PTR_ERR(ref_node);
>
> - done = 0;
> fds = u64_to_user_ptr(up->fds);
> - while (nr_args) {
> + for (done = 0; done < nr_args; done++) {
> struct fixed_file_table *table;
> unsigned index;
>
> @@ -7858,7 +7857,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> err = -EFAULT;
> break;
> }
> - i = array_index_nospec(up->offset, ctx->nr_user_files);
> + if (fd == IORING_REGISTER_FILES_SKIP)
> + continue;
> +
> + i = array_index_nospec(up->offset + done, ctx->nr_user_files);
> table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
> index = i & IORING_FILE_TABLE_MASK;
> if (table->files[index]) {
> @@ -7896,9 +7898,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> break;
> }
> }
> - nr_args--;
> - done++;
> - up->offset++;
> }
>
> if (needs_switch) {
>
> --
> Pavel Begunkov
Ah. Got it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2020-12-22 2:10 ` Noah Goldstein
@ 2021-01-26 12:26 ` Pavel Begunkov
2021-01-26 17:14 ` Noah Goldstein
0 siblings, 1 reply; 8+ messages in thread
From: Pavel Begunkov @ 2021-01-26 12:26 UTC (permalink / raw)
To: Noah Goldstein
Cc: noah, Jens Axboe, Alexander Viro, io-uring, linux-fsdevel,
linux-kernel
On 22/12/2020 02:10, Noah Goldstein wrote:
> On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
>> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
>>>
>>> This patch makes it so that specify a file descriptor value of -2 will
>>> skip updating the corresponding fixed file index.
>>>
>>> This will allow for users to reduce the number of syscalls necessary
>>> to update a sparse file range when using the fixed file option.
>>
>> Answering the github thread -- it's indeed a simple change, I had it the
>> same day you posted the issue. See below it's a bit cleaner. However, I
>> want to first review "io_uring: buffer registration enhancements", and
>> if it's good, for easier merging/etc I'd rather prefer to let it go
>> first (even if partially).
Noah, want to give it a try? I've just sent a prep patch, with it you
can implement it cleaner with one continue.
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index 941fe9b64fd9..b3ae9d5da17e 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -7847,9 +7847,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>> if (IS_ERR(ref_node))
>> return PTR_ERR(ref_node);
>>
>> - done = 0;
>> fds = u64_to_user_ptr(up->fds);
>> - while (nr_args) {
>> + for (done = 0; done < nr_args; done++) {
>> struct fixed_file_table *table;
>> unsigned index;
>>
>> @@ -7858,7 +7857,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>> err = -EFAULT;
>> break;
>> }
>> - i = array_index_nospec(up->offset, ctx->nr_user_files);
>> + if (fd == IORING_REGISTER_FILES_SKIP)
>> + continue;
>> +
>> + i = array_index_nospec(up->offset + done, ctx->nr_user_files);
>> table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
>> index = i & IORING_FILE_TABLE_MASK;
>> if (table->files[index]) {
>> @@ -7896,9 +7898,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
>> break;
>> }
>> }
>> - nr_args--;
>> - done++;
>> - up->offset++;
>> }
>>
>> if (needs_switch) {
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2021-01-26 12:26 ` Pavel Begunkov
@ 2021-01-26 17:14 ` Noah Goldstein
2021-01-26 17:20 ` Pavel Begunkov
0 siblings, 1 reply; 8+ messages in thread
From: Noah Goldstein @ 2021-01-26 17:14 UTC (permalink / raw)
To: Pavel Begunkov
Cc: noah, Jens Axboe, Alexander Viro, open list:IO_URING,
open list:FILESYSTEMS (VFS and infrastructure), open list
On Tue, Jan 26, 2021 at 7:29 AM Pavel Begunkov <[email protected]> wrote:
>
> On 22/12/2020 02:10, Noah Goldstein wrote:
> > On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
> >> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
> >>>
> >>> This patch makes it so that specify a file descriptor value of -2 will
> >>> skip updating the corresponding fixed file index.
> >>>
> >>> This will allow for users to reduce the number of syscalls necessary
> >>> to update a sparse file range when using the fixed file option.
> >>
> >> Answering the github thread -- it's indeed a simple change, I had it the
> >> same day you posted the issue. See below it's a bit cleaner. However, I
> >> want to first review "io_uring: buffer registration enhancements", and
> >> if it's good, for easier merging/etc I'd rather prefer to let it go
> >> first (even if partially).
>
> Noah, want to give it a try? I've just sent a prep patch, with it you
> can implement it cleaner with one continue.
>
Absolutely. Will get on it ASAP.
> >>
> >> diff --git a/fs/io_uring.c b/fs/io_uring.c
> >> index 941fe9b64fd9..b3ae9d5da17e 100644
> >> --- a/fs/io_uring.c
> >> +++ b/fs/io_uring.c
> >> @@ -7847,9 +7847,8 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> >> if (IS_ERR(ref_node))
> >> return PTR_ERR(ref_node);
> >>
> >> - done = 0;
> >> fds = u64_to_user_ptr(up->fds);
> >> - while (nr_args) {
> >> + for (done = 0; done < nr_args; done++) {
> >> struct fixed_file_table *table;
> >> unsigned index;
> >>
> >> @@ -7858,7 +7857,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> >> err = -EFAULT;
> >> break;
> >> }
> >> - i = array_index_nospec(up->offset, ctx->nr_user_files);
> >> + if (fd == IORING_REGISTER_FILES_SKIP)
> >> + continue;
> >> +
> >> + i = array_index_nospec(up->offset + done, ctx->nr_user_files);
> >> table = &ctx->file_data->table[i >> IORING_FILE_TABLE_SHIFT];
> >> index = i & IORING_FILE_TABLE_MASK;
> >> if (table->files[index]) {
> >> @@ -7896,9 +7898,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
> >> break;
> >> }
> >> }
> >> - nr_args--;
> >> - done++;
> >> - up->offset++;
> >> }
> >>
> >> if (needs_switch) {
>
> --
> Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2021-01-26 17:14 ` Noah Goldstein
@ 2021-01-26 17:20 ` Pavel Begunkov
2021-01-26 18:43 ` Noah Goldstein
0 siblings, 1 reply; 8+ messages in thread
From: Pavel Begunkov @ 2021-01-26 17:20 UTC (permalink / raw)
To: Noah Goldstein
Cc: noah, Jens Axboe, Alexander Viro, open list:IO_URING,
open list:FILESYSTEMS (VFS and infrastructure), open list
On 26/01/2021 17:14, Noah Goldstein wrote:
> On Tue, Jan 26, 2021 at 7:29 AM Pavel Begunkov <[email protected]> wrote:
>>
>> On 22/12/2020 02:10, Noah Goldstein wrote:
>>> On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
>>>> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
>>>>>
>>>>> This patch makes it so that specify a file descriptor value of -2 will
>>>>> skip updating the corresponding fixed file index.
>>>>>
>>>>> This will allow for users to reduce the number of syscalls necessary
>>>>> to update a sparse file range when using the fixed file option.
>>>>
>>>> Answering the github thread -- it's indeed a simple change, I had it the
>>>> same day you posted the issue. See below it's a bit cleaner. However, I
>>>> want to first review "io_uring: buffer registration enhancements", and
>>>> if it's good, for easier merging/etc I'd rather prefer to let it go
>>>> first (even if partially).
>>
>> Noah, want to give it a try? I've just sent a prep patch, with it you
>> can implement it cleaner with one continue.
>
> Absolutely. Will get on it ASAP.
Perfect. Even better if you add a liburing test
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2021-01-26 17:20 ` Pavel Begunkov
@ 2021-01-26 18:43 ` Noah Goldstein
2021-01-26 19:39 ` Pavel Begunkov
0 siblings, 1 reply; 8+ messages in thread
From: Noah Goldstein @ 2021-01-26 18:43 UTC (permalink / raw)
To: Pavel Begunkov
Cc: noah, Jens Axboe, Alexander Viro, open list:IO_URING,
open list:FILESYSTEMS (VFS and infrastructure), open list
On Tue, Jan 26, 2021 at 12:24 PM Pavel Begunkov <[email protected]> wrote:
>
> On 26/01/2021 17:14, Noah Goldstein wrote:
> > On Tue, Jan 26, 2021 at 7:29 AM Pavel Begunkov <[email protected]> wrote:
> >>
> >> On 22/12/2020 02:10, Noah Goldstein wrote:
> >>> On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
> >>>> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
> >>>>>
> >>>>> This patch makes it so that specify a file descriptor value of -2 will
> >>>>> skip updating the corresponding fixed file index.
> >>>>>
> >>>>> This will allow for users to reduce the number of syscalls necessary
> >>>>> to update a sparse file range when using the fixed file option.
> >>>>
> >>>> Answering the github thread -- it's indeed a simple change, I had it the
> >>>> same day you posted the issue. See below it's a bit cleaner. However, I
> >>>> want to first review "io_uring: buffer registration enhancements", and
> >>>> if it's good, for easier merging/etc I'd rather prefer to let it go
> >>>> first (even if partially).
> >>
> >> Noah, want to give it a try? I've just sent a prep patch, with it you
> >> can implement it cleaner with one continue.
> >
> > Absolutely. Will get on it ASAP.
>
> Perfect. Even better if you add a liburing test
>
> --
> Pavel Begunkov
Do you think the return value should not include files skipped?
i.e register fds[1, 2, 3, -1] with no errors returns 4. should fds[1,
2, -2, -1] return 3 or 4 do you think?
Personally think the latter makes more sense. Thoughts?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update
2021-01-26 18:43 ` Noah Goldstein
@ 2021-01-26 19:39 ` Pavel Begunkov
0 siblings, 0 replies; 8+ messages in thread
From: Pavel Begunkov @ 2021-01-26 19:39 UTC (permalink / raw)
To: Noah Goldstein
Cc: noah, Jens Axboe, Alexander Viro, open list:IO_URING,
open list:FILESYSTEMS (VFS and infrastructure), open list
On 26/01/2021 18:43, Noah Goldstein wrote:
> On Tue, Jan 26, 2021 at 12:24 PM Pavel Begunkov <[email protected]> wrote:
>>
>> On 26/01/2021 17:14, Noah Goldstein wrote:
>>> On Tue, Jan 26, 2021 at 7:29 AM Pavel Begunkov <[email protected]> wrote:
>>>>
>>>> On 22/12/2020 02:10, Noah Goldstein wrote:
>>>>> On Sun, Dec 20, 2020 at 03:18:05PM +0000, Pavel Begunkov wrote:
>>>>>> On 20/12/2020 06:50, noah wrote:> From: noah <[email protected]>
>>>>>>>
>>>>>>> This patch makes it so that specify a file descriptor value of -2 will
>>>>>>> skip updating the corresponding fixed file index.
>>>>>>>
>>>>>>> This will allow for users to reduce the number of syscalls necessary
>>>>>>> to update a sparse file range when using the fixed file option.
>>>>>>
>>>>>> Answering the github thread -- it's indeed a simple change, I had it the
>>>>>> same day you posted the issue. See below it's a bit cleaner. However, I
>>>>>> want to first review "io_uring: buffer registration enhancements", and
>>>>>> if it's good, for easier merging/etc I'd rather prefer to let it go
>>>>>> first (even if partially).
>>>>
>>>> Noah, want to give it a try? I've just sent a prep patch, with it you
>>>> can implement it cleaner with one continue.
>>>
>>> Absolutely. Will get on it ASAP.
>>
>> Perfect. Even better if you add a liburing test
>
> Do you think the return value should not include files skipped?
>
> i.e register fds[1, 2, 3, -1] with no errors returns 4. should fds[1,
> 2, -2, -1] return 3 or 4 do you think?
>
> Personally think the latter makes more sense. Thoughts?
Let's just return @done, 4 in your case. Because otherwise locating which
index has failed would be hell. And it's consistent with delete (i.e. -1).
--
Pavel Begunkov
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-01-27 10:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-20 6:50 [PATCH] fs: io_uring.c: Add skip option for __io_sqe_files_update noah
2020-12-20 15:18 ` Pavel Begunkov
2020-12-22 2:10 ` Noah Goldstein
2021-01-26 12:26 ` Pavel Begunkov
2021-01-26 17:14 ` Noah Goldstein
2021-01-26 17:20 ` Pavel Begunkov
2021-01-26 18:43 ` Noah Goldstein
2021-01-26 19:39 ` Pavel Begunkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox