From 46936650256695f9bc706eb7d586761eb6555628 Mon Sep 17 00:00:00 2001 From: Wen Chen Date: Mon, 1 Dec 2025 20:11:03 +0800 Subject: [PATCH] urma: fixing ubcore hash table initialization failure. urma inclusion category: feature bugzilla: https://gitee.com/openeuler/release-management/issues/ID3WJX ---------------------------------------------- This patch primarily addresses the issue of hash table entry failures The implementation provides the following key functionalities: 1. Adjust the hash type enumeration value. 2. Remove and deregister unused hash table entries. 3. The device's active TP and deactive TP logic is inverted, causing the interception to fail. 4. Fixed the failure of user-space calls to the set_tp/get_tp interface. Signed-off-by: Wen Chen --- .../ub/urma/ubcore/ubcore_connect_adapter.c | 4 +- drivers/ub/urma/ubcore/ubcore_device.c | 57 +---------------- drivers/ub/urma/ubcore/ubcore_jetty.c | 2 +- drivers/ub/urma/uburma/uburma_cmd.c | 64 +++++++++++++++++++ 4 files changed, 69 insertions(+), 58 deletions(-) diff --git a/drivers/ub/urma/ubcore/ubcore_connect_adapter.c b/drivers/ub/urma/ubcore/ubcore_connect_adapter.c index b4a0f0b96c85..dbb8dccd68ef 100644 --- a/drivers/ub/urma/ubcore/ubcore_connect_adapter.c +++ b/drivers/ub/urma/ubcore/ubcore_connect_adapter.c @@ -52,7 +52,7 @@ static int ubcore_active_tp(struct ubcore_device *dev, { int ret; - if (!dev || !dev->ops || dev->ops->active_tp || + if (!dev || !dev->ops || !dev->ops->active_tp || active_cfg == NULL) { ubcore_log_err("Invalid parameter.\n"); return -EINVAL; @@ -76,7 +76,7 @@ static int ubcore_deactive_tp(struct ubcore_device *dev, { int ret; - if (!dev || !dev->ops || dev->ops->active_tp) { + if (!dev || !dev->ops || !dev->ops->deactive_tp) { ubcore_log_err("Invalid parameter.\n"); return -EINVAL; } diff --git a/drivers/ub/urma/ubcore/ubcore_device.c b/drivers/ub/urma/ubcore/ubcore_device.c index 213cce97f809..6170ad347863 100644 --- a/drivers/ub/urma/ubcore/ubcore_device.c +++ b/drivers/ub/urma/ubcore/ubcore_device.c @@ -624,6 +624,8 @@ static int ubcore_alloc_hash_tables(struct ubcore_device *dev) ubcore_update_hash_tables_size(&dev->attr.dev_cap); for (i = 0; i < ARRAY_SIZE(g_ht_params); i++) { + if (g_ht_params[i].size == 0) + continue; ret = ubcore_hash_table_alloc(&dev->ht[i], &g_ht_params[i]); if (ret != 0) { ubcore_log_err("alloc hash tables failed.\n"); @@ -639,60 +641,6 @@ static int ubcore_alloc_hash_tables(struct ubcore_device *dev) return -1; } -static void ubcore_destroy_vtp_in_unreg_dev(void *arg) -{ - struct ubcore_vtp *vtp = (struct ubcore_vtp *)arg; - - if (vtp->cfg.vtpn != UINT_MAX && vtp->ub_dev->ops->destroy_vtp != NULL) - (void)vtp->ub_dev->ops->destroy_vtp(vtp); - else - kfree(vtp); -} - -static void ubcore_destroy_tp_in_unreg_dev(void *arg) -{ - struct ubcore_tp *tp = (struct ubcore_tp *)arg; - - if (tp->ub_dev->ops->destroy_tp != NULL) - (void)tp->ub_dev->ops->destroy_tp(tp); -} - -static void ubcore_destroy_utp_in_unreg_dev(void *arg) -{ - struct ubcore_utp *utp = (struct ubcore_utp *)arg; - - if (utp->ub_dev->ops->destroy_utp != NULL) - (void)utp->ub_dev->ops->destroy_utp(utp); -} - -static void ubcore_destroy_tpg_in_unreg_dev(void *arg) -{ - struct ubcore_tpg *tpg = (struct ubcore_tpg *)arg; - - if (tpg->ub_dev->ops->destroy_tpg != NULL) - (void)tpg->ub_dev->ops->destroy_tpg(tpg); -} - -static void ubcore_free_driver_res(struct ubcore_device *dev) -{ - if (!dev->attr.tp_maintainer) - return; - - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_RM_VTP], - ubcore_destroy_vtp_in_unreg_dev); - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_RC_VTP], - ubcore_destroy_vtp_in_unreg_dev); - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_UM_VTP], - ubcore_destroy_vtp_in_unreg_dev); - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_TP], - ubcore_destroy_tp_in_unreg_dev); - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_UTP], - ubcore_destroy_utp_in_unreg_dev); - - ubcore_hash_table_free_with_cb(&dev->ht[UBCORE_HT_TPG], - ubcore_destroy_tpg_in_unreg_dev); -} - static void ubcore_free_hash_tables(struct ubcore_device *dev) { uint32_t i; @@ -928,7 +876,6 @@ static int init_ubcore_device(struct ubcore_device *dev) static void uninit_ubcore_device(struct ubcore_device *dev) { mutex_destroy(&dev->ldev_mutex); - ubcore_free_driver_res(dev); ubcore_free_hash_tables(dev); ubcore_destroy_eidtable(dev); uninit_ubcore_mue(dev); diff --git a/drivers/ub/urma/ubcore/ubcore_jetty.c b/drivers/ub/urma/ubcore/ubcore_jetty.c index efa5c2163ad8..3d630a5d30cf 100644 --- a/drivers/ub/urma/ubcore/ubcore_jetty.c +++ b/drivers/ub/urma/ubcore/ubcore_jetty.c @@ -1938,7 +1938,7 @@ int ubcore_bind_jetty_ex(struct ubcore_jetty *jetty, struct ubcore_active_tp_cfg *active_tp_cfg, struct ubcore_udata *udata) { - if (!jetty || !tjetty || jetty->ub_dev || + if (!jetty || !tjetty || !jetty->ub_dev || !jetty->ub_dev->ops || !active_tp_cfg) { ubcore_log_err("Invalid parameter.\n"); return -EINVAL; diff --git a/drivers/ub/urma/uburma/uburma_cmd.c b/drivers/ub/urma/uburma/uburma_cmd.c index 79cbb7a999dd..4bf939a8fc3b 100644 --- a/drivers/ub/urma/uburma/uburma_cmd.c +++ b/drivers/ub/urma/uburma/uburma_cmd.c @@ -2990,6 +2990,68 @@ static int uburma_cmd_get_tp_list(struct ubcore_device *ubc_dev, return ret; } +static int uburma_cmd_set_tp_attr(struct ubcore_device *ubc_dev, + struct uburma_file *file, + struct uburma_cmd_hdr *hdr) +{ + struct ubcore_tp_attr_value tp_attr = { 0 }; + struct uburma_cmd_set_tp_attr arg = { 0 }; + struct ubcore_udata udata = { 0 }; + int ret; + + ret = uburma_tlv_parse(hdr, &arg); + if (ret != 0) + return ret; + + if (sizeof(arg.in.tp_attr) != sizeof(struct ubcore_tp_attr_value)) { + uburma_log_err("Invalid parameter.\n"); + return -EINVAL; + } + fill_udata(&udata, file->ucontext, &arg.udata); + (void)memcpy(&tp_attr, arg.in.tp_attr, sizeof(arg.in.tp_attr)); + + ret = ubcore_set_tp_attr(ubc_dev, arg.in.tp_handle, arg.in.tp_attr_cnt, + arg.in.tp_attr_bitmap, &tp_attr, &udata); + if (ret != 0) + uburma_log_err( + "Failed to set tp attribution values, ret: %d.\n", ret); + + return ret; +} + +static int uburma_cmd_get_tp_attr(struct ubcore_device *ubc_dev, + struct uburma_file *file, + struct uburma_cmd_hdr *hdr) +{ + struct ubcore_tp_attr_value tp_attr = { 0 }; + struct uburma_cmd_get_tp_attr arg = { 0 }; + struct ubcore_udata udata = { 0 }; + int ret; + + ret = uburma_tlv_parse(hdr, &arg); + if (ret != 0) + return ret; + + if (sizeof(arg.out.tp_attr) != sizeof(struct ubcore_tp_attr_value)) { + uburma_log_err("Invalid parameter.\n"); + return -EINVAL; + } + fill_udata(&udata, file->ucontext, &arg.udata); + + ret = ubcore_get_tp_attr(ubc_dev, arg.in.tp_handle, + &arg.out.tp_attr_cnt, &arg.out.tp_attr_bitmap, + &tp_attr, &udata); + if (ret != 0) { + uburma_log_err( + "Failed to get tp attribution values, ret: %d.\n", ret); + return ret; + } + (void)memcpy(arg.out.tp_attr, &tp_attr, + sizeof(struct ubcore_tp_attr_value)); + + return uburma_tlv_append(hdr, &arg); +} + static int uburma_cmd_exchange_tp_info(struct ubcore_device *ubc_dev, struct uburma_file *file, struct uburma_cmd_hdr *hdr) @@ -3139,6 +3201,8 @@ static uburma_cmd_handler g_uburma_cmd_handlers[] = { [UBURMA_CMD_DELETE_JFR_BATCH] = uburma_cmd_delete_jfr_batch, [UBURMA_CMD_DELETE_JFC_BATCH] = uburma_cmd_delete_jfc_batch, [UBURMA_CMD_DELETE_JETTY_BATCH] = uburma_cmd_delete_jetty_batch, + [UBURMA_CMD_SET_TP_ATTR] = uburma_cmd_set_tp_attr, + [UBURMA_CMD_GET_TP_ATTR] = uburma_cmd_get_tp_attr, [UBURMA_CMD_EXCHANGE_TP_INFO] = uburma_cmd_exchange_tp_info, }; -- Gitee