Pass down hot plug CONNECTOR ID to user-space
v4 cover Pass down hot plug CONNECTOR ID to user-space
Patch series addresses a shortcoming where we're sending a hot plug event without passing the actual CONNECTOR that caused it. This takes into consideration both the polling path and the HPD (Hot Plug Detect) path.
v4:
- removed the "This patch" bit - Dmitry
- added a short note when the flag is set and cleared - Dmitry
- address double dead-locking detected - kbot: https://lore.kernel.org/dri-devel/[email protected]/
- virtual connectors do not seem have any kind of hotplug - added
polling in vkms - as noted by Ian
v3: Address comments from Dmitry
- guard connector status write with mode_config.mutex
- avoid setting up the connector status and immediately unset it. Do the
unset in drm_kms_helper_hotplug_event/drm_kms_helper_connector_hotplug_event
- v3 is at https://lore.kernel.org/dri-devel/[email protected]/
v2: Address comments from Daniel
- split patch into 2, one that introduces a bool to track connector
connection status change and a patch that uses that to be able to send
hot plug events with the proper CONNECTOR ID to udev and further pass
that down to user-space
- nuke out mutex when iterating connector list
- fix typo
- v2 is at https://lore.kernel.org/dri-devel/[email protected]/
Marius Vlad (3):
drm: Introduce a new connector status
drm: Propagate connector status change
drm/vkms: Add polling for HPD
drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_probe_helper.c | 39 ++++++++++++++++++++++++++---- drivers/gpu/drm/drm_sysfs.c | 1 + drivers/gpu/drm/vkms/vkms_drv.c | 4 +++ include/drm/drm_connector.h | 3 +++ 5 files changed, 43 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.2
PATCH v4 1/3 drm: Introduce a new connector status
Introduce a new boolean variable used to track connector's connect/disconnect status and it is being used on both polling and the HPD (Hot Plug Detect) paths.
A subsequent change would make use of this connector status to propagate per-connector udev hotplug events.
The connector status is set in the drm_connector_funcs.fill_modes and cleared out when firing out KMS uevents.
Allows user-space to receive the connector's ID, rather than having a generic hot-plug event for all connectors, or in the HPD path, just the first one found with a connection status change.
--- drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_probe_helper.c | 17 +++++++++++++++++ drivers/gpu/drm/drm_sysfs.c | 1 + include/drm/drm_connector.h | 3 +++ 4 files changed, 22 insertions(+)
drivers/gpu/drm/drm_connector.c +1 -0
@@ -274,6 +274,7 @@ static int drm_connector_init_only(struct drm_device *dev,/* provide ddc symlink in sysfs */ connector->ddc = ddc; + connector->status_changed = false;INIT_LIST_HEAD (&connector->head);INIT_LIST_HEAD (&connector->global_connector_list_entry);
drivers/gpu/drm/drm_probe_helper.c +17 -0
@@ -629,6 +629,8 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector,mod_delayed_work (system_wq, &dev->mode_config.output_poll_work,0 ); + + connector->status_changed = true; }/*
@@ -732,6 +734,17 @@ EXPORT_SYMBOL(drm_helper_probe_single_connector_modes);*/ void drm_kms_helper_hotplug_event (struct drm_device *dev) { +struct drm_connector *connector; +struct drm_connector_list_iter conn_iter; + +mutex_lock (&dev->mode_config.mutex); +drm_connector_list_iter_begin (dev, &conn_iter); +drm_for_each_connector_iter (connector, &conn_iter) { + connector->status_changed = false; + } +drm_connector_list_iter_end (&conn_iter); +mutex_unlock (&dev->mode_config.mutex); +drm_sysfs_hotplug_event (dev);drm_client_dev_hotplug (dev); }
@@ -748,6 +761,10 @@ void drm_kms_helper_connector_hotplug_event(struct drm_connector *connector) {struct drm_device *dev = connector->dev; +mutex_lock (&dev->mode_config.mutex); + connector->status_changed = false; +mutex_unlock (&dev->mode_config.mutex); +drm_sysfs_connector_hotplug_event (connector);drm_client_dev_hotplug (dev); }
drivers/gpu/drm/drm_sysfs.c +1 -0
@@ -199,6 +199,7 @@ static ssize_t status_store(struct device *device,return ret; old_force = connector->force; + connector->status_changed = true;if (sysfs_streq (buf,"detect" )) connector->force =0 ;
include/drm/drm_connector.h +3 -0
@@ -2146,6 +2146,9 @@ struct drm_connector {/** @force: a DRM_FORCE_<foo> state for forced mode sets */ enum drm_connector_force force; +/** @status_changed: if the old status doesn't match current connection status */ +bool status_changed; +/** * @edid_override: Override EDID set via debugfs. *
Signature · 1 line
2.47.2
PATCH v4 2/3 drm: Propagate connector status change
In reply to Marius VladOn the HPD (Hot Plug Detect) path this change makes use of the connector status to notify all connectors, rather than just first one found that suffered a status change.
Similarly on the polling side, this also takes into consideration sending per-connector udev hotplug events.
--- drivers/gpu/drm/drm_probe_helper.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_probe_helper.c +17 -5
@@ -861,8 +861,14 @@ static void output_poll_execute(struct work_struct *work)mutex_unlock (&dev->mode_config.mutex); out: -if (changed) -drm_kms_helper_hotplug_event (dev); +if (changed) { +drm_connector_list_iter_begin (dev, &conn_iter); +drm_for_each_connector_iter (connector, &conn_iter) { +if (connector->status_changed) +drm_kms_helper_connector_hotplug_event (connector); + } +drm_connector_list_iter_end (&conn_iter); + }if (repoll)schedule_delayed_work (delayed_work,DRM_OUTPUT_POLL_PERIOD );
@@ -1124,10 +1130,16 @@ bool drm_helper_hpd_irq_event(struct drm_device *dev)drm_connector_list_iter_end (&conn_iter);mutex_unlock (&dev->mode_config.mutex); -if (changed ==1 ) +if (changed ==1 ) {drm_kms_helper_connector_hotplug_event (first_changed_connector); -else if (changed >0 ) -drm_kms_helper_hotplug_event (dev); + }else if (changed >0 ) { +drm_connector_list_iter_begin (dev, &conn_iter); +drm_for_each_connector_iter (connector, &conn_iter) { +if (connector->status_changed) +drm_kms_helper_connector_hotplug_event (connector); + } +drm_connector_list_iter_end (&conn_iter); + }if (first_changed_connector)drm_connector_put (first_changed_connector);
Signature · 1 line
2.47.2
PATCH v4 3/3 drm/vkms: Add polling for HPD
In reply to Marius Vladvkms is missing any kind of HPD (polling/irq), so add polling to handle hotplug events.
--- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/vkms/vkms_drv.c +4 -0
@@ -198,6 +198,9 @@ static int vkms_create(struct vkms_config *config)if (ret) goto out_devres; +/* init kms poll for handling hpd */ +drm_kms_helper_poll_init (&vkms_device->drm); +drm_client_setup (&vkms_device->drm,NULL );return 0 ;
@@ -240,6 +243,7 @@ static void vkms_destroy(struct vkms_config *config) fdev = config->dev->faux_dev; +drm_kms_helper_poll_fini (&config->dev->drm);drm_dev_unregister (&config->dev->drm);drm_atomic_helper_shutdown (&config->dev->drm);devres_release_group (&fdev->dev,NULL );
Signature · 1 line
2.47.2
Louis Chauvet
maintainerRe: [PATCH v4 3/3] drm/vkms: Add polling for HPD
Le 03/11/2025 à 18:45, Marius Vlad a écrit :
Quoted 2 lines
vkms is missing any kind of HPD (polling/irq), so add polling to handle hotplug events.
Hi,
I am a bit surprised by this addition, we currently have hotplug/unplug in VKMS using configFS, and it seems to work. The current "irq" system is writing in configFS the status and call drm_kms_helper_hotplug_event after the status is updated [1].
I think the polling will not work, I read in the drm_kms_helper_poll_init documentation that the connector is not polled if some connector flags are not set [2]/[3].
If the polling works, I don't think it will be enough for the current VKMS implementation. Currently setting status using configFS will do everything synchronously:
- Set the connector status (next call to connector->detect will have the new value)
- Call drm_kms_helper_hotplug_event
With your implementation, I think you expect something to update connector->status_changed in between, using polling if I understood correctly, which will probably happen after the call to drm_kms_helper_hotplug_event.
[1]:https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/vkms/vkms_connector.c?ref_type=heads#L91-96 [2]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L917-L918 [3]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L793
Quoted 27 lines
Signed-off-by Marius Vlad <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/vkms/vkms_drv.c +4
-0@@ -198,6 +198,9 @@ static int vkms_create(struct vkms_config *config)if (ret) goto out_devres; +/* init kms poll for handling hpd */ +drm_kms_helper_poll_init (&vkms_device->drm); +drm_client_setup (&vkms_device->drm,NULL );return 0 ;@@ -240,6 +243,7 @@ static void vkms_destroy(struct vkms_config *config) fdev = config->dev->faux_dev; +drm_kms_helper_poll_fini (&config->dev->drm);drm_dev_unregister (&config->dev->drm);drm_atomic_helper_shutdown (&config->dev->drm);devres_release_group (&fdev->dev,NULL );
Signature · 4 lines
-- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v4 3/3] drm/vkms: Add polling for HPD
Quoted 7 lines · Louis Chauvet
Le 03/11/2025 à 18:45, Marius Vlad a écrit :
Quoted 2 lines
vkms is missing any kind of HPD (polling/irq), so add polling to handle hotplug events.
Hi,
Hi Louis, thanks for the quick reply!
Quoted 5 lines
I am a bit surprised by this addition, we currently have hotplug/unplug in VKMS using configFS, and it seems to work. The current "irq" system is writing in configFS the status and call
drm_kms_helper_hotplug_eventafter the status is updated [1].
The situation is that the VKMS connectors/card are also being exposed through sysfs similar to real devices. That's where we trigger/simulate a connector hot-plug without physically unplugging cables. Wasn't aware that VKMS had something similar to that with ConfigFS, so that needs adjusting.
Quoted 4 lines
I think the polling will not work, I read in the
drm_kms_helper_poll_initdocumentation that the connector is not polled if some connector flags are not set [2]/[3].
In this case the loop will be no-op, but prior to the loop changed is set to changed = dev->mode_config.delayed_event [1] so the code at [2] will do run.
Quoted 8 lines
If the polling works, I don't think it will be enough for the current VKMS implementation. Currently setting status using configFS will do everything synchronously:
- Set the connector status (next call toconnector->detectwill have the new value)
- Calldrm_kms_helper_hotplug_event
Quoted 4 lines
With your implementation, I think you expect something to update
connector->status_changedin between, using polling if I understood correctly, which will probably happen after the call todrm_kms_helper_hotplug_event.
Right, that's another path for VKMS.
[1] https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L769
[2] https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L846
Quoted 35 lines
[1]:https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/vkms/vkms_connector.c?ref_type=heads#L91-96 [2]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L917-L918 [3]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L793
Quoted 23 lines
Signed-off-by Marius Vlad <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/vkms/vkms_drv.c +4
-0@@ -198,6 +198,9 @@ static int vkms_create(struct vkms_config *config)if (ret) goto out_devres; +/* init kms poll for handling hpd */ +drm_kms_helper_poll_init (&vkms_device->drm); +drm_client_setup (&vkms_device->drm,NULL );return 0 ;@@ -240,6 +243,7 @@ static void vkms_destroy(struct vkms_config *config) fdev = config->dev->faux_dev; +drm_kms_helper_poll_fini (&config->dev->drm);drm_dev_unregister (&config->dev->drm);drm_atomic_helper_shutdown (&config->dev->drm);devres_release_group (&fdev->dev,NULL );Signature · 4 lines
-- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Louis Chauvet
maintainerRe: [PATCH v4 3/3] drm/vkms: Add polling for HPD
Le 04/11/2025 à 15:19, Marius Vlad a écrit :
Quoted 14 lines · Louis Chauvet
Quoted 7 lines
Le 03/11/2025 à 18:45, Marius Vlad a écrit :
Quoted 2 lines
vkms is missing any kind of HPD (polling/irq), so add polling to handle hotplug events.
Hi,
Hi Louis, thanks for the quick reply!
Quoted 5 lines
I am a bit surprised by this addition, we currently have hotplug/unplug in VKMS using configFS, and it seems to work. The current "irq" system is writing in configFS the status and call
drm_kms_helper_hotplug_eventafter the status is updated [1].
Quoted 5 lines
The situation is that the VKMS connectors/card are also being exposed through sysfs similar to real devices. That's where we trigger/simulate a connector hot-plug without physically unplugging cables. Wasn't aware that VKMS had something similar to that with ConfigFS, so that needs adjusting.
Yes, that very recent, I am not surprised that you missed it.
Quoted 6 lines
Quoted 3 lines
I think the polling will not work, I read in the
drm_kms_helper_poll_initdocumentation that the connector is not polled if some connector flags are not set [2]/[3].In this case the loop will be no-op, but prior to the loop
changedis set tochanged = dev->mode_config.delayed_event[1] so the code at [2] will do run.
Ho, make sense, thanks for the explanation!
Quoted 8 lines
Quoted 8 lines
If the polling works, I don't think it will be enough for the current VKMS implementation. Currently setting status using configFS will do everything synchronously:
- Set the connector status (next call toconnector->detectwill have the new value)
- Calldrm_kms_helper_hotplug_event
Quoted 5 lines
Quoted 4 lines
With your implementation, I think you expect something to update
connector->status_changedin between, using polling if I understood correctly, which will probably happen after the call todrm_kms_helper_hotplug_event.Right, that's another path for VKMS.
Let me know if you have any question about the current implementation, I can help if needed.
Quoted 38 lines
[1] https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L769
[2] https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L846Quoted 35 lines
[1]:https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/vkms/vkms_connector.c?ref_type=heads#L91-96 [2]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L917-L918 [3]:https://elixir.bootlin.com/linux/v6.17.7/source/drivers/gpu/drm/drm_probe_helper.c#L793
Quoted 23 lines
Signed-off-by Marius Vlad <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/vkms/vkms_drv.c +4
-0@@ -198,6 +198,9 @@ static int vkms_create(struct vkms_config *config)if (ret) goto out_devres; +/* init kms poll for handling hpd */ +drm_kms_helper_poll_init (&vkms_device->drm); +drm_client_setup (&vkms_device->drm,NULL );return 0 ;@@ -240,6 +243,7 @@ static void vkms_destroy(struct vkms_config *config) fdev = config->dev->faux_dev; +drm_kms_helper_poll_fini (&config->dev->drm);drm_dev_unregister (&config->dev->drm);drm_atomic_helper_shutdown (&config->dev->drm);devres_release_group (&fdev->dev,NULL );Signature · 4 lines
-- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Signature · 4 lines
-- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com