diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 0262f2c48a..ed1e2fabce 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1488,8 +1488,15 @@ unmap_common( if ( put_handle ) put_maptrack_handle(lgt, op->handle); - /* See the respective comment in map_grant_ref(). */ - if ( rc == GNTST_okay && ld != rd && gnttab_need_iommu_mapping(ld) ) + /* + * map_grant_ref() will only increment the refcount (and update the + * IOMMU) once per mapping. So we only want to decrement it once the + * maptrack handle has been put, alongside the further IOMMU update. + * + * For the second and third check, see the respective comment in + * map_grant_ref(). + */ + if ( put_handle && ld != rd && gnttab_need_iommu_mapping(ld) ) { void **slot; union maptrack_node node;