Skip to contentSkip to conversation

drm/msm: Fix separate_gpu_kms for multi-gpu

PATCH New Rob Clark 2 participants 2 messages Dec 3

Subsystems (4)
lore
Share & tools
lore

Rob Clark

author maintainer
#0 lore raw

PATCH v2 1/1 drm/msm: Fix separate_gpu_kms for multi-gpu

The auto mode was falling back to separate devices if the # of GPUs or # of displays was greater than 1. Rework this so that we pair up displays and GPUs until we run out of one or the other, and then create standalone devices for anything remaining.

---
 drivers/gpu/drm/msm/adreno/adreno_device.c |  4 +-
 drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c   |  9 ++-
 drivers/gpu/drm/msm/msm_drv.c              | 91 ++++++++++++++--------
 drivers/gpu/drm/msm/msm_drv.h              | 10 +--
 drivers/gpu/drm/msm/msm_mdss.c             |  9 ++-
 5 files changed, 79 insertions(+), 44 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_device.c +2 -2
index a3b2440a1a27..bf401dcceb30 100644
@@ -272,7 +272,7 @@ static int adreno_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	if (!msm_separate_gpu_kms_components())
+	if (!msm_separate_gpu_kms_components(&pdev->dev, true))
 		return component_add(&pdev->dev, &a3xx_ops);
 
 	if (!adreno_has_gpu(pdev->dev.of_node))
@@ -292,7 +292,7 @@ static int adreno_probe(struct platform_device *pdev)
 static void adreno_remove(struct platform_device *pdev)
 {
 	component_del(&pdev->dev, &a3xx_ops);
-	if (msm_separate_gpu_kms_components())
+	if (msm_separate_gpu_kms_components(&pdev->dev, true))
 		msm_gpu_remove(pdev);
 }
 
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +7 -2
index ad08a040982f..8bff3a075c79 100644
@@ -16,14 +16,19 @@
 #include "mdp4_kms.h"
 
 static const struct of_device_id mdp4_dt_match[];
-int msm_count_mdp4(void)
+int msm_count_mdp4(struct device_node *target_np)
 {
 	struct device_node *np;
 	int count = 0;
 
 	for_each_matching_node(np, mdp4_dt_match) {
-		if (of_device_is_available(np))
+		if (of_device_is_available(np)) {
 			count++;
+			if (target_np == np) {
+				of_node_put(np);
+				return count;
+			}
+		}
 	}
 
 	return count;
drivers/gpu/drm/msm/msm_drv.c +58 -33

142 lines not on this page · raw message

drivers/gpu/drm/msm/msm_drv.h +5 -5
index b65702ac0140..628eb9965704 100644
@@ -394,11 +394,11 @@ static inline bool msm_dp_wide_bus_available(const struct msm_dp *dp_display)
 #ifdef CONFIG_DRM_MSM_MDP4
 void msm_mdp4_register(void);
 void msm_mdp4_unregister(void);
-int msm_count_mdp4(void);
+int msm_count_mdp4(struct device_node *target_np);
 #else
 static inline void msm_mdp4_register(void) {}
 static inline void msm_mdp4_unregister(void) {}
-static inline int msm_count_mdp4(void) { return 0; }
+static inline int msm_count_mdp4(struct device_node *target_np) { return 0; }
 #endif
 
 #ifdef CONFIG_DRM_MSM_MDP5
@@ -420,11 +420,11 @@ static inline void msm_dpu_unregister(void) {}
 #ifdef CONFIG_DRM_MSM_MDSS
 void msm_mdss_register(void);
 void msm_mdss_unregister(void);
-int msm_count_mdss(void);
+int msm_count_mdss(struct device_node *target_np);
 #else
 static inline void msm_mdss_register(void) {}
 static inline void msm_mdss_unregister(void) {}
-static inline int msm_count_mdss(void) { return 0; }
+static inline int msm_count_mdss(struct device_node *target_np) { return 0; }
 #endif
 
 #ifdef CONFIG_DEBUG_FS
@@ -539,6 +539,6 @@ void msm_kms_shutdown(struct platform_device *pdev);
 
 bool msm_disp_drv_should_bind(struct device *dev, bool dpu_driver);
 
-bool msm_separate_gpu_kms_components(void);
+bool msm_separate_gpu_kms_components(struct device *dev, bool is_gpu);
 
 #endif /* __MSM_DRV_H__ */
drivers/gpu/drm/msm/msm_mdss.c +7 -2
index fb0261ae9c78..506ae31c5587 100644
@@ -77,14 +77,19 @@ static int msm_mdss_parse_data_bus_icc_path(struct device *dev,
 
 static const struct of_device_id mdss_dt_match[];
 
-int msm_count_mdss(void)
+int msm_count_mdss(struct device_node *target_np)
 {
 	struct device_node *np;
 	int count = 0;
 
 	for_each_matching_node(np, mdss_dt_match) {
-		if (of_device_is_available(np))
+		if (of_device_is_available(np)) {
 			count++;
+			if (target_np == np) {
+				of_node_put(np);
+				return count;
+			}
+		}
 	}
 
 	return count;
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [Medium] drm/msm: spurious GPU matches and missing break in msm_drv_probe() - [Medium] drm/msm…

Thank you for your contribution! Sashiko AI review found 6 potential issues to consider:
- [Medium] drm/msm: spurious GPU matches and missing break in msm_drv_probe()
- [Medium] drm/msm: msm_count_gpus() miss lets adreno_probe() bind unrecognized GPUs
- [Low] drm/msm: leftover pr_err() debug logging in msm_drv.c
- [Low] drm/msm: missing of_node_put() on error return in msm_drv_probe()
- [Low] drm/msm: undocumented revert of separate_gpu_kms from tristate int to bool
- [Low] drm/msm: missing Fixes trailer for cf27afc3bd6e
--

commit 822067c1eca76ec23892df78b025e01b4a98f7fc
Author: Rob Clark <[email protected]>

Quoted 8 lines

drm/msm: Fix separate_gpu_kms for multi-gpu

The auto mode was falling back to separate devices if the # of GPUs or # of displays was greater than 1. Rework this so that we pair up displays and GPUs until we run out of one or the other, and then create standalone devices for anything remaining.

[Severity: Low]
This fixes the auto-selection logic introduced by commit cf27afc3bd6e ("drm/msm: default separate_gpu_kms to auto selection"). Should it include:

Fixes cf27afc3bd6e ("drm/msm: default separate_gpu_kms to auto selection")

drivers/gpu/drm/msm/adreno/adreno_device.c static int adreno_probe(struct platform_device *pdev) · line 276

Quoted 13 lines
drivers/gpu/drm/msm/adreno/adreno_device.c +1 -1
index eb96a2b35518b..64b9824011287 100644
@@ -270,7 +270,7 @@ static int adreno_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	if (!msm_separate_gpu_kms_components())
+	if (!msm_separate_gpu_kms_components(&pdev->dev, true))
 		return component_add(&pdev->dev, &a3xx_ops);
 
 	if (!adreno_has_gpu(pdev->dev.of_node))

[Severity: Medium]
Can adreno_probe() now bind an unrecognized GPU instead of returning -ENODEV?

When an enabled GPU node fails adreno_has_gpu() (such as an unknown chip ID), msm_count_gpus(dev->of_node) skips it and falls through to return the total count of other recognized GPUs (0 on a single-GPU SoC). With the previous msm_count_gpus() == 0 guard removed, gpu_idx > num_disp is false whenever that count is at most num_disp, so adreno_probe() returns component_add() with 0 and registers an orphaned component.

Checking adreno_has_gpu() before msm_separate_gpu_kms_components() in adreno_probe() avoids binding unrecognized GPUs, and returning 0 when a non-NULL target_np is not found in msm_count_gpus(), msm_count_mdp4(), and msm_count_mdss() avoids returning the total count on a lookup miss.

[ ... ]

Quoted 15 lines
drivers/gpu/drm/msm/msm_drv.c +2 -5
index cd59daa02bf94..f7a0d43cd06b1 100644
@@ -56,16 +56,15 @@ MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disab
 module_param(modeset, bool, 0600);
 
 /*
- * separate_gpu_kms (tristate):
- *   -1 (default): decide automatically based on hardware topology. Split devices
- *                 if there is more than one GPU or more than one display master.
- *    0: force single DRM device (bind display + GPU)
- *    1: force separate DRM devices
+ * When not using separate gpu and kms devices, the display and gpu devices
+ * are #'d, with the n'th gpu being paired off with the n'th display, until

drivers/gpu/drm/msm/msm_drv.c MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disab · line 67

Quoted 10 lines
drivers/gpu/drm/msm/msm_drv.c +5 -3
+ * we run out of gpu or display devices at which point any remaining devices
+ * are stand-alone (ie. either gpu-only or display-only).
  */
-static int separate_gpu_kms = -1;
+static bool separate_gpu_kms = 0;
 MODULE_PARM_DESC(separate_gpu_kms,
-		 "Use separate DRM device for the GPU (-1=auto (default), 0=single DRM device, 1=separate DRM devices)");
-module_param(separate_gpu_kms, int, 0400);
+		 "Use separate DRM device for the GPU (0=single DRM device per pair of GPU+DPU, 1=separate DRM devices)");
+module_param(separate_gpu_kms, bool, 0400);

[Severity: Low]
Should the commit message explain changing separate_gpu_kms back from a tristate int to a bool and removing the -1 value? This also shifts multi-display single-GPU systems from separate devices to one combined GPU+display device plus standalone display-only devices. Also, static bool separate_gpu_kms does not need the explicit = 0 initializer.

[ ... ]

Quoted 5 lines
drivers/gpu/drm/msm/msm_drv.c +5 -0
+	if (is_gpu) {
+		int gpu_idx = msm_count_gpus(dev->of_node);
+		int num_disp = msm_count_mdp4(NULL) + msm_count_mdss(NULL);
+
+		pr_err("%s: gpu: %u > %u\n", __func__, gpu_idx, num_disp);

drivers/gpu/drm/msm/msm_drv.c static inline bool msm_gpu_node_present(struct device_node *np) · line 147

Quoted 10 lines
drivers/gpu/drm/msm/msm_drv.c +9 -0
+
+		return gpu_idx > num_disp;
+	} else {
+		int num_gpu = msm_count_gpus(NULL);
+		int disp_idx = msm_display_idx(dev);
+
+		pr_err("%s: display: %u > %u\n", __func__, disp_idx, num_gpu);
+
+		return disp_idx > num_gpu;
 	}

[Severity: Low]
Are these pr_err() calls (and the pr_err() in msm_drv_probe()) leftover debug prints? They log at KERN_ERR on every normal probe, bind, and remove, format signed int values with %u, and the one in msm_drv_probe() uses of_node_full_name() instead of %pOF.

[ ... ]

drivers/gpu/drm/msm/msm_drv.c int msm_drv_probe(struct device *master_dev, · line 1190

Quoted 7 lines
drivers/gpu/drm/msm/msm_drv.c +7 -0
+			/* If we are the display, try adding the matching gpu: */
+			for_each_matching_node (np, msm_gpu_match) {
+				if (disp_idx != msm_count_gpus(np))
+					continue;
+				ret = add_gpu_components(master_dev, np, &match);
+				if (ret)
+					return ret;

[Severity: Low]
Does this early return leak the reference on np held by for_each_matching_node()? add_gpu_components() currently always returns 0, so the leak is latent, but it should call of_node_put(np) before returning.

drivers/gpu/drm/msm/msm_drv.c int msm_drv_probe(struct device *master_dev, · line 1194

Quoted 4 lines
drivers/gpu/drm/msm/msm_drv.c +4 -0
+				pr_err("%s: matched: %s + %s\n", __func__,
+					of_node_full_name(master_dev->of_node),
+					of_node_full_name(np));
+			}

[Severity: Medium]
Can this loop spuriously match disabled or unsupported GPU nodes?

When np is disabled or rejected by adreno_has_gpu(), msm_count_gpus(np) falls through and returns the total number of present GPUs. For the display whose disp_idx equals that total, disp_idx == msm_count_gpus(np) matches every disabled or unsupported GPU node (add_gpu_components() currently turns it into a no-op because it re-checks msm_gpu_node_present(), but the loop still logs a bogus match).

In addition, the loop never breaks after finding the matching GPU, causing nested DT walks and repeated adreno_has_gpu() checks, and the same unmatched-returns-total behavior in msm_count_mdp4() and msm_count_mdss() affects msm_display_idx(). A single-pass loop that skips !msm_gpu_node_present(np), increments a local index, and breaks with of_node_put(np) once it matches disp_idx would avoid these issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1