On Mon, 4 Dec 2023 18:33:00 +0100 Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx> wrote: > +/** > + * panthor_vm_idle() - Flag a VM idle > + * @VM: VM to flag as idle. > + * > + * When we know the GPU is done with the VM (no more jobs to process), > + * we can relinquish the AS slot attached to this VM, if any. > + * > + * We don't release the slot immediately, but instead place the VM in > + * the LRU list, so it can be evicted if another VM needs an AS slot. > + * This way, VMs keep attached to the AS they were given until we run > + * out of free slot, limiting the number of MMU operations (TLB flush > + * and other AS updates). > + */ > +void panthor_vm_idle(struct panthor_vm *vm) > +{ > + struct panthor_device *ptdev = vm->ptdev; > + > + mutex_lock(&ptdev->mmu->as.slots_lock); > + if (vm->as.id >= 0 && list_empty(&vm->as.lru_node)) > + list_add_tail(&vm->as.lru_node, &ptdev->mmu->as.lru_list); This doesn't work as soon as we have more than one scheduling group per VM. If one of them is being scheduled out while the other stays on a FW slot, the VM becomes idle and its AS might be re-assigned to a different group. We need to refcnt the active users here, and only return the AS when this active_cnt reaches 0. > + mutex_unlock(&ptdev->mmu->as.slots_lock); > +}