diff mbox series

[2/3] drm/vmwgfx: Print errors when running on broken/unsupported configs

Message ID 20230321020949.335012-2-zack@kde.org (mailing list archive)
State New, archived
Headers show
Series [1/3] drm/vmwgfx: Drop mksstat_init_record fn as currently unused | expand

Commit Message

Zack Rusin March 21, 2023, 2:09 a.m. UTC
From: Zack Rusin <zackr@vmware.com>

virtualbox implemented an incomplete version of the svga device which
they decided to drop soon after the initial release. The device was
always broken in various ways and never supported by vmwgfx.

vmwgfx should refuse to load on those configurations but currently
drm has no way of reloading fbdev when the specific pci driver refuses
to load, which would leave users without a usable fb. Instead of
refusing to load print an error and disable a bunch of functionality
that virtualbox never implemented to at least get fb to work on their
setup.

Signed-off-by: Zack Rusin <zackr@vmware.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 29 +++++++++++++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  2 ++
 drivers/gpu/drm/vmwgfx/vmwgfx_msg.c |  9 +++++++++
 3 files changed, 40 insertions(+)

Comments

Martin Krastev (VMware) March 21, 2023, 12:56 p.m. UTC | #1
From: Martin Krastev <krastevm@vmware.com>


LGTM!

Reviewed-by: Martin Krastev <krastevm@vmware.com>


Regards,

Martin


On 21.03.23 г. 4:09 ч., Zack Rusin wrote:
> From: Zack Rusin <zackr@vmware.com>
>
> virtualbox implemented an incomplete version of the svga device which
> they decided to drop soon after the initial release. The device was
> always broken in various ways and never supported by vmwgfx.
>
> vmwgfx should refuse to load on those configurations but currently
> drm has no way of reloading fbdev when the specific pci driver refuses
> to load, which would leave users without a usable fb. Instead of
> refusing to load print an error and disable a bunch of functionality
> that virtualbox never implemented to at least get fb to work on their
> setup.
>
> Signed-off-by: Zack Rusin <zackr@vmware.com>
> ---
>   drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 29 +++++++++++++++++++++++++++++
>   drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  2 ++
>   drivers/gpu/drm/vmwgfx/vmwgfx_msg.c |  9 +++++++++
>   3 files changed, 40 insertions(+)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 2588615a2a38..8b24ecf60e3e 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -45,6 +45,9 @@
>   #include <drm/ttm/ttm_placement.h>
>   #include <generated/utsrelease.h>
>   
> +#ifdef CONFIG_X86
> +#include <asm/hypervisor.h>
> +#endif
>   #include <linux/cc_platform.h>
>   #include <linux/dma-mapping.h>
>   #include <linux/module.h>
> @@ -897,6 +900,16 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
>   				 cap2_names, ARRAY_SIZE(cap2_names));
>   	}
>   
> +	if (!vmwgfx_supported(dev_priv)) {
> +		vmw_disable_backdoor();
> +		drm_err_once(&dev_priv->drm,
> +			     "vmwgfx seems to be running on an unsupported hypervisor.");
> +		drm_err_once(&dev_priv->drm,
> +			     "This configuration is likely broken.");
> +		drm_err_once(&dev_priv->drm,
> +			     "Please switch to a supported graphics device to avoid problems.");
> +	}
> +
>   	ret = vmw_dma_select_mode(dev_priv);
>   	if (unlikely(ret != 0)) {
>   		drm_info(&dev_priv->drm,
> @@ -1320,6 +1333,22 @@ static void vmw_master_drop(struct drm_device *dev,
>   	vmw_kms_legacy_hotspot_clear(dev_priv);
>   }
>   
> +bool vmwgfx_supported(struct vmw_private *vmw)
> +{
> +#if defined(CONFIG_X86)
> +	return hypervisor_is_type(X86_HYPER_VMWARE);
> +#elif defined(CONFIG_ARM64)
> +	/*
> +	 * On aarch64 only svga3 is supported
> +	 */
> +	return vmw->pci_id == VMWGFX_PCI_ID_SVGA3;
> +#else
> +	drm_warn_once(&vmw->drm,
> +		      "vmwgfx is running on an unknown architecture.");
> +	return false;
> +#endif
> +}
> +
>   /**
>    * __vmw_svga_enable - Enable SVGA mode, FIFO and use of VRAM.
>    *
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> index fb8f0c0642c0..3810a9984a7f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> @@ -773,6 +773,7 @@ static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
>   
>   extern void vmw_svga_enable(struct vmw_private *dev_priv);
>   extern void vmw_svga_disable(struct vmw_private *dev_priv);
> +bool vmwgfx_supported(struct vmw_private *vmw);
>   
>   
>   /**
> @@ -1358,6 +1359,7 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
>   		    struct vmw_diff_cpy *diff);
>   
>   /* Host messaging -vmwgfx_msg.c: */
> +void vmw_disable_backdoor(void);
>   int vmw_host_get_guestinfo(const char *guest_info_param,
>   			   char *buffer, size_t *length);
>   __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> index ca1a3fe44fa5..2651fe0ef518 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> @@ -1179,3 +1179,12 @@ int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
>   
>   	return -EAGAIN;
>   }
> +
> +/**
> + * vmw_disable_backdoor: Disables all backdoor communication
> + * with the hypervisor.
> + */
> +void vmw_disable_backdoor(void)
> +{
> +	vmw_msg_enabled = 0;
> +}
Maaz Mombasawala (VMware) March 21, 2023, 7:54 p.m. UTC | #2
On 3/20/23 19:09, Zack Rusin wrote:
> From: Zack Rusin <zackr@vmware.com>
> 
> virtualbox implemented an incomplete version of the svga device which
> they decided to drop soon after the initial release. The device was
> always broken in various ways and never supported by vmwgfx.
> 
> vmwgfx should refuse to load on those configurations but currently
> drm has no way of reloading fbdev when the specific pci driver refuses
> to load, which would leave users without a usable fb. Instead of
> refusing to load print an error and disable a bunch of functionality
> that virtualbox never implemented to at least get fb to work on their
> setup.
> 
> Signed-off-by: Zack Rusin <zackr@vmware.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 29 +++++++++++++++++++++++++++++
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  2 ++
>  drivers/gpu/drm/vmwgfx/vmwgfx_msg.c |  9 +++++++++
>  3 files changed, 40 insertions(+)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 2588615a2a38..8b24ecf60e3e 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -45,6 +45,9 @@
>  #include <drm/ttm/ttm_placement.h>
>  #include <generated/utsrelease.h>
>  
> +#ifdef CONFIG_X86
> +#include <asm/hypervisor.h>
> +#endif
>  #include <linux/cc_platform.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/module.h>
> @@ -897,6 +900,16 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
>  				 cap2_names, ARRAY_SIZE(cap2_names));
>  	}
>  
> +	if (!vmwgfx_supported(dev_priv)) {
> +		vmw_disable_backdoor();
> +		drm_err_once(&dev_priv->drm,
> +			     "vmwgfx seems to be running on an unsupported hypervisor.");
> +		drm_err_once(&dev_priv->drm,
> +			     "This configuration is likely broken.");
> +		drm_err_once(&dev_priv->drm,
> +			     "Please switch to a supported graphics device to avoid problems.");
> +	}
> +
>  	ret = vmw_dma_select_mode(dev_priv);
>  	if (unlikely(ret != 0)) {
>  		drm_info(&dev_priv->drm,
> @@ -1320,6 +1333,22 @@ static void vmw_master_drop(struct drm_device *dev,
>  	vmw_kms_legacy_hotspot_clear(dev_priv);
>  }
>  
> +bool vmwgfx_supported(struct vmw_private *vmw)
> +{
> +#if defined(CONFIG_X86)
> +	return hypervisor_is_type(X86_HYPER_VMWARE);
> +#elif defined(CONFIG_ARM64)
> +	/*
> +	 * On aarch64 only svga3 is supported
> +	 */
> +	return vmw->pci_id == VMWGFX_PCI_ID_SVGA3;
> +#else
> +	drm_warn_once(&vmw->drm,
> +		      "vmwgfx is running on an unknown architecture.");
> +	return false;
> +#endif
> +}
> +
>  /**
>   * __vmw_svga_enable - Enable SVGA mode, FIFO and use of VRAM.
>   *
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> index fb8f0c0642c0..3810a9984a7f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
> @@ -773,6 +773,7 @@ static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
>  
>  extern void vmw_svga_enable(struct vmw_private *dev_priv);
>  extern void vmw_svga_disable(struct vmw_private *dev_priv);
> +bool vmwgfx_supported(struct vmw_private *vmw);
>  
>  
>  /**
> @@ -1358,6 +1359,7 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
>  		    struct vmw_diff_cpy *diff);
>  
>  /* Host messaging -vmwgfx_msg.c: */
> +void vmw_disable_backdoor(void);
>  int vmw_host_get_guestinfo(const char *guest_info_param,
>  			   char *buffer, size_t *length);
>  __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> index ca1a3fe44fa5..2651fe0ef518 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
> @@ -1179,3 +1179,12 @@ int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
>  
>  	return -EAGAIN;
>  }
> +
> +/**
> + * vmw_disable_backdoor: Disables all backdoor communication
> + * with the hypervisor.
> + */
> +void vmw_disable_backdoor(void)
> +{
> +	vmw_msg_enabled = 0;
> +}


LGTM

Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 2588615a2a38..8b24ecf60e3e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -45,6 +45,9 @@ 
 #include <drm/ttm/ttm_placement.h>
 #include <generated/utsrelease.h>
 
+#ifdef CONFIG_X86
+#include <asm/hypervisor.h>
+#endif
 #include <linux/cc_platform.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
@@ -897,6 +900,16 @@  static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
 				 cap2_names, ARRAY_SIZE(cap2_names));
 	}
 
+	if (!vmwgfx_supported(dev_priv)) {
+		vmw_disable_backdoor();
+		drm_err_once(&dev_priv->drm,
+			     "vmwgfx seems to be running on an unsupported hypervisor.");
+		drm_err_once(&dev_priv->drm,
+			     "This configuration is likely broken.");
+		drm_err_once(&dev_priv->drm,
+			     "Please switch to a supported graphics device to avoid problems.");
+	}
+
 	ret = vmw_dma_select_mode(dev_priv);
 	if (unlikely(ret != 0)) {
 		drm_info(&dev_priv->drm,
@@ -1320,6 +1333,22 @@  static void vmw_master_drop(struct drm_device *dev,
 	vmw_kms_legacy_hotspot_clear(dev_priv);
 }
 
+bool vmwgfx_supported(struct vmw_private *vmw)
+{
+#if defined(CONFIG_X86)
+	return hypervisor_is_type(X86_HYPER_VMWARE);
+#elif defined(CONFIG_ARM64)
+	/*
+	 * On aarch64 only svga3 is supported
+	 */
+	return vmw->pci_id == VMWGFX_PCI_ID_SVGA3;
+#else
+	drm_warn_once(&vmw->drm,
+		      "vmwgfx is running on an unknown architecture.");
+	return false;
+#endif
+}
+
 /**
  * __vmw_svga_enable - Enable SVGA mode, FIFO and use of VRAM.
  *
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index fb8f0c0642c0..3810a9984a7f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -773,6 +773,7 @@  static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
 
 extern void vmw_svga_enable(struct vmw_private *dev_priv);
 extern void vmw_svga_disable(struct vmw_private *dev_priv);
+bool vmwgfx_supported(struct vmw_private *vmw);
 
 
 /**
@@ -1358,6 +1359,7 @@  int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
 		    struct vmw_diff_cpy *diff);
 
 /* Host messaging -vmwgfx_msg.c: */
+void vmw_disable_backdoor(void);
 int vmw_host_get_guestinfo(const char *guest_info_param,
 			   char *buffer, size_t *length);
 __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
index ca1a3fe44fa5..2651fe0ef518 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c
@@ -1179,3 +1179,12 @@  int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
 
 	return -EAGAIN;
 }
+
+/**
+ * vmw_disable_backdoor: Disables all backdoor communication
+ * with the hypervisor.
+ */
+void vmw_disable_backdoor(void)
+{
+	vmw_msg_enabled = 0;
+}