Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp722481pxb; Tue, 5 Apr 2022 20:21:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEaMl9mJIeDQzBI0CvZS5qgPoK1APXtiaRQlS8tw8ZU8ZwH+zivwKI9oev2axSds/fFwSJ X-Received: by 2002:a17:902:ab57:b0:156:c63e:9d1a with SMTP id ij23-20020a170902ab5700b00156c63e9d1amr6653686plb.49.1649215278489; Tue, 05 Apr 2022 20:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649215278; cv=none; d=google.com; s=arc-20160816; b=mtXr8zAHP26tIJYd+ijbBpWplaGbllxzVTlNvfNiRbhES8v5fSq9tZauKx/Q9W1CYN z6o+Vxi4+ScpxrbuO2SPmAqehQXt7PqWbA9TvfggbY2Dq0ezU0ibVWB6DOfjx4CJUlKe rWmNAgoQI+/5CZpIWAQTvswCpdIkYxtpKTfN825qRNEL7Iyd2ChykWZCkNHdeeK1/qCL 8LHIfKTE2gMvjRJsUTRntlcUJ18dpMUzkyYO/9BU5m72OV+tv0CaIenko7pVJZ8onDmd X8qbdOGMsI8BaQY/oMa0LBffrZ7GR9eTUqcUJj+qCxBdhct/rMMNFhUUcxRzNNrb1C2s 3z2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+f+QoMoRnIyAiUCshqO8OazhKaDgeQdO9aaL6xsV7Rk=; b=SGtYAG1z/6AuvvHVJzcHQkW9789SHyspksnJdz1K22LEfsaX7qxoC3eHj0s2HXicZT rcShF4fJ391Zx+TJPCfcMhDn+gyEd0xk4ce24yARLLKIntAufUDDMIokGKnnk3z8fJSX uNxCMdB+OZWNDW6NBjZK65dcikTomYsDuc0ehZDVJVW5bV8J5xkHaRtANM3N5Ekyymc6 DYvnfFlicOC64Sn3aKZYFnEz6htyLZko77IdCkYkkaA3baU8tVD2sb5qnruVYnBSrmL+ IGutvuZimx1t3oRTIF1WYKKO11kZOmJdqODvThAhQaLZavS4rvDt6fSwoN97jV5zR65u SU2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MwgxXu+A; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o15-20020a63fb0f000000b003984299e83fsi15489620pgh.474.2022.04.05.20.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 20:21:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MwgxXu+A; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C8F1309722; Tue, 5 Apr 2022 19:55:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235999AbiDEIA7 (ORCPT + 99 others); Tue, 5 Apr 2022 04:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231531AbiDEHtr (ORCPT ); Tue, 5 Apr 2022 03:49:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 136A09398F; Tue, 5 Apr 2022 00:47:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A89F6B81B92; Tue, 5 Apr 2022 07:47:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A19AC340EE; Tue, 5 Apr 2022 07:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144822; bh=ElmofO0t8MaF8IY09Yte0+kOzk2cD6EXAVYxlSObhGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MwgxXu+AnPafZN+wq1NNpJzZWZ7TrYzrARZgBcx6STOVgDUbIGRE9ahWsGMsIUFn2 kQ5N/TOVW2lbt4j81byCR74UTIivMfVrurDgHF29cwHeIiN1w7QYWWHtlOpwYKmEqQ JobNUC7+QooobbpC9uv04+1iP6EAhfmp6U3oP5Q0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Zimmermann , Zack Rusin , Javier Martinez Canillas , Hans de Goede Subject: [PATCH 5.17 0145/1126] fbdev: Hot-unplug firmware fb devices on forced removal Date: Tue, 5 Apr 2022 09:14:52 +0200 Message-Id: <20220405070411.838460137@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Zimmermann commit 27599aacbaefcbf2af7b06b0029459bbf682000d upstream. 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: Thomas Zimmermann Reported-by: Zack Rusin Reviewed-by: Javier Martinez Canillas Reviewed-by: Zack Rusin Reviewed-by: Hans de Goede CC: stable@vger.kernel.org # v5.11+ Link: https://patchwork.freedesktop.org/patch/msgid/20220125091222.21457-2-tzimmermann@suse.de Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbmem.c | 29 ++++++++++++++++++++++++++--- include/linux/fb.h | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1559,18 +1560,36 @@ static void do_remove_conflicting_frameb /* check all firmware fbs and kick off if the base addr overlaps */ for_each_registered_fb(i) { struct apertures_struct *gen_aper; + struct device *device; if (!(registered_fb[i]->flags & FBINFO_MISC_FIRMWARE)) continue; gen_aper = registered_fb[i]->apertures; + device = registered_fb[i]->device; if (fb_do_apertures_overlap(gen_aper, a) || (primary && gen_aper && gen_aper->count && gen_aper->ranges[0].base == VGA_FB_PHYS)) { printk(KERN_INFO "fb%d: switching to %s from %s\n", i, name, registered_fb[i]->fix.id); - do_unregister_framebuffer(registered_fb[i]); + + /* + * 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]); + } } } } @@ -1900,9 +1919,13 @@ EXPORT_SYMBOL(register_framebuffer); void unregister_framebuffer(struct fb_info *fb_info) { - mutex_lock(®istration_lock); + bool forced_out = fb_info->forced_out; + + if (!forced_out) + mutex_lock(®istration_lock); do_unregister_framebuffer(fb_info); - mutex_unlock(®istration_lock); + if (!forced_out) + mutex_unlock(®istration_lock); } EXPORT_SYMBOL(unregister_framebuffer); --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -502,6 +502,7 @@ struct fb_info { } *apertures; 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) {