Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdkfd: evict_process_queues_cpsch() returns 0 with
  unretired MES queues
- [Medium] drm/amdkfd: missing kfd_flush_tlb() in
  restore_process_queues_cpsch() rollback
--

commit 912d1284460b9827cb7b366431ada4596ab37d25
Author: Armas Spann <[email protected]>

drm/amdkfd: keep eviction and restore consistent when MES fails

This commit continues evicting remaining queues when MES queue removal
fails, preserves -EIO across devices in kfd_process_evict_queues(), and
rolls back already-added queues when restore_process_queues_cpsch() fails.

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> index eabb9a6953451..f952880a66657 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

[ ... ]

> @@ -2227,6 +2243,27 @@ static int restore_process_queues_cpsch(struct 
> device_queue_manager *dqm,
>  out:
>       dqm_unlock(dqm);
>       return retval;
> +
> +rollback:
> +     /*
> +      * A half restored process is a problem for the next eviction: it
> +      * finds qpd->evicted set and leaves the queues restored so far
> +      * running. Take those off the hardware again, so that the process
> +      * is fully evicted and the retry starts from a known state. A
> +      * removal that cannot be sent (-EIO) leaves the queue mapped and
> +      * marked evicted, as evict_process_queues_cpsch() does.
> +      */
> +     list_for_each_entry(q, &qpd->queues_list, list) {
> +             q->properties.is_evicted = true;
> +             if (!q->properties.is_active)
> +                     continue;
> +
> +             q->properties.is_active = false;
> +             decrement_queue_count(dqm, qpd, q);
> +             if (dqm->dev->kfd->shared_resources.enable_mes)
> +                     remove_queue_mes(dqm, q, qpd);

[Severity: Medium]
If remove_queue_mes() fails with -EIO here (or during an earlier call to
evict_process_queues_cpsch()), can a subsequent eviction return 0 while
unretired queues are still mapped in MES?

When a later queue fails add_queue_mes() (for instance with -ETIMEDOUT,
which fences MES, or -EIO when a reset starts), remove_queue_mes() in this
rollback returns -EIO and leaves the earlier queues mapped in MES with
qpd->evicted still set to 1.  Because restore_process_helper() has already
armed a new eviction fence before calling kfd_process_restore_queues(), a
TTM eviction that runs before the restore retry sees qpd->evicted++ > 0 in
evict_process_queues_cpsch() and returns 0 instead of -EIO:

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:evict_process_queues_cpsch()
 {
        dqm_lock(dqm);
        if (qpd->evicted++ > 0) /* already evicted, do nothing */
                goto out;
    ...
}

evict_process_worker() then signals the eviction fence and lets TTM move
or unmap BOs while those unretired queues are still on the hardware.

> +     }
> +     goto out;
>  }

[Severity: Medium]
Does this rollback path also need to call kfd_flush_tlb(pdd) after
removing the already-restored queues from MES?

Queues added earlier in the loop may have started executing and issuing
memory accesses before a later queue failed dqm_repin_mqd_bo() or
add_queue_mes().  MES does not perform a heavyweight TLB flush on queue
removal, and because qpd->evicted stays 1, a subsequent call to
evict_process_queues_cpsch() before the restore retry takes the
qpd->evicted++ > 0 early exit and skips kfd_flush_tlb(pdd) as well,
allowing BOs or SVM ranges to be migrated or freed before in-flight memory
accesses complete.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=6

Reply via email to