<div dir="ltr">Ping<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 22, 2019 at 4:45 PM Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
<br>
- move all adjustments into one place<br>
- specify GDS/GWS/OA alignment in basic units of the heaps<br>
- it looks like GDS alignment was 1 instead of 4<br>
<br>
Signed-off-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    |  7 -------<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 16 ++++++++++++----<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  6 +++---<br>
 3 files changed, 15 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
index f4f00217546e..d21dd2f369da 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
@@ -47,24 +47,20 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,<br>
                             u64 flags, enum ttm_bo_type type,<br>
                             struct reservation_object *resv,<br>
                             struct drm_gem_object **obj)<br>
 {<br>
        struct amdgpu_bo *bo;<br>
        struct amdgpu_bo_param bp;<br>
        int r;<br>
<br>
        memset(&bp, 0, sizeof(bp));<br>
        *obj = NULL;<br>
-       /* At least align on page size */<br>
-       if (alignment < PAGE_SIZE) {<br>
-               alignment = PAGE_SIZE;<br>
-       }<br>
<br>
        bp.size = size;<br>
        bp.byte_align = alignment;<br>
        bp.type = type;<br>
        bp.resv = resv;<br>
        bp.preferred_domain = initial_domain;<br>
 retry:<br>
        bp.flags = flags;<br>
        bp.domain = initial_domain;<br>
        r = amdgpu_bo_create(adev, &bp, &bo);<br>
@@ -237,23 +233,20 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,<br>
        if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |<br>
            AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA)) {<br>
                if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {<br>
                        /* if gds bo is created from user space, it must be<br>
                         * passed to bo list<br>
                         */<br>
                        DRM_ERROR("GDS bo cannot be per-vm-bo\n");<br>
                        return -EINVAL;<br>
                }<br>
                flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;<br>
-               /* GDS allocations must be DW aligned */<br>
-               if (args->in.domains & AMDGPU_GEM_DOMAIN_GDS)<br>
-                       size = ALIGN(size, 4);<br>
        }<br>
<br>
        if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {<br>
                r = amdgpu_bo_reserve(vm-><a href="http://root.base.bo" rel="noreferrer" target="_blank">root.base.bo</a>, false);<br>
                if (r)<br>
                        return r;<br>
<br>
                resv = vm->root.base.bo->tbo.resv;<br>
        }<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
index 728e15e5d68a..fd9c4beeaaa4 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
@@ -419,26 +419,34 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,<br>
                .interruptible = (bp->type != ttm_bo_type_kernel),<br>
                .no_wait_gpu = false,<br>
                .resv = bp->resv,<br>
                .flags = TTM_OPT_FLAG_ALLOW_RES_EVICT<br>
        };<br>
        struct amdgpu_bo *bo;<br>
        unsigned long page_align, size = bp->size;<br>
        size_t acc_size;<br>
        int r;<br>
<br>
-       page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;<br>
-       if (bp->domain & (AMDGPU_GEM_DOMAIN_GDS | AMDGPU_GEM_DOMAIN_GWS |<br>
-                         AMDGPU_GEM_DOMAIN_OA))<br>
+       /* Note that GDS/GWS/OA allocates 1 page per byte/resource. */<br>
+       if (bp->domain & (AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA)) {<br>
+               /* GWS and OA don't need any alignment. */<br>
+               page_align = bp->byte_align;<br>
                size <<= PAGE_SHIFT;<br>
-       else<br>
+       } else if (bp->domain & AMDGPU_GEM_DOMAIN_GDS) {<br>
+               /* Both size and alignment must be a multiple of 4. */<br>
+               page_align = ALIGN(bp->byte_align, 4);<br>
+               size = ALIGN(size, 4) << PAGE_SHIFT;<br>
+       } else {<br>
+               /* Memory should be aligned at least to a page size. */<br>
+               page_align = ALIGN(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;<br>
                size = ALIGN(size, PAGE_SIZE);<br>
+       }<br>
<br>
        if (!amdgpu_bo_validate_size(adev, size, bp->domain))<br>
                return -ENOMEM;<br>
<br>
        *bo_ptr = NULL;<br>
<br>
        acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,<br>
                                       sizeof(struct amdgpu_bo));<br>
<br>
        bo = kzalloc(sizeof(struct amdgpu_bo), GFP_KERNEL);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index b852abb9db0f..73e71e61dc99 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -1749,47 +1749,47 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)<br>
<br>
        /* Initialize various on-chip memory pools */<br>
        r = ttm_bo_init_mm(&adev->mman.bdev, AMDGPU_PL_GDS,<br>
                           adev->gds.mem.total_size);<br>
        if (r) {<br>
                DRM_ERROR("Failed initializing GDS heap.\n");<br>
                return r;<br>
        }<br>
<br>
        r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,<br>
-                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,<br>
+                                   4, AMDGPU_GEM_DOMAIN_GDS,<br>
                                    &adev->gds.gds_gfx_bo, NULL, NULL);<br>
        if (r)<br>
                return r;<br>
<br>
        r = ttm_bo_init_mm(&adev->mman.bdev, AMDGPU_PL_GWS,<br>
                           adev->gds.gws.total_size);<br>
        if (r) {<br>
                DRM_ERROR("Failed initializing gws heap.\n");<br>
                return r;<br>
        }<br>
<br>
        r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,<br>
-                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,<br>
+                                   1, AMDGPU_GEM_DOMAIN_GWS,<br>
                                    &adev->gds.gws_gfx_bo, NULL, NULL);<br>
        if (r)<br>
                return r;<br>
<br>
        r = ttm_bo_init_mm(&adev->mman.bdev, AMDGPU_PL_OA,<br>
                           adev->gds.oa.total_size);<br>
        if (r) {<br>
                DRM_ERROR("Failed initializing oa heap.\n");<br>
                return r;<br>
        }<br>
<br>
        r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,<br>
-                                   PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,<br>
+                                   1, AMDGPU_GEM_DOMAIN_OA,<br>
                                    &adev->gds.oa_gfx_bo, NULL, NULL);<br>
        if (r)<br>
                return r;<br>
<br>
        /* Register debugfs entries for amdgpu_ttm */<br>
        r = amdgpu_ttm_debugfs_init(adev);<br>
        if (r) {<br>
                DRM_ERROR("Failed to init debugfs\n");<br>
                return r;<br>
        }<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div>