Commit ad2b502b authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'misc-habanalabs-fixes-2021-09-29' of...

Merge tag 'misc-habanalabs-fixes-2021-09-29' of https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/linux into char-misc-linus

Oded writes:

This tag contains the following fix for 5.15-rc4:

- Prevent memset of ioctl arguments in case driver returns -EINTR

* tag 'misc-habanalabs-fixes-2021-09-29' of https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/linux:
  habanalabs: fix resetting args in wait for CS IOCTL
parents 9e1ff307 4ca57d51
...@@ -2649,11 +2649,18 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -2649,11 +2649,18 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)
free_seq_arr: free_seq_arr:
kfree(cs_seq_arr); kfree(cs_seq_arr);
/* update output args */
memset(args, 0, sizeof(*args));
if (rc) if (rc)
return rc; return rc;
if (mcs_data.wait_status == -ERESTARTSYS) {
dev_err_ratelimited(hdev->dev,
"user process got signal while waiting for Multi-CS\n");
return -EINTR;
}
/* update output args */
memset(args, 0, sizeof(*args));
if (mcs_data.completion_bitmap) { if (mcs_data.completion_bitmap) {
args->out.status = HL_WAIT_CS_STATUS_COMPLETED; args->out.status = HL_WAIT_CS_STATUS_COMPLETED;
args->out.cs_completion_map = mcs_data.completion_bitmap; args->out.cs_completion_map = mcs_data.completion_bitmap;
...@@ -2667,8 +2674,6 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -2667,8 +2674,6 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)
/* update if some CS was gone */ /* update if some CS was gone */
if (mcs_data.timestamp) if (mcs_data.timestamp)
args->out.flags |= HL_WAIT_CS_STATUS_FLAG_GONE; args->out.flags |= HL_WAIT_CS_STATUS_FLAG_GONE;
} else if (mcs_data.wait_status == -ERESTARTSYS) {
args->out.status = HL_WAIT_CS_STATUS_INTERRUPTED;
} else { } else {
args->out.status = HL_WAIT_CS_STATUS_BUSY; args->out.status = HL_WAIT_CS_STATUS_BUSY;
} }
...@@ -2688,16 +2693,17 @@ static int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -2688,16 +2693,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, rc = _hl_cs_wait_ioctl(hdev, hpriv->ctx, args->in.timeout_us, seq,
&status, &timestamp); &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)); memset(args, 0, sizeof(*args));
if (rc) { if (rc) {
if (rc == -ERESTARTSYS) { if (rc == -ETIMEDOUT) {
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) {
dev_err_ratelimited(hdev->dev, dev_err_ratelimited(hdev->dev,
"CS %llu has timed-out while user process is waiting for it\n", "CS %llu has timed-out while user process is waiting for it\n",
seq); seq);
...@@ -2823,7 +2829,6 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, ...@@ -2823,7 +2829,6 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
dev_err_ratelimited(hdev->dev, dev_err_ratelimited(hdev->dev,
"user process got signal while waiting for interrupt ID %d\n", "user process got signal while waiting for interrupt ID %d\n",
interrupt->interrupt_id); interrupt->interrupt_id);
*status = HL_WAIT_CS_STATUS_INTERRUPTED;
rc = -EINTR; rc = -EINTR;
} else { } else {
*status = CS_WAIT_STATUS_BUSY; *status = CS_WAIT_STATUS_BUSY;
...@@ -2878,8 +2883,6 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -2878,8 +2883,6 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data)
args->in.interrupt_timeout_us, args->in.addr, args->in.interrupt_timeout_us, args->in.addr,
args->in.target, interrupt_offset, &status); args->in.target, interrupt_offset, &status);
memset(args, 0, sizeof(*args));
if (rc) { if (rc) {
if (rc != -EINTR) if (rc != -EINTR)
dev_err_ratelimited(hdev->dev, dev_err_ratelimited(hdev->dev,
...@@ -2888,6 +2891,8 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data) ...@@ -2888,6 +2891,8 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data)
return rc; return rc;
} }
memset(args, 0, sizeof(*args));
switch (status) { switch (status) {
case CS_WAIT_STATUS_COMPLETED: case CS_WAIT_STATUS_COMPLETED:
args->out.status = HL_WAIT_CS_STATUS_COMPLETED; args->out.status = HL_WAIT_CS_STATUS_COMPLETED;
......
...@@ -917,7 +917,6 @@ struct hl_wait_cs_in { ...@@ -917,7 +917,6 @@ struct hl_wait_cs_in {
#define HL_WAIT_CS_STATUS_BUSY 1 #define HL_WAIT_CS_STATUS_BUSY 1
#define HL_WAIT_CS_STATUS_TIMEDOUT 2 #define HL_WAIT_CS_STATUS_TIMEDOUT 2
#define HL_WAIT_CS_STATUS_ABORTED 3 #define HL_WAIT_CS_STATUS_ABORTED 3
#define HL_WAIT_CS_STATUS_INTERRUPTED 4
#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 #define HL_WAIT_CS_STATUS_FLAG_GONE 0x1
#define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2 #define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2
...@@ -1286,7 +1285,8 @@ struct hl_debug_args { ...@@ -1286,7 +1285,8 @@ struct hl_debug_args {
* EIO - The CS was aborted (usually because the device was reset) * EIO - The CS was aborted (usually because the device was reset)
* ENODEV - The device wants to do hard-reset (so user need to close FD) * ENODEV - The device wants to do hard-reset (so user need to close FD)
* *
* The driver also returns a custom define inside the IOCTL which can be: * The driver also returns a custom define in case the IOCTL call returned 0.
* The define can be one of the following:
* *
* HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0) * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0)
* HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0) * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0)
...@@ -1294,8 +1294,6 @@ struct hl_debug_args { ...@@ -1294,8 +1294,6 @@ struct hl_debug_args {
* (ETIMEDOUT) * (ETIMEDOUT)
* HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the
* device was reset (EIO) * device was reset (EIO)
* HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR)
*
*/ */
#define HL_IOCTL_WAIT_CS \ #define HL_IOCTL_WAIT_CS \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment