Commit 9aab74e
Ming Lei
blk-mq: Defer freeing of tags page_list to SRCU callback
JIRA: https://issues.redhat.com/browse/RHEL-123480
commit ad0d05d
Author: Ming Lei <ming.lei@redhat.com>
Date: Sat Aug 30 10:18:21 2025 +0800
blk-mq: Defer freeing of tags page_list to SRCU callback
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.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Ming Lei <ming.lei@redhat.com>1 parent eda11d6 commit 9aab74e
3 files changed
+38
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
576 | 579 | | |
577 | 580 | | |
578 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
579 | 601 | | |
580 | 602 | | |
581 | 603 | | |
582 | 604 | | |
583 | | - | |
| 605 | + | |
584 | 606 | | |
585 | 607 | | |
586 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3454 | 3454 | | |
3455 | 3455 | | |
3456 | 3456 | | |
3457 | | - | |
3458 | 3457 | | |
3459 | 3458 | | |
3460 | 3459 | | |
| |||
3478 | 3477 | | |
3479 | 3478 | | |
3480 | 3479 | | |
3481 | | - | |
3482 | | - | |
3483 | | - | |
3484 | | - | |
3485 | | - | |
3486 | | - | |
3487 | | - | |
3488 | | - | |
3489 | | - | |
3490 | | - | |
3491 | | - | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
3492 | 3484 | | |
3493 | 3485 | | |
3494 | 3486 | | |
| |||
4834 | 4826 | | |
4835 | 4827 | | |
4836 | 4828 | | |
| 4829 | + | |
| 4830 | + | |
| 4831 | + | |
4837 | 4832 | | |
4838 | 4833 | | |
4839 | 4834 | | |
| |||
4842 | 4837 | | |
4843 | 4838 | | |
4844 | 4839 | | |
4845 | | - | |
| 4840 | + | |
4846 | 4841 | | |
4847 | 4842 | | |
4848 | 4843 | | |
| |||
4871 | 4866 | | |
4872 | 4867 | | |
4873 | 4868 | | |
| 4869 | + | |
| 4870 | + | |
4874 | 4871 | | |
4875 | 4872 | | |
4876 | 4873 | | |
| |||
4916 | 4913 | | |
4917 | 4914 | | |
4918 | 4915 | | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
4919 | 4919 | | |
4920 | 4920 | | |
4921 | 4921 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| 545 | + | |
545 | 546 | | |
546 | 547 | | |
547 | 548 | | |
| |||
797 | 798 | | |
798 | 799 | | |
799 | 800 | | |
| 801 | + | |
800 | 802 | | |
801 | 803 | | |
802 | 804 | | |
| |||
0 commit comments