From: "Christian König" <christian.koenig@amd.com>
To: "Timur Kristóf" <timur.kristof@gmail.com>,
amd-gfx@lists.freedesktop.org,
"Alex Deucher" <alexander.deucher@amd.com>,
"Natalie Vock" <natalie.vock@gmx.de>,
"John Olender" <john.olender@gmail.com>,
"Liu Leo" <Leo.Liu@amd.com>
Subject: Re: [PATCH 4/5] drm/amdgpu/uvd: Fix forcing BOs into UVD segment when it isn't at 0
Date: Tue, 19 May 2026 11:06:51 +0200 [thread overview]
Message-ID: <be651c7b-a9f0-4cbd-bf0a-30b2499b2ef1@amd.com> (raw)
In-Reply-To: <20260519082204.60811-5-timur.kristof@gmail.com>
On 5/19/26 10:22, Timur Kristóf wrote:
> UVD 4.x and older can only access FB and MSG buffers from a
> specific 256M VRAM segment that the VCPU BO is also located in.
> We already modify all placements of the given BO to ensure
> the BO is placed within this segment.
>
> Previously, amdgpu_uvd_force_into_uvd_segment() always assumed
> that the UVD segment is the first 256M of VRAM, even though
> under some conditions the VCPU BO could be allocated outside
> this segment, which made UVD non-functional as the BOs were
> not inside the same segment as the UVD VCPU BO.
>
> Solve that by using the segment where the VCPU BO actually is.
>
> This fixes an issue with UVD failing to initialize on SI/CIK
> when resizable BAR is enabled and the VCPU BO is allocated
> in a different segment.
>
> Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/3851
> Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 36 +++++++++++++++----------
> 1 file changed, 22 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> index 1e59ca924abe..993957927782 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
> @@ -550,16 +550,29 @@ void amdgpu_uvd_free_handles(struct amdgpu_device *adev, struct drm_file *filp)
> }
> }
>
> +/**
> + * amdgpu_uvd_force_into_uvd_segment() - Forces placement of a BO into the UVD segment
> + *
> + * @abo: buffer object whose placement is forced
> + *
> + * UVD 4.x and older can only access FB and MSG buffers from a specific 256M VRAM segment
> + * that the VCPU BO is also located in. Force the BO into that segment.
> + */
> static void amdgpu_uvd_force_into_uvd_segment(struct amdgpu_bo *abo)
> {
> - int i;
> + struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
> + struct amdgpu_bo *vcpu_bo = adev->uvd.inst[0].vcpu_bo;
> + struct amdgpu_res_cursor vcpu_cur;
>
> - for (i = 0; i < abo->placement.num_placement; ++i) {
> - abo->placements[i].fpfn = 0 >> PAGE_SHIFT;
> - abo->placements[i].lpfn = (256 * 1024 * 1024) >> PAGE_SHIFT;
> - if (abo->placements[i].mem_type == TTM_PL_VRAM)
> - abo->placements[i].flags |= TTM_PL_FLAG_CONTIGUOUS;
> - }
> + amdgpu_res_first(vcpu_bo->tbo.resource, 0, amdgpu_bo_size(vcpu_bo), &vcpu_cur);
> +
> + abo->placement.num_placement = 1;
> + abo->placements[0].fpfn = ALIGN_DOWN(vcpu_cur.start, SZ_256M) >> PAGE_SHIFT;
> + abo->placements[0].lpfn = abo->placements[0].fpfn + (SZ_256M >> PAGE_SHIFT);
> + abo->placements[0].mem_type = adev->uvd.inst[0].vcpu_bo->tbo.resource->mem_type;
This should clearly be applied to all placements, it's just that VRAM should use the vcpu segment and GTT the first one.
> +
> + if (abo->placements[0].mem_type == TTM_PL_VRAM)
> + abo->placements[0].flags |= TTM_PL_FLAG_CONTIGUOUS;
> }
>
> static u64 amdgpu_uvd_get_addr_from_ctx(struct amdgpu_uvd_cs_ctx *ctx)
> @@ -600,13 +613,8 @@ static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
> if (!ctx->parser->adev->uvd.address_64_bit) {
> /* check if it's a message or feedback command */
> cmd = amdgpu_ib_get_value(ctx->ib, ctx->idx) >> 1;
> - if (cmd == 0x0 || cmd == 0x3) {
> - /* yes, force it into VRAM */
> - uint32_t domain = AMDGPU_GEM_DOMAIN_VRAM;
> -
> - amdgpu_bo_placement_from_domain(bo, domain);
> - }
> - amdgpu_uvd_force_into_uvd_segment(bo);
> + if (cmd == 0x0 || cmd == 0x3)
> + amdgpu_uvd_force_into_uvd_segment(bo);
The existing code was already correct. We just messed up the GTT handling by not having the correct check in the manager and not supporting GTT->GTT moves.
Regards,
Christian.
>
> r = ttm_bo_validate(&bo->tbo, &bo->placement, &tctx);
> }
next prev parent reply other threads:[~2026-05-19 9:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 8:21 [PATCH 0/5] drm/amdgpu/uvd: Fix UVD BO memory placement issues Timur Kristóf
2026-05-19 8:22 ` [PATCH 1/5] drm/amdgpu: Respect placement requirements in amdgpu_gtt_mgr functions Timur Kristóf
2026-05-19 8:52 ` Christian König
2026-05-19 8:22 ` [PATCH 2/5] drm/amdgpu: Use placements of 256M GART segments for SI/CIK Timur Kristóf
2026-05-19 8:54 ` Christian König
2026-05-19 8:59 ` Timur Kristóf
2026-05-19 9:01 ` Christian König
2026-05-19 9:16 ` Timur Kristóf
2026-05-19 8:22 ` [PATCH 3/5] drm/amdgpu/uvd: Place VCPU BO only in VRAM for UVD 4.x and older Timur Kristóf
2026-05-19 8:56 ` Christian König
2026-05-19 8:22 ` [PATCH 4/5] drm/amdgpu/uvd: Fix forcing BOs into UVD segment when it isn't at 0 Timur Kristóf
2026-05-19 9:06 ` Christian König [this message]
2026-05-19 9:32 ` Timur Kristóf
2026-05-19 8:22 ` [PATCH 5/5] drm/amdgpu/uvd: Move BOs to GTT when we can't place them in VRAM correctly Timur Kristóf
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=be651c7b-a9f0-4cbd-bf0a-30b2499b2ef1@amd.com \
--to=christian.koenig@amd.com \
--cc=Leo.Liu@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=john.olender@gmail.com \
--cc=natalie.vock@gmx.de \
--cc=timur.kristof@gmail.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