Skip to content

Commit 07afd31

Browse files
Long LiChandan Babu R
authored andcommitted
xfs: add lock protection when remove perag from radix tree
Take mp->m_perag_lock for deletions from the perag radix tree in xfs_initialize_perag to prevent racing with tagging operations. Lookups are fine - they are RCU protected so already deal with the tree changing shape underneath the lookup - but tagging operations require the tree to be stable while the tags are propagated back up to the root. Right now there's nothing stopping radix tree tagging from operating while a growfs operation is progress and adding/removing new entries into the radix tree. Hence we can have traversals that require a stable tree occurring at the same time we are removing unused entries from the radix tree which causes the shape of the tree to change. Likely this hasn't caused a problem in the past because we are only doing append addition and removal so the active AG part of the tree is not changing shape, but that doesn't mean it is safe. Just making the radix tree modifications serialise against each other is obviously correct. Signed-off-by: Long Li <leo.lilong@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent 98bdbf6 commit 07afd31

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

fs/xfs/libxfs/xfs_ag.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,17 @@ xfs_initialize_perag(
424424

425425
out_remove_pag:
426426
xfs_defer_drain_free(&pag->pag_intents_drain);
427+
spin_lock(&mp->m_perag_lock);
427428
radix_tree_delete(&mp->m_perag_tree, index);
429+
spin_unlock(&mp->m_perag_lock);
428430
out_free_pag:
429431
kmem_free(pag);
430432
out_unwind_new_pags:
431433
/* unwind any prior newly initialized pags */
432434
for (index = first_initialised; index < agcount; index++) {
435+
spin_lock(&mp->m_perag_lock);
433436
pag = radix_tree_delete(&mp->m_perag_tree, index);
437+
spin_unlock(&mp->m_perag_lock);
434438
if (!pag)
435439
break;
436440
xfs_buf_hash_destroy(pag);

0 commit comments

Comments
 (0)