Re: [PATCH] drm/amdgpu: fix an underflow on non-4KB-page systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 29.03.21 um 21:27 schrieb Xi Ruoyao:
Hi Christian,

I don't think there is any constraint implemented to ensure `num_entries %
AMDGPU_GPU_PAGES_IN_CPU_PAGE == 0`.  For example, in `amdgpu_vm_bo_map()`:

         /* validate the parameters */
         if (saddr & AMDGPU_GPU_PAGE_MASK || offset & AMDGPU_GPU_PAGE_MASK ||
             size == 0 || size & AMDGPU_GPU_PAGE_MASK)
                 return -EINVAL;

/* snip */

         saddr /= AMDGPU_GPU_PAGE_SIZE;
         eaddr /= AMDGPU_GPU_PAGE_SIZE;

/* snip */

         mapping->start = saddr;
         mapping->last = eaddr;


If we really want to ensure (mapping->last - mapping->start + 1) %
AMDGPU_GPU_PAGES_IN_CPU_PAGE == 0, then we should replace "AMDGPU_GPU_PAGE_MASK"
in "validate the parameters" with "PAGE_MASK".

Yeah, good point.

I tried it and it broke userspace: Xorg startup fails with EINVAL with this
change.

Well in theory it is possible that we always fill the GPUVM on a 4k basis while the native page size of the CPU is larger. Let me double check the code.

BTW: What code base are you based on? The code your post here is quite outdated.

Christian.


On 2021-03-30 02:30 +0800, Xi Ruoyao wrote:
On 2021-03-30 02:21 +0800, Xi Ruoyao wrote:
On 2021-03-29 20:10 +0200, Christian König wrote:
You need to identify the root cause of this, most likely start or last
are not a multiple of AMDGPU_GPU_PAGES_IN_CPU_PAGE.
I printk'ed the value of start & last, they are all a multiple of 4
(AMDGPU_GPU_PAGES_IN_CPU_PAGE).

However... `num_entries = last - start + 1` so it became some irrational
thing...  Either this line is wrong, or someone called
amdgpu_vm_bo_update_mapping with [start, last) instead of [start, last], which
is unexpected.
I added BUG_ON(num_entries % AMDGPU_GPU_PAGES_IN_CPU_PAGE != 0), get:

Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c90750>]
amdgpu_vm_bo_update_mapping.constprop.0+0x218/0xae8
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c922b8>]
amdgpu_vm_bo_update+0x270/0x4c0
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c823ec>]
amdgpu_gem_va_ioctl+0x40c/0x430
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c1cae4>]
drm_ioctl_kernel+0xcc/0x120
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c1cfd8>]
drm_ioctl+0x220/0x408
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff83c5ea48>]
amdgpu_drm_ioctl+0x58/0x98
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff838feac4>] sys_ioctl+0xcc/0xe8
Mar 30 02:28:27 xry111-A1901 kernel: [<ffffffff836e74f0>]
syscall_common+0x34/0x58

BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1549
Fixes: a39f2a8d7066 ("drm/amdgpu: nuke amdgpu_vm_bo_split_mapping v2")
Reported-by: Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
Reported-by: Dan Horák <dan@xxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Xi Ruoyao <xry111@xxxxxxxxxxxxxxxx>
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index ad91c0c3c423..cee0cc9c8085 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1707,7 +1707,7 @@ static int amdgpu_vm_bo_update_mapping(struct
amdgpu_device *adev,
                  }
                  start = tmp;
-       } while (unlikely(start != last + 1));
+       } while (unlikely(start < last + 1));
         r = vm->update_funcs->commit(&params, fence);
base-commit: a5e13c6df0e41702d2b2c77c8ad41677ebb065b3

_______________________________________________
amd-gfx mailing list
amd-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/amd-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux