Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdkfd: partial failure in restore_process_queues_cpsch()
  breaks eviction
- [High] drm/amdkfd: kfd_process_evict_queues() overwrites -EIO across
  multiple PDDs
- [Medium] drm/amdkfd: restore_process_queues_cpsch() misses GFX11
  oversubscription work
--

commit 96e422e9089ef50f901d8f75facedb9f1a4d5c7f
Author: Armas Spann <[email protected]>

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

This commit continues evicting remaining process queues when
remove_queue_mes() fails and returns -EIO, and defers marking queues active
in restore_process_queues_cpsch() until add_queue_mes() succeeds while
skipping already-active queues on retry.

> 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 0d40053b34c88..dbbc6c0794ed3 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
> @@ -1900,11 +1900,24 @@ static int evict_process_queues_cpsch(struct 
> device_queue_manager *dqm,
>               decrement_queue_count(dqm, qpd, q);
>  
>               if (dqm->dev->kfd->shared_resources.enable_mes) {
> -                     retval = remove_queue_mes(dqm, q, qpd);
> -                     if (retval) {
> -                             dev_err(dev, "Failed to evict queue %d\n",
> -                                     q->properties.queue_id);
> -                             goto out;
> +                     int r = remove_queue_mes(dqm, q, qpd);
> +
> +                     if (r) {
> +                             /*
> +                              * -EIO means a GPU reset is under way or MES
> +                              * is fenced off, both reported already.
> +                              */
> +                             if (r != -EIO)
> +                                     dev_err(dev, "Failed to evict queue 
> %d\n",
> +                                             q->properties.queue_id);
> +                             /*
> +                              * Keep going so that every queue ends up in
> +                              * the evicted state. The caller treats -EIO
> +                              * as evicted, not to be added back. MES may
> +                              * still use this MQD, so it stays pinned.
> +                              */
> +                             retval = -EIO;
> +                             continue;
>                       }
>               }

[Severity: High]
Can kfd_process_evict_queues() lose this -EIO return value when a process
spans multiple PDDs?

In kfd_process_evict_queues(), a single variable r is overwritten on each
PDD iteration:

drivers/gpu/drm/amd/amdkfd/kfd_process.c:kfd_process_evict_queues() {
    ...
        for (i = 0; i < p->n_pdds; i++) {
                ...
                r = pdd->dev->dqm->ops.evict_process_queues(pdd->dev->dqm,
                                                            &pdd->qpd);
                if (r && r != -EIO) {
                        dev_err(dev, "Failed to evict process queues\n");
                        goto fail;
                }
                n_evicted++;
        }

        return r;
}

When remove_queue_mes() fails on an earlier PDD and returns -EIO, the loop
continues and a later PDD that succeeds overwrites r with 0.
evict_process_worker() then sees a successful return, signals the eviction
fence while the unremoved queue on the earlier PDD may still be active in
MES, and schedules p->restore_work.

> @@ -2114,13 +2127,15 @@ static int restore_process_queues_cpsch(struct 
> device_queue_manager *dqm,
>               if (!QUEUE_IS_ACTIVE(q->properties))
>                       continue;
>  
> -             q->properties.is_active = true;
> -             increment_queue_count(dqm, &pdd->qpd, q);
> +             /* Restored by an earlier attempt that failed further down */
> +             if (q->properties.is_active)
> +                     continue;
>  
>               retval = dqm_repin_mqd_bo(dqm, q);
>               if (retval) {
>                       dev_err(dev, "Failed to repin MQD for queue %d\n",
>                               q->properties.queue_id);
> +                     q->properties.is_evicted = true;
>                       goto out;
>               }
>  
> @@ -2129,9 +2144,14 @@ static int restore_process_queues_cpsch(struct 
> device_queue_manager *dqm,
>                       if (retval) {
>                               dev_err(dev, "Failed to restore queue %d\n",
>                                       q->properties.queue_id);
> +                             q->properties.is_evicted = true;
>                               goto out;
>                       }
>               }
> +
> +             /* Count the queue as active only once MES has taken it */
> +             q->properties.is_active = true;
> +             increment_queue_count(dqm, &pdd->qpd, q);
>       }
>       if (!dqm->dev->kfd->shared_resources.enable_mes)
>               retval = execute_queues_cpsch(dqm,

[Severity: High]
If dqm_repin_mqd_bo() or add_queue_mes() fails after earlier queues in
qpd->queues_list have already been restored, does jumping to out with
qpd->evicted still set to 1 prevent those active queues from being evicted?

The queues restored before the failure are now running in MES with
is_active = true and is_evicted = false.  Because qpd->evicted remains 1, a
subsequent evict_process_queues_cpsch() hits "if (qpd->evicted++ > 0) goto
out;" and returns 0 without removing the running queues from MES or flushing
the TLB.  With qpd->evicted now bumped to 2, the next
restore_process_queues_cpsch() retry only decrements qpd->evicted back to 1
and exits without restoring the remaining queues.

[Severity: Medium]
Does moving increment_queue_count() after add_queue_mes() skip scheduling
dqm->notify_unmap_work on GFX11 when the restored queue is the one that
crosses the oversubscription threshold?

add_queue_mes() checks dqm->active_cp_queue_count > get_cp_queues_num(dqm)
before returning.  Because increment_queue_count() has not been called yet,
the final restored compute queue that brings active_cp_queue_count to
get_cp_queues_num(dqm) + 1 is not counted during that check, leaving
dqm->notify_unmap_work unscheduled.

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

Reply via email to