nouveau_range_fault() now uses hmm_range_fault_unlocked_timeout() for
the HMM fault path. Pass the remaining SVM fault timeout into HMM as a
positive relative timeout instead of open-coding the HMM retry loop in
nouveau.

Keep the outer absolute timeout around nouveau's
mmu_interval_read_retry() loop. HMM's timeout only bounds retries while
HMM is walking and faulting the range. Once HMM returns successfully, a
continuous stream of mmu-notifier invalidations can still make
mmu_interval_read_retry() restart the operation. This path runs from the
GPU fault worker, so fatal signals for the faulting userspace task cannot
be relied on to break that outer loop.

Use time_after_eq() before the HMM call so the remaining timeout passed
to HMM is always positive. This preserves the old timeout behavior at the
expiry boundary and avoids passing 0, which means retry indefinitely, to
hmm_range_fault_unlocked_timeout().

Signed-off-by: Stanislav Kinsburskii <[email protected]>
---
 drivers/gpu/drm/nouveau/nouveau_svm.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c 
b/drivers/gpu/drm/nouveau/nouveau_svm.c
index 4cfb6eb7c771..58735446d783 100644
--- a/drivers/gpu/drm/nouveau/nouveau_svm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_svm.c
@@ -678,14 +678,20 @@ static int nouveau_range_fault(struct nouveau_svmm *svmm,
        range.end = notifier->notifier.interval_tree.last + 1;
 
        while (true) {
-               if (time_after(jiffies, timeout)) {
+               long remaining = timeout - jiffies;
+
+               /*
+                * The HMM timeout only bounds retries while HMM is walking and
+                * faulting the range. This fault is handled by a kernel worker,
+                * so fatal signals from the faulting process cannot stop an
+                * endless stream of invalidations here.
+                */
+               if (time_after_eq(jiffies, timeout)) {
                        ret = -EBUSY;
                        goto out;
                }
 
-               ret = hmm_range_fault_unlocked_timeout(&range,
-                                                      max(timeout - jiffies,
-                                                          1L));
+               ret = hmm_range_fault_unlocked_timeout(&range, remaining);
                if (ret)
                        goto out;
 


Reply via email to