Skip to contentSkip to conversation

habanalabs: fix resetting args in wait for interrupt

PATCH Superseded Oded Gabbay 1 participant 2 messages Sep 27, 2021 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 habanalabs: fix resetting args in wait for interrupt

From: Rajaravi Krishna Katta <[email protected]>

If _hl_interrupt_wait_ioctl returns EINTR, resetting args would clear user flags and will result in error in case the userspace will repeat the ioctl call.

---
 drivers/misc/habanalabs/common/command_submission.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
index 91b57544f7c6..39fc6d4fb971 100644
@@ -2878,8 +2878,6 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data)
 				args->in.interrupt_timeout_us, args->in.addr,
 				args->in.target, interrupt_offset, &status);
 
-	memset(args, 0, sizeof(*args));
-
 	if (rc) {
 		if (rc != -EINTR)
 			dev_err_ratelimited(hdev->dev,
@@ -2888,6 +2886,8 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data)
 		return rc;
 	}
 
+	memset(args, 0, sizeof(*args));
+
 	switch (status) {
 	case CS_WAIT_STATUS_COMPLETED:
 		args->out.status = HL_WAIT_CS_STATUS_COMPLETED;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 habanalabs: fix resetting args in wait for CS

From: Rajaravi Krishna Katta <[email protected]>

If _hl_cs_wait_ioctl returns -ERESTARTSYS, resetting args would clear user flags and will result in error in case the userspace repeats the ioctl call.

---
 .../misc/habanalabs/common/command_submission.c   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +8 -7
index 39fc6d4fb971..b479d9ebeb94 100644
@@ -2688,16 +2688,17 @@ static int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)
 	rc = _hl_cs_wait_ioctl(hdev, hpriv->ctx, args->in.timeout_us, seq,
 				&status, &timestamp);
 
+	if (rc == -ERESTARTSYS) {
+		dev_err_ratelimited(hdev->dev,
+			"user process got signal while waiting for CS handle %llu\n",
+			seq);
+		return -EINTR;
+	}
+
 	memset(args, 0, sizeof(*args));
 
 	if (rc) {
-		if (rc == -ERESTARTSYS) {
-			dev_err_ratelimited(hdev->dev,
-				"user process got signal while waiting for CS handle %llu\n",
-				seq);
-			args->out.status = HL_WAIT_CS_STATUS_INTERRUPTED;
-			rc = -EINTR;
-		} else if (rc == -ETIMEDOUT) {
+		if (rc == -ETIMEDOUT) {
 			dev_err_ratelimited(hdev->dev,
 				"CS %llu has timed-out while user process is waiting for it\n",
 				seq);
Signature · 1 line
2.17.1