habanalabs/gaudi: collect undefined opcode error info
PATCH 1/17 habanalabs/gaudi: collect undefined opcode error info
From: Tal Cohen <[email protected]>
when an undefined opcode error occurres, the driver collects the relevant information from the Qman and stores it inside the hdev data structure. An event fd indication is sent towards the user space.
Note: another commit shall be followed which will add support to read the error info by an ioctl.
--- drivers/misc/habanalabs/common/device.c | 13 ++- drivers/misc/habanalabs/common/habanalabs.h | 40 ++++++- .../misc/habanalabs/common/habanalabs_drv.c | 1 + drivers/misc/habanalabs/gaudi/gaudi.c | 108 ++++++++++++++---- include/uapi/misc/habanalabs.h | 8 +- 5 files changed, 138 insertions(+), 32 deletions(-)
drivers/misc/habanalabs/common/device.c +7 -6
@@ -1531,10 +1531,11 @@ int hl_device_reset(struct hl_device *hdev, u32 flags)return rc; } -static void hl_notifier_event_send (struct hl_notifier_event *notifier_event,u64 event) +static void hl_notifier_event_send (struct hl_notifier_event *notifier_event,u64 event_mask) {mutex_lock (¬ifier_event->lock); - notifier_event->events_mask |= event; + notifier_event->events_mask |= event_mask; +if (notifier_event->eventfd)eventfd_signal (notifier_event->eventfd,1 );
@@ -1545,17 +1546,17 @@ static void hl_notifier_event_send(struct hl_notifier_event *notifier_event, u64* hl_notifier_event_send_all - notify all user processes via eventfd * * @hdev: pointer to habanalabs device structure -* @event: the occurred event +* @event_mask: the occurred event/s * Returns 0 for success or an error on failure. */ -void hl_notifier_event_send_all (struct hl_device *hdev,u64 event) +void hl_notifier_event_send_all (struct hl_device *hdev,u64 event_mask) {struct hl_fpriv *hpriv;mutex_lock (&hdev->fpriv_list_lock);list_for_each_entry (hpriv, &hdev->fpriv_list, dev_node) -hl_notifier_event_send (&hpriv->notifier_event, event); +hl_notifier_event_send (&hpriv->notifier_event, event_mask);mutex_unlock (&hdev->fpriv_list_lock);
@@ -1563,7 +1564,7 @@ void hl_notifier_event_send_all(struct hl_device *hdev, u64 event)mutex_lock (&hdev->fpriv_ctrl_list_lock);list_for_each_entry (hpriv, &hdev->fpriv_ctrl_list, dev_node) -hl_notifier_event_send (&hpriv->notifier_event, event); +hl_notifier_event_send (&hpriv->notifier_event, event_mask);mutex_unlock (&hdev->fpriv_ctrl_list_lock); }
drivers/misc/habanalabs/common/habanalabs.h +37 -3
@@ -2644,14 +2644,48 @@ struct razwi_info {u8 type; }; +#define MAX_QMAN_STREAMS_INFO 4 +#define OPCODE_INFO_MAX_ADDR_SIZE 8 +/** +* struct undefined_opcode_info - info about last undefined opcode error +* @timestamp: timestamp of the undefined opcode error +* @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ +* entiers. In case all streams array entries are +* filled with values, it means the execution was in Lower-CP. +* @cq_addr: the address of the current handled command buffer +* @cq_size: the size of the current handled command buffer +* @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array. +* should be equal to 1 incase of undefined opcode +* in Upper-CP (specific stream) and equal to 4 incase +* of undefined opcode in Lower-CP. +* @engine_id: engine-id that the error occurred on +* @stream_id: the stream id the error occurred on. In case the stream equals to +* MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP. +* @write_enable: if set, writing to undefined opcode parameters in the structure +* is enable so the first (root cause) undefined opcode will not be +* overwritten. +*/ +struct undefined_opcode_info { +ktime_t timestamp; +u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO ][OPCODE_INFO_MAX_ADDR_SIZE ]; +u64 cq_addr; +u32 cq_size; +u32 cb_addr_streams_len; +u32 engine_id; +u32 stream_id; +bool write_enable; +}; +/** * struct last_error_session_info - info about last session errors occurred. * @cs_timeout: CS timeout error last information. * @razwi: razwi last information. +* @undef_opcode: undefined opcode information */ struct last_error_session_info { -struct cs_timeout_info cs_timeout; -struct razwi_info razwi; +struct cs_timeout_info cs_timeout; +struct razwi_info razwi; +struct undefined_opcode_info undef_opcode; };/**
@@ -3159,7 +3193,7 @@ int hl_device_utilization(struct hl_device *hdev, u32 *utilization);int hl_build_hwmon_channel_info (struct hl_device *hdev,struct cpucp_sensor *sensors_arr); -void hl_notifier_event_send_all (struct hl_device *hdev,u64 event); +void hl_notifier_event_send_all (struct hl_device *hdev,u64 event_mask);int hl_sysfs_init (struct hl_device *hdev);void hl_sysfs_fini (struct hl_device *hdev);
drivers/misc/habanalabs/common/habanalabs_drv.c +1 -0
@@ -198,6 +198,7 @@ int hl_device_open(struct inode *inode, struct file *filp)atomic_set (&hdev->last_error.cs_timeout.write_enable,1 );atomic_set (&hdev->last_error.razwi.write_enable,1 ); + hdev->last_error.undef_opcode.write_enable = true; hdev->open_counter++; hdev->last_successful_open_jif = jiffies;
drivers/misc/habanalabs/gaudi/gaudi.c +87 -21
218 lines not on this page · raw message
include/uapi/misc/habanalabs.h +6 -2
@@ -1402,9 +1402,13 @@ struct hl_debug_args {/* * Notifier event values - for the notification mechanism and the HL_INFO_GET_EVENTS command * -* HL_NOTIFIER_EVENT_TPC_ASSERT - Indicates TPC assert event +* HL_NOTIFIER_EVENT_TPC_ASSERT - Indicates TPC assert event +* HL_NOTIFIER_EVENT_UNDEFINED_OPCODE - Indicates undefined operation code +* HL_NOTIFIER_EVENT_DEVICE_RESET - Indicates device requires a reset */ -#define HL_NOTIFIER_EVENT_TPC_ASSERT (1 << 0) +#define HL_NOTIFIER_EVENT_TPC_ASSERT (1ULL << 0) +#define HL_NOTIFIER_EVENT_UNDEFINED_OPCODE (1ULL << 1) +#define HL_NOTIFIER_EVENT_DEVICE_RESET (1ULL << 2)/* * Various information operations such as:
Signature · 1 line
2.25.1
PATCH 2/17 habanalabs: expose undefined opcode status via info ioctl
From: Tal Cohen <[email protected]>
The info ioctl retrieves information on the last undefined opcode occurred.
--- .../misc/habanalabs/common/habanalabs_ioctl.c | 25 ++++++++++++++++ include/uapi/misc/habanalabs.h | 30 +++++++++++++++++++ 2 files changed, 55 insertions(+)
drivers/misc/habanalabs/common/habanalabs_ioctl.c +25 -0
@@ -610,6 +610,28 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args)return copy_to_user (out, &info,min_t (size_t, max_size,sizeof (info))) ? -EFAULT :0 ; } +static int undefined_opcode_info (struct hl_fpriv *hpriv,struct hl_info_args *args) +{ +struct hl_device *hdev = hpriv->hdev; +u32 max_size = args->return_size; +struct hl_info_undefined_opcode_event info = {0 }; +void __user *out = (void __user *) (uintptr_t ) args->return_pointer; + +if ((!max_size) || (!out)) +return -EINVAL ; + + info.timestamp =ktime_to_ns (hdev->last_error.undef_opcode.timestamp); + info.engine_id = hdev->last_error.undef_opcode.engine_id; + info.cq_addr = hdev->last_error.undef_opcode.cq_addr; + info.cq_size = hdev->last_error.undef_opcode.cq_size; + info.stream_id = hdev->last_error.undef_opcode.stream_id; + info.cb_addr_streams_len = hdev->last_error.undef_opcode.cb_addr_streams_len; +memcpy (info.cb_addr_streams, hdev->last_error.undef_opcode.cb_addr_streams, +sizeof (info.cb_addr_streams)); + +return copy_to_user (out, &info,min_t (size_t, max_size,sizeof (info))) ? -EFAULT :0 ; +} +static int dev_mem_alloc_page_sizes_info (struct hl_fpriv *hpriv,struct hl_info_args *args) {void __user *out = (void __user *) (uintptr_t ) args->return_pointer;
@@ -718,6 +740,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,case HL_INFO_RAZWI_EVENT :return razwi_info (hpriv, args); +case HL_INFO_UNDEFINED_OPCODE_EVENT : +return undefined_opcode_info (hpriv, args); +case HL_INFO_DEV_MEM_ALLOC_PAGE_SIZES :return dev_mem_alloc_page_sizes_info (hpriv, args);
include/uapi/misc/habanalabs.h +30 -0
@@ -352,6 +352,7 @@ enum hl_server_type {* HL_INFO_REGISTER_EVENTFD - Register eventfd for event notifications. * HL_INFO_UNREGISTER_EVENTFD - Unregister eventfd * HL_INFO_GET_EVENTS - Retrieve the last occurred events +* HL_INFO_UNDEFINED_OPCODE_EVENT - Retrieve last undefined opcode error information. */ #define HL_INFO_HW_IP_INFO 0#define HL_INFO_HW_EVENTS 1
@@ -380,6 +381,7 @@ enum hl_server_type {#define HL_INFO_REGISTER_EVENTFD 28#define HL_INFO_UNREGISTER_EVENTFD 29#define HL_INFO_GET_EVENTS 30 +#define HL_INFO_UNDEFINED_OPCODE_EVENT 31#define HL_INFO_VERSION_MAX_LEN 128#define HL_INFO_CARD_NAME_MAX_LEN 16
@@ -656,6 +658,34 @@ struct hl_info_razwi_event {__u8 pad[2 ]; }; +#define MAX_QMAN_STREAMS_INFO 4 +#define OPCODE_INFO_MAX_ADDR_SIZE 8 +/** +* struct hl_info_undefined_opcode_event - info about last undefined opcode error +* @timestamp: timestamp of the undefined opcode error +* @cb_addr_streams: CB addresses (per stream) that are currently exists in the PQ +* entiers. In case all streams array entries are +* filled with values, it means the execution was in Lower-CP. +* @cq_addr: the address of the current handled command buffer +* @cq_size: the size of the current handled command buffer +* @cb_addr_streams_len: num of streams - actual len of cb_addr_streams array. +* should be equal to 1 incase of undefined opcode +* in Upper-CP (specific stream) and equal to 4 incase +* of undefined opcode in Lower-CP. +* @engine_id: engine-id that the error occurred on +* @stream_id: the stream id the error occurred on. In case the stream equals to +* MAX_QMAN_STREAMS_INFO it means the error occurred on a Lower-CP. +*/ +struct hl_info_undefined_opcode_event { +__s64 timestamp; +__u64 cb_addr_streams[MAX_QMAN_STREAMS_INFO ][OPCODE_INFO_MAX_ADDR_SIZE ]; +__u64 cq_addr; +__u32 cq_size; +__u32 cb_addr_streams_len; +__u32 engine_id; +__u32 stream_id; +}; +/** * struct hl_info_dev_memalloc_page_sizes - valid page sizes in device mem alloc information. * @page_order_bitmask: bitmap in which a set bit represents the order of the supported page size
Signature · 1 line
2.25.1
PATCH 3/17 habanalabs/gaudi: invoke device reset from one code block
In reply to Oded GabbayFrom: Tal Cohen <[email protected]>
In order to prepare the driver code for device reset event notification, change the event handler function flow to call device reset from one code block.
In addition, the commit fixes an issue that reset was performed w/o checking the 'hard_reset_on_fw_event' state and w/o setting the HL_DRV_RESET_DELAY flag.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +16 -9
@@ -7795,10 +7795,10 @@ static void gaudi_handle_eqe(struct hl_device *hdev,struct gaudi_device *gaudi = hdev->asic_specific;u64 data =le64_to_cpu (eq_entry->data[0 ]), event_mask =0 ;u32 ctl =le32_to_cpu (eq_entry->hdr.ctl); -u32 fw_fatal_err_flag =0 ; +u32 fw_fatal_err_flag =0 , flags =0 ;u16 event_type = ((ctl &EQ_CTL_EVENT_TYPE_MASK ) >>EQ_CTL_EVENT_TYPE_SHIFT ); -bool reset_required; +bool reset_required, reset_direct = false;u8 cause;int rc;
@@ -7886,7 +7886,8 @@ static void gaudi_handle_eqe(struct hl_device *hdev,dev_err (hdev->dev,"reset required due to %s\n" , gaudi_irq_map_table[event_type].name); -hl_device_reset (hdev,0 ); + reset_direct = true; + goto reset_device; }else {hl_fw_unmask_irq (hdev, event_type); }
@@ -7908,7 +7909,8 @@ static void gaudi_handle_eqe(struct hl_device *hdev,dev_err (hdev->dev,"reset required due to %s\n" , gaudi_irq_map_table[event_type].name); -hl_device_reset (hdev,0 ); + reset_direct = true; + goto reset_device; }else {hl_fw_unmask_irq (hdev, event_type); }
@@ -8050,12 +8052,17 @@ static void gaudi_handle_eqe(struct hl_device *hdev,return ; reset_device: -if (hdev->asic_prop.fw_security_enabled) -hl_device_reset (hdev,HL_DRV_RESET_HARD - |HL_DRV_RESET_BYPASS_REQ_TO_FW - | fw_fatal_err_flag); + reset_required = true; + +if (hdev->asic_prop.fw_security_enabled && !reset_direct) + flags =HL_DRV_RESET_HARD |HL_DRV_RESET_BYPASS_REQ_TO_FW | fw_fatal_err_flag;else if (hdev->hard_reset_on_fw_events) -hl_device_reset (hdev,HL_DRV_RESET_HARD |HL_DRV_RESET_DELAY | fw_fatal_err_flag); + flags =HL_DRV_RESET_HARD |HL_DRV_RESET_DELAY | fw_fatal_err_flag; +else + reset_required = false; + +if (reset_required) +hl_device_reset (hdev, flags);else hl_fw_unmask_irq (hdev, event_type); }
Signature · 1 line
2.25.1
PATCH 4/17 habanalabs/gaudi: send device reset notification
In reply to Oded GabbayFrom: Tal Cohen <[email protected]>
Device reset event, indicates that the device shall be reset - after a short delay. In such case, the driver sends a notification towards the User process. This allows the User process to be able to take several debug actions for system diagnostic purposes.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +10 -3
@@ -8054,13 +8054,20 @@ static void gaudi_handle_eqe(struct hl_device *hdev, reset_device: reset_required = true; -if (hdev->asic_prop.fw_security_enabled && !reset_direct) +if (hdev->asic_prop.fw_security_enabled && !reset_direct) { flags =HL_DRV_RESET_HARD |HL_DRV_RESET_BYPASS_REQ_TO_FW | fw_fatal_err_flag; -else if (hdev->hard_reset_on_fw_events) + event_mask |=HL_NOTIFIER_EVENT_DEVICE_RESET ; + }else if (hdev->hard_reset_on_fw_events) { flags =HL_DRV_RESET_HARD |HL_DRV_RESET_DELAY | fw_fatal_err_flag; -else + event_mask |=HL_NOTIFIER_EVENT_DEVICE_RESET ; + }else { reset_required = false; + } +/* despite reset doesn't execute. a notification on +* occurred event needs to be sent here +*/ +hl_notifier_event_send_all (hdev, event_mask);if (reset_required)hl_device_reset (hdev, flags);else
Signature · 1 line
2.25.1
PATCH 5/17 habanalabs: send an event notification when CS timeout occurs
In reply to Oded GabbayFrom: Tal Cohen <[email protected]>
The Driver needs to inform the User process whenever one of its CS is timed out. The Driver shall recognize the CS timeout and shall send an eventfd notification, towards user space, whenever a timeout is expired on a CS.
--- .../habanalabs/common/command_submission.c | 26 ++++++++++++------- include/uapi/misc/habanalabs.h | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +17 -9
@@ -797,10 +797,11 @@ static void cs_do_release(struct kref *ref)static void cs_timedout (struct work_struct *work) {struct hl_device *hdev; +u64 event_mask;int rc; struct hl_cs *cs = container_of(work, struct hl_cs, work_tdr.work); -bool skip_reset_on_timeout = cs->skip_reset_on_timeout; +bool skip_reset_on_timeout = cs->skip_reset_on_timeout, device_reset = false; rc =cs_get_unless_zero (cs);if (!rc)
@@ -811,9 +812,15 @@ static void cs_timedout(struct work_struct *work)return ; } -/* Mark the CS is timed out so we won't try to cancel its TDR */ -if (likely (!skip_reset_on_timeout)) +if (likely (!skip_reset_on_timeout)) { +if (hdev->reset_on_lockup) + device_reset = true; +else + hdev->reset_info.needs_reset = true; + +/* Mark the CS is timed out so we won't try to cancel its TDR */ cs->timedout = true; + } hdev = cs->ctx->hdev;
@@ -822,6 +829,11 @@ static void cs_timedout(struct work_struct *work)if (rc) { hdev->last_error.cs_timeout.timestamp =ktime_get (); hdev->last_error.cs_timeout.seq = cs->sequence; + + event_mask = device_reset ? (HL_NOTIFIER_EVENT_CS_TIMEOUT | +HL_NOTIFIER_EVENT_DEVICE_RESET ) :HL_NOTIFIER_EVENT_CS_TIMEOUT ; + +hl_notifier_event_send_all (hdev, event_mask); }switch (cs->type) {
@@ -856,12 +868,8 @@ static void cs_timedout(struct work_struct *work)cs_put (cs); -if (likely (!skip_reset_on_timeout)) { -if (hdev->reset_on_lockup) -hl_device_reset (hdev,HL_DRV_RESET_TDR ); -else - hdev->reset_info.needs_reset = true; - } +if (device_reset) +hl_device_reset (hdev,HL_DRV_RESET_TDR ); } static int allocate_cs(struct hl_device *hdev, struct hl_ctx *ctx,
include/uapi/misc/habanalabs.h +2 -0
@@ -1435,10 +1435,12 @@ struct hl_debug_args {* HL_NOTIFIER_EVENT_TPC_ASSERT - Indicates TPC assert event * HL_NOTIFIER_EVENT_UNDEFINED_OPCODE - Indicates undefined operation code * HL_NOTIFIER_EVENT_DEVICE_RESET - Indicates device requires a reset +* HL_NOTIFIER_EVENT_CS_TIMEOUT - Indicates CS timeout error */ #define HL_NOTIFIER_EVENT_TPC_ASSERT (1ULL << 0)#define HL_NOTIFIER_EVENT_UNDEFINED_OPCODE (1ULL << 1)#define HL_NOTIFIER_EVENT_DEVICE_RESET (1ULL << 2) +#define HL_NOTIFIER_EVENT_CS_TIMEOUT (1ULL << 3)/* * Various information operations such as:
Signature · 1 line
2.25.1
PATCH 6/17 habanalabs: avoid unnecessary error print
In reply to Oded GabbayFrom: Dani Liberman <[email protected]>
When sending a packet to FW right after it made reset, we will get packet timeout. Since it is expected behavior, we don't need to print an error in such case.
Hence, when driver is in hard reset it will avoid from printing error messages about packet timeout.
--- drivers/misc/habanalabs/common/firmware_if.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/common/firmware_if.c +8 -1
@@ -267,7 +267,14 @@ int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,hl_hw_queue_inc_ci_kernel (hdev, hw_queue_id);if (rc == -ETIMEDOUT ) { -dev_err (hdev->dev,"Device CPU packet timeout (0x%x)\n" , tmp); +/* If FW performed reset just before sending it a packet, we will get a timeout. +* This is expected behavior, hence no need for error message. +*/ +if (!hl_device_operational (hdev,NULL ) && !hdev->reset_info.is_in_soft_reset) +dev_dbg (hdev->dev,"Device CPU packet timeout (0x%x) due to FW reset\n" , + tmp); +else +dev_err (hdev->dev,"Device CPU packet timeout (0x%x)\n" , tmp); hdev->device_cpu_disabled = true; goto out; }
Signature · 1 line
2.25.1
PATCH 7/17 habanalabs/gaudi: fix incorrect MME offset calculation
In reply to Oded GabbayFrom: Koby Elbaz <[email protected]>
Once FW raised an event following a MME2 QMAN error, the driver should have gone to the corresponding status registers, trying to gather more info on the error, yet it was accidentally accessing MME1 QMAN address space.
Generally, we have x4 MMEs, while 0 & 2 are marked MASTER, and 1 & 3 are marked SLAVE. The former can be addressed, yet addressing the latter is considered an access violation, and will result in a hung system, which is what unintentionally happened above. Note that this cannot happen in a secured system, since these registers are protected with range registers.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +8 -3
@@ -454,7 +454,7 @@ static const int gaudi_queue_id_to_engine_id[] = { [GAUDI_QUEUE_ID_DMA_6_0...GAUDI_QUEUE_ID_DMA_6_3] = GAUDI_ENGINE_ID_DMA_6, [GAUDI_QUEUE_ID_DMA_7_0...GAUDI_QUEUE_ID_DMA_7_3] = GAUDI_ENGINE_ID_DMA_7, [GAUDI_QUEUE_ID_MME_0_0...GAUDI_QUEUE_ID_MME_0_3] = GAUDI_ENGINE_ID_MME_0, - [GAUDI_QUEUE_ID_MME_1_0...GAUDI_QUEUE_ID_MME_1_3] = GAUDI_ENGINE_ID_MME_1, + [GAUDI_QUEUE_ID_MME_1_0...GAUDI_QUEUE_ID_MME_1_3] = GAUDI_ENGINE_ID_MME_2, [GAUDI_QUEUE_ID_TPC_0_0...GAUDI_QUEUE_ID_TPC_0_3] = GAUDI_ENGINE_ID_TPC_0, [GAUDI_QUEUE_ID_TPC_1_0...GAUDI_QUEUE_ID_TPC_1_3] = GAUDI_ENGINE_ID_TPC_1, [GAUDI_QUEUE_ID_TPC_2_0...GAUDI_QUEUE_ID_TPC_2_3] = GAUDI_ENGINE_ID_TPC_2,
@@ -7383,8 +7383,13 @@ static void gaudi_handle_qman_err(struct hl_device *hdev, u16 event_type, u64 *esnprintf (desc,ARRAY_SIZE (desc),"%s%d" ,"TPC_QM" , index);break ; case GAUDI_EVENT_MME0_QM ... GAUDI_EVENT_MME2_QM: - index = event_type -GAUDI_EVENT_MME0_QM ; - qid_base =GAUDI_QUEUE_ID_MME_0_0 + index *QMAN_STREAMS ; +if (event_type ==GAUDI_EVENT_MME0_QM ) { + index =0 ; + qid_base =GAUDI_QUEUE_ID_MME_0_0 ; + }else if (event_type ==GAUDI_EVENT_MME2_QM ) { + index =2 ; + qid_base =GAUDI_QUEUE_ID_MME_1_0 ; + } qman_base = mmMME0_QM_BASE + index *MME_QMAN_OFFSET ;snprintf (desc,ARRAY_SIZE (desc),"%s%d" ,"MME_QM" , index);break ;
Signature · 1 line
2.25.1
PATCH 8/17 habanalabs: add validity check for cq counter offset
In reply to Oded GabbayFrom: farah kassabri <[email protected]>
Driver performs no validity check for the user cq counter offset used in both wait_for_interrupt and register_for_timestamp APIs.
--- drivers/misc/habanalabs/common/command_submission.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/common/command_submission.c +8 -1
@@ -2979,7 +2979,7 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf,u64 current_cq_counter;/* Validate ts_offset not exceeding last max */ -if (requested_offset_record > cb_last) { +if (requested_offset_record >= cb_last) {dev_err (buf->mmg->dev,"Ts offset exceeds max CB offset(0x%llx)\n" , (u64 )(uintptr_t )cb_last);return -EINVAL ;
@@ -3064,6 +3064,13 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, goto put_ctx; } +/* Validate the cq offset */ +if (((u64 *) cq_cb->kernel_address + cq_counters_offset) >= + ((u64 *) cq_cb->kernel_address + (cq_cb->size /sizeof (u64)))) { + rc = -EINVAL ; + goto put_cq_cb; + } +if (register_ts_record) {dev_dbg (hdev->dev,"Timestamp registration: interrupt id: %u, ts offset: %llu, cq_offset: %llu\n" , interrupt->interrupt_id, ts_offset, cq_counters_offset);
Signature · 1 line
2.25.1
PATCH 9/17 habanalabs/gaudi: fix shift out of bounds
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
When validating NIC queues, queue offset calculation must be performed only for NIC queues.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +9 -7
@@ -5692,15 +5692,17 @@ static int gaudi_parse_cb_no_ext_queue(struct hl_device *hdev, {struct asic_fixed_properties *asic_prop = &hdev->asic_prop;struct gaudi_device *gaudi = hdev->asic_specific; -u32 nic_mask_q_id =1 << (HW_CAP_NIC_SHIFT + - ((parser->hw_queue_id -GAUDI_QUEUE_ID_NIC_0_0 ) >>2 )); +u32 nic_queue_offset, nic_mask_q_id;if ((parser->hw_queue_id >=GAUDI_QUEUE_ID_NIC_0_0 ) && - (parser->hw_queue_id <=GAUDI_QUEUE_ID_NIC_9_3 ) && - (!(gaudi->hw_cap_initialized & nic_mask_q_id))) { -dev_err (hdev->dev,"h/w queue %d is disabled\n" , - parser->hw_queue_id); -return -EINVAL ; + (parser->hw_queue_id <=GAUDI_QUEUE_ID_NIC_9_3 )) { + nic_queue_offset = parser->hw_queue_id -GAUDI_QUEUE_ID_NIC_0_0 ; + nic_mask_q_id =1 << (HW_CAP_NIC_SHIFT + (nic_queue_offset >>2 )); + +if (!(gaudi->hw_cap_initialized & nic_mask_q_id)) { +dev_err (hdev->dev,"h/w queue %d is disabled\n" , parser->hw_queue_id); +return -EINVAL ; + } }/* For internal queue jobs just check if CB address is valid */
Signature · 1 line
2.25.1
PATCH 10/17 habanalabs: fix NULL dereference on cs timeout
In reply to Oded GabbayFrom: Yuri Nudelman <[email protected]>
Device descriptor is accessed before an assignment
--- drivers/misc/habanalabs/common/command_submission.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
@@ -812,6 +812,8 @@ static void cs_timedout(struct work_struct *work)return ; } + hdev = cs->ctx->hdev; +if (likely (!skip_reset_on_timeout)) {if (hdev->reset_on_lockup) device_reset = true;
@@ -822,8 +824,6 @@ static void cs_timedout(struct work_struct *work) cs->timedout = true; } - hdev = cs->ctx->hdev; -/* Save only the first CS timeout parameters */ rc =atomic_cmpxchg (&hdev->last_error.cs_timeout.write_enable,1 ,0 );if (rc) {
Signature · 1 line
2.25.1
PATCH 11/17 habanalabs: remove unused get_dma_desc_list_size
In reply to Oded GabbayThis asic callback function is not called anymore from the common code. The asic-specific function itself is called but from within the asic-specific code.
--- drivers/misc/habanalabs/common/habanalabs.h | 3 --- drivers/misc/habanalabs/gaudi/gaudi.c | 1 - drivers/misc/habanalabs/goya/goya.c | 1 - 3 files changed, 5 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +0 -3
@@ -1260,7 +1260,6 @@ struct fw_load_mgr {* @hl_dma_unmap_sgtable: DMA unmap scatter-gather table. * @cs_parser: parse Command Submission. * @asic_dma_map_sgtable: DMA map scatter-gather table. -* @get_dma_desc_list_size: get number of LIN_DMA packets required for CB. * @add_end_of_cb_packets: Add packets to the end of CB, if device requires it. * @update_eq_ci: update event queue CI. * @context_switch: called upon ASID context switch.
@@ -1379,8 +1378,6 @@ struct hl_asic_funcs {int (*cs_parser)(struct hl_device *hdev,struct hl_cs_parser *parser);int (*asic_dma_map_sgtable)(struct hl_device *hdev,struct sg_table *sgt,enum dma_data_direction dir); -u32 (*get_dma_desc_list_size)(struct hl_device *hdev, -struct sg_table *sgt); void (*add_end_of_cb_packets)(struct hl_device *hdev, void *kernel_address, u32 len, u64 cq_addr, u32 cq_val, u32 msix_num,
drivers/misc/habanalabs/gaudi/gaudi.c +0 -1
@@ -9315,7 +9315,6 @@ static const struct hl_asic_funcs gaudi_funcs = { .hl_dma_unmap_sgtable = hl_dma_unmap_sgtable, .cs_parser = gaudi_cs_parser, .asic_dma_map_sgtable = hl_dma_map_sgtable, - .get_dma_desc_list_size = gaudi_get_dma_desc_list_size, .add_end_of_cb_packets = gaudi_add_end_of_cb_packets, .update_eq_ci = gaudi_update_eq_ci, .context_switch = gaudi_context_switch,
drivers/misc/habanalabs/goya/goya.c +0 -1
@@ -5461,7 +5461,6 @@ static const struct hl_asic_funcs goya_funcs = { .hl_dma_unmap_sgtable = hl_dma_unmap_sgtable, .cs_parser = goya_cs_parser, .asic_dma_map_sgtable = hl_dma_map_sgtable, - .get_dma_desc_list_size = goya_get_dma_desc_list_size, .add_end_of_cb_packets = goya_add_end_of_cb_packets, .update_eq_ci = goya_update_eq_ci, .context_switch = goya_context_switch,
Signature · 1 line
2.25.1
PATCH 12/17 habanalabs/gaudi: notify user process on device unavailable
In reply to Oded GabbayFrom: Tal Cohen <[email protected]>
When a device error occurs, user process would like to get some indication on the error by reading some device HW info. If the device is unavailable, user process can't perform any HW device reading.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 5 ++++- include/uapi/misc/habanalabs.h | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +4 -1
@@ -8063,7 +8063,10 @@ static void gaudi_handle_eqe(struct hl_device *hdev,if (hdev->asic_prop.fw_security_enabled && !reset_direct) { flags =HL_DRV_RESET_HARD |HL_DRV_RESET_BYPASS_REQ_TO_FW | fw_fatal_err_flag; - event_mask |=HL_NOTIFIER_EVENT_DEVICE_RESET ; + +/* notify on device unavailable while the reset triggered by fw */ + event_mask |= (HL_NOTIFIER_EVENT_DEVICE_RESET | +HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE ); }else if (hdev->hard_reset_on_fw_events) { flags =HL_DRV_RESET_HARD |HL_DRV_RESET_DELAY | fw_fatal_err_flag; event_mask |=HL_NOTIFIER_EVENT_DEVICE_RESET ;
include/uapi/misc/habanalabs.h +7 -5
@@ -1432,15 +1432,17 @@ struct hl_debug_args {/* * Notifier event values - for the notification mechanism and the HL_INFO_GET_EVENTS command * -* HL_NOTIFIER_EVENT_TPC_ASSERT - Indicates TPC assert event -* HL_NOTIFIER_EVENT_UNDEFINED_OPCODE - Indicates undefined operation code -* HL_NOTIFIER_EVENT_DEVICE_RESET - Indicates device requires a reset -* HL_NOTIFIER_EVENT_CS_TIMEOUT - Indicates CS timeout error +* HL_NOTIFIER_EVENT_TPC_ASSERT - Indicates TPC assert event +* HL_NOTIFIER_EVENT_UNDEFINED_OPCODE - Indicates undefined operation code +* HL_NOTIFIER_EVENT_DEVICE_RESET - Indicates device requires a reset +* HL_NOTIFIER_EVENT_CS_TIMEOUT - Indicates CS timeout error +* HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE - Indicates device is unavailable */ #define HL_NOTIFIER_EVENT_TPC_ASSERT (1ULL << 0)#define HL_NOTIFIER_EVENT_UNDEFINED_OPCODE (1ULL << 1)#define HL_NOTIFIER_EVENT_DEVICE_RESET (1ULL << 2) -#define HL_NOTIFIER_EVENT_CS_TIMEOUT (1ULL << 3) +#define HL_NOTIFIER_EVENT_CS_TIMEOUT (1ULL << 3) +#define HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE (1ULL << 4)/* * Various information operations such as:
Signature · 1 line
2.25.1
PATCH 13/17 habanalabs: add critical indication in sram ecc
In reply to Oded GabbayFrom: ran shalit <[email protected]>
Multiple SRAM SERR events are treated as critical events, and host should be notified about it. Thus, adding is_critical indication as part of SRAM ECC failure packet.
--- drivers/misc/habanalabs/include/common/cpucp_if.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/include/common/cpucp_if.h +2 -1
@@ -68,7 +68,8 @@ struct hl_eq_ecc_data {__le64 ecc_address;__le64 ecc_syndrom;__u8 memory_wrapper_idx; -__u8 pad[7 ]; +__u8 is_critical; +__u8 pad[6 ]; };enum hl_sm_sei_cause {
Signature · 1 line
2.25.1
PATCH 14/17 habanalabs: check fence pointer before use
In reply to Oded Gabbayfence pointer can be NULL in this path, as shown by an earlier check.
--- drivers/misc/habanalabs/common/command_submission.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/command_submission.c +1 -1
@@ -2581,7 +2581,7 @@ static int hl_cs_poll_fences(struct multi_cs_data *mcs_data, struct multi_cs_com* For this we have to validate that the timestamp is * earliest of all timestamps so far. */ -if (mcs_data->update_ts && +if (fence && mcs_data->update_ts && (ktime_compare (fence->timestamp, first_cs_time) <0 )) first_cs_time = fence->timestamp;break ;
Signature · 1 line
2.25.1
PATCH 15/17 habanalabs: print pointer with correct modifier
In reply to Oded GabbayUse %p instead of %llx for printing pointers.
--- drivers/misc/habanalabs/common/command_submission.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
@@ -3035,8 +3035,8 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, *pend = requested_offset_record; -dev_dbg (buf->mmg->dev,"Found available node in TS kernel CB(0x%llx)\n" , - (u64 )(uintptr_t )requested_offset_record); +dev_dbg (buf->mmg->dev,"Found available node in TS kernel CB %p\n" , + requested_offset_record);return 0 ; }
Signature · 1 line
2.25.1
PATCH 16/17 habanalabs: use kvcalloc when possible
In reply to Oded Gabbaykvcalloc is same as kvmalloc_array with GFP_ZERO.
--- drivers/misc/habanalabs/common/mmu/mmu_v1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/common/mmu/mmu_v1.c +2 -3
@@ -393,9 +393,8 @@ static int hl_mmu_v1_init(struct hl_device *hdev) goto err_pool_add; } - hdev->mmu_priv.dr.mmu_shadow_hop0 =kvmalloc_array (prop->max_asid, - prop->mmu_hop_table_size, -GFP_KERNEL | __GFP_ZERO); + hdev->mmu_priv.dr.mmu_shadow_hop0 =kvcalloc (prop->max_asid, prop->mmu_hop_table_size, +GFP_KERNEL );if (ZERO_OR_NULL_PTR (hdev->mmu_priv.dr.mmu_shadow_hop0)) { rc = -ENOMEM ; goto err_pool_add;
Signature · 1 line
2.25.1
PATCH 17/17 habanalabs: fix comment style
In reply to Oded Gabbayfunction name should not be preceded with @
--- drivers/misc/habanalabs/common/memory_mgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/memory_mgr.c +1 -1
@@ -135,7 +135,7 @@ int hl_mmap_mem_buf_put_handle(struct hl_mem_mgr *mmg, u64 handle) }/** -* @hl_mmap_mem_buf_alloc - allocate a new mappable buffer +* hl_mmap_mem_buf_alloc - allocate a new mappable buffer * * @mmg: parent unifed memory manager * @behavior: behavior object describing this buffer polymorphic behavior
Signature · 1 line
2.25.1