public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oded Gabbay <ogabbay@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Ofir Bitton <obitton@habana.ai>
Subject: [PATCH 06/11] habanalabs: add new return code to device fd open
Date: Wed, 16 Mar 2022 13:41:24 +0200	[thread overview]
Message-ID: <20220316114129.2520107-6-ogabbay@kernel.org> (raw)
In-Reply-To: <20220316114129.2520107-1-ogabbay@kernel.org>

From: Ofir Bitton <obitton@habana.ai>

In order to be more informative during device open, we are adding a
new return code -EAGAIN that indicates device is still going through
resource reclaiming and hence it cannot be used yet.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/misc/habanalabs/common/device.c         |  4 ++++
 drivers/misc/habanalabs/common/habanalabs.h     |  2 ++
 drivers/misc/habanalabs/common/habanalabs_drv.c | 15 ++++++++++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/habanalabs/common/device.c b/drivers/misc/habanalabs/common/device.c
index dc9341a64541..3eb392b4308a 100644
--- a/drivers/misc/habanalabs/common/device.c
+++ b/drivers/misc/habanalabs/common/device.c
@@ -107,6 +107,8 @@ static void hpriv_release(struct kref *ref)
 	hdev->is_compute_ctx_active = false;
 	mutex_unlock(&hdev->fpriv_list_lock);
 
+	hdev->compute_ctx_in_release = 0;
+
 	kfree(hpriv);
 }
 
@@ -150,6 +152,8 @@ static int hl_device_release(struct inode *inode, struct file *filp)
 	hl_ts_mgr_fini(hpriv->hdev, &hpriv->ts_mem_mgr);
 	hl_ctx_mgr_fini(hdev, &hpriv->ctx_mgr);
 
+	hdev->compute_ctx_in_release = 1;
+
 	if (!hl_hpriv_put(hpriv))
 		dev_notice(hdev->dev,
 			"User process closed FD but device still in use\n");
diff --git a/drivers/misc/habanalabs/common/habanalabs.h b/drivers/misc/habanalabs/common/habanalabs.h
index 564797766f42..0079f43bc596 100644
--- a/drivers/misc/habanalabs/common/habanalabs.h
+++ b/drivers/misc/habanalabs/common/habanalabs.h
@@ -2710,6 +2710,7 @@ struct hl_reset_info {
  *                        cases where Linux was not loaded to device CPU
  * @supports_wait_for_multi_cs: true if wait for multi CS is supported
  * @is_compute_ctx_active: Whether there is an active compute context executing.
+ * @compute_ctx_in_release: true if the current compute context is being released.
  */
 struct hl_device {
 	struct pci_dev			*pdev;
@@ -2828,6 +2829,7 @@ struct hl_device {
 	u8				supports_wait_for_multi_cs;
 	u8				stream_master_qid_arr_size;
 	u8				is_compute_ctx_active;
+	u8				compute_ctx_in_release;
 
 	/* Parameters for bring-up */
 	u64				nic_ports_mask;
diff --git a/drivers/misc/habanalabs/common/habanalabs_drv.c b/drivers/misc/habanalabs/common/habanalabs_drv.c
index ca404ed9d9a7..e870c32a0733 100644
--- a/drivers/misc/habanalabs/common/habanalabs_drv.c
+++ b/drivers/misc/habanalabs/common/habanalabs_drv.c
@@ -150,7 +150,20 @@ int hl_device_open(struct inode *inode, struct file *filp)
 		dev_err_ratelimited(hdev->dev,
 			"Can't open %s because it is %s\n",
 			dev_name(hdev->dev), hdev->status[status]);
-		rc = -EPERM;
+
+		if (status == HL_DEVICE_STATUS_IN_RESET)
+			rc = -EAGAIN;
+		else
+			rc = -EPERM;
+
+		goto out_err;
+	}
+
+	if (hdev->compute_ctx_in_release) {
+		dev_dbg_ratelimited(hdev->dev,
+			"Can't open %s because another user is still releasing it\n",
+			dev_name(hdev->dev));
+		rc = -EAGAIN;
 		goto out_err;
 	}
 
-- 
2.25.1


  parent reply	other threads:[~2022-03-16 11:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 11:41 [PATCH 01/11] habanalabs: set non-0 value in dram default page size Oded Gabbay
2022-03-16 11:41 ` [PATCH 02/11] habanalabs: add DRAM default page size to HW info Oded Gabbay
2022-03-16 11:41 ` [PATCH 03/11] habanalabs: change mmu_get_real_page_size to be ASIC-specific Oded Gabbay
2022-03-16 11:41 ` [PATCH 04/11] habanalabs: convert all MMU masks/shifts to arrays Oded Gabbay
2022-03-16 11:41 ` [PATCH 05/11] habanalabs: add user API to get valid DRAM page sizes Oded Gabbay
2022-03-16 11:41 ` Oded Gabbay [this message]
2022-03-16 11:41 ` [PATCH 07/11] habanalabs: expose compute ctx status through info ioctl Oded Gabbay
2022-03-16 11:41 ` [PATCH 08/11] habanalabs/gaudi: increase submission resources Oded Gabbay
2022-03-16 11:41 ` [PATCH 09/11] habanalabs/gaudi: avoid resetting max power in hard reset Oded Gabbay
2022-03-16 11:41 ` [PATCH 10/11] habanalabs: parse full firmware versions Oded Gabbay
2022-03-16 11:41 ` [PATCH 11/11] habanalabs: modify dma_mask to be ASIC specific property Oded Gabbay

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=20220316114129.2520107-6-ogabbay@kernel.org \
    --to=ogabbay@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=obitton@habana.ai \
    /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