Skip to content

Commit a61ec0d

Browse files
committed
Merge tag 'io_uring-6.15-20250410' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Reject zero sized legacy provided buffers upfront. No ill side effects from this one, only really done to shut up a silly syzbot test case. - Fix for a regression in tag posting for registered files or buffers, where the tag would be posted even when the registration failed. - two minor zcrx cleanups for code added this merge window. * tag 'io_uring-6.15-20250410' of git://git.kernel.dk/linux: io_uring/kbuf: reject zero sized provided buffers io_uring/zcrx: separate niov number from pages io_uring/zcrx: put refill data into separate cache line io_uring: don't post tag CQEs on file/buffer registration failure
2 parents 8f43640 + cf96072 commit a61ec0d

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

io_uring/kbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ int io_provide_buffers_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
504504
p->nbufs = tmp;
505505
p->addr = READ_ONCE(sqe->addr);
506506
p->len = READ_ONCE(sqe->len);
507+
if (!p->len)
508+
return -EINVAL;
507509

508510
if (check_mul_overflow((unsigned long)p->len, (unsigned long)p->nbufs,
509511
&size))

io_uring/rsrc.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ void io_rsrc_cache_free(struct io_ring_ctx *ctx)
175175
io_alloc_cache_free(&ctx->imu_cache, kfree);
176176
}
177177

178+
static void io_clear_table_tags(struct io_rsrc_data *data)
179+
{
180+
int i;
181+
182+
for (i = 0; i < data->nr; i++) {
183+
struct io_rsrc_node *node = data->nodes[i];
184+
185+
if (node)
186+
node->tag = 0;
187+
}
188+
}
189+
178190
__cold void io_rsrc_data_free(struct io_ring_ctx *ctx,
179191
struct io_rsrc_data *data)
180192
{
@@ -583,6 +595,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
583595
io_file_table_set_alloc_range(ctx, 0, ctx->file_table.data.nr);
584596
return 0;
585597
fail:
598+
io_clear_table_tags(&ctx->file_table.data);
586599
io_sqe_files_unregister(ctx);
587600
return ret;
588601
}
@@ -902,8 +915,10 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
902915
}
903916

904917
ctx->buf_table = data;
905-
if (ret)
918+
if (ret) {
919+
io_clear_table_tags(&ctx->buf_table);
906920
io_sqe_buffers_unregister(ctx);
921+
}
907922
return ret;
908923
}
909924

io_uring/zcrx.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
181181
kvfree(area->nia.niovs);
182182
kvfree(area->user_refs);
183183
if (area->pages) {
184-
unpin_user_pages(area->pages, area->nia.num_niovs);
184+
unpin_user_pages(area->pages, area->nr_folios);
185185
kvfree(area->pages);
186186
}
187187
kfree(area);
@@ -192,7 +192,7 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
192192
struct io_uring_zcrx_area_reg *area_reg)
193193
{
194194
struct io_zcrx_area *area;
195-
int i, ret, nr_pages;
195+
int i, ret, nr_pages, nr_iovs;
196196
struct iovec iov;
197197

198198
if (area_reg->flags || area_reg->rq_area_token)
@@ -220,35 +220,36 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
220220
area->pages = NULL;
221221
goto err;
222222
}
223-
area->nia.num_niovs = nr_pages;
223+
area->nr_folios = nr_iovs = nr_pages;
224+
area->nia.num_niovs = nr_iovs;
224225

225-
area->nia.niovs = kvmalloc_array(nr_pages, sizeof(area->nia.niovs[0]),
226+
area->nia.niovs = kvmalloc_array(nr_iovs, sizeof(area->nia.niovs[0]),
226227
GFP_KERNEL | __GFP_ZERO);
227228
if (!area->nia.niovs)
228229
goto err;
229230

230-
area->freelist = kvmalloc_array(nr_pages, sizeof(area->freelist[0]),
231+
area->freelist = kvmalloc_array(nr_iovs, sizeof(area->freelist[0]),
231232
GFP_KERNEL | __GFP_ZERO);
232233
if (!area->freelist)
233234
goto err;
234235

235-
for (i = 0; i < nr_pages; i++)
236+
for (i = 0; i < nr_iovs; i++)
236237
area->freelist[i] = i;
237238

238-
area->user_refs = kvmalloc_array(nr_pages, sizeof(area->user_refs[0]),
239+
area->user_refs = kvmalloc_array(nr_iovs, sizeof(area->user_refs[0]),
239240
GFP_KERNEL | __GFP_ZERO);
240241
if (!area->user_refs)
241242
goto err;
242243

243-
for (i = 0; i < nr_pages; i++) {
244+
for (i = 0; i < nr_iovs; i++) {
244245
struct net_iov *niov = &area->nia.niovs[i];
245246

246247
niov->owner = &area->nia;
247248
area->freelist[i] = i;
248249
atomic_set(&area->user_refs[i], 0);
249250
}
250251

251-
area->free_count = nr_pages;
252+
area->free_count = nr_iovs;
252253
area->ifq = ifq;
253254
/* we're only supporting one area per ifq for now */
254255
area->area_id = 0;

io_uring/zcrx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct io_zcrx_area {
1515
bool is_mapped;
1616
u16 area_id;
1717
struct page **pages;
18+
unsigned long nr_folios;
1819

1920
/* freelist */
2021
spinlock_t freelist_lock ____cacheline_aligned_in_smp;
@@ -26,11 +27,11 @@ struct io_zcrx_ifq {
2627
struct io_ring_ctx *ctx;
2728
struct io_zcrx_area *area;
2829

30+
spinlock_t rq_lock ____cacheline_aligned_in_smp;
2931
struct io_uring *rq_ring;
3032
struct io_uring_zcrx_rqe *rqes;
31-
u32 rq_entries;
3233
u32 cached_rq_head;
33-
spinlock_t rq_lock;
34+
u32 rq_entries;
3435

3536
u32 if_rxq;
3637
struct device *dev;

0 commit comments

Comments
 (0)