All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Maxime Ripard" <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v10 30/36] drm/tidss: plane: Implement hardware state readout
Date: Fri, 27 Nov 2026 10:20:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-237098@kernel.org> (raw)
In-Reply-To: <20261127-drm-state-readout-v10-30-0259582d45a8@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/tidss: -ENODEV in tidss_plane_atomic_readout_state() on
  partial commits
- [Medium] drm/tidss: tidss_plane_readout_fb() ignores vertical
  decimation
- [Medium] drm/tidss: false alpha state mismatch in
  tidss_plane_atomic_readout_state()
--

commit 3be74e07814475f76096d9b92a77584c340fd8f8
Author: Maxime Ripard <mripard@kernel.org>

drm/tidss: plane: Implement hardware state readout

This commit implements the atomic_sro_readout_state and
atomic_sro_compare_state hooks for tidss planes so that planes enabled by
firmware can be read out at boot and compared after atomic commits.

> diff --git a/drivers/gpu/drm/tidss/tidss_plane.c b/drivers/gpu/drm/tidss/tidss_plane.c
> index b0d5d6959b885..a9b4005d1d603 100644
> --- a/drivers/gpu/drm/tidss/tidss_plane.c
> +++ b/drivers/gpu/drm/tidss/tidss_plane.c
[ ... ]
> @@ -176,11 +180,252 @@ static const struct drm_plane_helper_funcs tidss_primary_plane_helper_funcs = {
>  	.get_scanout_buffer = drm_fb_dma_get_scanout_buffer,
>  };
>  
> +static const struct drm_framebuffer_funcs tidss_plane_readout_fb_funcs = {
> +	.destroy	= drm_gem_fb_destroy,
> +};
> +
> +static struct drm_framebuffer *tidss_plane_readout_fb(struct drm_plane *plane)
> +{
[ ... ]
> +	dispc_plane_get_picture_size(dispc, tplane->hw_plane_id, &fb->width,
> +				     &fb->height);
> +
> +	/*
> +	 * A pixel increment of 1 means that the DMA engine fetches every
> +	 * pixel of the source buffer. Any other value means that
> +	 * horizontal decimation is enabled, and the buffer geometry
> +	 * cannot be reconstructed from the registers.
> +	 */
> +	if (dispc_plane_get_pixel_inc(dispc, tplane->hw_plane_id) != 1) {
> +		ret = -EINVAL;
> +		goto err_free_fb;
> +	}
> +
> +	/*
> +	 * The row increment register holds the extra bytes between the
> +	 * end of a row of the picture and the beginning of the next one,
> +	 * which includes any padding the firmware might have programmed.
> +	 */
> +	fb->pitches[0] = fb->width * (drm_format_info_bpp(info, 0) / 8) +
> +			 dispc_plane_get_row_inc(dispc, tplane->hw_plane_id) - 1;

[Severity: Medium]
Does checking dispc_plane_get_pixel_inc() != 1 miss vertical decimation?

In dispc_vid_calc_scaling(), vertical decimation (scale.yinc > 1) can be
enabled while scale.xinc == 1.  In that case dispc_plane_setup() still
programs DISPC_VID_PIXEL_INC to 1, but writes the decimated height
(src_h >> 16) / scale.yinc into DISPC_VID_PICTURE_SIZE and multiplies
fb_width by scale.yinc in DISPC_VID_ROW_INC:

drivers/gpu/drm/tidss/tidss_dispc.c:dispc_plane_setup() {
    ...
	dispc_vid_write(dispc, hw_plane, DISPC_VID_ROW_INC,
			pixinc(1 + (scale.yinc * fb_width -
				    scale.xinc * scale.in_w),
			       cpp));
    ...
}

As a result, tidss_plane_readout_fb() reconstructs fb->pitches[0] as
scale.yinc times the actual pitch and fb->height (along with
plane_state->src_h) as 1 / scale.yinc of the actual height, causing state
comparison mismatches after blocking commits with vertical decimation or
corrupted framebuffer geometry if enabled by firmware at boot.

[ ... ]

> +static int tidss_plane_atomic_readout_state(struct drm_plane *plane,
> +					    struct drm_atomic_sro_state *state,
> +					    struct drm_plane_state *plane_state)
> +{
[ ... ]
> +	crtc = tidss_plane_readout_crtc(plane, &crtc_x, &crtc_y,
> +					&normalized_zpos);
> +	if (IS_ERR(crtc)) {
> +		ret = PTR_ERR(crtc);
> +
> +		/*
> +		 * tidss_crtc_atomic_disable() disables the overlay layers of
> +		 * the video port, but the planes on a CRTC being disabled
> +		 * aren't disabled in the VID pipeline. A plane that isn't
> +		 * routed to any layer is thus disabled.
> +		 */
> +		if (ret == -ENODEV)
> +			goto out;
> +
> +		goto err_runtime_pm;
> +	}
> +
> +	crtc_state = drm_atomic_sro_get_crtc_state(state, crtc);
> +	if (!crtc_state) {
> +		ret = -ENODEV;
> +		goto err_runtime_pm;
> +	}
> +
> +	/*
> +	 * K2G has no overlay manager to tell us whether the plane is
> +	 * routed, and the planes of a disabled video port are left
> +	 * enabled: a plane on an inactive CRTC isn't scanned out.
> +	 */
> +	if (!crtc_state->active)
> +		goto out;

[Severity: Medium]
Should !crtc_state jump to out instead of returning -ENODEV?

Because tidss commits planes with DRM_PLANE_COMMIT_ACTIVE_ONLY, disabling
a CRTC (or detaching a plane after its CRTC was disabled) leaves
DISPC_VID_ATTRIBUTES_ENABLE_MASK set in hardware.  On K2G, where
dispc_ovr_get_plane() always returns hw_videoport 0 (or on K3 when
firmware left an overlay layer enabled on an inactive video port),
tidss_plane_readout_crtc() still returns that inactive CRTC.

When a later blocking commit updates a property on the unbound plane
without touching the inactive CRTC,
drm_atomic_helper_sro_readout_commit_crtcs_state() only populates
state->crtcs for CRTCs included in the commit.
drm_atomic_sro_get_crtc_state() then returns NULL and
tidss_plane_atomic_readout_state() fails post-commit readout verification
with -ENODEV instead of reporting the plane as disabled.

Also, on multi-videoport K3 SoCs, dispc_ovr_get_plane() scans video ports
from 0 upward without checking whether the video port is enabled, so an
overlay layer left enabled on a disabled lower-numbered video port can
shadow an active higher-numbered video port using the same plane.

[ ... ]

> +	/*
> +	 * The global alpha register is 8 bits wide and is programmed
> +	 * from the high byte of the 16 bits alpha property.
> +	 * Replicating the byte is the only inverse that preserves the
> +	 * fraction of full opacity (0x00 -> 0x0000, 0xff -> 0xffff)
> +	 * and round-trips through a program-then-readout cycle.
> +	 */
> +	plane_state->alpha =
> +		dispc_plane_get_global_alpha(dispc, tplane->hw_plane_id) * 0x0101;
> +	plane_state->pixel_blend_mode =
> +		dispc_plane_get_blend_mode(dispc, tplane->hw_plane_id);
> +
> +	crtc_state->plane_mask |= drm_plane_mask(plane);
> +
> +out:
> +	tidss_runtime_put(tidss);
> +	return 0;
> +
> +err_runtime_pm:
> +	tidss_runtime_put(tidss);
> +	return ret;
> +}
> +
>  static const struct drm_plane_funcs tidss_plane_funcs = {
>  	.update_plane = drm_atomic_helper_update_plane,
>  	.disable_plane = drm_atomic_helper_disable_plane,
>  	.destroy = drm_plane_destroy,
>  	.atomic_create_state = drm_atomic_helper_plane_create_state,
> +	.atomic_sro_readout_state = tidss_plane_atomic_readout_state,
> +	.atomic_sro_compare_state = drm_atomic_helper_plane_compare_state,

[Severity: Medium]
Will drm_atomic_helper_plane_compare_state() report false alpha mismatches
whenever userspace commits an alpha value whose high and low bytes differ?

dispc_plane_setup() programs the 8-bit global alpha register from
state->alpha >> 8 while expected->alpha keeps the full 16-bit value from
userspace (for example, 0x8000 for 50% opacity).  Replicating the read-out
byte with * 0x0101 produces actual->alpha = 0x8080, which fails the exact
16-bit comparison in drm_atomic_helper_plane_compare_state().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-drm-state-readout-v10-0-0259582d45a8@kernel.org?part=30

  reply	other threads:[~2026-11-27 10:20 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  9:52 [PATCH v10 00/36] drm: Implement state readout support Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 01/36] drm/bridge-helper: Don't unlock the connection mutex after a backoff Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 02/36] drm/tests: hdmi-state-helper: Handle EDEADLK in the 420-only test Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 03/36] drm/tests: hdmi-state-helper: Handle EDEADLK in the color format test Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 04/36] drm/atomic: Add drm_private_obj name Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 05/36] drm/bridge: Switch print_state to use bridge name Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 06/36] drm/atomic_sro: Create drm_atomic_sro_state container Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 07/36] drm/atomic_sro: Create kernel parameter to force or disable readout Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 08/36] drm/atomic_sro: Add atomic state readout infrastructure Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 09/36] drm/atomic_sro: Create documentation Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 10/36] drm/bridge: Handle bridges with hardware state readout Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 11/36] drm/mode-config: Read out hardware state in drm_mode_config_create_initial_state Maxime Ripard
2026-11-27 10:09   ` sashiko-bot
2026-11-27  9:52 ` [PATCH v10 12/36] drm/atomic_sro: Provide helpers to implement hardware state readout Maxime Ripard
2026-11-27 10:15   ` sashiko-bot
2026-11-27  9:52 ` [PATCH v10 13/36] drm/mode-config: Introduce hw_reset hook Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 14/36] drm/modeset-helper: Add drm_mode_config_helper_hw_reset() Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 15/36] drm/atomic_helper: Compare actual and readout states once the commit is done Maxime Ripard
2026-11-27  9:52 ` [PATCH v10 16/36] drm/atomic-state-helper: Provide comparison macros Maxime Ripard
2026-11-27 11:20   ` Tomi Valkeinen
2026-11-27  9:52 ` [PATCH v10 17/36] drm/atomic-state-helper: Provide atomic_compare_state helpers Maxime Ripard
2026-11-27 10:09   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 18/36] drm/atomic-helper: Document State Read-Out as a state initialization approach Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 19/36] drm/tests: kunit: Add a drm_printer helper Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 20/36] drm/tests: Add tests for the atomic state readout Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 21/36] drm/encoder: Create atomic_sro_get_current_crtc hook Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 22/36] drm/bridge: display-connector: Implement readout support Maxime Ripard
2026-11-27 10:23   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 23/36] drm/bridge_connector: Implement hw readout for connector Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 24/36] drm/atomic_sro: Provide helpers to find the refresh rate from a clock Maxime Ripard
2026-11-28 22:56   ` kernel test robot
2026-11-27  9:53 ` [PATCH v10 25/36] drm/tidss: Implement hw_reset Maxime Ripard
2026-11-27 10:15   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 26/36] drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-27 10:13   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 27/36] drm/tidss: crtc: Implement hardware state readout Maxime Ripard
2026-11-27 10:15   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 28/36] drm/tidss: encoder: " Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 29/36] drm/tidss: kms: Hook up " Maxime Ripard
2026-11-27 10:15   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 30/36] drm/tidss: plane: Implement " Maxime Ripard
2026-11-27 10:20   ` sashiko-bot [this message]
2026-11-27  9:53 ` [PATCH v10 31/36] drm/tidss: encoder: Implement atomic_sro_get_current_crtc Maxime Ripard
2026-11-27  9:53 ` [PATCH v10 32/36] drm/bridge: sii902x: Implement hw state readout Maxime Ripard
2026-11-27 10:24   ` sashiko-bot
2026-11-27  9:53 ` [PATCH v10 33/36] drm/panel: Implement state readout support Maxime Ripard
2026-11-27  9:53 ` [PATCH DO NOT MERGE v10 34/36] fixup! drm/tidss: dispc: Add hardware state readout helpers Maxime Ripard
2026-11-27  9:53 ` [PATCH DO NOT MERGE v10 35/36] drm/tidss: oldi: Implement hardware state readout Maxime Ripard
2026-11-27 10:22   ` sashiko-bot
2026-11-27  9:53 ` [PATCH HACK v10 36/36] drm/panel: Prepare and enable panels read out as active Maxime Ripard

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=sashiko-outbox-237098@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mripard@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.