Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2818DC982DF for ; Fri, 18 Sep 2026 13:34:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 97BA810F361; Fri, 18 Sep 2026 13:34:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="eQoAbN82"; dkim-atps=neutral Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010006.outbound.protection.outlook.com [52.101.193.6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 787CC10F361 for ; Fri, 18 Sep 2026 13:34:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KS55pFBKqkxjngOhcMByWfuIWfW+WTgSApAktoy6sQdl+ZNplZ+bsVHi3mNcH/XR/aw8VL/65yqYoMcd6CRqfeZNKM2j2G66gFLNyTplkjs2Z6Nu4l46OEmpMvsj7pvXmEUr2A1qIoDoVtQcCIxT/gvc/D6vN2SZy7rOD799CgrixqmaBxG+9WRATbDiPov/Jen4n0fWKfcE2Hv70nLTCMpFZ2iMYtGDay9CzEaH1ulnEUL7ShJ47yMqRZs2m4V8jE/vte6FyLtsBGh3DabjYv3j5GLnJw/4vMTsj7X7qXT+ZB7UV0JLRIBBxZfD2UMVPGOidIZc5gOJZnpSaKobIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ngadwgu5a5g0kmn3RrRISnMk7Z3LHcmKZcWnY3BN4Js=; b=d7iTCeiPjwtDGMBLJdcuPUCVASrGkySM1PbloUodTmynD3WGZDcegUuoLDkeHeXVk/ogmzZXGi3FQKia1Rv5hMAqaUu8pWoO5oW6QiWA+68hocmJTDxZg0impNAyah4PcZspZQp2PT0HRMbGNgtA5YQOo1cR7VPZG0ttmBLrB3egpDY4nMAk+ajp+jH6m4a2pJHD4f0AWsQgEZfbqzNkRNS8wH2P6U74gK23mjU/JWs2Dp+RjrZSNoMS+q4vQuWngdcQ0RazRQhvkkZWd+pIZ24lKjUU4Sd7TOB8oe1j3Lz63FWbb3rOq37CUcVnETuXT4aQwJI4TFyzdOpeCekLmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ngadwgu5a5g0kmn3RrRISnMk7Z3LHcmKZcWnY3BN4Js=; b=eQoAbN82v2HrkGs0gaRrPV+2Yy6G/7Kf1QvMeFZV9IbHpcdt8bey0FCj0lvoW3VU/tuZPKyxfsX1uptVSjS6CiaRAKH6jQfDDgbgh3ZoE6hRvhfZ8aGBXXVTbtnPhDqVLpjQXWSAiOvUsgEk/0KO87dnI0I6aUbKq9rcFnXJ9bc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from SA0PR12MB7091.namprd12.prod.outlook.com (2603:10b6:806:2d5::17) by SJ2PR12MB7896.namprd12.prod.outlook.com (2603:10b6:a03:4c6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.13; Fri, 18 Sep 2026 13:34:10 +0000 Received: from SA0PR12MB7091.namprd12.prod.outlook.com ([fe80::ec33:1213:cfd8:63bc]) by SA0PR12MB7091.namprd12.prod.outlook.com ([fe80::ec33:1213:cfd8:63bc%6]) with mapi id 15.21.0428.011; Fri, 18 Sep 2026 13:34:10 +0000 Message-ID: <04dc6bc5-4fb0-4e8b-a3f4-bc681ddf0b73@amd.com> Date: Fri, 18 Sep 2026 19:04:05 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 01/18] drm/amdgpu: More compact VCN IB emission To: Tvrtko Ursulin , amd-gfx@lists.freedesktop.org Cc: kernel-dev@igalia.com, =?UTF-8?Q?Timur_Krist=C3=B3f?= , Alex Deucher References: <20260918120518.96922-1-tvrtko.ursulin@igalia.com> <20260918120518.96922-2-tvrtko.ursulin@igalia.com> <474139b2-c3c2-4d2b-81d7-e209231870f2@amd.com> <84ae6c9c-6ea5-4e02-9dbe-5ba855580da1@igalia.com> <052c9390-8906-4f8f-a501-30730c41f011@igalia.com> Content-Language: en-US From: "Lazar, Lijo" In-Reply-To: <052c9390-8906-4f8f-a501-30730c41f011@igalia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MA5PR01CA0266.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:21c::13) To SA0PR12MB7091.namprd12.prod.outlook.com (2603:10b6:806:2d5::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA0PR12MB7091:EE_|SJ2PR12MB7896:EE_ X-MS-Office365-Filtering-Correlation-Id: 084dc241-4d1d-4584-ebe1-08df15898554 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|1800799024|376014|366016|22082099003|18002099003|56012099006|11063799006|4143699003|6133799003|10067099003; X-Microsoft-Antispam-Message-Info: gBLGFu9ukpwm7t6a+5PtlZD/+angH/r/nhsXXi9sdToBYToesZ+/9JPONHnyOw+0Zx6GNZQZOhC0VoWJavSe0608scOkK07jrSjtPddyCvRUXP40d8U3CZjytkpi85pvp2Qg6AWiMQw+EAWIxn0wDirCahxsIym1wLgpneKNgSVWlm5kxl59rmXPtCmceAG0U2HRm42J7Muc/K0bSKKK0asyeL8TIKltCeBzyYhBsIq9Oamf/T+Ak1CtGbquRRFKKvfL3sKB2zDx8YYhHQQ4yNcBSvF9LlQnBGMYXo4loUIPjQjLufTtkT7DIIc+mwQwKzp59dCcehfI65c1EHwpHF2lD709HSEaTvW5Jsg4I+EsKwrrVjNDmw5Tsuy5ZVKegOa3PASDwUEGzAx7mMi2Kn13OeiW078zRS8M85BPrLL0VSCkvKK8fLC24HNZDadozqJUJGjNlho5zqW7ZUJ+fZW2DUyWRJ8uLjocEWhM6d6sr7bIl+YyUTMQcleIk0xQavTMugxVJk4VSsxoXRgalgSm2Ff+kKF5TdkzqzfOnyfT54eL4jFmT7aqxzE0I1qTzYMTTZYkuCLX7OzDnpIm7QhGHu0jEPWkjc6BzSzQ5IIJSm2olqmJjg0bOePoOW86TZDZ3mrFzLUBuFeomYiBmS87JWpMSq1Maa1i9gIc6Zo= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA0PR12MB7091.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(1800799024)(376014)(366016)(22082099003)(18002099003)(56012099006)(11063799006)(4143699003)(6133799003)(10067099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?T0ZxanFZckJKQ1k2NDlseEMvVkhycUJlV0hWdDZ2Q1YxQ0s3QUR4dTRmZXhB?= =?utf-8?B?WWFDZ3lPNzd4T2dHUUVBdDVCN21YVS95OUdjK241TmdGdzdCL2Q5V0YyRjc3?= =?utf-8?B?MW84ZkZF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QOTl4L1A3cWpp?= =?utf-8?B?bnpXZ3J6R0ZVZTVTNW93V0lCNWxpUUQ2KzhYN2JwT2xYN1lVZzl6bUtJeTlr?= =?utf-8?B?UllnTWg3b3o3ZEJTeVYrZlBRNFd4SE9LUlVJeEl5VVR2K2V2b0Npb0JicUY0?= =?utf-8?B?NG5kYkFOMk1lR2p5RjlQRkJJRHJaTG96T2JtQUpuN2t5bmJ5T0RFZFJoWmFH?= =?utf-8?B?ek1UK0JwdGc4RGhUODZsYWRtL2NyYVpOV1dLYWYyOWR3KzlsQVVrcUtKTnJ1?= =?utf-8?B?Rmlxckd0My9MVTB0OFMwY3JtTngxSU5HekljT2luUkVxMUtxMlVQV3RsYkkv?= =?utf-8?B?aGRXc2JoWlNJNlJMYWdOYmZyVjlxTkJMbi9vVzZ0ZmIrcjFHT29sQmRyT1FN?= =?utf-8?Q?AiDHf+qJ0OVXveH8Ze?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 084dc241-4d1d-4584-ebe1-08df15898554 X-MS-Exchange-CrossTenant-AuthSource: SA0PR12MB7091.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2026 13:34:10.3119 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wvQjNSAwA1a+CtnJmnDliVU5Ett7jURu1V5cWWhfQYlBzJN5i5VHZS9+naliasNm X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7896 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On 18-Sep-26 6:59 PM, Tvrtko Ursulin wrote: > > On 18/09/2026 14:23, Lazar, Lijo wrote: >> On 18-Sep-26 6:43 PM, Tvrtko Ursulin wrote: >>> >>> On 18/09/2026 14:08, Lazar, Lijo wrote: >>>> >>>> >>>> On 18-Sep-26 5:35 PM, Tvrtko Ursulin wrote: >>>>> Avoid constant register reloads while emitting IBs by using a local >>>>> write >>>>> pointer and only updating the size at the end of each helper. >>>>> >>>>> Signed-off-by: Tvrtko Ursulin >>>>> Cc: Timur Kristóf >>>>> Cc: Alex Deucher >>>>> --- >>>>> v2: >>>>>   *  Fix decode buffer overwrite >>>> >>>> Overall for this series, below type of calculation  - >>>> >>>>      ib->length_dw = ptr - ib->ptr; >>>> >>>> is not anticipating a case like below. >>>> >>>>          r = amdgpu_vcn_enc_get_create_msg(ring, 1, &ib, NULL); >>>>          if (r) >>>>                  goto error; >>>> >>>>          r = amdgpu_vcn_enc_get_destroy_msg(ring, 1, &ib, &fence); >>>>          if (r) >>>>                  goto error; >>> >>> So amdgpu_vcn_enc_ring_test_ib() - are you saying there is a bug >>> there? Help me see it please. >>> >>> ib->length_dw update is enclosed in both of those helpers, same as >>> before the patch. >>> >> >> What I'm saying is - >> >> It's the same ib pointer that is passed to back to back calls. >> >> Legacy implementation fills like - >> >> ib->ptr[ib->length_dw++] >> >> So no assumption that it is starting from offset 0 always. After the >> function is filled, length gets updated based on what is filled. >> >> I don't see the same with an assignment like >> >>      ib->length_dw = ptr - ib->ptr; > > Hm, but both of those helpers emit separate jobs with their own > respective IB. > Wouldn't this kind of logic help to be on the safer side - ib->length_dw += ptr - &ib->ptr[start_size]; Thanks, Lijo > Regards, > > Tvrtko > >>>>> --- >>>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 134 ++++++++++++ >>>>> +----------- >>>>>   1 file changed, 75 insertions(+), 59 deletions(-) >>>>> >>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/ >>>>> drm/amd/amdgpu/amdgpu_vcn.c >>>>> index 17db7264269e..2c367ee6e182 100644 >>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c >>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c >>>>> @@ -622,9 +622,12 @@ static int amdgpu_vcn_dec_send_msg(struct >>>>> amdgpu_ring *ring, >>>>>   { >>>>>       u64 addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>>       struct amdgpu_device *adev = ring->adev; >>>>> +    struct amdgpu_vcn_reg *internal = &adev->vcn.inst[ring- >>>>> >me].internal; >>>>> +    uint32_t nop = PACKET0(internal->nop, 0); >>>>>       struct dma_fence *f = NULL; >>>>>       struct amdgpu_job *job; >>>>>       struct amdgpu_ib *ib; >>>>> +    uint32_t *ptr; >>>>>       int i, r; >>>>>       r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, >>>>> @@ -635,15 +638,16 @@ static int amdgpu_vcn_dec_send_msg(struct >>>>> amdgpu_ring *ring, >>>>>           goto err; >>>>>       ib = &job->ibs[0]; >>>>> -    ib->ptr[0] = PACKET0(adev->vcn.inst[ring->me].internal.data0, 0); >>>>> -    ib->ptr[1] = addr; >>>>> -    ib->ptr[2] = PACKET0(adev->vcn.inst[ring->me].internal.data1, 0); >>>>> -    ib->ptr[3] = addr >> 32; >>>>> -    ib->ptr[4] = PACKET0(adev->vcn.inst[ring->me].internal.cmd, 0); >>>>> -    ib->ptr[5] = 0; >>>>> +    ptr = ib->ptr; >>>>> +    *ptr++ = PACKET0(internal->data0, 0); >>>>> +    *ptr++ = addr; >>>>> +    *ptr++ = PACKET0(internal->data1, 0); >>>>> +    *ptr++ = addr >> 32; >>>>> +    *ptr++ = PACKET0(internal->cmd, 0); >>>>> +    *ptr++ = 0; >>>>>       for (i = 6; i < 16; i += 2) { >>>>> -        ib->ptr[i] = PACKET0(adev->vcn.inst[ring- >>>>> >me].internal.nop, 0); >>>>> -        ib->ptr[i+1] = 0; >>>>> +        *ptr++ = nop; >>>>> +        *ptr++ = 0; >>>>>       } >>>>>       ib->length_dw = 16; >>>>> @@ -763,17 +767,20 @@ int amdgpu_vcn_dec_ring_test_ib(struct >>>>> amdgpu_ring *ring, long timeout) >>>>>   static uint32_t *amdgpu_vcn_unified_ring_ib_header(struct >>>>> amdgpu_ib *ib, >>>>>                           uint32_t ib_pack_in_dw, bool enc) >>>>>   { >>>>> +    u32 *ptr = &ib->ptr[ib->length_dw]; >>>>>       uint32_t *ib_checksum; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000010; /* single queue >>>>> checksum */ >>>>> -    ib->ptr[ib->length_dw++] = 0x30000002; >>>>> -    ib_checksum = &ib->ptr[ib->length_dw++]; >>>>> -    ib->ptr[ib->length_dw++] = ib_pack_in_dw; >>>>> +    *ptr++ = 0x00000010; /* single queue checksum */ >>>>> +    *ptr++ = 0x30000002; >>>>> +    ib_checksum = ptr++; >>>>> +    *ptr++ = ib_pack_in_dw; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000010; /* engine info */ >>>>> -    ib->ptr[ib->length_dw++] = 0x30000001; >>>>> -    ib->ptr[ib->length_dw++] = enc ? 0x2 : 0x3; >>>>> -    ib->ptr[ib->length_dw++] = ib_pack_in_dw * sizeof(uint32_t); >>>>> +    *ptr++ = 0x00000010; /* engine info */ >>>>> +    *ptr++ = 0x30000001; >>>>> +    *ptr++ = enc ? 0x2 : 0x3; >>>>> +    *ptr++ = ib_pack_in_dw * sizeof(uint32_t); >>>>> + >>>>> +    ib->length_dw = ptr - ib->ptr; >>>>>       return ib_checksum; >>>>>   } >>>>> @@ -803,7 +810,8 @@ static int amdgpu_vcn_dec_sw_send_msg(struct >>>>> amdgpu_ring *ring, >>>>>       uint64_t addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>>       uint32_t *ib_checksum; >>>>>       uint32_t ib_pack_in_dw; >>>>> -    int i, r; >>>>> +    u32 *ptr; >>>>> +    int r; >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           ib_size_dw += 8; >>>>> @@ -825,18 +833,20 @@ static int amdgpu_vcn_dec_sw_send_msg(struct >>>>> amdgpu_ring *ring, >>>>>           ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, >>>>> ib_pack_in_dw, false); >>>>>       } >>>>> -    ib->ptr[ib->length_dw++] = sizeof(struct >>>>> amdgpu_vcn_decode_buffer) + 8; >>>>> -    ib->ptr[ib->length_dw++] = >>>>> cpu_to_le32(AMDGPU_VCN_IB_FLAG_DECODE_BUFFER); >>>>> -    decode_buffer = (struct amdgpu_vcn_decode_buffer *)&(ib- >>>>> >ptr[ib- >length_dw]); >>>>> -    ib->length_dw += sizeof(struct amdgpu_vcn_decode_buffer) / 4; >>>>> +    ptr = &ib->ptr[ib->length_dw]; >>>>> + >>>>> +    *ptr++ = sizeof(struct amdgpu_vcn_decode_buffer) + 8; >>>>> +    *ptr++ = cpu_to_le32(AMDGPU_VCN_IB_FLAG_DECODE_BUFFER); >>>>> +    decode_buffer = (struct amdgpu_vcn_decode_buffer *)ptr; >>>>> +    ptr += sizeof(struct amdgpu_vcn_decode_buffer) / 4; >>>>> +    ib->length_dw = ptr - ib->ptr; >>>>>       memset(decode_buffer, 0, sizeof(struct >>>>> amdgpu_vcn_decode_buffer)); >>>>>       decode_buffer->valid_buf_flag |= >>>>> cpu_to_le32(AMDGPU_VCN_CMD_FLAG_MSG_BUFFER); >>>>>       decode_buffer->msg_buffer_address_hi = cpu_to_le32(addr >> 32); >>>>>       decode_buffer->msg_buffer_address_lo = cpu_to_le32(addr); >>>>> -    for (i = ib->length_dw; i < ib_size_dw; ++i) >>>>> -        ib->ptr[i] = 0x0; >>>>> +    memset32(ptr, 0, ib_size_dw - ib->length_dw); >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, >>>>> ib_pack_in_dw); >>>>> @@ -934,7 +944,8 @@ static int amdgpu_vcn_enc_get_create_msg(struct >>>>> amdgpu_ring *ring, uint32_t hand >>>>>       struct dma_fence *f = NULL; >>>>>       uint32_t *ib_checksum = NULL; >>>>>       uint64_t addr; >>>>> -    int i, r; >>>>> +    u32 *ptr; >>>>> +    int r; >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           ib_size_dw += 8; >>>>> @@ -947,31 +958,33 @@ static int >>>>> amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand >>>>>           return r; >>>>>       ib = &job->ibs[0]; >>>>> -    addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>> - >>>>>       ib->length_dw = 0; >>>>> +    addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, 0x11, >>>>> true); >>>>> -    ib->ptr[ib->length_dw++] = 0x00000018; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000001; /* session info */ >>>>> -    ib->ptr[ib->length_dw++] = handle; >>>>> -    ib->ptr[ib->length_dw++] = upper_32_bits(addr); >>>>> -    ib->ptr[ib->length_dw++] = addr; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> +    ptr = &ib->ptr[ib->length_dw]; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000014; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000002; /* task info */ >>>>> -    ib->ptr[ib->length_dw++] = 0x0000001c; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> +    *ptr++ = 0x00000018; >>>>> +    *ptr++ = 0x00000001; /* session info */ >>>>> +    *ptr++ = handle; >>>>> +    *ptr++ = upper_32_bits(addr); >>>>> +    *ptr++ = addr; >>>>> +    *ptr++ = 0x00000000; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000008; >>>>> -    ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */ >>>>> +    *ptr++ = 0x00000014; >>>>> +    *ptr++ = 0x00000002; /* task info */ >>>>> +    *ptr++ = 0x0000001c; >>>>> +    *ptr++ = 0x00000000; >>>>> +    *ptr++ = 0x00000000; >>>>> -    for (i = ib->length_dw; i < ib_size_dw; ++i) >>>>> -        ib->ptr[i] = 0x0; >>>>> +    *ptr++ = 0x00000008; >>>>> +    *ptr++ = 0x08000001; /* op initialize */ >>>>> + >>>>> +    ib->length_dw = ptr - ib->ptr; >>>>> + >>>>> +    memset32(ptr, 0, ib_size_dw - ib->length_dw); >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, 0x11); >>>>> @@ -1002,7 +1015,8 @@ static int >>>>> amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han >>>>>       struct dma_fence *f = NULL; >>>>>       uint32_t *ib_checksum = NULL; >>>>>       uint64_t addr; >>>>> -    int i, r; >>>>> +    u32 *ptr; >>>>> +    int r; >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           ib_size_dw += 8; >>>>> @@ -1015,31 +1029,33 @@ static int >>>>> amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han >>>>>           return r; >>>>>       ib = &job->ibs[0]; >>>>> -    addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>> - >>>>>       ib->length_dw = 0; >>>>> +    addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr); >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           ib_checksum = amdgpu_vcn_unified_ring_ib_header(ib, 0x11, >>>>> true); >>>>> -    ib->ptr[ib->length_dw++] = 0x00000018; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000001; >>>>> -    ib->ptr[ib->length_dw++] = handle; >>>>> -    ib->ptr[ib->length_dw++] = upper_32_bits(addr); >>>>> -    ib->ptr[ib->length_dw++] = addr; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> +    ptr = &ib->ptr[ib->length_dw]; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000014; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000002; >>>>> -    ib->ptr[ib->length_dw++] = 0x0000001c; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000000; >>>>> +    *ptr++ = 0x00000018; >>>>> +    *ptr++ = 0x00000001; >>>>> +    *ptr++ = handle; >>>>> +    *ptr++ = upper_32_bits(addr); >>>>> +    *ptr++ = addr; >>>>> +    *ptr++ = 0x00000000; >>>>> -    ib->ptr[ib->length_dw++] = 0x00000008; >>>>> -    ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */ >>>>> +    *ptr++ = 0x00000014; >>>>> +    *ptr++ = 0x00000002; >>>>> +    *ptr++ = 0x0000001c; >>>>> +    *ptr++ = 0x00000000; >>>>> +    *ptr++ = 0x00000000; >>>>> -    for (i = ib->length_dw; i < ib_size_dw; ++i) >>>>> -        ib->ptr[i] = 0x0; >>>>> +    *ptr++ = 0x00000008; >>>>> +    *ptr++ = 0x08000002; /* op close session */ >>>>> + >>>>> +    ib->length_dw = ptr - ib->ptr; >>>>> + >>>>> +    memset32(ptr, 0, ib_size_dw - ib->length_dw); >>>>>       if (adev->vcn.inst[ring->me].using_unified_queue) >>>>>           amdgpu_vcn_unified_ring_ib_checksum(&ib_checksum, 0x11); >>>> >>> >> >