Commit 65817085 authored by Kirti Wankhede's avatar Kirti Wankhede Committed by Alex Williamson

vfio iommu: Remove atomicity of ref_count of pinned pages

vfio_pfn.ref_count is always updated while holding iommu->lock, using
atomic variable is overkill.
Signed-off-by: default avatarKirti Wankhede <kwankhede@nvidia.com>
Reviewed-by: default avatarNeo Jia <cjia@nvidia.com>
Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Reviewed-by: default avatarYan Zhao <yan.y.zhao@intel.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent a8a24f3f
...@@ -112,7 +112,7 @@ struct vfio_pfn { ...@@ -112,7 +112,7 @@ struct vfio_pfn {
struct rb_node node; struct rb_node node;
dma_addr_t iova; /* Device address */ dma_addr_t iova; /* Device address */
unsigned long pfn; /* Host pfn */ unsigned long pfn; /* Host pfn */
atomic_t ref_count; unsigned int ref_count;
}; };
struct vfio_regions { struct vfio_regions {
...@@ -233,7 +233,7 @@ static int vfio_add_to_pfn_list(struct vfio_dma *dma, dma_addr_t iova, ...@@ -233,7 +233,7 @@ static int vfio_add_to_pfn_list(struct vfio_dma *dma, dma_addr_t iova,
vpfn->iova = iova; vpfn->iova = iova;
vpfn->pfn = pfn; vpfn->pfn = pfn;
atomic_set(&vpfn->ref_count, 1); vpfn->ref_count = 1;
vfio_link_pfn(dma, vpfn); vfio_link_pfn(dma, vpfn);
return 0; return 0;
} }
...@@ -251,7 +251,7 @@ static struct vfio_pfn *vfio_iova_get_vfio_pfn(struct vfio_dma *dma, ...@@ -251,7 +251,7 @@ static struct vfio_pfn *vfio_iova_get_vfio_pfn(struct vfio_dma *dma,
struct vfio_pfn *vpfn = vfio_find_vpfn(dma, iova); struct vfio_pfn *vpfn = vfio_find_vpfn(dma, iova);
if (vpfn) if (vpfn)
atomic_inc(&vpfn->ref_count); vpfn->ref_count++;
return vpfn; return vpfn;
} }
...@@ -259,7 +259,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn) ...@@ -259,7 +259,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
{ {
int ret = 0; int ret = 0;
if (atomic_dec_and_test(&vpfn->ref_count)) { vpfn->ref_count--;
if (!vpfn->ref_count) {
ret = put_pfn(vpfn->pfn, dma->prot); ret = put_pfn(vpfn->pfn, dma->prot);
vfio_remove_from_pfn_list(dma, vpfn); vfio_remove_from_pfn_list(dma, vpfn);
} }
......
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