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

scsi: target: core: De-RCU of se_lun and se_lun acl

se_lun and se_lun_acl are immutable pointers of struct se_dev_entry.
Remove RCU usage for access to those pointers.

Link: https://lore.kernel.org/r/20220727214125.19647-3-d.bogdanov@yadro.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Dmitry Bogdanov and committed by
Martin K. Petersen
ef4f7e4b dd0a66ad

+27 -49
+1 -2
drivers/target/target_core_alua.c
··· 934 934 935 935 spin_lock(&lun->lun_deve_lock); 936 936 list_for_each_entry(se_deve, &lun->lun_deve_list, lun_link) { 937 - lacl = rcu_dereference_check(se_deve->se_lun_acl, 938 - lockdep_is_held(&lun->lun_deve_lock)); 937 + lacl = se_deve->se_lun_acl; 939 938 940 939 /* 941 940 * spc4r37 p.242:
+11 -18
drivers/target/target_core_device.c
··· 75 75 return TCM_WRITE_PROTECTED; 76 76 } 77 77 78 - se_lun = rcu_dereference(deve->se_lun); 78 + se_lun = deve->se_lun; 79 79 80 80 if (!percpu_ref_tryget_live(&se_lun->lun_ref)) { 81 81 se_lun = NULL; ··· 152 152 rcu_read_lock(); 153 153 deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun); 154 154 if (deve) { 155 - se_lun = rcu_dereference(deve->se_lun); 155 + se_lun = deve->se_lun; 156 156 157 157 if (!percpu_ref_tryget_live(&se_lun->lun_ref)) { 158 158 se_lun = NULL; ··· 216 216 217 217 rcu_read_lock(); 218 218 hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 219 - lun = rcu_dereference(deve->se_lun); 219 + lun = deve->se_lun; 220 220 if (!lun) { 221 221 pr_err("%s device entries device pointer is" 222 222 " NULL, but Initiator has access.\n", ··· 243 243 struct se_dev_entry *deve; 244 244 245 245 mutex_lock(&nacl->lun_entry_mutex); 246 - hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 247 - struct se_lun *lun = rcu_dereference_check(deve->se_lun, 248 - lockdep_is_held(&nacl->lun_entry_mutex)); 249 - core_disable_device_list_for_node(lun, deve, nacl, tpg); 250 - } 246 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) 247 + core_disable_device_list_for_node(deve->se_lun, deve, nacl, tpg); 251 248 mutex_unlock(&nacl->lun_entry_mutex); 252 249 } 253 250 ··· 331 334 mutex_lock(&nacl->lun_entry_mutex); 332 335 orig = target_nacl_find_deve(nacl, mapped_lun); 333 336 if (orig && orig->se_lun) { 334 - struct se_lun *orig_lun = rcu_dereference_check(orig->se_lun, 335 - lockdep_is_held(&nacl->lun_entry_mutex)); 337 + struct se_lun *orig_lun = orig->se_lun; 336 338 337 339 if (orig_lun != lun) { 338 340 pr_err("Existing orig->se_lun doesn't match new lun" ··· 351 355 return -EINVAL; 352 356 } 353 357 354 - rcu_assign_pointer(new->se_lun, lun); 355 - rcu_assign_pointer(new->se_lun_acl, lun_acl); 358 + new->se_lun = lun; 359 + new->se_lun_acl = lun_acl; 356 360 hlist_del_rcu(&orig->link); 357 361 hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); 358 362 mutex_unlock(&nacl->lun_entry_mutex); ··· 370 374 return 0; 371 375 } 372 376 373 - rcu_assign_pointer(new->se_lun, lun); 374 - rcu_assign_pointer(new->se_lun_acl, lun_acl); 377 + new->se_lun = lun; 378 + new->se_lun_acl = lun_acl; 375 379 hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); 376 380 mutex_unlock(&nacl->lun_entry_mutex); 377 381 ··· 450 454 451 455 mutex_lock(&nacl->lun_entry_mutex); 452 456 hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 453 - struct se_lun *tmp_lun = rcu_dereference_check(deve->se_lun, 454 - lockdep_is_held(&nacl->lun_entry_mutex)); 455 - 456 - if (lun != tmp_lun) 457 + if (lun != deve->se_lun) 457 458 continue; 458 459 459 460 core_disable_device_list_for_node(lun, deve, nacl, tpg);
+8 -20
drivers/target/target_core_pr.c
··· 739 739 if (!deve_tmp->se_lun_acl) 740 740 continue; 741 741 742 - lacl_tmp = rcu_dereference_check(deve_tmp->se_lun_acl, 743 - lockdep_is_held(&lun_tmp->lun_deve_lock)); 742 + lacl_tmp = deve_tmp->se_lun_acl; 744 743 nacl_tmp = lacl_tmp->se_lun_nacl; 745 744 /* 746 745 * Skip the matching struct se_node_acl that is allocated ··· 783 784 * the original *pr_reg is processed in 784 785 * __core_scsi3_add_registration() 785 786 */ 786 - dest_lun = rcu_dereference_check(deve_tmp->se_lun, 787 - kref_read(&deve_tmp->pr_kref) != 0); 787 + dest_lun = deve_tmp->se_lun; 788 788 789 789 pr_reg_atp = __core_scsi3_do_alloc_registration(dev, 790 790 nacl_tmp, dest_lun, deve_tmp, ··· 1435 1437 1436 1438 static int core_scsi3_lunacl_depend_item(struct se_dev_entry *se_deve) 1437 1439 { 1438 - struct se_lun_acl *lun_acl; 1439 - 1440 1440 /* 1441 1441 * For nacl->dynamic_node_acl=1 1442 1442 */ 1443 - lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1444 - kref_read(&se_deve->pr_kref) != 0); 1445 - if (!lun_acl) 1443 + if (!se_deve->se_lun_acl) 1446 1444 return 0; 1447 1445 1448 - return target_depend_item(&lun_acl->se_lun_group.cg_item); 1446 + return target_depend_item(&se_deve->se_lun_acl->se_lun_group.cg_item); 1449 1447 } 1450 1448 1451 1449 static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) 1452 1450 { 1453 - struct se_lun_acl *lun_acl; 1454 - 1455 1451 /* 1456 1452 * For nacl->dynamic_node_acl=1 1457 1453 */ 1458 - lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1459 - kref_read(&se_deve->pr_kref) != 0); 1460 - if (!lun_acl) { 1454 + if (!se_deve->se_lun_acl) { 1461 1455 kref_put(&se_deve->pr_kref, target_pr_kref_release); 1462 1456 return; 1463 1457 } 1464 1458 1465 - target_undepend_item(&lun_acl->se_lun_group.cg_item); 1459 + target_undepend_item(&se_deve->se_lun_acl->se_lun_group.cg_item); 1466 1460 kref_put(&se_deve->pr_kref, target_pr_kref_release); 1467 1461 } 1468 1462 ··· 1741 1751 * and then call __core_scsi3_add_registration() in the 1742 1752 * 2nd loop which will never fail. 1743 1753 */ 1744 - dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 1745 - kref_read(&dest_se_deve->pr_kref) != 0); 1754 + dest_lun = dest_se_deve->se_lun; 1746 1755 1747 1756 dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, 1748 1757 dest_node_acl, dest_lun, dest_se_deve, ··· 3435 3446 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl, 3436 3447 iport_ptr); 3437 3448 if (!dest_pr_reg) { 3438 - struct se_lun *dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 3439 - kref_read(&dest_se_deve->pr_kref) != 0); 3449 + struct se_lun *dest_lun = dest_se_deve->se_lun; 3440 3450 3441 3451 spin_unlock(&dev->dev_reservation_lock); 3442 3452 if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl,
+4 -6
drivers/target/target_core_stat.c
··· 877 877 struct se_lun_acl *lacl = auth_to_lacl(item); 878 878 struct se_node_acl *nacl = lacl->se_lun_nacl; 879 879 struct se_dev_entry *deve; 880 - struct se_lun *lun; 881 880 ssize_t ret; 882 881 883 882 rcu_read_lock(); ··· 885 886 rcu_read_unlock(); 886 887 return -ENODEV; 887 888 } 888 - lun = rcu_dereference(deve->se_lun); 889 + 889 890 /* scsiDeviceIndex */ 890 - ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); 891 + ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 891 892 rcu_read_unlock(); 892 893 return ret; 893 894 } ··· 1216 1217 struct se_lun_acl *lacl = iport_to_lacl(item); 1217 1218 struct se_node_acl *nacl = lacl->se_lun_nacl; 1218 1219 struct se_dev_entry *deve; 1219 - struct se_lun *lun; 1220 1220 ssize_t ret; 1221 1221 1222 1222 rcu_read_lock(); ··· 1224 1226 rcu_read_unlock(); 1225 1227 return -ENODEV; 1226 1228 } 1227 - lun = rcu_dereference(deve->se_lun); 1229 + 1228 1230 /* scsiDeviceIndex */ 1229 - ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); 1231 + ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 1230 1232 rcu_read_unlock(); 1231 1233 return ret; 1232 1234 }
+1 -1
drivers/target/target_core_xcopy.c
··· 88 88 struct se_device *this_dev; 89 89 int rc; 90 90 91 - this_lun = rcu_dereference(deve->se_lun); 91 + this_lun = deve->se_lun; 92 92 this_dev = rcu_dereference_raw(this_lun->lun_se_dev); 93 93 94 94 rc = target_xcopy_locate_se_dev_e4_iter(this_dev, dev_wwn);
+2 -2
include/target/target_core_base.h
··· 665 665 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ 666 666 struct kref pr_kref; 667 667 struct completion pr_comp; 668 - struct se_lun_acl __rcu *se_lun_acl; 668 + struct se_lun_acl *se_lun_acl; 669 669 spinlock_t ua_lock; 670 - struct se_lun __rcu *se_lun; 670 + struct se_lun *se_lun; 671 671 #define DEF_PR_REG_ACTIVE 1 672 672 unsigned long deve_flags; 673 673 struct list_head alua_port_list;