Re: [PATCH 3/5] blk-mq: Defer freeing of tags page_list to SRCU callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 2025/08/01 19:44, Ming Lei 写道:
Tag iterators can race with the freeing of the request pages(tags->page_list),
potentially leading to use-after-free issues.

Defer the freeing of the page list and the tags structure itself until
after an SRCU grace period has passed. This ensures that any concurrent
tag iterators have completed before the memory is released. With this
way, we can replace the big tags->lock in tags iterator code path with
srcu for solving the issue.

This is achieved by:
- Adding a new `srcu_struct tags_srcu` to `blk_mq_tag_set` to protect
   tag map iteration.
- Adding an `rcu_head` to `struct blk_mq_tags` to be used with
   `call_srcu`.
- Moving the page list freeing logic and the `kfree(tags)` call into a
   new callback function, `blk_mq_free_tags_callback`.
- In `blk_mq_free_tags`, invoking `call_srcu` to schedule the new
   callback for deferred execution.

The read-side protection for the tag iterators will be added in a
subsequent patch.

Signed-off-by: Ming Lei<ming.lei@xxxxxxxxxx>
---
  block/blk-mq-tag.c     | 24 +++++++++++++++++++++++-
  block/blk-mq.c         | 26 +++++++++++++-------------
  include/linux/blk-mq.h |  2 ++
  3 files changed, 38 insertions(+), 14 deletions(-)

LGTM
Reviewed-by: Yu Kuai <yukuai3@xxxxxxxxxx>





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux