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: b851adeac0858c7d257b3 ("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>
This commit is contained in:
Hang Yuan 2019-01-14 18:43:39 +08:00 committed by Zhenyu Wang
parent ba0a64bcf8
commit 6c2d0f9976
3 changed files with 16 additions and 4 deletions

View File

@ -41,7 +41,7 @@ struct intel_gvt_mpt {
int (*host_init)(struct device *dev, void *gvt, const void *ops); int (*host_init)(struct device *dev, void *gvt, const void *ops);
void (*host_exit)(struct device *dev, void *gvt); void (*host_exit)(struct device *dev, void *gvt);
int (*attach_vgpu)(void *vgpu, unsigned long *handle); int (*attach_vgpu)(void *vgpu, unsigned long *handle);
void (*detach_vgpu)(unsigned long handle); void (*detach_vgpu)(void *vgpu);
int (*inject_msi)(unsigned long handle, u32 addr, u16 data); int (*inject_msi)(unsigned long handle, u32 addr, u16 data);
unsigned long (*from_virt_to_mfn)(void *p); unsigned long (*from_virt_to_mfn)(void *p);
int (*enable_page_track)(unsigned long handle, u64 gfn); int (*enable_page_track)(unsigned long handle, u64 gfn);

View File

@ -1662,9 +1662,21 @@ static int kvmgt_attach_vgpu(void *vgpu, unsigned long *handle)
return 0; return 0;
} }
static void kvmgt_detach_vgpu(unsigned long handle) static void kvmgt_detach_vgpu(void *p_vgpu)
{ {
/* nothing to do here */ int i;
struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu;
if (!vgpu->vdev.region)
return;
for (i = 0; i < vgpu->vdev.num_regions; i++)
if (vgpu->vdev.region[i].ops->release)
vgpu->vdev.region[i].ops->release(vgpu,
&vgpu->vdev.region[i]);
vgpu->vdev.num_regions = 0;
kfree(vgpu->vdev.region);
vgpu->vdev.region = NULL;
} }
static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data) static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data)

View File

@ -101,7 +101,7 @@ static inline void intel_gvt_hypervisor_detach_vgpu(struct intel_vgpu *vgpu)
if (!intel_gvt_host.mpt->detach_vgpu) if (!intel_gvt_host.mpt->detach_vgpu)
return; return;
intel_gvt_host.mpt->detach_vgpu(vgpu->handle); intel_gvt_host.mpt->detach_vgpu(vgpu);
} }
#define MSI_CAP_CONTROL(offset) (offset + 2) #define MSI_CAP_CONTROL(offset) (offset + 2)