aie2_populate_range() now uses hmm_range_fault_unlocked_timeout() to let
HMM own mmap_lock acquisition and retry handling while populating an
invalid user mapping. The timeout passed to that helper is a relative
HMM retry budget, not an absolute deadline.

Pass HMM_RANGE_DEFAULT_TIMEOUT directly to the HMM helper instead of
computing the remaining time from a local absolute deadline. The broader
command submission path still keeps its existing timeout around repeated
range population attempts, while each HMM fault attempt receives a fresh
retry budget for HMM's internal mmu-notifier retries.

Keep the existing driver-visible timeout errno by translating -EBUSY
from hmm_range_fault_unlocked_timeout() to -ETIME on return.

Signed-off-by: Stanislav Kinsburskii <[email protected]>
---
 drivers/accel/amdxdna/aie2_ctx.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 548ba4315554..21f2817751f9 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -1037,7 +1037,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj 
*abo)
        bool found;
        int ret;
 
-       timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
+       timeout = msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 again:
        found = false;
        down_write(&xdna->notifier_lock);
@@ -1062,13 +1062,9 @@ static int aie2_populate_range(struct amdxdna_gem_obj 
*abo)
                return -EFAULT;
        }
 
-       ret = hmm_range_fault_unlocked_timeout(&mapp->range,
-                       max_t(long, timeout - jiffies, 1));
-       if (ret) {
-               if (ret == -EBUSY)
-                       ret = -ETIME;
+       ret = hmm_range_fault_unlocked_timeout(&mapp->range, timeout);
+       if (ret)
                goto put_mm;
-       }
 
        down_write(&xdna->notifier_lock);
        if (mmu_interval_read_retry(&mapp->notifier, mapp->range.notifier_seq)) 
{
@@ -1086,7 +1082,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj 
*abo)
 put_mm:
        amdxdna_umap_put(mapp);
        mmput(mm);
-       return ret;
+       return ret == -EBUSY ? -ETIME : ret;
 }
 
 int aie2_cmd_submit(struct amdxdna_hwctx *hwctx, struct amdxdna_sched_job 
*job, u64 *seq)


Reply via email to