} while (i != ring->idx);
- id = list_first_entry(&adev->vm_manager.ids_lru,
- struct amdgpu_vm_id,
- list);
-
- if (!amdgpu_sync_is_idle(&id->active, NULL)) {
- struct list_head *head = &adev->vm_manager.ids_lru;
- struct amdgpu_vm_id *tmp;
-
- list_for_each_entry_safe(id, tmp, &adev->vm_manager.ids_lru,
- list) {
- if (amdgpu_sync_is_idle(&id->active, NULL)) {
- list_move(&id->list, head);
- head = &id->list;
- }
- }
+ /* Check if we have an idle VMID */
+ list_for_each_entry(id, &adev->vm_manager.ids_lru, list) {
+ if (amdgpu_sync_is_idle(&id->active, ring))
+ break;
+
+ }
+
+ /* If we can't find a idle VMID to use, just wait for the oldest */
+ if (&id->list == &adev->vm_manager.ids_lru) {
id = list_first_entry(&adev->vm_manager.ids_lru,
struct amdgpu_vm_id,
list);