]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amdgpu: allow variable BO struct creation
authorNirmoy Das <nirmoy.das@amd.com>
Mon, 8 Mar 2021 13:00:06 +0000 (14:00 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 9 Apr 2021 20:45:12 +0000 (16:45 -0400)
Allow allocating BO structures with different structure size
than struct amdgpu_bo.

v2: Check bo_ptr_size in all amdgpu_bo_create() caller.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
drivers/gpu/drm/amd/amdgpu/amdgpu_test.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 1c6be53313a83b711481f2251954b531e682d257..c52e169ec6fc2f908843be21748edfd6dd4b10e6 100644 (file)
@@ -246,6 +246,7 @@ int amdgpu_amdkfd_alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
        bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
        bp.type = ttm_bo_type_kernel;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
        if (cp_mqd_gfx9)
                bp.flags |= AMDGPU_GEM_CREATE_CP_MQD_GFX9;
@@ -327,6 +328,7 @@ int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size,
        bp.flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
        bp.type = ttm_bo_type_device;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
        r = amdgpu_bo_create(adev, &bp, &bo);
        if (r) {
index d9b35df33806d178afbea6d44954396121bee021..313517f7cf107c9a8ad6deb7e9bfa0f672cab5ed 100644 (file)
@@ -85,6 +85,8 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
        bp.flags = 0;
        bp.type = ttm_bo_type_kernel;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
+
        n = AMDGPU_BENCHMARK_ITERATIONS;
        r = amdgpu_bo_create(adev, &bp, &sobj);
        if (r) {
index 5807cad833d370fb8838c6d07e34cf400e4ef34b..c5a9a4fb10d2bde0767b8f76d95d633e5f44709f 100644 (file)
@@ -126,6 +126,8 @@ int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
                        AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
                bp.type = ttm_bo_type_kernel;
                bp.resv = NULL;
+               bp.bo_ptr_size = sizeof(struct amdgpu_bo);
+
                r = amdgpu_bo_create(adev, &bp, &adev->gart.bo);
                if (r) {
                        return r;
index fb7171e5507cb957e794210f9caef897f65bfae0..bca260d56f76fac44511211d0650e8f86b7b5232 100644 (file)
@@ -71,6 +71,8 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
        bp.preferred_domain = initial_domain;
        bp.flags = flags;
        bp.domain = initial_domain;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
+
        r = amdgpu_bo_create(adev, &bp, &bo);
        if (r)
                return r;
index 56e83ada62de4144679ea0e251b0473073e2e358..b9d68fd2610c0ddbf6f427bd84cb1bd13fd6683c 100644 (file)
@@ -55,6 +55,8 @@ int amdgpu_gmc_pdb0_alloc(struct amdgpu_device *adev)
                AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
        bp.type = ttm_bo_type_kernel;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
+
        r = amdgpu_bo_create(adev, &bp, &adev->gmc.pdb0_bo);
        if (r)
                return r;
index b99e9d8736c210d9228baafa55becc02eacb9789..6aa3f7cfd74029cf67a86043f05e747ef7ab8a3b 100644 (file)
@@ -248,6 +248,7 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
        bp.flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
        bp.type = ttm_bo_type_kernel;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
        if (!*bo_ptr) {
                r = amdgpu_bo_create(adev, &bp, bo_ptr);
@@ -543,9 +544,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
        if (!amdgpu_bo_validate_size(adev, size, bp->domain))
                return -ENOMEM;
 
-       *bo_ptr = NULL;
+       BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo));
 
-       bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);
+       *bo_ptr = NULL;
+       bo = kzalloc(bp->bo_ptr_size, GFP_KERNEL);
        if (bo == NULL)
                return -ENOMEM;
        drm_gem_private_object_init(adev_to_drm(adev), &bo->tbo.base, size);
@@ -635,6 +637,7 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
                AMDGPU_GEM_CREATE_SHADOW;
        bp.type = ttm_bo_type_kernel;
        bp.resv = bo->tbo.base.resv;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
        r = amdgpu_bo_do_create(adev, &bp, &bo->shadow);
        if (!r) {
@@ -669,6 +672,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
        int r;
 
        bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+
        r = amdgpu_bo_do_create(adev, bp, bo_ptr);
        if (r)
                return r;
index 54ceb065e5463d72901cebb6bbc1b49785e0c9e5..8e2b556f0b7bf9c6f6176b1aa223ddda4e86b885 100644 (file)
@@ -40,6 +40,7 @@
 struct amdgpu_bo_param {
        unsigned long                   size;
        int                             byte_align;
+       u32                             bo_ptr_size;
        u32                             domain;
        u32                             preferred_domain;
        u64                             flags;
index 7b230bcbf2c6ee7e1f5f93d57f5d2a4110177d87..909d830b513e24184e4c2cc8b3b466de51692d25 100644 (file)
@@ -62,6 +62,7 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
        bp.flags = 0;
        bp.type = ttm_bo_type_kernel;
        bp.resv = NULL;
+       bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
        r = amdgpu_bo_create(adev, &bp, &vram_obj);
        if (r) {
index f314e1e269cdff8fa81b993f3a25136769813abf..abb3ab053a59bf80ddfc9ad60c862c1fb15413f9 100644 (file)
@@ -869,6 +869,7 @@ static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
        bp->domain = amdgpu_bo_get_preferred_pin_domain(adev, bp->domain);
        bp->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
                AMDGPU_GEM_CREATE_CPU_GTT_USWC;
+       bp->bo_ptr_size = sizeof(struct amdgpu_bo);
        if (vm->use_cpu_for_update)
                bp->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
        else if (!vm->root.base.bo || vm->root.base.bo->shadow)