qla2xxx target fixes
Subsystems (2)
cover qla2xxx target fixes
From: Roland Dreier <[email protected]>
Hi Nic / Arun:
Here are a few pretty major fixes that I hope can get into the 3.5 merge of this stuff (Steve's patch that saves 128MB of memory per port is maybe not strictly a fix but is pretty major).
Please review / apply.
Thanks!
Roland Dreier (2):
tcm_qla2xxx: Add hook so qla_target code can shutdown sessions
qla2xxx: Don't create duplicate target sessions
Steve Hodgson (1):
tcm_qla2xxx: Convert FC address map from flat array to btree
drivers/scsi/qla2xxx/Kconfig | 1 + drivers/scsi/qla2xxx/qla_target.c | 96 ++++++++--------- drivers/scsi/qla2xxx/qla_target.h | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 201 ++++++++++++++++-------------------- drivers/scsi/qla2xxx/tcm_qla2xxx.h | 22 +--- 5 files changed, 138 insertions(+), 183 deletions(-)
Signature · 1 line
1.7.9.5
PATCH 1/3 tcm_qla2xxx: Convert FC address map from flat array to btree
From: Steve Hodgson <[email protected]>
tcm_qla2xxx needs a map from 24-bit FC addresses to node ACL pointers to look up incoming commands. Current code keeps this as a flat vmalloc()ed array with 2^24 entries -- with 8-byte pointers, this consumes 128MB per FC port! Occupancy of this array is at most on the order of hundreds of entries (and even that would be a lot of initiators on an FC fabric), so this wastes a huge amount of memory.
Change this map to use the kernel's btree library; this reduces the memory used to be O(number of entries) and has no measurable speed impact (in fact since the data structure is now packed rather than sparse, the cache/TLB effects may actually make this a net win).
--- drivers/scsi/qla2xxx/Kconfig | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 195 ++++++++++++++++-------------------- drivers/scsi/qla2xxx/tcm_qla2xxx.h | 22 +--- 3 files changed, 90 insertions(+), 128 deletions(-)
drivers/scsi/qla2xxx/Kconfig +1 -0
@@ -30,6 +30,7 @@ config TCM_QLA2XXX tristate "TCM_QLA2XXX fabric module for Qlogic 2xxx series target mode HBAs" depends on SCSI_QLA_FC && TARGET_CORE select LIBFC + select BTREE default n ---help--- Say Y here to enable the TCM_QLA2XXX fabric module for Qlogic 2xxx series target mode HBAs
drivers/scsi/qla2xxx/tcm_qla2xxx.c +85 -110
304 lines not on this page · raw message
drivers/scsi/qla2xxx/tcm_qla2xxx.h +4 -18
@@ -1,4 +1,5 @@#include <target/target_core_base.h> +#include <linux/btree.h> #define TCM_QLA2XXX_VERSION "v0.1"/* length of ASCII WWPNs including pad */
@@ -45,21 +46,6 @@ struct tcm_qla2xxx_tpg {#define QLA_TPG_ATTRIB (tpg) (&(tpg)->tpg_attrib) -/* -* Used for the 24-bit lport->lport_fcport_map; -*/ -struct tcm_qla2xxx_fc_al_pa { -struct se_node_acl *se_nacl; -}; - -struct tcm_qla2xxx_fc_area { -struct tcm_qla2xxx_fc_al_pa al_pas[256 ]; -}; - -struct tcm_qla2xxx_fc_domain { -struct tcm_qla2xxx_fc_area areas[256 ]; -}; -struct tcm_qla2xxx_fc_loopid {struct se_node_acl *se_nacl; };
@@ -77,10 +63,10 @@ struct tcm_qla2xxx_lport {char lport_name[TCM_QLA2XXX_NAMELEN ];/* ASCII formatted WWPN+WWNN for NPIV FC Target Lport */ char lport_npiv_name[TCM_QLA2XXX_NPIV_NAMELEN ]; -/* vmalloc'ed memory for fc_port pointers in 24-bit FC Port ID space */ -char *lport_fcport_map; +/* map for fc_port pointers in 24-bit FC Port ID space */ +struct btree_head32 lport_fcport_map;/* vmalloc-ed memory for fc_port pointers for 16-bit FC loop ID */ -char *lport_loopid_map; +struct tcm_qla2xxx_fc_loopid *lport_loopid_map;/* Pointer to struct scsi_qla_host from qla2xxx LLD */ struct scsi_qla_host *qla_vha;/* Pointer to struct scsi_qla_host for NPIV VP from qla2xxx LLD */
Signature · 1 line
1.7.9.5
PATCH 2/3 tcm_qla2xxx: Add hook so qla_target code can shutdown sessions
In reply to Roland DreierFrom: Roland Dreier <[email protected]>
When qla_tgt_del_sess_work_fn() does a ->put_sess, that may drop the last reference to a session and free it. We need to make sure the session release function waits for all pending commands, or else we may hit use-after-free if those commands complete after the session is gone.
This won't happen unless we do target_splice_sess_cmd_list() via tcm_qla2xxx_shutdown_session(). So add a hook in qla_tgt_func_tmpl to let qla_target call ->shutdown_sess before ->put_sess.
--- drivers/scsi/qla2xxx/qla_target.c | 1 + drivers/scsi/qla2xxx/qla_target.h | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 6 ++++++ 3 files changed, 8 insertions(+)
drivers/scsi/qla2xxx/qla_target.c +1 -0
@@ -691,6 +691,7 @@ static void qlt_del_sess_work_fn(struct delayed_work *work)ql_dbg (ql_dbg_tgt_mgt, vha,0xf004 ,"Timeout: sess %p about to be deleted\n" , sess); + ha->tgt.tgt_ops->shutdown_sess (sess); ha->tgt.tgt_ops->put_sess (sess); }
drivers/scsi/qla2xxx/qla_target.h +1 -0
@@ -647,6 +647,7 @@ struct qla_tgt_func_tmpl { const uint8_t *); void (*clear_nacl_from_fcport_map)(struct qla_tgt_sess *);void (*put_sess)(struct qla_tgt_sess *); +void (*shutdown_sess)(struct qla_tgt_sess *); };int qla2x00_wait_for_hba_online (struct scsi_qla_host *);
drivers/scsi/qla2xxx/tcm_qla2xxx.c +6 -0
@@ -843,6 +843,11 @@ void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess)target_put_session (sess->se_sess); } +void tcm_qla2xxx_shutdown_sess (struct qla_tgt_sess *sess) +{ +tcm_qla2xxx_shutdown_session (sess->se_sess); +} + static struct se_node_acl *tcm_qla2xxx_make_nodeacl( struct se_portal_group *se_tpg, struct config_group *group,
@@ -1526,6 +1531,7 @@ static struct qla_tgt_func_tmpl tcm_qla2xxx_template = { .find_sess_by_loop_id = tcm_qla2xxx_find_sess_by_loop_id, .clear_nacl_from_fcport_map = tcm_qla2xxx_clear_nacl_from_fcport_map, .put_sess = tcm_qla2xxx_put_sess, + .shutdown_sess = tcm_qla2xxx_shutdown_sess, };static int tcm_qla2xxx_init_lport (struct tcm_qla2xxx_lport *lport)
Signature · 1 line
1.7.9.5
PATCH 3/3 qla2xxx: Don't create duplicate target sessions
In reply to Roland DreierFrom: Roland Dreier <[email protected]>
We run into problems when tearing down ACLs with IO in flight from the initiator with current code. What happens is that when removing an ACL, we tear down the associated session; then when more commands come in, we queue them up and create a new session in qla_tgt_do_work() for each command. If multiple commands get queued up, we create multiple sessions, each with its own associated dynamic ACL.
Then when we reestablish the ACL, we find the wrong dynamic ACL and convert it back to a normal ACL -- unfortunately the session in the session table that points to the normal ACL has already been overwritten and so all future commands find a session that still points to a dynamic ACL (which rejects all commands except INQUIRY / REPORT LUNS).
Fix this by just always looking up the session in qla_tgt_do_work() and avoiding creating duplicate sessions. This also simplifies the code (since we don't have two places to look up sessions) and moves more work out of the interrupt handler and into the work queue.
--- drivers/scsi/qla2xxx/qla_target.c | 95 ++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 55 deletions(-)
drivers/scsi/qla2xxx/qla_target.c +40 -55
@@ -720,9 +720,8 @@ static struct qla_tgt_sess *qlt_create_sess(unsigned char be_sid[3 ];/* Check to avoid double sessions */ -#if 0 spin_lock_irqsave (&ha->hardware_lock, flags); -list_for_each_entry (sess, &tgt->sess_list, sess_list_entry) { +list_for_each_entry (sess, &ha->tgt.qla_tgt->sess_list, sess_list_entry) {if (!memcmp (sess->port_name, fcport->port_name,WWN_SIZE )) {ql_dbg (ql_dbg_tgt_mgt, vha,0xf005 , "Double sess %p found (s_id %x:%x:%x, "
@@ -731,12 +730,12 @@ static struct qla_tgt_sess *qlt_create_sess( sess->s_id.b.al_pa, sess->s_id.b.area, sess->loop_id, fcport->d_id.b.domain, fcport->d_id.b.al_pa, fcport->d_id.b.area, - fcport->loop_id) + fcport->loop_id);if (sess->deleted)qlt_undelete_sess (sess); -qlt_sess_get (sess); +kref_get (&sess->se_sess->sess_kref); sess->s_id = fcport->d_id; sess->loop_id = fcport->loop_id; sess->conf_compl_supported = !!(fcport->flags &
@@ -744,12 +743,11 @@ static struct qla_tgt_sess *qlt_create_sess(if (sess->local && !local) sess->local =0 ;spin_unlock_irqrestore (&ha->hardware_lock, flags); - goto out; + +return sess; } } -spin_unlock_irq_restore (&ha->hardware_lock, flags); -#endif -/* We are under tgt_mutex, so a new sess can't be added behind us */ +spin_unlock_irqrestore (&ha->hardware_lock, flags); sess =kzalloc (sizeof (*sess),GFP_KERNEL );if (!sess) {
@@ -2634,7 +2632,7 @@ static void qlt_do_work(struct work_struct *work)scsi_qla_host_t *vha = cmd->vha;struct qla_hw_data *ha = vha->hw;struct qla_tgt *tgt = ha->tgt.qla_tgt; -struct qla_tgt_sess *sess = cmd->sess; +struct qla_tgt_sess *sess =NULL ;atio_from_isp_t *atio = &cmd->atio;unsigned char *cdb;unsigned long flags;
@@ -2642,25 +2640,49 @@ static void qlt_do_work(struct work_struct *work)int ret, fcp_task_attr, data_dir, bidi =0 ;;if (tgt->tgt_stop) - goto out_term; + goto out_term; -if (!sess) { -uint8_t *s_id =NULL ; +spin_lock_irqsave (&ha->hardware_lock, flags); + sess = ha->tgt.tgt_ops->find_sess_by_s_id (vha, + atio->u.isp24.fcp_hdr.s_id); +if (sess) { +if (unlikely (sess->tearing_down)) { + sess =NULL ; +spin_unlock_irqrestore (&ha->hardware_lock, flags); + goto out_term; + }else { +/* Do the extra kref_get() before dropping qla_hw_data->hardware_lock. */ +kref_get (&sess->se_sess->sess_kref); + } + } +spin_unlock_irqrestore (&ha->hardware_lock, flags); + +if (unlikely (!sess)) { +uint8_t *s_id = atio->u.isp24.fcp_hdr.s_id; - s_id = atio->u.isp24.fcp_hdr.s_id; +ql_dbg (ql_dbg_tgt_mgt, vha,0xe125 ,"qla_target(%d):" +" Unable to find wwn login (s_id %x:%x:%x)," +" trying to create it manually\n" , vha->vp_idx, + s_id[0 ], s_id[1 ], s_id[2 ]); + +if (atio->u.raw.entry_count >1 ) { +ql_dbg (ql_dbg_tgt_mgt, vha,0xe127 ,"Dropping multy entry" +" cmd %p\n" , cmd); + goto out_term; + }mutex_lock (&ha->tgt.tgt_mutex); - cmd->sess = sess =qlt_make_local_sess (vha, s_id); -/* sess has got an extra creation ref */ + sess =qlt_make_local_sess (vha, s_id); +/* sess has an extra creation ref. */ mutex_unlock (&ha->tgt.tgt_mutex);if (!sess) goto out_term; - cmd->loop_id = sess->loop_id; } -if (tgt->tgt_stop) - goto out_term; + cmd->sess = sess; + cmd->loop_id = sess->loop_id; + cmd->conf_compl_supported = sess->conf_compl_supported; cdb = &atio->u.isp24.fcp_cmnd.cdb[0 ]; cmd->tag = atio->u.isp24.exchange_addr;
@@ -2716,9 +2738,7 @@ static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, {struct qla_hw_data *ha = vha->hw;struct qla_tgt *tgt = ha->tgt.qla_tgt; -struct qla_tgt_sess *sess;struct qla_tgt_cmd *cmd; -int res =0 ;if (unlikely (tgt->tgt_stop)) { ql_dbg(ql_dbg_tgt_mgt, vha, 0xf021,
@@ -2740,45 +2760,10 @@ static int qlt_handle_cmd_for_atio(struct scsi_qla_host *vha, cmd->tgt = ha->tgt.qla_tgt; cmd->vha = vha; - sess = ha->tgt.tgt_ops->find_sess_by_s_id (vha, - atio->u.isp24.fcp_hdr.s_id); -if (unlikely (!sess)) { -ql_dbg (ql_dbg_tgt_mgt, vha,0xf022 , -"qla_target(%d): Unable to find wwn login (s_id %x:%x:%x)," -" trying to create it manually\n" , vha->vp_idx, - atio->u.isp24.fcp_hdr.s_id[0 ], - atio->u.isp24.fcp_hdr.s_id[1 ], - atio->u.isp24.fcp_hdr.s_id[2 ]); - -if (atio->u.raw.entry_count >1 ) { -ql_dbg (ql_dbg_tgt_mgt, vha,0xf023 , -"Dropping multy entry cmd %p\n" , cmd); - goto out_free_cmd; - } - goto out_sched; - } - -if (sess->tearing_down || tgt->tgt_stop) - goto out_free_cmd; - - cmd->sess = sess; - cmd->loop_id = sess->loop_id; - cmd->conf_compl_supported = sess->conf_compl_supported; -/* -* Get the extra kref_get() before dropping qla_hw_data->hardware_lock, -* and call kref_put() in qlt_do_work() process context to drop the -* extra reference. -*/ -kref_get (&sess->se_sess->sess_kref); - -out_sched:INIT_WORK (&cmd->work, qlt_do_work);queue_work (qla_tgt_wq, &cmd->work);return 0 ; -out_free_cmd: -qlt_free_cmd (cmd); -return res; }/* ha->hardware_lock supposed to be held on entry */
Signature · 1 line
1.7.9.5
Nicholas A. Bellinger
AppliedRe: [PATCH 1/3] tcm_qla2xxx: Convert FC address map from flat array to btree
In reply to Roland DreierQuoted 14 lines · Roland Dreier
From: Steve Hodgson <[email protected]>
tcm_qla2xxxneeds a map from 24-bit FC addresses to node ACL pointers to look up incoming commands. Current code keeps this as a flat vmalloc()ed array with 2^24 entries -- with 8-byte pointers, this consumes 128MB per FC port! Occupancy of this array is at most on the order of hundreds of entries (and even that would be a lot of initiators on an FC fabric), so this wastes a huge amount of memory.Change this map to use the kernel's btree library; this reduces the memory used to be O(number of entries) and has no measurable speed impact (in fact since the data structure is now packed rather than sparse, the cache/TLB effects may actually make this a net win).
Quoted 8 lines
Signed-off-by Steve Hodgson <[email protected]>Signed-off-by Roland Dreier <[email protected]>--- drivers/scsi/qla2xxx/Kconfig | 1 + drivers/scsi/qla2xxx/tcm_qla2xxx.c | 195 ++++++++++++++++-------------------- drivers/scsi/qla2xxx/tcm_qla2xxx.h | 22 +--- 3 files changed, 90 insertions(+), 128 deletions(-)
I think this patch looks like a safe enough mechanical change in tcm_qla2xxx code for the benefit here, and definitely should be included for the initial 3.5 merge..
Applied to lio-core.git, and including the full series into this evenings for-next-merge re-spin.
Excellent work here by Steve Hodgson to convert the FC address <-> node ACL pointer lookup logic to use the in-kernel btree library !!
Thanks Roland!
--nab