diff mbox series

drm/i915: Force VT'd workarounds when running as a guest OS

Message ID 20201019101523.4145-1-chris@chris-wilson.co.uk
State Accepted
Commit f566fdcd6cc49a9d5b5d782f56e3e7cb243f01b8
Headers show
Series drm/i915: Force VT'd workarounds when running as a guest OS | expand

Commit Message

Chris Wilson Oct. 19, 2020, 10:15 a.m. UTC
If i915.ko is being used as a passthrough device, it does not know if
the host is using intel_iommu. Mixing the iommu and gfx causing a few
issues (such as scanout overfetch) which we need to workaround inside
the driver, so if we detect we are running under a hypervisor, also
assume the device access is being virtualised.

Reported-by: Stefan Fritsch <sf@sfritsch.de>
Suggested-by: Stefan Fritsch <sf@sfritsch.de>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Stefan Fritsch <sf@sfritsch.de>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/i915/i915_drv.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Stefan Fritsch Oct. 19, 2020, 1:08 p.m. UTC | #1
Works for me and makes the fault messages disappear. Thanks.

Tested-by: Stefan Fritsch <sf@sfritsch.de>



On Mon, 19 Oct 2020, Chris Wilson wrote:

> If i915.ko is being used as a passthrough device, it does not know if

> the host is using intel_iommu. Mixing the iommu and gfx causing a few

> issues (such as scanout overfetch) which we need to workaround inside

> the driver, so if we detect we are running under a hypervisor, also

> assume the device access is being virtualised.

> 

> Reported-by: Stefan Fritsch <sf@sfritsch.de>

> Suggested-by: Stefan Fritsch <sf@sfritsch.de>

> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>

> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

> Cc: Stefan Fritsch <sf@sfritsch.de>

> Cc: stable@vger.kernel.org

> ---

>  drivers/gpu/drm/i915/i915_drv.h | 6 +++++-

>  1 file changed, 5 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h

> index 1a5729932c81..bcd8650603d8 100644

> --- a/drivers/gpu/drm/i915/i915_drv.h

> +++ b/drivers/gpu/drm/i915/i915_drv.h

> @@ -33,6 +33,8 @@

>  #include <uapi/drm/i915_drm.h>

>  #include <uapi/drm/drm_fourcc.h>

>  

> +#include <asm/hypervisor.h>

> +

>  #include <linux/io-mapping.h>

>  #include <linux/i2c.h>

>  #include <linux/i2c-algo-bit.h>

> @@ -1760,7 +1762,9 @@ static inline bool intel_vtd_active(void)

>  	if (intel_iommu_gfx_mapped)

>  		return true;

>  #endif

> -	return false;

> +

> +	/* Running as a guest, we assume the host is enforcing VT'd */

> +	return !hypervisor_is_type(X86_HYPER_NATIVE);

>  }

>  

>  static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)

>
Zhenyu Wang Oct. 20, 2020, 3:05 a.m. UTC | #2
On 2020.10.19 11:15:23 +0100, Chris Wilson wrote:
> If i915.ko is being used as a passthrough device, it does not know if
> the host is using intel_iommu. Mixing the iommu and gfx causing a few
> issues (such as scanout overfetch) which we need to workaround inside
> the driver, so if we detect we are running under a hypervisor, also
> assume the device access is being virtualised.
> 
> Reported-by: Stefan Fritsch <sf@sfritsch.de>
> Suggested-by: Stefan Fritsch <sf@sfritsch.de>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Stefan Fritsch <sf@sfritsch.de>
> Cc: stable@vger.kernel.org
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 1a5729932c81..bcd8650603d8 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -33,6 +33,8 @@
>  #include <uapi/drm/i915_drm.h>
>  #include <uapi/drm/drm_fourcc.h>
>  
> +#include <asm/hypervisor.h>
> +
>  #include <linux/io-mapping.h>
>  #include <linux/i2c.h>
>  #include <linux/i2c-algo-bit.h>
> @@ -1760,7 +1762,9 @@ static inline bool intel_vtd_active(void)
>  	if (intel_iommu_gfx_mapped)
>  		return true;
>  #endif
> -	return false;
> +
> +	/* Running as a guest, we assume the host is enforcing VT'd */
> +	return !hypervisor_is_type(X86_HYPER_NATIVE);
>  }
>  
>  static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
> -- 

Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Chris Wilson Oct. 20, 2020, 10:25 a.m. UTC | #3
Quoting Stefan Fritsch (2020-10-19 14:08:17)
> Works for me and makes the fault messages disappear. Thanks.

> 

> Tested-by: Stefan Fritsch <sf@sfritsch.de>


Thanks for the report and testing. In hindsight, this should have been
obvious.

Pushed,
-Chris
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 1a5729932c81..bcd8650603d8 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -33,6 +33,8 @@ 
 #include <uapi/drm/i915_drm.h>
 #include <uapi/drm/drm_fourcc.h>
 
+#include <asm/hypervisor.h>
+
 #include <linux/io-mapping.h>
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
@@ -1760,7 +1762,9 @@  static inline bool intel_vtd_active(void)
 	if (intel_iommu_gfx_mapped)
 		return true;
 #endif
-	return false;
+
+	/* Running as a guest, we assume the host is enforcing VT'd */
+	return !hypervisor_is_type(X86_HYPER_NATIVE);
 }
 
 static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)