Commit 27599aac authored by Thomas Zimmermann's avatar Thomas Zimmermann

fbdev: Hot-unplug firmware fb devices on forced removal

Hot-unplug all firmware-framebuffer devices as part of removing
them via remove_conflicting_framebuffers() et al. Releases all
memory regions to be acquired by native drivers.

Firmware, such as EFI, install a framebuffer while posting the
computer. After removing the firmware-framebuffer device from fbdev,
a native driver takes over the hardware and the firmware framebuffer
becomes invalid.

Firmware-framebuffer drivers, specifically simplefb, don't release
their device from Linux' device hierarchy. It still owns the firmware
framebuffer and blocks the native drivers from loading. This has been
observed in the vmwgfx driver. [1]

Initiating a device removal (i.e., hot unplug) as part of
remove_conflicting_framebuffers() removes the underlying device and
returns the memory range to the system.

[1] https://lore.kernel.org/dri-devel/20220117180359.18114-1-zack@kde.org/

v2:
	* rename variable 'dev' to 'device' (Javier)
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reported-by: default avatarZack Rusin <zackr@vmware.com>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Reviewed-by: default avatarZack Rusin <zackr@vmware.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
CC: stable@vger.kernel.org # v5.11+
Link: https://patchwork.freedesktop.org/patch/msgid/20220125091222.21457-2-tzimmermann@suse.de
parent 31b04883
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/linux_logo.h> #include <linux/linux_logo.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/platform_device.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/console.h> #include <linux/console.h>
#include <linux/kmod.h> #include <linux/kmod.h>
...@@ -1557,20 +1558,38 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a, ...@@ -1557,20 +1558,38 @@ static void do_remove_conflicting_framebuffers(struct apertures_struct *a,
/* check all firmware fbs and kick off if the base addr overlaps */ /* check all firmware fbs and kick off if the base addr overlaps */
for_each_registered_fb(i) { for_each_registered_fb(i) {
struct apertures_struct *gen_aper; struct apertures_struct *gen_aper;
struct device *device;
if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE)) if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE))
continue; continue;
gen_aper = registered_fb[i]->apertures; gen_aper = registered_fb[i]->apertures;
device = registered_fb[i]->device;
if (fb_do_apertures_overlap(gen_aper, a) || if (fb_do_apertures_overlap(gen_aper, a) ||
(primary && gen_aper && gen_aper->count && (primary && gen_aper && gen_aper->count &&
gen_aper->ranges[0].base == VGA_FB_PHYS)) { gen_aper->ranges[0].base == VGA_FB_PHYS)) {
printk(KERN_INFO "fb%d: switching to %s from %s\n", printk(KERN_INFO "fb%d: switching to %s from %s\n",
i, name, registered_fb[i]->fix.id); i, name, registered_fb[i]->fix.id);
/*
* If we kick-out a firmware driver, we also want to remove
* the underlying platform device, such as simple-framebuffer,
* VESA, EFI, etc. A native driver will then be able to
* allocate the memory range.
*
* If it's not a platform device, at least print a warning. A
* fix would add code to remove the device from the system.
*/
if (dev_is_platform(device)) {
registered_fb[i]->forced_out = true;
platform_device_unregister(to_platform_device(device));
} else {
pr_warn("fb%d: cannot remove device\n", i);
do_unregister_framebuffer(registered_fb[i]); do_unregister_framebuffer(registered_fb[i]);
} }
} }
}
} }
static bool lockless_register_fb; static bool lockless_register_fb;
...@@ -1851,8 +1870,12 @@ EXPORT_SYMBOL(register_framebuffer); ...@@ -1851,8 +1870,12 @@ EXPORT_SYMBOL(register_framebuffer);
void void
unregister_framebuffer(struct fb_info *fb_info) unregister_framebuffer(struct fb_info *fb_info)
{ {
bool forced_out = fb_info->forced_out;
if (!forced_out)
mutex_lock(&registration_lock); mutex_lock(&registration_lock);
do_unregister_framebuffer(fb_info); do_unregister_framebuffer(fb_info);
if (!forced_out)
mutex_unlock(&registration_lock); mutex_unlock(&registration_lock);
} }
EXPORT_SYMBOL(unregister_framebuffer); EXPORT_SYMBOL(unregister_framebuffer);
......
...@@ -502,6 +502,7 @@ struct fb_info { ...@@ -502,6 +502,7 @@ struct fb_info {
} *apertures; } *apertures;
bool skip_vt_switch; /* no VT switch on suspend/resume required */ bool skip_vt_switch; /* no VT switch on suspend/resume required */
bool forced_out; /* set when being removed by another driver */
}; };
static inline struct apertures_struct *alloc_apertures(unsigned int max_num) { static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment