Skip to contentSkip to conversation

soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free

PATCH Applied Johan Hovold 8 participants 51 messages Feb 17, 2024 – Mar 6, 2024

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

cover soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

The intermittent hard resets that have also been reported since 6.8-rc1 unfortunately still remains and suggests that we are dealing with two separate regressions. There is some indication that also the hard resets (e.g. due to register accesses to unclocked hardware) are also due to changes in the DRM subsystem as it happens around the time that the eDP panel and display controller would be initialised during boot (the runtime PM rework?). This remains to be verified, however.

Included is also a fix for a related OF node reference leak in the aux-hpd driver found through inspection when reworking the driver.

The use-after-free bug is triggered by a probe deferral and highlighted some further bugs in the involved drivers, which were registering child devices before deferring probe. This behaviour is not correct and can both trigger probe deferral loops and potentially also further issues with the DRM bridge implementation.

This series can either go through the Qualcomm SoC tree (pmic_glink) or the DRM tree. The PHY patches do not depend on the rest of the series and could possibly be merged separately through the PHY tree.

Whichever gets this to mainline the fastest.

Johan

[1] https://lore.kernel.org/lkml/[email protected]/

Johan Hovold (5):
drm/bridge: aux-hpd: fix OF node leaks
drm/bridge: aux-hpd: separate allocation and registration
soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
phy: qcom-qmp-combo: fix drm bridge registration
phy: qcom-qmp-combo: fix type-c switch registration

Rob Clark (1):
soc: qcom: pmic_glink: Fix boot when QRTR=m

 drivers/gpu/drm/bridge/aux-hpd-bridge.c   | 70 ++++++++++++++++++-----
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 16 +++---
 drivers/soc/qcom/pmic_glink.c             | 21 +++----
 drivers/soc/qcom/pmic_glink_altmode.c     | 16 +++++-
 include/drm/bridge/aux-bridge.h           | 15 +++++
 5 files changed, 102 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 drm/bridge: aux-hpd: fix OF node leaks

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

Fixes 6914968a0b52 ("drm/bridge: properly refcount DT nodes in aux bridge drivers")
Cc Dmitry Baryshkov <[email protected]>
Cc Neil Armstrong <[email protected]>
---
 drivers/gpu/drm/bridge/aux-hpd-bridge.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +3 -0
index bb55f697a181..9e71daf95bde 100644
@@ -25,6 +25,7 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
 	ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 
 	of_node_put(adev->dev.platform_data);
+	of_node_put(adev->dev.of_node);
 
 	kfree(adev);
 }
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
 		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 		kfree(adev);
 		return ERR_PTR(ret);
Signature · 1 line
2.43.0
#12 lore raw

PATCH 2/6 drm/bridge: aux-hpd: separate allocation and registration

In reply to Johan Hovold

Combining allocation and registration is an anti-pattern that should be avoided. Add two new functions for allocating and registering an dp-hpd bridge with a proper 'devm' prefix so that it is clear that these are device managed interfaces.

devm_drm_dp_hpd_bridge_alloc()
devm_drm_dp_hpd_bridge_add()

The new interface will be used to fix a use-after-free bug in the Qualcomm PMIC GLINK driver and may prevent similar issues from being introduced elsewhere.

The existing drm_dp_hpd_bridge_register() is reimplemented using the above and left in place for now.

---
 drivers/gpu/drm/bridge/aux-hpd-bridge.c | 67 +++++++++++++++++++------
 include/drm/bridge/aux-bridge.h         | 15 ++++++
 2 files changed, 67 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +52 -15
index 9e71daf95bde..6886db2d9e00 100644
@@ -30,16 +30,13 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
 	kfree(adev);
 }
 
-static void drm_aux_hpd_bridge_unregister_adev(void *_adev)
+static void drm_aux_hpd_bridge_free_adev(void *_adev)
 {
-	struct auxiliary_device *adev = _adev;
-
-	auxiliary_device_delete(adev);
-	auxiliary_device_uninit(adev);
+	auxiliary_device_uninit(_adev);
 }
 
 /**
- * drm_dp_hpd_bridge_register - Create a simple HPD DisplayPort bridge
+ * devm_drm_dp_hpd_bridge_alloc - allocate a HPD DisplayPort bridge
  * @parent: device instance providing this bridge
  * @np: device node pointer corresponding to this bridge instance
  *
@@ -47,11 +44,9 @@ static void drm_aux_hpd_bridge_unregister_adev(void *_adev)
  * DRM_MODE_CONNECTOR_DisplayPort, which terminates the bridge chain and is
  * able to send the HPD events.
  *
- * Return: device instance that will handle created bridge or an error code
- * encoded into the pointer.
+ * Return: bridge auxiliary device pointer or an error pointer
  */
-struct device *drm_dp_hpd_bridge_register(struct device *parent,
-					  struct device_node *np)
+struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np)
 {
 	struct auxiliary_device *adev;
 	int ret;
@@ -82,13 +77,55 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 		return ERR_PTR(ret);
 	}
 
-	ret = auxiliary_device_add(adev);
-	if (ret) {
-		auxiliary_device_uninit(adev);
+	ret = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_free_adev, adev);
+	if (ret)
 		return ERR_PTR(ret);
-	}
 
-	ret = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_unregister_adev, adev);
+	return adev;
+}
+EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_alloc);
+
+static void drm_aux_hpd_bridge_del_adev(void *_adev)
+{
+	auxiliary_device_delete(_adev);
+}
+
+/**
+ * devm_drm_dp_hpd_bridge_add - register a HDP DisplayPort bridge
+ * @dev: struct device to tie registration lifetime to
+ * @adev: bridge auxiliary device to be registered
+ *
+ * Returns: zero on success or a negative errno
+ */
+int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev)
+{
+	int ret;
+
+	ret = auxiliary_device_add(adev);
+	if (ret)
+		return ret;
+
+	return devm_add_action_or_reset(dev, drm_aux_hpd_bridge_del_adev, adev);
+}
+EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_add);
+
+/**
+ * drm_dp_hpd_bridge_register - allocate and register a HDP DisplayPort bridge
+ * @parent: device instance providing this bridge
+ * @np: device node pointer corresponding to this bridge instance
+ *
+ * Return: device instance that will handle created bridge or an error pointer
+ */
+struct device *drm_dp_hpd_bridge_register(struct device *parent, struct device_node *np)
+{
+	struct auxiliary_device *adev;
+	int ret;
+
+	adev = devm_drm_dp_hpd_bridge_alloc(parent, np);
+	if (IS_ERR(adev))
+		return ERR_CAST(adev);
+
+	ret = devm_drm_dp_hpd_bridge_add(parent, adev);
 	if (ret)
 		return ERR_PTR(ret);
 
include/drm/bridge/aux-bridge.h +15 -0
index c4c423e97f06..4453906105ca 100644
@@ -9,6 +9,8 @@
 
 #include <drm/drm_connector.h>
 
+struct auxiliary_device;
+
 #if IS_ENABLED(CONFIG_DRM_AUX_BRIDGE)
 int drm_aux_bridge_register(struct device *parent);
 #else
@@ -19,10 +21,23 @@ static inline int drm_aux_bridge_register(struct device *parent)
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE)
+struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np);
+int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev);
 struct device *drm_dp_hpd_bridge_register(struct device *parent,
 					  struct device_node *np);
 void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status status);
 #else
+static inline struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent,
+								    struct device_node *np)
+{
+	return NULL;
+}
+
+static inline int devm_drm_dp_hpd_bridge_add(struct auxiliary_device *adev)
+{
+	return 0;
+}
+
 static inline struct device *drm_dp_hpd_bridge_register(struct device *parent,
 							struct device_node *np)
 {
Signature · 1 line
2.43.0
#17 lore raw

PATCH 3/6 soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free

In reply to Johan Hovold

A recent DRM series purporting to simplify support for "transparent bridges" and handling of probe deferrals ironically exposed a use-after-free issue on pmic_glink_altmode probe deferral.

This has manifested itself as the display subsystem occasionally failing to initialise and NULL-pointer dereferences during boot of machines like the Lenovo ThinkPad X13s.

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

When the display controller is later initialised, this triggers a use-after-free when attaching the bridges:

	dp -> aux -> dp-hpd (freed)

which may, for example, result in the freed bridge failing to attach:

[drm:drm_bridge_attach [drm]] *ERROR* failed to attach bridge /soc@0/phy@88eb000 to encoder TMDS-31: -16

or a NULL-pointer dereference:

	Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
	...
	Call trace:
	  drm_bridge_attach+0x70/0x1a8 [drm]
	  drm_aux_bridge_attach+0x24/0x38 [aux_bridge]
	  drm_bridge_attach+0x80/0x1a8 [drm]
	  dp_bridge_init+0xa8/0x15c [msm]
	  msm_dp_modeset_init+0x28/0xc4 [msm]

The DRM bridge implementation is clearly fragile and implicitly built on the assumption that bridges may never go away. In this case, the fix is to move the bridge registration in the pmic_glink_altmode driver to after all resources have been looked up.

Incidentally, with the new dp-hpd bridge implementation, which registers child devices, this is also a requirement due to a long-standing issue in driver core that can otherwise lead to a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Fixes 080b4e24852b ("soc: qcom: pmic_glink: Introduce altmode support")
Fixes 2bcca96abfbf ("soc: qcom: pmic-glink: switch to DRM_AUX_HPD_BRIDGE")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
---
 drivers/soc/qcom/pmic_glink_altmode.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +13 -3
index 5fcd0fdd2faa..b3808fc24c69 100644
@@ -76,7 +76,7 @@ struct pmic_glink_altmode_port {
 
 	struct work_struct work;
 
-	struct device *bridge;
+	struct auxiliary_device *bridge;
 
 	enum typec_orientation orientation;
 	u16 svid;
@@ -230,7 +230,7 @@ static void pmic_glink_altmode_worker(struct work_struct *work)
 	else
 		pmic_glink_altmode_enable_usb(altmode, alt_port);
 
-	drm_aux_hpd_bridge_notify(alt_port->bridge,
+	drm_aux_hpd_bridge_notify(&alt_port->bridge->dev,
 				  alt_port->hpd_state ?
 				  connector_status_connected :
 				  connector_status_disconnected);
@@ -454,7 +454,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		alt_port->index = port;
 		INIT_WORK(&alt_port->work, pmic_glink_altmode_worker);
 
-		alt_port->bridge = drm_dp_hpd_bridge_register(dev, to_of_node(fwnode));
+		alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode));
 		if (IS_ERR(alt_port->bridge)) {
 			fwnode_handle_put(fwnode);
 			return PTR_ERR(alt_port->bridge);
@@ -510,6 +510,16 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		}
 	}
 
+	for (port = 0; port < ARRAY_SIZE(altmode->ports); port++) {
+		alt_port = &altmode->ports[port];
+		if (!alt_port->bridge)
+			continue;
+
+		ret = devm_drm_dp_hpd_bridge_add(dev, alt_port->bridge);
+		if (ret)
+			return ret;
+	}
+
 	altmode->client = devm_pmic_glink_register_client(dev,
 							  altmode->owner_id,
 							  pmic_glink_altmode_callback,
Signature · 1 line
2.43.0
#24 lore raw

PATCH 4/6 soc: qcom: pmic_glink: Fix boot when QRTR=m

In reply to Johan Hovold

From: Rob Clark <[email protected]>

We need to bail out before adding/removing devices if we are going to -EPROBE_DEFER. Otherwise boot can get stuck in a probe deferral loop due to a long-standing issue in driver core (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Deregistering the altmode child device can potentially also trigger bugs in the DRM bridge implementation, which does not expect bridges to go away.

[ johan: rebase on 6.8-rc4, amend commit message and mention DRM ]
Fixes 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Cc Bjorn Andersson <[email protected]>
---
 drivers/soc/qcom/pmic_glink.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/soc/qcom/pmic_glink.c +11 -10
index f4bfd24386f1..f913e9bd57ed 100644
@@ -265,10 +265,17 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
 	pg->client_mask = *match_data;
 
+	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
+	if (IS_ERR(pg->pdr)) {
+		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr),
+				    "failed to initialize pdr\n");
+		return ret;
+	}
+
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) {
 		ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi");
 		if (ret)
-			return ret;
+			goto out_release_pdr_handle;
 	}
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE)) {
 		ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
@@ -281,17 +288,11 @@ static int pmic_glink_probe(struct platform_device *pdev)
 			goto out_release_altmode_aux;
 	}
 
-	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
-	if (IS_ERR(pg->pdr)) {
-		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr), "failed to initialize pdr\n");
-		goto out_release_aux_devices;
-	}
-
 	service = pdr_add_lookup(pg->pdr, "tms/servreg", "msm/adsp/charger_pd");
 	if (IS_ERR(service)) {
 		ret = dev_err_probe(&pdev->dev, PTR_ERR(service),
 				    "failed adding pdr lookup for charger_pd\n");
-		goto out_release_pdr_handle;
+		goto out_release_aux_devices;
 	}
 
 	mutex_lock(&__pmic_glink_lock);
@@ -300,8 +301,6 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
 	return 0;
 
-out_release_pdr_handle:
-	pdr_handle_release(pg->pdr);
 out_release_aux_devices:
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
 		pmic_glink_del_aux_device(pg, &pg->ps_aux);
@@ -311,6 +310,8 @@ static int pmic_glink_probe(struct platform_device *pdev)
 out_release_ucsi_aux:
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
 		pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
+out_release_pdr_handle:
+	pdr_handle_release(pg->pdr);
 
 	return ret;
 }
Signature · 1 line
2.43.0
#28 lore raw

PATCH 5/6 phy: qcom-qmp-combo: fix drm bridge registration

In reply to Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

This could potentially also trigger a bug in the DRM bridge implementation which does not expect bridges to go away even if device links may avoid triggering this (when enabled).

Move registration of the DRM aux bridge to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Fixes 35921910bbd0 ("phy: qcom: qmp-combo: switch to DRM_AUX_BRIDGE")
Fixes 1904c3f578dc ("phy: qcom-qmp-combo: Introduce drm_bridge")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -4
index 1ad10110dd25..e19d6a084f10 100644
@@ -3566,10 +3566,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = drm_aux_bridge_register(dev);
-	if (ret)
-		return ret;
-
 	/* Check for legacy binding with child nodes. */
 	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
 	if (usb_np) {
@@ -3589,6 +3585,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_node_put;
 
+	ret = drm_aux_bridge_register(dev);
+	if (ret)
+		goto err_node_put;
+
 	pm_runtime_set_active(dev);
 	ret = devm_pm_runtime_enable(dev);
 	if (ret)
Signature · 1 line
2.43.0
#33 lore raw

PATCH 6/6 phy: qcom-qmp-combo: fix type-c switch registration

In reply to Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Move registration of the typec switch to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Fixes 2851117f8f42 ("phy: qcom-qmp-combo: Introduce orientation switching")
Cc Bjorn Andersson <[email protected]>
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -4
index e19d6a084f10..17c4ad7553a5 100644
@@ -3562,10 +3562,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = qmp_combo_typec_switch_register(qmp);
-	if (ret)
-		return ret;
-
 	/* Check for legacy binding with child nodes. */
 	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
 	if (usb_np) {
@@ -3585,6 +3581,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_node_put;
 
+	ret = qmp_combo_typec_switch_register(qmp);
+	if (ret)
+		goto err_node_put;
+
 	ret = drm_aux_bridge_register(dev);
 	if (ret)
 		goto err_node_put;
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 5/6
#29 lore raw

Re: [PATCH 5/6] phy: qcom-qmp-combo: fix drm bridge registration

In reply to Johan Hovold
Quoted 43 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

This could potentially also trigger a bug in the DRM bridge implementation which does not expect bridges to go away even if device links may avoid triggering this (when enabled).

Move registration of the DRM aux bridge to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Fixes 35921910bbd0 ("phy: qcom: qmp-combo: switch to DRM_AUX_BRIDGE")
Fixes 1904c3f578dc ("phy: qcom-qmp-combo: Introduce drm_bridge")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
---
  drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +0 -4
index 1ad10110dd25..e19d6a084f10 100644
@@ -3566,10 +3566,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
  	if (ret)
  		return ret;
 
-	ret = drm_aux_bridge_register(dev);
-	if (ret)
-		return ret;
-
  	/* Check for legacy binding with child nodes. */
  	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
  	if (usb_np) {

drivers/phy/qualcomm/phy-qcom-qmp-combo.c static int qmp_combo_probe(struct platform_device *pdev) · line 3594

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -0
@@ -3589,6 +3585,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
  	if (ret)
  		goto err_node_put;
 
+	ret = drm_aux_bridge_register(dev);
+	if (ret)
+		goto err_node_put;
+
  	pm_runtime_set_active(dev);
  	ret = devm_pm_runtime_enable(dev);
  	if (ret)
#2 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
 		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 		kfree(adev);
 		return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

How do you think about to avoid such a bit of duplicate source code by adding a label here?

Regards,
Markus

#3 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

Quoted 18 lines · Markus Elfring
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
 		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 		kfree(adev);
 		return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

Quoted 2 lines

How do you think about to avoid such a bit of duplicate source code by adding a label here?

No, the current code is fine and what you are suggesting is in any case unrelated to this fix.

If this function ever grows a third error path like that, I too would consider it however.

Johan

#18 lore raw
In reply to Johan Hovold

…

Quoted 8 lines

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

…

I got the impression that the change description can be improved another bit.

1. Will any additional imperative wordings become helpful?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.8-rc5#n94

…

drivers/soc/qcom/pmic_glink_altmode.c struct pmic_glink_altmode_port { · line 82

Quoted 10 lines

+++ b/drivers/soc/qcom/pmic_glink_altmode.c

drivers/soc/qcom/pmic_glink_altmode.c +1 -1
@@ -76,7 +76,7 @@ struct pmic_glink_altmode_port {
 
 	struct work_struct work;
 
-	struct device *bridge;
+	struct auxiliary_device *bridge;
 
 	enum typec_orientation orientation;
 	u16 svid;

…

2. How do you think about to stress such a data type adjustment?

Regards,
Markus

#19 lore raw
In reply to Johan Hovold

…

Quoted 8 lines

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

…

Quoted 1 line

+++ b/drivers/soc/qcom/pmic_glink_altmode.c

…

drivers/soc/qcom/pmic_glink_altmode.c static int pmic_glink_altmode_probe(struct auxiliary_device *adev, · line 460

Quoted 9 lines
drivers/soc/qcom/pmic_glink_altmode.c +1 -1
@@ -454,7 +454,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		alt_port->index = port;
 		INIT_WORK(&alt_port->work, pmic_glink_altmode_worker);
 
-		alt_port->bridge = drm_dp_hpd_bridge_register(dev, to_of_node(fwnode));
+		alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode));
 		if (IS_ERR(alt_port->bridge)) {
 			fwnode_handle_put(fwnode);
 			return PTR_ERR(alt_port->bridge);

…

The function call “fwnode_handle_put(fwnode)” is used in multiple if branches.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/soc/qcom/pmic_glink_altmode.c#L435

I suggest to add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

Regards,
Markus

#20 lore raw
Quoted 23 lines · Markus Elfring

…

Quoted 8 lines

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

…

Quoted 1 line

+++ b/drivers/soc/qcom/pmic_glink_altmode.c

…

Quoted 9 lines
drivers/soc/qcom/pmic_glink_altmode.c +1 -1
@@ -454,7 +454,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		alt_port->index = port;
 		INIT_WORK(&alt_port->work, pmic_glink_altmode_worker);
 
-		alt_port->bridge = drm_dp_hpd_bridge_register(dev, to_of_node(fwnode));
+		alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode));
 		if (IS_ERR(alt_port->bridge)) {
 			fwnode_handle_put(fwnode);
 			return PTR_ERR(alt_port->bridge);

…

Quoted 5 lines

The function call “fwnode_handle_put(fwnode)” is used in multiple if branches.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/soc/qcom/pmic_glink_altmode.c#L435

I suggest to add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

Markus, as people have told you repeatedly, just stop with these comments. You're not helping, in fact, you are actively harmful to the kernel community as you are wasting people's time.

Johan

#4 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 19 lines · Johan Hovold
Quoted 18 lines · Markus Elfring
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
 		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 		kfree(adev);
 		return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

Quoted 8 lines
Quoted 2 lines

How do you think about to avoid such a bit of duplicate source code by adding a label here?

No, the current code is fine and what you are suggesting is in any case unrelated to this fix.

If this function ever grows a third error path like that, I too would consider it however.

I guess these of_node_puts can all go away shortly with cleanup anyway?

julia

#5 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

Quoted 27 lines · Julia Lawall
Quoted 22 lines · Johan Hovold
Quoted 20 lines · Markus Elfring
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
  ret = auxiliary_device_init(adev);
  if (ret) {
+         of_node_put(adev->dev.platform_data);
+         of_node_put(adev->dev.of_node);
          ida_free(&drm_aux_hpd_bridge_ida, adev->id);
          kfree(adev);
          return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

How do you think about to avoid such a bit of duplicate source code by adding a label here?

Quoted 7 lines
Quoted 5 lines

No, the current code is fine and what you are suggesting is in any case unrelated to this fix.

If this function ever grows a third error path like that, I too would consider it however.

I guess these of_node_puts can all go away shortly with cleanup anyway?

I'm not sure about it. Those are long-living variables, so they are not a subject of cleanup.h, are they?

Signature · 2 lines
With best wishes
Dmitry
#21 lore raw
In reply to Johan Hovold
Quoted 7 lines
Quoted 5 lines

The function call “fwnode_handle_put(fwnode)” is used in multiple if branches.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/soc/qcom/pmic_glink_altmode.c#L435

I suggest to add a jump target so that a bit of exception handling can be better reused at the end of this function implementation.

Markus, as people have told you repeatedly, just stop with these comments.

How does such a response fit to advices from another known information sources?

Section “7) Centralized exiting of functions”
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.8-rc5#n526

Quoted 2 lines

You're not helping, in fact, you are actively harmful to the kernel community as you are wasting people's time.

The proposed source code transformation can eventually be (automatically) achieved also with help of improved development tools.

Regards,
Markus

#6 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Dmitry Baryshkov
Quoted 31 lines · Dmitry Baryshkov
Quoted 30 lines · Julia Lawall
Quoted 25 lines · Johan Hovold
Quoted 18 lines · Markus Elfring
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
  ret = auxiliary_device_init(adev);
  if (ret) {
+         of_node_put(adev->dev.platform_data);
+         of_node_put(adev->dev.of_node);
          ida_free(&drm_aux_hpd_bridge_ida, adev->id);
          kfree(adev);
          return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

Quoted 2 lines

How do you think about to avoid such a bit of duplicate source code by adding a label here?

No, the current code is fine and what you are suggesting is in any case unrelated to this fix.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

If this function ever grows a third error path like that, I too would consider it however.

I guess these of_node_puts can all go away shortly with cleanup anyway?

I'm not sure about it. Those are long-living variables, so they are not a subject of cleanup.h, are they?

OK, I didn't look at this code in detail, but cleanup would just call of_node_put, not actually free the data.

julia

#7 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

Quoted 39 lines · Julia Lawall
Quoted 34 lines · Dmitry Baryshkov
Quoted 33 lines · Julia Lawall
Quoted 27 lines · Johan Hovold
Quoted 18 lines · Markus Elfring
Quoted 2 lines

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

…

Quoted 1 line

+++ b/drivers/gpu/drm/bridge/aux-hpd-bridge.c

…

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 9 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
  ret = auxiliary_device_init(adev);
  if (ret) {
+         of_node_put(adev->dev.platform_data);
+         of_node_put(adev->dev.of_node);
          ida_free(&drm_aux_hpd_bridge_ida, adev->id);
          kfree(adev);
          return ERR_PTR(ret);

The last two statements are also used in a previous if branch.
https://elixir.bootlin.com/linux/v6.8-rc5/source/drivers/gpu/drm/bridge/aux-hpd-bridge.c#L63

Quoted 2 lines

How do you think about to avoid such a bit of duplicate source code by adding a label here?

No, the current code is fine and what you are suggesting is in any case unrelated to this fix.

If this function ever grows a third error path like that, I too would consider it however.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I guess these of_node_puts can all go away shortly with cleanup anyway?

I'm not sure about it. Those are long-living variables, so they are not a subject of cleanup.h, are they?

OK, I didn't look at this code in detail, but cleanup would just call of_node_put, not actually free the data.

Yes. The nodes should be put either in case of the failure or (if everything goes fine) at the device unregistration.

Signature · 2 lines
With best wishes
Dmitry
maintainer Reviewed-by on v1 1/6
#8 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 7 lines · Johan Hovold

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

Fixes 6914968a0b52 ("drm/bridge: properly refcount DT nodes in aux bridge drivers")
Cc Dmitry Baryshkov <[email protected]>
Cc Neil Armstrong <[email protected]>

Regards,
Bjorn

Quoted 28 lines
---
 drivers/gpu/drm/bridge/aux-hpd-bridge.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +3 -0
index bb55f697a181..9e71daf95bde 100644
@@ -25,6 +25,7 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
 	ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 
 	of_node_put(adev->dev.platform_data);
+	of_node_put(adev->dev.of_node);
 
 	kfree(adev);
 }
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
 		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 		kfree(adev);
 		return ERR_PTR(ret);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 2/6
#13 lore raw

Re: [PATCH 2/6] drm/bridge: aux-hpd: separate allocation and registration

In reply to Johan Hovold
Quoted 1 line · Johan Hovold
drivers/gpu/drm/bridge/aux-hpd-bridge.c +0 -0

[..]

Quoted 2 lines

+/**
+ * devm_drm_dp_hpd_bridge_add - register a HDP DisplayPort bridge

kernel-doc wants () after function names.

Quoted 4 lines

+ * @dev: struct device to tie registration lifetime to
+ * @adev: bridge auxiliary device to be registered
+ *
+ * Returns: zero on success or a negative errno

and "Return:" without the 's'.

This could however be done in a separate patch, as the file is already wrong in this regard.

Regards,
Bjorn

maintainer Reviewed-by on v1 3/6
#22 lore raw
In reply to Johan Hovold
Quoted 47 lines · Johan Hovold

A recent DRM series purporting to simplify support for "transparent bridges" and handling of probe deferrals ironically exposed a use-after-free issue on pmic_glink_altmode probe deferral.

This has manifested itself as the display subsystem occasionally failing to initialise and NULL-pointer dereferences during boot of machines like the Lenovo ThinkPad X13s.

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

When the display controller is later initialised, this triggers a use-after-free when attaching the bridges:

	dp -> aux -> dp-hpd (freed)

which may, for example, result in the freed bridge failing to attach:

[drm:drm_bridge_attach [drm]] *ERROR* failed to attach bridge /soc@0/phy@88eb000 to encoder TMDS-31: -16

or a NULL-pointer dereference:

	Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
	...
	Call trace:
	  drm_bridge_attach+0x70/0x1a8 [drm]
	  drm_aux_bridge_attach+0x24/0x38 [aux_bridge]
	  drm_bridge_attach+0x80/0x1a8 [drm]
	  dp_bridge_init+0xa8/0x15c [msm]
	  msm_dp_modeset_init+0x28/0xc4 [msm]

The DRM bridge implementation is clearly fragile and implicitly built on the assumption that bridges may never go away. In this case, the fix is to move the bridge registration in the pmic_glink_altmode driver to after all resources have been looked up.

Incidentally, with the new dp-hpd bridge implementation, which registers child devices, this is also a requirement due to a long-standing issue in driver core that can otherwise lead to a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Quoted 6 lines
Fixes 080b4e24852b ("soc: qcom: pmic_glink: Introduce altmode support")
Fixes 2bcca96abfbf ("soc: qcom: pmic-glink: switch to DRM_AUX_HPD_BRIDGE")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>

Regards,
Bjorn

Quoted 55 lines
---
 drivers/soc/qcom/pmic_glink_altmode.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/soc/qcom/pmic_glink_altmode.c +13 -3
index 5fcd0fdd2faa..b3808fc24c69 100644
@@ -76,7 +76,7 @@ struct pmic_glink_altmode_port {
 
 	struct work_struct work;
 
-	struct device *bridge;
+	struct auxiliary_device *bridge;
 
 	enum typec_orientation orientation;
 	u16 svid;
@@ -230,7 +230,7 @@ static void pmic_glink_altmode_worker(struct work_struct *work)
 	else
 		pmic_glink_altmode_enable_usb(altmode, alt_port);
 
-	drm_aux_hpd_bridge_notify(alt_port->bridge,
+	drm_aux_hpd_bridge_notify(&alt_port->bridge->dev,
 				  alt_port->hpd_state ?
 				  connector_status_connected :
 				  connector_status_disconnected);
@@ -454,7 +454,7 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		alt_port->index = port;
 		INIT_WORK(&alt_port->work, pmic_glink_altmode_worker);
 
-		alt_port->bridge = drm_dp_hpd_bridge_register(dev, to_of_node(fwnode));
+		alt_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode));
 		if (IS_ERR(alt_port->bridge)) {
 			fwnode_handle_put(fwnode);
 			return PTR_ERR(alt_port->bridge);
@@ -510,6 +510,16 @@ static int pmic_glink_altmode_probe(struct auxiliary_device *adev,
 		}
 	}
 
+	for (port = 0; port < ARRAY_SIZE(altmode->ports); port++) {
+		alt_port = &altmode->ports[port];
+		if (!alt_port->bridge)
+			continue;
+
+		ret = devm_drm_dp_hpd_bridge_add(dev, alt_port->bridge);
+		if (ret)
+			return ret;
+	}
+
 	altmode->client = devm_pmic_glink_register_client(dev,
 							  altmode->owner_id,
 							  pmic_glink_altmode_callback,
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 4/6
#25 lore raw

Re: [PATCH 4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m

In reply to Johan Hovold
Quoted 11 lines · Johan Hovold

From: Rob Clark <[email protected]>

We need to bail out before adding/removing devices if we are going to -EPROBE_DEFER. Otherwise boot can get stuck in a probe deferral loop due to a long-standing issue in driver core (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Deregistering the altmode child device can potentially also trigger bugs in the DRM bridge implementation, which does not expect bridges to go away.

Quoted 8 lines
[ johan: rebase on 6.8-rc4, amend commit message and mention DRM ]
Fixes 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Cc Bjorn Andersson <[email protected]>

Regards,
Bjorn

Quoted 67 lines
---
 drivers/soc/qcom/pmic_glink.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/soc/qcom/pmic_glink.c +11 -10
index f4bfd24386f1..f913e9bd57ed 100644
@@ -265,10 +265,17 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
 	pg->client_mask = *match_data;
 
+	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
+	if (IS_ERR(pg->pdr)) {
+		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr),
+				    "failed to initialize pdr\n");
+		return ret;
+	}
+
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) {
 		ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi");
 		if (ret)
-			return ret;
+			goto out_release_pdr_handle;
 	}
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE)) {
 		ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
@@ -281,17 +288,11 @@ static int pmic_glink_probe(struct platform_device *pdev)
 			goto out_release_altmode_aux;
 	}
 
-	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
-	if (IS_ERR(pg->pdr)) {
-		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr), "failed to initialize pdr\n");
-		goto out_release_aux_devices;
-	}
-
 	service = pdr_add_lookup(pg->pdr, "tms/servreg", "msm/adsp/charger_pd");
 	if (IS_ERR(service)) {
 		ret = dev_err_probe(&pdev->dev, PTR_ERR(service),
 				    "failed adding pdr lookup for charger_pd\n");
-		goto out_release_pdr_handle;
+		goto out_release_aux_devices;
 	}
 
 	mutex_lock(&__pmic_glink_lock);
@@ -300,8 +301,6 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
 	return 0;
 
-out_release_pdr_handle:
-	pdr_handle_release(pg->pdr);
 out_release_aux_devices:
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
 		pmic_glink_del_aux_device(pg, &pg->ps_aux);
@@ -311,6 +310,8 @@ static int pmic_glink_probe(struct platform_device *pdev)
 out_release_ucsi_aux:
 	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
 		pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
+out_release_pdr_handle:
+	pdr_handle_release(pg->pdr);
 
 	return ret;
 }
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 5/6
#30 lore raw

Re: [PATCH 5/6] phy: qcom-qmp-combo: fix drm bridge registration

In reply to Johan Hovold
Quoted 17 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

This could potentially also trigger a bug in the DRM bridge implementation which does not expect bridges to go away even if device links may avoid triggering this (when enabled).

Move registration of the DRM aux bridge to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Quoted 6 lines
Fixes 35921910bbd0 ("phy: qcom: qmp-combo: switch to DRM_AUX_BRIDGE")
Fixes 1904c3f578dc ("phy: qcom-qmp-combo: Introduce drm_bridge")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>

Regards,
Bjorn

Quoted 33 lines
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -4
index 1ad10110dd25..e19d6a084f10 100644
@@ -3566,10 +3566,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = drm_aux_bridge_register(dev);
-	if (ret)
-		return ret;
-
 	/* Check for legacy binding with child nodes. */
 	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
 	if (usb_np) {
@@ -3589,6 +3585,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_node_put;
 
+	ret = drm_aux_bridge_register(dev);
+	if (ret)
+		goto err_node_put;
+
 	pm_runtime_set_active(dev);
 	ret = devm_pm_runtime_enable(dev);
 	if (ret)
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 6/6
#34 lore raw

Re: [PATCH 6/6] phy: qcom-qmp-combo: fix type-c switch registration

In reply to Johan Hovold
Quoted 13 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Move registration of the typec switch to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Quoted 4 lines
Fixes 2851117f8f42 ("phy: qcom-qmp-combo: Introduce orientation switching")
Cc Bjorn Andersson <[email protected]>

Regards,
Bjorn

Quoted 33 lines
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -4
index e19d6a084f10..17c4ad7553a5 100644
@@ -3562,10 +3562,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = qmp_combo_typec_switch_register(qmp);
-	if (ret)
-		return ret;
-
 	/* Check for legacy binding with child nodes. */
 	usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
 	if (usb_np) {
@@ -3585,6 +3581,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_node_put;
 
+	ret = qmp_combo_typec_switch_register(qmp);
+	if (ret)
+		goto err_node_put;
+
 	ret = drm_aux_bridge_register(dev);
 	if (ret)
 		goto err_node_put;
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH 2/6] drm/bridge: aux-hpd: separate allocation and registration

In reply to Bjorn Andersson
Quoted 7 lines · Bjorn Andersson
Quoted 1 line · Johan Hovold
drivers/gpu/drm/bridge/aux-hpd-bridge.c +0 -0

[..]

Quoted 2 lines

+/**
+ * devm_drm_dp_hpd_bridge_add - register a HDP DisplayPort bridge

kernel-doc wants () after function names.

I don't think that's required for the symbol name here even if some subsystems (drivers) use it.

Quoted 6 lines
Quoted 4 lines

+ * @dev: struct device to tie registration lifetime to
+ * @adev: bridge auxiliary device to be registered
+ *
+ * Returns: zero on success or a negative errno

and "Return:" without the 's'.

This was a mistake however. Perhaps whoever applies this can drop it, or I can send a v2.

Side note: Looks like there are more instances with an 's' than without under driver/gpu/drm...

Quoted 4 lines

This could however be done in a separate patch, as the file is already wrong in this regard.

Thanks for reviewing.

Johan

Reviewed-by on v1 2/6
#15 lore raw

Re: [PATCH 2/6] drm/bridge: aux-hpd: separate allocation and registration

In reply to Johan Hovold
Quoted 9 lines · Johan Hovold

Combining allocation and registration is an anti-pattern that should be avoided. Add two new functions for allocating and registering an dp-hpd bridge with a proper 'devm' prefix so that it is clear that these are device managed interfaces.

devm_drm_dp_hpd_bridge_alloc()
devm_drm_dp_hpd_bridge_add()

Quoted 8 lines

The new interface will be used to fix a use-after-free bug in the Qualcomm PMIC GLINK driver and may prevent similar issues from being introduced elsewhere.

The existing drm_dp_hpd_bridge_register() is reimplemented using the above and left in place for now.

Minor nit below.

Quoted 118 lines
---
 drivers/gpu/drm/bridge/aux-hpd-bridge.c | 67 +++++++++++++++++++------
 include/drm/bridge/aux-bridge.h         | 15 ++++++
 2 files changed, 67 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +52 -15
index 9e71daf95bde..6886db2d9e00 100644
@@ -30,16 +30,13 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
        kfree(adev);
 }
 
-static void drm_aux_hpd_bridge_unregister_adev(void *_adev)
+static void drm_aux_hpd_bridge_free_adev(void *_adev)
 {
-       struct auxiliary_device *adev = _adev;
-
-       auxiliary_device_delete(adev);
-       auxiliary_device_uninit(adev);
+       auxiliary_device_uninit(_adev);
 }
 
 /**
- * drm_dp_hpd_bridge_register - Create a simple HPD DisplayPort bridge
+ * devm_drm_dp_hpd_bridge_alloc - allocate a HPD DisplayPort bridge
  * @parent: device instance providing this bridge
  * @np: device node pointer corresponding to this bridge instance
  *
@@ -47,11 +44,9 @@ static void drm_aux_hpd_bridge_unregister_adev(void *_adev)
  * DRM_MODE_CONNECTOR_DisplayPort, which terminates the bridge chain and is
  * able to send the HPD events.
  *
- * Return: device instance that will handle created bridge or an error code
- * encoded into the pointer.
+ * Return: bridge auxiliary device pointer or an error pointer
  */
-struct device *drm_dp_hpd_bridge_register(struct device *parent,
-                                         struct device_node *np)
+struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np)
 {
        struct auxiliary_device *adev;
        int ret;
@@ -82,13 +77,55 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
                return ERR_PTR(ret);
        }
 
-       ret = auxiliary_device_add(adev);
-       if (ret) {
-               auxiliary_device_uninit(adev);
+       ret = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_free_adev, adev);
+       if (ret)
                return ERR_PTR(ret);
-       }
 
-       ret = devm_add_action_or_reset(parent, drm_aux_hpd_bridge_unregister_adev, adev);
+       return adev;
+}
+EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_alloc);
+
+static void drm_aux_hpd_bridge_del_adev(void *_adev)
+{
+       auxiliary_device_delete(_adev);
+}
+
+/**
+ * devm_drm_dp_hpd_bridge_add - register a HDP DisplayPort bridge
+ * @dev: struct device to tie registration lifetime to
+ * @adev: bridge auxiliary device to be registered
+ *
+ * Returns: zero on success or a negative errno
+ */
+int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev)
+{
+       int ret;
+
+       ret = auxiliary_device_add(adev);
+       if (ret)
+               return ret;
+
+       return devm_add_action_or_reset(dev, drm_aux_hpd_bridge_del_adev, adev);
+}
+EXPORT_SYMBOL_GPL(devm_drm_dp_hpd_bridge_add);
+
+/**
+ * drm_dp_hpd_bridge_register - allocate and register a HDP DisplayPort bridge
+ * @parent: device instance providing this bridge
+ * @np: device node pointer corresponding to this bridge instance
+ *
+ * Return: device instance that will handle created bridge or an error pointer
+ */
+struct device *drm_dp_hpd_bridge_register(struct device *parent, struct device_node *np)
+{
+       struct auxiliary_device *adev;
+       int ret;
+
+       adev = devm_drm_dp_hpd_bridge_alloc(parent, np);
+       if (IS_ERR(adev))
+               return ERR_CAST(adev);
+
+       ret = devm_drm_dp_hpd_bridge_add(parent, adev);
        if (ret)
                return ERR_PTR(ret);
 
include/drm/bridge/aux-bridge.h +2 -0
index c4c423e97f06..4453906105ca 100644
@@ -9,6 +9,8 @@
 
 #include <drm/drm_connector.h>
 
+struct auxiliary_device;
+
 #if IS_ENABLED(CONFIG_DRM_AUX_BRIDGE)
 int drm_aux_bridge_register(struct device *parent);
 #else

include/drm/bridge/aux-bridge.h static inline int drm_aux_bridge_register(struct device *parent) · line 25

Quoted 5 lines
include/drm/bridge/aux-bridge.h +2 -0
@@ -19,10 +21,23 @@ static inline int drm_aux_bridge_register(struct device *parent)
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE)
+struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np);
+int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev);

I had a pretty close idea during prototyping, but I ended up doing it as a single function for the following reasons:

First, this exports the implementation detail that internally the code uses an aux device.
Also, by exporting the aux device the code becomes less type-safe. By mistake one can call devm_drm_dp_hpd_bridge_add() on any aux device, which is not necessarily the HPD bridge.
I'd prefer to see an opaque device-specific structure instead. WDYT?

Quoted 21 lines
include/drm/bridge/aux-bridge.h +11 -1
 struct device *drm_dp_hpd_bridge_register(struct device *parent,
                                          struct device_node *np);
 void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status status);
 #else
+static inline struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent,
+                                                                   struct device_node *np)
+{
+       return NULL;
+}
+
+static inline int devm_drm_dp_hpd_bridge_add(struct auxiliary_device *adev)
+{
+       return 0;
+}
+
 static inline struct device *drm_dp_hpd_bridge_register(struct device *parent,
                                                        struct device_node *np)
 {
--

2.43.0

Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 1/6
#9 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

Fixes 6914968a0b52 ("drm/bridge: properly refcount DT nodes in aux bridge drivers")
Cc Dmitry Baryshkov <[email protected]>
Cc Neil Armstrong <[email protected]>
Quoted 3 lines
---
 drivers/gpu/drm/bridge/aux-hpd-bridge.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 3/6
#23 lore raw
In reply to Johan Hovold
Quoted 54 lines · Johan Hovold

A recent DRM series purporting to simplify support for "transparent bridges" and handling of probe deferrals ironically exposed a use-after-free issue on pmic_glink_altmode probe deferral.

This has manifested itself as the display subsystem occasionally failing to initialise and NULL-pointer dereferences during boot of machines like the Lenovo ThinkPad X13s.

Specifically, the dp-hpd bridge is currently registered before all resources have been acquired which means that it can also be deregistered on probe deferrals.

In the meantime there is a race window where the new aux bridge driver (or PHY driver previously) may have looked up the dp-hpd bridge and stored a (non-reference-counted) pointer to the bridge which is about to be deallocated.

When the display controller is later initialised, this triggers a use-after-free when attaching the bridges:

        dp -> aux -> dp-hpd (freed)

which may, for example, result in the freed bridge failing to attach:

[drm:drm_bridge_attach [drm]] *ERROR* failed to attach bridge /soc@0/phy@88eb000 to encoder TMDS-31: -16

or a NULL-pointer dereference:

        Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
        ...
        Call trace:
          drm_bridge_attach+0x70/0x1a8 [drm]
          drm_aux_bridge_attach+0x24/0x38 [aux_bridge]
          drm_bridge_attach+0x80/0x1a8 [drm]
          dp_bridge_init+0xa8/0x15c [msm]
          msm_dp_modeset_init+0x28/0xc4 [msm]

The DRM bridge implementation is clearly fragile and implicitly built on the assumption that bridges may never go away. In this case, the fix is to move the bridge registration in the pmic_glink_altmode driver to after all resources have been looked up.

Incidentally, with the new dp-hpd bridge implementation, which registers child devices, this is also a requirement due to a long-standing issue in driver core that can otherwise lead to a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Fixes 080b4e24852b ("soc: qcom: pmic_glink: Introduce altmode support")
Fixes 2bcca96abfbf ("soc: qcom: pmic-glink: switch to DRM_AUX_HPD_BRIDGE")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
Quoted 4 lines
---
 drivers/soc/qcom/pmic_glink_altmode.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 4/6
#26 lore raw

Re: [PATCH 4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m

In reply to Johan Hovold
Quoted 20 lines · Johan Hovold

From: Rob Clark <[email protected]>

We need to bail out before adding/removing devices if we are going to -EPROBE_DEFER. Otherwise boot can get stuck in a probe deferral loop due to a long-standing issue in driver core (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Deregistering the altmode child device can potentially also trigger bugs in the DRM bridge implementation, which does not expect bridges to go away.

[ johan: rebase on 6.8-rc4, amend commit message and mention DRM ]
Fixes 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Cc Bjorn Andersson <[email protected]>
Quoted 4 lines
---
 drivers/soc/qcom/pmic_glink.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 5/6
#31 lore raw

Re: [PATCH 5/6] phy: qcom-qmp-combo: fix drm bridge registration

In reply to Johan Hovold
Quoted 24 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

This could potentially also trigger a bug in the DRM bridge implementation which does not expect bridges to go away even if device links may avoid triggering this (when enabled).

Move registration of the DRM aux bridge to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Fixes 35921910bbd0 ("phy: qcom: qmp-combo: switch to DRM_AUX_BRIDGE")
Fixes 1904c3f578dc ("phy: qcom-qmp-combo: Introduce drm_bridge")
Cc Bjorn Andersson <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
Quoted 4 lines
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 6/6
#35 lore raw

Re: [PATCH 6/6] phy: qcom-qmp-combo: fix type-c switch registration

In reply to Johan Hovold
Quoted 14 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Move registration of the typec switch to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Quoted 7 lines
Fixes 2851117f8f42 ("phy: qcom-qmp-combo: Introduce orientation switching")
Cc Bjorn Andersson <[email protected]>
---
 drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Note to myself (or to anybody else, who has spare hands), we should probably implement the same changes for phy-qcom-qmp-usbc.c

Quoted 30 lines
drivers/phy/qualcomm/phy-qcom-qmp-combo.c +4 -5
index e19d6a084f10..17c4ad7553a5 100644
@@ -3562,10 +3562,6 @@ static int qmp_combo_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
-       ret = qmp_combo_typec_switch_register(qmp);
-       if (ret)
-               return ret;
-
        /* Check for legacy binding with child nodes. */
        usb_np = of_get_child_by_name(dev->of_node, "usb3-phy");
        if (usb_np) {
@@ -3585,6 +3581,10 @@ static int qmp_combo_probe(struct platform_device *pdev)
        if (ret)
                goto err_node_put;
 
+       ret = qmp_combo_typec_switch_register(qmp);
+       if (ret)
+               goto err_node_put;
+
        ret = drm_aux_bridge_register(dev);
        if (ret)
                goto err_node_put;
--

2.43.0

Signature · 2 lines
With best wishes
Dmitry
maintainer Reviewed-by on v1 1/6
#10 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 24 lines · Johan Hovold

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

Fixes 6914968a0b52 ("drm/bridge: properly refcount DT nodes in aux bridge drivers")
Cc Dmitry Baryshkov <[email protected]>
Cc Neil Armstrong <[email protected]>
---
  drivers/gpu/drm/bridge/aux-hpd-bridge.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +1 -0
index bb55f697a181..9e71daf95bde 100644
@@ -25,6 +25,7 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
  	ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 
  	of_node_put(adev->dev.platform_data);
+	of_node_put(adev->dev.of_node);
 
  	kfree(adev);
  }

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
  	ret = auxiliary_device_init(adev);
  	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
  		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
  		kfree(adev);
  		return ERR_PTR(ret);
maintainer Reviewed-by on v1 1/6
#11 lore raw

Re: [PATCH 1/6] drm/bridge: aux-hpd: fix OF node leaks

In reply to Johan Hovold
Quoted 24 lines · Johan Hovold

The two device node references taken during allocation need to be dropped when the auxiliary device is freed.

Fixes 6914968a0b52 ("drm/bridge: properly refcount DT nodes in aux bridge drivers")
Cc Dmitry Baryshkov <[email protected]>
Cc Neil Armstrong <[email protected]>
---
  drivers/gpu/drm/bridge/aux-hpd-bridge.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/aux-hpd-bridge.c +1 -0
index bb55f697a181..9e71daf95bde 100644
@@ -25,6 +25,7 @@ static void drm_aux_hpd_bridge_release(struct device *dev)
  	ida_free(&drm_aux_hpd_bridge_ida, adev->id);
 
  	of_node_put(adev->dev.platform_data);
+	of_node_put(adev->dev.of_node);
 
  	kfree(adev);
  }

drivers/gpu/drm/bridge/aux-hpd-bridge.c struct device *drm_dp_hpd_bridge_register(struct device *parent, · line 82

Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-bridge.c +2 -0
@@ -74,6 +75,8 @@ struct device *drm_dp_hpd_bridge_register(struct device *parent,
 
  	ret = auxiliary_device_init(adev);
  	if (ret) {
+		of_node_put(adev->dev.platform_data);
+		of_node_put(adev->dev.of_node);
  		ida_free(&drm_aux_hpd_bridge_ida, adev->id);
  		kfree(adev);
  		return ERR_PTR(ret);
maintainer Applied
#37 lore raw
In reply to Johan Hovold

Hi,

Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

      https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Signature · 1 line
Neil
maintainer
#38 lore raw
Quoted 18 lines · Neil Armstrong

Hi,

Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

       https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

To clarify, I only applied patch 1 to drm-misc-fixes

Thanks,
Neil

maintainer Reviewed-by on v1 4/6
#27 lore raw

Re: [PATCH 4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m

In reply to Johan Hovold
Quoted 75 lines · Johan Hovold

From: Rob Clark <[email protected]>

We need to bail out before adding/removing devices if we are going to -EPROBE_DEFER. Otherwise boot can get stuck in a probe deferral loop due to a long-standing issue in driver core (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Deregistering the altmode child device can potentially also trigger bugs in the DRM bridge implementation, which does not expect bridges to go away.

[ johan: rebase on 6.8-rc4, amend commit message and mention DRM ]
Fixes 58ef4ece1e41 ("soc: qcom: pmic_glink: Introduce base PMIC GLINK driver")
Cc Bjorn Andersson <[email protected]>
---
  drivers/soc/qcom/pmic_glink.c | 21 +++++++++++----------
  1 file changed, 11 insertions(+), 10 deletions(-)
drivers/soc/qcom/pmic_glink.c +9 -10
index f4bfd24386f1..f913e9bd57ed 100644
@@ -265,10 +265,17 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
  	pg->client_mask = *match_data;
 
+	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
+	if (IS_ERR(pg->pdr)) {
+		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr),
+				    "failed to initialize pdr\n");
+		return ret;
+	}
+
  	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) {
  		ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi");
  		if (ret)
-			return ret;
+			goto out_release_pdr_handle;
  	}
  	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE)) {
  		ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
@@ -281,17 +288,11 @@ static int pmic_glink_probe(struct platform_device *pdev)
  			goto out_release_altmode_aux;
  	}
 
-	pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
-	if (IS_ERR(pg->pdr)) {
-		ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr), "failed to initialize pdr\n");
-		goto out_release_aux_devices;
-	}
-
  	service = pdr_add_lookup(pg->pdr, "tms/servreg", "msm/adsp/charger_pd");
  	if (IS_ERR(service)) {
  		ret = dev_err_probe(&pdev->dev, PTR_ERR(service),
  				    "failed adding pdr lookup for charger_pd\n");
-		goto out_release_pdr_handle;
+		goto out_release_aux_devices;
  	}
 
  	mutex_lock(&__pmic_glink_lock);
@@ -300,8 +301,6 @@ static int pmic_glink_probe(struct platform_device *pdev)
 
  	return 0;
 
-out_release_pdr_handle:
-	pdr_handle_release(pg->pdr);
  out_release_aux_devices:
  	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
  		pmic_glink_del_aux_device(pg, &pg->ps_aux);

drivers/soc/qcom/pmic_glink.c static int pmic_glink_probe(struct platform_device *pdev) · line 317

Quoted 8 lines
drivers/soc/qcom/pmic_glink.c +2 -0
@@ -311,6 +310,8 @@ static int pmic_glink_probe(struct platform_device *pdev)
  out_release_ucsi_aux:
  	if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
  		pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
+out_release_pdr_handle:
+	pdr_handle_release(pg->pdr);
 
  	return ret;
  }
maintainer Acked-by on v1 5/6
#32 lore raw

Re: [PATCH 5/6] phy: qcom-qmp-combo: fix drm bridge registration

In reply to Johan Hovold
Quoted 9 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

This could potentially also trigger a bug in the DRM bridge implementation which does not expect bridges to go away even if device links may avoid triggering this (when enabled).

Quoted 7 lines

Move registration of the DRM aux bridge to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Signature · 1 line
~Vinod
maintainer Acked-by on v1 6/6
#36 lore raw

Re: [PATCH 6/6] phy: qcom-qmp-combo: fix type-c switch registration

In reply to Johan Hovold
Quoted 5 lines · Johan Hovold

Due to a long-standing issue in driver core, drivers may not probe defer after having registered child devices to avoid triggering a probe deferral loop (see fbc35b45f9f6 ("Add documentation on meaning of -EPROBE_DEFER")).

Quoted 7 lines

Move registration of the typec switch to after looking up clocks and other resources.

Note that PHY creation can in theory also trigger a probe deferral when a 'phy' supply is used. This does not seem to affect the QMP PHY driver but the PHY subsystem should be reworked to address this (i.e. by separating initialisation and registration of the PHY).

Signature · 1 line
~Vinod
#16 lore raw

Re: [PATCH 2/6] drm/bridge: aux-hpd: separate allocation and registration

In reply to Dmitry Baryshkov
Quoted 14 lines · Dmitry Baryshkov
Quoted 13 lines · Johan Hovold

Combining allocation and registration is an anti-pattern that should be avoided. Add two new functions for allocating and registering an dp-hpd bridge with a proper 'devm' prefix so that it is clear that these are device managed interfaces.

devm_drm_dp_hpd_bridge_alloc()
devm_drm_dp_hpd_bridge_add()

The new interface will be used to fix a use-after-free bug in the Qualcomm PMIC GLINK driver and may prevent similar issues from being introduced elsewhere.

Quoted 6 lines
Quoted 4 lines

The existing drm_dp_hpd_bridge_register() is reimplemented using the above and left in place for now.

Thanks for reviewing.

Quoted 25 lines

Minor nit below.

Quoted 14 lines
include/drm/bridge/aux-bridge.h +2 -0
index c4c423e97f06..4453906105ca 100644
@@ -9,6 +9,8 @@
 
 #include <drm/drm_connector.h>
 
+struct auxiliary_device;
+
 #if IS_ENABLED(CONFIG_DRM_AUX_BRIDGE)
 int drm_aux_bridge_register(struct device *parent);
 #else

include/drm/bridge/aux-bridge.h static inline int drm_aux_bridge_register(struct device *parent) · line 25

Quoted 5 lines
include/drm/bridge/aux-bridge.h +2 -0
@@ -19,10 +21,23 @@ static inline int drm_aux_bridge_register(struct device *parent)
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE)
+struct auxiliary_device *devm_drm_dp_hpd_bridge_alloc(struct device *parent, struct device_node *np);
+int devm_drm_dp_hpd_bridge_add(struct device *dev, struct auxiliary_device *adev);

I had a pretty close idea during prototyping, but I ended up doing it as a single function for the following reasons:

Quoted 2 lines

First, this exports the implementation detail that internally the code uses an aux device.

That's not an issue. The opposite, with interfaces trying to do too much and hide details from the developers so that they can no longer reason about what is going on, is a real problem though.

Quoted 3 lines

Also, by exporting the aux device the code becomes less type-safe. By mistake one can call devm_drm_dp_hpd_bridge_add() on any aux device, which is not necessarily the HPD bridge.

No. First, that is currently not even an issue either as the registration interface is safe to use with any aux device.

Second, if you cared about about type-safety you wouldn't have used a struct device pointer for drm_aux_hpd_bridge_notify() which you back cast to an aux device.

Quoted 1 line

I'd prefer to see an opaque device-specific structure instead. WDYT?

That should have been there from the start. But I'm not interested in cleaning up this mess beyond what is minimally required to fix the regressions it caused.

This can be reworked for 6.9 or later.

Quoted 3 lines

include/drm/bridge/aux-bridge.h static inline int drm_aux_bridge_register(struct device *parent) · line 28

Quoted 3 lines
include/drm/bridge/aux-bridge.h +0 -0
 struct device *drm_dp_hpd_bridge_register(struct device *parent,
                                          struct device_node *np);
 void drm_aux_hpd_bridge_notify(struct device *dev, enum drm_connector_status status);

Johan

#39 lore raw
In reply to Neil Armstrong
Quoted 31 lines · Neil Armstrong
Quoted 18 lines · Neil Armstrong

Hi,

Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

       https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

With Vinod acking the PHY patches, I believe you have what you need to merge the whole series now?

Johan

maintainer
#40 lore raw
Quoted 32 lines · Johan Hovold
Quoted 31 lines · Neil Armstrong
Quoted 29 lines · Neil Armstrong

Hi,

Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

        https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 8 lines
Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

I only applied patch 1, which is a standalone fix and goes into a separate tree, for the next patches it would be indeed simpler for them to go via drm-misc when they are properly acked.

Neil

Quoted 5 lines

With Vinod acking the PHY patches, I believe you have what you need to merge the whole series now?

Johan

#41 lore raw
Quoted 38 lines · Neil Armstrong
Quoted 36 lines · Johan Hovold
Quoted 31 lines · Neil Armstrong
Quoted 18 lines · Neil Armstrong

Hi,

Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

        https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

Quoted 8 lines
Quoted 4 lines

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

I only applied patch 1, which is a standalone fix and goes into a separate tree, for the next patches it would be indeed simpler for them to go via drm-misc when they are properly acked.

I think PHY patches can go through a usual route (phy/next or phy/fixes). For patches 3 and 4 I'd need an ack from Bjorn to merge them through drm-misc-next or drm-misc-fixes.

Signature · 2 lines
With best wishes
Dmitry
#43 lore raw
In reply to Neil Armstrong
Quoted 24 lines · Neil Armstrong
Quoted 23 lines · Johan Hovold
Quoted 18 lines · Neil Armstrong
Quoted 4 lines · Neil Armstrong

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

        https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

Quoted 8 lines
Quoted 4 lines

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

I only applied patch 1, which is a standalone fix and goes into a separate tree, for the next patches it would be indeed simpler for them to go via drm-misc when they are properly acked.

But it is *not* standalone as I tried to explain above.

So you have to drop it again as the later patches depend on it and cannot be merged (through a different tree) without it.

I thought you had all the acks you needed to take this through drm-misc, but we can wait a bit more if necessary (and there's no rush to get the first one in).

Johan

#42 lore raw
In reply to Dmitry Baryshkov
Quoted 30 lines · Dmitry Baryshkov
Quoted 29 lines · Neil Armstrong
Quoted 27 lines · Johan Hovold
Quoted 18 lines · Neil Armstrong
Quoted 4 lines · Neil Armstrong

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

        https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

Quoted 6 lines
Quoted 3 lines

I only applied patch 1, which is a standalone fix and goes into a separate tree, for the next patches it would be indeed simpler for them to go via drm-misc when they are properly acked.

I think PHY patches can go through a usual route (phy/next or phy/fixes).

They can, but I've explicitly asked Vinod to ack them so that they can go in with the rest of the series through DRM.

They also fix a regression that came in through DRM in 6.8-rc1 (the bridge rework which started registering child devices) so it makes sense to also route the fix the same way. And to do it for this cycle.

Quoted 2 lines

For patches 3 and 4 I'd need an ack from Bjorn to merge them through drm-misc-next or drm-misc-fixes.

You have Bjorn's ack. He's reviewed all the patches for this purpose and we discussed this in person two days ago.

And, again, this has to go in for *this* cycle. You broke the display on the X13s and other machines so this cannot wait for 6.9.

Johan

maintainer
#44 lore raw
In reply to Johan Hovold
Quoted 30 lines · Johan Hovold
Quoted 29 lines · Neil Armstrong
Quoted 27 lines · Johan Hovold
Quoted 18 lines · Neil Armstrong
Quoted 4 lines · Neil Armstrong

Thanks, Applied to https://anongit.freedesktop.org/git/drm/drm-misc.git (drm-misc-fixes)

[1/6] drm/bridge: aux-hpd: fix OF node leaks

         https://cgit.freedesktop.org/drm/drm-misc/commit/?id=9ee485bdda68d6d3f5728cbe3150eb9013d7d22b
Quoted 11 lines

[2/6] drm/bridge: aux-hpd: separate allocation and registration
(no commit info)
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
(no commit info)
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
(no commit info)
[5/6] phy: qcom-qmp-combo: fix drm bridge registration
(no commit info)
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
(no commit info)

Quoted 1 line

To clarify, I only applied patch 1 to drm-misc-fixes

Ok, but can you please not do that? :)

These patches should go in through the same tree to avoid conflicts.

I discussed this with Bjorn and Dmitry the other day and the conclusion was that it was easiest to take all of these through DRM.

Quoted 8 lines
Quoted 3 lines

I only applied patch 1, which is a standalone fix and goes into a separate tree, for the next patches it would be indeed simpler for them to go via drm-misc when they are properly acked.

But it is *not* standalone as I tried to explain above.

So you have to drop it again as the later patches depend on it and cannot be merged (through a different tree) without it.

drm-misc branches cannot be rebased, it must be reverted, but it can still be applied on drm-misc-next and I'll send a revert patch for drm-misc-fixes if needed, not a big deal.

Quoted 3 lines

I thought you had all the acks you needed to take this through drm-misc, but we can wait a bit more if necessary (and there's no rush to get the first one in).

If you want it to be in v6.9, it's too late since the last drm-misc-next PR has been sent yesterday (https://cgit.freedesktop.org/drm/drm-misc/tag/?h=drm-misc-next-2024-02-22)

Please ping Thomas or Maxime, perhaps it's not too late since the drm-misc-next tree really closes on sunday.

Neil

Quoted 2 lines

Johan

#45 lore raw
Quoted 14 lines · Neil Armstrong
Quoted 4 lines · Johan Hovold

But it is *not* standalone as I tried to explain above.

So you have to drop it again as the later patches depend on it and cannot be merged (through a different tree) without it.

drm-misc branches cannot be rebased, it must be reverted, but it can still be applied on drm-misc-next and I'll send a revert patch for drm-misc-fixes if needed, not a big deal.

Quoted 3 lines

I thought you had all the acks you needed to take this through drm-misc, but we can wait a bit more if necessary (and there's no rush to get the first one in).

Quoted 5 lines

If you want it to be in v6.9, it's too late since the last drm-misc-next PR has been sent yesterday (https://cgit.freedesktop.org/drm/drm-misc/tag/?h=drm-misc-next-2024-02-22)

Please ping Thomas or Maxime, perhaps it's not too late since the drm-misc-next tree really closes on sunday.

I don't want this in 6.9, this is needed for *6.8* as this fixes a DRM regression in 6.8-rc1 that breaks the display on machines like the X13s.

If you guys can't sort this out in time, then perhaps Bjorn can take this through the Qualcomm tree instead (with DRM acks).

But again, this is fixing a severe *regression* in 6.8-rc1. It can not wait for 6.9.

Johan

maintainer Acked-by on the v1 series
#48 lore raw
In reply to Johan Hovold
Quoted 48 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

The intermittent hard resets that have also been reported since 6.8-rc1 unfortunately still remains and suggests that we are dealing with two separate regressions. There is some indication that also the hard resets (e.g. due to register accesses to unclocked hardware) are also due to changes in the DRM subsystem as it happens around the time that the eDP panel and display controller would be initialised during boot (the runtime PM rework?). This remains to be verified, however.

Included is also a fix for a related OF node reference leak in the aux-hpd driver found through inspection when reworking the driver.

The use-after-free bug is triggered by a probe deferral and highlighted some further bugs in the involved drivers, which were registering child devices before deferring probe. This behaviour is not correct and can both trigger probe deferral loops and potentially also further issues with the DRM bridge implementation.

This series can either go through the Qualcomm SoC tree (pmic_glink) or the DRM tree. The PHY patches do not depend on the rest of the series and could possibly be merged separately through the PHY tree.

Whichever gets this to mainline the fastest.

Johan

[1] https://lore.kernel.org/lkml/[email protected]/

Johan Hovold (5):
drm/bridge: aux-hpd: fix OF node leaks
drm/bridge: aux-hpd: separate allocation and registration
soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
phy: qcom-qmp-combo: fix drm bridge registration
phy: qcom-qmp-combo: fix type-c switch registration

Rob Clark (1):
soc: qcom: pmic_glink: Fix boot when QRTR=m

Quoted 7 lines
  drivers/gpu/drm/bridge/aux-hpd-bridge.c   | 70 ++++++++++++++++++-----
  drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 16 +++---
  drivers/soc/qcom/pmic_glink.c             | 21 +++----
  drivers/soc/qcom/pmic_glink_altmode.c     | 16 +++++-
  include/drm/bridge/aux-bridge.h           | 15 +++++
  5 files changed, 102 insertions(+), 36 deletions(-)

For the serie:

After an offline discussion, Dmitry, it's ok to push the remaining patches to drm-misc-fixes.

Thanks,
Neil

maintainer
#46 lore raw
In reply to Johan Hovold
Quoted 21 lines · Johan Hovold
Quoted 14 lines · Neil Armstrong
Quoted 4 lines · Johan Hovold

But it is *not* standalone as I tried to explain above.

So you have to drop it again as the later patches depend on it and cannot be merged (through a different tree) without it.

drm-misc branches cannot be rebased, it must be reverted, but it can still be applied on drm-misc-next and I'll send a revert patch for drm-misc-fixes if needed, not a big deal.

Quoted 3 lines

I thought you had all the acks you needed to take this through drm-misc, but we can wait a bit more if necessary (and there's no rush to get the first one in).

Quoted 5 lines

If you want it to be in v6.9, it's too late since the last drm-misc-next PR has been sent yesterday (https://cgit.freedesktop.org/drm/drm-misc/tag/?h=drm-misc-next-2024-02-22)

Please ping Thomas or Maxime, perhaps it's not too late since the drm-misc-next tree really closes on sunday.

Quoted 8 lines

I don't want this in 6.9, this is needed for *6.8* as this fixes a DRM regression in 6.8-rc1 that breaks the display on machines like the X13s.

If you guys can't sort this out in time, then perhaps Bjorn can take this through the Qualcomm tree instead (with DRM acks).

But again, this is fixing a severe *regression* in 6.8-rc1. It can not wait for 6.9.

Right, I can't apply them right now, I send a patchset ack so it can be applied ASAP,

Thanks,
Neil

Quoted 2 lines

Johan

#49 lore raw

Re: (subset) [PATCH 0/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free

In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Applied to drm-misc-fixes, thanks!

[2/6] drm/bridge: aux-hpd: separate allocation and registration

      commit: e5ca263508f7e9d2cf711edf3258d11ca087885c
[3/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free
      commit: b979f2d50a099f3402418d7ff5f26c3952fb08bb
[4/6] soc: qcom: pmic_glink: Fix boot when QRTR=m
      commit: f79ee78767ca60e7a2c89eacd2dbdf237d97e838

Note, PHY patches (5,6) do not have dependency on the drm patch, so they can go through the phy/fixes tree.

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>
#47 lore raw
In reply to Neil Armstrong
Quoted 26 lines · Neil Armstrong
Quoted 24 lines · Johan Hovold
Quoted 14 lines · Neil Armstrong
Quoted 4 lines · Johan Hovold

But it is *not* standalone as I tried to explain above.

So you have to drop it again as the later patches depend on it and cannot be merged (through a different tree) without it.

drm-misc branches cannot be rebased, it must be reverted, but it can still be applied on drm-misc-next and I'll send a revert patch for drm-misc-fixes if needed, not a big deal.

Quoted 3 lines

I thought you had all the acks you needed to take this through drm-misc, but we can wait a bit more if necessary (and there's no rush to get the first one in).

Quoted 5 lines

If you want it to be in v6.9, it's too late since the last drm-misc-next PR has been sent yesterday (https://cgit.freedesktop.org/drm/drm-misc/tag/?h=drm-misc-next-2024-02-22)

Please ping Thomas or Maxime, perhaps it's not too late since the drm-misc-next tree really closes on sunday.

I don't want this in 6.9, this is needed for *6.8* as this fixes a DRM regression in 6.8-rc1 that breaks the display on machines like the X13s.

Quoted 7 lines
Quoted 5 lines

If you guys can't sort this out in time, then perhaps Bjorn can take this through the Qualcomm tree instead (with DRM acks).

But again, this is fixing a severe *regression* in 6.8-rc1. It can not wait for 6.9.

Right, I can't apply them right now, I send a patchset ack so it can be applied ASAP,

Applied and pushed patches 2-4. Patches 5 and 6 can go through the phy/fixes. There is no need for them to go through drm-misc tree.

Signature · 2 lines
With best wishes
Dmitry
maintainer Applied
#50 lore raw

Re: (subset) [PATCH 0/6] soc: qcom: pmic_glink_altmode: fix drm bridge use-after-free

In reply to Johan Hovold
Quoted 10 lines · Johan Hovold

Starting with 6.8-rc1 the internal display sometimes fails to come up on machines like the Lenovo ThinkPad X13s and the logs indicate that this is due to a regression in the DRM subsystem [1].

This series fixes a race in the pmic_glink_altmode driver which was exposed / triggered by the transparent DRM bridges rework that went into 6.8-rc1 and that manifested itself as a bridge failing to attach and sometimes triggering a NULL-pointer dereference.

[...]

Applied, thanks!

[5/6] phy: qcom-qmp-combo: fix drm bridge registration

      commit: d2d7b8e88023b75320662c2305d61779ff060950
[6/6] phy: qcom-qmp-combo: fix type-c switch registration
      commit: 47b412c1ea77112f1148b4edd71700a388c7c80f

Best regards,

Signature · 1 line
~Vinod