Commit e27c5b9d authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

writeback: remove broken rbtree_postorder_for_each_entry_safe() usage in cgwb_bdi_destroy()

a20135ff ("writeback: don't drain bdi_writeback_congested on bdi
destruction") added rbtree_postorder_for_each_entry_safe() which is
used to remove all entries; however, according to Cody, the iterator
isn't safe against operations which may rebalance the tree.  Fix it by
switching to repeatedly removing rb_first() until empty.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Reported-by: default avatarCody P Schafer <dev@codyps.com>
Fixes: a20135ff ("writeback: don't drain bdi_writeback_congested on bdi destruction")
Link: http://lkml.kernel.org/g/1443997973-1700-1-git-send-email-dev@codyps.comSigned-off-by: default avatarJens Axboe <axboe@fb.com>
parent 0dfc70c3
...@@ -681,7 +681,7 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi) ...@@ -681,7 +681,7 @@ static int cgwb_bdi_init(struct backing_dev_info *bdi)
static void cgwb_bdi_destroy(struct backing_dev_info *bdi) static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
{ {
struct radix_tree_iter iter; struct radix_tree_iter iter;
struct bdi_writeback_congested *congested, *congested_n; struct rb_node *rbn;
void **slot; void **slot;
WARN_ON(test_bit(WB_registered, &bdi->wb.state)); WARN_ON(test_bit(WB_registered, &bdi->wb.state));
...@@ -691,9 +691,11 @@ static void cgwb_bdi_destroy(struct backing_dev_info *bdi) ...@@ -691,9 +691,11 @@ static void cgwb_bdi_destroy(struct backing_dev_info *bdi)
radix_tree_for_each_slot(slot, &bdi->cgwb_tree, &iter, 0) radix_tree_for_each_slot(slot, &bdi->cgwb_tree, &iter, 0)
cgwb_kill(*slot); cgwb_kill(*slot);
rbtree_postorder_for_each_entry_safe(congested, congested_n, while ((rbn = rb_first(&bdi->cgwb_congested_tree))) {
&bdi->cgwb_congested_tree, rb_node) { struct bdi_writeback_congested *congested =
rb_erase(&congested->rb_node, &bdi->cgwb_congested_tree); rb_entry(rbn, struct bdi_writeback_congested, rb_node);
rb_erase(rbn, &bdi->cgwb_congested_tree);
congested->bdi = NULL; /* mark @congested unlinked */ congested->bdi = NULL; /* mark @congested unlinked */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment