Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 76c56a5affeb ("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

authored by

Mohammed Gamal and committed by
Deepak Rawat
e048834c b4a6aaea

+18 -1
+18 -1
drivers/gpu/drm/hyperv/hyperv_drm_drv.c
··· 225 225 { 226 226 struct drm_device *dev = hv_get_drvdata(hdev); 227 227 struct hyperv_drm_device *hv = to_hv(dev); 228 + struct pci_dev *pdev; 228 229 229 230 drm_dev_unplug(dev); 230 231 drm_atomic_helper_shutdown(dev); 231 232 vmbus_close(hdev->channel); 232 233 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 + } 234 251 235 252 return 0; 236 253 }