clean_process_queues_cpsch will exit early if the memory is evicted,
which means that we can miss running the shader cleaner if the memory
was evicted at the time. Run the cleaner when the memory is restored to
handle this condition

Signed-off-by: Kent Russell <[email protected]>
---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c    | 12 +++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h                |  5 +++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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 86b70748617b..a67db9d31cc0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1571,8 +1571,11 @@ static int clean_process_queues_cpsch(struct 
device_queue_manager *dqm,
        int retval = 0;
 
        dqm_lock(dqm);
-       if (qpd->evicted++ > 0) /* already evicted, do nothing */
+       if (qpd->evicted++ > 0) {
+               /* Already evicted; defer fault clean to restore time */
+               qpd->fault_pending = true;
                goto out;
+       }
 
        pdd = qpd_to_pdd(qpd);
 
@@ -1763,6 +1766,13 @@ static int restore_process_queues_cpsch(struct 
device_queue_manager *dqm,
                        }
                }
        }
+
+       /* Handle deferred fault cleaning from racing 
clean_process_queues_cpsch */
+       if (qpd->fault_pending) {
+               qpd->fault_pending = false;
+               dqm->dev->kfd2kgd->hqd_gfx_clean_fault(dqm->dev->adev);
+       }
+
        if (!dqm->dev->kfd->shared_resources.enable_mes)
                retval = execute_queues_cpsch(dqm,
                                              
KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0, USE_DEFAULT_GRACE_PERIOD);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 158fa70a1a8e..5cd8f55f589c 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -695,6 +695,11 @@ struct qcm_process_device {
        bool is_debug;
        unsigned int evicted; /* eviction counter, 0=active */
 
+       /* Set when fault cleaning was requested but skipped due to eviction.
+        * Checked at restore time to ensure the fault is cleaned.
+        */
+       bool fault_pending;
+
        /* This flag tells if we should reset all wavefronts on
         * process termination
         */
-- 
2.43.0

Reply via email to