Skip to content

Commit 992da01

Browse files
isilenceaxboe
authored andcommitted
io_uring: change registration/upd/rsrc tagging ABI
There are ABI moments about recently added rsrc registration/update and tagging that might become a nuisance in the future. First, IORING_REGISTER_RSRC[_UPD] hide different types of resources under it, so breaks fine control over them by restrictions. It works for now, but once those are wanted under restrictions it would require a rework. It was also inconvenient trying to fit a new resource not supporting all the features (e.g. dynamic update) into the interface, so better to return to IORING_REGISTER_* top level dispatching. Second, register/update were considered to accept a type of resource, however that's not a good idea because there might be several ways of registration of a single resource type, e.g. we may want to add non-contig buffers or anything more exquisite as dma mapped memory. So, remove IORING_RSRC_[FILE,BUFFER] out of the ABI, and place them internally for now to limit changes. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/9b554897a7c17ad6e3becc48dfed2f7af9f423d5.1623339162.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 216e583 commit 992da01

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

fs/io_uring.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ struct io_task_work {
783783
task_work_func_t func;
784784
};
785785

786+
enum {
787+
IORING_RSRC_FILE = 0,
788+
IORING_RSRC_BUFFER = 1,
789+
};
790+
786791
/*
787792
* NOTE! Each of the iocb union members has the file pointer
788793
* as the first entry in their struct definition. So you can
@@ -9911,21 +9916,21 @@ static int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
99119916
}
99129917

99139918
static int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
9914-
unsigned size)
9919+
unsigned size, unsigned type)
99159920
{
99169921
struct io_uring_rsrc_update2 up;
99179922

99189923
if (size != sizeof(up))
99199924
return -EINVAL;
99209925
if (copy_from_user(&up, arg, sizeof(up)))
99219926
return -EFAULT;
9922-
if (!up.nr)
9927+
if (!up.nr || up.resv)
99239928
return -EINVAL;
9924-
return __io_register_rsrc_update(ctx, up.type, &up, up.nr);
9929+
return __io_register_rsrc_update(ctx, type, &up, up.nr);
99259930
}
99269931

99279932
static int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
9928-
unsigned int size)
9933+
unsigned int size, unsigned int type)
99299934
{
99309935
struct io_uring_rsrc_register rr;
99319936

@@ -9936,10 +9941,10 @@ static int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
99369941
memset(&rr, 0, sizeof(rr));
99379942
if (copy_from_user(&rr, arg, size))
99389943
return -EFAULT;
9939-
if (!rr.nr)
9944+
if (!rr.nr || rr.resv || rr.resv2)
99409945
return -EINVAL;
99419946

9942-
switch (rr.type) {
9947+
switch (type) {
99439948
case IORING_RSRC_FILE:
99449949
return io_sqe_files_register(ctx, u64_to_user_ptr(rr.data),
99459950
rr.nr, u64_to_user_ptr(rr.tags));
@@ -9961,8 +9966,10 @@ static bool io_register_op_must_quiesce(int op)
99619966
case IORING_REGISTER_PROBE:
99629967
case IORING_REGISTER_PERSONALITY:
99639968
case IORING_UNREGISTER_PERSONALITY:
9964-
case IORING_REGISTER_RSRC:
9965-
case IORING_REGISTER_RSRC_UPDATE:
9969+
case IORING_REGISTER_FILES2:
9970+
case IORING_REGISTER_FILES_UPDATE2:
9971+
case IORING_REGISTER_BUFFERS2:
9972+
case IORING_REGISTER_BUFFERS_UPDATE:
99669973
return false;
99679974
default:
99689975
return true;
@@ -10088,11 +10095,19 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
1008810095
case IORING_REGISTER_RESTRICTIONS:
1008910096
ret = io_register_restrictions(ctx, arg, nr_args);
1009010097
break;
10091-
case IORING_REGISTER_RSRC:
10092-
ret = io_register_rsrc(ctx, arg, nr_args);
10098+
case IORING_REGISTER_FILES2:
10099+
ret = io_register_rsrc(ctx, arg, nr_args, IORING_RSRC_FILE);
10100+
break;
10101+
case IORING_REGISTER_FILES_UPDATE2:
10102+
ret = io_register_rsrc_update(ctx, arg, nr_args,
10103+
IORING_RSRC_FILE);
10104+
break;
10105+
case IORING_REGISTER_BUFFERS2:
10106+
ret = io_register_rsrc(ctx, arg, nr_args, IORING_RSRC_BUFFER);
1009310107
break;
10094-
case IORING_REGISTER_RSRC_UPDATE:
10095-
ret = io_register_rsrc_update(ctx, arg, nr_args);
10108+
case IORING_REGISTER_BUFFERS_UPDATE:
10109+
ret = io_register_rsrc_update(ctx, arg, nr_args,
10110+
IORING_RSRC_BUFFER);
1009610111
break;
1009710112
default:
1009810113
ret = -EINVAL;

include/uapi/linux/io_uring.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,12 @@ enum {
298298
IORING_UNREGISTER_PERSONALITY = 10,
299299
IORING_REGISTER_RESTRICTIONS = 11,
300300
IORING_REGISTER_ENABLE_RINGS = 12,
301-
IORING_REGISTER_RSRC = 13,
302-
IORING_REGISTER_RSRC_UPDATE = 14,
301+
302+
/* extended with tagging */
303+
IORING_REGISTER_FILES2 = 13,
304+
IORING_REGISTER_FILES_UPDATE2 = 14,
305+
IORING_REGISTER_BUFFERS2 = 15,
306+
IORING_REGISTER_BUFFERS_UPDATE = 16,
303307

304308
/* this goes last */
305309
IORING_REGISTER_LAST
@@ -312,14 +316,10 @@ struct io_uring_files_update {
312316
__aligned_u64 /* __s32 * */ fds;
313317
};
314318

315-
enum {
316-
IORING_RSRC_FILE = 0,
317-
IORING_RSRC_BUFFER = 1,
318-
};
319-
320319
struct io_uring_rsrc_register {
321-
__u32 type;
322320
__u32 nr;
321+
__u32 resv;
322+
__u64 resv2;
323323
__aligned_u64 data;
324324
__aligned_u64 tags;
325325
};
@@ -335,8 +335,8 @@ struct io_uring_rsrc_update2 {
335335
__u32 resv;
336336
__aligned_u64 data;
337337
__aligned_u64 tags;
338-
__u32 type;
339338
__u32 nr;
339+
__u32 resv2;
340340
};
341341

342342
/* Skip updating fd indexes set to this value in the fd table */

0 commit comments

Comments
 (0)