Skip to contentSkip to conversation

hyperv, sysfb: Do not use screen_info in drivers

PATCH In review Thomas Zimmermann 3 participants 10 messages Jan 3, 2024 – Jan 8, 2024

Subsystems (7)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover hyperv, sysfb: Do not use screen_info in drivers

The global screen_info state is only meant for architecture and firmware code. Replace its use in hyperv graphics drivers with the correct aperture helpers.

Patches 1 and 2 update hyperv-drm and hyperv-fb to use the correct aperture helpers instead of screen_info for removing existing firmware framebuffers.

Hyperv-fb also modifies screen_info for better use with kexec. While that update makes sense, it's not supposed to be done by the driver. Patch 3 adds similar code to sysfb and patch 4 removes the code from the driver.

An intented side effect of this patchset is that all systems now benefit from better kexec support. After rebooting with kexec, the kernel operated on stale settings on screen_info. Patch 3 fixes this and the kexec kernel will use screen_info in any meaningful way.

Thomas Zimmermann (4):
drm/hyperv: Remove firmware framebuffers with aperture helper fbdev/hyperv_fb: Remove firmware framebuffers with aperture helpers firmware/sysfb: Clear screen_info state after consuming it fbdev/hyperv_fb: Do not clear global screen_info

 drivers/firmware/sysfb.c                | 14 +++++++++++++-
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c |  8 ++------
 drivers/video/fbdev/hyperv_fb.c         | 20 +++++++-------------
 3 files changed, 22 insertions(+), 20 deletions(-)

base-commit: 25232eb8a9ac7fa0dac7e846a4bf7fba2b6db39a

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/4 drm/hyperv: Remove firmware framebuffers with aperture helper

Replace use of screen_info state with the correct interface from the aperture helpers. The state is only for architecture and firmware code. It is not guaranteed to contain valid data. Drivers are thus not allowed to use it.

For removing conflicting firmware framebuffers, there are aperture helpers. Hence replace screen_info with the correct function that will remove conflicting framebuffers for the hyperv-drm driver. Also move the call to the correct place within the driver.

---
 drivers/gpu/drm/hyperv/hyperv_drm_drv.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm_drv.c +2 -6
index d511d17c5bdf..cff85086f2d6 100644
@@ -7,7 +7,6 @@
 #include <linux/hyperv.h>
 #include <linux/module.h>
 #include <linux/pci.h>
-#include <linux/screen_info.h>
 
 #include <drm/drm_aperture.h>
 #include <drm/drm_atomic_helper.h>
@@ -73,11 +72,6 @@ static int hyperv_setup_vram(struct hyperv_drm_device *hv,
 	struct drm_device *dev = &hv->dev;
 	int ret;
 
-	if (IS_ENABLED(CONFIG_SYSFB))
-		drm_aperture_remove_conflicting_framebuffers(screen_info.lfb_base,
-							     screen_info.lfb_size,
-							     &hyperv_driver);
-
 	hv->fb_size = (unsigned long)hv->mmio_megabytes * 1024 * 1024;
 
 	ret = vmbus_allocate_mmio(&hv->mem, hdev, 0, -1, hv->fb_size, 0x100000,
@@ -130,6 +124,8 @@ static int hyperv_vmbus_probe(struct hv_device *hdev,
 		goto err_hv_set_drv_data;
 	}
 
+	drm_aperture_remove_framebuffers(&hyperv_driver);
+
 	ret = hyperv_setup_vram(hv, hdev);
 	if (ret)
 		goto err_vmbus_close;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] drm/hyperv: Remove firmware framebuffers with aperture helper

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 5 lines

Replace use of screen_info state with the correct interface from the aperture helpers. The state is only for architecture and firmware code. It is not guaranteed to contain valid data. Drivers are thus not allowed to use it.

Quoted 7 lines

For removing conflicting firmware framebuffers, there are aperture helpers. Hence replace screen_info with the correct function that will remove conflicting framebuffers for the hyperv-drm driver. Also move the call to the correct place within the driver.

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
maintainer
#3 lore raw

Re: [PATCH 1/4] drm/hyperv: Remove firmware framebuffers with aperture helper

Quoted 14 lines · Javier Martinez Canillas

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 10 lines

Replace use of screen_info state with the correct interface from the aperture helpers. The state is only for architecture and firmware code. It is not guaranteed to contain valid data. Drivers are thus not allowed to use it.

For removing conflicting firmware framebuffers, there are aperture helpers. Hence replace screen_info with the correct function that will remove conflicting framebuffers for the hyperv-drm driver. Also move the call to the correct place within the driver.

Quoted 4 lines
Quoted 2 lines

---

Series applied to fbdev git tree.

Thanks,
Helge

author maintainer
#4 lore raw

PATCH 2/4 fbdev/hyperv_fb: Remove firmware framebuffers with aperture helpers

In reply to Thomas Zimmermann

Replace use of screen_info state with the correct interfaces from the aperture helpers. The state is only for architecture and firmware code. It is not guaranteed to contain valid data. Drivers are thus not allowed to use it.

For removing conflicting firmware framebuffers, there are aperture helpers. Hence replace screen_info with the correct functions that will remove conflicting framebuffers for the hypervfb driver. For GEN1 PCI devices, the driver reads the framebuffer base and size from the PCI BAR, and uses the range for removing the firmware framebuffer. For GEN2 VMBUS devices no range can be detected, so the driver clears all firmware framebuffers.

---
 drivers/video/fbdev/hyperv_fb.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/video/fbdev/hyperv_fb.c +6 -5
index a80939fe2ee6..76c956b9a321 100644
@@ -975,7 +975,8 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
 	struct pci_dev *pdev  = NULL;
 	void __iomem *fb_virt;
 	int gen2vm = efi_enabled(EFI_BOOT);
-	resource_size_t base, size;
+	resource_size_t base = 0;
+	resource_size_t size = 0;
 	phys_addr_t paddr;
 	int ret;
 
@@ -1010,9 +1011,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
 			goto getmem_done;
 		}
 		pr_info("Unable to allocate enough contiguous physical memory on Gen 1 VM. Using MMIO instead.\n");
-	} else if (IS_ENABLED(CONFIG_SYSFB)) {
-		base = screen_info.lfb_base;
-		size = screen_info.lfb_size;
 	} else {
 		goto err1;
 	}
@@ -1056,7 +1054,10 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
 	info->screen_size = dio_fb_size;
 
 getmem_done:
-	aperture_remove_conflicting_devices(base, size, KBUILD_MODNAME);
+	if (base && size)
+		aperture_remove_conflicting_devices(base, size, KBUILD_MODNAME);
+	else
+		aperture_remove_all_conflicting_devices(KBUILD_MODNAME);
 
 	if (!gen2vm) {
 		pci_dev_put(pdev);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] fbdev/hyperv_fb: Remove firmware framebuffers with aperture helpers

Quoted 13 lines · Thomas Zimmermann

Replace use of screen_info state with the correct interfaces from the aperture helpers. The state is only for architecture and firmware code. It is not guaranteed to contain valid data. Drivers are thus not allowed to use it.

For removing conflicting firmware framebuffers, there are aperture helpers. Hence replace screen_info with the correct functions that will remove conflicting framebuffers for the hypervfb driver. For GEN1 PCI devices, the driver reads the framebuffer base and size from the PCI BAR, and uses the range for removing the firmware framebuffer. For GEN2 VMBUS devices no range can be detected, so the driver clears all firmware framebuffers.

Quoted 2 lines

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#6 lore raw

PATCH 3/4 firmware/sysfb: Clear screen_info state after consuming it

In reply to Thomas Zimmermann

After consuming the global screen_info_state in sysfb_init(), the created platform device maintains the firmware framebuffer. Clear screen_info to avoid conflicting access. Subsequent kexec reboots now ignore the firmware framebuffer.

---
 drivers/firmware/sysfb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/firmware/sysfb.c +13 -1
index 82fcfd29bc4d..19706bd2642a 100644
@@ -71,7 +71,7 @@ EXPORT_SYMBOL_GPL(sysfb_disable);
 
 static __init int sysfb_init(void)
 {
-	struct screen_info *si = &screen_info;
+	const struct screen_info *si = &screen_info;
 	struct simplefb_platform_data mode;
 	const char *name;
 	bool compatible;
@@ -119,6 +119,18 @@ static __init int sysfb_init(void)
 	if (ret)
 		goto err;
 
+	/*
+	 * The firmware framebuffer is now maintained by the created
+	 * device. Disable screen_info after we've consumed it. Prevents
+	 * invalid access during kexec reboots.
+	 *
+	 * TODO: Vgacon still relies on the global screen_info. Make
+	 *       vgacon work with the platform device, so we can clear
+	 *       the screen_info unconditionally.
+	 */
+	if (strcmp(name, "platform-framebuffer"))
+		screen_info.orig_video_isVGA = 0;
+
 	goto unlock_mutex;
 err:
 	platform_device_put(pd);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 3/4
#7 lore raw

Re: [PATCH 3/4] firmware/sysfb: Clear screen_info state after consuming it

Quoted 7 lines · Thomas Zimmermann

After consuming the global screen_info_state in sysfb_init(), the created platform device maintains the firmware framebuffer. Clear screen_info to avoid conflicting access. Subsequent kexec reboots now ignore the firmware framebuffer.

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#8 lore raw

PATCH 4/4 fbdev/hyperv_fb: Do not clear global screen_info

In reply to Thomas Zimmermann

Do not clear the global instance of screen_info. If necessary, clearing fields in screen_info should be done by architecture or firmware code that maintains the firmware framebuffer.

---
 drivers/video/fbdev/hyperv_fb.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/video/fbdev/hyperv_fb.c +1 -8
index 76c956b9a321..7d5717805c0b 100644
@@ -48,7 +48,6 @@
 #include <linux/aperture.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/screen_info.h>
 #include <linux/vmalloc.h>
 #include <linux/init.h>
 #include <linux/completion.h>
@@ -1059,14 +1058,8 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
 	else
 		aperture_remove_all_conflicting_devices(KBUILD_MODNAME);
 
-	if (!gen2vm) {
+	if (!gen2vm)
 		pci_dev_put(pdev);
-	} else if (IS_ENABLED(CONFIG_SYSFB)) {
-		/* framebuffer is reallocated, clear screen_info to avoid misuse from kexec */
-		screen_info.lfb_size = 0;
-		screen_info.lfb_base = 0;
-		screen_info.orig_video_isVGA = 0;
-	}
 
 	return 0;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 4/4
#9 lore raw

Re: [PATCH 4/4] fbdev/hyperv_fb: Do not clear global screen_info

Quoted 6 lines · Thomas Zimmermann

Do not clear the global instance of screen_info. If necessary, clearing fields in screen_info should be done by architecture or firmware code that maintains the firmware framebuffer.

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat