From: Lucas Stach <l.stach@pengutronix.de>
To: Christian Gmeiner <christian.gmeiner@gmail.com>,
Russell King <linux+etnaviv@armlinux.org.uk>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>
Cc: etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
Christian Gmeiner <cgmeiner@igalia.com>
Subject: Re: [PATCH v3 1/2] drm/etnaviv: Reference count struct etnaviv_file_private
Date: Fri, 10 Jul 2026 14:45:23 +0200 [thread overview]
Message-ID: <acef82d460bdeb9d9997daf7c05ecb4e2ccb96f9.camel@pengutronix.de> (raw)
In-Reply-To: <20260710-etnaviv-reset-notification-v3-1-7a145c8a1d01@igalia.com>
Am Freitag, dem 10.07.2026 um 14:03 +0200 schrieb Christian Gmeiner:
> From: Christian Gmeiner <cgmeiner@igalia.com>
>
> The next commit updates per-context data from the GPU reset path, which
> runs in the scheduler timeout worker. This can race with closing the DRM
> file: drm_sched_entity_flush() only waits until the entity queue is
> empty, it does not wait for jobs still running on the hardware. So the
> context can already be freed while the reset path still needs it.
>
> Reference count the context and let every submit hold a reference, the
> same way a submit already keeps its mmu context and pid alive. No
> functional change.
>
> Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
> ---
> drivers/gpu/drm/etnaviv/etnaviv_drv.c | 17 ++++++++++++++++-
> drivers/gpu/drm/etnaviv/etnaviv_drv.h | 11 +++++++++++
> drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 5 ++++-
> 3 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> index 08aca9035fc1..a27ed014fb4e 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
> @@ -60,6 +60,19 @@ static void load_gpu(struct drm_device *dev)
> }
> }
>
> +static void etnaviv_file_private_release(struct kref *kref)
> +{
> + struct etnaviv_file_private *ctx =
> + container_of(kref, struct etnaviv_file_private, refcount);
> +
> + kfree(ctx);
> +}
> +
> +void etnaviv_file_private_put(struct etnaviv_file_private *ctx)
> +{
> + kref_put(&ctx->refcount, etnaviv_file_private_release);
> +}
> +
> static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
> {
> struct etnaviv_drm_private *priv = dev->dev_private;
> @@ -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);
> if (ret < 0)
> @@ -120,7 +135,7 @@ static void etnaviv_postclose(struct drm_device *dev, struct drm_file *file)
>
> xa_erase(&priv->active_contexts, ctx->id);
>
> - kfree(ctx);
> + etnaviv_file_private_put(ctx);
> }
>
> /*
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.h b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> index 55a9e745604d..cba4323ae589 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.h
> @@ -7,6 +7,7 @@
> #define __ETNAVIV_DRV_H__
>
> #include <linux/io.h>
> +#include <linux/kref.h>
> #include <linux/list.h>
> #include <linux/mm_types.h>
> #include <linux/sizes.h>
> @@ -29,6 +30,7 @@ struct etnaviv_iommu_global;
> #define ETNAVIV_SOFTPIN_START_ADDRESS SZ_4M /* must be >= SUBALLOC_SIZE */
>
> struct etnaviv_file_private {
> + struct kref refcount;
> int id;
> struct etnaviv_iommu_context *mmu;
> struct drm_sched_entity sched_entity[ETNA_MAX_PIPES];
> @@ -53,6 +55,15 @@ struct etnaviv_drm_private {
> struct etnaviv_cmdbuf *flop_reset_data_ppu;
> };
>
> +void etnaviv_file_private_put(struct etnaviv_file_private *ctx);
> +
> +static inline struct etnaviv_file_private *
> +etnaviv_file_private_get(struct etnaviv_file_private *ctx)
> +{
> + kref_get(&ctx->refcount);
> + return ctx;
> +}
> +
> int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
> struct drm_file *file);
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> index 1a77a09b3377..98f1f59a8b05 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
> @@ -398,6 +398,9 @@ static void submit_cleanup(struct kref *kref)
>
> put_pid(submit->pid);
>
> + if (submit->ctx)
> + etnaviv_file_private_put(submit->ctx);
> +
> kfree(submit->pmrs);
> kfree(submit);
> }
> @@ -526,7 +529,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
> if (ret)
> goto err_submit_put;
>
> - submit->ctx = file->driver_priv;
> + submit->ctx = etnaviv_file_private_get(file->driver_priv);
> submit->mmu_context = etnaviv_iommu_context_get(submit->ctx->mmu);
> submit->exec_state = args->exec_state;
> submit->flags = args->flags;
next prev parent reply other threads:[~2026-07-10 12:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 12:03 [PATCH v3 0/2] drm/etnaviv: Add GPU reset counters for robustness Christian Gmeiner
2026-07-10 12:03 ` [PATCH v3 1/2] drm/etnaviv: Reference count struct etnaviv_file_private Christian Gmeiner
2026-07-10 12:45 ` Lucas Stach [this message]
2026-07-10 12:03 ` [PATCH v3 2/2] drm/etnaviv: Add GPU reset counters Christian Gmeiner
2026-07-10 12:45 ` Lucas Stach
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=acef82d460bdeb9d9997daf7c05ecb4e2ccb96f9.camel@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=airlied@gmail.com \
--cc=cgmeiner@igalia.com \
--cc=christian.gmeiner@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=etnaviv@lists.freedesktop.org \
--cc=kernel-dev@igalia.com \
--cc=linux+etnaviv@armlinux.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®