drm/hyperv: Don't rely on screen_info.lfb_base for Gen1 VMs
Subsystems (5)
Saurabh Sengar
maintainerPATCH 1/1 drm/hyperv: Don't rely on screen_info.lfb_base for Gen1 VMs
hyperv_setup_vram tries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such cases drm_aperture_remove_conflicting_framebuffers will not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.
--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +20 -4
@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) { +drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, + screen_info.lfb_size, + false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;
Signature · 1 line
2.34.1
From: Saurabh Sengar <[email protected]> Sent: Friday, September 9, 2022 7:44 AM
Quoted 54 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +20
-5@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) { +drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, + screen_info.lfb_size, + false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ; --
Quoted 1 line
2.34.1
Thomas Zimmermann
maintainerHi
Am 09.09.22 um 16:43 schrieb Saurabh Sengar:
Quoted 22 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +0
-0@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev;
drivers/gpu/drm/hyperv/hyperv_drm_drv.c static int hyperv_setup_vram(struct hyperv_drm_device *hv, · line 81
Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +4
-4+struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) { + drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base, + screen_info.lfb_size,
Using screen_info here seems wrong in any case. You want to remove the framebuffer devices that conflict with your driver, which might be unrelated to screen_info. AFAICT the correct solution would always retrieve the PCI device for removal (i.e., always do the else branch).
Best regard
Thomas
Quoted 19 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +16
-0+ false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Saurabh Singh Sengar
maintainerQuoted 32 lines · Thomas Zimmermann
Hi
Am 09.09.22 um 16:43 schrieb Saurabh Sengar:
Quoted 29 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-4@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) {
Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c static int hyperv_setup_vram(struct hyperv_drm_device *hv, · line 81
Quoted 2 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-0+ drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base, + screen_info.lfb_size,Using
screen_infohere seems wrong in any case. You want to remove the framebuffer devices that conflict with your driver, which might be unrelated toscreen_info. AFAICT the correct solution would always retrieve the PCI device for removal (i.e., always do the else branch).
In a Gen2 VM, the Hyper-V frame buffer device is presented only as a VMbus device. It's not presented as a PCI device like it is in a Gen1 VM. This would have worked if we had the frame buffer device available as PCI device in Gen2 but unfortunately thats not the case here.
Regards,
Saurabh
Quoted 29 lines
Best regard
ThomasQuoted 17 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +16
-0+ false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerHi
Am 11.09.22 um 18:21 schrieb Saurabh Singh Sengar:
Quoted 42 lines · Thomas Zimmermann
Quoted 32 lines
Hi
Am 09.09.22 um 16:43 schrieb Saurabh Sengar:
Quoted 29 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-4@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) {Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c static int hyperv_setup_vram(struct hyperv_drm_device *hv, · line 81
Quoted 2 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-0+ drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base, + screen_info.lfb_size,Using
screen_infohere seems wrong in any case. You want to remove the framebuffer devices that conflict with your driver, which might be unrelated toscreen_info. AFAICT the correct solution would always retrieve the PCI device for removal (i.e., always do the else branch).
Quoted 4 lines
In a Gen2 VM, the Hyper-V frame buffer device is presented only as a VMbus device. It's not presented as a PCI device like it is in a Gen1 VM. This would have worked if we had the frame buffer device available as PCI device in Gen2 but unfortunately thats not the case here.
Thanks for explaining. There is an instance of struct hv_device passed to the probe function. I suspect you cannot get the framebuffer range from this instance (e.g., via the device's platform_data)?
If you absolutely can't get the actual memory region from the device, it's better to remove all framebuffers via drm_aperture_remove_framebuffers() than to use screen_info.
Best regards
Thomas
Quoted 36 lines
Regards,
SaurabhQuoted 29 lines
Best regard
ThomasQuoted 17 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +16
-0+ false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Saurabh Singh Sengar
maintainerQuoted 55 lines · Thomas Zimmermann
Hi
Am 11.09.22 um 18:21 schrieb Saurabh Singh Sengar:
Quoted 42 lines · Thomas Zimmermann
Quoted 32 lines
Hi
Am 09.09.22 um 16:43 schrieb Saurabh Sengar:
Quoted 29 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-4@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) {Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c static int hyperv_setup_vram(struct hyperv_drm_device *hv, · line 81
Quoted 2 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-0+ drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base, + screen_info.lfb_size,Using
screen_infohere seems wrong in any case. You want to remove the framebuffer devices that conflict with your driver, which might be unrelated toscreen_info. AFAICT the correct solution would always retrieve the PCI device for removal (i.e., always do the else branch).Quoted 4 lines
In a Gen2 VM, the Hyper-V frame buffer device is presented only as a VMbus device. It's not presented as a PCI device like it is in a Gen1 VM. This would have worked if we had the frame buffer device available as PCI device in Gen2 but unfortunately thats not the case here.
Thanks for explaining. There is an instance of struct
hv_devicepassed to the probe function. I suspect you cannot get the framebuffer range from this instance (e.g., via the device'splatform_data)?
Quoted 6 lines
If you absolutely can't get the actual memory region from the device, it's better to remove all framebuffers via
drm_aperture_remove_framebuffers()than to usescreen_info.Best regards
Thomas
Thanks for your suggestion, and I thought of using drm_aperture_remove_framebuffers here, but this driver will be used in many different systems with many other graphics devices (GPU etc). Removing all the framebuffer is a bit blunt approach which may disturb the devices we are not intended to and which are even outside of the HyperV MMIO region. I feel this API use will be risky, and I would like to stick to the earlier method which is proven to be working for many years and we are sure it won't disturb anyone outside MMIO region.
Regards,
Saurabh
Quoted 45 lines
Quoted 37 lines
Regards,
SaurabhQuoted 29 lines
Best regard
ThomasQuoted 17 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +16
-0+ false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo TotevSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Thomas Zimmermann
maintainerHi
Am 13.09.22 um 17:15 schrieb Saurabh Singh Sengar:
Quoted 63 lines · Thomas Zimmermann
Quoted 55 lines
Hi
Am 11.09.22 um 18:21 schrieb Saurabh Singh Sengar:
Quoted 42 lines · Thomas Zimmermann
Quoted 32 lines
Hi
Am 09.09.22 um 16:43 schrieb Saurabh Sengar:
Quoted 29 lines
hyperv_setup_vramtries to remove conflicting framebuffer based on 'screen_info'. As observed in past due to some bug or wrong setting in grub, the 'screen_info' fields may not be set for Gen1, and in such casesdrm_aperture_remove_conflicting_framebufferswill not do anything useful.
For Gen1 VMs, it should always be possible to get framebuffer conflict removed using PCI device instead.Fixes a0ab5abced55 ("drm/hyperv : Removing the restruction of VRAM allocation with PCI bar size")Signed-off-by Saurabh Sengar <[email protected]>--- drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-4@@ -73,12 +73,28 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv, struct hv_device *hdev) {struct drm_device *dev = &hv->dev; +struct pci_dev *pdev;int ret; -drm_aperture_remove_conflicting_framebuffers (screen_info.lfb_base, - screen_info.lfb_size, - false, - &hyperv_driver); +if (efi_enabled (EFI_BOOT )) {Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c static int hyperv_setup_vram(struct hyperv_drm_device *hv, · line 81
Quoted 2 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2
-0+ drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base, + screen_info.lfb_size,Using
screen_infohere seems wrong in any case. You want to remove the framebuffer devices that conflict with your driver, which might be unrelated toscreen_info. AFAICT the correct solution would always retrieve the PCI device for removal (i.e., always do the else branch).Quoted 4 lines
In a Gen2 VM, the Hyper-V frame buffer device is presented only as a VMbus device. It's not presented as a PCI device like it is in a Gen1 VM. This would have worked if we had the frame buffer device available as PCI device in Gen2 but unfortunately thats not the case here.
Thanks for explaining. There is an instance of struct
hv_devicepassed to the probe function. I suspect you cannot get the framebuffer range from this instance (e.g., via the device'splatform_data)?Quoted 6 lines
If you absolutely can't get the actual memory region from the device, it's better to remove all framebuffers via
drm_aperture_remove_framebuffers()than to usescreen_info.Best regards
Thomas
Quoted 7 lines
Thanks for your suggestion, and I thought of using
drm_aperture_remove_framebuffershere, but this driver will be used in many different systems with many other graphics devices (GPU etc). Removing all the framebuffer is a bit blunt approach which may disturb the devices we are not intended to and which are even outside of the HyperV MMIO region. I feel this API use will be risky, and I would like to stick to the earlier method which is proven to be working for many years and we are sure it won't disturb anyone outside MMIO region.
But the problem with the current code is that you also remove the driver that covers the boot-up graphics, even if it's not even a hyperv device. That's why I said that you should try to detect if the hyperv device you're creating actually uses the screen_info when you create the device.
Set that information as device data and look it up in the hyperv-drm driver. If no such screen_info data is attached to the device, you don't have to remove conflicting framebuffers at all.
Best regards
Thomas
Quoted 51 lines
Regards,
SaurabhQuoted 45 lines
Quoted 37 lines
Regards,
SaurabhQuoted 29 lines
Best regard
ThomasQuoted 17 lines
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +16
-0+ false, + &hyperv_driver); + }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 ; + } + + ret =drm_aperture_remove_conflicting_pci_framebuffers (pdev, &hyperv_driver); +pci_dev_put (pdev); +if (ret) { +drm_err (dev,"Not able to remove boot fb\n" ); +return ret; + } + } hv->fb_size = (unsigned long )hv->mmio_megabytes *1024 *1024 ;Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo TotevSignature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev