[Mesa-dev] [PATCH] winsys/radeon: cleanup virtual memory nonsense

Christian König deathsimple at vodafone.de
Tue Nov 19 07:44:24 PST 2013


Am 19.11.2013 16:19, schrieb Alex Deucher:
> On Tue, Nov 19, 2013 at 5:05 AM, Christian König
> <deathsimple at vodafone.de> wrote:
>> From: Christian König <christian.koenig at amd.com>
>>
>> The alignment of a virtual memory area must always be at least 4096 bytes.
>>
>> It only worked because size was aligned to 4096 outside of the function.
>>
>> Signed-off-by: Christian König <christian.koenig at amd.com>
> CC the 9.2 and 10.0 branches?  Does this fix the problems you were
> looking at last week?

Unfortunately not. I just stumbled over it while working on a patch that 
artificially unaligned all buffers. E.g. when the driver says align the 
buffer to 4k then make sure that it's aligned to 4k but not to 8k. Tried 
to force the lockup with it, but that doesn't work either.

Christian.

> Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
>
>> ---
>>   src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 37 +++++++++++++--------------
>>   src/gallium/winsys/radeon/drm/radeon_drm_bo.h |  1 -
>>   2 files changed, 18 insertions(+), 20 deletions(-)
>>
>> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
>> index 19e2715..3019a52 100644
>> --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
>> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
>> @@ -202,15 +202,15 @@ static uint64_t radeon_bomgr_find_va(struct radeon_bomgr *mgr, uint64_t size, ui
>>       struct radeon_bo_va_hole *hole, *n;
>>       uint64_t offset = 0, waste = 0;
>>
>> +    alignment = MAX2(alignment, 4096);
>> +    size = align(size, 4096);
>> +
>>       pipe_mutex_lock(mgr->bo_va_mutex);
>>       /* first look for a hole */
>>       LIST_FOR_EACH_ENTRY_SAFE(hole, n, &mgr->va_holes, list) {
>>           offset = hole->offset;
>> -        waste = 0;
>> -        if (alignment) {
>> -            waste = offset % alignment;
>> -            waste = waste ? alignment - waste : 0;
>> -        }
>> +        waste = offset % alignment;
>> +        waste = waste ? alignment - waste : 0;
>>           offset += waste;
>>           if (offset >= (hole->offset + hole->size)) {
>>               continue;
>> @@ -242,11 +242,8 @@ static uint64_t radeon_bomgr_find_va(struct radeon_bomgr *mgr, uint64_t size, ui
>>       }
>>
>>       offset = mgr->va_offset;
>> -    waste = 0;
>> -    if (alignment) {
>> -        waste = offset % alignment;
>> -        waste = waste ? alignment - waste : 0;
>> -    }
>> +    waste = offset % alignment;
>> +    waste = waste ? alignment - waste : 0;
>>       if (waste) {
>>           n = CALLOC_STRUCT(radeon_bo_va_hole);
>>           n->size = waste;
>> @@ -261,6 +258,8 @@ static uint64_t radeon_bomgr_find_va(struct radeon_bomgr *mgr, uint64_t size, ui
>>
>>   static void radeon_bomgr_force_va(struct radeon_bomgr *mgr, uint64_t va, uint64_t size)
>>   {
>> +    size = align(size, 4096);
>> +
>>       pipe_mutex_lock(mgr->bo_va_mutex);
>>       if (va >= mgr->va_offset) {
>>           if (va > mgr->va_offset) {
>> @@ -303,6 +302,8 @@ static void radeon_bomgr_free_va(struct radeon_bomgr *mgr, uint64_t va, uint64_t
>>   {
>>       struct radeon_bo_va_hole *hole;
>>
>> +    size = align(size, 4096);
>> +
>>       pipe_mutex_lock(mgr->bo_va_mutex);
>>       if ((va + size) == mgr->va_offset) {
>>           mgr->va_offset = va;
>> @@ -385,7 +386,7 @@ static void radeon_bo_destroy(struct pb_buffer *_buf)
>>       drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args);
>>
>>       if (mgr->va) {
>> -        radeon_bomgr_free_va(mgr, bo->va, bo->va_size);
>> +        radeon_bomgr_free_va(mgr, bo->va, bo->base.size);
>>       }
>>
>>       pipe_mutex_destroy(bo->map_mutex);
>> @@ -600,8 +601,7 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
>>       if (mgr->va) {
>>           struct drm_radeon_gem_va va;
>>
>> -        bo->va_size = align(size,  4096);
>> -        bo->va = radeon_bomgr_find_va(mgr, bo->va_size, desc->alignment);
>> +        bo->va = radeon_bomgr_find_va(mgr, size, desc->alignment);
>>
>>           va.handle = bo->handle;
>>           va.vm_id = 0;
>> @@ -621,9 +621,9 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr,
>>               return NULL;
>>           }
>>           if (va.operation == RADEON_VA_RESULT_VA_EXIST) {
>> -            radeon_bomgr_free_va(mgr, bo->va, bo->va_size);
>> +            radeon_bomgr_free_va(mgr, bo->va, size);
>>               bo->va = va.offset;
>> -            radeon_bomgr_force_va(mgr, bo->va, bo->va_size);
>> +            radeon_bomgr_force_va(mgr, bo->va, size);
>>           }
>>       }
>>
>> @@ -931,8 +931,7 @@ done:
>>       if (mgr->va && !bo->va) {
>>           struct drm_radeon_gem_va va;
>>
>> -        bo->va_size = ((bo->base.size + 4095) & ~4095);
>> -        bo->va = radeon_bomgr_find_va(mgr, bo->va_size, 1 << 20);
>> +        bo->va = radeon_bomgr_find_va(mgr, bo->base.size, 1 << 20);
>>
>>           va.handle = bo->handle;
>>           va.operation = RADEON_VA_MAP;
>> @@ -949,9 +948,9 @@ done:
>>               return NULL;
>>           }
>>           if (va.operation == RADEON_VA_RESULT_VA_EXIST) {
>> -            radeon_bomgr_free_va(mgr, bo->va, bo->va_size);
>> +            radeon_bomgr_free_va(mgr, bo->va, bo->base.size);
>>               bo->va = va.offset;
>> -            radeon_bomgr_force_va(mgr, bo->va, bo->va_size);
>> +            radeon_bomgr_force_va(mgr, bo->va, bo->base.size);
>>           }
>>       }
>>
>> diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h
>> index ee8919b..5536bc1 100644
>> --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h
>> +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h
>> @@ -56,7 +56,6 @@ struct radeon_bo {
>>       uint32_t handle;
>>       uint32_t name;
>>       uint64_t va;
>> -    uint64_t va_size;
>>       enum radeon_bo_domain initial_domain;
>>
>>       /* how many command streams is this bo referenced in? */
>> --
>> 1.8.1.2
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev



More information about the mesa-dev mailing list