Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The GTT fallback logic fails to handle `-EINVAL` for shared framebuffers and `-ENOSPC` when VRAM is full, breaking atomic commits. - [High] Unconditional pinning to VRAM causes severe CPU thrashing and dmesg spam on every page flip under memory pressure. --
commit 56a58731a1850c7efcd10ad3db0b21ff08dd0a48 Author: Matthew Schwartz <[email protected]> Subject: drm/amd/display: Pin native scanout to VRAM on large-carveout APUs This patch modifies the framebuffer preparation logic to pin native scanout buffers in VRAM for APUs with large carveouts. If the VRAM allocation fails, it falls back to GTT to ensure the swapchain remains in a single memory domain. > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c > b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c > index 23a9faa2ea89f..8a5d03185c479 100644 > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c > @@ -958,13 +959,35 @@ static int amdgpu_dm_plane_helper_prepare_fb(struct > drm_plane *plane, > if (r) > goto error_unlock; > > - if (plane->type != DRM_PLANE_TYPE_CURSOR) > - domain = amdgpu_display_supported_domains(adev, rbo->flags); > - else > + /* > + * Pin native scanout in VRAM on APUs so a swapchain stays in one > + * memory domain. A VRAM/GTT split changes its mem_type between flips > + * and amdgpu_dm_crtc_mem_type_changed() rejects the async flip. Skip > + * small carveouts that may not fit, and imported buffers. > + */ > + pin_vram_only = plane->type != DRM_PLANE_TYPE_CURSOR && > + (adev->flags & AMD_IS_APU) && > + !rbo->tbo.base.import_attach && > + adev->gmc.real_vram_size > AMDGPU_SG_THRESHOLD; > + > + if (plane->type == DRM_PLANE_TYPE_CURSOR || pin_vram_only) > domain = AMDGPU_GEM_DOMAIN_VRAM; > + else > + domain = amdgpu_display_supported_domains(adev, rbo->flags); > > rbo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; > r = amdgpu_bo_pin(rbo, domain); [Severity: High] Does this unconditional VRAM pinning attempt cause severe CPU thrashing and dmesg spam on every page flip under memory pressure? Since prepare_fb runs on every page flip for unpinned swapchain buffers, a full VRAM might cause amdgpu_bo_pin() to perform an expensive memory eviction search and log a hard error via dev_err() 60 times a second. Additionally, if a buffer was previously placed in GTT via the fallback and unpinned, the next page flip will attempt to migrate it back to VRAM, causing an eviction storm. > + if (r == -ENOMEM && pin_vram_only) { [Severity: High] Will this strict check for -ENOMEM fail to handle -EINVAL and -ENOSPC, causing the VRAM-to-GTT fallback to be skipped? When VRAM is full, TTM's allocation often returns -ENOSPC instead of -ENOMEM. If a framebuffer is shared across planes (e.g., cloned displays) and the first plane falls back to GTT, the buffer is pinned in GTT with pin_count = 1. When the second plane calls amdgpu_bo_pin() with AMDGPU_GEM_DOMAIN_VRAM, it returns -EINVAL. Skipping the fallback in these cases would break the atomic commit. > + /* > + * VRAM could not fit the buffer. Fall back to GTT where > + * allowed so the swapchain stays in one domain. > + */ > + domain = amdgpu_display_supported_domains(adev, rbo->flags); > + if (domain & AMDGPU_GEM_DOMAIN_GTT) { > + domain = AMDGPU_GEM_DOMAIN_GTT; > + r = amdgpu_bo_pin(rbo, domain); > + } > + } > if (unlikely(r != 0)) { > if (r != -ERESTARTSYS) -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
