Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/zcrx: add user_struct and mm_struct to io_zcrx_ifq

In preparation for removing ifq->ctx and making ifq lifetime independent
of ring ctx, add user_struct and mm_struct to io_zcrx_ifq.

In the ifq cleanup path, these are the only fields used from the main
ring ctx to do accounting. Taking a copy in the ifq allows ifq->ctx to
be removed later, including the ctx->refs held by the ifq.

Signed-off-by: David Wei <dw@davidwei.uk>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

David Wei and committed by
Jens Axboe
5c686456 edd706ed

+20 -6
+18 -6
io_uring/zcrx.c
··· 200 200 } 201 201 202 202 mem->account_pages = io_count_account_pages(pages, nr_pages); 203 - ret = io_account_mem(ifq->ctx->user, ifq->ctx->mm_account, mem->account_pages); 203 + ret = io_account_mem(ifq->user, ifq->mm_account, mem->account_pages); 204 204 if (ret < 0) 205 205 mem->account_pages = 0; 206 206 ··· 344 344 atomic_inc(io_get_user_counter(niov)); 345 345 } 346 346 347 - static int io_allocate_rbuf_ring(struct io_zcrx_ifq *ifq, 347 + static int io_allocate_rbuf_ring(struct io_ring_ctx *ctx, 348 + struct io_zcrx_ifq *ifq, 348 349 struct io_uring_zcrx_ifq_reg *reg, 349 350 struct io_uring_region_desc *rd, 350 351 u32 id) ··· 363 362 mmap_offset = IORING_MAP_OFF_ZCRX_REGION; 364 363 mmap_offset += id << IORING_OFF_PBUF_SHIFT; 365 364 366 - ret = io_create_region(ifq->ctx, &ifq->region, rd, mmap_offset); 365 + ret = io_create_region(ctx, &ifq->region, rd, mmap_offset); 367 366 if (ret < 0) 368 367 return ret; 369 368 ··· 379 378 380 379 static void io_free_rbuf_ring(struct io_zcrx_ifq *ifq) 381 380 { 382 - io_free_region(ifq->ctx->user, &ifq->region); 381 + io_free_region(ifq->user, &ifq->region); 383 382 ifq->rq_ring = NULL; 384 383 ifq->rqes = NULL; 385 384 } ··· 391 390 io_release_area_mem(&area->mem); 392 391 393 392 if (area->mem.account_pages) 394 - io_unaccount_mem(area->ifq->ctx->user, area->ifq->ctx->mm_account, 393 + io_unaccount_mem(ifq->user, ifq->mm_account, 395 394 area->mem.account_pages); 396 395 397 396 kvfree(area->freelist); ··· 526 525 527 526 if (ifq->area) 528 527 io_zcrx_free_area(ifq, ifq->area); 528 + free_uid(ifq->user); 529 + if (ifq->mm_account) 530 + mmdrop(ifq->mm_account); 529 531 if (ifq->dev) 530 532 put_device(ifq->dev); 531 533 ··· 592 588 ifq = io_zcrx_ifq_alloc(ctx); 593 589 if (!ifq) 594 590 return -ENOMEM; 591 + if (ctx->user) { 592 + get_uid(ctx->user); 593 + ifq->user = ctx->user; 594 + } 595 + if (ctx->mm_account) { 596 + mmgrab(ctx->mm_account); 597 + ifq->mm_account = ctx->mm_account; 598 + } 595 599 ifq->rq_entries = reg.rq_entries; 596 600 597 601 scoped_guard(mutex, &ctx->mmap_lock) { ··· 609 597 goto ifq_free; 610 598 } 611 599 612 - ret = io_allocate_rbuf_ring(ifq, &reg, &rd, id); 600 + ret = io_allocate_rbuf_ring(ctx, ifq, &reg, &rd, id); 613 601 if (ret) 614 602 goto err; 615 603
+2
io_uring/zcrx.h
··· 42 42 struct io_ring_ctx *ctx; 43 43 struct io_zcrx_area *area; 44 44 unsigned niov_shift; 45 + struct user_struct *user; 46 + struct mm_struct *mm_account; 45 47 46 48 spinlock_t rq_lock ____cacheline_aligned_in_smp; 47 49 struct io_uring *rq_ring;