From: sashiko-bot@kernel.org
To: "Rob Clark" <robin.clark@oss.qualcomm.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [RFT PATCH] drm/msm: Fix separate_gpu_kms for multi-gpu
Date: Wed, 02 Dec 2026 18:45:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-246456@kernel.org> (raw)
In-Reply-To: <20261202183415.22149-1-robin.clark@oss.qualcomm.com>
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
prev parent reply other threads:[~2026-12-02 18:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-246456@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=robin.clark@oss.qualcomm.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.