* [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu
@ 2026-12-02 18:34 Rob Clark
2026-12-02 18:43 ` Rob Clark
2026-12-02 18:45 ` sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Rob Clark @ 2026-12-02 18:34 UTC (permalink / raw)
To: dri-devel
Cc: linux-arm-msm, freedreno, Rob Clark, Dmitry Baryshkov,
Abhinav Kumar, Jessica Zhang, Sean Paul, Marijn Suijten,
David Airlie, Simona Vetter, Mahadevan P, Luca Ceresoli,
open list
The default of auto-pick was not handling the case of multiple GPU
devices. Handle this by matching GPU and DPU devices, so if a SoC
has an equal # of display and GPU devices, they get paired up one-
by-one.
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
---
I don't have such a device at hand. But this at least works when
there is a single GPU+DPU. I'd appreciate if someone could test
this on such a device.
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 7 ++++--
drivers/gpu/drm/msm/msm_drv.c | 28 ++++++++++++++++++------
drivers/gpu/drm/msm/msm_drv.h | 8 +++----
drivers/gpu/drm/msm/msm_mdss.c | 7 ++++--
4 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
index ad08a040982f..e3d27e0020a0 100644
--- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
+++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
@@ -16,14 +16,17 @@
#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)
+ return count;
+ }
}
return count;
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index cd59daa02bf9..49bac1ec64db 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -98,14 +98,17 @@ static inline bool msm_gpu_node_present(struct device_node *np)
return np && of_device_is_available(np) && adreno_has_gpu(np);
}
-static int msm_count_gpus(void)
+static int msm_count_gpus(struct device_node *target_np)
{
struct device_node *np;
int count = 0;
for_each_matching_node(np, msm_gpu_match) {
- if (msm_gpu_node_present(np))
+ if (msm_gpu_node_present(np)) {
count++;
+ if (target_np == np)
+ return count;
+ }
}
return count;
@@ -113,11 +116,10 @@ static int msm_count_gpus(void)
static bool msm_separate_gpu_kms_auto(void)
{
- int gpus = msm_count_gpus();
- int display_subsystems = msm_count_mdss() + msm_count_mdp4();
+ int gpus = msm_count_gpus(NULL);
+ int display_subsystems = msm_count_mdss(NULL) + msm_count_mdp4(NULL);
- /* Single card if there is exactly one GPU and one display subsystem */
- if (gpus == 1 && display_subsystems == 1)
+ if (gpus != display_subsystems)
return false;
return true;
@@ -125,7 +127,7 @@ static bool msm_separate_gpu_kms_auto(void)
bool msm_separate_gpu_kms_components(void)
{
- if (msm_count_gpus() == 0)
+ if (msm_count_gpus(NULL) == 0)
return true;
switch (separate_gpu_kms) {
@@ -1105,6 +1107,18 @@ static int add_gpu_components(struct device *dev,
if (!np || !msm_gpu_node_present(np))
return 0;
+ unsigned disp_idx = msm_count_mdss(dev->of_node) + msm_count_mdp4(dev->of_node);
+ unsigned gpu_idx = msm_count_gpus(gpu_np);
+
+ pr_err("disp_idx=%u, gpu_idx=%u\n", disp_idx, gpu_idx);
+
+ /*
+ * If we have multiple GPUs, we should match the N'th GPU with the
+ * N'th DPU.
+ */
+ if (disp_idx && (disp_idx != gpu_idx))
+ return 0;
+
drm_of_component_match_add(dev, matchptr, component_compare_of, np);
struct device_node *gmu_np __free(device_node) = of_parse_phandle(np, "qcom,gmu", 0);
diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
index b65702ac0140..63d9ded69bb7 100644
--- a/drivers/gpu/drm/msm/msm_drv.h
+++ b/drivers/gpu/drm/msm/msm_drv.h
@@ -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
diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c
index fb0261ae9c78..a320345a5736 100644
--- a/drivers/gpu/drm/msm/msm_mdss.c
+++ b/drivers/gpu/drm/msm/msm_mdss.c
@@ -77,14 +77,17 @@ 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)
+ return count;
+ }
}
return count;
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu
2026-12-02 18:34 [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu Rob Clark
@ 2026-12-02 18:43 ` Rob Clark
2026-12-02 18:45 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Rob Clark @ 2026-12-02 18:43 UTC (permalink / raw)
To: dri-devel
Cc: linux-arm-msm, freedreno, Dmitry Baryshkov, Abhinav Kumar,
Jessica Zhang, Sean Paul, Marijn Suijten, David Airlie,
Simona Vetter, Mahadevan P, Luca Ceresoli, open list
On Wed, Dec 2, 2026 at 10:34 AM Rob Clark <robin.clark@oss.qualcomm.com> wrote:
>
> The default of auto-pick was not handling the case of multiple GPU
> devices. Handle this by matching GPU and DPU devices, so if a SoC
> has an equal # of display and GPU devices, they get paired up one-
> by-one.
>
> Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
> ---
> I don't have such a device at hand. But this at least works when
> there is a single GPU+DPU. I'd appreciate if someone could test
> this on such a device.
>
> drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 7 ++++--
> drivers/gpu/drm/msm/msm_drv.c | 28 ++++++++++++++++++------
> drivers/gpu/drm/msm/msm_drv.h | 8 +++----
> drivers/gpu/drm/msm/msm_mdss.c | 7 ++++--
> 4 files changed, 35 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> index ad08a040982f..e3d27e0020a0 100644
> --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> @@ -16,14 +16,17 @@
> #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)
> + return count;
> + }
> }
>
> return count;
> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index cd59daa02bf9..49bac1ec64db 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -98,14 +98,17 @@ static inline bool msm_gpu_node_present(struct device_node *np)
> return np && of_device_is_available(np) && adreno_has_gpu(np);
> }
>
> -static int msm_count_gpus(void)
> +static int msm_count_gpus(struct device_node *target_np)
> {
> struct device_node *np;
> int count = 0;
>
> for_each_matching_node(np, msm_gpu_match) {
> - if (msm_gpu_node_present(np))
> + if (msm_gpu_node_present(np)) {
> count++;
> + if (target_np == np)
> + return count;
> + }
> }
>
> return count;
> @@ -113,11 +116,10 @@ static int msm_count_gpus(void)
>
> static bool msm_separate_gpu_kms_auto(void)
> {
> - int gpus = msm_count_gpus();
> - int display_subsystems = msm_count_mdss() + msm_count_mdp4();
> + int gpus = msm_count_gpus(NULL);
> + int display_subsystems = msm_count_mdss(NULL) + msm_count_mdp4(NULL);
>
> - /* Single card if there is exactly one GPU and one display subsystem */
> - if (gpus == 1 && display_subsystems == 1)
> + if (gpus != display_subsystems)
possibly if # of gpus != # of dpus, we should match up the first
min(gpus, display_subsystems) and create singletons for whatever is
left over
BR,
-R
> return false;
>
> return true;
> @@ -125,7 +127,7 @@ static bool msm_separate_gpu_kms_auto(void)
>
> bool msm_separate_gpu_kms_components(void)
> {
> - if (msm_count_gpus() == 0)
> + if (msm_count_gpus(NULL) == 0)
> return true;
>
> switch (separate_gpu_kms) {
> @@ -1105,6 +1107,18 @@ static int add_gpu_components(struct device *dev,
> if (!np || !msm_gpu_node_present(np))
> return 0;
>
> + unsigned disp_idx = msm_count_mdss(dev->of_node) + msm_count_mdp4(dev->of_node);
> + unsigned gpu_idx = msm_count_gpus(gpu_np);
> +
> + pr_err("disp_idx=%u, gpu_idx=%u\n", disp_idx, gpu_idx);
> +
> + /*
> + * If we have multiple GPUs, we should match the N'th GPU with the
> + * N'th DPU.
> + */
> + if (disp_idx && (disp_idx != gpu_idx))
> + return 0;
> +
> drm_of_component_match_add(dev, matchptr, component_compare_of, np);
>
> struct device_node *gmu_np __free(device_node) = of_parse_phandle(np, "qcom,gmu", 0);
> diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
> index b65702ac0140..63d9ded69bb7 100644
> --- a/drivers/gpu/drm/msm/msm_drv.h
> +++ b/drivers/gpu/drm/msm/msm_drv.h
> @@ -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
> diff --git a/drivers/gpu/drm/msm/msm_mdss.c b/drivers/gpu/drm/msm/msm_mdss.c
> index fb0261ae9c78..a320345a5736 100644
> --- a/drivers/gpu/drm/msm/msm_mdss.c
> +++ b/drivers/gpu/drm/msm/msm_mdss.c
> @@ -77,14 +77,17 @@ 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)
> + return count;
> + }
> }
>
> return count;
> --
> 2.56.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu
2026-12-02 18:34 [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu Rob Clark
2026-12-02 18:43 ` Rob Clark
@ 2026-12-02 18:45 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-02 18:45 UTC (permalink / raw)
To: Rob Clark, dri-devel
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/msm: inverted boolean return value in
msm_separate_gpu_kms_auto()
- [High] drm/msm: unmatched target_np returns total count in
msm_count_*()
- [High] drm/msm: add_gpu_components() passes NULL gpu_np and checks
only first GPU
- [Medium] drm/msm: device_node refcount leak on early return in
msm_count_*()
- [Low] drm/msm: leftover pr_err() debug print in add_gpu_components()
--
commit 26bd8b0728ea32f5eae5c7537ac1e3cf8ad995f9
Author: Rob Clark <robin.clark@oss.qualcomm.com>
drm/msm: Fix separate_gpu_kms for multi-gpu
This commit updates separate_gpu_kms auto-selection and GPU component
matching to pair GPU and display devices by index when a system has an
equal number of GPUs and display subsystems.
> diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> index ad08a040982fa..e3d27e0020a01 100644
> --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c
> @@ -16,14 +16,17 @@
> #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)
> + return count;
> + }
> }
>
> return count;
[Severity: Medium]
Does returning directly from inside for_each_matching_node() leak the
reference on np? for_each_matching_node() holds a reference on the loop
cursor until the next iteration, so early returns in msm_count_mdp4(),
msm_count_gpus(), and msm_count_mdss() need of_node_put(np).
> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index cd59daa02bf94..49bac1ec64db9 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -98,14 +98,17 @@ static inline bool msm_gpu_node_present(struct device_node *np)
> return np && of_device_is_available(np) && adreno_has_gpu(np);
> }
>
> -static int msm_count_gpus(void)
> +static int msm_count_gpus(struct device_node *target_np)
> {
> struct device_node *np;
> int count = 0;
>
> for_each_matching_node(np, msm_gpu_match) {
> - if (msm_gpu_node_present(np))
> + if (msm_gpu_node_present(np)) {
> count++;
> + if (target_np == np)
> + return count;
> + }
> }
>
> return count;
> @@ -113,11 +116,10 @@ static int msm_count_gpus(void)
>
> static bool msm_separate_gpu_kms_auto(void)
> {
> - int gpus = msm_count_gpus();
> - int display_subsystems = msm_count_mdss() + msm_count_mdp4();
> + int gpus = msm_count_gpus(NULL);
> + int display_subsystems = msm_count_mdss(NULL) + msm_count_mdp4(NULL);
>
> - /* Single card if there is exactly one GPU and one display subsystem */
> - if (gpus == 1 && display_subsystems == 1)
> + if (gpus != display_subsystems)
> return false;
>
> return true;
[Severity: High]
Is the boolean return value of msm_separate_gpu_kms_auto() inverted here?
In msm_separate_gpu_kms_components(), returning true means separate GPU
and KMS DRM devices (matching separate_gpu_kms == 1), while false means
combining them into a single DRM device (matching separate_gpu_kms == 0).
Returning true when gpus == display_subsystems forces separate devices on
1-GPU + 1-display and N-GPU + N-display systems, and returning false when
gpus != display_subsystems attempts to combine them on asymmetric or
headless systems (leaving a standalone GPU unbound when display_subsystems
is 0 because adreno_probe() skips msm_gpu_probe()).
> @@ -1105,6 +1107,18 @@ static int add_gpu_components(struct device *dev,
> if (!np || !msm_gpu_node_present(np))
> return 0;
>
> + unsigned disp_idx = msm_count_mdss(dev->of_node) + msm_count_mdp4(dev->of_node);
[Severity: High]
What happens when target_np is non-NULL but not found by msm_count_mdss(),
msm_count_mdp4(), or msm_count_gpus()?
When target_np does not match any entry, those helpers finish the loop and
return the total count of available nodes instead of 0. In
add_gpu_components(), this causes two problems:
1. When called from msm_gpu_probe() for a standalone GPU master (kms_init
is NULL), dev->of_node is a GPU node, so disp_idx becomes the total number
of display subsystems in the system rather than 0. If disp_idx is
non-zero and disp_idx != gpu_idx, add_gpu_components() returns 0 without
adding anything to matchptr, and msm_drv_probe() then passes match == NULL
to component_master_add_with_match(), causing a NULL pointer dereference
on match->num.
2. When called from dpu_dev_probe() or mdp5_dev_probe(), dev is the child
DPU or MDP5 device rather than the parent MDSS device, so dev->of_node
never matches mdss_dt_match in msm_count_mdss() and disp_idx always
evaluates to the total MDSS count instead of the display index.
> + unsigned gpu_idx = msm_count_gpus(gpu_np);
[Severity: High]
Can this pair KMS devices with GPUs when gpu_np is NULL on KMS probe
paths?
dpu_dev_probe(), mdp5_dev_probe(), and mdp4_probe() all pass gpu_np = NULL
to msm_drv_probe(). In add_gpu_components(), np is then always set to the
first matching GPU node via of_find_matching_node(NULL, msm_gpu_match),
and msm_count_gpus(gpu_np) is called with NULL, returning the total number
of GPUs rather than a specific GPU index. On a 2-GPU system, gpu_idx is
always 2 during KMS probe, so display 1 skips binding a GPU and display 2
binds the first GPU node.
> +
> + pr_err("disp_idx=%u, gpu_idx=%u\n", disp_idx, gpu_idx);
[Severity: Low]
This looks like a leftover debug printk that logs at KERN_ERR on every
probe.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202183415.22149-1-robin.clark@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-02 18:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:34 [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu Rob Clark
2026-12-02 18:43 ` Rob Clark
2026-12-02 18:45 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.