On Wed, Dec 2, 2026 at 1:39 AM Eren Özen via B4 Relay
<[email protected]> wrote:
>
> From: Eren Özen <[email protected]>
>
> On rings with emit_frame_cntl, amdgpu_ib_schedule() writes a
> FRAME_CONTROL start before the first IB and an end after the last one,
> and whenever AMDGPU_IB_FLAGS_SECURE changes between two IBs of a job it
> writes an end and a start back to back. Each FRAME_CONTROL is 2 dwords
> on gfx9, gfx10, gfx11 and gfx13, but neither the gfx emit_frame_size
> nor emit_ib_size of these rings counts them. Userspace sets the secure
> flag per IB (amdgpu_cs.c copies the IB flags unchanged), and nothing
> requires the IBs of a job to agree, so a job that switches the flag
> often enough between its IBs writes more than amdgpu_ring_alloc()
> reserved for it.
>
> On gfx9, one job of 63 NOP IBs that alternate the flag makes
> amdgpu_ring_commit() report "writing more dwords to the ring than
> expected!". A job of 192 such IBs, the gfx limit, needs up to about 1740
> dwords, while the reservation and max_dw are 1024. With the default
> sched_hw_submission of 2 the gfx ring holds 2048 dwords, so such a job
> can overwrite commands of another job that is still in flight
> (inferred, not tested).
>
> Count 4 dwords for the start and end in emit_frame_size, and 4 more per
> IB in emit_ib_size for the end and start of a switch. The worst cases
> become 208 + 192 * 8 = 1744 dwords on gfx9 (also for the gfx9 software
> rings used with MCBP), 1741 on gfx10, 1765 on gfx11 and 1699 on gfx13,
> so raise the max_dw of these gfx rings from 1024 to 2048 (otherwise
> amdgpu_ring_init() WARNs). With the default sched_hw_submission of 2
> that makes each gfx ring 16 KiB instead of 8 KiB.
>
> Tested on a Ryzen 7 5800H (Cezanne, GC 9.3.0) with one job per IB
> count on the gfx ring, every other IB secure. Before this change every
> job of 53 to 63 IBs made amdgpu_ring_commit() report the error (larger
> jobs were not submitted on that kernel); with it, no job of 1 to 192
> IBs did. The same jobs without secure IBs stayed clean on both kernels.
> No WARNs at boot, the gfx ring is 16 KiB (debugfs amdgpu_ring_gfx is
> 16396 bytes), and the IB tests in debugfs amdgpu_test_ib pass. gfx10,
> gfx11, gfx13 and the gfx9 MCBP software rings are not tested.
>
> Fixes: 0bb5d5b03f78 ("drm/amdgpu: Move to a per-IB secure flag (TMZ)")
> Fixes: f77c9aff85ca ("drm/amdgpu: Fix per-IB secure flag GFX hang")
> Signed-off-by: Eren Özen <[email protected]>
> ---
> An alternative is to limit the secure-flag switches per job in
> amdgpu_cs and count only that limit. Rejecting mixed flags outright
> would break RADV, which does not set the flag on its postamble IBs, so
> a secure RADV submission can already switch once. I chose the static
> count because the ring has to be sized for the worst case anyway, but I
> can rework it if you prefer a limit.
>
> The test kernel also carried three unrelated amdgpu compute ring
> patches.
>
> I found this with an AI coding assistant while reviewing the ring frame
> sizes. A small test program that triggers the message is available on
> request.
> ---
>  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c |  8 +++++---
>  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c |  8 +++++---
>  drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c |  8 +++++---

You can drop the gfx13 changes.  I just sent a patch to remove
frame_cntl from gfx13.  It doesn't support TMZ on a per frame basis,
same as gfx12.

Alex

>  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  | 16 ++++++++++------
>  4 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
> index b28dd5eaf1bb..fb87fd059b3f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
> @@ -4680,7 +4680,7 @@ static int gfx_v10_0_gfx_ring_init(struct amdgpu_device 
> *adev, int ring_id,
>         irq_type = AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + ring->pipe;
>         hw_prio = amdgpu_gfx_is_high_priority_graphics_queue(adev, ring) ?
>                         AMDGPU_GFX_PIPE_PRIO_HIGH : 
> AMDGPU_GFX_PIPE_PRIO_NORMAL;
> -       return amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq, 
> irq_type,
> +       return amdgpu_ring_init(adev, ring, 2048, &adev->gfx.eop_irq, 
> irq_type,
>                                 hw_prio, NULL);
>  }
>
> @@ -9724,8 +9724,10 @@ static const struct amdgpu_ring_funcs 
> gfx_v10_0_ring_funcs_gfx = {
>                 8 + 8 + /* FENCE x2 */
>                 2 + /* SWITCH_BUFFER */
>                 8 + /* gfx_v10_0_emit_mem_sync */
> -               2, /* gfx_v10_0_ring_emit_cleaner_shader */
> -       .emit_ib_size = 4, /* gfx_v10_0_ring_emit_ib_gfx */
> +               2 + /* gfx_v10_0_ring_emit_cleaner_shader */
> +               4, /* FRAME_CONTROL start and end */
> +       .emit_ib_size = 4 + /* gfx_v10_0_ring_emit_ib_gfx */
> +               4, /* FRAME_CONTROL end and start when the secure flag 
> changes */
>         .emit_ib = gfx_v10_0_ring_emit_ib_gfx,
>         .emit_fence = gfx_v10_0_ring_emit_fence,
>         .emit_pipeline_sync = gfx_v10_0_ring_emit_pipeline_sync,
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> index 16b211174c8d..24495d07fd6a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> @@ -1247,7 +1247,7 @@ static int gfx_v11_0_gfx_ring_init(struct amdgpu_device 
> *adev, int ring_id,
>         irq_type = AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + ring->pipe;
>         hw_prio = amdgpu_gfx_is_high_priority_graphics_queue(adev, ring) ?
>                 AMDGPU_GFX_PIPE_PRIO_HIGH : AMDGPU_GFX_PIPE_PRIO_NORMAL;
> -       return amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq, 
> irq_type,
> +       return amdgpu_ring_init(adev, ring, 2048, &adev->gfx.eop_irq, 
> irq_type,
>                                 hw_prio, NULL);
>  }
>
> @@ -7047,8 +7047,10 @@ static const struct amdgpu_ring_funcs 
> gfx_v11_0_ring_funcs_gfx = {
>                 22 + /* SET_Q_PREEMPTION_MODE */
>                 8 + 8 + /* FENCE x2 */
>                 8 + /* gfx_v11_0_emit_mem_sync */
> -               2, /* gfx_v11_0_ring_emit_cleaner_shader */
> -       .emit_ib_size = 4, /* gfx_v11_0_ring_emit_ib_gfx */
> +               2 + /* gfx_v11_0_ring_emit_cleaner_shader */
> +               4, /* FRAME_CONTROL start and end */
> +       .emit_ib_size = 4 + /* gfx_v11_0_ring_emit_ib_gfx */
> +               4, /* FRAME_CONTROL end and start when the secure flag 
> changes */
>         .emit_ib = gfx_v11_0_ring_emit_ib_gfx,
>         .emit_fence = gfx_v11_0_ring_emit_fence,
>         .emit_pipeline_sync = gfx_v11_0_ring_emit_pipeline_sync,
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c
> index c06fa6b9b299..48bb10bba677 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v13_0.c
> @@ -998,7 +998,7 @@ static int gfx_v13_0_gfx_ring_init(struct amdgpu_device 
> *adev, int ring_id,
>         sprintf(ring->name, "gfx_%d.%d.%d", ring->me, ring->pipe, 
> ring->queue);
>
>         irq_type = AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP + ring->pipe;
> -       r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq, irq_type,
> +       r = amdgpu_ring_init(adev, ring, 2048, &adev->gfx.eop_irq, irq_type,
>                              AMDGPU_RING_PRIO_DEFAULT, NULL);
>         if (r)
>                 return r;
> @@ -5524,8 +5524,10 @@ static const struct amdgpu_ring_funcs 
> gfx_v13_0_ring_funcs_gfx = {
>                 5 + /* HDP_INVL */
>                 8 + 8 + /* FENCE x2 */
>                 8 + /* gfx_v13_0_emit_mem_sync */
> -               2, /* gfx_v13_0_ring_emit_cleaner_shader */
> -       .emit_ib_size = 4, /* gfx_v13_0_ring_emit_ib_gfx */
> +               2 + /* gfx_v13_0_ring_emit_cleaner_shader */
> +               4, /* FRAME_CONTROL start and end */
> +       .emit_ib_size = 4 + /* gfx_v13_0_ring_emit_ib_gfx */
> +               4, /* FRAME_CONTROL end and start when the secure flag 
> changes */
>         .emit_ib = gfx_v13_0_ring_emit_ib_gfx,
>         .emit_fence = gfx_v13_0_ring_emit_fence,
>         .emit_pipeline_sync = gfx_v13_0_ring_emit_pipeline_sync,
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
> b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> index c343224423d3..7b90715a2060 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
> @@ -2355,7 +2355,7 @@ static int gfx_v9_0_sw_init(struct amdgpu_ip_block 
> *ip_block)
>                 /* disable scheduler on the real ring */
>                 ring->no_scheduler = adev->gfx.mcbp;
>                 ring->vm_hub = AMDGPU_GFXHUB(0);
> -               r = amdgpu_ring_init(adev, ring, 1024, &adev->gfx.eop_irq,
> +               r = amdgpu_ring_init(adev, ring, 2048, &adev->gfx.eop_irq,
>                                      AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP,
>                                      AMDGPU_RING_PRIO_DEFAULT, NULL);
>                 if (r)
> @@ -2373,7 +2373,7 @@ static int gfx_v9_0_sw_init(struct amdgpu_ip_block 
> *ip_block)
>                         ring->is_sw_ring = true;
>                         hw_prio = amdgpu_sw_ring_priority(i);
>                         ring->vm_hub = AMDGPU_GFXHUB(0);
> -                       r = amdgpu_ring_init(adev, ring, 1024, 
> &adev->gfx.eop_irq,
> +                       r = amdgpu_ring_init(adev, ring, 2048, 
> &adev->gfx.eop_irq,
>                                              AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP, 
> hw_prio,
>                                              NULL);
>                         if (r)
> @@ -7631,8 +7631,10 @@ static const struct amdgpu_ring_funcs 
> gfx_v9_0_ring_funcs_gfx = {
>                 8 + 8 + /* FENCE x2 */
>                 2 + /* SWITCH_BUFFER */
>                 7 + /* gfx_v9_0_emit_mem_sync */
> -               2, /* gfx_v9_0_ring_emit_cleaner_shader */
> -       .emit_ib_size = 4, /* gfx_v9_0_ring_emit_ib_gfx */
> +               2 + /* gfx_v9_0_ring_emit_cleaner_shader */
> +               4, /* FRAME_CONTROL start and end */
> +       .emit_ib_size = 4 + /* gfx_v9_0_ring_emit_ib_gfx */
> +               4, /* FRAME_CONTROL end and start when the secure flag 
> changes */
>         .emit_ib = gfx_v9_0_ring_emit_ib_gfx,
>         .emit_fence = gfx_v9_0_ring_emit_fence,
>         .emit_pipeline_sync = gfx_v9_0_ring_emit_pipeline_sync,
> @@ -7689,8 +7691,10 @@ static const struct amdgpu_ring_funcs 
> gfx_v9_0_sw_ring_funcs_gfx = {
>                 8 + 8 + /* FENCE x2 */
>                 2 + /* SWITCH_BUFFER */
>                 7 + /* gfx_v9_0_emit_mem_sync */
> -               2, /* gfx_v9_0_ring_emit_cleaner_shader */
> -       .emit_ib_size = 4, /* gfx_v9_0_ring_emit_ib_gfx */
> +               2 + /* gfx_v9_0_ring_emit_cleaner_shader */
> +               4, /* FRAME_CONTROL start and end */
> +       .emit_ib_size = 4 + /* gfx_v9_0_ring_emit_ib_gfx */
> +               4, /* FRAME_CONTROL end and start when the secure flag 
> changes */
>         .emit_ib = gfx_v9_0_ring_emit_ib_gfx,
>         .emit_fence = gfx_v9_0_ring_emit_fence,
>         .emit_pipeline_sync = gfx_v9_0_ring_emit_pipeline_sync,
>
> ---
> base-commit: 38541b3d475e3eac453e1064014d5d4356383075
> change-id: 20261202-gfx-frame-cntl-d0b829405080
>
> Best regards,
> --
> Eren Özen <[email protected]>
>
>

Reply via email to