On 5/13/26 4:04 PM, Timur Kristóf wrote:
> The VCPU BO contains the actual FW at an offset, but
> it was not calculated into the VCPU BO size.
> Subtract this from the FW size to make sure there is
> no out of bounds access.
> 
> Additionally, increase the VCE_V2_0_DATA_SIZE to
> have extra space after the VCE handles.
> 
> Also increase the data size used for each VCE handle.
> The FW needs 23744 bytes, use 24K to be safe.
> 
> This fixes VM faults when using VCE 2.
> 
> Cc: John Olender <[email protected]>
> Closes: https://gitlab.freedesktop.org/drm/amd/-/work_items/4802
> Fixes: e98226221467 ("drm/amdgpu: recalculate VCE firmware BO size")
> Signed-off-by: Timur Kristóf <[email protected]>
> Reviewed-by: Christian König <[email protected]>

Looks to be effective on both Kaveri and Hawaii against a wide range of
test input sizes.

Thanks,
John

> ---
>  drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c 
> b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
> index db149eda6204..3a6fc8604108 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c
> @@ -37,9 +37,14 @@
>  #include "oss/oss_2_0_d.h"
>  #include "oss/oss_2_0_sh_mask.h"
>  
> +
> +/* Use 24K to be safe. The FW supposedly only requires 23744 bytes. */
> +#define VCE_V2_0_DATA_ENTRY_SIZE (24 * 1024)
> +
>  #define VCE_V2_0_FW_SIZE     (256 * 1024)
>  #define VCE_V2_0_STACK_SIZE  (64 * 1024)
> -#define VCE_V2_0_DATA_SIZE   (23552 * AMDGPU_MAX_VCE_HANDLES)
> +#define VCE_V2_0_DATA_SIZE   (VCE_V2_0_DATA_ENTRY_SIZE * 
> (AMDGPU_MAX_VCE_HANDLES + 1))
> +
>  #define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK        0x02
>  
>  static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev);
> @@ -183,7 +188,7 @@ static void vce_v2_0_mc_resume(struct amdgpu_device *adev)
>       WREG32(mmVCE_LMI_VCPU_CACHE_40BIT_BAR, (adev->vce.gpu_addr >> 8));
>  
>       offset = AMDGPU_VCE_FIRMWARE_OFFSET;
> -     size = VCE_V2_0_FW_SIZE;
> +     size = VCE_V2_0_FW_SIZE - AMDGPU_VCE_FIRMWARE_OFFSET;
>       WREG32(mmVCE_VCPU_CACHE_OFFSET0, offset & 0x7fffffff);
>       WREG32(mmVCE_VCPU_CACHE_SIZE0, size);
>  

Reply via email to