From 5d42ee71befb6f1b9fb5476d02c75000558debe2 Mon Sep 17 00:00:00 2001 From: jsg Date: Mon, 18 May 2026 02:10:30 +0000 Subject: [PATCH] drm/amdgpu: rework how we handle TLB fences From Alex Deucher f0d3bb6f5125c69ce872a7574afd6d9e1f7ea349 in linux-6.18.y/6.18.32 69c5fbd2b93b5ced77c6e79afe83371bca84c788 in mainline linux --- sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c | 7 ++++++- sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c index cdd28408574..c824cbfee45 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.c @@ -1126,7 +1126,10 @@ amdgpu_vm_tlb_flush(struct amdgpu_vm_update_params *params, } /* Prepare a TLB flush fence to be attached to PTs */ - if (!params->unlocked) { + /* The check for need_tlb_fence should be dropped once we + * sort out the issues with KIQ/MES TLB invalidation timeouts. + */ + if (!params->unlocked && vm->need_tlb_fence) { amdgpu_vm_tlb_fence_create(params->adev, vm, fence); /* Makes sure no PD/PT is freed before the flush */ @@ -2672,6 +2675,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, ttm_lru_bulk_move_init(&vm->lru_bulk_move); vm->is_compute_context = false; + vm->need_tlb_fence = amdgpu_userq_enabled(&adev->ddev); vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode & AMDGPU_VM_USE_CPU_FOR_GFX); @@ -2809,6 +2813,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) dma_fence_put(vm->last_update); vm->last_update = dma_fence_get_stub(); vm->is_compute_context = true; + vm->need_tlb_fence = true; unreserve_bo: amdgpu_bo_unreserve(vm->root.bo); diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.h b/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.h index adc7245b1c9..8156a5c90a5 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.h +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_vm.h @@ -449,6 +449,8 @@ struct amdgpu_vm { struct ttm_lru_bulk_move lru_bulk_move; /* Flag to indicate if VM is used for compute */ bool is_compute_context; + /* Flag to indicate if VM needs a TLB fence (KFD or KGD) */ + bool need_tlb_fence; /* Memory partition number, -1 means any partition */ int8_t mem_id;