Fixes for multi-level page tables
Subsystems (2)
cover Fixes for multi-level page tables
I worked on these fixes on amd-kfd-staging with a merge of the recent multi- level page table changes. With these changes KFDTest passes on Vega10, including some tests that tend to stress VM memory management.
They applied cleanly to current amd-staging-4.9 but are only compile-tested on that branch.
Felix Kuehling (3):
drm/amdgpu: Make max_pfn 64-bit
drm/amdgpu: Fix Vega10 VM initialization drm/amdgpu: Fix multi-level page table bugs for large BOs
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 6 files changed, 29 insertions(+), 23 deletions(-)
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): 1490749231-16157-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
PATCH 1/3 drm/amdgpu: Make max_pfn 64-bit
With 4-level page tables the maximum VM size is 256TB. That's 64G pages, which can't be represented in 32-bit.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
@@ -336,7 +336,7 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,struct amdgpu_vm *vm, uint64_t saddr, uint64_t size) { - unsigned last_pfn; + uint64_t last_pfn;uint64_t eaddr;/* validate the parameters */
@@ -346,7 +346,7 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, eaddr = saddr + size -1 ; last_pfn = eaddr /AMDGPU_GPU_PAGE_SIZE ;if (last_pfn >= adev->vm_manager.max_pfn) { -dev_err (adev->dev,"va above limit (0x%08X >= 0x%08X)\n" , +dev_err (adev->dev,"va above limit (0x%08llX >= 0x%08llX)\n" , last_pfn, adev->vm_manager.max_pfn);return -EINVAL ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -153,7 +153,7 @@ struct amdgpu_vm_manager {u64 fence_context;unsigned seqno[AMDGPU_MAX_RINGS ]; -uint32_t max_pfn; +uint64_t max_pfn;uint32_t num_level;/* vram base address for page table entry */ u64 vram_base_offset;
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +3 -2
@@ -227,8 +227,9 @@ int gfxhub_v1_0_gart_enable(struct amdgpu_device *adev)WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32) + i*2 , - adev->vm_manager.max_pfn -1 ); -WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 ,0 ); +lower_32_bits (adev->vm_manager.max_pfn -1 )); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 , +upper_32_bits (adev->vm_manager.max_pfn -1 )); }
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3 -2
@@ -247,8 +247,9 @@ int mmhub_v1_0_gart_enable(struct amdgpu_device *adev)WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32) + i*2 , - adev->vm_manager.max_pfn -1 ); -WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 ,0 ); +lower_32_bits (adev->vm_manager.max_pfn -1 )); +WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 , +upper_32_bits (adev->vm_manager.max_pfn -1 )); }return 0 ;
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): 1490749231-16157-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Christian König
Reviewed-byRe: [PATCH 1/3] drm/amdgpu: Make max_pfn 64-bit
Am 29.03.2017 um 03:00 schrieb Felix Kuehling:
Quoted 4 lines
With 4-level page tables the maximum VM size is 256TB. That's 64G pages, which can't be represented in 32-bit.
Signed-off-by Felix Kuehling <[email protected]>
Quoted 64 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -336,7 +336,7 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,struct amdgpu_vm *vm, uint64_t saddr, uint64_t size) { - unsigned last_pfn; + uint64_t last_pfn;uint64_t eaddr;/* validate the parameters */ @@ -346,7 +346,7 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, eaddr = saddr + size -1 ; last_pfn = eaddr /AMDGPU_GPU_PAGE_SIZE ;if (last_pfn >= adev->vm_manager.max_pfn) { -dev_err (adev->dev,"va above limit (0x%08X >= 0x%08X)\n" , +dev_err (adev->dev,"va above limit (0x%08llX >= 0x%08llX)\n" , last_pfn, adev->vm_manager.max_pfn);return -EINVAL ; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-1@@ -153,7 +153,7 @@ struct amdgpu_vm_manager {u64 fence_context;unsigned seqno[AMDGPU_MAX_RINGS ]; -uint32_t max_pfn; +uint64_t max_pfn;uint32_t num_level;/* vram base address for page table entry */ u64 vram_base_offset;drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c +3
-2@@ -227,8 +227,9 @@ int gfxhub_v1_0_gart_enable(struct amdgpu_device *adev)WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32) + i*2 , - adev->vm_manager.max_pfn -1 ); -WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 ,0 ); +lower_32_bits (adev->vm_manager.max_pfn -1 )); +WREG32 (SOC15_REG_OFFSET (GC ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 , +upper_32_bits (adev->vm_manager.max_pfn -1 )); }drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +0
-0@@ -247,8 +247,9 @@ int mmhub_v1_0_gart_enable(struct amdgpu_device *adev)WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_LO32) + i*2 ,0 );
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c int mmhub_v1_0_gart_enable(struct amdgpu_device *adev) · line 255
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +3
-2WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_START_ADDR_HI32) + i*2 ,0 );WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_LO32) + i*2 , - adev->vm_manager.max_pfn -1 ); -WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 ,0 ); +lower_32_bits (adev->vm_manager.max_pfn -1 )); +WREG32 (SOC15_REG_OFFSET (MMHUB ,0 , mmVM_CONTEXT1_PAGE_TABLE_END_ADDR_HI32) + i*2 , +upper_32_bits (adev->vm_manager.max_pfn -1 )); }return 0 ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/3 drm/amdgpu: Fix Vega10 VM initialization
In reply to a message not in the archiveadev->family is not initialized yet when amdgpu_get_block_size is called. Use adev->asic_type instead.
Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_init is called after adev->vm_manager.max_pfn is initialized. Move the minimum VM-size enforcement ahead of max_pfn initializtion. Cast to 64-bit before the left-shift.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -3
@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */ -if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -10
@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device *adev)* amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - } adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);
@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit). */ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;/* Set the internal MC address mask * This is the max address of the GPU's
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): 1490749231-16157-3-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangRe: [PATCH 2/3] drm/amdgpu: Fix Vega10 VM initialization
Quoted 11 lines · Felix Kuehling
adev->familyis not initialized yet whenamdgpu_get_block_sizeis called. Useadev->asic_typeinstead.Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_initis called afteradev->vm_manager.max_pfnis initialized. Move the minimum VM-size enforcement ahead ofmax_pfninitializtion. Cast to 64-bit before the left-shift.Signed-off-by Felix Kuehling <[email protected]>
Just note:
For now, it's OK to set the minimum vm size 256G,
In this case, there is no PD bit anyway.
Christian also mentioned that PD should be 4k size, then 256T was required. When reach an agreement, we may update them all.
Quoted 13 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static bool amdgpu_check_pot_argument(int arg) · line 1051
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-3-if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }
Nice catch.
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_vm_init(struct amdgpu_device *adev) · line 519
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-6@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device *adev)* amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - }
David had a patch to fix it yesterday.
But your patch involves by vm size checking. :)
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2
-3adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit).
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 570
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +5
-1*/ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;/* Set the internal MC address mask * This is the max address of the GPU's
_______________________________________________
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): [email protected]
Re: [PATCH 2/3] drm/amdgpu: Fix Vega10 VM initialization
Quoted 11 lines · Jerry (Junwei)
Quoted 10 lines · Felix Kuehling
adev->familyis not initialized yet whenamdgpu_get_block_sizeis called. Useadev->asic_typeinstead.Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_initis called afteradev->vm_manager.max_pfnis initialized. Move the minimum VM-size enforcement ahead ofmax_pfninitializtion. Cast to 64-bit before the left-shift.
Quoted 6 lines
Quoted 1 line
Signed-off-by Felix Kuehling <[email protected]>Reviewed-by Junwei Zhang <[email protected]>Just note:
For now, it's OK to set the minimum vm size 256G,
In this case, there is no PD bit anyway.
With VM size of 256GB, the amdgpu_vm_bo_size(adev, 0) calculates 0, and the page directory allocation with amdgpu_bo_create fails in amdgpu_vm_init.
In other words, amdgpu_vm_num_entries(adev, 0) needs to return at least
1. That means vm_size needs to be at least 512GB.
Regards,
Felix
Quoted 72 lines
Christian also mentioned that PD should be 4k size, then 256T was required.
When reach an agreement, we may update them all.Quoted 14 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static bool amdgpu_check_pot_argument(int arg) · line 1051
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-3-if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }Nice catch.
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_vm_init(struct amdgpu_device · line 520
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-6@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device*adev) * amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - }David had a patch to fix it yesterday.
But your patch involves by vm size checking. :)Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-4adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit). */ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 570
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0/* Set the internal MC address mask * This is the max address of the GPU's
_______________________________________________
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): 0091f779-a045-7009-3746-6957ccacd62f-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/3] drm/amdgpu: Fix Vega10 VM initialization
Quoted 19 lines · Felix Kuehling
Quoted 11 lines · Jerry (Junwei)
Quoted 10 lines · Felix Kuehling
adev->familyis not initialized yet whenamdgpu_get_block_sizeis called. Useadev->asic_typeinstead.Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_initis called afteradev->vm_manager.max_pfnis initialized. Move the minimum VM-size enforcement ahead ofmax_pfninitializtion. Cast to 64-bit before the left-shift.Quoted 6 lines
Quoted 1 line
Signed-off-by Felix Kuehling <[email protected]>Reviewed-by Junwei Zhang <[email protected]>Just note:
For now, it's OK to set the minimum vm size 256G,
In this case, there is no PD bit anyway.
Quoted 5 lines
With VM size of 256GB, the
amdgpu_vm_bo_size(adev, 0)calculates 0, and the page directory allocation withamdgpu_bo_createfails inamdgpu_vm_init.In other words,
amdgpu_vm_num_entries(adev, 0)needs to return at least
1. That meansvm_sizeneeds to be at least 512GB.
Sorry for the typo, I'd like to say 512GB.
Maybe it will become 256TB, depending on the discussion in the future.
Jerry
Quoted 76 lines
Regards,
FelixQuoted 72 lines
Christian also mentioned that PD should be 4k size, then 256T was required.
When reach an agreement, we may update them all.Quoted 14 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static bool amdgpu_check_pot_argument(int arg) · line 1051
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-3-if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }Nice catch.
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_vm_init(struct amdgpu_device · line 520
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-6@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device*adev) * amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - }David had a patch to fix it yesterday.
But your patch involves by vm size checking. :)Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-4adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit). */ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 570
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0/* Set the internal MC address mask * This is the max address of the GPU's
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/3] drm/amdgpu: Fix Vega10 VM initialization
In reply to a message not in the archiveAm 29.03.2017 um 03:48 schrieb Felix Kuehling:
Quoted 15 lines · Jerry (Junwei)
Quoted 14 lines · Felix Kuehling
Quoted 11 lines
adev->familyis not initialized yet whenamdgpu_get_block_sizeis called. Useadev->asic_typeinstead.Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_initis called afteradev->vm_manager.max_pfnis initialized. Move the minimum VM-size enforcement ahead ofmax_pfninitializtion. Cast to 64-bit before the left-shift.Signed-off-by Felix Kuehling <[email protected]>Reviewed-by Junwei Zhang <[email protected]>
Quoted 8 lines
Quoted 3 lines
Just note:
For now, it's OK to set the minimum vm size 256G,
In this case, there is no PD bit anyway.With VM size of 256GB, the
amdgpu_vm_bo_size(adev, 0)calculates 0, and the page directory allocation withamdgpu_bo_createfails inamdgpu_vm_init.In other words,
amdgpu_vm_num_entries(adev, 0)needs to return at least
1. That meansvm_sizeneeds to be at least 512GB.
Those fixes are correct, but doesn't address the real problem.
The intention of amdgpu_vm_size and amgpu_vm_block_size is to save memory by reducing the size of the PD/PTs.
Since we now use 4 level PDs/PTs the size of each is 4KB, which is usually the smallest allocation size anyway.
So I suggest to just drop support for amdgpu_vm_size for Vega10 and always use 256TB instead.
Jerry do you want to take care of this or should I look into it? Should be trivial to do.
Regards,
Christian.
Quoted 73 lines
Regards,
FelixQuoted 69 lines
Christian also mentioned that PD should be 4k size, then 256T was required.
When reach an agreement, we may update them all.Quoted 14 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static bool amdgpu_check_pot_argument(int arg) · line 1051
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-3-if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }Nice catch.
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_vm_init(struct amdgpu_device · line 520
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-6@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device*adev) * amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - }David had a patch to fix it yesterday.
But your patch involves by vm size checking. :)Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-4adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit). */ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 570
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0/* Set the internal MC address mask * This is the max address of the GPU's
_______________________________________________
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): b0d2a78d-ab7d-f5b7-a35e-a9d6c80771a7-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 2/3] drm/amdgpu: Fix Vega10 VM initialization
Quoted 25 lines · Christian König
Am 29.03.2017 um 03:48 schrieb Felix Kuehling:
Quoted 15 lines · Jerry (Junwei)
Quoted 14 lines · Felix Kuehling
Quoted 11 lines
adev->familyis not initialized yet whenamdgpu_get_block_sizeis called. Useadev->asic_typeinstead.Minimum VM size is 512GB, not 256GB, for a single page table entry in the root page table.
gmc_v9_0_vm_initis called afteradev->vm_manager.max_pfnis initialized. Move the minimum VM-size enforcement ahead ofmax_pfninitializtion. Cast to 64-bit before the left-shift.Signed-off-by Felix Kuehling <[email protected]>Reviewed-by Junwei Zhang <[email protected]>Quoted 8 lines
Quoted 3 lines
Just note:
For now, it's OK to set the minimum vm size 256G,
In this case, there is no PD bit anyway.With VM size of 256GB, the
amdgpu_vm_bo_size(adev, 0)calculates 0, and the page directory allocation withamdgpu_bo_createfails inamdgpu_vm_init.In other words,
amdgpu_vm_num_entries(adev, 0)needs to return at least
1. That meansvm_sizeneeds to be at least 512GB.
Quoted 7 lines
Those fixes are correct, but doesn't address the real problem.
The intention of
amdgpu_vm_sizeandamgpu_vm_block_sizeis to save memory by reducing the size of the PD/PTs.Since we now use 4 level PDs/PTs the size of each is 4KB, which is usually the smallest allocation size anyway.
I remember we use 512B (9-bit) for each PD/PT for Vega10.
Quoted 6 lines
So I suggest to just drop support for
amdgpu_vm_sizefor Vega10 and always use 256TB instead.Jerry do you want to take care of this or should I look into it? Should be trivial to do.
Do you mean to fix the vm_size for Vega10?
Yes, I will take over it.
Jerry
Quoted 77 lines
Regards,
Christian.Quoted 73 lines
Regards,
FelixQuoted 69 lines
Christian also mentioned that PD should be 4k size, then 256T was required.
When reach an agreement, we may update them all.Quoted 14 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -1042,10 +1042,10 @@ static bool amdgpu_check_pot_argument(int arg)static void amdgpu_get_block_size (struct amdgpu_device *adev) {/* from AI, asic starts to support multiple level VMPT */ drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static bool amdgpu_check_pot_argument(int arg) · line 1051
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-3-if (adev->family >=AMDGPU_FAMILY_AI ) { +if (adev->asic_type >=CHIP_VEGA10 ) {if (amdgpu_vm_block_size !=9 ) -dev_warn (adev->dev,"Multi-VMPT limits block size to" -"one page!\n" ); +dev_warn (adev->dev, +"Multi-VMPT limits block size to one page!\n" ); amdgpu_vm_block_size =9 ;return ; }Nice catch.
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_vm_init(struct amdgpu_device · line 520
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-6@@ -511,12 +511,6 @@ static int gmc_v9_0_vm_init(struct amdgpu_device*adev) * amdkfd will use VMIDs 8-15 */ adev->vm_manager.num_ids =AMDGPU_NUM_OF_VMIDS ; -/* Because of four level VMPTs, vm size at least is 256GB. -256TB is OK as well */ -if (amdgpu_vm_size <256 ) { -DRM_WARN ("vm size at least is 256GB!\n" ); - amdgpu_vm_size =256 ; - }David had a patch to fix it yesterday.
But your patch involves by vm size checking. :)Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-4adev->vm_manager.num_level =3 ;amdgpu_vm_manager_init (adev);@@ -563,11 +557,14 @@ static int gmc_v9_0_sw_init(void *handle)if (r)return r; -/* Adjust VM size here. -* Currently default to 64GB ((16 << 20) 4k pages). -* Max GPUVM size is 48 bits. +/* Because of four level VMPTs, vm size is at least 512GB. +* The maximum size is 256TB (48bit). */ - adev->vm_manager.max_pfn = amdgpu_vm_size <<18 ; +if (amdgpu_vm_size <512 ) { +DRM_WARN ("VM size is at least 512GB!\n" ); + amdgpu_vm_size =512 ; + } + adev->vm_manager.max_pfn = (uint64_t )amdgpu_vm_size <<18 ;
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 570
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0/* Set the internal MC address mask * This is the max address of the GPU's
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: Fix multi-level page table bugs for large BOs
In reply to a message not in the archiveFix 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -3
@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;
@@ -312,8 +314,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 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON (level))return NULL ; +WARN_ON (!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): 1490749231-16157-4-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 25 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, · line 321
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2@@ -312,8 +314,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);
Do you mean to create a full sub-pt if pt_idx != from and != to? I didn't catch it up clear.
In my perspective, we may need to clear the saddr and eaddr upper level bit before going on to allocate the next level PT. Otherwise, the number of next PT entry will be incorrect, more than num_entries as the upper level PT number calculated in.
e.g.
there is a address contains
PD + PT1 + PT2 + PT3
for the first round, we could get correct "from" and "to" address with right "shift"(3 blocks), then walk over the address space in PD range.
Then for the 2nd round, we cannot get the expected "from" and "to" address with "shift"(2 blocks), as it walks over the address space in PD + PT1 range. While we'd like it's in range PT1 indeed.
The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (r)return r; }@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; }
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 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1-if (level) +if (WARN_ON (level))return NULL ; +WARN_ON (!entry->bo); +return 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): [email protected]
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Hi Jerry,
Let me clarify my understanding of the problem and the intention of the fix.
Address range per page: 4KB
Address range per PT (level 3): 2MB
Address range per PD (level 2): 1GB
Address range per PD (level 1): 512GB
Address range per PD (level 0): 256TB
Imagine for example a mapping that spans multiple level 2 page directories. Say from 0.5GB to 2.5GB.
At level 0:
from = 0
to = 0
At level 1:
from = 0
to = 2
So for level 2 amdgpu_vm_alloc_levels gets called 3 times (pt_idx = [0..2]). Without my change, it gets called with the same saddr and eaddr 3 times. So it calculates the same "from" and "to" each time:
from = 256 % 512 = 256
to = 767 % 512 = 255
Obviously that doesn't work. What we really want is this (from..to in level 2 when called for pt_idx values from level 1):
For pt_idx=0 we want to fill the second half of the level 2 page directory with page tables:
from = 256
to = 511
For pt_idx=1 we need to fill the entire level 2 page directories with page tables:
from = 0
to = 511
For pt_idx=2 we want to fill the first half of the level 2 page directory with page tables:
from = 0
to = 255
This creates a contiguous range of page tables across the three level 2 page directories that are spanned by the allocation. My change achieves that.
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
Regards,
Felix
--
F e l i x K u e h l i n g
SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada
(O) +1(289)695-1597
_ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| |
/_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com
________________________________
From: Zhang, Jerry
Sent: Tuesday, March 28, 2017 10:54:03 PM
To: Kuehling, Felix; [email protected]; Koenig, Christian; Zhou, David(ChunMing)
Cc: Deucher, Alexander; Russell, Kent
Subject: Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 25 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, · line 321
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2@@ -312,8 +314,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);
Do you mean to create a full sub-pt if pt_idx != from and != to? I didn't catch it up clear.
In my perspective, we may need to clear the saddr and eaddr upper level bit before going on to allocate the next level PT.
Otherwise, the number of next PT entry will be incorrect, more than num_entries as the upper level PT number calculated in.
e.g.
there is a address contains
PD + PT1 + PT2 + PT3
for the first round, we could get correct "from" and "to" address with right "shift"(3 blocks), then walk over the address space in PD range.
Then for the 2nd round, we cannot get the expected "from" and "to" address with "shift"(2 blocks), as it walks over the address space in PD + PT1 range. While we'd like it's in range PT1 indeed.
The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (r)return r; }@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; }
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 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1-if (level) +if (WARN_ON (level))return NULL ; +WARN_ON (!entry->bo); +return 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): DM5PR1201MB0235AB2363725D0D8320265292350-grEf7a3NxMBd8L2jMOIKKmrFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/[email protected]
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangRe: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Hi Felix,
Thanks for your illustration with patience.
I got your meaning then, and thanks to fix that.
Quoted 4 lines
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
It may be more clear if modulo-division called before the caller. Anyway,
Quoted 146 lines · Felix
Hi Jerry,
Let me clarify my understanding of the problem and the intention of the fix.
Address range per page: 4KB
Address range per PT (level 3): 2MB
Address range per PD (level 2): 1GB
Address range per PD (level 1): 512GB
Address range per PD (level 0): 256TBImagine for example a mapping that spans multiple level 2 page directories. Say from 0.5GB to 2.5GB.
At level 0:
from = 0
to = 0At level 1:
from = 0
to = 2So for level 2
amdgpu_vm_alloc_levelsgets called 3 times (pt_idx= [0..2]). Without my change, it gets called with the same saddr and eaddr 3 times. So it calculates the same "from" and "to" each time:
from = 256 % 512 = 256
to = 767 % 512 = 255Obviously that doesn't work. What we really want is this (from..to in level 2 when called for
pt_idxvalues from level 1):For pt_idx=0 we want to fill the second half of the level 2 page directory with page tables:
from = 256
to = 511For pt_idx=1 we need to fill the entire level 2 page directories with page tables:
from = 0
to = 511For pt_idx=2 we want to fill the first half of the level 2 page directory with page tables:
from = 0
to = 255This creates a contiguous range of page tables across the three level 2 page directories that are spanned by the allocation. My change achieves that.
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
Regards,
Felix--
F e l i x K u e h l i n g
SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada
(O) +1(289)695-1597_ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| |/_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com
-------------------------------------------------------------------------------
*From:* Zhang, Jerry
*Sent:* Tuesday, March 28, 2017 10:54:03 PM
*To:* Kuehling, Felix; [email protected]; Koenig, Christian; Zhou, David(ChunMing)
*Cc:* Deucher, Alexander; Russell, Kent
*Subject:* Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOsQuoted 25 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, · line 321
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2@@ -312,8 +314,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);Do you mean to create a full sub-pt if
pt_idx!= from and != to? I didn't catch it up clear.In my perspective, we may need to clear the saddr and eaddr upper level bit before going on to allocate the next level PT.
Otherwise, the number of next PT entry will be incorrect, more thannum_entriesas the upper level PT number calculated in.e.g.
there is a address contains
PD + PT1 + PT2 + PT3for the first round, we could get correct "from" and "to" address with right "shift"(3 blocks), then walk over the address space in PD range.
Then for the 2nd round, we cannot get the expected "from" and "to" address with "shift"(2 blocks), as it walks over the address space in PD + PT1 range. While we'd like it's in range PT1 indeed.
The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1if (r)return r; }@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON (level))return NULL ;
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 972
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+WARN_ON (!entry->bo); +return 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): [email protected]
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Am 29.03.2017 um 07:58 schrieb Zhang, Jerry (Junwei):
Quoted 6 lines
Hi Felix,
Thanks for your illustration with patience.
I got your meaning then, and thanks to fix that.Quoted 1 line
I think you're right, there are some extra high bits in saddr and
Quoted 8 lines
eaddr, but
Quoted 1 line
they get discarded by the modulo-division in the next recursion
level. For
Quoted 1 line
added clarity the modulo division (or masking of high bits) could be
moved up
Quoted 1 line
to the caller.
It may be more clear if modulo-division called before the caller.
Yeah, indeed that isn't easy to get on first glance.
Please clean that up and also remove all those WARN_ON(), we don't want to spam the system log with backtraces like this.
Regards,
Christian.
Quoted 158 lines
Anyway,
Reviewed-by Junwei Zhang <[email protected]>Quoted 153 lines · Felix
Hi Jerry,
Let me clarify my understanding of the problem and the intention of the fix.
Address range per page: 4KB
Address range per PT (level 3): 2MB
Address range per PD (level 2): 1GB
Address range per PD (level 1): 512GB
Address range per PD (level 0): 256TBImagine for example a mapping that spans multiple level 2 page directories. Say from 0.5GB to 2.5GB.
At level 0:
from = 0
to = 0At level 1:
from = 0
to = 2So for level 2
amdgpu_vm_alloc_levelsgets called 3 times (pt_idx= [0..2]). Without my change, it gets called with the same saddr and eaddr 3 times. So it calculates the same "from" and "to" each time:
from = 256 % 512 = 256
to = 767 % 512 = 255Obviously that doesn't work. What we really want is this (from..to in level 2 when called for
pt_idxvalues from level 1):For pt_idx=0 we want to fill the second half of the level 2 page directory with page tables:
from = 256
to = 511For pt_idx=1 we need to fill the entire level 2 page directories with page tables:
from = 0
to = 511For pt_idx=2 we want to fill the first half of the level 2 page directory with page tables:
from = 0
to = 255This creates a contiguous range of page tables across the three level 2 page directories that are spanned by the allocation. My change achieves that.
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
Regards,
FelixSignature · 17 lines
F e l i x K u e h l i n g SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada (O) +1(289)695-1597 _ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| | /_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com ------------------------------------------------------------------------------- *From:* Zhang, Jerry *Sent:* Tuesday, March 28, 2017 10:54:03 PM *To:* Kuehling, Felix; [email protected]; Koenig, Christian; Zhou, David(ChunMing) *Cc:* Deucher, Alexander; Russell, Kent *Subject:* Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOsQuoted 38 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-2@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(structamdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;@@ -312,8 +314,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,Quoted 2 lines
sub_saddr,
+sub_eaddr, level);Do you mean to create a full sub-pt if
pt_idx!= from and != to? I didn't catch it up clear.In my perspective, we may need to clear the saddr and eaddr upper level bit before going on to allocate the next level PT.
Otherwise, the number of next PT entry will be incorrect, more thannum_entriesas the upper level PT number calculated in.e.g.
there is a address contains
PD + PT1 + PT2 + PT3for the first round, we could get correct "from" and "to" address with right "shift"(3 blocks), then walk over the address space in PD range.
Then for the 2nd round, we cannot get the expected "from" and "to" address with "shift"(2 blocks), as it walks over the address space in PD + PT1 range. While we'd like it's in range PT1 indeed.
The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 12 lines
if (r) return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON (level))return NULL ;
Quoted 10 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo · line 972
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+WARN_ON (!entry->bo); +return entry->bo; }_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): 8acdbd65-f99d-3e0e-b61b-318cf27d7a3b-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 6 lines · Christian König
Am 29.03.2017 um 07:58 schrieb Zhang, Jerry (Junwei):
Quoted 5 lines
Hi Felix,
Thanks for your illustration with patience.
I got your meaning then, and thanks to fix that.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
It may be more clear if modulo-division called before the caller.
Yeah, indeed that isn't easy to get on first glance.
Understanding :)
Quoted 175 lines
Please clean that up and also remove all those
WARN_ON(), we don't want to spam the system log with backtraces like this.Regards,
Christian.Quoted 166 lines
Anyway,
Reviewed-by Junwei Zhang <[email protected]>Quoted 151 lines · Felix
Hi Jerry,
Let me clarify my understanding of the problem and the intention of the fix.
Address range per page: 4KB
Address range per PT (level 3): 2MB
Address range per PD (level 2): 1GB
Address range per PD (level 1): 512GB
Address range per PD (level 0): 256TBImagine for example a mapping that spans multiple level 2 page directories. Say from 0.5GB to 2.5GB.
At level 0:
from = 0
to = 0At level 1:
from = 0
to = 2So for level 2
amdgpu_vm_alloc_levelsgets called 3 times (pt_idx= [0..2]). Without my change, it gets called with the same saddr and eaddr 3 times. So it calculates the same "from" and "to" each time:
from = 256 % 512 = 256
to = 767 % 512 = 255Obviously that doesn't work. What we really want is this (from..to in level 2 when called for
pt_idxvalues from level 1):For pt_idx=0 we want to fill the second half of the level 2 page directory with page tables:
from = 256
to = 511For pt_idx=1 we need to fill the entire level 2 page directories with page tables:
from = 0
to = 511For pt_idx=2 we want to fill the first half of the level 2 page directory with page tables:
from = 0
to = 255This creates a contiguous range of page tables across the three level 2 page directories that are spanned by the allocation. My change achieves that.
I think you're right, there are some extra high bits in saddr and eaddr, but they get discarded by the modulo-division in the next recursion level. For added clarity the modulo division (or masking of high bits) could be moved up to the caller.
Regards,
Felix--
F e l i x K u e h l i n g
SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada
(O) +1(289)695-1597_ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| |/_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com
-------------------------------------------------------------------------------
*From:* Zhang, Jerry
*Sent:* Tuesday, March 28, 2017 10:54:03 PM
*To:* Kuehling, Felix; [email protected]; Koenig, Christian; Zhou, David(ChunMing)
*Cc:* Deucher, Alexander; Russell, Kent
*Subject:* Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOsQuoted 28 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;@@ -312,8 +314,11 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_alloc_levels(struct amdgpu_device · line 322
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-2}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);Do you mean to create a full sub-pt if
pt_idx!= from and != to? I didn't catch it up clear.In my perspective, we may need to clear the saddr and eaddr upper level bit before going on to allocate the next level PT.
Otherwise, the number of next PT entry will be incorrect, more thannum_entriesas the upper level PT number calculated in.e.g.
there is a address contains
PD + PT1 + PT2 + PT3for the first round, we could get correct "from" and "to" address with right "shift"(3 blocks), then walk over the address space in PD range.
Then for the 2nd round, we cannot get the expected "from" and "to" address with "shift"(2 blocks), as it walks over the address space in PD + PT1 range. While we'd like it's in range PT1 indeed.
The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0if (r)return r;}drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(structamdgpu_pte_update_params *p, entry = &entry->entries[idx]; } -if (level) +if (WARN_ON (level))return NULL ;Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo *amdgpu_vm_get_pt(struct · line 972
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+WARN_ON (!entry->bo); +return entry->bo; }_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
In reply to a message not in the archiveQuoted 9 lines · Christian König
Am 29.03.2017 um 07:58 schrieb Zhang, Jerry (Junwei):
Quoted 8 lines
Hi Felix,
Thanks for your illustration with patience.
I got your meaning then, and thanks to fix that.Quoted 1 line
I think you're right, there are some extra high bits in saddr and
eaddr, but
Quoted 1 line
they get discarded by the modulo-division in the next recursion
Quoted 8 lines
Quoted 6 lines
level. For
Quoted 1 line
added clarity the modulo division (or masking of high bits) could
be moved up
Quoted 1 line
to the caller.
It may be more clear if modulo-division called before the caller.
Yeah, indeed that isn't easy to get on first glance.
OK, I'll fix that.
Quoted 3 lines
Please clean that up and also remove all those
WARN_ON(), we don't want to spam the system log with backtraces like this.
I disagree. When you see the backtraces from WARN_ONs in amdgpu_vm_get_pt, it means the driver is trying to update a page table that hasn't been allocated. Without those WARN_ONs there is absolutely no warning of any kind - amdgpu_vm_update_pte just fails silently (it's a void function).
Therefore I wouldn't call those warnings spam. Given that the VM PT allocation code for multi-levels is non-trivial, I think that's a good sanity check to have and really helpful to see in a log when user report random VM faults.
Regards,
Felix
Quoted 195 lines
Regards,
Christian.Quoted 189 lines
Anyway,
Reviewed-by Junwei Zhang <[email protected]>Quoted 65 lines · Felix
Hi Jerry,
Let me clarify my understanding of the problem and the intention of the fix.
Address range per page: 4KB
Address range per PT (level 3): 2MB
Address range per PD (level 2): 1GB
Address range per PD (level 1): 512GB
Address range per PD (level 0): 256TBImagine for example a mapping that spans multiple level 2 page directories. Say
from 0.5GB to 2.5GB.At level 0:
from = 0
to = 0At level 1:
from = 0
to = 2So for level 2
amdgpu_vm_alloc_levelsgets called 3 times (pt_idx= [0..2]).
Without my change, it gets called with the same saddr and eaddr 3 times. So it
calculates the same "from" and "to" each time:
from = 256 % 512 = 256
to = 767 % 512 = 255Obviously that doesn't work. What we really want is this (from..to in level 2
when called forpt_idxvalues from level 1):For pt_idx=0 we want to fill the second half of the level 2 page directory with
page tables:
from = 256
to = 511For pt_idx=1 we need to fill the entire level 2 page directories with page tables:
from = 0
to = 511For pt_idx=2 we want to fill the first half of the level 2 page directory with
page tables:
from = 0
to = 255This creates a contiguous range of page tables across the three level 2 page
directories that are spanned by the allocation. My change achieves that.I think you're right, there are some extra high bits in saddr and eaddr, but
they get discarded by the modulo-division in the next recursion level. For
added clarity the modulo division (or masking of high bits) could be moved up
to the caller.Quoted 115 lines
Regards,
FelixSignature · 19 lines
F e l i x K u e h l i n g SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada (O) +1(289)695-1597 _ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| | /_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com ------------------------------------------------------------------------------- *From:* Zhang, Jerry *Sent:* Tuesday, March 28, 2017 10:54:03 PM *To:* Kuehling, Felix; [email protected]; Koenig, Christian; Zhou, David(ChunMing) *Cc:* Deucher, Alexander; Russell, Kent *Subject:* Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOsQuoted 39 lines · Felix Kuehling
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.Signed-off-by Felix Kuehling <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-2@@ -278,6 +278,8 @@ static int amdgpu_vm_alloc_levels(structamdgpu_device *adev, from = (saddr >> shift) %amdgpu_vm_num_entries (adev, level); to = (eaddr >> shift) %amdgpu_vm_num_entries (adev, level); +WARN_ON (from > to); +if (to > parent->last_entry_used) parent->last_entry_used = to;@@ -312,8 +314,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,Quoted 2 lines
sub_saddr,
+sub_eaddr, level);Do you mean to create a full sub-pt if
pt_idx!= from and != to? I didn't catch it up clear.In my perspective, we may need to clear the saddr and eaddr upper level bit
before going on to allocate the next level PT. Otherwise, the number of next PT entry will be incorrect, more thannum_entries
as the upper level PT number calculated in.e.g.
there is a address contains
PD + PT1 + PT2 + PT3for the first round, we could get correct "from" and "to" address with right
"shift"(3 blocks), then walk over the address space in PD range.Then for the 2nd round, we cannot get the expected "from" and "to" address with
"shift"(2 blocks), as it walks over the address space in PD + PT1 range.
While we'd like it's in range PT1 indeed.The fault way goes on with later round.
Perhaps, that's the root cause about the issue you face.
Jerry.
Quoted 8 lines
if (r) return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -957,9 +962,11 @@ static struct amdgpu_bo *amdgpu_vm_get_pt(struct amdgpu_pte_update_params *p, entry = &entry->entries[idx];drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static struct amdgpu_bo · line 972
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1} -if (level) +if (WARN_ON (level))return NULL ; +WARN_ON (!entry->bo); +return entry->bo; }_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): bdbacee3-2c61-ebcb-1421-5c0a77dc27e0-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 11 lines · Felix Kuehling
Quoted 3 lines · Christian König
Please clean that up and also remove all those
WARN_ON(), we don't want to spam the system log with backtraces like this.I disagree. When you see the backtraces from
WARN_ONsinamdgpu_vm_get_pt, it means the driver is trying to update a page table that hasn't been allocated. Without thoseWARN_ONsthere is absolutely no warning of any kind -amdgpu_vm_update_ptejust fails silently (it's a void function).
Quoted 4 lines
Therefore I wouldn't call those warnings spam. Given that the VM PT allocation code for multi-levels is non-trivial, I think that's a good sanity check to have and really helpful to see in a log when user report random VM faults.
WARN_ON_ONCE might be a compromise. We'll still get a backtrace, but it won't cause crazy log spam if the bad condition is consistently hit.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ 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): a2d6c20e-d35f-e135-342b-47f86683c3e3-otUistvHUpPR7s880joybQ@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Am 29.03.2017 um 16:46 schrieb Michel Dänzer:
Quoted 10 lines · Felix Kuehling
Quoted 9 lines · Christian König
Quoted 2 lines
Please clean that up and also remove all those
WARN_ON(), we don't want to spam the system log with backtraces like this.I disagree. When you see the backtraces from
WARN_ONsinamdgpu_vm_get_pt, it means the driver is trying to update a page table that hasn't been allocated. Without thoseWARN_ONsthere is absolutely no warning of any kind -amdgpu_vm_update_ptejust fails silently (it's a void function).
Quoted 6 lines
Quoted 4 lines
Therefore I wouldn't call those warnings spam. Given that the VM PT allocation code for multi-levels is non-trivial, I think that's a good sanity check to have and really helpful to see in a log when user report random VM faults.
WARN_ON_ONCEmight be a compromise. We'll still get a backtrace, but it won't cause crazy log spam if the bad condition is consistently hit.
Good idea. We should also only add one at the beginning of the function and not multiple catches for each dependent variable.
Regards,
Christian.
_______________________________________________
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): d7279f4d-023e-a8fb-c08f-4e85fec87bd6-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 16 lines · Christian König
Am 29.03.2017 um 16:46 schrieb Michel Dänzer:
Quoted 15 lines · Felix Kuehling
Quoted 14 lines · Christian König
Quoted 2 lines
Please clean that up and also remove all those
WARN_ON(), we don't want to spam the system log with backtraces like this.I disagree. When you see the backtraces from
WARN_ONsinamdgpu_vm_get_pt, it means the driver is trying to update a page table that hasn't been allocated. Without thoseWARN_ONsthere is absolutely no warning of any kind -amdgpu_vm_update_ptejust fails silently (it's a void function).Therefore I wouldn't call those warnings spam. Given that the VM PT allocation code for multi-levels is non-trivial, I think that's a good sanity check to have and really helpful to see in a log when user report
random VM faults.
Quoted 4 lines
Quoted 2 lines
WARN_ON_ONCEmight be a compromise. We'll still get a backtrace, but it won't cause crazy log spam if the bad condition is consistently hit.Good idea. We should also only add one at the beginning of the function and not multiple catches for each dependent variable.
I don't understand what you mean here. Are we still talking about amdgpu_vm_update_pte? You'll have to walk the page table before you know whether a PT BO actually exists. So I don't understand what check would make sense at the start (before the page table walk).
I removed the WARN_ON from amdgpu_vm_alloc_levels and instead return an error if "from" or "to" are out of range. I'll send out v2 of my patch in a minute.
Regards,
Felix
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
zhoucm1
Reviewed-by Chunming ZhouEspecially nice for sub level saddr/eaddr calculation.
Regards,
David Zhou
Quoted 12 lines · Felix Kuehling
I worked on these fixes on amd-kfd-staging with a merge of the recent multi- level page table changes. With these changes KFDTest passes on Vega10, including some tests that tend to stress VM memory management.
They applied cleanly to current amd-staging-4.9 but are only compile-tested on that branch.
Felix Kuehling (3):
drm/amdgpu: Makemax_pfn64-bit
drm/amdgpu: Fix Vega10 VM initialization drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 6 files changed, 29 insertions(+), 23 deletions(-)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangQuoted 6 lines · Felix Kuehling
I worked on these fixes on amd-kfd-staging with a merge of the recent multi- level page table changes. With these changes KFDTest passes on Vega10, including some tests that tend to stress VM memory management.
They applied cleanly to current amd-staging-4.9 but are only compile-tested on that branch.
Patch 1 and 3
Sorry I didn't got the patch 2 in mailbox.
Am I missing anything?
Quoted 6 lines
Felix Kuehling (3):
drm/amdgpu: Makemax_pfn64-bit
drm/amdgpu: Fix Vega10 VM initialization drm/amdgpu: Fix multi-level page table bugs for large BOs
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 6 files changed, 29 insertions(+), 23 deletions(-)
_______________________________________________
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): [email protected]
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangQuoted 5 lines · Jerry (Junwei)
Quoted 4 lines · Felix Kuehling
I worked on these fixes on amd-kfd-staging with a merge of the recent multi- level page table changes. With these changes KFDTest passes on Vega10, including some tests that tend to stress VM memory management.
Quoted 8 lines
Quoted 2 lines
They applied cleanly to current amd-staging-4.9 but are only compile-tested on that branch.
Patch 1 and 3
Reviewed-by Junwei Zhang <[email protected]>Sorry I didn't got the patch 2 in mailbox.
Am I missing anything?
I found the patch 2 in my vega10 folder.
Jerry
Quoted 15 lines
Quoted 7 lines
Felix Kuehling (3):
drm/amdgpu: Makemax_pfn64-bit
drm/amdgpu: Fix Vega10 VM initialization drm/amdgpu: Fix multi-level page table bugs for large BOsQuoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++---------- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 5 +++-- 6 files changed, 29 insertions(+), 23 deletions(-)
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx