public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: Fix mem_type change detection for async flips
@ 2026-06-04  6:44 Matthew Schwartz
  2026-06-04  9:49 ` Melissa Wen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matthew Schwartz @ 2026-06-04  6:44 UTC (permalink / raw)
  To: Leo Li, Alex Deucher, Daniel Wheeler, Tom Chung
  Cc: dri-devel, amd-gfx, Matthew Schwartz

[Why]
amdgpu_dm_crtc_mem_type_changed() fetches the "old" and "new" plane state
with two drm_atomic_get_plane_state() calls, which both return the new
state. It compares a state against itself, so it never detects a mem_type
change and never rejects the async flip.

On DCN 3.0.1, this shows up as intermittent corruption when a single DCC
plane is scanned out with immediate flips under gamescope and its buffer
moves between the VRAM carveout and GTT.

[How]
Use drm_atomic_get_old_plane_state() and drm_atomic_get_new_plane_state()
to compare the actual old and new states. These return NULL rather than
an error pointer for a plane that is not part of the commit, so the
IS_ERR() check becomes a NULL check that skips those planes, such as an
unmodified cursor still in the CRTC's plane_mask.

Fixes: 4caacd1671b7a ("drm/amd/display: Do not elevate mem_type change to full update")
Signed-off-by: Matthew Schwartz <matthew.schwartz@linux.dev>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 6c1e7e13f0399..711640739179e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -12934,13 +12934,11 @@ static bool amdgpu_dm_crtc_mem_type_changed(struct drm_device *dev,
 	struct drm_plane_state *new_plane_state, *old_plane_state;
 
 	drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
-		new_plane_state = drm_atomic_get_plane_state(state, plane);
-		old_plane_state = drm_atomic_get_plane_state(state, plane);
+		new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+		old_plane_state = drm_atomic_get_old_plane_state(state, plane);
 
-		if (IS_ERR(new_plane_state) || IS_ERR(old_plane_state)) {
-			drm_err(dev, "Failed to get plane state for plane %s\n", plane->name);
-			return false;
-		}
+		if (!old_plane_state || !new_plane_state)
+			continue;
 
 		if (old_plane_state->fb && new_plane_state->fb &&
 		    get_mem_type(old_plane_state->fb) != get_mem_type(new_plane_state->fb))
-- 
2.54.0


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

* Re: [PATCH] drm/amd/display: Fix mem_type change detection for async flips
  2026-06-04  6:44 [PATCH] drm/amd/display: Fix mem_type change detection for async flips Matthew Schwartz
@ 2026-06-04  9:49 ` Melissa Wen
  2026-06-04 20:42 ` Claude review: " Claude Code Review Bot
  2026-06-04 20:42 ` Claude Code Review Bot
  2 siblings, 0 replies; 4+ messages in thread
From: Melissa Wen @ 2026-06-04  9:49 UTC (permalink / raw)
  To: Matthew Schwartz, Leo Li, Alex Deucher, Daniel Wheeler, Tom Chung
  Cc: dri-devel, amd-gfx



On 04/06/2026 08:44, Matthew Schwartz wrote:
> [Why]
> amdgpu_dm_crtc_mem_type_changed() fetches the "old" and "new" plane state
> with two drm_atomic_get_plane_state() calls, which both return the new
> state. It compares a state against itself, so it never detects a mem_type
> change and never rejects the async flip.
>
> On DCN 3.0.1, this shows up as intermittent corruption when a single DCC
> plane is scanned out with immediate flips under gamescope and its buffer
> moves between the VRAM carveout and GTT.
>
> [How]
> Use drm_atomic_get_old_plane_state() and drm_atomic_get_new_plane_state()
> to compare the actual old and new states. These return NULL rather than
> an error pointer for a plane that is not part of the commit, so the
> IS_ERR() check becomes a NULL check that skips those planes, such as an
> unmodified cursor still in the CRTC's plane_mask.

Nice catch!

Reviewed-by: Melissa Wen <mwen@igalia.com>

>
> Fixes: 4caacd1671b7a ("drm/amd/display: Do not elevate mem_type change to full update")
> Signed-off-by: Matthew Schwartz <matthew.schwartz@linux.dev>
> ---
>   drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 6c1e7e13f0399..711640739179e 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -12934,13 +12934,11 @@ static bool amdgpu_dm_crtc_mem_type_changed(struct drm_device *dev,
>   	struct drm_plane_state *new_plane_state, *old_plane_state;
>   
>   	drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
> -		new_plane_state = drm_atomic_get_plane_state(state, plane);
> -		old_plane_state = drm_atomic_get_plane_state(state, plane);
> +		new_plane_state = drm_atomic_get_new_plane_state(state, plane);
> +		old_plane_state = drm_atomic_get_old_plane_state(state, plane);
>   
> -		if (IS_ERR(new_plane_state) || IS_ERR(old_plane_state)) {
> -			drm_err(dev, "Failed to get plane state for plane %s\n", plane->name);
> -			return false;
> -		}
> +		if (!old_plane_state || !new_plane_state)
> +			continue;
>   
>   		if (old_plane_state->fb && new_plane_state->fb &&
>   		    get_mem_type(old_plane_state->fb) != get_mem_type(new_plane_state->fb))


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

* Claude review: drm/amd/display: Fix mem_type change detection for async flips
  2026-06-04  6:44 [PATCH] drm/amd/display: Fix mem_type change detection for async flips Matthew Schwartz
  2026-06-04  9:49 ` Melissa Wen
@ 2026-06-04 20:42 ` Claude Code Review Bot
  2026-06-04 20:42 ` Claude Code Review Bot
  2 siblings, 0 replies; 4+ messages in thread
From: Claude Code Review Bot @ 2026-06-04 20:42 UTC (permalink / raw)
  To: dri-devel-reviews

Overall Series Review

Subject: drm/amd/display: Fix mem_type change detection for async flips
Author: Matthew Schwartz <matthew.schwartz@linux.dev>
Patches: 2
Reviewed: 2026-06-05T06:42:09.444539

---

This is a single-patch fix for a clear and real bug in `amdgpu_dm_crtc_mem_type_changed()`. The analysis in the commit message is accurate: `drm_atomic_get_plane_state()` is a get-or-allocate function that returns the **new** state pointer (or allocates one if the plane isn't yet in the commit). Calling it twice for the same plane returns the same pointer both times, so the comparison `get_mem_type(old_plane_state->fb) != get_mem_type(new_plane_state->fb)` always evaluates to false, completely defeating the mem_type change detection.

The fix is correct, minimal, and well-explained. **Recommend merge.**

---
Generated by Claude Code Patch Reviewer

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

* Claude review: drm/amd/display: Fix mem_type change detection for async flips
  2026-06-04  6:44 [PATCH] drm/amd/display: Fix mem_type change detection for async flips Matthew Schwartz
  2026-06-04  9:49 ` Melissa Wen
  2026-06-04 20:42 ` Claude review: " Claude Code Review Bot
@ 2026-06-04 20:42 ` Claude Code Review Bot
  2 siblings, 0 replies; 4+ messages in thread
From: Claude Code Review Bot @ 2026-06-04 20:42 UTC (permalink / raw)
  To: dri-devel-reviews

Patch Review

**Bug analysis: Correct.** The existing code at `amdgpu_dm.c:12785-12786`:

```c
new_plane_state = drm_atomic_get_plane_state(state, plane);
old_plane_state = drm_atomic_get_plane_state(state, plane);
```

`drm_atomic_get_plane_state()` is declared `__must_check` and returns an `ERR_PTR` on failure or the (new) plane state pointer on success. Since both calls pass the same `(state, plane)`, the second call finds the plane already added to the atomic state and returns the same `new_state` pointer. So `old_plane_state == new_plane_state` always, and the mem_type comparison is a no-op.

**Fix analysis: Correct.** The replacement:

```c
new_plane_state = drm_atomic_get_new_plane_state(state, plane);
old_plane_state = drm_atomic_get_old_plane_state(state, plane);
```

These are simple inline lookups (confirmed in `drm_atomic.h:808-828`) that return `state->planes[idx].old_state` and `.new_state` respectively, or NULL if the plane is not part of the commit. This correctly retrieves distinct old/new states for comparison.

**NULL handling: Correct.** The change from `IS_ERR()` to a NULL check with `continue`:

```c
if (!old_plane_state || !new_plane_state)
    continue;
```

This is correct because `drm_atomic_get_old/new_plane_state()` returns NULL (not ERR_PTR) when the plane isn't in the commit. Using `continue` rather than `return false` is the right semantic — a plane not participating in this commit can't have a mem_type change, so we skip it and check the remaining planes. The old code's `return false` was also defensively acceptable (since that means "no change detected"), but `continue` is more precise and avoids short-circuiting the loop.

**Iteration scope note (minor).** The loop uses `crtc_state->plane_mask`, which includes all planes currently associated with the CRTC — including planes not being modified in this commit. For those planes, `drm_atomic_get_new_plane_state()` will return NULL, and the `continue` correctly skips them. This is a strict improvement over the old code, which would have *added* every plane in the mask to the atomic state as a side effect of calling `drm_atomic_get_plane_state()` — unnecessarily pulling in unrelated planes during atomic check.

**Commit message quality: Good.** The `[Why]`/`[How]` structure clearly explains both the root cause and the fix. The `Fixes:` tag references the correct introducing commit. The description of the real-world symptom (corruption under gamescope with DCN 3.0.1 when buffers migrate between VRAM and GTT) is helpful.

**No issues found.** The patch is clean, correct, and minimal.

---
Generated by Claude Code Patch Reviewer

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

end of thread, other threads:[~2026-06-04 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-04  6:44 [PATCH] drm/amd/display: Fix mem_type change detection for async flips Matthew Schwartz
2026-06-04  9:49 ` Melissa Wen
2026-06-04 20:42 ` Claude review: " Claude Code Review Bot
2026-06-04 20:42 ` Claude Code Review Bot

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