dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Gmeiner" <christian.gmeiner@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/etnaviv: Reference count struct etnaviv_file_private
Date: Fri, 10 Jul 2026 09:20:32 +0000	[thread overview]
Message-ID: <20260710092033.AEAB31F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260710-etnaviv-reset-notification-v2-1-90cfebcf22a2@igalia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unchecked return value of drm_sched_entity_init leads to NULL pointer dereference on file close.
--

--- Patch [1]: [PATCH v2 1/2] drm/etnaviv: Reference count struct etnaviv_file_private ---
commit ac09092a81050d73fa591427824ad978bbce1e24
Author: Christian Gmeiner <cgmeiner@igalia.com>

drm/etnaviv: Reference count struct etnaviv_file_private

This commit introduces reference counting for etnaviv_file_private to ensure
the context remains alive while the GPU reset path is still running. The
scheduler timeout worker now holds a reference, avoiding a race with closing
the DRM file.

> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> index 08aca9035fc1a..a27ed014fb4e7 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
[ ... ]
> @@ -70,6 +83,8 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
>  	if (!ctx)
>  		return -ENOMEM;
>  
> +	kref_init(&ctx->refcount);
> +
>  	ret = xa_alloc_cyclic(&priv->active_contexts, &ctx->id, ctx,
>  			      xa_limit_32b, &priv->next_context_id, GFP_KERNEL);

[Severity: High]
This is a pre-existing issue, but does etnaviv_open() need to check the
return value of drm_sched_entity_init()?

Looking at etnaviv_open() just below this block, the driver initializes a
scheduler entity for each valid GPU without checking for failure:

etnaviv_open() {
        ...
        drm_sched_entity_init(&ctx->sched_entity[i],
                              DRM_SCHED_PRIORITY_NORMAL, &sched,
                              1, NULL);
        ...
}

If drm_sched_entity_init() fails (e.g., due to memory exhaustion),
entity->stats remains NULL. 

Later, etnaviv_postclose() unconditionally tears down all entities:

etnaviv_postclose() {
        ...
        if (gpu)
                drm_sched_entity_destroy(&ctx->sched_entity[i]);
        ...
}

This eventually invokes drm_sched_entity_fini() in
drivers/gpu/drm/scheduler/sched_entity.c, which calls:

        drm_sched_entity_stats_put(entity->stats);

Could this cause a NULL pointer dereference in kref_put() when it attempts
to operate on the NULL entity->stats pointer during file close?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260710-etnaviv-reset-notification-v2-0-90cfebcf22a2@igalia.com?part=1

  reply	other threads:[~2026-07-10  9:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  9:00 [PATCH v2 0/2] drm/etnaviv: Add GPU reset counters for robustness Christian Gmeiner
2026-07-10  9:00 ` [PATCH v2 1/2] drm/etnaviv: Reference count struct etnaviv_file_private Christian Gmeiner
2026-07-10  9:20   ` sashiko-bot [this message]
2026-07-10  9:00 ` [PATCH v2 2/2] drm/etnaviv: Add GPU reset counters Christian Gmeiner
2026-07-10  9:27   ` sashiko-bot
2026-07-10 11:47   ` Lucas Stach
2026-07-10 12:01     ` Christian Gmeiner

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=20260710092033.AEAB31F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=christian.gmeiner@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox