dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ruoyu Wang <ruoyuw560@gmail.com>
To: Koby Elbaz <koby.elbaz@intel.com>,
	Konstantin Sinyuk <konstantin.sinyuk@intel.com>,
	Oded Gabbay <ogabbay@kernel.org>,
	farah kassabri <fkassabri@habana.ai>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Ruoyu Wang <ruoyuw560@gmail.com>
Subject: [PATCH] accel/habanalabs: publish signal handle after SOB setup
Date: Sat, 20 Jun 2026 23:53:13 +0800	[thread overview]
Message-ID: <20260620155313.79464-1-ruoyuw560@gmail.com> (raw)

cs_ioctl_reserve_signals() makes the encapsulated signal handle visible
in the context IDR before the SOB pointer and pre-reserve SOB value are
set. Concurrent unreserve and wait paths dereference those fields after
IDR lookup.

Reserve the IDR slot with a NULL entry, initialize the handle including
the SOB fields, and replace the slot with the handle only after the
visible state is ready.

Fixes: dadf17abb724 ("habanalabs: add support for encapsulated signals reservation")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 .../habanalabs/common/command_submission.c    | 25 +++++++++++++------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
index ba4257bda77b..791fc01e24c5 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -2009,6 +2009,7 @@ static int cs_ioctl_reserve_signals(struct hl_fpriv *hpriv,
 	struct hl_cs_encaps_sig_handle *handle;
 	struct hl_encaps_signals_mgr *mgr;
 	struct hl_hw_sob *hw_sob;
+	void *old;
 	int hdl_id;
 	int rc = 0;
 
@@ -2045,13 +2046,19 @@ static int cs_ioctl_reserve_signals(struct hl_fpriv *hpriv,
 	}
 
 	handle->count = count;
+	handle->q_idx = q_idx;
+	handle->hdev = hdev;
+	handle->cs_seq = ULLONG_MAX;
+	kref_init(&handle->refcount);
 
 	hl_ctx_get(hpriv->ctx);
 	handle->ctx = hpriv->ctx;
 	mgr = &hpriv->ctx->sig_mgr;
 
 	spin_lock(&mgr->lock);
-	hdl_id = idr_alloc(&mgr->handles, handle, 1, 0, GFP_ATOMIC);
+	hdl_id = idr_alloc(&mgr->handles, NULL, 1, 0, GFP_ATOMIC);
+	if (hdl_id >= 0)
+		handle->id = hdl_id;
 	spin_unlock(&mgr->lock);
 
 	if (hdl_id < 0) {
@@ -2060,11 +2067,6 @@ static int cs_ioctl_reserve_signals(struct hl_fpriv *hpriv,
 		goto put_ctx;
 	}
 
-	handle->id = hdl_id;
-	handle->q_idx = q_idx;
-	handle->hdev = hdev;
-	kref_init(&handle->refcount);
-
 	hdev->asic_funcs->hw_queues_lock(hdev);
 
 	hw_sob = &prop->hw_sob[prop->curr_sob_offset];
@@ -2093,11 +2095,18 @@ static int cs_ioctl_reserve_signals(struct hl_fpriv *hpriv,
 	 */
 	handle->pre_sob_val = prop->next_sob_val - handle->count;
 
-	handle->cs_seq = ULLONG_MAX;
-
 	*signals_count = prop->next_sob_val;
 	hdev->asic_funcs->hw_queues_unlock(hdev);
 
+	spin_lock(&mgr->lock);
+	old = idr_replace(&mgr->handles, handle, hdl_id);
+	spin_unlock(&mgr->lock);
+
+	if (WARN_ON(IS_ERR(old))) {
+		rc = PTR_ERR(old);
+		goto remove_idr;
+	}
+
 	*sob_addr = handle->hw_sob->sob_addr;
 	*handle_id = hdl_id;
 

             reply	other threads:[~2026-06-21 11:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20 15:53 Ruoyu Wang [this message]
2026-06-20 16:08 ` [PATCH] accel/habanalabs: publish signal handle after SOB setup sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260620155313.79464-1-ruoyuw560@gmail.com \
    --to=ruoyuw560@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fkassabri@habana.ai \
    --cc=koby.elbaz@intel.com \
    --cc=konstantin.sinyuk@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox