linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/hyperv: Fix device removal on Gen1 VMs
@ 2021-11-19 11:29 Mohammed Gamal
  2021-11-20  0:42 ` Deepak Rawat
  0 siblings, 1 reply; 2+ messages in thread
From: Mohammed Gamal @ 2021-11-19 11:29 UTC (permalink / raw)
  To: linux-hyperv, dri-devel, decui, drawat.floss
  Cc: linux-kernel, daniel, airlied, Mohammed Gamal

The Hyper-V DRM driver tries to free MMIO region on removing
the device regardless of VM type, while Gen1 VMs don't use MMIO
and hence causing the kernel to crash on a NULL pointer dereference.

Fix this by making deallocating MMIO only on Gen2 machines and implement
removal for Gen1

Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic video device")

Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
---
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c b/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
index cd818a629183..9f923beb7d8d 100644
--- a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
+++ b/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
@@ -225,12 +225,29 @@ static int hyperv_vmbus_remove(struct hv_device *hdev)
 {
 	struct drm_device *dev = hv_get_drvdata(hdev);
 	struct hyperv_drm_device *hv = to_hv(dev);
+	struct pci_dev *pdev;
 
 	drm_dev_unplug(dev);
 	drm_atomic_helper_shutdown(dev);
 	vmbus_close(hdev->channel);
 	hv_set_drvdata(hdev, NULL);
-	vmbus_free_mmio(hv->mem->start, hv->fb_size);
+
+	/*
+	 * Free allocated MMIO memory only on Gen2 VMs.
+	 * On Gen1 VMs, release the PCI device
+	 */
+	if (efi_enabled(EFI_BOOT)) {
+		vmbus_free_mmio(hv->mem->start, hv->fb_size);
+	} else {
+		pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
+				PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
+		if (!pdev) {
+			drm_err(dev, "Unable to find PCI Hyper-V video\n");
+			return -ENODEV;
+		}
+		pci_release_region(pdev, 0);
+		pci_dev_put(pdev);
+	}
 
 	return 0;
 }
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/hyperv: Fix device removal on Gen1 VMs
  2021-11-19 11:29 [PATCH] drm/hyperv: Fix device removal on Gen1 VMs Mohammed Gamal
@ 2021-11-20  0:42 ` Deepak Rawat
  0 siblings, 0 replies; 2+ messages in thread
From: Deepak Rawat @ 2021-11-20  0:42 UTC (permalink / raw)
  To: Mohammed Gamal, linux-hyperv, dri-devel, decui
  Cc: linux-kernel, daniel, airlied

Thanks for the patch.

Reviewed-by: Deepak Rawat <drawat.floss@gmail.com>

I will push this to drm-fixes, let me know otherwise.

Deepak

On Fri, 2021-11-19 at 12:29 +0100, Mohammed Gamal wrote:
> The Hyper-V DRM driver tries to free MMIO region on removing
> the device regardless of VM type, while Gen1 VMs don't use MMIO
> and hence causing the kernel to crash on a NULL pointer dereference.
> 
> Fix this by making deallocating MMIO only on Gen2 machines and
> implement
> removal for Gen1
> 
> Fixes: 76c56a5affeb ("drm/hyperv: Add DRM driver for hyperv synthetic
> video device")
> 
> Signed-off-by: Mohammed Gamal <mgamal@redhat.com>
> ---
>  drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
> b/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
> index cd818a629183..9f923beb7d8d 100644
> --- a/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
> +++ b/drivers/gpu/drm/hyperv/hyperv_drm_drv.c
> @@ -225,12 +225,29 @@ static int hyperv_vmbus_remove(struct hv_device
> *hdev)
>  {
>         struct drm_device *dev = hv_get_drvdata(hdev);
>         struct hyperv_drm_device *hv = to_hv(dev);
> +       struct pci_dev *pdev;
>  
>         drm_dev_unplug(dev);
>         drm_atomic_helper_shutdown(dev);
>         vmbus_close(hdev->channel);
>         hv_set_drvdata(hdev, NULL);
> -       vmbus_free_mmio(hv->mem->start, hv->fb_size);
> +
> +       /*
> +        * Free allocated MMIO memory only on Gen2 VMs.
> +        * On Gen1 VMs, release the PCI device
> +        */
> +       if (efi_enabled(EFI_BOOT)) {
> +               vmbus_free_mmio(hv->mem->start, hv->fb_size);
> +       } else {
> +               pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
> +                               PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
> +               if (!pdev) {
> +                       drm_err(dev, "Unable to find PCI Hyper-V
> video\n");
> +                       return -ENODEV;
> +               }
> +               pci_release_region(pdev, 0);
> +               pci_dev_put(pdev);
> +       }
>  
>         return 0;
>  }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-20  0:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19 11:29 [PATCH] drm/hyperv: Fix device removal on Gen1 VMs Mohammed Gamal
2021-11-20  0:42 ` Deepak Rawat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).