]> git.baikalelectronics.ru Git - kernel.git/commit
iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind
authorDaniel Marcovitch <dmarcovitch@nvidia.com>
Fri, 9 Jun 2023 10:51:45 +0000 (10:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:50 +0000 (09:42 +0200)
commit13ed255248dfbbb7f23f9170c7a537fb9ca22c73
tree50942c06474094cfc63f6a6b26800ce5080efc93
parent25afb3e03bf8ab02567af4b6ffbfd6250a91a9f8
iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind

[ Upstream commit 534103bcd52ca9c1fecbc70e717b4a538dc4ded8 ]

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: 8bc54824da4e ("iommu/amd: Convert from atomic_t to refcount_t on pasid_state->count")
Signed-off-by: Daniel Marcovitch <dmarcovitch@nvidia.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
Link: https://lore.kernel.org/r/20230609105146.7773-2-vasant.hegde@amd.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/amd/iommu_v2.c