habanalabs/gaudi2: change device f/w security check
PATCH 1/6 habanalabs/gaudi2: change device f/w security check
From: farah kassabri <[email protected]>
On Gaudi2 the f/w always configures the PCIe iATU and allows access to scratchpad registers. Therefore, we can know if the f/w is secured by reading a status bit from the f/w registers.
--- drivers/misc/habanalabs/common/firmware_if.c | 2 ++ drivers/misc/habanalabs/gaudi2/gaudi2.c | 21 ++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +2 -0
@@ -1476,6 +1476,8 @@ static void hl_fw_preboot_update_state(struct hl_device *hdev)*/ prop->hard_reset_done_by_fw = !!(cpu_boot_dev_sts0 &CPU_BOOT_DEV_STS0_FW_HARD_RST_EN ); + prop->fw_security_enabled = !!(cpu_boot_dev_sts0 &CPU_BOOT_DEV_STS0_SECURITY_EN ); +dev_dbg (hdev->dev,"Firmware preboot boot device status0 %#x\n" , cpu_boot_dev_sts0);
drivers/misc/habanalabs/gaudi2/gaudi2.c +6 -15
@@ -2493,7 +2493,6 @@ static int gaudi2_early_init(struct hl_device *hdev)struct asic_fixed_properties *prop = &hdev->asic_prop;struct pci_dev *pdev = hdev->pdev;resource_size_t pci_bar_size; -u32 fw_boot_status;int rc; rc =gaudi2_set_fixed_properties (hdev);
@@ -2521,22 +2520,14 @@ static int gaudi2_early_init(struct hl_device *hdev) prop->dram_pci_bar_size =pci_resource_len (pdev,DRAM_BAR_ID ); hdev->dram_pci_bar_start =pci_resource_start (pdev,DRAM_BAR_ID ); -/* If FW security is enabled at this point it means no access to ELBI */ -if (hdev->asic_prop.fw_security_enabled) { - hdev->asic_prop.iatu_done_by_fw = true; - goto pci_init; - } - - rc =hl_pci_elbi_read (hdev,CFG_BASE + mmCPU_BOOT_DEV_STS0, &fw_boot_status); -if (rc) - goto free_queue_props; - -/* Check whether FW is configuring iATU */ -if ((fw_boot_status &CPU_BOOT_DEV_STS0_ENABLED ) && - (fw_boot_status &CPU_BOOT_DEV_STS0_FW_IATU_CONF_EN )) +/* +* Only in pldm driver config iATU +*/ +if (hdev->pldm) + hdev->asic_prop.iatu_done_by_fw = false; +else hdev->asic_prop.iatu_done_by_fw = true; -pci_init: rc =hl_pci_init (hdev);if (rc) goto free_queue_props;
Signature · 1 line
2.25.1
PATCH 2/6 habanalabs: remove left-over code from bring-up
There is some left-over code from the gaudi2 bring-up that wasn't removed so far.
--- drivers/misc/habanalabs/common/firmware_if.c | 20 ------------- .../habanalabs/include/common/hl_boot_if.h | 28 ++++++++++++++----- 2 files changed, 21 insertions(+), 27 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +0 -20
@@ -15,14 +15,6 @@#define FW_FILE_MAX_SIZE 0x1400000/* maximum size of 20MB */ -struct fw_binning_conf { -u64 tpc_binning; -u32 dec_binning; -u32 hbm_binning; -u32 edma_binning; -u32 mme_redundancy; -}; -static char *extract_fw_ver_from_str (const char *fw_str) {char *str, *fw_ver, *whitespace;
@@ -2424,18 +2416,6 @@ static int hl_fw_dynamic_send_msg(struct hl_device *hdev, msg.reset_cause = *(__u8 *) data;break ; -case HL_COMMS_BINNING_CONF_TYPE : - { -struct fw_binning_conf *binning_conf = (struct fw_binning_conf *) data; - - msg.tpc_binning_conf =cpu_to_le64 (binning_conf->tpc_binning); - msg.dec_binning_conf =cpu_to_le32 (binning_conf->dec_binning); - msg.hbm_binning_conf =cpu_to_le32 (binning_conf->hbm_binning); - msg.edma_binning_conf =cpu_to_le32 (binning_conf->edma_binning); - msg.mme_redundancy_conf =cpu_to_le32 (binning_conf->mme_redundancy); -break ; - } -default : dev_err(hdev->dev, "Send COMMS message - invalid message type %u\n",
drivers/misc/habanalabs/include/common/hl_boot_if.h +21 -7
@@ -465,6 +465,26 @@ enum comms_msg_type { HL_COMMS_BINNING_CONF_TYPE = 3, }; +/* +* Binning information shared between LKD and FW +* @tpc_mask - TPC binning information +* @dec_mask - Decoder binning information +* @hbm_mask - HBM binning information +* @edma_mask - EDMA binning information +* @mme_mask_l - MME binning information lower 32 +* @mme_mask_h - MME binning information upper 32 +* @reserved - reserved field for 64 bit alignment +*/ +struct lkd_fw_binning_info { +__le64 tpc_mask; +__le32 dec_mask; +__le32 hbm_mask; +__le32 edma_mask; +__le32 mme_mask_l; +__le32 mme_mask_h; +__le32 reserved; +}; +/* TODO: remove this struct after the code is updated to use message */ /* this is the comms descriptor header - meta data */ struct comms_desc_header {
@@ -525,13 +545,7 @@ struct lkd_fw_comms_msg {struct {__u8 fw_cfg_skip;/* 1 - skip, 0 - don't skip */ }; -struct { -__le64 tpc_binning_conf; -__le32 dec_binning_conf; -__le32 hbm_binning_conf; -__le32 edma_binning_conf; -__le32 mme_redundancy_conf;/* use MME_REDUNDANT_COLUMN */ - }; +struct lkd_fw_binning_info binning_info; }; };
Signature · 1 line
2.25.1
PATCH 3/6 habanalabs/gaudi2: new API to control engine cores running mode
In reply to Oded GabbayFrom: Tal Cohen <[email protected]>
The current flow of halting the engine cores is implemented by command buffers built by the user space and sent towards the Driver.
This current flow is broken since the user space does not know when the cores actually halt as sending a workload is async op.
Therefore the application can not free the memory that is mapped to the engine cores.
This new API allows the user space to control the running mode. The API call is sync (returns after the cores are set to the requested mode).
--- .../habanalabs/common/command_submission.c | 43 ++++++++++- drivers/misc/habanalabs/common/habanalabs.h | 8 ++- drivers/misc/habanalabs/gaudi2/gaudi2.c | 72 +++++++++++++++++-- .../include/gaudi2/asic_reg/gaudi2_regs.h | 1 + include/uapi/misc/habanalabs.h | 38 ++++++++-- 5 files changed, 151 insertions(+), 11 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +42 -1
@@ -13,7 +13,7 @@#define HL_CS_FLAGS_TYPE_MASK (HL_CS_FLAGS_SIGNAL | HL_CS_FLAGS_WAIT | \ HL_CS_FLAGS_COLLECTIVE_WAIT | HL_CS_FLAGS_RESERVE_SIGNALS_ONLY | \ - HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY) + HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY | HL_CS_FLAGS_ENGINE_CORE_COMMAND)#define MAX_TS_ITER_NUM 10
@@ -1244,6 +1244,8 @@ static enum hl_cs_type hl_cs_get_cs_type(u32 cs_type_flags)return CS_RESERVE_SIGNALS ; else if (cs_type_flags & HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY) return CS_UNRESERVE_SIGNALS; + else if (cs_type_flags & HL_CS_FLAGS_ENGINE_CORE_COMMAND) + return CS_TYPE_ENGINE_CORE; else return CS_TYPE_DEFAULT; }
@@ -2355,6 +2357,41 @@ static int cs_ioctl_signal_wait(struct hl_fpriv *hpriv, enum hl_cs_type cs_type,return rc; } +static int cs_ioctl_engine_cores (struct hl_fpriv *hpriv,u64 engine_cores, +u32 num_engine_cores,u32 core_command) +{ +int rc; +struct hl_device *hdev = hpriv->hdev; +void __user *engine_cores_arr; +u32 *cores; + +if (!num_engine_cores || num_engine_cores > hdev->asic_prop.num_engine_cores) { +dev_err (hdev->dev,"Number of engine cores %d is invalid\n" , num_engine_cores); +return -EINVAL ; + } + +if (core_command !=HL_ENGINE_CORE_RUN && core_command !=HL_ENGINE_CORE_HALT ) { +dev_err (hdev->dev,"Engine core command is invalid\n" ); +return -EINVAL ; + } + + engine_cores_arr = (void __user *) (uintptr_t ) engine_cores; + cores =kmalloc_array (num_engine_cores,sizeof (u32),GFP_KERNEL ); +if (!cores) +return -ENOMEM ; + +if (copy_from_user (cores, engine_cores_arr, num_engine_cores *sizeof (u32))) { +dev_err (hdev->dev,"Failed to copy core-ids array from user\n" ); +kfree (cores); +return -EFAULT ; + } + + rc = hdev->asic_funcs->set_engine_cores (hdev, cores, num_engine_cores, core_command); +kfree (cores); + +return rc; +} +int hl_cs_ioctl (struct hl_fpriv *hpriv,void *data) {union hl_cs_args *args = data;
@@ -2407,6 +2444,10 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data) rc =cs_ioctl_unreserve_signals (hpriv, args->in.encaps_sig_handle_id);break ; +case CS_TYPE_ENGINE_CORE : + rc =cs_ioctl_engine_cores (hpriv, args->in.engine_cores, + args->in.num_engine_cores, args->in.core_command); +break ;default : rc = cs_ioctl_default(hpriv, chunks, num_chunks, &cs_seq, args->in.cs_flags,
drivers/misc/habanalabs/common/habanalabs.h +7 -1
@@ -345,7 +345,8 @@ enum hl_cs_type {CS_TYPE_WAIT ,CS_TYPE_COLLECTIVE_WAIT ,CS_RESERVE_SIGNALS , - CS_UNRESERVE_SIGNALS +CS_UNRESERVE_SIGNALS , + CS_TYPE_ENGINE_CORE };/*
@@ -617,6 +618,7 @@ struct hl_hints_range {* which the property supports_user_set_page_size is true * (i.e. the DRAM supports multiple page sizes), otherwise * it will shall be equal to dram_page_size. +* @num_engine_cores: number of engine cpu cores * @collective_first_sob: first sync object available for collective use * @collective_first_mon: first monitor available for collective use * @sync_stream_first_sob: first sync object available for sync stream use
@@ -737,6 +739,7 @@ struct asic_fixed_properties {u32 faulty_dram_cluster_map;u32 xbar_edge_enabled_mask;u32 device_mem_alloc_default_page_size; +u32 num_engine_cores;u16 collective_first_sob;u16 collective_first_mon;u16 sync_stream_first_sob;
@@ -1511,6 +1514,7 @@ struct engines_data {* @check_if_razwi_happened: check if there was a razwi due to RR violation. * @access_dev_mem: access device memory * @set_dram_bar_base: set the base of the DRAM BAR +* @set_engine_cores: set a config command to enigne cores */ struct hl_asic_funcs {int (*early_init)(struct hl_device *hdev);
@@ -1645,6 +1649,8 @@ struct hl_asic_funcs {int (*access_dev_mem)(struct hl_device *hdev,enum pci_region region_type,u64 addr,u64 *val,enum debugfs_access_type acc_type);u64 (*set_dram_bar_base)(struct hl_device *hdev,u64 addr); +int (*set_engine_cores)(struct hl_device *hdev,u32 *core_ids, +u32 num_cores,u32 core_command); };
drivers/misc/habanalabs/gaudi2/gaudi2.c +67 -5
111 lines not on this page · raw message
drivers/misc/habanalabs/include/gaudi2/asic_reg/gaudi2_regs.h +1 -0
@@ -239,6 +239,7 @@#define SFT_IF_RTR_OFFSET (mmSFT0_HBW_RTR_IF1_RTR_H3_BASE - mmSFT0_HBW_RTR_IF0_RTR_H3_BASE)#define ARC_HALT_REQ_OFFSET (mmARC_FARM_ARC0_AUX_RUN_HALT_REQ - mmARC_FARM_ARC0_AUX_BASE) +#define ARC_HALT_ACK_OFFSET (mmARC_FARM_ARC0_AUX_RUN_HALT_ACK - mmARC_FARM_ARC0_AUX_BASE)#define ARC_REGION_CFG_OFFSET (region) \ (mmARC_FARM_ARC0_AUX_ARC_REGION_CFG_0 + (region * 4) - mmARC_FARM_ARC0_AUX_BASE)
include/uapi/misc/habanalabs.h +34 -4
@@ -1361,17 +1361,47 @@ struct hl_cs_chunk {#define HL_CS_FLAGS_RESERVE_SIGNALS_ONLY 0x1000#define HL_CS_FLAGS_UNRESERVE_SIGNALS_ONLY 0x2000 +/* +* The engine cores CS is merged into the existing CS ioctls. +* Use it to control the engine cores mode. +*/ +#define HL_CS_FLAGS_ENGINE_CORE_COMMAND 0x4000 +#define HL_CS_STATUS_SUCCESS 0#define HL_MAX_JOBS_PER_CS 512 +/* HL_ENGINE_CORE_ values +* +* HL_ENGINE_CORE_HALT: engine core halt +* HL_ENGINE_CORE_RUN: engine core run +*/ +#define HL_ENGINE_CORE_HALT (1 << 0) +#define HL_ENGINE_CORE_RUN (1 << 1) +struct hl_cs_in { -/* this holds address of array of hl_cs_chunk for restore phase */ -__u64 chunks_restore; +union { +struct { +/* this holds address of array of hl_cs_chunk for restore phase */ +__u64 chunks_restore; -/* holds address of array of hl_cs_chunk for execution phase */ -__u64 chunks_execute; +/* holds address of array of hl_cs_chunk for execution phase */ +__u64 chunks_execute; + }; + +/* Valid only when HL_CS_FLAGS_ENGINE_CORE_COMMAND is set */ +struct { +/* this holds address of array of uint32 for engine_cores */ +__u64 engine_cores; + +/* number of engine cores in engine_cores array */ +__u32 num_engine_cores; + +/* the core command to be sent towards engine cores */ +__u32 core_command; + }; + };union {/*
Signature · 1 line
2.25.1
PATCH 4/6 habanalabs: unify hwmon resources clean up
In reply to Oded GabbayFrom: Dani Liberman <[email protected]>
Since hwmon fini code is common for all asics, unified it to common function.
--- drivers/misc/habanalabs/common/habanalabs.h | 1 + drivers/misc/habanalabs/common/hwmon.c | 21 +++++++++++++++++++++ drivers/misc/habanalabs/gaudi/gaudi.c | 18 +----------------- drivers/misc/habanalabs/gaudi2/gaudi2.c | 18 +----------------- drivers/misc/habanalabs/goya/goya.c | 17 +---------------- 5 files changed, 25 insertions(+), 50 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +1 -0
@@ -3529,6 +3529,7 @@ void hl_sysfs_fini(struct hl_device *hdev);int hl_hwmon_init (struct hl_device *hdev);void hl_hwmon_fini (struct hl_device *hdev); +void hl_hwmon_release_resources (struct hl_device *hdev); int hl_cb_create(struct hl_device *hdev, struct hl_mem_mgr *mmg, struct hl_ctx *ctx, u32 cb_size, bool internal_cb,
drivers/misc/habanalabs/common/hwmon.c +21 -0
@@ -910,3 +910,24 @@ void hl_hwmon_fini(struct hl_device *hdev)hwmon_device_unregister (hdev->hwmon_dev); } + +void hl_hwmon_release_resources (struct hl_device *hdev) +{ +const struct hwmon_channel_info **channel_info_arr; +int i =0 ; + +if (!hdev->hl_chip_info->info) +return ; + + channel_info_arr = hdev->hl_chip_info->info; + +while (channel_info_arr[i]) { +kfree (channel_info_arr[i]->config); +kfree (channel_info_arr[i]); + i++; + } + +kfree (channel_info_arr); + + hdev->hl_chip_info->info =NULL ; +}
drivers/misc/habanalabs/gaudi/gaudi.c +1 -17
@@ -1682,23 +1682,7 @@ static int gaudi_late_init(struct hl_device *hdev)static void gaudi_late_fini (struct hl_device *hdev) { -const struct hwmon_channel_info **channel_info_arr; -int i =0 ; - -if (!hdev->hl_chip_info->info) -return ; - - channel_info_arr = hdev->hl_chip_info->info; - -while (channel_info_arr[i]) { -kfree (channel_info_arr[i]->config); -kfree (channel_info_arr[i]); - i++; - } - -kfree (channel_info_arr); - - hdev->hl_chip_info->info =NULL ; +hl_hwmon_release_resources (hdev); }static int gaudi_alloc_cpu_accessible_dma_mem (struct hl_device *hdev)
drivers/misc/habanalabs/gaudi2/gaudi2.c +1 -17
@@ -2711,23 +2711,7 @@ static int gaudi2_late_init(struct hl_device *hdev)static void gaudi2_late_fini (struct hl_device *hdev) { -const struct hwmon_channel_info **channel_info_arr; -int i =0 ; - -if (!hdev->hl_chip_info->info) -return ; - - channel_info_arr = hdev->hl_chip_info->info; - -while (channel_info_arr[i]) { -kfree (channel_info_arr[i]->config); -kfree (channel_info_arr[i]); - i++; - } - -kfree (channel_info_arr); - - hdev->hl_chip_info->info =NULL ; +hl_hwmon_release_resources (hdev); }static void gaudi2_user_mapped_dec_init (struct gaudi2_device *gaudi2,u32 start_idx)
drivers/misc/habanalabs/goya/goya.c +1 -16
@@ -916,26 +916,11 @@ int goya_late_init(struct hl_device *hdev)*/ void goya_late_fini (struct hl_device *hdev) { -const struct hwmon_channel_info **channel_info_arr;struct goya_device *goya = hdev->asic_specific; -int i =0 ;cancel_delayed_work_sync (&goya->goya_work->work_freq); -if (!hdev->hl_chip_info->info) -return ; - - channel_info_arr = hdev->hl_chip_info->info; - -while (channel_info_arr[i]) { -kfree (channel_info_arr[i]->config); -kfree (channel_info_arr[i]); - i++; - } - -kfree (channel_info_arr); - - hdev->hl_chip_info->info =NULL ; +hl_hwmon_release_resources (hdev); }static void goya_set_pci_memory_regions (struct hl_device *hdev)
Signature · 1 line
2.25.1
PATCH 5/6 habanalabs: fix H/W block handling for partial unmappings
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
Several munmap() calls can be done or a mapped H/W block that has a larger size than a page size.
Releasing the object should be done only when all mapped range is unmapped.
--- drivers/misc/habanalabs/common/debugfs.c | 14 ++++++++------ drivers/misc/habanalabs/common/habanalabs.h | 6 ++++-- drivers/misc/habanalabs/common/memory.c | 10 +++++++++- 3 files changed, 21 insertions(+), 9 deletions(-)
drivers/misc/habanalabs/common/debugfs.c +8 -6
@@ -291,14 +291,16 @@ static int vm_show(struct seq_file *s, void *data)if (ctx->asid !=HL_KERNEL_ASID_ID && !list_empty (&ctx->hw_block_mem_list)) {seq_puts (s,"\nhw_block mappings:\n\n" ); -seq_puts (s," virtual address size HW block id\n" ); -seq_puts (s,"-------------------------------------------\n" ); +seq_puts (s, +" virtual address block size mapped size HW block id\n" ); +seq_puts (s, +"---------------------------------------------------------------\n" );mutex_lock (&ctx->hw_block_list_lock); -list_for_each_entry (lnode, &ctx->hw_block_mem_list, - node) { +list_for_each_entry (lnode, &ctx->hw_block_mem_list, node) {seq_printf (s, -" 0x%-14lx %-6u %-9u\n" , - lnode->vaddr, lnode->size, lnode->id); +" 0x%-14lx %-6u %-6u %-9u\n" , + lnode->vaddr, lnode->block_size, lnode->mapped_size, + lnode->id); }mutex_unlock (&ctx->hw_block_list_lock); }
drivers/misc/habanalabs/common/habanalabs.h +4 -2
@@ -2063,14 +2063,16 @@ struct hl_vm_hash_node {* @node: node to hang on the list in context object. * @ctx: the context this node belongs to. * @vaddr: virtual address of the HW block. -* @size: size of the block. +* @block_size: size of the block. +* @mapped_size: size of the block which is mapped. May change if partial un-mappings are done. * @id: HW block id (handle). */ struct hl_vm_hw_block_list_node {struct list_head node;struct hl_ctx *ctx;unsigned long vaddr; -u32 size; +u32 block_size; +u32 mapped_size;u32 id; };
drivers/misc/habanalabs/common/memory.c +9 -1
@@ -1442,6 +1442,13 @@ static void hw_block_vm_close(struct vm_area_struct *vma)struct hl_vm_hw_block_list_node *lnode = (struct hl_vm_hw_block_list_node *) vma->vm_private_data;struct hl_ctx *ctx = lnode->ctx; +long new_mmap_size; + + new_mmap_size = lnode->mapped_size - (vma->vm_end - vma->vm_start); +if (new_mmap_size >0 ) { + lnode->mapped_size = new_mmap_size; +return ; + }mutex_lock (&ctx->hw_block_list_lock);list_del (&lnode->node);
@@ -1502,7 +1509,8 @@ int hl_hw_block_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma) lnode->ctx = ctx; lnode->vaddr = vma->vm_start; - lnode->size = block_size; + lnode->block_size = block_size; + lnode->mapped_size = lnode->block_size; lnode->id = block_id; vma->vm_private_data = lnode;
Signature · 1 line
2.25.1
PATCH 6/6 habanalabs: remove secured PCI IDs
In reply to Oded GabbayFrom: Ofir Bitton <[email protected]>
Secured PCI ID will not be supported in new asics because the security status can always be read from the f/w.
--- drivers/misc/habanalabs/common/habanalabs_drv.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/misc/habanalabs/common/habanalabs_drv.c +0 -6
@@ -58,14 +58,12 @@ MODULE_PARM_DESC(boot_error_status_mask,#define PCI_IDS_GAUDI_SEC 0x1010#define PCI_IDS_GAUDI2 0x1020 -#define PCI_IDS_GAUDI2_SEC 0x1030static const struct pci_device_id ids[] = { {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GOYA ), }, {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GAUDI ), }, {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GAUDI_SEC ), }, {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GAUDI2 ), }, - {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GAUDI2_SEC ), }, {0 , } };MODULE_DEVICE_TABLE (pci, ids);
@@ -95,9 +93,6 @@ static enum hl_asic_type get_asic_type(u16 device)case PCI_IDS_GAUDI2 : asic_type =ASIC_GAUDI2 ;break ; -case PCI_IDS_GAUDI2_SEC : - asic_type =ASIC_GAUDI2_SEC ; -break ;default : asic_type =ASIC_INVALID ;break ;
@@ -110,7 +105,6 @@ static bool is_asic_secured(enum hl_asic_type asic_type) {switch (asic_type) {case ASIC_GAUDI_SEC : -case ASIC_GAUDI2_SEC :return true;default :return false;
Signature · 1 line
2.25.1