// SPDX-License-Identifier: GPL-2.0
 
 /*
- * Copyright 2016-2019 HabanaLabs, Ltd.
+ * Copyright 2016-2021 HabanaLabs, Ltd.
  * All Rights Reserved.
  */
 
        }
 
        handle->count = count;
+
+       hl_ctx_get(hdev, hpriv->ctx);
+       handle->ctx = hpriv->ctx;
        mgr = &hpriv->ctx->sig_mgr;
 
        spin_lock(&mgr->lock);
        if (hdl_id < 0) {
                dev_err(hdev->dev, "Failed to allocate IDR for a new signal reservation\n");
                rc = -EINVAL;
-               goto free_handle;
+               goto put_ctx;
        }
 
        handle->id = hdl_id;
        idr_remove(&mgr->handles, hdl_id);
        spin_unlock(&mgr->lock);
 
-free_handle:
+put_ctx:
+       hl_ctx_put(handle->ctx);
        kfree(handle);
 
 out:
 
                /* Release the id and free allocated memory of the handle */
                idr_remove(&mgr->handles, handle_id);
+               hl_ctx_put(encaps_sig_hdl->ctx);
                kfree(encaps_sig_hdl);
        } else {
                rc = -EINVAL;
 
 // SPDX-License-Identifier: GPL-2.0
 
 /*
- * Copyright 2016-2019 HabanaLabs, Ltd.
+ * Copyright 2016-2021 HabanaLabs, Ltd.
  * All Rights Reserved.
  */
 
 {
        struct hl_cs_encaps_sig_handle *handle =
                container_of(ref, struct hl_cs_encaps_sig_handle, refcount);
-       struct hl_ctx *ctx = handle->hdev->compute_ctx;
-       struct hl_encaps_signals_mgr *mgr = &ctx->sig_mgr;
+       struct hl_encaps_signals_mgr *mgr = &handle->ctx->sig_mgr;
 
        spin_lock(&mgr->lock);
        idr_remove(&mgr->handles, handle->id);
        spin_unlock(&mgr->lock);
 
+       hl_ctx_put(handle->ctx);
        kfree(handle);
 }
 
 {
        struct hl_cs_encaps_sig_handle *handle =
                container_of(ref, struct hl_cs_encaps_sig_handle, refcount);
-       struct hl_ctx *ctx = handle->hdev->compute_ctx;
-       struct hl_encaps_signals_mgr *mgr = &ctx->sig_mgr;
+       struct hl_encaps_signals_mgr *mgr = &handle->ctx->sig_mgr;
 
        /* if we're here, then there was a signals reservation but cs with
         * encaps signals wasn't submitted, so need to put refcount
        idr_remove(&mgr->handles, handle->id);
        spin_unlock(&mgr->lock);
 
+       hl_ctx_put(handle->ctx);
        kfree(handle);
 }
 
 
  *            wait cs are used to wait of the reserved encaps signals.
  * @hdev: pointer to habanalabs device structure.
  * @hw_sob: pointer to  H/W SOB used in the reservation.
+ * @ctx: pointer to the user's context data structure
  * @cs_seq: staged cs sequence which contains encapsulated signals
  * @id: idr handler id to be used to fetch the handler info
  * @q_idx: stream queue index
        struct kref refcount;
        struct hl_device *hdev;
        struct hl_hw_sob *hw_sob;
+       struct hl_ctx *ctx;
        u64  cs_seq;
        u32  id;
        u32  q_idx;
 
        struct hl_encaps_signals_mgr *mgr;
        int rc = 0;
 
-       mgr = &hdev->compute_ctx->sig_mgr;
+       mgr = &cs->ctx->sig_mgr;
 
        spin_lock(&mgr->lock);
        encaps_sig_hdl = idr_find(&mgr->handles, cs->encaps_sig_hdl_id);