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

Zhang, Tina tina.zhang at intel.com
Fri Feb 2 07:06:48 UTC 2018



> -----Original Message-----
> From: Zhenyu Wang [mailto:zhenyuw at linux.intel.com]
> Sent: Friday, February 2, 2018 2:45 PM
> To: Zhang, Tina <tina.zhang at intel.com>
> Cc: Wang, Zhi A <zhi.a.wang at intel.com>; intel-gvt-dev at lists.freedesktop.org
> Subject: Re: [PATCH] drm/i915/gvt: Expose opregion in vgpu open
> 
> 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?
Do you mean "kvmgt_set_opregion" could be included in "kvmgt_guest_init()" or above it?
Well, "kvmgt_guest_init()" is the place to initialize the "kvmgt_guest_info", which might not be the right place for "kvmgt_set_opregion".

BR,
Tina
> 
> >  	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


More information about the intel-gvt-dev mailing list