Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scst: Use RCU read lock when accessing sess_tgt_dev_list #151

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions scst/src/scst_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -14084,11 +14084,11 @@ int scst_get_max_lun_commands(struct scst_session *sess, uint64_t lun)

TRACE_ENTRY();

mutex_lock(&scst_mutex);

if (sess == NULL) {
struct scst_device *dev;

mutex_lock(&scst_mutex);

list_for_each_entry(dev, &scst_dev_list, dev_list_entry) {
if (dev->handler == &scst_null_devtype)
continue;
Expand All @@ -14097,40 +14097,48 @@ int scst_get_max_lun_commands(struct scst_session *sess, uint64_t lun)
if (res > dev->max_tgt_dev_commands)
res = dev->max_tgt_dev_commands;
}
goto out_unlock;

mutex_unlock(&scst_mutex);

goto out;
}

if (lun != NO_SUCH_LUN) {
struct list_head *head =
&sess->sess_tgt_dev_list[SESS_TGT_DEV_LIST_HASH_FN(lun)];
struct list_head *head;
struct scst_tgt_dev *tgt_dev;

list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) {
rcu_read_lock();
head = &sess->sess_tgt_dev_list[SESS_TGT_DEV_LIST_HASH_FN(lun)];

list_for_each_entry_rcu(tgt_dev, head, sess_tgt_dev_list_entry) {
if (tgt_dev->lun == lun) {
res = tgt_dev->dev->max_tgt_dev_commands;
TRACE_DBG("tgt_dev %p, dev %s, max_tgt_dev_commands "
"%d (res %d)", tgt_dev, tgt_dev->dev->virt_name,
tgt_dev->dev->max_tgt_dev_commands, res);
TRACE_DBG("tgt_dev %p, dev %s, max_tgt_dev_commands %d (res %d)",
tgt_dev, tgt_dev->dev->virt_name,
tgt_dev->dev->max_tgt_dev_commands, res);
break;
}
}
goto out_unlock;
rcu_read_unlock();

goto out;
}

rcu_read_lock();
for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) {
struct list_head *head = &sess->sess_tgt_dev_list[i];
struct scst_tgt_dev *tgt_dev;

list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) {
list_for_each_entry_rcu(tgt_dev, head, sess_tgt_dev_list_entry) {
if (res > tgt_dev->dev->max_tgt_dev_commands)
res = tgt_dev->dev->max_tgt_dev_commands;
}
}
rcu_read_unlock();

out_unlock:
mutex_unlock(&scst_mutex);

out:
TRACE_EXIT_RES(res);

return res;
}
EXPORT_SYMBOL(scst_get_max_lun_commands);
Expand Down
4 changes: 3 additions & 1 deletion scst/src/scst_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2557,11 +2557,12 @@ static ssize_t scst_tgt_forward_dst_store(struct kobject *kobj,
list_for_each_entry(sess, &tgt->sess_list, sess_list_entry) {
int i;

rcu_read_lock();
for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) {
struct list_head *head = &sess->sess_tgt_dev_list[i];
struct scst_tgt_dev *tgt_dev;

list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) {
list_for_each_entry_rcu(tgt_dev, head, sess_tgt_dev_list_entry) {
if (tgt->tgt_forward_dst)
set_bit(SCST_TGT_DEV_FORWARD_DST,
&tgt_dev->tgt_dev_flags);
Expand All @@ -2570,6 +2571,7 @@ static ssize_t scst_tgt_forward_dst_store(struct kobject *kobj,
&tgt_dev->tgt_dev_flags);
}
}
rcu_read_unlock();
}

if (tgt->tgt_forward_dst)
Expand Down
18 changes: 10 additions & 8 deletions scst/src/scst_targ.c
Original file line number Diff line number Diff line change
Expand Up @@ -6153,7 +6153,6 @@ static int scst_abort_all_nexus_loss_sess(struct scst_mgmt_cmd *mcmd,
int res;
int i;
struct scst_session *sess = mcmd->sess;
struct scst_tgt_dev *tgt_dev;

TRACE_ENTRY();

Expand All @@ -6168,23 +6167,25 @@ static int scst_abort_all_nexus_loss_sess(struct scst_mgmt_cmd *mcmd,
rcu_read_lock();
for (i = 0; i < SESS_TGT_DEV_LIST_HASH_SIZE; i++) {
struct list_head *head = &sess->sess_tgt_dev_list[i];
struct scst_tgt_dev *tgt_dev;

list_for_each_entry_rcu(tgt_dev, head,
sess_tgt_dev_list_entry) {
__scst_abort_task_set(mcmd, tgt_dev);

scst_call_dev_task_mgmt_fn_received(mcmd, tgt_dev);

tm_dbg_task_mgmt(tgt_dev->dev, "NEXUS LOSS SESS or "
"ABORT ALL SESS or UNREG SESS",
tm_dbg_task_mgmt(tgt_dev->dev,
"NEXUS LOSS SESS or ABORT ALL SESS or UNREG SESS",
(mcmd->fn == SCST_UNREG_SESS_TM));
}
if (nexus_loss_unreg_sess) {
/*
* We need at first abort all affected commands and
* only then release them as part of clearing ACA
*/
list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) {
list_for_each_entry_rcu(tgt_dev, head,
sess_tgt_dev_list_entry) {
scst_clear_aca(tgt_dev,
(tgt_dev != mcmd->mcmd_tgt_dev));
}
Expand Down Expand Up @@ -6253,22 +6254,23 @@ static int scst_abort_all_nexus_loss_tgt(struct scst_mgmt_cmd *mcmd,
struct scst_tgt_dev *tgt_dev;

list_for_each_entry_rcu(tgt_dev, head,
sess_tgt_dev_list_entry) {
sess_tgt_dev_list_entry) {
__scst_abort_task_set(mcmd, tgt_dev);

if (mcmd->sess == tgt_dev->sess)
scst_call_dev_task_mgmt_fn_received(
mcmd, tgt_dev);

tm_dbg_task_mgmt(tgt_dev->dev, "NEXUS LOSS or "
"ABORT ALL", 0);
tm_dbg_task_mgmt(tgt_dev->dev,
"NEXUS LOSS or ABORT ALL", 0);
}
if (nexus_loss) {
/*
* We need at first abort all affected commands and
* only then release them as part of clearing ACA
*/
list_for_each_entry(tgt_dev, head, sess_tgt_dev_list_entry) {
list_for_each_entry_rcu(tgt_dev, head,
sess_tgt_dev_list_entry) {
scst_clear_aca(tgt_dev,
(tgt_dev != mcmd->mcmd_tgt_dev));
}
Expand Down