Fixes for two fairly obscure but annoying when triggered races in
 iSCSI.
 
 Signed-off-by: James E.J. Bottomley <jejb@linux.ibm.com>
 -----BEGIN PGP SIGNATURE-----
 
 iJwEABMIAEQWIQTnYEDbdso9F2cI+arnQslM7pishQUCX7gmiiYcamFtZXMuYm90
 dG9tbGV5QGhhbnNlbnBhcnRuZXJzaGlwLmNvbQAKCRDnQslM7pishcJeAP4v9I6j
 fh/0E3tU+Hb8ZerNoD8p2q7vdxeKkihXWw5/EwEA2SoFW6VNTrJdhUq1+hJ1QWOR
 Awrex3uy1m11ETLgIcM=
 =A1lM
 -----END PGP SIGNATURE-----

Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI fixes from James Bottomley:
 "Fixes for two fairly obscure but annoying when triggered races in
  iSCSI"

* tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi:
  scsi: target: iscsi: Fix cmd abort fabric stop race
  scsi: libiscsi: Fix NOP race condition
This commit is contained in:
Linus Torvalds 2020-11-20 16:24:28 -08:00
Родитель 4fd84bc969 f36199355c
Коммит 27bba9c532
3 изменённых файлов: 31 добавлений и 12 удалений

Просмотреть файл

@ -533,8 +533,8 @@ static void iscsi_complete_task(struct iscsi_task *task, int state)
if (conn->task == task) if (conn->task == task)
conn->task = NULL; conn->task = NULL;
if (conn->ping_task == task) if (READ_ONCE(conn->ping_task) == task)
conn->ping_task = NULL; WRITE_ONCE(conn->ping_task, NULL);
/* release get from queueing */ /* release get from queueing */
__iscsi_put_task(task); __iscsi_put_task(task);
@ -738,6 +738,9 @@ __iscsi_conn_send_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
task->conn->session->age); task->conn->session->age);
} }
if (unlikely(READ_ONCE(conn->ping_task) == INVALID_SCSI_TASK))
WRITE_ONCE(conn->ping_task, task);
if (!ihost->workq) { if (!ihost->workq) {
if (iscsi_prep_mgmt_task(conn, task)) if (iscsi_prep_mgmt_task(conn, task))
goto free_task; goto free_task;
@ -941,8 +944,11 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
struct iscsi_nopout hdr; struct iscsi_nopout hdr;
struct iscsi_task *task; struct iscsi_task *task;
if (!rhdr && conn->ping_task) if (!rhdr) {
return -EINVAL; if (READ_ONCE(conn->ping_task))
return -EINVAL;
WRITE_ONCE(conn->ping_task, INVALID_SCSI_TASK);
}
memset(&hdr, 0, sizeof(struct iscsi_nopout)); memset(&hdr, 0, sizeof(struct iscsi_nopout));
hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE; hdr.opcode = ISCSI_OP_NOOP_OUT | ISCSI_OP_IMMEDIATE;
@ -957,11 +963,12 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0); task = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
if (!task) { if (!task) {
if (!rhdr)
WRITE_ONCE(conn->ping_task, NULL);
iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n"); iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
return -EIO; return -EIO;
} else if (!rhdr) { } else if (!rhdr) {
/* only track our nops */ /* only track our nops */
conn->ping_task = task;
conn->last_ping = jiffies; conn->last_ping = jiffies;
} }
@ -984,7 +991,7 @@ static int iscsi_nop_out_rsp(struct iscsi_task *task,
struct iscsi_conn *conn = task->conn; struct iscsi_conn *conn = task->conn;
int rc = 0; int rc = 0;
if (conn->ping_task != task) { if (READ_ONCE(conn->ping_task) != task) {
/* /*
* If this is not in response to one of our * If this is not in response to one of our
* nops then it must be from userspace. * nops then it must be from userspace.
@ -1923,7 +1930,7 @@ static void iscsi_start_tx(struct iscsi_conn *conn)
*/ */
static int iscsi_has_ping_timed_out(struct iscsi_conn *conn) static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
{ {
if (conn->ping_task && if (READ_ONCE(conn->ping_task) &&
time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) + time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) +
(conn->ping_timeout * HZ), jiffies)) (conn->ping_timeout * HZ), jiffies))
return 1; return 1;
@ -2058,7 +2065,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
* Checking the transport already or nop from a cmd timeout still * Checking the transport already or nop from a cmd timeout still
* running * running
*/ */
if (conn->ping_task) { if (READ_ONCE(conn->ping_task)) {
task->have_checked_conn = true; task->have_checked_conn = true;
rc = BLK_EH_RESET_TIMER; rc = BLK_EH_RESET_TIMER;
goto done; goto done;

Просмотреть файл

@ -483,8 +483,7 @@ EXPORT_SYMBOL(iscsit_queue_rsp);
void iscsit_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd) void iscsit_aborted_task(struct iscsi_conn *conn, struct iscsi_cmd *cmd)
{ {
spin_lock_bh(&conn->cmd_lock); spin_lock_bh(&conn->cmd_lock);
if (!list_empty(&cmd->i_conn_node) && if (!list_empty(&cmd->i_conn_node))
!(cmd->se_cmd.transport_state & CMD_T_FABRIC_STOP))
list_del_init(&cmd->i_conn_node); list_del_init(&cmd->i_conn_node);
spin_unlock_bh(&conn->cmd_lock); spin_unlock_bh(&conn->cmd_lock);
@ -4083,12 +4082,22 @@ static void iscsit_release_commands_from_conn(struct iscsi_conn *conn)
spin_lock_bh(&conn->cmd_lock); spin_lock_bh(&conn->cmd_lock);
list_splice_init(&conn->conn_cmd_list, &tmp_list); list_splice_init(&conn->conn_cmd_list, &tmp_list);
list_for_each_entry(cmd, &tmp_list, i_conn_node) { list_for_each_entry_safe(cmd, cmd_tmp, &tmp_list, i_conn_node) {
struct se_cmd *se_cmd = &cmd->se_cmd; struct se_cmd *se_cmd = &cmd->se_cmd;
if (se_cmd->se_tfo != NULL) { if (se_cmd->se_tfo != NULL) {
spin_lock_irq(&se_cmd->t_state_lock); spin_lock_irq(&se_cmd->t_state_lock);
se_cmd->transport_state |= CMD_T_FABRIC_STOP; if (se_cmd->transport_state & CMD_T_ABORTED) {
/*
* LIO's abort path owns the cleanup for this,
* so put it back on the list and let
* aborted_task handle it.
*/
list_move_tail(&cmd->i_conn_node,
&conn->conn_cmd_list);
} else {
se_cmd->transport_state |= CMD_T_FABRIC_STOP;
}
spin_unlock_irq(&se_cmd->t_state_lock); spin_unlock_irq(&se_cmd->t_state_lock);
} }
} }

Просмотреть файл

@ -132,6 +132,9 @@ struct iscsi_task {
void *dd_data; /* driver/transport data */ void *dd_data; /* driver/transport data */
}; };
/* invalid scsi_task pointer */
#define INVALID_SCSI_TASK (struct iscsi_task *)-1l
static inline int iscsi_task_has_unsol_data(struct iscsi_task *task) static inline int iscsi_task_has_unsol_data(struct iscsi_task *task)
{ {
return task->unsol_r2t.data_length > task->unsol_r2t.sent; return task->unsol_r2t.data_length > task->unsol_r2t.sent;