Skip to content

Commit e048834

Browse files
Mohammed Gamaldeepak-rawat
authored andcommitted
drm/hyperv: Fix device removal on Gen1 VMs
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: 76c56a5 ("drm/hyperv: Add DRM driver for hyperv synthetic video device") Signed-off-by: Mohammed Gamal <mgamal@redhat.com> Reviewed-by: Deepak Rawat <drawat.floss@gmail.com> Signed-off-by: Deepak Rawat <drawat.floss@gmail.com> Link: https://patchwork.freedesktop.org/patch/msgid/20211119112900.300537-1-mgamal@redhat.com
1 parent b4a6aae commit e048834

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎drivers/gpu/drm/hyperv/hyperv_drm_drv.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,29 @@ static int hyperv_vmbus_remove(struct hv_device *hdev)
225225
{
226226
struct drm_device *dev = hv_get_drvdata(hdev);
227227
struct hyperv_drm_device *hv = to_hv(dev);
228+
struct pci_dev *pdev;
228229

229230
drm_dev_unplug(dev);
230231
drm_atomic_helper_shutdown(dev);
231232
vmbus_close(hdev->channel);
232233
hv_set_drvdata(hdev, NULL);
233-
vmbus_free_mmio(hv->mem->start, hv->fb_size);
234+
235+
/*
236+
* Free allocated MMIO memory only on Gen2 VMs.
237+
* On Gen1 VMs, release the PCI device
238+
*/
239+
if (efi_enabled(EFI_BOOT)) {
240+
vmbus_free_mmio(hv->mem->start, hv->fb_size);
241+
} else {
242+
pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT,
243+
PCI_DEVICE_ID_HYPERV_VIDEO, NULL);
244+
if (!pdev) {
245+
drm_err(dev, "Unable to find PCI Hyper-V video\n");
246+
return -ENODEV;
247+
}
248+
pci_release_region(pdev, 0);
249+
pci_dev_put(pdev);
250+
}
234251

235252
return 0;
236253
}

0 commit comments

Comments
 (0)