Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Previn" <alan.previn.teres.alexis@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v9 2/2] drm/xe/guc: Compress GuC log and CTB dump with zstd
Date: Tue, 15 Sep 2026 18:00:27 +0000	[thread overview]
Message-ID: <20260915180027.C37081F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915174840.531473-6-alan.previn.teres.alexis@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] drm/xe: infinite loop in zstd_compress_stream if output buffer fills
- [Medium] drm/xe: KASAN out-of-bounds read in xe_print_blob_ascii85 due to unaligned buffer size
--

commit c797cc861f3e71f2974f41eee132c8271bc241da
Author: Zhanjun Dong <zhanjun.dong@intel.com>

drm/xe/guc: Compress GuC log and CTB dump with zstd

This commit replaces the raw ascii85 dumps of GuC log and CTB snapshots with
a zstd-compressed ascii85 stream. It adds the DRM_XE_COMPRESS_DUMP Kconfig
option to control this behavior, aiming to significantly reduce the size of
error dumps.

> diff --git a/drivers/gpu/drm/xe/xe_guc_log.c b/drivers/gpu/drm/xe/xe_guc_log.c
> index 538d4df0f7aa7..aaeb0f76af305 100644
> --- a/drivers/gpu/drm/xe/xe_guc_log.c
> +++ b/drivers/gpu/drm/xe/xe_guc_log.c
[ ... ]
> @@ -225,16 +228,148 @@ struct xe_guc_log_snapshot *xe_guc_log_snapshot_capture(struct xe_guc_log *log,
>  	return snapshot;
>  }
>  
> +#if IS_ENABLED(CONFIG_DRM_XE_COMPRESS_DUMP)
> +static void xe_guc_print_blob_compressed(struct xe_gt *gt, struct drm_printer *p,
> +					 const char *length_label, const char *data_label,
> +					 void **chunks, int num_chunks,
> +					 size_t chunk_size, size_t total_size)
> +{
[ ... ]
> +	dst_size = zstd_compress_bound(total_size);
> +	dst = kvzalloc(dst_size, GFP_KERNEL);

[Severity: Medium]
Will this allocate a buffer that is not 4-byte aligned? It appears dst_size
is determined by zstd_compress_bound(total_size) which is not guaranteed to
be a multiple of 4. When xe_print_blob_ascii85 is later called with a size
rounded up to 4 bytes, this can cause a KASAN out-of-bounds read.

> +	if (!dst)
> +		goto err;
[ ... ]
> +	remain = total_size;
> +	for (i = 0; i < num_chunks && remain; i++) {
> +		size_t size = min(chunk_size, remain);
> +		zstd_in_buffer inbuf = { .src = chunks[i], .size = size, .pos = 0 };
> +
> +		while (inbuf.pos < inbuf.size) {
> +			ret = zstd_compress_stream(cstream, &outbuf, &inbuf);
> +			if (ZSTD_isError(ret)) {

[Severity: High]
Can this loop spin infinitely if the output buffer fills up? The while loop
relies entirely on input consumption (inbuf.pos < inbuf.size) but lacks a
bailout condition or error check for when the output buffer (outbuf) is
full. 

ZSTD explicitly documents that zstd_compress_bound() is not guaranteed to be
sufficient for streaming compression. If the output buffer fills and
zstd_compress_stream() consumes no input, would this cause a hard lockup?

> +				xe_gt_err(gt, "zstd_compress_stream failed: %s\n",
> +					  ZSTD_getErrorName(ret));
> +				goto err;
> +			}
> +		}
> +		remain -= size;
> +	}
> +
> +	do {
> +		ret = zstd_end_stream(cstream, &outbuf);
> +		if (ZSTD_isError(ret)) {
> +			xe_gt_err(gt, "zstd_end_stream failed: %s\n",
> +				  ZSTD_getErrorName(ret));
> +			goto err;
> +		}
> +	} while (ret > 0 && outbuf.pos < outbuf.size);
> +
> +	drm_printf(p, "%s.length: 0x%zx -> 0x%zx Algo: ZSTD\n",
> +		   length_label, total_size, outbuf.pos);
> +	xe_print_blob_ascii85(p, data_label, '\n', dst, 0,
> +			      DIV_ROUND_UP(outbuf.pos, sizeof(u32)) * sizeof(u32));

[Severity: Medium]
If outbuf.pos is close to dst_size and not a multiple of 4, will this
rounded-up size cause xe_print_blob_ascii85 to read beyond the KASAN
boundaries of the allocated buffer?

> +	goto out;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915174840.531473-4-alan.previn.teres.alexis@intel.com?part=2

  reply	other threads:[~2026-09-15 18:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 17:48 [PATCH v9 0/2] drm/xe/guc: Compress GuC log and CTB dump with zstd Alan Previn
2026-09-15 17:48 ` [PATCH v9 1/2] drm/xe: Remove extra newlines from LRC snapshot dump Alan Previn
2026-09-16 15:10   ` Rodrigo Vivi
2026-09-16 15:14     ` Souza, Jose
2026-09-15 17:48 ` [PATCH v9 2/2] drm/xe/guc: Compress GuC log and CTB dump with zstd Alan Previn
2026-09-15 18:00   ` sashiko-bot [this message]
2026-09-16 15:38   ` Rodrigo Vivi
2026-09-16 20:18     ` Teres Alexis, Alan Previn
2026-09-16 21:24   ` Julia Filipchuk
2026-09-16 21:28     ` Teres Alexis, Alan Previn
2026-09-15 18:10 ` ✗ CI.checkpatch: warning for drm/xe/guc: Compress GuC log and CTB dump with zstd (rev5) Patchwork
2026-09-15 18:13 ` ✓ CI.KUnit: success " Patchwork
2026-09-15 19:07 ` ✓ Xe.CI.BAT: " Patchwork
2026-09-16  1:17 ` ✓ Xe.CI.FULL: " Patchwork

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=20260915180027.C37081F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alan.previn.teres.alexis@intel.com \
    --cc=intel-xe@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