Skip to content

Commit 3b87184

Browse files
committed
io_uring/advise: support 64-bit lengths
The existing fadvise/madvise support only supports 32-bit lengths. Add support for 64-bit lengths, enabled by the application setting sqe->off rather than sqe->len for the length. If sqe->len is set, then that is used as the 32-bit length. If sqe->len is zero, then sqe->off is read for full 64-bit support. Older kernels will return -EINVAL if 64-bit support isn't available. Fixes: 4840e41 ("io_uring: add IORING_OP_FADVISE") Fixes: c1ca757 ("io_uring: add IORING_OP_MADVISE") Reported-by: Stefan <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 11d1946 commit 3b87184

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

io_uring/advise.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
struct io_fadvise {
1818
struct file *file;
1919
u64 offset;
20-
u32 len;
20+
u64 len;
2121
u32 advice;
2222
};
2323

2424
struct io_madvise {
2525
struct file *file;
2626
u64 addr;
27-
u32 len;
27+
u64 len;
2828
u32 advice;
2929
};
3030

@@ -33,11 +33,13 @@ int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3333
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
3434
struct io_madvise *ma = io_kiocb_to_cmd(req, struct io_madvise);
3535

36-
if (sqe->buf_index || sqe->off || sqe->splice_fd_in)
36+
if (sqe->buf_index || sqe->splice_fd_in)
3737
return -EINVAL;
3838

3939
ma->addr = READ_ONCE(sqe->addr);
40-
ma->len = READ_ONCE(sqe->len);
40+
ma->len = READ_ONCE(sqe->off);
41+
if (!ma->len)
42+
ma->len = READ_ONCE(sqe->len);
4143
ma->advice = READ_ONCE(sqe->fadvise_advice);
4244
req->flags |= REQ_F_FORCE_ASYNC;
4345
return 0;
@@ -78,11 +80,13 @@ int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
7880
{
7981
struct io_fadvise *fa = io_kiocb_to_cmd(req, struct io_fadvise);
8082

81-
if (sqe->buf_index || sqe->addr || sqe->splice_fd_in)
83+
if (sqe->buf_index || sqe->splice_fd_in)
8284
return -EINVAL;
8385

8486
fa->offset = READ_ONCE(sqe->off);
85-
fa->len = READ_ONCE(sqe->len);
87+
fa->len = READ_ONCE(sqe->addr);
88+
if (!fa->len)
89+
fa->len = READ_ONCE(sqe->len);
8690
fa->advice = READ_ONCE(sqe->fadvise_advice);
8791
if (io_fadvise_force_async(fa))
8892
req->flags |= REQ_F_FORCE_ASYNC;

0 commit comments

Comments
 (0)