habanalabs: remove dead code from free_device_memory()
PATCH 1/2 habanalabs: remove dead code from free_device_memory()
From: Tomer Tayar <[email protected]>
free_device_memory() ends with if and else, each has a return statement, followed by another return statement that can never be reached. Restructure the function and remove this dead code.
Signed-off-by Tomer Tayar <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/memory.c | 50 +++++++++++-------------- 1 file changed, 22 insertions(+), 28 deletions(-)
drivers/misc/habanalabs/common/memory.c +22 -28
@@ -359,41 +359,35 @@ static int free_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args)spin_lock (&vm->idr_lock); phys_pg_pack =idr_find (&vm->phys_pg_pack_handles, handle); -if (phys_pg_pack) { -if (atomic_read (&phys_pg_pack->mapping_cnt) >0 ) { -dev_err (hdev->dev,"handle %u is mapped, cannot free\n" , - handle); -spin_unlock (&vm->idr_lock); -return -EINVAL ; - } - -if (phys_pg_pack->exporting_cnt) { -dev_dbg (hdev->dev,"handle %u is exported, cannot free\n" , handle); -spin_unlock (&vm->idr_lock); -return -EINVAL ; - } - -/* -* must remove from idr before the freeing of the physical -* pages as the refcount of the pool is also the trigger of the -* idr destroy -*/ -idr_remove (&vm->phys_pg_pack_handles, handle); +if (!phys_pg_pack) {spin_unlock (&vm->idr_lock); +dev_err (hdev->dev,"free device memory failed, no match for handle %u\n" , handle); +return -EINVAL ; + } -atomic64_sub (phys_pg_pack->total_size, &ctx->dram_phys_mem); -atomic64_sub (phys_pg_pack->total_size, &hdev->dram_used_mem); +if (atomic_read (&phys_pg_pack->mapping_cnt) >0 ) { +spin_unlock (&vm->idr_lock); +dev_err (hdev->dev,"handle %u is mapped, cannot free\n" , handle); +return -EINVAL ; + } -free_phys_pg_pack (hdev, phys_pg_pack); -return 0 ; - }else { +if (phys_pg_pack->exporting_cnt) {spin_unlock (&vm->idr_lock); -dev_err (hdev->dev, -"free device memory failed, no match for handle %u\n" , - handle); +dev_dbg (hdev->dev,"handle %u is exported, cannot free\n" , handle);return -EINVAL ; } +/* must remove from idr before the freeing of the physical pages as the refcount of the pool +* is also the trigger of the idr destroy +*/ +idr_remove (&vm->phys_pg_pack_handles, handle); +spin_unlock (&vm->idr_lock); + +atomic64_sub (phys_pg_pack->total_size, &ctx->dram_phys_mem); +atomic64_sub (phys_pg_pack->total_size, &hdev->dram_used_mem); + +free_phys_pg_pack (hdev, phys_pg_pack); +return 0 ; }
Signature · 1 line
2.25.1
PATCH 2/2 habanalabs: communicate supported page sizes to user
From: Ohad Sharabi <[email protected]>
Because in future ASICs the driver will allow the user to set the page size we need to make sure this data is propagated in all APIs.
In addition, since this is already an ASIC property we no longer need ASIC function for it.
Signed-off-by Ohad Sharabi <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/habanalabs.h | 5 +++-- drivers/misc/habanalabs/common/habanalabs_ioctl.c | 2 +- drivers/misc/habanalabs/common/memory.c | 4 ++-- drivers/misc/habanalabs/gaudi/gaudi.c | 7 ------- drivers/misc/habanalabs/goya/goya.c | 7 ------- 5 files changed, 6 insertions(+), 19 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +3 -2
@@ -401,6 +401,8 @@ enum hl_device_hw_state {* @hop_masks: array holds HOPs masks. * @last_mask: mask to get the bit indicating this is the last hop. * @pgt_size: size for page tables. +* @supported_pages_mask: bitmask for supported page size (relevant only for MMUs +* supporting multiple page size). * @page_size: default page size used to allocate memory. * @num_hops: The amount of hops supported by the translation table. * @hop_table_size: HOP table size.
@@ -415,6 +417,7 @@ struct hl_mmu_properties {u64 hop_masks[MMU_HOP_MAX ];u64 last_mask;u64 pgt_size; +u64 supported_pages_mask;u32 page_size;u32 num_hops;u32 hop_table_size;
@@ -1332,7 +1335,6 @@ struct fw_load_mgr {* @get_sob_addr: get SOB base address offset. * @set_pci_memory_regions: setting properties of PCI memory regions * @get_stream_master_qid_arr: get pointer to stream masters QID array -* @get_valid_dram_page_orders: get valid device memory allocation page orders * @access_dev_mem: access device memory * @set_dram_bar_base: set the base of the DRAM BAR */
@@ -1453,7 +1455,6 @@ struct hl_asic_funcs { u32* (*get_stream_master_qid_arr)(void);int (*mmu_get_real_page_size)(struct hl_device *hdev,struct hl_mmu_properties *mmu_prop,u32 page_size,u32 *real_page_size,bool is_dram_addr); -void (*get_valid_dram_page_orders)(struct hl_info_dev_memalloc_page_sizes *info);int (*access_dev_mem)(struct hl_device *hdev,struct pci_mem_region *region,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);
drivers/misc/habanalabs/common/habanalabs_ioctl.c +1 -1
@@ -648,7 +648,7 @@ static int dev_mem_alloc_page_sizes_info(struct hl_fpriv *hpriv, struct hl_info_* For this reason for all ASICs that not support multiple page size the function will * return an empty bitmask indicating that multiple page sizes is not supported. */ - hdev->asic_funcs->get_valid_dram_page_orders (&info); + info.page_order_bitmask = hdev->asic_prop.dmmu.supported_pages_mask;return copy_to_user (out, &info,min_t (size_t, max_size,sizeof (info))) ? -EFAULT :0 ; }
drivers/misc/habanalabs/common/memory.c +2 -2
@@ -27,7 +27,7 @@ static int allocate_timestamps_buffers(struct hl_fpriv *hpriv,static int set_alloc_page_size (struct hl_device *hdev,struct hl_mem_in *args,u32 *page_size) {struct asic_fixed_properties *prop = &hdev->asic_prop; -u32 psize; +u64 psize;/* * for ASIC that supports setting the allocation page size by user we will address
@@ -37,7 +37,7 @@ static int set_alloc_page_size(struct hl_device *hdev, struct hl_mem_in *args, u psize = args->alloc.page_size;if (!is_power_of_2 (psize)) { -dev_err (hdev->dev,"user page size (%#x) is not power of 2\n" , psize); +dev_err (hdev->dev,"user page size (%#llx) is not power of 2\n" , psize);return -EINVAL ; } }else {
drivers/misc/habanalabs/gaudi/gaudi.c +0 -7
@@ -9237,12 +9237,6 @@ static u32 *gaudi_get_stream_master_qid_arr(void)return gaudi_stream_master; } -static void gaudi_get_valid_dram_page_orders (struct hl_info_dev_memalloc_page_sizes *info) -{ -/* set 0 since multiple pages are not supported */ - info->page_order_bitmask =0 ; -} -static ssize_t infineon_ver_show (struct device *dev,struct device_attribute *attr,char *buf) {struct hl_device *hdev =dev_get_drvdata (dev);
@@ -9351,7 +9345,6 @@ static const struct hl_asic_funcs gaudi_funcs = { .set_pci_memory_regions = gaudi_set_pci_memory_regions, .get_stream_master_qid_arr = gaudi_get_stream_master_qid_arr, .mmu_get_real_page_size = hl_mmu_get_real_page_size, - .get_valid_dram_page_orders = gaudi_get_valid_dram_page_orders, .access_dev_mem = hl_access_dev_mem, .set_dram_bar_base = gaudi_set_hbm_bar_base, };
drivers/misc/habanalabs/goya/goya.c +0 -7
@@ -5405,12 +5405,6 @@ static u32 *goya_get_stream_master_qid_arr(void)return NULL ; } -static void goya_get_valid_dram_page_orders (struct hl_info_dev_memalloc_page_sizes *info) -{ -/* set 0 since multiple pages are not supported */ - info->page_order_bitmask =0 ; -} -static int goya_get_monitor_dump (struct hl_device *hdev,void *data) {return -EOPNOTSUPP ;
@@ -5505,7 +5499,6 @@ static const struct hl_asic_funcs goya_funcs = { .set_pci_memory_regions = goya_set_pci_memory_regions, .get_stream_master_qid_arr = goya_get_stream_master_qid_arr, .mmu_get_real_page_size = hl_mmu_get_real_page_size, - .get_valid_dram_page_orders = goya_get_valid_dram_page_orders, .access_dev_mem = hl_access_dev_mem, .set_dram_bar_base = goya_set_ddr_bar_base, };
Signature · 1 line
2.25.1