Skip to content

Commit 1d0f874

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vhost-vdpa: reset vendor specific mapping to initial state in .release
Devices with on-chip IOMMU or vendor specific IOTLB implementation may need to restore iotlb mapping to the initial or default state using the .reset_map op, as it's desirable for some parent devices to not work with DMA ops and maintain a simple IOMMU model with .reset_map. In particular, device reset should not cause mapping to go away on such IOTLB model, so persistent mapping is implied across reset. Before the userspace process using vhost-vdpa is gone, give it a chance to reset iotlb back to the initial state in vhost_vdpa_cleanup(). Signed-off-by: Si-Wei Liu <[email protected]> Acked-by: Eugenio Pérez <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent d2cf1b6 commit 1d0f874

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/vhost/vdpa.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ static struct vhost_vdpa_as *vhost_vdpa_find_alloc_as(struct vhost_vdpa *v,
131131
return vhost_vdpa_alloc_as(v, asid);
132132
}
133133

134+
static void vhost_vdpa_reset_map(struct vhost_vdpa *v, u32 asid)
135+
{
136+
struct vdpa_device *vdpa = v->vdpa;
137+
const struct vdpa_config_ops *ops = vdpa->config;
138+
139+
if (ops->reset_map)
140+
ops->reset_map(vdpa, asid);
141+
}
142+
134143
static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid)
135144
{
136145
struct vhost_vdpa_as *as = asid_to_as(v, asid);
@@ -140,6 +149,14 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid)
140149

141150
hlist_del(&as->hash_link);
142151
vhost_vdpa_iotlb_unmap(v, &as->iotlb, 0ULL, 0ULL - 1, asid);
152+
/*
153+
* Devices with vendor specific IOMMU may need to restore
154+
* iotlb to the initial or default state, which cannot be
155+
* cleaned up in the all range unmap call above. Give them
156+
* a chance to clean up or reset the map to the desired
157+
* state.
158+
*/
159+
vhost_vdpa_reset_map(v, asid);
143160
kfree(as);
144161

145162
return 0;

0 commit comments

Comments
 (0)