Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/iwpm: Rely on the rdma_nl_[un]register() to ensure that requests are valid

The core netlink code alread guarentees that no netlink callback can be
running outside the rdma_nl_register/unregister() region and this
registration happens during module init/exit. Thus it is already prevented
that iwpm_valid_client() can ever fail. Remove it.

Link: https://lore.kernel.org/r/a9f05a78f9996bf6ea47099b5e02671bf742f5ab.1627048781.git.leonro@nvidia.com
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Leon Romanovsky and committed by
Jason Gunthorpe
bbafcbc2 bdb0e4e3

+1 -68
+1 -33
drivers/infiniband/core/iwpm_msg.c
··· 69 69 const char *err_str = ""; 70 70 int ret = -EINVAL; 71 71 72 - if (!iwpm_valid_client(nl_client)) { 73 - err_str = "Invalid port mapper client"; 74 - goto pid_query_error; 75 - } 76 72 if (iwpm_check_registration(nl_client, IWPM_REG_VALID) || 77 73 iwpm_user_pid == IWPM_PID_UNAVAILABLE) 78 74 return 0; ··· 149 153 const char *err_str = ""; 150 154 int ret = -EINVAL; 151 155 152 - if (!iwpm_valid_client(nl_client)) { 153 - err_str = "Invalid port mapper client"; 154 - goto add_mapping_error; 155 - } 156 156 if (!iwpm_valid_pid()) 157 157 return 0; 158 158 if (!iwpm_check_registration(nl_client, IWPM_REG_VALID)) { ··· 232 240 const char *err_str = ""; 233 241 int ret = -EINVAL; 234 242 235 - if (!iwpm_valid_client(nl_client)) { 236 - err_str = "Invalid port mapper client"; 237 - goto query_mapping_error; 238 - } 239 243 if (!iwpm_valid_pid()) 240 244 return 0; 241 245 if (!iwpm_check_registration(nl_client, IWPM_REG_VALID)) { ··· 319 331 const char *err_str = ""; 320 332 int ret = -EINVAL; 321 333 322 - if (!iwpm_valid_client(nl_client)) { 323 - err_str = "Invalid port mapper client"; 324 - goto remove_mapping_error; 325 - } 326 334 if (!iwpm_valid_pid()) 327 335 return 0; 328 336 if (iwpm_check_registration(nl_client, IWPM_REG_UNDEF)) { ··· 428 444 atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq); 429 445 pr_debug("%s: iWarp Port Mapper (pid = %d) is available!\n", 430 446 __func__, iwpm_user_pid); 431 - if (iwpm_valid_client(nl_client)) 432 - iwpm_set_registration(nl_client, IWPM_REG_VALID); 447 + iwpm_set_registration(nl_client, IWPM_REG_VALID); 433 448 register_pid_response_exit: 434 449 nlmsg_request->request_done = 1; 435 450 /* always for found nlmsg_request */ ··· 632 649 return ret; 633 650 634 651 nl_client = RDMA_NL_GET_CLIENT(cb->nlh->nlmsg_type); 635 - if (!iwpm_valid_client(nl_client)) { 636 - pr_info("%s: Invalid port mapper client = %u\n", 637 - __func__, nl_client); 638 - return ret; 639 - } 640 652 atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq); 641 653 642 654 local_sockaddr = (struct sockaddr_storage *) ··· 714 736 return ret; 715 737 } 716 738 nl_client = RDMA_NL_GET_CLIENT(cb->nlh->nlmsg_type); 717 - if (!iwpm_valid_client(nl_client)) { 718 - pr_info("%s: Invalid port mapper client = %u\n", 719 - __func__, nl_client); 720 - return ret; 721 - } 722 739 iwpm_set_registration(nl_client, IWPM_REG_INCOMPL); 723 740 atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq); 724 741 iwpm_user_pid = cb->nlh->nlmsg_pid; ··· 836 863 } 837 864 abi_version = nla_get_u16(nltb[IWPM_NLA_HELLO_ABI_VERSION]); 838 865 nl_client = RDMA_NL_GET_CLIENT(cb->nlh->nlmsg_type); 839 - if (!iwpm_valid_client(nl_client)) { 840 - pr_info("%s: Invalid port mapper client = %u\n", 841 - __func__, nl_client); 842 - return ret; 843 - } 844 866 iwpm_set_registration(nl_client, IWPM_REG_INCOMPL); 845 867 atomic_set(&echo_nlmsg_seq, cb->nlh->nlmsg_seq); 846 868 iwpm_ulib_version = min_t(u16, IWPM_UABI_VERSION, abi_version);
-18
drivers/infiniband/core/iwpm_util.c
··· 70 70 return -ENOMEM; 71 71 } 72 72 73 - iwpm_set_valid(nl_client, 1); 74 73 iwpm_set_registration(nl_client, IWPM_REG_UNDEF); 75 74 pr_debug("%s: Mapinfo and reminfo tables are created\n", __func__); 76 75 return 0; ··· 89 90 free_hash_bucket(); 90 91 free_reminfo_bucket(); 91 92 pr_debug("%s: Resources are destroyed\n", __func__); 92 - iwpm_set_valid(nl_client, 0); 93 93 iwpm_set_registration(nl_client, IWPM_REG_UNDEF); 94 94 return 0; 95 95 } ··· 113 115 unsigned long flags; 114 116 int ret = -EINVAL; 115 117 116 - if (!iwpm_valid_client(nl_client)) 117 - return ret; 118 118 map_info = kzalloc(sizeof(struct iwpm_mapping_info), GFP_KERNEL); 119 119 if (!map_info) 120 120 return -ENOMEM; ··· 272 276 unsigned long flags; 273 277 int ret = -EINVAL; 274 278 275 - if (!iwpm_valid_client(nl_client)) { 276 - pr_info("%s: Invalid client = %u\n", __func__, nl_client); 277 - return ret; 278 - } 279 279 spin_lock_irqsave(&iwpm_reminfo_lock, flags); 280 280 if (iwpm_reminfo_bucket) { 281 281 hash_bucket_head = get_reminfo_hash_bucket( ··· 384 392 int iwpm_get_nlmsg_seq(void) 385 393 { 386 394 return atomic_inc_return(&iwpm_admin.nlmsg_seq); 387 - } 388 - 389 - int iwpm_valid_client(u8 nl_client) 390 - { 391 - return iwpm_admin.client_list[nl_client]; 392 - } 393 - 394 - void iwpm_set_valid(u8 nl_client, int valid) 395 - { 396 - iwpm_admin.client_list[nl_client] = valid; 397 395 } 398 396 399 397 /* valid client */
-17
drivers/infiniband/core/iwpm_util.h
··· 91 91 92 92 struct iwpm_admin_data { 93 93 atomic_t nlmsg_seq; 94 - int client_list[RDMA_NL_NUM_CLIENTS]; 95 94 u32 reg_list[RDMA_NL_NUM_CLIENTS]; 96 95 }; 97 96 ··· 144 145 * @reminfo: The remote info to be added 145 146 */ 146 147 void iwpm_add_remote_info(struct iwpm_remote_info *reminfo); 147 - 148 - /** 149 - * iwpm_valid_client - Check if the port mapper client is valid 150 - * @nl_client: The index of the netlink client 151 - * 152 - * Valid clients need to call iwpm_init() before using 153 - * the port mapper 154 - */ 155 - int iwpm_valid_client(u8 nl_client); 156 - 157 - /** 158 - * iwpm_set_valid - Set the port mapper client to valid or not 159 - * @nl_client: The index of the netlink client 160 - * @valid: 1 if valid or 0 if invalid 161 - */ 162 - void iwpm_set_valid(u8 nl_client, int valid); 163 148 164 149 /** 165 150 * iwpm_check_registration - Check if the client registration