drm/amdgpu: Fix multi-level page table bugs for large BOs v2
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix multi-level page table bugs for large BOs v2
Fix the start/end address calculation for address ranges that span multiple page directories in amdgpu_vm_alloc_levels.
Add WARN_ONs if page tables aren't found. Otherwise the page table update would just fail silently.
v2:
* Change WARN_ON to WARN_ON_ONCE
* Move masking of high address bits to caller
* Add range-check for "from" and "to"
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -5
@@ -275,13 +275,18 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,memset (parent->entries,0 ,sizeof (struct amdgpu_vm_pt )); } - from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); - to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); + from = saddr >> shift; + to = eaddr >> shift; +if (from >=amdgpu_vm_num_entries (adev, level) || + to >=amdgpu_vm_num_entries (adev, level)) +return -EINVAL ;if (to > parent->last_entry_used) parent->last_entry_used = to; ++level; + saddr = saddr & ((1 << shift) -1 ); + eaddr = eaddr & ((1 << shift) -1 );/* walk over the address space and allocate the page tables */ for (pt_idx = from; pt_idx <= to; ++pt_idx) {
@@ -312,8 +317,11 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, }if (level < adev->vm_manager.num_level) { - r =amdgpu_vm_alloc_levels (adev, vm, entry, saddr, - eaddr, level); +uint64_t sub_saddr = (pt_idx == from) ? saddr :0 ; +uint64_t sub_eaddr = (pt_idx == to) ? eaddr : + ((1 << shift) -1 ); + r =amdgpu_vm_alloc_levels (adev, vm, entry, sub_saddr, + sub_eaddr, level);if (r)return r; }
@@ -957,9 +965,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON_ONCE (level))return NULL ; +WARN_ON_ONCE (!entry->bo); +return entry->bo; }
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1490802516-19647-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Am 29.03.2017 um 17:48 schrieb Felix Kuehling:
Quoted 28 lines
Fix the start/end address calculation for address ranges that span multiple page directories in
amdgpu_vm_alloc_levels.Add
WARN_ONsif page tables aren't found. Otherwise the page table update would just fail silently.v2:
* ChangeWARN_ONtoWARN_ON_ONCE
* Move masking of high address bits to caller
* Add range-check for "from" and "to"Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -275,13 +275,18 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,memset (parent->entries,0 ,sizeof (struct amdgpu_vm_pt )); } - from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); - to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); + from = saddr >> shift; + to = eaddr >> shift;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, · line 289
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+if (from >=amdgpu_vm_num_entries (adev, level) || + to >=amdgpu_vm_num_entries (adev, level)) +return -EINVAL ;if (to > parent->last_entry_used) parent->last_entry_used = to; ++level; + saddr = saddr & ((1 << shift) -1 ); + eaddr = eaddr & ((1 << shift) -1 );
Why do you need this part? The modulo above should have handled that.
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2/* walk over the address space and allocate the page tables */ for (pt_idx = from; pt_idx <= to; ++pt_idx) {@@ -312,8 +317,11 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, }if (level < adev->vm_manager.num_level) { - r =amdgpu_vm_alloc_levels (adev, vm, entry, saddr, - eaddr, level); +uint64_t sub_saddr = (pt_idx == from) ? saddr :0 ; +uint64_t sub_eaddr = (pt_idx == to) ? eaddr : + ((1 << shift) -1 ); + r =amdgpu_vm_alloc_levels (adev, vm, entry, sub_saddr, + sub_eaddr, level);if (r)return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, · line 972
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1@@ -957,9 +965,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON_ONCE (level))return NULL ; +WARN_ON_ONCE (!entry->bo); +
Please drop those warnings. It is perfectly valid not to have the PT allocated here.
Rather add a warning to the caller if it needs the BO.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, · line 975
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0return entry->bo; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 9f232666-12b9-9439-af3c-b2ea54fb92a6-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 32 lines · Christian König
Am 29.03.2017 um 17:48 schrieb Felix Kuehling:
Quoted 31 lines
Fix the start/end address calculation for address ranges that span multiple page directories in
amdgpu_vm_alloc_levels.Add
WARN_ONsif page tables aren't found. Otherwise the page table update would just fail silently.v2:
* ChangeWARN_ONtoWARN_ON_ONCE
* Move masking of high address bits to caller
* Add range-check for "from" and "to"Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-1@@ -275,13 +275,18 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,memset (parent->entries,0 ,sizeof (struct amdgpu_vm_pt )); } - from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); - to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); + from = saddr >> shift; + to = eaddr >> shift; +if (from >=amdgpu_vm_num_entries (adev, level) || + to >=amdgpu_vm_num_entries (adev, level))
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, · line 289
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0+return -EINVAL ;if (to > parent->last_entry_used) parent->last_entry_used = to; ++level; + saddr = saddr & ((1 << shift) -1 ); + eaddr = eaddr & ((1 << shift) -1 );Why do you need this part? The modulo above should have handled that.
This adjusts the saddr and eaddr for the next recursion level. It removes the high bits that don't matter in the next level. That's what we talked about in the code review: moving the masking of high-bits to the caller.
Quoted 30 lines
Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2/* walk over the address space and allocate the page tables */ for (pt_idx = from; pt_idx <= to; ++pt_idx) {@@ -312,8 +317,11 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, }if (level < adev->vm_manager.num_level) { - r =amdgpu_vm_alloc_levels (adev, vm, entry, saddr, - eaddr, level); +uint64_t sub_saddr = (pt_idx == from) ? saddr :0 ; +uint64_t sub_eaddr = (pt_idx == to) ? eaddr : + ((1 << shift) -1 ); + r =amdgpu_vm_alloc_levels (adev, vm, entry, sub_saddr, + sub_eaddr, level);if (r)return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo *amdgpu_vm_get_pt(struct · line 972
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -957,9 +965,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(structamdgpu_pte_update_params *p, entry = &entry->entries[idx]; } - if (level) +if (WARN_ON_ONCE (level))return NULL ; +WARN_ON_ONCE (!entry->bo); +Please drop those warnings. It is perfectly valid not to have the PT allocated here.
Quoted 1 line
Rather add a warning to the caller if it needs the BO.
This function is only called from two places in amdgpu_vm_update_ptes. In both cases the PT is needed and a failure means that we're silently not updating a page table that we expected to be there. I can add an error message to the caller instead. But then it'll be in two places instead of one.
Regards,
Felix
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, · line 975
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0return entry->bo; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx