accel/habanalabs: prevent immediate hard reset due to 2 adjacent H/W events
Oded Gabbay
maintainerPATCH 1/12 accel/habanalabs: prevent immediate hard reset due to 2 adjacent H/W events
From: Tomer Tayar <[email protected]>
When a H/W event is received while a user is registered to events, no immediate hard reset will happen, and instead the user will be notified and will have some time to handle it and eventually release the device, after which the reset will be done.
If a user, as part of the handling and as part of the cleanup steps towards releasing the device, unregisters from receiving those events, and at that time an adjacent H/W event is received, it will be assumed that the user is not registered to events and thus an immediate hard reset is required.
To prevent such an unwanted immediate reset, modify the driver to perform it if the user is not registered to events AND we don't already have a pending reset for a previous H/W event.
--- drivers/accel/habanalabs/common/device.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/accel/habanalabs/common/device.c +10 -1
@@ -1916,7 +1916,16 @@ int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask) } ctx =hl_get_compute_ctx (hdev); -if (!ctx || !ctx->hpriv->notifier_event.eventfd) +if (!ctx) + goto device_reset; + +/* +* There is no point in postponing the reset if user is not registered for events. +* However if no eventfd_ctx exists but the device release watchdog is already scheduled, it +* just implies that user has unregistered as part of handling a previous event. In this +* case an immediate reset is not required. +*/ +if (!ctx->hpriv->notifier_event.eventfd && !hdev->reset_info.watchdog_active) goto device_reset;/* Schedule the device release watchdog work unless reset is already in progress or if the
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 2/12 accel/habanalabs: update pending reset flags with new reset requests
From: Tomer Tayar <[email protected]>
If hl_device_cond_reset() is called while a reset is already pending but hasn't started, the reset request will be dropped.
If the flags of the new request are more severe, e.g. a hard reset while the pending reset is a compute reset, the eventual reset won't be suitable for the device status.
To prevent such cases, update the pending reset flags with the new requests flags before the requests are dropped.
--- drivers/accel/habanalabs/common/device.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/accel/habanalabs/common/device.c +3 -1
@@ -1937,8 +1937,10 @@ int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask) goto device_reset; } -if (hdev->reset_info.watchdog_active) +if (hdev->reset_info.watchdog_active) { + hdev->device_release_watchdog_work.flags |= flags; goto out; + } hdev->device_release_watchdog_work.flags = flags; dev_dbg(hdev->dev, "Device is going to be hard-reset in %u sec unless being released\n",
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 3/12 accel/habanalabs: notify user about undefined opcode event
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
In order for user to be aware of undefined opcode events, we must store all relevant information and notify user about the failure. The user will fetch the stored info via info ioctl.
--- drivers/accel/habanalabs/gaudi2/gaudi2.c | 142 ++++++++++++++++++++++- 1 file changed, 137 insertions(+), 5 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +137 -5
@@ -993,6 +993,111 @@ gaudi2_pcie_addr_dec_error_cause[GAUDI2_NUM_OF_PCIE_ADDR_DEC_ERR_CAUSE] = {"TLP is blocked by RR" }; +static const int gaudi2_queue_id_to_engine_id[] = { + [GAUDI2_QUEUE_ID_PDMA_0_0 ...GAUDI2_QUEUE_ID_PDMA_0_3 ] =GAUDI2_ENGINE_ID_PDMA_0 , + [GAUDI2_QUEUE_ID_PDMA_1_0 ...GAUDI2_QUEUE_ID_PDMA_1_3 ] =GAUDI2_ENGINE_ID_PDMA_1 , + [GAUDI2_QUEUE_ID_DCORE0_EDMA_0_0 ...GAUDI2_QUEUE_ID_DCORE0_EDMA_0_3 ] = +GAUDI2_DCORE0_ENGINE_ID_EDMA_0 , + [GAUDI2_QUEUE_ID_DCORE0_EDMA_1_0 ...GAUDI2_QUEUE_ID_DCORE0_EDMA_1_3 ] = +GAUDI2_DCORE0_ENGINE_ID_EDMA_1 , + [GAUDI2_QUEUE_ID_DCORE1_EDMA_0_0 ...GAUDI2_QUEUE_ID_DCORE1_EDMA_0_3 ] = +GAUDI2_DCORE1_ENGINE_ID_EDMA_0 , + [GAUDI2_QUEUE_ID_DCORE1_EDMA_1_0 ...GAUDI2_QUEUE_ID_DCORE1_EDMA_1_3 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[GAUDI2_QUEUE_ID_ROT_0_0 ...GAUDI2_QUEUE_ID_ROT_0_3 ] =GAUDI2_ENGINE_ID_ROT_0 , + [GAUDI2_QUEUE_ID_ROT_1_0 ...GAUDI2_QUEUE_ID_ROT_1_3 ] =GAUDI2_ENGINE_ID_ROT_1 , +}; +const u32 gaudi2_qm_blocks_bases[GAUDI2_QUEUE_ID_SIZE ] = { [GAUDI2_QUEUE_ID_PDMA_0_0 ] = mmPDMA0_QM_BASE, [GAUDI2_QUEUE_ID_PDMA_0_1 ] = mmPDMA0_QM_BASE,
@@ -7753,7 +7858,7 @@ static bool gaudi2_handle_ecc_event(struct hl_device *hdev, u16 event_type,return !!ecc_data->is_critical; } -static void print_lower_qman_data_on_err (struct hl_device *hdev,u64 qman_base) +static void handle_lower_qman_data_on_err (struct hl_device *hdev,u64 qman_base,u64 event_mask) {u32 lo, hi, cq_ptr_size, arc_cq_ptr_size;u64 cq_ptr, arc_cq_ptr, cp_current_inst;
@@ -7775,10 +7880,22 @@ static void print_lower_qman_data_on_err(struct hl_device *hdev, u64 qman_base)dev_info (hdev->dev,"LowerQM. CQ: {ptr %#llx, size %u}, ARC_CQ: {ptr %#llx, size %u}, CP: {instruction %#llx}\n" , cq_ptr, cq_ptr_size, arc_cq_ptr, arc_cq_ptr_size, cp_current_inst); + +if (event_mask &HL_NOTIFIER_EVENT_UNDEFINED_OPCODE ) { +if (arc_cq_ptr) { + hdev->captured_err_info.undef_opcode.cq_addr = arc_cq_ptr; + hdev->captured_err_info.undef_opcode.cq_size = arc_cq_ptr_size; + }else { + hdev->captured_err_info.undef_opcode.cq_addr = cq_ptr; + hdev->captured_err_info.undef_opcode.cq_size = cq_ptr_size; + } + + hdev->captured_err_info.undef_opcode.stream_id =QMAN_STREAMS ; + } }static int gaudi2_handle_qman_err_generic (struct hl_device *hdev,u16 event_type, -u64 qman_base,u32 qid_base) +u64 qman_base,u32 qid_base,u64 *event_mask) {u32 i, j, glbl_sts_val, arb_err_val, num_error_causes, error_count =0 ;u64 glbl_sts_addr, arb_err_addr;
@@ -7812,8 +7929,22 @@ static int gaudi2_handle_qman_err_generic(struct hl_device *hdev, u16 event_type error_count++; } -if (i ==QMAN_STREAMS ) -print_lower_qman_data_on_err (hdev, qman_base); +if (i ==QMAN_STREAMS && error_count) { +/* check for undefined opcode */ +if (glbl_sts_val &PDMA0_QM_GLBL_ERR_STS_CP_UNDEF_CMD_ERR_MASK && + hdev->captured_err_info.undef_opcode.write_enable) { +memset (&hdev->captured_err_info.undef_opcode,0 , +sizeof (hdev->captured_err_info.undef_opcode)); + + hdev->captured_err_info.undef_opcode.write_enable = false; + hdev->captured_err_info.undef_opcode.timestamp =ktime_get (); + hdev->captured_err_info.undef_opcode.engine_id = + gaudi2_queue_id_to_engine_id[qid_base]; + *event_mask |=HL_NOTIFIER_EVENT_UNDEFINED_OPCODE ; + } + +handle_lower_qman_data_on_err (hdev, qman_base, *event_mask); + } } arb_err_val =RREG32 (arb_err_addr);
@@ -8475,7 +8606,8 @@ static int gaudi2_handle_qman_err(struct hl_device *hdev, u16 event_type, u64 *ereturn 0 ; } - error_count =gaudi2_handle_qman_err_generic (hdev, event_type, qman_base, qid_base); + error_count =gaudi2_handle_qman_err_generic (hdev, event_type, qman_base, + qid_base, event_mask);/* Handle EDMA QM SEI here because there is no AXI error response event for EDMA */ if (event_type >=GAUDI2_EVENT_HDMA2_QM && event_type <=GAUDI2_EVENT_HDMA5_QM ) {
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 4/12 accel/habanalabs: print task name and request code upon ioctl failure
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
When an ioctl fails, it is useful to know what is the task command name and the full ioctl request code, in addition to the task pid and the ioctl number.
Add the additional information to the relevant debug error prints.
--- .../habanalabs/common/habanalabs_ioctl.c | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/accel/habanalabs/common/habanalabs_ioctl.c +17 -7
@@ -1194,9 +1194,13 @@ static long _hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg, retcode = -EFAULT ; out_err: -if (retcode) -dev_dbg_ratelimited (dev,"error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n" , -task_pid_nr (current), cmd, nr); +if (retcode) { +char task_comm[TASK_COMM_LEN ]; + +dev_dbg_ratelimited (dev, +"error in ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n" , +task_pid_nr (current),get_task_comm (task_comm, current), cmd, nr); + }if (kdata != stack_kdata)kfree (kdata);
@@ -1219,8 +1223,11 @@ long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)if ((nr >=HL_COMMAND_START ) && (nr <HL_COMMAND_END )) { ioctl = &hl_ioctls[nr]; }else { -dev_dbg_ratelimited (hdev->dev,"invalid ioctl: pid=%d, nr=0x%02x\n" , -task_pid_nr (current), nr); +char task_comm[TASK_COMM_LEN ]; + +dev_dbg_ratelimited (hdev->dev, +"invalid ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n" , +task_pid_nr (current),get_task_comm (task_comm, current), cmd, nr);return -ENOTTY ; }
@@ -1242,8 +1249,11 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)if (nr ==_IOC_NR (HL_IOCTL_INFO )) { ioctl = &hl_ioctls_control[nr]; }else { -dev_dbg_ratelimited (hdev->dev_ctrl,"invalid ioctl: pid=%d, nr=0x%02x\n" , -task_pid_nr (current), nr); +char task_comm[TASK_COMM_LEN ]; + +dev_dbg_ratelimited (hdev->dev_ctrl, +"invalid ioctl: pid=%d, comm=\"%s\", cmd=%#010x, nr=%#04x\n" , +task_pid_nr (current),get_task_comm (task_comm, current), cmd, nr);return -ENOTTY ; }
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 5/12 accel/habanalabs: print task name upon creation of a user context
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
It is useful for debug to know which user process have acquired the device.
Add this info to the relevant debug print, in addition to the already printed user context's ASID.
--- drivers/accel/habanalabs/common/context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/accel/habanalabs/common/context.c +4 -2
@@ -102,7 +102,7 @@ static void hl_ctx_fini(struct hl_ctx *ctx)kfree (ctx->cs_pending);if (ctx->asid !=HL_KERNEL_ASID_ID ) { -dev_dbg (hdev->dev,"closing user context %d\n" , ctx->asid); +dev_dbg (hdev->dev,"closing user context, asid=%u\n" , ctx->asid);/* The engines are stopped as there is no executing CS, but the * Coresight might be still working by accessing addresses
@@ -198,6 +198,7 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv)int hl_ctx_init (struct hl_device *hdev,struct hl_ctx *ctx,bool is_kernel_ctx) { +char task_comm[TASK_COMM_LEN ];int rc =0 , i; ctx->hdev = hdev;
@@ -267,7 +268,8 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)hl_encaps_sig_mgr_init (&ctx->sig_mgr); -dev_dbg (hdev->dev,"create user context %d\n" , ctx->asid); +dev_dbg (hdev->dev,"create user context, comm=\"%s\", asid=%u\n" , +get_task_comm (task_comm, current), ctx->asid); }return 0 ;
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 6/12 accel/habanalabs: set device status 'malfunction' while in rmmod
In reply to Oded GabbayFrom: Koby Elbaz <[email protected]>
hl_device_status() returns the status of an acquired device. If a device is going down (following an rmmod cmd),
it should be marked as an unusable/malfunctioning device, and hence should not be acquired.
However, since this was not the case so far (i.e., a device going down would inaccurately return 'in reset' status allowing the user to acquire the device) it introduced a bug where as part of a reset flow, the driver could not kill processes that have not run yet, and since those processes aren't blocked from reacquiring a device, we get eventually a new flow of a driver attempting to kill all processes in a list that can't be ever really empty.
--- drivers/accel/habanalabs/common/device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/accel/habanalabs/common/device.c +4 -2
@@ -315,7 +315,9 @@ enum hl_device_status hl_device_status(struct hl_device *hdev) {enum hl_device_status status; -if (hdev->reset_info.in_reset) { +if (hdev->device_fini_pending) { + status =HL_DEVICE_STATUS_MALFUNCTION ; + }else if (hdev->reset_info.in_reset) {if (hdev->reset_info.in_compute_reset) status =HL_DEVICE_STATUS_IN_RESET_AFTER_DEVICE_RELEASE ;else
@@ -343,9 +345,9 @@ bool hl_device_operational(struct hl_device *hdev, *status = current_status;switch (current_status) { +case HL_DEVICE_STATUS_MALFUNCTION :case HL_DEVICE_STATUS_IN_RESET :case HL_DEVICE_STATUS_IN_RESET_AFTER_DEVICE_RELEASE : -case HL_DEVICE_STATUS_MALFUNCTION :case HL_DEVICE_STATUS_NEEDS_RESET :return false;case HL_DEVICE_STATUS_OPERATIONAL :
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 7/12 accel/habanalabs: stop fetching MME SBTE error cause
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Because in this case we have only a single possible cause, we can safely stop fetching the cause from firmware.
--- drivers/accel/habanalabs/gaudi2/gaudi2.c | 31 ++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +8 -23
@@ -66,7 +66,6 @@#define GAUDI2_NUM_OF_TPC_INTR_CAUSE 31#define GAUDI2_NUM_OF_DEC_ERR_CAUSE 25#define GAUDI2_NUM_OF_MME_ERR_CAUSE 16 -#define GAUDI2_NUM_OF_MME_SBTE_ERR_CAUSE 5#define GAUDI2_NUM_OF_MME_WAP_ERR_CAUSE 7#define GAUDI2_NUM_OF_DMA_CORE_INTR_CAUSE 8#define GAUDI2_NUM_OF_MMU_SPI_SEI_CAUSE 19
@@ -916,14 +915,6 @@ static const char * const guadi2_mme_error_cause[GAUDI2_NUM_OF_MME_ERR_CAUSE] = "sbte_prtn_intr_4", }; -static const char *const guadi2_mme_sbte_error_cause[GAUDI2_NUM_OF_MME_SBTE_ERR_CAUSE ] = { -"i0" , -"i1" , -"i2" , -"i3" , -"i4" , -}; -static const char *const guadi2_mme_wap_error_cause[GAUDI2_NUM_OF_MME_WAP_ERR_CAUSE ] = {"WBC ERR RESP_0" ,"WBC ERR RESP_1" ,
@@ -8781,21 +8772,16 @@ static int gaudi2_handle_mme_err(struct hl_device *hdev, u8 mme_index, u16 eventreturn error_count; } -static int gaudi2_handle_mme_sbte_err (struct hl_device *hdev,u16 event_type, -u64 intr_cause_data) +static int gaudi2_handle_mme_sbte_err (struct hl_device *hdev,u16 event_type) { -int i, error_count =0 ; - -for (i =0 ; i <GAUDI2_NUM_OF_MME_SBTE_ERR_CAUSE ; i++) -if (intr_cause_data &BIT (i)) { -gaudi2_print_event (hdev, event_type, true, -"err cause: %s" , guadi2_mme_sbte_error_cause[i]); - error_count++; - } - +/* +* We have a single error cause here but the report mechanism is +* buggy. Hence there is no good reason to fetch the cause so we +* just check for glbl_errors and exit. +*/ hl_check_for_glbl_errors (hdev); -return error_count; +return GAUDI2_NA_EVENT_CAUSE ; } static int gaudi2_handle_mme_wap_err(struct hl_device *hdev, u8 mme_index, u16 event_type,
@@ -9856,8 +9842,7 @@ static void gaudi2_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_ent case GAUDI2_EVENT_MME1_SBTE0_AXI_ERR_RSP ... GAUDI2_EVENT_MME1_SBTE4_AXI_ERR_RSP: case GAUDI2_EVENT_MME2_SBTE0_AXI_ERR_RSP ... GAUDI2_EVENT_MME2_SBTE4_AXI_ERR_RSP: case GAUDI2_EVENT_MME3_SBTE0_AXI_ERR_RSP ... GAUDI2_EVENT_MME3_SBTE4_AXI_ERR_RSP: - error_count =gaudi2_handle_mme_sbte_err (hdev, event_type, -le64_to_cpu (eq_entry->intr_cause.intr_cause_data)); + error_count =gaudi2_handle_mme_sbte_err (hdev, event_type); event_mask |=HL_NOTIFIER_EVENT_USER_ENGINE_ERR ;break ; case GAUDI2_EVENT_VM0_ALARM_A ... GAUDI2_EVENT_VM3_ALARM_B:
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 8/12 accel/habanalabs: handle arc farm razwi
In reply to Oded GabbayFrom: Dani Liberman <[email protected]>
Implement razwi handling for arc farm and add it to arc farm sei event handler.
--- drivers/accel/habanalabs/gaudi2/gaudi2.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +13 -3
@@ -2097,7 +2097,8 @@ enum razwi_event_sources {RAZWI_PDMA ,RAZWI_NIC ,RAZWI_DEC , -RAZWI_ROT +RAZWI_ROT , +RAZWI_ARC_FARM }; struct hbm_mc_error_causes {
@@ -8049,6 +8050,9 @@ static enum gaudi2_engine_id gaudi2_razwi_calc_engine_id(struct hl_device *hdev,case RAZWI_ROT :return GAUDI2_ENGINE_ID_ROT_0 + module_idx; +case RAZWI_ARC_FARM : +return GAUDI2_ENGINE_ID_ARC_FARM ; +default :return GAUDI2_ENGINE_ID_SIZE ; }
@@ -8158,6 +8162,11 @@ static void gaudi2_ack_module_razwi_event_handler(struct hl_device *hdev, lbw_rtr_id = gaudi2_rot_initiator_lbw_rtr_id[module_idx];sprintf (initiator_name,"ROT_%u" , module_idx);break ; +case RAZWI_ARC_FARM : + lbw_rtr_id =DCORE1_RTR5 ; + hbw_rtr_id =DCORE1_RTR7 ; +sprintf (initiator_name,"ARC_FARM_%u" , module_idx); +break ;default :return ; }
@@ -8611,7 +8620,7 @@ static int gaudi2_handle_qman_err(struct hl_device *hdev, u16 event_type, u64 *ereturn error_count; } -static int gaudi2_handle_arc_farm_sei_err (struct hl_device *hdev,u16 event_type) +static int gaudi2_handle_arc_farm_sei_err (struct hl_device *hdev,u16 event_type,u64 *event_mask) {u32 i, sts_val, sts_clr_val, error_count =0 , arc_farm;
@@ -8633,6 +8642,7 @@ static int gaudi2_handle_arc_farm_sei_err(struct hl_device *hdev, u16 event_type sts_clr_val); } +gaudi2_ack_module_razwi_event_handler (hdev,RAZWI_ARC_FARM ,0 ,0 , event_mask);hl_check_for_glbl_errors (hdev);return error_count;
@@ -9619,7 +9629,7 @@ static void gaudi2_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entbreak ;case GAUDI2_EVENT_ARC_AXI_ERROR_RESPONSE_0 : - error_count =gaudi2_handle_arc_farm_sei_err (hdev, event_type); + error_count =gaudi2_handle_arc_farm_sei_err (hdev, event_type, &event_mask); event_mask |=HL_NOTIFIER_EVENT_USER_ENGINE_ERR ;break ;
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 9/12 accel/habanalabs: fix standalone preboot descriptor request
In reply to Oded GabbayFrom: farah kassabri <[email protected]>
The preboot used to statically allocate memory for the comms descriptor on the device memory when driver requested the descriptor information. Now preboot moved to dynamic memory allocation where it wants to check the size the driver expects vs. what the f/w expects.
Note there are no backward compatibility issues as older f/w versions simply ignore this value.
--- drivers/accel/habanalabs/common/firmware_if.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/habanalabs/common/firmware_if.c +2 -1
@@ -2743,7 +2743,8 @@ static int hl_fw_dynamic_init_cpu(struct hl_device *hdev,if (!(hdev->fw_components &FW_TYPE_BOOT_CPU )) {struct lkd_fw_binning_info *binning_info; - rc =hl_fw_dynamic_request_descriptor (hdev, fw_loader,0 ); + rc =hl_fw_dynamic_request_descriptor (hdev, fw_loader, +sizeof (struct lkd_msg_comms ));if (rc) goto protocol_err;
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 10/12 accel/habanalabs: print return code when process termination fails
In reply to Oded GabbayFrom: Koby Elbaz <[email protected]>
As part of driver teardown, we attempt to kill all user processes. It shouldn't fail, but if it does we want to print the error code that the kapi returned to us.
--- drivers/accel/habanalabs/common/device.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/accel/habanalabs/common/device.c +4 -3
@@ -1352,7 +1352,8 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, bool* we don't need to kill it. */ dev_dbg (hdev->dev, -"Can't get task struct for user process, assuming process was killed from outside the driver\n" ); +"Can't get task struct for user process %d, assuming process was killed from outside the driver\n" , +pid_nr (hpriv->taskpid)); } }
@@ -2438,14 +2439,14 @@ void hl_device_fini(struct hl_device *hdev) hdev->process_kill_trial_cnt =0 ; rc =device_kill_open_processes (hdev,HL_WAIT_PROCESS_KILL_ON_DEVICE_FINI , false);if (rc) { -dev_crit (hdev->dev,"Failed to kill all open processes\n" ); +dev_crit (hdev->dev,"Failed to kill all open processes (%d)\n" , rc);device_disable_open_processes (hdev, false); } hdev->process_kill_trial_cnt =0 ; rc =device_kill_open_processes (hdev,0 , true);if (rc) { -dev_crit (hdev->dev,"Failed to kill all control device open processes\n" ); +dev_crit (hdev->dev,"Failed to kill all control device open processes (%d)\n" , rc);device_disable_open_processes (hdev, true); }
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 11/12 accel/habanalabs: call put_pid after hpriv list is updated
In reply to Oded GabbayFrom: Koby Elbaz <[email protected]>
Because we might still be using related resources, decrementing PID's reference count should be done at later stages of the device release. A good place is right after the representing private structure is removed from LKD's list.
--- drivers/accel/habanalabs/common/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/accel/habanalabs/common/device.c +2 -2
@@ -408,8 +408,6 @@ static void hpriv_release(struct kref *ref) hdev->asic_funcs->send_device_activity (hdev, false); -put_pid (hpriv->taskpid); -hl_debugfs_remove_file (hpriv);mutex_destroy (&hpriv->ctx_lock);
@@ -448,6 +446,8 @@ static void hpriv_release(struct kref *ref)list_del (&hpriv->dev_node);mutex_unlock (&hdev->fpriv_list_lock); +put_pid (hpriv->taskpid); +if (reset_device) {hl_device_reset (hdev,HL_DRV_RESET_DEV_RELEASE ); }else {
Signature · 1 line
2.40.1
Oded Gabbay
maintainerPATCH 12/12 accel/habanalabs: rename fd_list to hpriv_list
In reply to Oded GabbayFrom: Koby Elbaz <[email protected]>
Every time an FD is returned to the user, the driver adds a corresponding private structure to the list.
Yet, it's still a list of private structures rather than of FDs. Remove, as well, an unnecessary comment.
--- drivers/accel/habanalabs/common/device.c | 43 +++++++++++------------- 1 file changed, 19 insertions(+), 24 deletions(-)
drivers/accel/habanalabs/common/device.c +19 -24
@@ -1304,18 +1304,18 @@ int hl_device_resume(struct hl_device *hdev)static int device_kill_open_processes (struct hl_device *hdev,u32 timeout,bool control_dev) {struct task_struct *task =NULL ; -struct list_head *fd_list; -struct hl_fpriv *hpriv; -struct mutex *fd_lock; +struct list_head *hpriv_list; +struct hl_fpriv *hpriv; +struct mutex *hpriv_lock;u32 pending_cnt; - fd_lock = control_dev ? &hdev->fpriv_ctrl_list_lock : &hdev->fpriv_list_lock; - fd_list = control_dev ? &hdev->fpriv_ctrl_list : &hdev->fpriv_list; + hpriv_lock = control_dev ? &hdev->fpriv_ctrl_list_lock : &hdev->fpriv_list_lock; + hpriv_list = control_dev ? &hdev->fpriv_ctrl_list : &hdev->fpriv_list;/* Giving time for user to close FD, and for processes that are inside * hl_device_open to finish */ -if (!list_empty (fd_list)) +if (!list_empty (hpriv_list))ssleep (1 );if (timeout) {
@@ -1331,12 +1331,12 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, bool } } -mutex_lock (fd_lock); +mutex_lock (hpriv_lock);/* This section must be protected because we are dereferencing * pointers that are freed if the process exits */ -list_for_each_entry (hpriv, fd_list, dev_node) { +list_for_each_entry (hpriv, hpriv_list, dev_node) { task =get_pid_task (hpriv->taskpid,PIDTYPE_PID );if (task) { dev_info(hdev->dev, "Killing user process pid=%d\n",
@@ -1346,18 +1346,13 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, boolput_task_struct (task); }else { -/* -* If we got here, it means that process was killed from outside the driver -* right after it started looping on fd_list and before get_pid_task, thus -* we don't need to kill it. -*/ dev_dbg (hdev->dev, -"Can't get task struct for user process %d, assuming process was killed from outside the driver\n" , +"Can't get task struct for user process %d, process was killed from outside the driver\n" ,pid_nr (hpriv->taskpid)); } } -mutex_unlock (fd_lock); +mutex_unlock (hpriv_lock);/* * We killed the open users, but that doesn't mean they are closed.
@@ -1369,7 +1364,7 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, bool*/ wait_for_processes: -while ((!list_empty (fd_list)) && (pending_cnt)) { +while ((!list_empty (hpriv_list)) && (pending_cnt)) {dev_dbg (hdev->dev,"Waiting for all unmap operations to finish before hard reset\n" );
@@ -1379,7 +1374,7 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, bool }/* All processes exited successfully */ -if (list_empty (fd_list)) +if (list_empty (hpriv_list))return 0 ;/* Give up waiting for processes to exit */
@@ -1393,17 +1388,17 @@ static int device_kill_open_processes(struct hl_device *hdev, u32 timeout, boolstatic void device_disable_open_processes (struct hl_device *hdev,bool control_dev) { -struct list_head *fd_list; +struct list_head *hpriv_list;struct hl_fpriv *hpriv; -struct mutex *fd_lock; +struct mutex *hpriv_lock; - fd_lock = control_dev ? &hdev->fpriv_ctrl_list_lock : &hdev->fpriv_list_lock; - fd_list = control_dev ? &hdev->fpriv_ctrl_list : &hdev->fpriv_list; + hpriv_lock = control_dev ? &hdev->fpriv_ctrl_list_lock : &hdev->fpriv_list_lock; + hpriv_list = control_dev ? &hdev->fpriv_ctrl_list : &hdev->fpriv_list; -mutex_lock (fd_lock); -list_for_each_entry (hpriv, fd_list, dev_node) +mutex_lock (hpriv_lock); +list_for_each_entry (hpriv, hpriv_list, dev_node) hpriv->hdev =NULL ; -mutex_unlock (fd_lock); +mutex_unlock (hpriv_lock); }static void send_disable_pci_access (struct hl_device *hdev,u32 flags)
Signature · 1 line
2.40.1