Remove not possible checks
cover Remove not possible checks
From: Leon Romanovsky <[email protected]>
The iwpm is part of iw_cm module load, it ensures that iwpm is valid prior to execution of any commands.
This series deletes such checks.
Thanks
Leon Romanovsky (3):
RDMA/iwcm: Release resources if iw_cm module initialization fails RDMA/iwpm: Remove not-needed reference counting RDMA/iwpm: Rely on the upper to ensure that requests are valid
drivers/infiniband/core/iwcm.c | 19 ++++--- drivers/infiniband/core/iwpm_msg.c | 34 +------------ drivers/infiniband/core/iwpm_util.c | 78 ++++++----------------------- drivers/infiniband/core/iwpm_util.h | 18 ------- 4 files changed, 28 insertions(+), 121 deletions(-)
Signature · 1 line
2.31.1
PATCH 2/3 RDMA/iwpm: Remove not-needed reference counting
From: Leon Romanovsky <[email protected]>
iwpm_init() and iwpm_exit() are called only once during iw_cm module load. This makes whole reference count implementation not needed at all.
--- drivers/infiniband/core/iwpm_util.c | 62 ++++++++--------------------- drivers/infiniband/core/iwpm_util.h | 1 - 2 files changed, 16 insertions(+), 47 deletions(-)
drivers/infiniband/core/iwpm_util.c +16 -46
@@ -48,7 +48,6 @@ static DEFINE_SPINLOCK(iwpm_mapinfo_lock);static struct hlist_head *iwpm_reminfo_bucket;static DEFINE_SPINLOCK (iwpm_reminfo_lock); -static DEFINE_MUTEX (iwpm_admin_lock);static struct iwpm_admin_data iwpm_admin;/**
@@ -59,39 +58,22 @@ static struct iwpm_admin_data iwpm_admin;*/ int iwpm_init (u8 nl_client) { -int ret =0 ; -mutex_lock (&iwpm_admin_lock); -if (!refcount_read (&iwpm_admin.refcount)) { - iwpm_hash_bucket =kcalloc (IWPM_MAPINFO_HASH_SIZE , -sizeof (struct hlist_head ), -GFP_KERNEL ); -if (!iwpm_hash_bucket) { - ret = -ENOMEM ; - goto init_exit; - } - iwpm_reminfo_bucket =kcalloc (IWPM_REMINFO_HASH_SIZE , -sizeof (struct hlist_head ), -GFP_KERNEL ); -if (!iwpm_reminfo_bucket) { -kfree (iwpm_hash_bucket); - ret = -ENOMEM ; - goto init_exit; - } + iwpm_hash_bucket =kcalloc (IWPM_MAPINFO_HASH_SIZE , +sizeof (struct hlist_head ),GFP_KERNEL ); +if (!iwpm_hash_bucket) +return -ENOMEM ; -refcount_set (&iwpm_admin.refcount,1 ); - }else { -refcount_inc (&iwpm_admin.refcount); + iwpm_reminfo_bucket =kcalloc (IWPM_REMINFO_HASH_SIZE , +sizeof (struct hlist_head ),GFP_KERNEL ); +if (!iwpm_reminfo_bucket) { +kfree (iwpm_hash_bucket); +return -ENOMEM ; } -init_exit: -mutex_unlock (&iwpm_admin_lock); -if (!ret) { -iwpm_set_valid (nl_client,1 ); -iwpm_set_registration (nl_client,IWPM_REG_UNDEF ); -pr_debug ("%s: Mapinfo and reminfo tables are created\n" , - __func__); - } -return ret; +iwpm_set_valid (nl_client,1 ); +iwpm_set_registration (nl_client,IWPM_REG_UNDEF ); +pr_debug ("%s: Mapinfo and reminfo tables are created\n" , __func__); +return 0 ; }static void free_hash_bucket (void );
@@ -105,21 +87,9 @@ static void free_reminfo_bucket(void);*/ int iwpm_exit (u8 nl_client) { - -if (!iwpm_valid_client (nl_client)) -return -EINVAL ; -mutex_lock (&iwpm_admin_lock); -if (!refcount_read (&iwpm_admin.refcount)) { -mutex_unlock (&iwpm_admin_lock); -pr_err ("%s Incorrect usage - negative refcount\n" , __func__); -return -EINVAL ; - } -if (refcount_dec_and_test (&iwpm_admin.refcount)) { -free_hash_bucket (); -free_reminfo_bucket (); -pr_debug ("%s: Resources are destroyed\n" , __func__); - } -mutex_unlock (&iwpm_admin_lock); +free_hash_bucket (); +free_reminfo_bucket (); +pr_debug ("%s: Resources are destroyed\n" , __func__);iwpm_set_valid (nl_client,0 );iwpm_set_registration (nl_client,IWPM_REG_UNDEF );return 0 ;
drivers/infiniband/core/iwpm_util.h +0 -1
@@ -90,7 +90,6 @@ struct iwpm_remote_info { };struct iwpm_admin_data { -refcount_t refcount;atomic_t nlmsg_seq;int client_list[RDMA_NL_NUM_CLIENTS ];u32 reg_list[RDMA_NL_NUM_CLIENTS ];
Signature · 1 line
2.31.1
PATCH 3/3 RDMA/iwpm: Rely on the upper to ensure that requests are valid
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
The iwpw has only one netlink client, which is iw_cm. That client is registered when the iw_cm module is loaded. The module load is triggered before any use of EXPORT_SYMBOL or netlink operation and it ensures that the iwpm is valid.
--- drivers/infiniband/core/iwpm_msg.c | 34 +---------------------------- drivers/infiniband/core/iwpm_util.c | 18 --------------- drivers/infiniband/core/iwpm_util.h | 17 --------------- 3 files changed, 1 insertion(+), 68 deletions(-)
drivers/infiniband/core/iwpm_msg.c +1 -33
@@ -69,10 +69,6 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client)const char *err_str ="" ;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) { - err_str ="Invalid port mapper client" ; - goto pid_query_error; - }if (iwpm_check_registration (nl_client,IWPM_REG_VALID ) || iwpm_user_pid ==IWPM_PID_UNAVAILABLE )return 0 ;
@@ -153,10 +149,6 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)const char *err_str ="" ;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) { - err_str ="Invalid port mapper client" ; - goto add_mapping_error; - }if (!iwpm_valid_pid ())return 0 ;if (!iwpm_check_registration (nl_client,IWPM_REG_VALID )) {
@@ -240,10 +232,6 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)const char *err_str ="" ;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) { - err_str ="Invalid port mapper client" ; - goto query_mapping_error; - }if (!iwpm_valid_pid ())return 0 ;if (!iwpm_check_registration (nl_client,IWPM_REG_VALID )) {
@@ -331,10 +319,6 @@ int iwpm_remove_mapping(struct sockaddr_storage *local_addr, u8 nl_client)const char *err_str ="" ;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) { - err_str ="Invalid port mapper client" ; - goto remove_mapping_error; - }if (!iwpm_valid_pid ())return 0 ;if (iwpm_check_registration (nl_client,IWPM_REG_UNDEF )) {
@@ -444,8 +428,7 @@ int iwpm_register_pid_cb(struct sk_buff *skb, struct netlink_callback *cb)atomic_set (&echo_nlmsg_seq, cb->nlh->nlmsg_seq);pr_debug ("%s: iWarp Port Mapper (pid = %d) is available!\n" , __func__, iwpm_user_pid); -if (iwpm_valid_client (nl_client)) -iwpm_set_registration (nl_client,IWPM_REG_VALID ); +iwpm_set_registration (nl_client,IWPM_REG_VALID ); register_pid_response_exit: nlmsg_request->request_done =1 ;/* always for found nlmsg_request */
@@ -649,11 +632,6 @@ int iwpm_remote_info_cb(struct sk_buff *skb, struct netlink_callback *cb)return ret; nl_client =RDMA_NL_GET_CLIENT (cb->nlh->nlmsg_type); -if (!iwpm_valid_client (nl_client)) { -pr_info ("%s: Invalid port mapper client = %u\n" , - __func__, nl_client); -return ret; - }atomic_set (&echo_nlmsg_seq, cb->nlh->nlmsg_seq); local_sockaddr = (struct sockaddr_storage *)
@@ -736,11 +714,6 @@ int iwpm_mapping_info_cb(struct sk_buff *skb, struct netlink_callback *cb)return ret; } nl_client =RDMA_NL_GET_CLIENT (cb->nlh->nlmsg_type); -if (!iwpm_valid_client (nl_client)) { -pr_info ("%s: Invalid port mapper client = %u\n" , - __func__, nl_client); -return ret; - }iwpm_set_registration (nl_client,IWPM_REG_INCOMPL );atomic_set (&echo_nlmsg_seq, cb->nlh->nlmsg_seq); iwpm_user_pid = cb->nlh->nlmsg_pid;
@@ -863,11 +836,6 @@ int iwpm_hello_cb(struct sk_buff *skb, struct netlink_callback *cb) } abi_version =nla_get_u16 (nltb[IWPM_NLA_HELLO_ABI_VERSION ]); nl_client =RDMA_NL_GET_CLIENT (cb->nlh->nlmsg_type); -if (!iwpm_valid_client (nl_client)) { -pr_info ("%s: Invalid port mapper client = %u\n" , - __func__, nl_client); -return ret; - }iwpm_set_registration (nl_client,IWPM_REG_INCOMPL );atomic_set (&echo_nlmsg_seq, cb->nlh->nlmsg_seq); iwpm_ulib_version =min_t (u16,IWPM_UABI_VERSION , abi_version);
drivers/infiniband/core/iwpm_util.c +0 -18
@@ -70,7 +70,6 @@ int iwpm_init(u8 nl_client)return -ENOMEM ; } -iwpm_set_valid (nl_client,1 );iwpm_set_registration (nl_client,IWPM_REG_UNDEF );pr_debug ("%s: Mapinfo and reminfo tables are created\n" , __func__);return 0 ;
@@ -90,7 +89,6 @@ int iwpm_exit(u8 nl_client)free_hash_bucket ();free_reminfo_bucket ();pr_debug ("%s: Resources are destroyed\n" , __func__); -iwpm_set_valid (nl_client,0 );iwpm_set_registration (nl_client,IWPM_REG_UNDEF );return 0 ; }
@@ -115,8 +113,6 @@ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,unsigned long flags;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) -return ret; map_info =kzalloc (sizeof (struct iwpm_mapping_info ),GFP_KERNEL );if (!map_info)return -ENOMEM ;
@@ -276,10 +272,6 @@ int iwpm_get_remote_info(struct sockaddr_storage *mapped_loc_addr,unsigned long flags;int ret = -EINVAL ; -if (!iwpm_valid_client (nl_client)) { -pr_info ("%s: Invalid client = %u\n" , __func__, nl_client); -return ret; - }spin_lock_irqsave (&iwpm_reminfo_lock, flags);if (iwpm_reminfo_bucket) { hash_bucket_head = get_reminfo_hash_bucket(
@@ -394,16 +386,6 @@ int iwpm_get_nlmsg_seq(void)return atomic_inc_return (&iwpm_admin.nlmsg_seq); } -int iwpm_valid_client (u8 nl_client) -{ -return iwpm_admin.client_list[nl_client]; -} - -void iwpm_set_valid (u8 nl_client,int valid) -{ - iwpm_admin.client_list[nl_client] = valid; -} -/* valid client */ u32 iwpm_get_registration (u8 nl_client) {
drivers/infiniband/core/iwpm_util.h +0 -17
@@ -91,7 +91,6 @@ struct iwpm_remote_info {struct iwpm_admin_data {atomic_t nlmsg_seq; -int client_list[RDMA_NL_NUM_CLIENTS ];u32 reg_list[RDMA_NL_NUM_CLIENTS ]; };
@@ -146,22 +145,6 @@ int iwpm_get_nlmsg_seq(void);*/ void iwpm_add_remote_info (struct iwpm_remote_info *reminfo); -/** -* iwpm_valid_client - Check if the port mapper client is valid -* @nl_client: The index of the netlink client -* -* Valid clients need to call iwpm_init() before using -* the port mapper -*/ -int iwpm_valid_client (u8 nl_client); - -/** -* iwpm_set_valid - Set the port mapper client to valid or not -* @nl_client: The index of the netlink client -* @valid: 1 if valid or 0 if invalid -*/ -void iwpm_set_valid (u8 nl_client,int valid); -/** * iwpm_check_registration - Check if the client registration * matches the given one
Signature · 1 line
2.31.1
PATCH 1/3 RDMA/iwcm: Release resources if iw_cm module initialization fails
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
The failure during iw_cm module initialization partially left the system with unreleased memory and other resources. Rewrite the module init/exit routines in such way that netlink commands will be opened only after successful initialization.
--- drivers/infiniband/core/iwcm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/infiniband/core/iwcm.c +12 -7
@@ -1186,29 +1186,34 @@ static int __init iw_cm_init(void) ret =iwpm_init (RDMA_NL_IWCM );if (ret) -pr_err ("iw_cm: couldn't init iwpm\n" ); -else -rdma_nl_register (RDMA_NL_IWCM , iwcm_nl_cb_table); +return ret; + iwcm_wq =alloc_ordered_workqueue ("iw_cm_wq" ,0 );if (!iwcm_wq) -return -ENOMEM ; + goto err_alloc; iwcm_ctl_table_hdr =register_net_sysctl (&init_net,"net/iw_cm" , iwcm_ctl_table);if (!iwcm_ctl_table_hdr) {pr_err ("iw_cm: couldn't register sysctl paths\n" ); -destroy_workqueue (iwcm_wq); -return -ENOMEM ; + goto err_sysctl; } +rdma_nl_register (RDMA_NL_IWCM , iwcm_nl_cb_table);return 0 ; + +err_sysctl: +destroy_workqueue (iwcm_wq); +err_alloc: +iwpm_exit (RDMA_NL_IWCM ); +return -ENOMEM ; } static void __exit iw_cm_cleanup(void) { +rdma_nl_unregister (RDMA_NL_IWCM );unregister_net_sysctl_table (iwcm_ctl_table_hdr);destroy_workqueue (iwcm_wq); -rdma_nl_unregister (RDMA_NL_IWCM );iwpm_exit (RDMA_NL_IWCM ); }
Signature · 1 line
2.31.1
Quoted 5 lines · Leon Romanovsky
From: Leon Romanovsky <[email protected]>
The iwpm is part of
iw_cmmodule load, it ensures that iwpm is valid prior to execution of any commands.
Quoted 8 lines
This series deletes such checks.
Thanks
Leon Romanovsky (3):
RDMA/iwcm: Release resources ifiw_cmmodule initialization fails RDMA/iwpm: Remove not-needed reference counting RDMA/iwpm: Rely on the upper to ensure that requests are valid
Applied to for-next, thanks
Jason