The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] drm/xe/oa: Fix sync entry leak on OA config emit failure
@ 2026-07-15  2:33 Linmao Li
  2026-07-30 22:20 ` Dixit, Ashutosh
  2026-07-31  1:19 ` [PATCH v2] " Linmao Li
  0 siblings, 2 replies; 4+ messages in thread
From: Linmao Li @ 2026-07-15  2:33 UTC (permalink / raw)
  To: Ashutosh Dixit, Matthew Brost, Thomas Hellström,
	Rodrigo Vivi
  Cc: David Airlie, Simona Vetter, José Roberto de Souza,
	Umesh Nerlige Ramappa, intel-xe, dri-devel, linux-kernel,
	Linmao Li

xe_oa_emit_oa_config() releases the sync entries and the syncs array
only on its success path. When it fails before the point of no return
(fence allocation, config buffer allocation or batch submission), it
returns without touching stream->syncs.

The stream open path handles such failures in the caller, but
xe_oa_config_locked() propagates the error without any cleanup, so the
syncs array and the fence references held by the parsed entries are
leaked. The next config ioctl overwrites stream->syncs, making the
memory unreachable for good.

Clean up the parsed syncs when xe_oa_emit_oa_config() fails, matching
the cleanup done by the stream open error path, and reset the stream
sync state so it does not point at freed entries.

Fixes: 9920c8b88c5c ("drm/xe/oa: Add syncs support to OA config ioctl")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
 drivers/gpu/drm/xe/xe_oa.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 2dce6a47202c..b1ce312ea97a 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -1594,6 +1594,12 @@ static long xe_oa_config_locked(struct xe_oa_stream *stream, u64 arg)
 		config = xchg(&stream->oa_config, config);
 		drm_dbg(&stream->oa->xe->drm, "changed to oa config uuid=%s\n",
 			stream->oa_config->uuid);
+	} else {
+		while (param.num_syncs--)
+			xe_sync_entry_cleanup(&param.syncs[param.num_syncs]);
+		kfree(param.syncs);
+		stream->num_syncs = 0;
+		stream->syncs = NULL;
 	}
 
 err_config_put:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/xe/oa: Fix sync entry leak on OA config emit failure
  2026-07-15  2:33 [PATCH] drm/xe/oa: Fix sync entry leak on OA config emit failure Linmao Li
@ 2026-07-30 22:20 ` Dixit, Ashutosh
  2026-07-31  1:19 ` [PATCH v2] " Linmao Li
  1 sibling, 0 replies; 4+ messages in thread
From: Dixit, Ashutosh @ 2026-07-30 22:20 UTC (permalink / raw)
  To: Linmao Li
  Cc: Matthew Brost, Thomas Hellström, Rodrigo Vivi, David Airlie,
	Simona Vetter, José Roberto de Souza, Umesh Nerlige Ramappa,
	intel-xe, dri-devel, linux-kernel

On Tue, 14 Jul 2026 19:33:32 -0700, Linmao Li wrote:
>

Hi Linmao,

Sorry for the delay in responding to this patch.

> xe_oa_emit_oa_config() releases the sync entries and the syncs array
> only on its success path. When it fails before the point of no return
> (fence allocation, config buffer allocation or batch submission), it
> returns without touching stream->syncs.
>
> The stream open path handles such failures in the caller, but
> xe_oa_config_locked() propagates the error without any cleanup, so the
> syncs array and the fence references held by the parsed entries are
> leaked. The next config ioctl overwrites stream->syncs, making the
> memory unreachable for good.
>
> Clean up the parsed syncs when xe_oa_emit_oa_config() fails, matching
> the cleanup done by the stream open error path, and reset the stream
> sync state so it does not point at freed entries.
>
> Fixes: 9920c8b88c5c ("drm/xe/oa: Add syncs support to OA config ioctl")
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
>  drivers/gpu/drm/xe/xe_oa.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index 2dce6a47202c..b1ce312ea97a 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -1594,6 +1594,12 @@ static long xe_oa_config_locked(struct xe_oa_stream *stream, u64 arg)
>		config = xchg(&stream->oa_config, config);
>		drm_dbg(&stream->oa->xe->drm, "changed to oa config uuid=%s\n",
>			stream->oa_config->uuid);
> +	} else {
> +		while (param.num_syncs--)
> +			xe_sync_entry_cleanup(&param.syncs[param.num_syncs]);
> +		kfree(param.syncs);
> +		stream->num_syncs = 0;
> +		stream->syncs = NULL;

Yes this looks correct to me. Except that we don't need the two lines
above. Can you please resend a v2 deleting the above two lines.

Thanks for the patch,
Ashutosh

>	}
>
>  err_config_put:
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] drm/xe/oa: Fix sync entry leak on OA config emit failure
  2026-07-15  2:33 [PATCH] drm/xe/oa: Fix sync entry leak on OA config emit failure Linmao Li
  2026-07-30 22:20 ` Dixit, Ashutosh
@ 2026-07-31  1:19 ` Linmao Li
  2026-08-10 22:15   ` Dixit, Ashutosh
  1 sibling, 1 reply; 4+ messages in thread
From: Linmao Li @ 2026-07-31  1:19 UTC (permalink / raw)
  To: Ashutosh Dixit, Matthew Brost, Thomas Hellström,
	Rodrigo Vivi
  Cc: David Airlie, Simona Vetter, José Roberto de Souza,
	Umesh Nerlige Ramappa, intel-xe, dri-devel, linux-kernel,
	Linmao Li

xe_oa_emit_oa_config() releases the sync entries and the syncs array
only on its success path. When it fails before the point of no return
(fence allocation, config buffer allocation or batch submission), it
returns without touching stream->syncs.

The stream open path handles such failures in the caller, but
xe_oa_config_locked() propagates the error without any cleanup, so the
syncs array and the fence references held by the parsed entries are
leaked. The next config ioctl overwrites stream->syncs, making the
memory unreachable for good.

Clean up the parsed syncs when xe_oa_emit_oa_config() fails, matching
the cleanup done by the stream open error path.

Fixes: 9920c8b88c5c ("drm/xe/oa: Add syncs support to OA config ioctl")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
v2:
- drop the stream->syncs/num_syncs reset; nothing dereferences them
  before they are overwritten or the stream is destroyed (Ashutosh Dixit)

 drivers/gpu/drm/xe/xe_oa.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index b3acbcd678b7c..d334ce8fed1c2 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -1594,6 +1594,10 @@ static long xe_oa_config_locked(struct xe_oa_stream *stream, u64 arg)
 		config = xchg(&stream->oa_config, config);
 		drm_dbg(&stream->oa->xe->drm, "changed to oa config uuid=%s\n",
 			stream->oa_config->uuid);
+	} else {
+		while (param.num_syncs--)
+			xe_sync_entry_cleanup(&param.syncs[param.num_syncs]);
+		kfree(param.syncs);
 	}
 
 err_config_put:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] drm/xe/oa: Fix sync entry leak on OA config emit failure
  2026-07-31  1:19 ` [PATCH v2] " Linmao Li
@ 2026-08-10 22:15   ` Dixit, Ashutosh
  0 siblings, 0 replies; 4+ messages in thread
From: Dixit, Ashutosh @ 2026-08-10 22:15 UTC (permalink / raw)
  To: Linmao Li
  Cc: Matthew Brost, Thomas Hellström, Rodrigo Vivi, David Airlie,
	Simona Vetter, José Roberto de Souza, Umesh Nerlige Ramappa,
	intel-xe, dri-devel, linux-kernel

On Thu, 30 Jul 2026 18:19:32 -0700, Linmao Li wrote:
>
> xe_oa_emit_oa_config() releases the sync entries and the syncs array
> only on its success path. When it fails before the point of no return
> (fence allocation, config buffer allocation or batch submission), it
> returns without touching stream->syncs.
>
> The stream open path handles such failures in the caller, but
> xe_oa_config_locked() propagates the error without any cleanup, so the
> syncs array and the fence references held by the parsed entries are
> leaked. The next config ioctl overwrites stream->syncs, making the
> memory unreachable for good.
>
> Clean up the parsed syncs when xe_oa_emit_oa_config() fails, matching
> the cleanup done by the stream open error path.
>
> Fixes: 9920c8b88c5c ("drm/xe/oa: Add syncs support to OA config ioctl")
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
> ---
> v2:
> - drop the stream->syncs/num_syncs reset; nothing dereferences them
>   before they are overwritten or the stream is destroyed (Ashutosh Dixit)
>
>  drivers/gpu/drm/xe/xe_oa.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index b3acbcd678b7c..d334ce8fed1c2 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -1594,6 +1594,10 @@ static long xe_oa_config_locked(struct xe_oa_stream *stream, u64 arg)
>		config = xchg(&stream->oa_config, config);
>		drm_dbg(&stream->oa->xe->drm, "changed to oa config uuid=%s\n",
>			stream->oa_config->uuid);
> +	} else {
> +		while (param.num_syncs--)
> +			xe_sync_entry_cleanup(&param.syncs[param.num_syncs]);
> +		kfree(param.syncs);
>	}

Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com>

Thanks for the patch Linmao, we'll get it merged.

Thanks.
--
Ashutosh


>
>  err_config_put:
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-10 22:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15  2:33 [PATCH] drm/xe/oa: Fix sync entry leak on OA config emit failure Linmao Li
2026-07-30 22:20 ` Dixit, Ashutosh
2026-07-31  1:19 ` [PATCH v2] " Linmao Li
2026-08-10 22:15   ` Dixit, Ashutosh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox