Check return of __xa_store when registering a context as this can fail
in a rare case if not memory can not be allocated. If this occurs fall
back on the tasklet flow control and try again in the future.

Signed-off-by: Matthew Brost <matthew.br...@intel.com>
---
 drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c 
b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
index b3157eeb2599..608b30907f4c 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
@@ -503,18 +503,24 @@ static inline bool lrc_desc_registered(struct intel_guc 
*guc, u32 id)
        return __get_context(guc, id);
 }
 
-static inline void set_lrc_desc_registered(struct intel_guc *guc, u32 id,
+static inline int set_lrc_desc_registered(struct intel_guc *guc, u32 id,
                                           struct intel_context *ce)
 {
        unsigned long flags;
+       void *ret;
 
        /*
         * xarray API doesn't have xa_save_irqsave wrapper, so calling the
         * lower level functions directly.
         */
        xa_lock_irqsave(&guc->context_lookup, flags);
-       __xa_store(&guc->context_lookup, id, ce, GFP_ATOMIC);
+       ret = __xa_store(&guc->context_lookup, id, ce, GFP_ATOMIC);
        xa_unlock_irqrestore(&guc->context_lookup, flags);
+
+       if (unlikely(xa_is_err(ret)))
+               return -EBUSY;  /* Try again in future */
+
+       return 0;
 }
 
 static int guc_submission_busy_loop(struct intel_guc* guc,
@@ -1831,7 +1837,9 @@ static int guc_lrc_desc_pin(struct intel_context *ce, 
bool loop)
        rcu_read_unlock();
 
        reset_lrc_desc(guc, desc_idx);
-       set_lrc_desc_registered(guc, desc_idx, ce);
+       ret = set_lrc_desc_registered(guc, desc_idx, ce);
+       if (unlikely(ret))
+               return ret;
 
        desc = __get_lrc_desc(guc, desc_idx);
        desc->engine_class = engine_class_to_guc_class(engine->class);
-- 
2.28.0

Reply via email to