iscsi changes for scsi-misc
Subsystems (5)
cover iscsi changes for scsi-misc
The following patches are some features and fixes for scsi-misc.
James, if you were going to merge the libiscsi locking changes here
http://www.spinics.net/lists/linux-scsi/msg69903.html
do not bother. The qlogic patches that were just merged had a conflict. The patches in the following emails should apply cleanly to misc.
PATCH 1/6 SCSI/libiscsi: Restructure iscsi_tcp r2t response logic
From: Shlomo Pongratz <[email protected]>
Restructure the iscsi_tcp_r2t_rsp routine in order to avoid allocating r2t from r2tpool.queue and returning it back in case the parameters rhdr->data_length and or rhdr->data_offset prohibit the requing.
Since the values of these parameters are known prior to the allocation, we can pre-check and thus avoid futile allocations.
--- drivers/scsi/libiscsi_tcp.c | 43 ++++++++++++++++++++++--------------------- 1 files changed, 22 insertions(+), 21 deletions(-)
drivers/scsi/libiscsi_tcp.c +22 -21
@@ -529,6 +529,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;struct iscsi_r2t_info *r2t;int r2tsn =be32_to_cpu (rhdr->r2tsn); +u32 data_length; +u32 data_offset;int rc;if (tcp_conn->in.datalen) {
@@ -554,40 +556,39 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)return 0 ; } - rc =kfifo_out (&tcp_task->r2tpool.queue, (void *)&r2t,sizeof (void *)); -if (!rc) { -iscsi_conn_printk (KERN_ERR , conn,"Could not allocate R2T. " -"Target has sent more R2Ts than it " -"negotiated for or driver has leaked.\n" ); -return ISCSI_ERR_PROTO ; - } - - r2t->exp_statsn = rhdr->statsn; - r2t->data_length =be32_to_cpu (rhdr->data_length); -if (r2t->data_length ==0 ) { + data_length =be32_to_cpu (rhdr->data_length); +if (data_length ==0 ) {iscsi_conn_printk (KERN_ERR , conn,"invalid R2T with zero data len\n" ); -kfifo_in (&tcp_task->r2tpool.queue, (void *)&r2t, -sizeof (void *));return ISCSI_ERR_DATALEN ; } -if (r2t->data_length > session->max_burst) +if (data_length > session->max_burst)ISCSI_DBG_TCP (conn,"invalid R2T with data len %u and max " "burst %u. Attempting to execute request.\n" , - r2t->data_length, session->max_burst); + data_length, session->max_burst); - r2t->data_offset =be32_to_cpu (rhdr->data_offset); -if (r2t->data_offset + r2t->data_length >scsi_out (task->sc)->length) { + data_offset =be32_to_cpu (rhdr->data_offset); +if (data_offset + data_length >scsi_out (task->sc)->length) {iscsi_conn_printk (KERN_ERR , conn,"invalid R2T with data len %u at offset %u " -"and total length %d\n" , r2t->data_length, - r2t->data_offset,scsi_out (task->sc)->length); -kfifo_in (&tcp_task->r2tpool.queue, (void *)&r2t, -sizeof (void *)); +"and total length %d\n" , data_length, + data_offset,scsi_out (task->sc)->length);return ISCSI_ERR_DATALEN ; } + rc =kfifo_out (&tcp_task->r2tpool.queue, (void *)&r2t,sizeof (void *)); +if (!rc) { +iscsi_conn_printk (KERN_ERR , conn,"Could not allocate R2T. " +"Target has sent more R2Ts than it " +"negotiated for or driver has leaked.\n" ); +return ISCSI_ERR_PROTO ; + } + + r2t->exp_statsn = rhdr->statsn; + r2t->data_length = data_length; + r2t->data_offset = data_offset; + r2t->ttt = rhdr->ttt;/* no flip */ r2t->datasn =0 ; r2t->sent =0 ;
Signature · 1 line
1.7.1
PATCH 2/6 SCSI/libiscsi: Reduce locking contention in fast path
In reply to [email protected]From: Shlomo Pongratz <[email protected]>
Replace the session lock with two locks, a forward lock and a backwards lock named frwd_lock and back_lock respectively.
The forward lock protects resources that change while sending a request to the target, such as cmdsn, queued_cmdsn, and allocating task from the commands' pool with kfifo_out.
The backward lock protects resources that change while processing a response or in error path, such as cmdsn_exp, cmdsn_max, and returning tasks to the commands' pool with kfifo_in.
Under a steady state fast-path situation, that is when one or more processes/threads submit IO to an iscsi device and a single kernel upcall (e.g softirq) is dealing with processing of responses without errors, this patch eliminates the contention between the queuecommand()/request response/scsi_done() flows associated with iscsi sessions.
Between the forward and the backward locks exists a strict locking hierarchy.
The mutual exclusion zone protected by the forward lock can enclose the mutual exclusion zone protected by the backward lock but not vice versa.
For example, in iscsi_conn_teardown or in iscsi_xmit_data when there is a
failure and __iscsi_put_task is called, the backward lock is taken while the
forward lock is still taken. On the other hand, if in the RX path a nop is
to be sent, for example in iscsi_handle_reject or __iscsi_complete_pdu than
the forward lock is released and the backward lock is taken for the duration
of iscsi_send_nopout, later the backward lock is released and the forward
lock is retaken.
libiscsi_tcp uses two kernel fifos the r2t pool and the r2t queue.
The insertion and deletion from these queues didn't corespond to the assumption taken by the new forward/backwards session locking paradigm.
That is, in iscsi_tcp_clenup_task which belongs to the RX (backwards) path, r2t is taken out from r2t queue and inserted to the r2t pool. In iscsi_tcp_get_curr_r2t which belong to the TX (forward) path, r2t is also inserted to the r2t pool and another r2t is pulled from r2t queue.
Only in iscsi_tcp_r2t_rsp which is called in the RX path but can requeue to the TX path, r2t is taken from the r2t pool and inserted to the r2t queue.
In order to cope with this situation, two spin locks were added, pool2queue and queue2pool. The former protects extracting from the r2t pool and inserting to the r2t queue, and the later protects the extracing from the r2t queue and inserting to the r2t pool.
--- drivers/scsi/be2iscsi/be_main.c | 26 +++--- drivers/scsi/bnx2i/bnx2i_hwi.c | 46 +++++----- drivers/scsi/bnx2i/bnx2i_iscsi.c | 8 +- drivers/scsi/iscsi_tcp.c | 22 ++-- drivers/scsi/libiscsi.c | 192 ++++++++++++++++++++++---------------- drivers/scsi/libiscsi_tcp.c | 28 ++++-- drivers/scsi/qla4xxx/ql4_isr.c | 4 +- include/scsi/libiscsi.h | 17 +++- include/scsi/libiscsi_tcp.h | 2 + 9 files changed, 195 insertions(+), 150 deletions(-)
drivers/scsi/be2iscsi/be_main.c +13 -13
@@ -232,20 +232,20 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc) cls_session =starget_to_session (scsi_target (sc->device)); session = cls_session->dd_data; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (!aborted_task || !aborted_task->sc) {/* we raced */ -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->fwrd_lock);return SUCCESS ; } aborted_io_task = aborted_task->dd_data;if (!aborted_io_task->scsi_cmnd) {/* raced or invalid command */ -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->fwrd_lock);return SUCCESS ; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->fwrd_lock);/* Invalidate WRB Posted for this Task */ AMAP_SET_BITS(struct amap_iscsi_wrb, invld, aborted_io_task->pwrb_handle->pwrb,
@@ -307,9 +307,9 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)/* invalidate iocbs */ cls_session =starget_to_session (scsi_target (sc->device)); session = cls_session->dd_data; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (!session->leadconn || session->state !=ISCSI_STATE_LOGGED_IN ) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return FAILED ; } conn = session->leadconn;
@@ -338,7 +338,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) num_invalidate++; inv_tbl++; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock); inv_tbl = phba->inv_tbl; nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
@@ -1150,9 +1150,9 @@ beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,return 1 ; } -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);__iscsi_complete_pdu (conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock);return 0 ; }
@@ -1568,7 +1568,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, pwrb = pwrb_handle->pwrb; type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);switch (type) {case HWH_TYPE_IO :case HWH_TYPE_IO_RD :
@@ -1607,7 +1607,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,break ; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock); } static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
@@ -4646,9 +4646,9 @@ beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,* login/startup related tasks. */ beiscsi_conn->login_in_progress =0 ; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);beiscsi_cleanup_task (task); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock); pwrb_handle =alloc_wrb_handle (phba, beiscsi_conn->beiscsi_conn_cid);
drivers/scsi/bnx2i/bnx2i_hwi.c +23 -23
178 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_iscsi.c +4 -4
@@ -1169,10 +1169,10 @@ static void bnx2i_cleanup_task(struct iscsi_task *task)if (task->state ==ISCSI_TASK_ABRT_TMF ) {bnx2i_send_cmd_cleanup_req (hba, task->dd_data); -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->back_lock);wait_for_completion_timeout (&bnx2i_conn->cmd_cleanup_cmpl,msecs_to_jiffies (ISCSI_CMD_CLEANUP_TIMEOUT )); -spin_lock_bh (&conn->session->lock); +spin_lock_bh (&conn->session->back_lock); }bnx2i_iscsi_unmap_sg_list (task->dd_data); }
@@ -2059,7 +2059,7 @@ int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep) goto out;if (session) { -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (bnx2i_ep->state !=EP_STATE_TCP_FIN_RCVD ) {if (session->state ==ISCSI_STATE_LOGGING_OUT ) {if (bnx2i_ep->state ==EP_STATE_LOGOUT_SENT ) {
@@ -2075,7 +2075,7 @@ int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep) }else close =1 ; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock); } bnx2i_ep->state =EP_STATE_DISCONN_START ;
drivers/scsi/iscsi_tcp.c +11 -11
@@ -593,9 +593,9 @@ static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn)iscsi_sw_tcp_conn_restore_callbacks (conn);sock_put (sock->sk); -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock); tcp_sw_conn->sock =NULL ; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);sockfd_put (sock); }
@@ -663,10 +663,10 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,if (err) goto free_socket; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);/* bind iSCSI connection and socket */ tcp_sw_conn->sock = sock; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);/* setup Socket parameters */ sk = sock->sk;
@@ -726,14 +726,14 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,switch (param) {case ISCSI_PARAM_CONN_PORT :case ISCSI_PARAM_CONN_ADDRESS : -spin_lock_bh (&conn->session->lock); +spin_lock_bh (&conn->session->frwd_lock);if (!tcp_sw_conn || !tcp_sw_conn->sock) { -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->frwd_lock);return -ENOTCONN ; } rc =kernel_getpeername (tcp_sw_conn->sock, (struct sockaddr *)&addr, &len); -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->frwd_lock);if (rc)return rc;
@@ -759,23 +759,23 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,switch (param) {case ISCSI_HOST_PARAM_IPADDRESS : -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock); conn = session->leadconn;if (!conn) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return -ENOTCONN ; } tcp_conn = conn->dd_data; tcp_sw_conn = tcp_conn->dd_data;if (!tcp_sw_conn->sock) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return -ENOTCONN ; } rc =kernel_getsockname (tcp_sw_conn->sock, (struct sockaddr *)&addr, &len); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);if (rc)return rc;
drivers/scsi/libiscsi.c +110 -82
643 lines not on this page · raw message
drivers/scsi/libiscsi_tcp.c +18 -10
@@ -446,7 +446,7 @@ iscsi_tcp_data_recv_prep(struct iscsi_tcp_conn *tcp_conn)* iscsi_tcp_cleanup_task - free tcp_task resources * @task: iscsi task * -* must be called with session lock +* must be called with session back_lock */ void iscsi_tcp_cleanup_task (struct iscsi_task *task) {
@@ -457,6 +457,7 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task)if (!task->sc)return ; +spin_lock_bh (&tcp_task->queue2pool);/* flush task's r2t queues */ while (kfifo_out (&tcp_task->r2tqueue, (void *)&r2t,sizeof (void *))) { kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
@@ -470,6 +471,7 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task) sizeof(void*)); tcp_task->r2t =NULL ; } +spin_unlock_bh (&tcp_task->queue2pool); }EXPORT_SYMBOL_GPL (iscsi_tcp_cleanup_task);
@@ -577,11 +579,13 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)return ISCSI_ERR_DATALEN ; } +spin_lock (&tcp_task->pool2queue); rc =kfifo_out (&tcp_task->r2tpool.queue, (void *)&r2t,sizeof (void *));if (!rc) {iscsi_conn_printk (KERN_ERR , conn,"Could not allocate R2T. " "Target has sent more R2Ts than it " "negotiated for or driver has leaked.\n" ); +spin_unlock (&tcp_task->pool2queue);return ISCSI_ERR_PROTO ; }
@@ -596,6 +600,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) tcp_task->exp_datasn = r2tsn +1 ;kfifo_in (&tcp_task->r2tqueue, (void *)&r2t,sizeof (void *)); conn->r2t_pdus_cnt++; +spin_unlock (&tcp_task->pool2queue);iscsi_requeue_task (task);return 0 ;
@@ -668,14 +673,14 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)switch (opcode) {case ISCSI_OP_SCSI_DATA_IN : -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_ctask (conn, hdr->itt);if (!task) rc =ISCSI_ERR_BAD_ITT ;else rc =iscsi_tcp_data_in (conn, task);if (rc) { -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);break ; }
@@ -708,11 +713,11 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr) tcp_conn->in.datalen, iscsi_tcp_process_data_in, rx_hash); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);return rc; } rc =__iscsi_complete_pdu (conn, hdr,NULL ,0 ); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);break ;case ISCSI_OP_SCSI_CMD_RSP :if (tcp_conn->in.datalen) {
@@ -722,18 +727,20 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr) rc =iscsi_complete_pdu (conn, hdr,NULL ,0 );break ;case ISCSI_OP_R2T : -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_ctask (conn, hdr->itt); +spin_unlock (&conn->session->back_lock);if (!task) rc =ISCSI_ERR_BAD_ITT ;else if (ahslen) rc =ISCSI_ERR_AHSLEN ;else if (task->sc->sc_data_direction ==DMA_TO_DEVICE ) { task->last_xfer = jiffies; +spin_lock (&conn->session->frwd_lock); rc =iscsi_tcp_r2t_rsp (conn, task); +spin_unlock (&conn->session->frwd_lock); }else rc =ISCSI_ERR_PROTO ; -spin_unlock (&conn->session->lock);break ;case ISCSI_OP_LOGIN_RSP :case ISCSI_OP_TEXT_RSP :
@@ -981,14 +988,13 @@ EXPORT_SYMBOL_GPL(iscsi_tcp_task_init);static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t (struct iscsi_task *task) { -struct iscsi_session *session = task->conn->session;struct iscsi_tcp_task *tcp_task = task->dd_data;struct iscsi_r2t_info *r2t =NULL ;if (iscsi_task_has_unsol_data (task)) r2t = &task->unsol_r2t;else { -spin_lock_bh (&session->lock); +spin_lock_bh (&tcp_task->queue2pool);if (tcp_task->r2t) { r2t = tcp_task->r2t;/* Continue with this R2T? */
@@ -1010,7 +1016,7 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)else r2t = tcp_task->r2t; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&tcp_task->queue2pool); }return r2t;
@@ -1140,6 +1146,8 @@ int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session)iscsi_pool_free (&tcp_task->r2tpool); goto r2t_alloc_fail; } +spin_lock_init (&tcp_task->pool2queue); +spin_lock_init (&tcp_task->queue2pool); }return 0 ;
drivers/scsi/qla4xxx/ql4_isr.c +2 -2
@@ -385,9 +385,9 @@ static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha, cls_conn = ddb_entry->conn; conn = cls_conn->dd_data; -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_task (conn, itt); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);if (task ==NULL ) {ql4_printk (KERN_ERR , ha,"%s: Task is NULL\n" , __func__);
include/scsi/libiscsi.h +12 -5
@@ -327,12 +327,19 @@ struct iscsi_session {struct iscsi_transport *tt;struct Scsi_Host *host;struct iscsi_conn *leadconn;/* leading connection */ -spinlock_t lock;/* protects session state, * -* sequence numbers, * +/* Between the forward and the backward locks exists a strict locking +* hierarchy. The mutual exclusion zone protected by the forward lock +* can enclose the mutual exclusion zone protected by the backward lock +* but not vice versa. +*/ +spinlock_t frwd_lock;/* protects session state, * +* cmdsn, queued_cmdsn * * session resources: * -* - cmdpool, * -* - mgmtpool, * -* - r2tpool */ +* - cmdpool kfifo_out , * +* - mgmtpool, */ +spinlock_t back_lock;/* protects cmdsn_exp * +* cmdsn_max, * +* cmdpool kfifo_in */ int state;/* session state */ int age;/* counts session re-opens */
include/scsi/libiscsi_tcp.h +2 -0
@@ -83,6 +83,8 @@ struct iscsi_tcp_task {struct iscsi_pool r2tpool;struct kfifo r2tqueue;void *dd_data; +spinlock_t pool2queue; +spinlock_t queue2pool; };enum {
Signature · 1 line
1.7.1
PATCH 3/6 SCSI/libiscsi: Remove unneeded code
In reply to [email protected]From: Shlomo Pongratz <[email protected]>
We never will have a closed window and something on one of those lists.
--- drivers/scsi/libiscsi.c | 12 ------------ 1 files changed, 0 insertions(+), 12 deletions(-)
drivers/scsi/libiscsi.c +0 -12
@@ -108,18 +108,6 @@ static void __iscsi_update_cmdsn(struct iscsi_session *session,if (exp_cmdsn != session->exp_cmdsn && !iscsi_sna_lt (exp_cmdsn, session->exp_cmdsn)) session->exp_cmdsn = exp_cmdsn; - -if (max_cmdsn != session->max_cmdsn && - !iscsi_sna_lt (max_cmdsn, session->max_cmdsn)) { - session->max_cmdsn = max_cmdsn; -/* -* if the window closed with IO queued, then kick the -* xmit thread -*/ -if (!list_empty (&session->leadconn->cmdqueue) || - !list_empty (&session->leadconn->mgmtqueue)) -iscsi_conn_queue_work (session->leadconn); - } }void iscsi_update_cmdsn (struct iscsi_session *session,struct iscsi_nopin *hdr)
Signature · 1 line
1.7.1
PATCH 4/6 be2iscsi: fix lun test in device reset callout
In reply to [email protected]From: Mike Christie <[email protected]>
We want to be checking the scsi_cmnd's lun against the possible tasks in the driver. Current check tests task against itself which was useless.
--- drivers/scsi/be2iscsi/be_main.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/be2iscsi/be_main.c +1 -1
@@ -325,7 +325,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)if (!abrt_task->sc || abrt_task->state ==ISCSI_TASK_FREE )continue ; -if (abrt_task->sc->device->lun != abrt_task->sc->device->lun) +if (sc->device->lun != abrt_task->sc->device->lun)continue ;/* Invalidate WRB Posted for this Task */
Signature · 1 line
1.7.1
PATCH 5/6 iscsi_boot_sysfs: Fix a memory leak in iscsi_boot_destroy_kset()
In reply to [email protected]From: Ethan Zhao <[email protected]>
Load and unload iscsi_ibft module will cause kernel memory leak, fix it in scsi/iscsi_boot_sysfs.c iscsi_boot_destroy_kset().
--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/scsi/iscsi_boot_sysfs.c +1 -0
@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset);
Signature · 1 line
1.7.1
PATCH 6/6 iscsi_tcp: check for valid session before accessing
In reply to [email protected]From: Mike Christie <[email protected]>
Check that the session is setup before accessing its connection. This fixes a oops where userspace tries to get the ip address before the session is bound to a host.
--- drivers/scsi/iscsi_tcp.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/scsi/iscsi_tcp.c +3 -0
@@ -759,6 +759,9 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,switch (param) {case ISCSI_HOST_PARAM_IPADDRESS : +if (!session) +return -ENOTCONN ; +spin_lock_bh (&session->frwd_lock); conn = session->leadconn;if (!conn) {
Signature · 1 line
1.7.1
Re: [PATCH 2/6] SCSI/libiscsi: Reduce locking contention in fast path
In reply to [email protected]Quoted 4 lines · On 12/20/2013 12:53 PM, [email protected] wrote:
From: Shlomo Pongratz <[email protected]>
Replace the session lock with two locks, a forward lock and a backwards lock named
frwd_lockandback_lockrespectively.
.....
Quoted 5 lines
Signed-off-by Shlomo Pongratz <[email protected]>Signed-off-by Or Gerlitz <[email protected]>[minor fix up to apply cleanly]Signed-off-by Mike Christie <[email protected]>
James, I messed up and sent the wrong patch. I sent the busted patch in this email. I am attaching the correct patch.
Quoted 1 line
From
d3d0305a320b46d5ecc67b505a978c1fd35f5bfbMon Sep 17 00:00:00 2001
From: Shlomo Pongratz <[email protected]>
Date: Fri, 17 Jan 2014 01:53:54 -0600
Subject: [PATCH 2/2] SCSI/libiscsi: Reduce locking contention in fast path (v2)
Replace the session lock with two locks, a forward lock and a backwards lock named frwd_lock and back_lock respectively.
The forward lock protects resources that change while sending a request to the target, such as cmdsn, queued_cmdsn, and allocating task from the commands' pool with kfifo_out.
The backward lock protects resources that change while processing a response or in error path, such as cmdsn_exp, cmdsn_max, and returning tasks to the commands' pool with kfifo_in.
Under a steady state fast-path situation, that is when one or more processes/threads submit IO to an iscsi device and a single kernel upcall (e.g softirq) is dealing with processing of responses without errors, this patch eliminates the contention between the queuecommand()/request response/scsi_done() flows associated with iscsi sessions.
Between the forward and the backward locks exists a strict locking hierarchy. The mutual exclusion zone protected by the forward lock can enclose the mutual exclusion zone protected by the backward lock but not vice versa.
For example, in iscsi_conn_teardown or in iscsi_xmit_data when there is a failure and __iscsi_put_task is called, the backward lock is taken while the forward lock is still taken. On the other hand, if in the RX path a nop is to be sent, for example in iscsi_handle_reject or __iscsi_complete_pdu than the forward lock is released and the backward lock is taken for the duration of iscsi_send_nopout, later the backward lock is released and the forward lock is retaken.
libiscsi_tcp uses two kernel fifos the r2t pool and the r2t queue.
The insertion and deletion from these queues didn't corespond to the assumption taken by the new forward/backwards session locking paradigm.
That is, in iscsi_tcp_clenup_task which belongs to the RX (backwards) path, r2t is taken out from r2t queue and inserted to the r2t pool. In iscsi_tcp_get_curr_r2t which belong to the TX (forward) path, r2t is also inserted to the r2t pool and another r2t is pulled from r2t queue.
Only in iscsi_tcp_r2t_rsp which is called in the RX path but can requeue to the TX path, r2t is taken from the r2t pool and inserted to the r2t queue.
In order to cope with this situation, two spin locks were added, pool2queue and queue2pool. The former protects extracting from the r2t pool and inserting to the r2t queue, and the later protects the extracing from the r2t queue and inserting to the r2t pool.
---
--- drivers/scsi/be2iscsi/be_main.c | 26 +++--- drivers/scsi/bnx2i/bnx2i_hwi.c | 46 ++++---- drivers/scsi/bnx2i/bnx2i_iscsi.c | 8 +- drivers/scsi/iscsi_tcp.c | 22 ++-- drivers/scsi/libiscsi.c | 214 +++++++++++++++++++++---------------- drivers/scsi/libiscsi_tcp.c | 28 +++-- drivers/scsi/qla4xxx/ql4_isr.c | 4 +- include/scsi/libiscsi.h | 17 ++- include/scsi/libiscsi_tcp.h | 2 + 9 files changed, 206 insertions(+), 161 deletions(-)
drivers/scsi/be2iscsi/be_main.c +13 -13
@@ -232,20 +232,20 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc) cls_session =starget_to_session (scsi_target (sc->device)); session = cls_session->dd_data; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (!aborted_task || !aborted_task->sc) {/* we raced */ -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return SUCCESS ; } aborted_io_task = aborted_task->dd_data;if (!aborted_io_task->scsi_cmnd) {/* raced or invalid command */ -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return SUCCESS ; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);/* Invalidate WRB Posted for this Task */ AMAP_SET_BITS(struct amap_iscsi_wrb, invld, aborted_io_task->pwrb_handle->pwrb,
@@ -307,9 +307,9 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)/* invalidate iocbs */ cls_session =starget_to_session (scsi_target (sc->device)); session = cls_session->dd_data; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (!session->leadconn || session->state !=ISCSI_STATE_LOGGED_IN ) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return FAILED ; } conn = session->leadconn;
@@ -338,7 +338,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) num_invalidate++; inv_tbl++; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock); inv_tbl = phba->inv_tbl; nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
@@ -1150,9 +1150,9 @@ beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,return 1 ; } -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);__iscsi_complete_pdu (conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock);return 0 ; }
@@ -1568,7 +1568,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, pwrb = pwrb_handle->pwrb; type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);switch (type) {case HWH_TYPE_IO :case HWH_TYPE_IO_RD :
@@ -1607,7 +1607,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,break ; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock); } static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
@@ -4646,9 +4646,9 @@ beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,* login/startup related tasks. */ beiscsi_conn->login_in_progress =0 ; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->back_lock);beiscsi_cleanup_task (task); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->back_lock); pwrb_handle =alloc_wrb_handle (phba, beiscsi_conn->beiscsi_conn_cid);
drivers/scsi/bnx2i/bnx2i_hwi.c +23 -23
178 lines not on this page · raw message
drivers/scsi/bnx2i/bnx2i_iscsi.c +4 -4
@@ -1169,10 +1169,10 @@ static void bnx2i_cleanup_task(struct iscsi_task *task)if (task->state ==ISCSI_TASK_ABRT_TMF ) {bnx2i_send_cmd_cleanup_req (hba, task->dd_data); -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->back_lock);wait_for_completion_timeout (&bnx2i_conn->cmd_cleanup_cmpl,msecs_to_jiffies (ISCSI_CMD_CLEANUP_TIMEOUT )); -spin_lock_bh (&conn->session->lock); +spin_lock_bh (&conn->session->back_lock); }bnx2i_iscsi_unmap_sg_list (task->dd_data); }
@@ -2059,7 +2059,7 @@ int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep) goto out;if (session) { -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);if (bnx2i_ep->state !=EP_STATE_TCP_FIN_RCVD ) {if (session->state ==ISCSI_STATE_LOGGING_OUT ) {if (bnx2i_ep->state ==EP_STATE_LOGOUT_SENT ) {
@@ -2075,7 +2075,7 @@ int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep) }else close =1 ; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock); } bnx2i_ep->state =EP_STATE_DISCONN_START ;
drivers/scsi/iscsi_tcp.c +11 -11
@@ -593,9 +593,9 @@ static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn)iscsi_sw_tcp_conn_restore_callbacks (conn);sock_put (sock->sk); -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock); tcp_sw_conn->sock =NULL ; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);sockfd_put (sock); }
@@ -663,10 +663,10 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,if (err) goto free_socket; -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock);/* bind iSCSI connection and socket */ tcp_sw_conn->sock = sock; -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);/* setup Socket parameters */ sk = sock->sk;
@@ -726,14 +726,14 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,switch (param) {case ISCSI_PARAM_CONN_PORT :case ISCSI_PARAM_CONN_ADDRESS : -spin_lock_bh (&conn->session->lock); +spin_lock_bh (&conn->session->frwd_lock);if (!tcp_sw_conn || !tcp_sw_conn->sock) { -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->frwd_lock);return -ENOTCONN ; } rc =kernel_getpeername (tcp_sw_conn->sock, (struct sockaddr *)&addr, &len); -spin_unlock_bh (&conn->session->lock); +spin_unlock_bh (&conn->session->frwd_lock);if (rc)return rc;
@@ -759,23 +759,23 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,switch (param) {case ISCSI_HOST_PARAM_IPADDRESS : -spin_lock_bh (&session->lock); +spin_lock_bh (&session->frwd_lock); conn = session->leadconn;if (!conn) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return -ENOTCONN ; } tcp_conn = conn->dd_data; tcp_sw_conn = tcp_conn->dd_data;if (!tcp_sw_conn->sock) { -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);return -ENOTCONN ; } rc =kernel_getsockname (tcp_sw_conn->sock, (struct sockaddr *)&addr, &len); -spin_unlock_bh (&session->lock); +spin_unlock_bh (&session->frwd_lock);if (rc)return rc;
drivers/scsi/libiscsi.c +121 -93
712 lines not on this page · raw message
drivers/scsi/libiscsi_tcp.c +18 -10
@@ -446,7 +446,7 @@ iscsi_tcp_data_recv_prep(struct iscsi_tcp_conn *tcp_conn)* iscsi_tcp_cleanup_task - free tcp_task resources * @task: iscsi task * -* must be called with session lock +* must be called with session back_lock */ void iscsi_tcp_cleanup_task (struct iscsi_task *task) {
@@ -457,6 +457,7 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task)if (!task->sc)return ; +spin_lock_bh (&tcp_task->queue2pool);/* flush task's r2t queues */ while (kfifo_out (&tcp_task->r2tqueue, (void *)&r2t,sizeof (void *))) { kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
@@ -470,6 +471,7 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task) sizeof(void*)); tcp_task->r2t =NULL ; } +spin_unlock_bh (&tcp_task->queue2pool); }EXPORT_SYMBOL_GPL (iscsi_tcp_cleanup_task);
@@ -577,11 +579,13 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)return ISCSI_ERR_DATALEN ; } +spin_lock (&tcp_task->pool2queue); rc =kfifo_out (&tcp_task->r2tpool.queue, (void *)&r2t,sizeof (void *));if (!rc) {iscsi_conn_printk (KERN_ERR , conn,"Could not allocate R2T. " "Target has sent more R2Ts than it " "negotiated for or driver has leaked.\n" ); +spin_unlock (&tcp_task->pool2queue);return ISCSI_ERR_PROTO ; }
@@ -596,6 +600,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task) tcp_task->exp_datasn = r2tsn +1 ;kfifo_in (&tcp_task->r2tqueue, (void *)&r2t,sizeof (void *)); conn->r2t_pdus_cnt++; +spin_unlock (&tcp_task->pool2queue);iscsi_requeue_task (task);return 0 ;
@@ -668,14 +673,14 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)switch (opcode) {case ISCSI_OP_SCSI_DATA_IN : -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_ctask (conn, hdr->itt);if (!task) rc =ISCSI_ERR_BAD_ITT ;else rc =iscsi_tcp_data_in (conn, task);if (rc) { -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);break ; }
@@ -708,11 +713,11 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr) tcp_conn->in.datalen, iscsi_tcp_process_data_in, rx_hash); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);return rc; } rc =__iscsi_complete_pdu (conn, hdr,NULL ,0 ); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);break ;case ISCSI_OP_SCSI_CMD_RSP :if (tcp_conn->in.datalen) {
@@ -722,18 +727,20 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr) rc =iscsi_complete_pdu (conn, hdr,NULL ,0 );break ;case ISCSI_OP_R2T : -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_ctask (conn, hdr->itt); +spin_unlock (&conn->session->back_lock);if (!task) rc =ISCSI_ERR_BAD_ITT ;else if (ahslen) rc =ISCSI_ERR_AHSLEN ;else if (task->sc->sc_data_direction ==DMA_TO_DEVICE ) { task->last_xfer = jiffies; +spin_lock (&conn->session->frwd_lock); rc =iscsi_tcp_r2t_rsp (conn, task); +spin_unlock (&conn->session->frwd_lock); }else rc =ISCSI_ERR_PROTO ; -spin_unlock (&conn->session->lock);break ;case ISCSI_OP_LOGIN_RSP :case ISCSI_OP_TEXT_RSP :
@@ -981,14 +988,13 @@ EXPORT_SYMBOL_GPL(iscsi_tcp_task_init);static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t (struct iscsi_task *task) { -struct iscsi_session *session = task->conn->session;struct iscsi_tcp_task *tcp_task = task->dd_data;struct iscsi_r2t_info *r2t =NULL ;if (iscsi_task_has_unsol_data (task)) r2t = &task->unsol_r2t;else { -spin_lock_bh (&session->lock); +spin_lock_bh (&tcp_task->queue2pool);if (tcp_task->r2t) { r2t = tcp_task->r2t;/* Continue with this R2T? */
@@ -1010,7 +1016,7 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)else r2t = tcp_task->r2t; } -spin_unlock_bh (&session->lock); +spin_unlock_bh (&tcp_task->queue2pool); }return r2t;
@@ -1140,6 +1146,8 @@ int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session)iscsi_pool_free (&tcp_task->r2tpool); goto r2t_alloc_fail; } +spin_lock_init (&tcp_task->pool2queue); +spin_lock_init (&tcp_task->queue2pool); }return 0 ;
drivers/scsi/qla4xxx/ql4_isr.c +2 -2
@@ -385,9 +385,9 @@ static void qla4xxx_passthru_status_entry(struct scsi_qla_host *ha, cls_conn = ddb_entry->conn; conn = cls_conn->dd_data; -spin_lock (&conn->session->lock); +spin_lock (&conn->session->back_lock); task =iscsi_itt_to_task (conn, itt); -spin_unlock (&conn->session->lock); +spin_unlock (&conn->session->back_lock);if (task ==NULL ) {ql4_printk (KERN_ERR , ha,"%s: Task is NULL\n" , __func__);
include/scsi/libiscsi.h +12 -5
@@ -327,12 +327,19 @@ struct iscsi_session {struct iscsi_transport *tt;struct Scsi_Host *host;struct iscsi_conn *leadconn;/* leading connection */ -spinlock_t lock;/* protects session state, * -* sequence numbers, * +/* Between the forward and the backward locks exists a strict locking +* hierarchy. The mutual exclusion zone protected by the forward lock +* can enclose the mutual exclusion zone protected by the backward lock +* but not vice versa. +*/ +spinlock_t frwd_lock;/* protects session state, * +* cmdsn, queued_cmdsn * * session resources: * -* - cmdpool, * -* - mgmtpool, * -* - r2tpool */ +* - cmdpool kfifo_out , * +* - mgmtpool, */ +spinlock_t back_lock;/* protects cmdsn_exp * +* cmdsn_max, * +* cmdpool kfifo_in */ int state;/* session state */ int age;/* counts session re-opens */
include/scsi/libiscsi_tcp.h +2 -0
@@ -83,6 +83,8 @@ struct iscsi_tcp_task {struct iscsi_pool r2tpool;struct kfifo r2tqueue;void *dd_data; +spinlock_t pool2queue; +spinlock_t queue2pool; };enum {
Signature · 1 line
1.7.1
Quoted 7 lines · On 12/20/2013 12:53 PM, [email protected] wrote:
The following patches are some features and fixes for scsi-misc.
James, if you were going to merge the libiscsi locking changes here
http://www.spinics.net/lists/linux-scsi/msg69903.html
do not bother. The qlogic patches that were just merged had a conflict. The patches in the following emails should apply cleanly to misc.
Ignore this patchset. It has a regression. I will resend when I am done testing a fix.