Skip to content

Commit ef4f7e4

Browse files
logostmartinkpetersen
authored andcommitted
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/[email protected] Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Dmitry Bogdanov <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent dd0a66a commit ef4f7e4

File tree

6 files changed

+27
-49
lines changed

6 files changed

+27
-49
lines changed

drivers/target/target_core_alua.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,7 @@ static void core_alua_queue_state_change_ua(struct t10_alua_tg_pt_gp *tg_pt_gp)
934934

935935
spin_lock(&lun->lun_deve_lock);
936936
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;
939938

940939
/*
941940
* spc4r37 p.242:

drivers/target/target_core_device.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ transport_lookup_cmd_lun(struct se_cmd *se_cmd)
7575
return TCM_WRITE_PROTECTED;
7676
}
7777

78-
se_lun = rcu_dereference(deve->se_lun);
78+
se_lun = deve->se_lun;
7979

8080
if (!percpu_ref_tryget_live(&se_lun->lun_ref)) {
8181
se_lun = NULL;
@@ -152,7 +152,7 @@ int transport_lookup_tmr_lun(struct se_cmd *se_cmd)
152152
rcu_read_lock();
153153
deve = target_nacl_find_deve(nacl, se_cmd->orig_fe_lun);
154154
if (deve) {
155-
se_lun = rcu_dereference(deve->se_lun);
155+
se_lun = deve->se_lun;
156156

157157
if (!percpu_ref_tryget_live(&se_lun->lun_ref)) {
158158
se_lun = NULL;
@@ -216,7 +216,7 @@ struct se_dev_entry *core_get_se_deve_from_rtpi(
216216

217217
rcu_read_lock();
218218
hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
219-
lun = rcu_dereference(deve->se_lun);
219+
lun = deve->se_lun;
220220
if (!lun) {
221221
pr_err("%s device entries device pointer is"
222222
" NULL, but Initiator has access.\n",
@@ -243,11 +243,8 @@ void core_free_device_list_for_node(
243243
struct se_dev_entry *deve;
244244

245245
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);
251248
mutex_unlock(&nacl->lun_entry_mutex);
252249
}
253250

@@ -334,8 +331,7 @@ int core_enable_device_list_for_node(
334331
mutex_lock(&nacl->lun_entry_mutex);
335332
orig = target_nacl_find_deve(nacl, mapped_lun);
336333
if (orig && orig->se_lun) {
337-
struct se_lun *orig_lun = rcu_dereference_check(orig->se_lun,
338-
lockdep_is_held(&nacl->lun_entry_mutex));
334+
struct se_lun *orig_lun = orig->se_lun;
339335

340336
if (orig_lun != lun) {
341337
pr_err("Existing orig->se_lun doesn't match new lun"
@@ -355,8 +351,8 @@ int core_enable_device_list_for_node(
355351
return -EINVAL;
356352
}
357353

358-
rcu_assign_pointer(new->se_lun, lun);
359-
rcu_assign_pointer(new->se_lun_acl, lun_acl);
354+
new->se_lun = lun;
355+
new->se_lun_acl = lun_acl;
360356
hlist_del_rcu(&orig->link);
361357
hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist);
362358
mutex_unlock(&nacl->lun_entry_mutex);
@@ -374,8 +370,8 @@ int core_enable_device_list_for_node(
374370
return 0;
375371
}
376372

377-
rcu_assign_pointer(new->se_lun, lun);
378-
rcu_assign_pointer(new->se_lun_acl, lun_acl);
373+
new->se_lun = lun;
374+
new->se_lun_acl = lun_acl;
379375
hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist);
380376
mutex_unlock(&nacl->lun_entry_mutex);
381377

@@ -454,10 +450,7 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
454450

455451
mutex_lock(&nacl->lun_entry_mutex);
456452
hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
457-
struct se_lun *tmp_lun = rcu_dereference_check(deve->se_lun,
458-
lockdep_is_held(&nacl->lun_entry_mutex));
459-
460-
if (lun != tmp_lun)
453+
if (lun != deve->se_lun)
461454
continue;
462455

463456
core_disable_device_list_for_node(lun, deve, nacl, tpg);

drivers/target/target_core_pr.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
739739
if (!deve_tmp->se_lun_acl)
740740
continue;
741741

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;
744743
nacl_tmp = lacl_tmp->se_lun_nacl;
745744
/*
746745
* Skip the matching struct se_node_acl that is allocated
@@ -784,8 +783,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
784783
* the original *pr_reg is processed in
785784
* __core_scsi3_add_registration()
786785
*/
787-
dest_lun = rcu_dereference_check(deve_tmp->se_lun,
788-
kref_read(&deve_tmp->pr_kref) != 0);
786+
dest_lun = deve_tmp->se_lun;
789787

790788
pr_reg_atp = __core_scsi3_do_alloc_registration(dev,
791789
nacl_tmp, dest_lun, deve_tmp,
@@ -1437,34 +1435,26 @@ static void core_scsi3_nodeacl_undepend_item(struct se_node_acl *nacl)
14371435

14381436
static int core_scsi3_lunacl_depend_item(struct se_dev_entry *se_deve)
14391437
{
1440-
struct se_lun_acl *lun_acl;
1441-
14421438
/*
14431439
* For nacl->dynamic_node_acl=1
14441440
*/
1445-
lun_acl = rcu_dereference_check(se_deve->se_lun_acl,
1446-
kref_read(&se_deve->pr_kref) != 0);
1447-
if (!lun_acl)
1441+
if (!se_deve->se_lun_acl)
14481442
return 0;
14491443

1450-
return target_depend_item(&lun_acl->se_lun_group.cg_item);
1444+
return target_depend_item(&se_deve->se_lun_acl->se_lun_group.cg_item);
14511445
}
14521446

14531447
static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
14541448
{
1455-
struct se_lun_acl *lun_acl;
1456-
14571449
/*
14581450
* For nacl->dynamic_node_acl=1
14591451
*/
1460-
lun_acl = rcu_dereference_check(se_deve->se_lun_acl,
1461-
kref_read(&se_deve->pr_kref) != 0);
1462-
if (!lun_acl) {
1452+
if (!se_deve->se_lun_acl) {
14631453
kref_put(&se_deve->pr_kref, target_pr_kref_release);
14641454
return;
14651455
}
14661456

1467-
target_undepend_item(&lun_acl->se_lun_group.cg_item);
1457+
target_undepend_item(&se_deve->se_lun_acl->se_lun_group.cg_item);
14681458
kref_put(&se_deve->pr_kref, target_pr_kref_release);
14691459
}
14701460

@@ -1751,8 +1741,7 @@ core_scsi3_decode_spec_i_port(
17511741
* and then call __core_scsi3_add_registration() in the
17521742
* 2nd loop which will never fail.
17531743
*/
1754-
dest_lun = rcu_dereference_check(dest_se_deve->se_lun,
1755-
kref_read(&dest_se_deve->pr_kref) != 0);
1744+
dest_lun = dest_se_deve->se_lun;
17561745

17571746
dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev,
17581747
dest_node_acl, dest_lun, dest_se_deve,
@@ -3446,8 +3435,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
34463435
dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
34473436
iport_ptr);
34483437
if (!dest_pr_reg) {
3449-
struct se_lun *dest_lun = rcu_dereference_check(dest_se_deve->se_lun,
3450-
kref_read(&dest_se_deve->pr_kref) != 0);
3438+
struct se_lun *dest_lun = dest_se_deve->se_lun;
34513439

34523440
spin_unlock(&dev->dev_reservation_lock);
34533441
if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl,

drivers/target/target_core_stat.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,6 @@ static ssize_t target_stat_auth_dev_show(struct config_item *item,
877877
struct se_lun_acl *lacl = auth_to_lacl(item);
878878
struct se_node_acl *nacl = lacl->se_lun_nacl;
879879
struct se_dev_entry *deve;
880-
struct se_lun *lun;
881880
ssize_t ret;
882881

883882
rcu_read_lock();
@@ -886,9 +885,9 @@ static ssize_t target_stat_auth_dev_show(struct config_item *item,
886885
rcu_read_unlock();
887886
return -ENODEV;
888887
}
889-
lun = rcu_dereference(deve->se_lun);
888+
890889
/* scsiDeviceIndex */
891-
ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
890+
ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index);
892891
rcu_read_unlock();
893892
return ret;
894893
}
@@ -1217,7 +1216,6 @@ static ssize_t target_stat_iport_dev_show(struct config_item *item,
12171216
struct se_lun_acl *lacl = iport_to_lacl(item);
12181217
struct se_node_acl *nacl = lacl->se_lun_nacl;
12191218
struct se_dev_entry *deve;
1220-
struct se_lun *lun;
12211219
ssize_t ret;
12221220

12231221
rcu_read_lock();
@@ -1226,9 +1224,9 @@ static ssize_t target_stat_iport_dev_show(struct config_item *item,
12261224
rcu_read_unlock();
12271225
return -ENODEV;
12281226
}
1229-
lun = rcu_dereference(deve->se_lun);
1227+
12301228
/* scsiDeviceIndex */
1231-
ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
1229+
ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index);
12321230
rcu_read_unlock();
12331231
return ret;
12341232
}

drivers/target/target_core_xcopy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int target_xcopy_locate_se_dev_e4(struct se_session *sess,
8888
struct se_device *this_dev;
8989
int rc;
9090

91-
this_lun = rcu_dereference(deve->se_lun);
91+
this_lun = deve->se_lun;
9292
this_dev = rcu_dereference_raw(this_lun->lun_se_dev);
9393

9494
rc = target_xcopy_locate_se_dev_e4_iter(this_dev, dev_wwn);

include/target/target_core_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ struct se_dev_entry {
665665
/* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */
666666
struct kref pr_kref;
667667
struct completion pr_comp;
668-
struct se_lun_acl __rcu *se_lun_acl;
668+
struct se_lun_acl *se_lun_acl;
669669
spinlock_t ua_lock;
670-
struct se_lun __rcu *se_lun;
670+
struct se_lun *se_lun;
671671
#define DEF_PR_REG_ACTIVE 1
672672
unsigned long deve_flags;
673673
struct list_head alua_port_list;

0 commit comments

Comments
 (0)