Skip to content

Commit 534103b

Browse files
Daniel Marcovitchjoergroedel
authored andcommitted
iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind
When unbinding pasid - a race condition exists vs outstanding page faults. To prevent this, the pasid_state object contains a refcount. * set to 1 on pasid bind * incremented on each ppr notification start * decremented on each ppr notification done * decremented on pasid unbind Since refcount_dec assumes that refcount will never reach 0: the current implementation causes the following to be invoked on pasid unbind: REFCOUNT_WARN("decrement hit 0; leaking memory") Fix this issue by changing refcount_dec to refcount_dec_and_test to explicitly handle refcount=1. Fixes: 8bc5482 ("iommu/amd: Convert from atomic_t to refcount_t on pasid_state->count") Signed-off-by: Daniel Marcovitch <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 06c2afb commit 534103b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/iommu/amd/iommu_v2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ static void put_pasid_state(struct pasid_state *pasid_state)
262262

263263
static void put_pasid_state_wait(struct pasid_state *pasid_state)
264264
{
265-
refcount_dec(&pasid_state->count);
266-
wait_event(pasid_state->wq, !refcount_read(&pasid_state->count));
265+
if (!refcount_dec_and_test(&pasid_state->count))
266+
wait_event(pasid_state->wq, !refcount_read(&pasid_state->count));
267267
free_pasid_state(pasid_state);
268268
}
269269

0 commit comments

Comments
 (0)