On 11/16/26 10:24 AM, Christian König wrote:
On 11/13/26 21:40, Kuehling, Felix wrote:
On 2026-11-13 15:29, Shahyan Soltani wrote:
Previously, the root PT was never cleared after setting vm->is_npa =
true within amdgpu_vm_make_npa(). This resulted in the flag
adev->gmc.no_retry_flags to never be applied for the NPA VMs.
Call amdgpu_vm_pt_clear() after vm->is_npa = true is set and the bo has
been pinned/validated. This allows the root PT of the NPA VM to be
cleared with the correct value.
If the pinning or reservation of the bo failed, the vm->is_npa flag will
no longer remain as true. This is to avoid conditionals outside of
amdgpu_vm_make_npa() that depend on the vm->is_npa flag to determine if
the VM is a correctly initialized NPA VM.
Warn if the VM already has mappings, since clearing the root PT will
break existing mappings. Do a heavy weight TLB flush after the root PT
clear to avoid any stale translations being left behind from a previous
table.
Remove the redundant second setting of vm->is_npa = true.
v2:
- Add the WARN_ON sanity check regarding an empty VM. (Felix)
- Change the return handling to only set vm->is_npa = true upon a
successful pin (Felix)
- Add the heavy weight TLB flush after the root PT clear (Philip)
Suggested-by: Christian König<[email protected]>
Signed-off-by: Shahyan Soltani<[email protected]>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 94b1cfe05e3e..c7187e0f99b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2820,20 +2820,27 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev,
struct amdgpu_vm *vm)
*/
int amdgpu_vm_make_npa(struct amdgpu_device *adev, struct amdgpu_vm *vm)
{
- int r = amdgpu_vm_make_compute(adev, vm);
+ int r;
+ r = amdgpu_vm_make_compute(adev, vm);
if (r)
return r;
- vm->is_npa = true;
+
r = amdgpu_bo_reserve(vm->root.bo, false);
if (r)
return r;
You need to reserve fence slots both for pin and clear after locking the root
PD.
How come we need to reserve a slot for amdgpu_bo_pin()?
As far as I can see, amdgpu_vm_pt_clear() needs a fence slot to be reserved because of "r =
vm->update_funcs->commit(¶ms, &vm->last_update);" calling
"amdgpu_vm_sdma_commit();".
That function then needs the fence slot to be reserved as it uses
"dma_resv_add_fence()" without reserving said slot for itself.
amdgpu_bo_pin() on the other hand seems to already reserve slots for itself anytime it uses a
fence ("amdgpu_bo_pin()->ttm_bo_validate()->ttm_bo_alloc_resource()" is a good
example).
Additionally I couldn't find any instances where a fence slot was reserved before
"amdgpu_bo_pin();" was called.
Unlike amdgpu_vm_pt_clear(), "amdgpu_bo_pin();" is called without reserving a
slot.
r = amdgpu_bo_pin(vm->root.bo, AMDGPU_GEM_DOMAIN_VRAM);
+ if (!r) {
+ /* Check if VM mappings are empty, clearing would break existing
mapping */
+ WARN_ON(!RB_EMPTY_ROOT(&vm->va.rb_root));
You should probably move that to the beginning as if
(WARN_ON(!RB_EMPTY_ROOT(&vm->va.rb_root))) return -EINVAL;
+ vm->is_npa = true;
+ r = amdgpu_vm_pt_clear(adev, vm, to_amdgpu_bo_vm(vm->root.bo), false);
+ amdgpu_ualink_flush_tlb(adev, TLB_FLUSH_HEAVYWEIGHT);
The TLB flush isn't really needed IMO. We don't expect there to be any previous
mappings that would need to be flushed. If there were previous mappings, we're
in a broken state anyway, and the WARN_ON would tell you about it.
Completely agree. Sashiko-bot also complained that this wouldn't even compile.
Regards,
Christian.
With the flush_tlb removed, this patch is
Reviewed-by: Felix Kuehling<[email protected]>
+ }
amdgpu_bo_unreserve(vm->root.bo);
if (r)
return r;
- vm->is_npa = true;
vm->need_tlb_fence = false;
return 0;