Skip to content

Commit 6581708

Browse files
Kirti Wankhedeawilliam
authored andcommitted
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: Kirti Wankhede <[email protected]> Reviewed-by: Neo Jia <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Reviewed-by: Yan Zhao <[email protected]> Signed-off-by: Alex Williamson <[email protected]>
1 parent a8a24f3 commit 6581708

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct vfio_pfn {
112112
struct rb_node node;
113113
dma_addr_t iova; /* Device address */
114114
unsigned long pfn; /* Host pfn */
115-
atomic_t ref_count;
115+
unsigned int ref_count;
116116
};
117117

118118
struct vfio_regions {
@@ -233,7 +233,7 @@ static int vfio_add_to_pfn_list(struct vfio_dma *dma, dma_addr_t iova,
233233

234234
vpfn->iova = iova;
235235
vpfn->pfn = pfn;
236-
atomic_set(&vpfn->ref_count, 1);
236+
vpfn->ref_count = 1;
237237
vfio_link_pfn(dma, vpfn);
238238
return 0;
239239
}
@@ -251,15 +251,16 @@ static struct vfio_pfn *vfio_iova_get_vfio_pfn(struct vfio_dma *dma,
251251
struct vfio_pfn *vpfn = vfio_find_vpfn(dma, iova);
252252

253253
if (vpfn)
254-
atomic_inc(&vpfn->ref_count);
254+
vpfn->ref_count++;
255255
return vpfn;
256256
}
257257

258258
static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
259259
{
260260
int ret = 0;
261261

262-
if (atomic_dec_and_test(&vpfn->ref_count)) {
262+
vpfn->ref_count--;
263+
if (!vpfn->ref_count) {
263264
ret = put_pfn(vpfn->pfn, dma->prot);
264265
vfio_remove_from_pfn_list(dma, vpfn);
265266
}

0 commit comments

Comments
 (0)