Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+21 -18
+19 -14
drivers/misc/habanalabs/common/command_submission.c
··· 2649 2649 free_seq_arr: 2650 2650 kfree(cs_seq_arr); 2651 2651 2652 - /* update output args */ 2653 - memset(args, 0, sizeof(*args)); 2654 2652 if (rc) 2655 2653 return rc; 2654 + 2655 + if (mcs_data.wait_status == -ERESTARTSYS) { 2656 + dev_err_ratelimited(hdev->dev, 2657 + "user process got signal while waiting for Multi-CS\n"); 2658 + return -EINTR; 2659 + } 2660 + 2661 + /* update output args */ 2662 + memset(args, 0, sizeof(*args)); 2656 2663 2657 2664 if (mcs_data.completion_bitmap) { 2658 2665 args->out.status = HL_WAIT_CS_STATUS_COMPLETED; ··· 2674 2667 /* update if some CS was gone */ 2675 2668 if (mcs_data.timestamp) 2676 2669 args->out.flags |= HL_WAIT_CS_STATUS_FLAG_GONE; 2677 - } else if (mcs_data.wait_status == -ERESTARTSYS) { 2678 - args->out.status = HL_WAIT_CS_STATUS_INTERRUPTED; 2679 2670 } else { 2680 2671 args->out.status = HL_WAIT_CS_STATUS_BUSY; 2681 2672 } ··· 2693 2688 rc = _hl_cs_wait_ioctl(hdev, hpriv->ctx, args->in.timeout_us, seq, 2694 2689 &status, &timestamp); 2695 2690 2691 + if (rc == -ERESTARTSYS) { 2692 + dev_err_ratelimited(hdev->dev, 2693 + "user process got signal while waiting for CS handle %llu\n", 2694 + seq); 2695 + return -EINTR; 2696 + } 2697 + 2696 2698 memset(args, 0, sizeof(*args)); 2697 2699 2698 2700 if (rc) { 2699 - if (rc == -ERESTARTSYS) { 2700 - dev_err_ratelimited(hdev->dev, 2701 - "user process got signal while waiting for CS handle %llu\n", 2702 - seq); 2703 - args->out.status = HL_WAIT_CS_STATUS_INTERRUPTED; 2704 - rc = -EINTR; 2705 - } else if (rc == -ETIMEDOUT) { 2701 + if (rc == -ETIMEDOUT) { 2706 2702 dev_err_ratelimited(hdev->dev, 2707 2703 "CS %llu has timed-out while user process is waiting for it\n", 2708 2704 seq); ··· 2829 2823 dev_err_ratelimited(hdev->dev, 2830 2824 "user process got signal while waiting for interrupt ID %d\n", 2831 2825 interrupt->interrupt_id); 2832 - *status = HL_WAIT_CS_STATUS_INTERRUPTED; 2833 2826 rc = -EINTR; 2834 2827 } else { 2835 2828 *status = CS_WAIT_STATUS_BUSY; ··· 2883 2878 args->in.interrupt_timeout_us, args->in.addr, 2884 2879 args->in.target, interrupt_offset, &status); 2885 2880 2886 - memset(args, 0, sizeof(*args)); 2887 - 2888 2881 if (rc) { 2889 2882 if (rc != -EINTR) 2890 2883 dev_err_ratelimited(hdev->dev, ··· 2890 2887 2891 2888 return rc; 2892 2889 } 2890 + 2891 + memset(args, 0, sizeof(*args)); 2893 2892 2894 2893 switch (status) { 2895 2894 case CS_WAIT_STATUS_COMPLETED:
+2 -4
include/uapi/misc/habanalabs.h
··· 917 917 #define HL_WAIT_CS_STATUS_BUSY 1 918 918 #define HL_WAIT_CS_STATUS_TIMEDOUT 2 919 919 #define HL_WAIT_CS_STATUS_ABORTED 3 920 - #define HL_WAIT_CS_STATUS_INTERRUPTED 4 921 920 922 921 #define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 923 922 #define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2 ··· 1285 1286 * EIO - The CS was aborted (usually because the device was reset) 1286 1287 * ENODEV - The device wants to do hard-reset (so user need to close FD) 1287 1288 * 1288 - * The driver also returns a custom define inside the IOCTL which can be: 1289 + * The driver also returns a custom define in case the IOCTL call returned 0. 1290 + * The define can be one of the following: 1289 1291 * 1290 1292 * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0) 1291 1293 * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0) ··· 1294 1294 * (ETIMEDOUT) 1295 1295 * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the 1296 1296 * device was reset (EIO) 1297 - * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR) 1298 - * 1299 1297 */ 1300 1298 1301 1299 #define HL_IOCTL_WAIT_CS \