android_kernel_samsung_sm8650/drivers/iommu/amd
Daniel Marcovitch 13ed255248 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: 8bc54824da ("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>
2023-09-13 09:42:50 +02:00
..
amd_iommu_types.h iommu/amd: Introduce Disable IRTE Caching Support 2023-08-23 17:52:21 +02:00
amd_iommu.h iommu/amd: Fix up merge conflict resolution 2023-06-09 10:34:00 +02:00
debugfs.c
init.c iommu/amd: Introduce Disable IRTE Caching Support 2023-08-23 17:52:21 +02:00
io_pgtable_v2.c iommu/amd: Initial support for AMD IOMMU v2 page table 2022-09-07 16:12:35 +02:00
io_pgtable.c iommu/amd/io-pgtable: Implement unmap_pages io_pgtable_ops callback 2022-09-07 16:12:33 +02:00
iommu_v2.c iommu/amd/iommu_v2: Fix pasid_state refcount dec hit 0 warning on pasid unbind 2023-09-13 09:42:50 +02:00
iommu.c iommu/amd/pgtbl_v2: Fix domain max address 2023-06-09 10:34:28 +02:00
Kconfig iommu/dma: Clean up Kconfig 2022-09-07 14:46:59 +02:00
Makefile iommu/amd: Initial support for AMD IOMMU v2 page table 2022-09-07 16:12:35 +02:00
quirks.c iommu/amd: Include PCI segment ID when initialize IOMMU 2022-07-07 09:37:51 +02:00