Skip to contentSkip to conversation

Revert "drm: hide unregistered connectors from GETCONNECTOR IOCTL"

PATCH In review Simon Ser 5 participants 14 messages Oct 17, 2022 – Nov 15, 2022

Subsystems (3)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

PATCH 1/2 Revert "drm: hide unregistered connectors from GETCONNECTOR IOCTL"

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

It turns out this breaks Mutter.

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
author
#1 lore raw

PATCH 2/2 drm/connector: send hotplug uevent on connector cleanup

A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:

1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.

The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.

Fix this by sending a hotplug uevent from drm_connector_cleanup().

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
index e3142c8142b3..90dad87e9ad0 100644
@@ -582,6 +582,9 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	mutex_destroy(&connector->mutex);
 
 	memset(connector, 0, sizeof(*connector));
+
+	if (dev->registered)
+		drm_sysfs_hotplug_event(dev);
 }
 EXPORT_SYMBOL(drm_connector_cleanup);
 
Signature · 1 line
2.38.0
Tested-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/connector: send hotplug uevent on connector cleanup

Quoted 20 lines · Simon Ser

A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:

1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.

The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.

Quoted 7 lines

Fix this by sending a hotplug uevent from drm_connector_cleanup().

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>

Jonas

Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] drm/connector: send hotplug uevent on connector cleanup

In reply to Simon Ser

LGTM! Thank you for the help with this:

Quoted 45 lines · Simon Ser

A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:

1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.

The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.

Fix this by sending a hotplug uevent from drm_connector_cleanup().

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
index e3142c8142b3..90dad87e9ad0 100644
@@ -582,6 +582,9 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	mutex_destroy(&connector->mutex);
 
 	memset(connector, 0, sizeof(*connector));
+
+	if (dev->registered)
+		drm_sysfs_hotplug_event(dev);
 }
 EXPORT_SYMBOL(drm_connector_cleanup);
 
Signature · 3 lines
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat
#4 lore raw

Re: [PATCH 2/2] drm/connector: send hotplug uevent on connector cleanup

In reply to Simon Ser
Quoted 15 lines · Simon Ser

A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:

1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.

Quoted 4 lines

The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.

So is the uevent sent by the mst delayed destroy work useless now, or what is going on there?

Quoted 29 lines

Fix this by sending a hotplug uevent from drm_connector_cleanup().

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/drm_connector.c +3 -0
index e3142c8142b3..90dad87e9ad0 100644
@@ -582,6 +582,9 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	mutex_destroy(&connector->mutex);
 
 	memset(connector, 0, sizeof(*connector));
+
+	if (dev->registered)
+		drm_sysfs_hotplug_event(dev);
 }
 EXPORT_SYMBOL(drm_connector_cleanup);
 
Signature · 1 line
2.38.0
Signature · 2 lines
Ville Syrjälä
Intel
author
#5 lore raw

Re: [PATCH 2/2] drm/connector: send hotplug uevent on connector cleanup

Quoted 17 lines · Ville Syrjälä
Quoted 15 lines · Simon Ser

A typical DP-MST unplug removes a KMS connector. However care must be taken to properly synchronize with user-space. The expected sequence of events is the following:

1. The kernel notices that the DP-MST port is gone.
2. The kernel marks the connector as disconnected, then sends a uevent to make user-space re-scan the connector list.
3. User-space notices the connector goes from connected to disconnected, disables it.
4. Kernel handles the the IOCTL disabling the connector. On success, the very last reference to the struct drm_connector is dropped and drm_connector_cleanup() is called.
5. The connector is removed from the list, and a uevent is sent to tell user-space that the connector disappeared.

Quoted 7 lines
Quoted 4 lines

The very last step was missing. As a result, user-space thought the connector still existed and could try to disable it again. Since the kernel no longer knows about the connector, that would end up with EINVAL and confused user-space.

So is the uevent sent by the mst delayed destroy work useless now, or what is going on there?

No, that one is still useful, step (2) above.

#6 lore raw
In reply to Simon Ser
Quoted 3 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

It turns out this breaks Mutter.

A bit more detail would be a good to help future archaeologists.

Quoted 26 lines
Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
Signature · 2 lines
Ville Syrjälä
Intel
#7 lore raw
Quoted 6 lines · Ville Syrjälä
Quoted 3 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

It turns out this breaks Mutter.

A bit more detail would be a good to help future archaeologists.

Perhaps a better explanation is

It turns out this causes logically active but disconnected MST display port connectors to disappear from the drmModeGetResources() list, meaning userspace is made to believe the connector is already disabled.

When userspace then attempts post a new mode set commit, if that commit uses the same CRTC used to previously drive the disconnected connector, it will fail as that CRTC is logically still tied to the disconnected connector.

This was discovered by a bisecting docking station hot plugging regression using mutter.

Jonas

Quoted 32 lines
Quoted 27 lines
Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
Signature · 2 lines
Ville Syrjälä
Intel
#8 lore raw
Quoted 4 lines · Jonas Ådahl
Quoted 3 lines · Ville Syrjälä
Quoted 2 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It turns out this breaks Mutter.

A bit more detail would be a good to help future archaeologists.

Perhaps a better explanation is

It turns out this causes logically active but disconnected MST display port connectors to disappear from the drmModeGetResources() list,

That was the whole point was it not? So I'd drop the "it turns out" part.

Quoted 1 line

meaning userspace is made to believe the connector is already disabled.

That wording to me implies its a generic issue affecting all userspace when so far it looks like only mutter is affected. So apparently mutter (for some reason) assumes that the connector has somehow magically been disabled by someone else if it disappears from the list of resources?

Quoted 44 lines

When userspace then attempts post a new mode set commit, if that commit uses the same CRTC used to previously drive the disconnected connector, it will fail as that CRTC is logically still tied to the disconnected connector.

This was discovered by a bisecting docking station hot plugging regression using mutter.

Jonas

Quoted 32 lines
Quoted 27 lines
Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
Signature · 2 lines
Ville Syrjälä
Intel
Signature · 2 lines
Ville Syrjälä
Intel
#9 lore raw
Quoted 14 lines · Ville Syrjälä
Quoted 4 lines · Jonas Ådahl
Quoted 3 lines · Ville Syrjälä
Quoted 2 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It turns out this breaks Mutter.

A bit more detail would be a good to help future archaeologists.

Perhaps a better explanation is

It turns out this causes logically active but disconnected MST display port connectors to disappear from the drmModeGetResources() list,

Quoted 7 lines

That was the whole point was it not? So I'd drop the "it turns out" part.

Quoted 1 line

meaning userspace is made to believe the connector is already disabled.

That wording to me implies its a generic issue affecting all userspace when so far it looks like only mutter is affected.

Maybe other userspace was? I only found out by testing drm-next, and only tried using mutter when bisecting.

Quoted 3 lines

So apparently mutter (for some reason) assumes that the connector has somehow magically been disabled by someone else if it disappears from the list of resources?

Mutter makes the assumption that connectors it can interact with are the ones that drmModeGetResources() return - nothing magic about that.

Jonas

Quoted 50 lines
Quoted 45 lines

When userspace then attempts post a new mode set commit, if that commit uses the same CRTC used to previously drive the disconnected connector, it will fail as that CRTC is logically still tied to the disconnected connector.

This was discovered by a bisecting docking station hot plugging regression using mutter.

Jonas

Quoted 32 lines
Quoted 27 lines
Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
Signature · 2 lines
Ville Syrjälä
Intel
Signature · 2 lines
Ville Syrjälä
Intel
#10 lore raw
Quoted 26 lines · Jonas Ådahl
Quoted 14 lines · Ville Syrjälä
Quoted 4 lines · Jonas Ådahl
Quoted 3 lines · Ville Syrjälä
Quoted 2 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

It turns out this breaks Mutter.

A bit more detail would be a good to help future archaeologists.

Perhaps a better explanation is

It turns out this causes logically active but disconnected MST display port connectors to disappear from the drmModeGetResources() list,

Quoted 7 lines

That was the whole point was it not? So I'd drop the "it turns out" part.

Quoted 1 line

meaning userspace is made to believe the connector is already disabled.

That wording to me implies its a generic issue affecting all userspace when so far it looks like only mutter is affected.

Maybe other userspace was? I only found out by testing drm-next, and only tried using mutter when bisecting.

Quoted 6 lines
Quoted 3 lines

So apparently mutter (for some reason) assumes that the connector has somehow magically been disabled by someone else if it disappears from the list of resources?

Mutter makes the assumption that connectors it can interact with are the ones that drmModeGetResources() return

I agree that on the face of it that assumption does seem perfectly reasonable.

Quoted 1 line

- nothing magic about that.

Well it's expecting a bit magic from the kernel if it decides that it doesn't need to disable what it already enabled. But I guess it's more of a case that the code just never expected this specific situation to happen, and thus the results are what they are.

I suppose the only concern with the change is what happens when you replug something back in before the old stuff has disappeared and you now have two connectors for the same thing on the list. IIRC the ddxen at least try to reuse the same xrandr output for the connector when the path prop matches. I suspect it might work by accident due to the new connector appearing (hopefully) later in the list than the old connector. But would probably need to test this to make sure.

Signature · 2 lines
Ville Syrjälä
Intel
#11 lore raw
In reply to Simon Ser

Can you update the commit message so at least the first patch can land for 6.1 so we can avoid regressions? E.g. something like

````
It caused logically active but disconnected MST display port connectors to
disappear from the drmModeGetResources() list, meaning userspace is made to
believe the connector is already disabled. This conflicts with the intended
behavior of userspace, which is to detect the connector got disconnected
and then disabling it.

When userspace later attempts post a new mode set commit, if that commit
uses the same CRTC used to previously drive the disconnected connector,
it will fail as that CRTC is logically still tied to the disconnected
connector.

This was discovered by a bisecting docking station hot plugging
regression using mutter.
```

(feel free to edit in any way you want).

Jonas

Quoted 30 lines · Simon Ser

This reverts commit 981f09295687f856d5345e19c7084aca481c1395.

It turns out this breaks Mutter.

Cc Daniel Vetter <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Jonas Ådahl <[email protected]>
---
 drivers/gpu/drm/drm_mode_config.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/drm_mode_config.c +0 -3
index 939d621c9ad4..688c8afe0bf1 100644
@@ -151,9 +151,6 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
 	count = 0;
 	connector_id = u64_to_user_ptr(card_res->connector_id_ptr);
 	drm_for_each_connector_iter(connector, &conn_iter) {
-		if (connector->registration_state != DRM_CONNECTOR_REGISTERED)
-			continue;
-
 		/* only expose writeback connectors if userspace understands them */
 		if (!file_priv->writeback_connectors &&
 		    (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK))
Signature · 1 line
2.38.0
author
#12 lore raw

I've already pushed both patches to drm-misc-next.

#13 lore raw
Quoted 1 line · Simon Ser

I've already pushed both patches to drm-misc-next.

It's not in any 6.1 rc yet, and apparently it needs to be pushed to drm-misc-fixes to get into 6.1.