[PATCH] drm/i915/gvt: Expose opregion in vgpu open

Zhenyu Wang zhenyuw at linux.intel.com
Fri Feb 2 06:44:42 UTC 2018


On 2018.02.02 07:04:27 +0800, Tina Zhang wrote:
> Opregion, fully virtualized by device model, is needed by hypervisors
> for display. That's why the emulated opregion is created and destroyed
> in MPT interface. For different hypervisors, this piece of memory might
> be wrapped into different interfaces. E.g. for KVM/VFIO, it is wrapped
> into a VFIO region during vGPU opening.
> 
> This patch puts the opregion registration in vgpu_open for KVM/VFIO.
> 
> V2:
> - Add return check for kvm_set_opregion. (Zhenyu)
> 
> Signed-off-by: Tina Zhang <tina.zhang at intel.com>
> ---
>  drivers/gpu/drm/i915/gvt/hypercall.h |  1 -
>  drivers/gpu/drm/i915/gvt/kvmgt.c     | 10 ++++++++--
>  drivers/gpu/drm/i915/gvt/mpt.h       | 15 ---------------
>  drivers/gpu/drm/i915/gvt/vgpu.c      |  4 ----
>  4 files changed, 8 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gvt/hypercall.h b/drivers/gpu/drm/i915/gvt/hypercall.h
> index f8e77e1..5544b27 100644
> --- a/drivers/gpu/drm/i915/gvt/hypercall.h
> +++ b/drivers/gpu/drm/i915/gvt/hypercall.h
> @@ -55,7 +55,6 @@ struct intel_gvt_mpt {
>  			      unsigned long mfn, unsigned int nr, bool map);
>  	int (*set_trap_area)(unsigned long handle, u64 start, u64 end,
>  			     bool map);
> -	int (*set_opregion)(void *vgpu);
>  	int (*get_vfio_device)(void *vgpu);
>  	void (*put_vfio_device)(void *vgpu);
>  	bool (*is_valid_gfn)(unsigned long handle, unsigned long gfn);
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 70f03e9..f4d5aad 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -405,10 +405,13 @@ static int kvmgt_set_opregion(void *p_vgpu)
>  	 * other one created by VFIO later, is used by guest actually.
>  	 */
>  	base = vgpu_opregion(vgpu)->va;
> -	if (!base)
> +	if (!base) {
> +		gvt_vgpu_err("failed to get virtual opregion\n");
>  		return -ENOMEM;
> +	}
>  
>  	if (memcmp(base, OPREGION_SIGNATURE, 16)) {
> +		gvt_vgpu_err("virtual opregion is invalid\n");
>  		memunmap(base);
>  		return -EINVAL;
>  	}
> @@ -550,6 +553,10 @@ static int intel_vgpu_open(struct mdev_device *mdev)
>  	if (ret)
>  		goto undo_group;
>  
> +	ret = kvmgt_set_opregion(vgpu);
> +	if (ret)
> +		goto undo_group;
> +

Looks this doesn't properly handle fail path for above init?
Or move into guest_init?

>  	intel_gvt_ops->vgpu_activate(vgpu);
>  
>  	atomic_set(&vgpu->vdev.released, 0);
> @@ -1602,7 +1609,6 @@ struct intel_gvt_mpt kvmgt_mpt = {
>  	.read_gpa = kvmgt_read_gpa,
>  	.write_gpa = kvmgt_write_gpa,
>  	.gfn_to_mfn = kvmgt_gfn_to_pfn,
> -	.set_opregion = kvmgt_set_opregion,
>  	.get_vfio_device = kvmgt_get_vfio_device,
>  	.put_vfio_device = kvmgt_put_vfio_device,
>  	.is_valid_gfn = kvmgt_is_valid_gfn,
> diff --git a/drivers/gpu/drm/i915/gvt/mpt.h b/drivers/gpu/drm/i915/gvt/mpt.h
> index 81aff4e..2abe8b3 100644
> --- a/drivers/gpu/drm/i915/gvt/mpt.h
> +++ b/drivers/gpu/drm/i915/gvt/mpt.h
> @@ -295,21 +295,6 @@ static inline int intel_gvt_hypervisor_set_trap_area(
>  }
>  
>  /**
> - * intel_gvt_hypervisor_set_opregion - Set opregion for guest
> - * @vgpu: a vGPU
> - *
> - * Returns:
> - * Zero on success, negative error code if failed.
> - */
> -static inline int intel_gvt_hypervisor_set_opregion(struct intel_vgpu *vgpu)
> -{
> -	if (!intel_gvt_host.mpt->set_opregion)
> -		return 0;
> -
> -	return intel_gvt_host.mpt->set_opregion(vgpu);
> -}
> -
> -/**
>   * intel_gvt_hypervisor_get_vfio_device - increase vfio device ref count
>   * @vgpu: a vGPU
>   *
> diff --git a/drivers/gpu/drm/i915/gvt/vgpu.c b/drivers/gpu/drm/i915/gvt/vgpu.c
> index b87b19d..aa14f21 100644
> --- a/drivers/gpu/drm/i915/gvt/vgpu.c
> +++ b/drivers/gpu/drm/i915/gvt/vgpu.c
> @@ -395,10 +395,6 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
>  	if (ret)
>  		goto out_clean_sched_policy;
>  
> -	ret = intel_gvt_hypervisor_set_opregion(vgpu);
> -	if (ret)
> -		goto out_clean_sched_policy;
> -
>  	mutex_unlock(&gvt->lock);
>  
>  	return vgpu;
> -- 
> 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/20180202/25047ea0/attachment.sig>


More information about the intel-gvt-dev mailing list