Skip to content

Commit 1bc8890

Browse files
committed
Merge branch 'io_uring-6.16' into for-6.17/io_uring
Merge in 6.16 io_uring fixes, to avoid clashes with pending net and settings changes. * io_uring-6.16: io_uring: gate REQ_F_ISREG on !S_ANON_INODE as well io_uring/kbuf: flag partial buffer mappings io_uring/net: mark iov as dynamically allocated even for single segments io_uring: fix resource leak in io_import_dmabuf() io_uring: don't assume uaddr alignment in io_vec_fill_bvec io_uring/rsrc: don't rely on user vaddr alignment io_uring/rsrc: fix folio unpinning io_uring: make fallocate be hashed work
2 parents cf73d99 + 6f11adc commit 1bc8890

8 files changed

Lines changed: 54 additions & 25 deletions

File tree

io_uring/io_uring.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,11 +1706,12 @@ static void io_iopoll_req_issued(struct io_kiocb *req, unsigned int issue_flags)
17061706

17071707
io_req_flags_t io_file_get_flags(struct file *file)
17081708
{
1709+
struct inode *inode = file_inode(file);
17091710
io_req_flags_t res = 0;
17101711

17111712
BUILD_BUG_ON(REQ_F_ISREG_BIT != REQ_F_SUPPORT_NOWAIT_BIT + 1);
17121713

1713-
if (S_ISREG(file_inode(file)->i_mode))
1714+
if (S_ISREG(inode->i_mode) && !(inode->i_flags & S_ANON_INODE))
17141715
res |= REQ_F_ISREG;
17151716
if ((file->f_flags & O_NONBLOCK) || (file->f_mode & FMODE_NOWAIT))
17161717
res |= REQ_F_SUPPORT_NOWAIT;

io_uring/kbuf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
271271
if (len > arg->max_len) {
272272
len = arg->max_len;
273273
if (!(bl->flags & IOBL_INC)) {
274+
arg->partial_map = 1;
274275
if (iov != arg->iovs)
275276
break;
276277
buf->len = len;

io_uring/kbuf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ struct buf_sel_arg {
5858
size_t max_len;
5959
unsigned short nr_iovs;
6060
unsigned short mode;
61-
unsigned buf_group;
61+
unsigned short buf_group;
62+
unsigned short partial_map;
6263
};
6364

6465
void __user *io_buffer_select(struct io_kiocb *req, size_t *len,

io_uring/net.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,17 @@ struct io_sr_msg {
7575
u16 flags;
7676
/* initialised and used only by !msg send variants */
7777
u16 buf_group;
78-
bool retry;
78+
unsigned short retry_flags;
7979
void __user *msg_control;
8080
/* used only for send zerocopy */
8181
struct io_kiocb *notif;
8282
};
8383

84+
enum sr_retry_flags {
85+
IO_SR_MSG_RETRY = 1,
86+
IO_SR_MSG_PARTIAL_MAP = 2,
87+
};
88+
8489
/*
8590
* Number of times we'll try and do receives if there's more data. If we
8691
* exceed this limit, then add us to the back of the queue and retry from
@@ -187,7 +192,7 @@ static inline void io_mshot_prep_retry(struct io_kiocb *req,
187192

188193
req->flags &= ~REQ_F_BL_EMPTY;
189194
sr->done_io = 0;
190-
sr->retry = false;
195+
sr->retry_flags = 0;
191196
sr->len = 0; /* get from the provided buffer */
192197
}
193198

@@ -397,7 +402,7 @@ int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
397402
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
398403

399404
sr->done_io = 0;
400-
sr->retry = false;
405+
sr->retry_flags = 0;
401406
sr->len = READ_ONCE(sqe->len);
402407
sr->flags = READ_ONCE(sqe->ioprio);
403408
if (sr->flags & ~SENDMSG_FLAGS)
@@ -751,7 +756,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
751756
struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);
752757

753758
sr->done_io = 0;
754-
sr->retry = false;
759+
sr->retry_flags = 0;
755760

756761
if (unlikely(sqe->file_index || sqe->addr2))
757762
return -EINVAL;
@@ -823,7 +828,7 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
823828

824829
cflags |= io_put_kbufs(req, this_ret, io_bundle_nbufs(kmsg, this_ret),
825830
issue_flags);
826-
if (sr->retry)
831+
if (sr->retry_flags & IO_SR_MSG_RETRY)
827832
cflags = req->cqe.flags | (cflags & CQE_F_MASK);
828833
/* bundle with no more immediate buffers, we're done */
829834
if (req->flags & REQ_F_BL_EMPTY)
@@ -832,12 +837,12 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret,
832837
* If more is available AND it was a full transfer, retry and
833838
* append to this one
834839
*/
835-
if (!sr->retry && kmsg->msg.msg_inq > 1 && this_ret > 0 &&
840+
if (!sr->retry_flags && kmsg->msg.msg_inq > 1 && this_ret > 0 &&
836841
!iov_iter_count(&kmsg->msg.msg_iter)) {
837842
req->cqe.flags = cflags & ~CQE_F_MASK;
838843
sr->len = kmsg->msg.msg_inq;
839844
sr->done_io += this_ret;
840-
sr->retry = true;
845+
sr->retry_flags |= IO_SR_MSG_RETRY;
841846
return false;
842847
}
843848
} else {
@@ -1077,6 +1082,14 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
10771082
if (unlikely(ret < 0))
10781083
return ret;
10791084

1085+
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
1086+
kmsg->vec.nr = ret;
1087+
kmsg->vec.iovec = arg.iovs;
1088+
req->flags |= REQ_F_NEED_CLEANUP;
1089+
}
1090+
if (arg.partial_map)
1091+
sr->retry_flags |= IO_SR_MSG_PARTIAL_MAP;
1092+
10801093
/* special case 1 vec, can be a fast path */
10811094
if (ret == 1) {
10821095
sr->buf = arg.iovs[0].iov_base;
@@ -1085,11 +1098,6 @@ static int io_recv_buf_select(struct io_kiocb *req, struct io_async_msghdr *kmsg
10851098
}
10861099
iov_iter_init(&kmsg->msg.msg_iter, ITER_DEST, arg.iovs, ret,
10871100
arg.out_len);
1088-
if (arg.iovs != &kmsg->fast_iov && arg.iovs != kmsg->vec.iovec) {
1089-
kmsg->vec.nr = ret;
1090-
kmsg->vec.iovec = arg.iovs;
1091-
req->flags |= REQ_F_NEED_CLEANUP;
1092-
}
10931101
} else {
10941102
void __user *buf;
10951103

@@ -1275,7 +1283,7 @@ int io_send_zc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
12751283
int ret;
12761284

12771285
zc->done_io = 0;
1278-
zc->retry = false;
1286+
zc->retry_flags = 0;
12791287

12801288
if (unlikely(READ_ONCE(sqe->__pad2[0]) || READ_ONCE(sqe->addr3)))
12811289
return -EINVAL;

io_uring/opdef.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ const struct io_issue_def io_issue_defs[] = {
216216
},
217217
[IORING_OP_FALLOCATE] = {
218218
.needs_file = 1,
219+
.hash_reg_file = 1,
219220
.prep = io_fallocate_prep,
220221
.issue = io_fallocate,
221222
},

io_uring/rsrc.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ static void io_release_ubuf(void *priv)
112112
struct io_mapped_ubuf *imu = priv;
113113
unsigned int i;
114114

115-
for (i = 0; i < imu->nr_bvecs; i++)
116-
unpin_user_page(imu->bvec[i].bv_page);
115+
for (i = 0; i < imu->nr_bvecs; i++) {
116+
struct folio *folio = page_folio(imu->bvec[i].bv_page);
117+
118+
unpin_user_folio(folio, 1);
119+
}
117120
}
118121

119122
static struct io_mapped_ubuf *io_alloc_imu(struct io_ring_ctx *ctx,
@@ -733,6 +736,7 @@ bool io_check_coalesce_buffer(struct page **page_array, int nr_pages,
733736

734737
data->nr_pages_mid = folio_nr_pages(folio);
735738
data->folio_shift = folio_shift(folio);
739+
data->first_folio_page_idx = folio_page_idx(folio, page_array[0]);
736740

737741
/*
738742
* Check if pages are contiguous inside a folio, and all folios have
@@ -826,7 +830,11 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
826830
if (coalesced)
827831
imu->folio_shift = data.folio_shift;
828832
refcount_set(&imu->refs, 1);
829-
off = (unsigned long) iov->iov_base & ((1UL << imu->folio_shift) - 1);
833+
834+
off = (unsigned long)iov->iov_base & ~PAGE_MASK;
835+
if (coalesced)
836+
off += data.first_folio_page_idx << PAGE_SHIFT;
837+
830838
node->buf = imu;
831839
ret = 0;
832840

@@ -842,8 +850,10 @@ static struct io_rsrc_node *io_sqe_buffer_register(struct io_ring_ctx *ctx,
842850
if (ret) {
843851
if (imu)
844852
io_free_imu(ctx, imu);
845-
if (pages)
846-
unpin_user_pages(pages, nr_pages);
853+
if (pages) {
854+
for (i = 0; i < nr_pages; i++)
855+
unpin_user_folio(page_folio(pages[i]), 1);
856+
}
847857
io_cache_free(&ctx->node_cache, node);
848858
node = ERR_PTR(ret);
849859
}
@@ -1331,7 +1341,6 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13311341
{
13321342
unsigned long folio_size = 1 << imu->folio_shift;
13331343
unsigned long folio_mask = folio_size - 1;
1334-
u64 folio_addr = imu->ubuf & ~folio_mask;
13351344
struct bio_vec *res_bvec = vec->bvec;
13361345
size_t total_len = 0;
13371346
unsigned bvec_idx = 0;
@@ -1353,8 +1362,13 @@ static int io_vec_fill_bvec(int ddir, struct iov_iter *iter,
13531362
if (unlikely(check_add_overflow(total_len, iov_len, &total_len)))
13541363
return -EOVERFLOW;
13551364

1356-
/* by using folio address it also accounts for bvec offset */
1357-
offset = buf_addr - folio_addr;
1365+
offset = buf_addr - imu->ubuf;
1366+
/*
1367+
* Only the first bvec can have non zero bv_offset, account it
1368+
* here and work with full folios below.
1369+
*/
1370+
offset += imu->bvec[0].bv_offset;
1371+
13581372
src_bvec = imu->bvec + (offset >> imu->folio_shift);
13591373
offset &= folio_mask;
13601374

io_uring/rsrc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct io_imu_folio_data {
4949
unsigned int nr_pages_mid;
5050
unsigned int folio_shift;
5151
unsigned int nr_folios;
52+
unsigned long first_folio_page_idx;
5253
};
5354

5455
bool io_rsrc_cache_init(struct io_ring_ctx *ctx);

io_uring/zcrx.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ static int io_import_dmabuf(struct io_zcrx_ifq *ifq,
106106
for_each_sgtable_dma_sg(mem->sgt, sg, i)
107107
total_size += sg_dma_len(sg);
108108

109-
if (total_size < off + len)
110-
return -EINVAL;
109+
if (total_size < off + len) {
110+
ret = -EINVAL;
111+
goto err;
112+
}
111113

112114
mem->dmabuf_offset = off;
113115
mem->size = len;

0 commit comments

Comments
 (0)