Skip to content

Commit 6c2d0f9

Browse files
Hang Yuanzhenyw
authored andcommitted
drm/i915/gvt: free VFIO region space in vgpu detach
VFIO region space is allocated when one region is registered for one vgpu. So free the space when destroy the vgpu. Also change the parameter of detach_vgpu callback to use vgpu directly. Fixes: b851ade ("drm/i915/gvt: Add opregion support") Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com> Signed-off-by: Hang Yuan <hang.yuan@linux.intel.com> Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
1 parent ba0a64b commit 6c2d0f9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

drivers/gpu/drm/i915/gvt/hypercall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct intel_gvt_mpt {
4141
int (*host_init)(struct device *dev, void *gvt, const void *ops);
4242
void (*host_exit)(struct device *dev, void *gvt);
4343
int (*attach_vgpu)(void *vgpu, unsigned long *handle);
44-
void (*detach_vgpu)(unsigned long handle);
44+
void (*detach_vgpu)(void *vgpu);
4545
int (*inject_msi)(unsigned long handle, u32 addr, u16 data);
4646
unsigned long (*from_virt_to_mfn)(void *p);
4747
int (*enable_page_track)(unsigned long handle, u64 gfn);

drivers/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,9 +1662,21 @@ static int kvmgt_attach_vgpu(void *vgpu, unsigned long *handle)
16621662
return 0;
16631663
}
16641664

1665-
static void kvmgt_detach_vgpu(unsigned long handle)
1665+
static void kvmgt_detach_vgpu(void *p_vgpu)
16661666
{
1667-
/* nothing to do here */
1667+
int i;
1668+
struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu;
1669+
1670+
if (!vgpu->vdev.region)
1671+
return;
1672+
1673+
for (i = 0; i < vgpu->vdev.num_regions; i++)
1674+
if (vgpu->vdev.region[i].ops->release)
1675+
vgpu->vdev.region[i].ops->release(vgpu,
1676+
&vgpu->vdev.region[i]);
1677+
vgpu->vdev.num_regions = 0;
1678+
kfree(vgpu->vdev.region);
1679+
vgpu->vdev.region = NULL;
16681680
}
16691681

16701682
static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data)

drivers/gpu/drm/i915/gvt/mpt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static inline void intel_gvt_hypervisor_detach_vgpu(struct intel_vgpu *vgpu)
101101
if (!intel_gvt_host.mpt->detach_vgpu)
102102
return;
103103

104-
intel_gvt_host.mpt->detach_vgpu(vgpu->handle);
104+
intel_gvt_host.mpt->detach_vgpu(vgpu);
105105
}
106106

107107
#define MSI_CAP_CONTROL(offset) (offset + 2)

0 commit comments

Comments
 (0)