diff mbox

[PATCHi,v2] drm/i915: Enhanced disable access to stolen memory as a guest

Message ID 1490351024-22347-1-git-send-email-xiong.y.zhang@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhang, Xiong Y March 24, 2017, 10:23 a.m. UTC
commit "04a68a3 drm/i915/gvt: Disable access to stolen memory as a guest"
isn't enough in GVT-d which will pass through IGD to guest and don't run
vgt code. While intel_vgpu_active() is true only when vgt code run on
host and guest in GVT-g.

v2:GVT-g may run in non qemu (Zhenyu)

Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.c        | 1 +
 drivers/gpu/drm/i915/i915_drv.h        | 1 +
 drivers/gpu/drm/i915/i915_gem_stolen.c | 4 ++--
 3 files changed, 4 insertions(+), 2 deletions(-)

Comments

Zhenyu Wang March 27, 2017, 2:21 a.m. UTC | #1
On 2017.03.24 18:23:44 +0800, Xiong Zhang wrote:
> commit "04a68a3 drm/i915/gvt: Disable access to stolen memory as a guest"
> isn't enough in GVT-d which will pass through IGD to guest and don't run
> vgt code. While intel_vgpu_active() is true only when vgt code run on
> host and guest in GVT-g.
> 
> v2:GVT-g may run in non qemu (Zhenyu)
> 
> Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_drv.c        | 1 +
>  drivers/gpu/drm/i915/i915_drv.h        | 1 +
>  drivers/gpu/drm/i915/i915_gem_stolen.c | 4 ++--
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
> index 03d9e45..8b807a9 100644
> --- a/drivers/gpu/drm/i915/i915_drv.c
> +++ b/drivers/gpu/drm/i915/i915_drv.c
> @@ -223,6 +223,7 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv)
>  					    PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
>  				    pch->subsystem_device ==
>  					    PCI_SUBDEVICE_ID_QEMU)) {
> +				dev_priv->run_on_qemu = true;
>  				dev_priv->pch_type =
>  					intel_virt_detect_pch(dev_priv);
>  			} else
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index a5947a4..ad95c87 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2145,6 +2145,7 @@ struct drm_i915_private {
>  	struct intel_uncore uncore;
>  
>  	struct i915_virtual_gpu vgpu;
> +	bool run_on_qemu;
>  
>  	struct intel_gvt *gvt;
>  
> diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
> index f3abdc2..6a011b0 100644
> --- a/drivers/gpu/drm/i915/i915_gem_stolen.c
> +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
> @@ -409,8 +409,8 @@ int i915_gem_init_stolen(struct drm_i915_private *dev_priv)
>  
>  	mutex_init(&dev_priv->mm.stolen_lock);
>  
> -	if (intel_vgpu_active(dev_priv)) {
> -		DRM_INFO("iGVT-g active, disabling use of stolen memory\n");
> +	if (dev_priv->run_on_qemu || intel_vgpu_active(dev_priv)) {
> +		DRM_INFO("Running in guest, disabling use of stolen memory\n");
>  		return 0;
>  	}
>  
> -- 

Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Daniel Vetter March 27, 2017, 11:55 a.m. UTC | #2
On Mon, Mar 27, 2017 at 10:21:42AM +0800, Zhenyu Wang wrote:
> On 2017.03.24 18:23:44 +0800, Xiong Zhang wrote:
> > commit "04a68a3 drm/i915/gvt: Disable access to stolen memory as a guest"
> > isn't enough in GVT-d which will pass through IGD to guest and don't run
> > vgt code. While intel_vgpu_active() is true only when vgt code run on
> > host and guest in GVT-g.
> > 
> > v2:GVT-g may run in non qemu (Zhenyu)
> > 
> > Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.com>
> > ---
> >  drivers/gpu/drm/i915/i915_drv.c        | 1 +
> >  drivers/gpu/drm/i915/i915_drv.h        | 1 +
> >  drivers/gpu/drm/i915/i915_gem_stolen.c | 4 ++--
> >  3 files changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
> > index 03d9e45..8b807a9 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.c
> > +++ b/drivers/gpu/drm/i915/i915_drv.c
> > @@ -223,6 +223,7 @@ static void intel_detect_pch(struct drm_i915_private *dev_priv)
> >  					    PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
> >  				    pch->subsystem_device ==
> >  					    PCI_SUBDEVICE_ID_QEMU)) {
> > +				dev_priv->run_on_qemu = true;
> >  				dev_priv->pch_type =
> >  					intel_virt_detect_pch(dev_priv);
> >  			} else
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> > index a5947a4..ad95c87 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -2145,6 +2145,7 @@ struct drm_i915_private {
> >  	struct intel_uncore uncore;
> >  
> >  	struct i915_virtual_gpu vgpu;
> > +	bool run_on_qemu;
> >  
> >  	struct intel_gvt *gvt;
> >  
> > diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
> > index f3abdc2..6a011b0 100644
> > --- a/drivers/gpu/drm/i915/i915_gem_stolen.c
> > +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
> > @@ -409,8 +409,8 @@ int i915_gem_init_stolen(struct drm_i915_private *dev_priv)
> >  
> >  	mutex_init(&dev_priv->mm.stolen_lock);
> >  
> > -	if (intel_vgpu_active(dev_priv)) {
> > -		DRM_INFO("iGVT-g active, disabling use of stolen memory\n");
> > +	if (dev_priv->run_on_qemu || intel_vgpu_active(dev_priv)) {
> > +		DRM_INFO("Running in guest, disabling use of stolen memory\n");
> >  		return 0;
> >  	}
> >  
> > -- 
> 
> Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>

Entirely disabling stolen is rather massive, this stuff is supposed to
work ... There should be special RMRR mappings in the iommu to help the
guest access the stolen range correctly from the gpu.

Which machine where does this blow up on?
-Daniel
Zhang, Xiong Y March 28, 2017, 1:28 a.m. UTC | #3
> > Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
> 
> Entirely disabling stolen is rather massive, this stuff is supposed to
> work ... There should be special RMRR mappings in the iommu to help the
> guest access the stolen range correctly from the gpu.
> 
> Which machine where does this blow up on?
> -Daniel
[Zhang, Xiong Y] Yes. Stolen memory is protected by RMRR on host. But Qemu couldn't support and don't have plan to support RMRR. Then EPT lack of mapping for stolen memory, guest couldn't access it.
The Qemu/Vfio is designed by Redhat engineers, Redhat has a white paper to explain why Qemu don't support RMRR:
https://access.redhat.com/sites/default/files/attachments/rmrr-wp1.pdf

> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
Daniel Vetter March 29, 2017, 11:58 a.m. UTC | #4
On Tue, Mar 28, 2017 at 01:28:43AM +0000, Zhang, Xiong Y wrote:
> > > Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
> > 
> > Entirely disabling stolen is rather massive, this stuff is supposed to
> > work ... There should be special RMRR mappings in the iommu to help the
> > guest access the stolen range correctly from the gpu.
> > 
> > Which machine where does this blow up on?
> > -Daniel
> [Zhang, Xiong Y] Yes. Stolen memory is protected by RMRR on host. But Qemu couldn't support and don't have plan to support RMRR. Then EPT lack of mapping for stolen memory, guest couldn't access it.
> The Qemu/Vfio is designed by Redhat engineers, Redhat has a white paper to explain why Qemu don't support RMRR:
> https://access.redhat.com/sites/default/files/attachments/rmrr-wp1.pdf

I chatted with Joonas, and he dug out the commit that changed this:

commit c875d2c1b8083cd627ea0463e20bf22c2d7421ee
Author: Alex Williamson <alex.williamson@redhat.com>
Date:   Thu Jul 3 09:57:02 2014 -0600

    iommu/vt-d: Exclude devices using RMRRs from IOMMU API domains
    
    The user of the IOMMU API domain expects to have full control of
    the IOVA space for the domain.  RMRRs are fundamentally incompatible
    with that idea.  We can neither map the RMRR into the IOMMU API
    domain, nor can we guarantee that the device won't continue DMA with
    the area described by the RMRR as part of the new domain.  Therefore
    we must prevent such devices from being used by the IOMMU API.
    
    Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
    Cc: David Woodhouse <dwmw2@infradead.org>
    Cc: stable@vger.kernel.org
    Signed-off-by: Joerg Roedel <jroedel@suse.de>

Please reference that commit (plus the whitepaper if you want to) in your
commit message, and resubmit it with a Fixes: and cc: stable lines. This
sounds like a bugfix that we need to backport.

Thanks, Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 03d9e45..8b807a9 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -223,6 +223,7 @@  static void intel_detect_pch(struct drm_i915_private *dev_priv)
 					    PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
 				    pch->subsystem_device ==
 					    PCI_SUBDEVICE_ID_QEMU)) {
+				dev_priv->run_on_qemu = true;
 				dev_priv->pch_type =
 					intel_virt_detect_pch(dev_priv);
 			} else
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a5947a4..ad95c87 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2145,6 +2145,7 @@  struct drm_i915_private {
 	struct intel_uncore uncore;
 
 	struct i915_virtual_gpu vgpu;
+	bool run_on_qemu;
 
 	struct intel_gvt *gvt;
 
diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
index f3abdc2..6a011b0 100644
--- a/drivers/gpu/drm/i915/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
@@ -409,8 +409,8 @@  int i915_gem_init_stolen(struct drm_i915_private *dev_priv)
 
 	mutex_init(&dev_priv->mm.stolen_lock);
 
-	if (intel_vgpu_active(dev_priv)) {
-		DRM_INFO("iGVT-g active, disabling use of stolen memory\n");
+	if (dev_priv->run_on_qemu || intel_vgpu_active(dev_priv)) {
+		DRM_INFO("Running in guest, disabling use of stolen memory\n");
 		return 0;
 	}