lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5ab0ff01-6d26-4e52-b8b9-215b1304b6a5@amd.com>
Date: Tue, 8 Apr 2025 19:40:49 +0200
From: Christian König <christian.koenig@....com>
To: Erico Nunes <nunes.erico@...il.com>, Qiang Yu <yuq825@...il.com>
Cc: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
 Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
 David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
 dri-devel@...ts.freedesktop.org, lima@...ts.freedesktop.org,
 linux-kernel@...r.kernel.org, "Yang, Philip" <Philip.Yang@....com>,
 Danilo Krummrich <dakr@...hat.com>
Subject: Re: [PATCH 1/1] drm/lima: implement the file flush callback

Am 08.04.25 um 17:46 schrieb Erico Nunes:
> With this callback implemented, a terminating application will wait for
> the sched entity to be flushed out to the hardware and cancel all other
> pending jobs before destroying its context.
> This prevents applications with multiple contexts from running into a
> race condition between running tasks and context destroy when
> terminating.
>
> Signed-off-by: Erico Nunes <nunes.erico@...il.com>

Looks perfectly valid to me and is most likely the right thing to do for other drivers as well.

Reviewed-by: Christian König <christian.koenig@....com>

> ---
>  drivers/gpu/drm/lima/lima_ctx.c | 18 ++++++++++++++++++
>  drivers/gpu/drm/lima/lima_ctx.h |  1 +
>  drivers/gpu/drm/lima/lima_drv.c | 17 ++++++++++++++++-
>  3 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c
> index 0e668fc1e0f9..e8fb5788ca69 100644
> --- a/drivers/gpu/drm/lima/lima_ctx.c
> +++ b/drivers/gpu/drm/lima/lima_ctx.c
> @@ -100,3 +100,21 @@ void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr)
>  	xa_destroy(&mgr->handles);
>  	mutex_destroy(&mgr->lock);
>  }
> +
> +long lima_ctx_mgr_flush(struct lima_ctx_mgr *mgr, long timeout)
> +{
> +	struct lima_ctx *ctx;
> +	unsigned long id;
> +
> +	mutex_lock(&mgr->lock);
> +	xa_for_each(&mgr->handles, id, ctx) {
> +		for (int i = 0; i < lima_pipe_num; i++) {
> +			struct lima_sched_context *context = &ctx->context[i];
> +			struct drm_sched_entity *entity = &context->base;
> +
> +			timeout = drm_sched_entity_flush(entity, timeout);
> +		}
> +	}
> +	mutex_unlock(&mgr->lock);
> +	return timeout;
> +}
> diff --git a/drivers/gpu/drm/lima/lima_ctx.h b/drivers/gpu/drm/lima/lima_ctx.h
> index 5b1063ce968b..ff133db6ae4c 100644
> --- a/drivers/gpu/drm/lima/lima_ctx.h
> +++ b/drivers/gpu/drm/lima/lima_ctx.h
> @@ -30,5 +30,6 @@ struct lima_ctx *lima_ctx_get(struct lima_ctx_mgr *mgr, u32 id);
>  void lima_ctx_put(struct lima_ctx *ctx);
>  void lima_ctx_mgr_init(struct lima_ctx_mgr *mgr);
>  void lima_ctx_mgr_fini(struct lima_ctx_mgr *mgr);
> +long lima_ctx_mgr_flush(struct lima_ctx_mgr *mgr, long timeout);
>  
>  #endif
> diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
> index 11ace5cebf4c..08169b0d9c28 100644
> --- a/drivers/gpu/drm/lima/lima_drv.c
> +++ b/drivers/gpu/drm/lima/lima_drv.c
> @@ -254,7 +254,22 @@ static const struct drm_ioctl_desc lima_drm_driver_ioctls[] = {
>  	DRM_IOCTL_DEF_DRV(LIMA_CTX_FREE, lima_ioctl_ctx_free, DRM_RENDER_ALLOW),
>  };
>  
> -DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops);
> +static int lima_drm_driver_flush(struct file *filp, fl_owner_t id)
> +{
> +	struct drm_file *file = filp->private_data;
> +	struct lima_drm_priv *priv = file->driver_priv;
> +	long timeout = MAX_WAIT_SCHED_ENTITY_Q_EMPTY;
> +
> +	timeout = lima_ctx_mgr_flush(&priv->ctx_mgr, timeout);
> +
> +	return timeout >= 0 ? 0 : timeout;
> +}
> +
> +static const struct file_operations lima_drm_driver_fops = {
> +	.owner = THIS_MODULE,
> +	.flush = lima_drm_driver_flush,
> +	DRM_GEM_FOPS,
> +};
>  
>  /*
>   * Changelog:


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ