mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javierm@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Daniel Vetter <daniel@ffwll.ch>, David Airlie <airlied@linux.ie>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>
Subject: [RFC PATCH v4 09/11] drm: Fix race between sysfb and DRM devices registration
Date: Fri, 29 Apr 2022 10:42:51 +0200	[thread overview]
Message-ID: <20220429084253.1085911-10-javierm@redhat.com> (raw)
In-Reply-To: <20220429084253.1085911-1-javierm@redhat.com>

The platform devices registered by sysfb match with firmware-based DRM or
fbdev drivers, that are used to have early graphics using a framebuffer
provided by the system firmware.

DRM or fbdev drivers later are probed and remove all conflicting framebuffers,
leading to these platform devices for generic drivers to be unregistered.

But the current solution has a race, since the sysfb_init() function could
be called after a DRM driver is probed and requested to unregister devices
for drivers with conflicting framebuffes.

To prevent this, disable any future sysfb platform device registration by
calling sysfb_disable(), if either a framebuffer device or a DRM device is
registered. Since in that case a display will already be present.

Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---

(no changes since v3)

Changes in v3:
- Call sysfb_disable() when a DRM device is registered rather than
  when conflicting framebuffers are removed (Thomas Zimmermann).

 drivers/gpu/drm/drm_drv.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 8214a0b1ab7f..e577c42861c6 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -34,6 +34,7 @@
 #include <linux/pseudo_fs.h>
 #include <linux/slab.h>
 #include <linux/srcu.h>
+#include <linux/sysfb.h>
 
 #include <drm/drm_cache.h>
 #include <drm/drm_client.h>
@@ -913,6 +914,17 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
 out_unlock:
 	if (drm_dev_needs_global_mutex(dev))
 		mutex_unlock(&drm_global_mutex);
+
+	/*
+	 * If a driver registers a DRM device, then it can be assumed that a
+	 * display will be present and there is no need for a generic driver
+	 * using the firmware setup system framebuffer.
+	 *
+	 * Disable sysfb and prevent registering simple framebuffer devices.
+	 */
+	if (!drm_core_check_feature(dev, DRIVER_FIRMWARE))
+		sysfb_disable();
+
 	return ret;
 }
 EXPORT_SYMBOL(drm_dev_register);
-- 
2.35.1


  parent reply	other threads:[~2022-04-29  8:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-29  8:42 [RFC PATCH v4 00/11] Fix some race between sysfb device registration and drivers probe Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 01/11] drm: Add a capability flag for simple framebuffer drivers Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 02/11] drm/fb-helper: Set FBINFO_MISC_FIRMWARE flag for DRIVER_FIRMWARE fb Javier Martinez Canillas
2022-04-29  9:14   ` Thomas Zimmermann
2022-04-29  9:23     ` Javier Martinez Canillas
2022-04-29 10:20       ` Thomas Zimmermann
2022-04-29 10:50         ` Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 03/11] drm/simpledrm: Set the DRM_FIRMWARE capability Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 04/11] firmware: sysfb: Make sysfb_create_simplefb() return a pdev pointer Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 05/11] firmware: sysfb: Add helpers to unregister a pdev and disable registration Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 06/11] fbdev: Restart conflicting fb removal loop when unregistering devices Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 07/11] fbdev: Make sysfb to unregister its own registered devices Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 08/11] fbdev: Fix race between sysfb and framebuffer devices registration Javier Martinez Canillas
2022-04-29  8:42 ` Javier Martinez Canillas [this message]
2022-04-29  8:42 ` [RFC PATCH v4 10/11] Revert "fbdev: Prevent probing generic drivers if a FB is already registered" Javier Martinez Canillas
2022-04-29  8:42 ` [RFC PATCH v4 11/11] fbdev: Make registered_fb[] private to fbmem.c Javier Martinez Canillas
2022-04-29 15:02   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220429084253.1085911-10-javierm@redhat.com \
    --to=javierm@redhat.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@ffwll.ch \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®