[PATCH] drm/i915/gvt: free VFIO region space in vgpu detach

Zhenyu Wang zhenyuw at linux.intel.com
Tue Jan 15 10:15:16 UTC 2019


On 2019.01.14 18:43:39 +0800, hang.yuan at linux.intel.com wrote:
> From: Hang Yuan <hang.yuan at linux.intel.com>
> 
> 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")
> Signed-off-by: Hang Yuan <hang.yuan at linux.intel.com>
> ---

Looks fine to me, will pick up.

Reviewed-by: Zhenyu Wang <zhenyuw at linux.intel.com>

>  drivers/gpu/drm/i915/gvt/hypercall.h |  2 +-
>  drivers/gpu/drm/i915/gvt/kvmgt.c     | 16 ++++++++++++++--
>  drivers/gpu/drm/i915/gvt/mpt.h       |  2 +-
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/hypercall.h b/drivers/gpu/drm/i915/gvt/hypercall.h
> index 5079886..831ab34 100644
> --- a/drivers/gpu/drm/i915/gvt/hypercall.h
> +++ b/drivers/gpu/drm/i915/gvt/hypercall.h
> @@ -47,7 +47,7 @@ struct intel_gvt_mpt {
>  	int (*host_init)(struct device *dev, void *gvt, const void *ops);
>  	void (*host_exit)(struct device *dev);
>  	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);
>  	unsigned long (*from_virt_to_mfn)(void *p);
>  	int (*enable_page_track)(unsigned long handle, u64 gfn);
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index a19e684..b6bb650 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -1671,9 +1671,21 @@ static int kvmgt_attach_vgpu(void *vgpu, unsigned long *handle)
>  	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)
> diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h
> index 9b4225d..5b5995a 100644
> --- a/drivers/gpu/drm/i915/gvt/mpt.h
> +++ b/drivers/gpu/drm/i915/gvt/mpt.h
> @@ -99,7 +99,7 @@ static inline void intel_gvt_hypervisor_detach_vgpu(struct intel_vgpu *vgpu)
>  	if (!intel_gvt_host.mpt->detach_vgpu)
>  		return;
>  
> -	intel_gvt_host.mpt->detach_vgpu(vgpu->handle);
> +	intel_gvt_host.mpt->detach_vgpu(vgpu);
>  }
>  
>  #define MSI_CAP_CONTROL(offset) (offset + 2)
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-gvt-dev mailing list
> intel-gvt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev

-- 
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/intel-gvt-dev/attachments/20190115/40a4fb3d/attachment.sig>


More information about the intel-gvt-dev mailing list