[PATCH] drm/amdgpu: Add more checks to discovery fetch

Alex Deucher alexdeucher at gmail.com
Thu May 29 13:56:54 UTC 2025


On Thu, May 29, 2025 at 7:47 AM Lijo Lazar <lijo.lazar at amd.com> wrote:
>
> Add more checks for valid vram size and log error, if any.
>
> Signed-off-by: Lijo Lazar <lijo.lazar at amd.com>

Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> index 9e738fae2b74..a0e9bf9b2710 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
> @@ -270,9 +270,10 @@ static int amdgpu_discovery_read_binary_from_sysmem(struct amdgpu_device *adev,
>  static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
>                                                  uint8_t *binary)
>  {
> +       bool sz_valid = true;
>         uint64_t vram_size;
> -       u32 msg;
>         int i, ret = 0;
> +       u32 msg;
>
>         if (!amdgpu_sriov_vf(adev)) {
>                 /* It can take up to a second for IFWI init to complete on some dGPUs,
> @@ -291,9 +292,13 @@ static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
>                 }
>         }
>
> -       vram_size = (uint64_t)RREG32(mmRCC_CONFIG_MEMSIZE) << 20;
> +       vram_size = RREG32(mmRCC_CONFIG_MEMSIZE);
> +       if (!vram_size || vram_size == U32_MAX)
> +               sz_valid = false;
> +       else
> +               vram_size <<= 20;
>
> -       if (vram_size) {
> +       if (sz_valid) {
>                 uint64_t pos = vram_size - DISCOVERY_TMR_OFFSET;
>                 amdgpu_device_vram_access(adev, pos, (uint32_t *)binary,
>                                           adev->mman.discovery_tmr_size, false);
> @@ -301,6 +306,11 @@ static int amdgpu_discovery_read_binary_from_mem(struct amdgpu_device *adev,
>                 ret = amdgpu_discovery_read_binary_from_sysmem(adev, binary);
>         }
>
> +       if (ret)
> +               dev_err(adev->dev,
> +                       "failed to read discovery info from memory, vram size read: %llx",
> +                       vram_size);
> +
>         return ret;
>  }
>
> --
> 2.25.1
>


More information about the amd-gfx mailing list