Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Zimmermann" <tzimmermann@suse.de>
Cc: imx@lists.linux.dev, intel-xe@lists.freedesktop.org,
	ojeda@kernel.org, linux-hyperv@vger.kernel.org,
	dri-devel@lists.freedesktop.org, Frank.Li@kernel.org,
	wsa+renesas@sang-engineering.com,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 04/13] drm/panic: Return errno codes if panic output fails
Date: Mon, 24 Aug 2026 13:15:46 +0000	[thread overview]
Message-ID: <20260824131546.B364A1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824125201.218863-5-tzimmermann@suse.de>

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

New issues:
- [Medium] Using KUNIT_ASSERT_EQ causes kernel test memory to leak if the drawing function returns an error, bypassing explicit resource cleanup.

Pre-existing issues:
- [High] Concurrent invocation of the debugfs trigger for planes on different devices causes data races on global panic buffers, leading to memory corruption.
--

--- Patch [4]: [PATCH v2 04/13] drm/panic: Return errno codes if panic output fails ---
commit 6a8545466378db489975c829328cc895f57550b4
Author: Thomas Zimmermann <tzimmermann@suse.de>

drm/panic: Return errno codes if panic output fails

Return errno codes from the panic output helpers to detect invalid panic
handling and avoid flushing the display if an error occurred. The panic
test cases are updated to assert these new return values.

> diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c
> index 62490d32019cc..cc33a2b4bb52a 100644
> --- a/drivers/gpu/drm/drm_panic.c
> +++ b/drivers/gpu/drm/drm_panic.c

[ ... ]

> @@ -945,9 +954,15 @@ static void draw_panic_plane(struct drm_plane *plane, const char *description)
>  
>  	drm_panic_set_description(description);
>  
> -	draw_panic_dispatch(&sb);
> -	if (plane->helper_private->panic_flush)
> -		plane->helper_private->panic_flush(plane);
> +	ret = draw_panic_dispatch(&sb);

[Severity: High]
This is a pre-existing issue, but can concurrent writes to the debugfs trigger
corrupt global buffers?

If a user concurrently writes to the debugfs trigger files (drm_panic_plane_%d)
for planes on different DRM devices, draw_panic_plane() executes concurrently
because dev->mode_config.panic_lock is a per-device lock.

When DRM_PANIC_TYPE_QR is active, multiple threads could enter
drm_panic_get_qr_code_url() and modify the global static variables qrbuf1,
qrbuf2, and stream.workspace without cross-device synchronization:

drivers/gpu/drm/drm_panic.c:drm_panic_get_qr_code_url() {
    ...
    stream.next_in = kmsg;
    stream.avail_in = kmsg_len;
    stream.total_in = 0;
    stream.next_out = qrbuf2;
    stream.avail_out = QR_BUFFER2_SIZE;
    stream.total_out = 0;
    ...
}

Could this cause memory corruption during simultaneous debugfs writes?

> +	if (!ret) {
> +		/*
> +		 * Only flush if we have a panic screen to display. Otherwise
> +		 * it's probably better to leave the display output as-is.
> +		 */
> +		if (plane->helper_private->panic_flush)
> +			plane->helper_private->panic_flush(plane);
> +	}
>  
>  	drm_panic_clear_description();

[ ... ]

> diff --git a/drivers/gpu/drm/tests/drm_panic_test.c b/drivers/gpu/drm/tests/drm_panic_test.c
> index ad2f3a2f93b6a..fdd77b0cc54c9 100644
> --- a/drivers/gpu/drm/tests/drm_panic_test.c
> +++ b/drivers/gpu/drm/tests/drm_panic_test.c

[ ... ]

> @@ -102,7 +102,8 @@ static void drm_test_panic_screen_user_map(struct kunit *test)
>  	sb->height = params->height;
>  	sb->pitch[0] = params->width * sb->format->cpp[0];
>  
> -	params->draw_screen(sb);
> +	ret = params->draw_screen(sb);
> +	KUNIT_ASSERT_EQ(test, ret, 0);

[Severity: Medium]
Will this KUNIT_ASSERT_EQ() cause memory leaks if the test fails?

If params->draw_screen() returns an error, KUNIT_ASSERT_EQ() will abort the
test thread immediately. This means the test will skip explicit resource
cleanup, such as the vfree(fb) call at the end of
drm_test_panic_screen_user_map().

Should this use KUNIT_EXPECT_EQ() instead to allow the cleanup code to run?

>  
>  	for (i = 0; i < fb_size; i++)
>  		drm_panic_check_color_byte(test, fb[i]);

[ ... ]

> @@ -146,7 +147,8 @@ static void drm_test_panic_screen_user_page(struct kunit *test)
>  	sb->height = params->height;
>  	sb->pitch[0] = params->width * sb->format->cpp[0];
>  
> -	params->draw_screen(sb);
> +	ret = params->draw_screen(sb);
> +	KUNIT_ASSERT_EQ(test, ret, 0);

[Severity: Medium]
Similarly here in drm_test_panic_screen_user_page(), if KUNIT_ASSERT_EQ()
aborts the test on failure, will it skip the free_pages: cleanup label,
resulting in a permanent memory leak?

>  
>  	for (p = 0; p < npages; p++) {
>  		int bytes_in_page = (p == npages - 1) ? fb_size - p * PAGE_SIZE : PAGE_SIZE;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824125201.218863-1-tzimmermann@suse.de?part=4

  reply	other threads:[~2026-08-24 13:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 12:43 [PATCH v2 00/13] drm/panic: Split into core and helpers Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 01/13] drm/panic: Do not use un-escaped URL as format string Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 02/13] drm/panic: Test address from kmap op for NULL Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 03/13] drm/panic: Return -EINVAL if font is not available Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 04/13] drm/panic: Return errno codes if panic output fails Thomas Zimmermann
2026-08-24 13:15   ` sashiko-bot [this message]
2026-08-24 12:43 ` [PATCH v2 05/13] drm/panic: Pass colors to draw_panic_dispatch() Thomas Zimmermann
2026-08-24 13:13   ` sashiko-bot
2026-08-24 12:43 ` [PATCH v2 06/13] drm/panic: Pass global module parameters to drm_panic_dispatch() Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 07/13] drm/panic: Retry in dispatch function if panic output fails Thomas Zimmermann
2026-08-24 13:21   ` sashiko-bot
2026-08-24 12:43 ` [PATCH v2 08/13] drm/panic: Split draw_panic_plane() Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 09/13] drm/panic: Restrict to primary planes; unconditionally unregister Thomas Zimmermann
2026-08-24 13:31   ` sashiko-bot
2026-08-24 12:43 ` [PATCH v2 10/13] drm/panic: Display panic screen via per-plane callback Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 11/13] drm/panic: Internalize panic locking in DRM core and helpers Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 12/13] drm/panic: Move panic display code into helper library Thomas Zimmermann
2026-08-24 12:43 ` [PATCH v2 13/13] drm/panic: Compile KUnit tests as module Thomas Zimmermann
2026-08-24 14:11   ` sashiko-bot
2026-08-24 16:29 ` ✓ i915.CI.BAT: success for drm/panic: Split into core and helpers (rev2) 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=20260824131546.B364A1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imx@lists.linux.dev \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tzimmermann@suse.de \
    --cc=wsa+renesas@sang-engineering.com \
    /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