[PATCH] drm/amd/amdgpu: cast mem->num_pages to 64-bits when shifting

Christian König ckoenig.leichtzumerken at gmail.com
Mon Jun 17 19:25:43 UTC 2019


Reviewed-by: Christian König <christian.koenig at amd.com>

Am 17.06.19 um 20:21 schrieb Tom St Denis:
> ping?
>
> On Fri, Jun 14, 2019 at 12:51 PM StDenis, Tom <Tom.StDenis at amd.com 
> <mailto:Tom.StDenis at amd.com>> wrote:
>
>     On 32-bit hosts mem->num_pages is 32-bits and can overflow
>     when shifted.  Add a cast to avoid this.
>
>     Signed-off-by: Tom St Denis <tom.stdenis at amd.com
>     <mailto:tom.stdenis at amd.com>>
>     ---
>      drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 8 +++++---
>      1 file changed, 5 insertions(+), 3 deletions(-)
>
>     diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>     b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>     index c963ad86072e..31895d3c33de 100644
>     --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>     +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>     @@ -279,14 +279,16 @@ static int amdgpu_vram_mgr_new(struct
>     ttm_mem_type_manager *man,
>             uint64_t vis_usage = 0;
>             unsigned i;
>             int r;
>     +       uint64_t mem_bytes;
>
>             lpfn = place->lpfn;
>             if (!lpfn)
>                     lpfn = man->size;
>
>             /* bail out quickly if there's likely not enough VRAM for
>     this BO */
>     -       if (atomic64_add_return(mem->num_pages << PAGE_SHIFT,
>     &mgr->usage) > adev->gmc.mc_vram_size) {
>     -               atomic64_sub(mem->num_pages << PAGE_SHIFT,
>     &mgr->usage);
>     +       mem_bytes = (u64)mem->num_pages << PAGE_SHIFT;
>     +       if (atomic64_add_return(mem_bytes, &mgr->usage) >
>     adev->gmc.mc_vram_size) {
>     +               atomic64_sub(mem_bytes, &mgr->usage);
>                     mem->mm_node = NULL;
>                     return 0;
>             }
>     @@ -308,7 +310,7 @@ static int amdgpu_vram_mgr_new(struct
>     ttm_mem_type_manager *man,
>             nodes = kvmalloc_array((uint32_t)num_nodes, sizeof(*nodes),
>                                    GFP_KERNEL | __GFP_ZERO);
>             if (!nodes) {
>     -               atomic64_sub(mem->num_pages << PAGE_SHIFT,
>     &mgr->usage);
>     +               atomic64_sub(mem_bytes, &mgr->usage);
>                     return -ENOMEM;
>             }
>
>     -- 
>     2.21.0
>
>     _______________________________________________
>     amd-gfx mailing list
>     amd-gfx at lists.freedesktop.org <mailto:amd-gfx at lists.freedesktop.org>
>     https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/amd-gfx/attachments/20190617/542f23da/attachment.html>


More information about the amd-gfx mailing list