Skip to contentSkip to conversation

qla2xxx misc. bug fixes

PATCH In review Nilesh Javali 3 participants 14 messages Jun 18, 2024 – Jun 21, 2024

Subsystems (2)
lore
Share & tools
lore

Nilesh Javali

author maintainer
#0 lore raw

cover qla2xxx misc. bug fixes

Martin,

Please apply the qla2xxx driver miscellaneous bug fixes to the scsi tree at your earliest convenience.

Thanks,
Nilesh

Manish Rangankar (1):
qla2xxx: During vport delete send async logout explicitly

Nilesh Javali (2):
qla2xxx: validate nvme_local_port correctly
qla2xxx: Update version to 10.02.09.300-k

Quinn Tran (4):
qla2xxx: unable to act on RSCN for port online
qla2xxx: Fix flash read failure
qla2xxx: Reduce fabric scan duplicate code
qla2xxx: Use QP lock to search for bsg

Saurav Kashyap (1):
qla2xxx: Return ENOBUFS if sg_cnt is more than one for ELS cmds

Shreyas Deodhar (3):
qla2xxx: Fix for possible memory corruption
qla2xxx: complete command early within lock
qla2xxx: Fix optrom version displayed in FDMI

 drivers/scsi/qla2xxx/qla_bsg.c     |  98 +++---
 drivers/scsi/qla2xxx/qla_def.h     |  17 +-
 drivers/scsi/qla2xxx/qla_gbl.h     |   6 +-
 drivers/scsi/qla2xxx/qla_gs.c      | 467 +++++++++++++----------------
 drivers/scsi/qla2xxx/qla_init.c    |  92 ++++--
 drivers/scsi/qla2xxx/qla_inline.h  |  18 ++
 drivers/scsi/qla2xxx/qla_mid.c     |   2 +-
 drivers/scsi/qla2xxx/qla_nvme.c    |   5 +-
 drivers/scsi/qla2xxx/qla_os.c      |  19 +-
 drivers/scsi/qla2xxx/qla_sup.c     | 100 ++++--
 drivers/scsi/qla2xxx/qla_version.h |   4 +-
 11 files changed, 458 insertions(+), 370 deletions(-)

base-commit: e8a1d87b7983b461d1d625e2973cdaadc0bd8ff5

Signature · 1 line
2.23.1
author maintainer
#1 lore raw

PATCH 1/11 qla2xxx: unable to act on RSCN for port online

From: Quinn Tran <[email protected]>

The device does not come online when the target port is online. There were multiple RSCNs indicating multiple devices were affected. Driver is in the process of finishing a fabric scan. A new RSCN (device up) arrived at the tail end of the last fabric scan. Driver mistaken the new RSCN is being taken care of by the previous fabric scan, where this notification is cleared and not act on. The laser needs to be blinked again to get the device to show up.

To prevent driver from accidentally clearing the RSCN notification, each RSCN is given a generation value. A fabric scan will scan for that generation(s). Any new RSCN arrive after the scan start will have a new generation value. This will trigger another scan to get latest data. The RSCN notification flag will be cleared when the scan is associate to that generation.

Fixes bb2ca6b3f09a ("scsi: qla2xxx: Relogin during fabric disturbance")
---
 drivers/scsi/qla2xxx/qla_def.h    |  3 +++
 drivers/scsi/qla2xxx/qla_gs.c     | 33 ++++++++++++++++++++++++++++---
 drivers/scsi/qla2xxx/qla_init.c   | 24 +++++++++++++++++-----
 drivers/scsi/qla2xxx/qla_inline.h | 18 +++++++++++++++++
 4 files changed, 70 insertions(+), 8 deletions(-)
drivers/scsi/qla2xxx/qla_def.h +3 -0
index 2f49baf131e2..ba134f6237b8 100644
@@ -3312,6 +3312,8 @@ struct fab_scan_rp {
 struct fab_scan {
 	struct fab_scan_rp *l;
 	u32 size;
+	u32 rscn_gen_start;
+	u32 rscn_gen_end;
 	u16 scan_retry;
 #define MAX_SCAN_RETRIES 5
 	enum scan_flags_t scan_flags;
@@ -5030,6 +5032,7 @@ typedef struct scsi_qla_host {
 
 	/* Counter to detect races between ELS and RSCN events */
 	atomic_t		generation_tick;
+	atomic_t		rscn_gen;
 	/* Time when global fcport update has been scheduled */
 	int			total_fcport_update_gen;
 	/* List of pending LOGOs, protected by tgt_mutex */
drivers/scsi/qla2xxx/qla_gs.c +30 -3
index 1cf9d200d563..e801cd9e2345 100644
@@ -3168,6 +3168,29 @@ static int qla2x00_is_a_vp(scsi_qla_host_t *vha, u64 wwn)
 	return rc;
 }
 
+static bool qla_ok_to_clear_rscn(scsi_qla_host_t *vha, fc_port_t *fcport)
+{
+	u32 rscn_gen;
+
+	rscn_gen = atomic_read(&vha->rscn_gen);
+	ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x2017,
+	    "%s %d %8phC rscn_gen %x start %x end %x current %x\n",
+	    __func__, __LINE__, fcport->port_name, fcport->rscn_gen,
+	    vha->scan.rscn_gen_start, vha->scan.rscn_gen_end, rscn_gen);
+
+	if (val_is_in_range(fcport->rscn_gen, vha->scan.rscn_gen_start,
+	    vha->scan.rscn_gen_end))
+		/* rscn came in before fabric scan */
+		return true;
+
+	if (val_is_in_range(fcport->rscn_gen, vha->scan.rscn_gen_end, rscn_gen))
+		/* rscn came in after fabric scan */
+		return false;
+
+	/* rare: fcport's scan_needed + rscn_gen must be stale */
+	return true;
+}
+
 void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
 {
 	fc_port_t *fcport;
@@ -3281,10 +3304,10 @@ void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
 				   (fcport->scan_needed &&
 				    fcport->port_type != FCT_INITIATOR &&
 				    fcport->port_type != FCT_NVME_INITIATOR)) {
+				fcport->scan_needed = 0;
 				qlt_schedule_sess_for_deletion(fcport);
 			}
 			fcport->d_id.b24 = rp->id.b24;
-			fcport->scan_needed = 0;
 			break;
 		}
 
@@ -3325,7 +3348,9 @@ void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
 				do_delete = true;
 			}
 
-			fcport->scan_needed = 0;
+			if (qla_ok_to_clear_rscn(vha, fcport))
+				fcport->scan_needed = 0;
+
 			if (((qla_dual_mode_enabled(vha) ||
 			      qla_ini_mode_enabled(vha)) &&
 			    atomic_read(&fcport->state) == FCS_ONLINE) ||
@@ -3355,7 +3380,9 @@ void qla24xx_async_gnnft_done(scsi_qla_host_t *vha, srb_t *sp)
 					    fcport->port_name, fcport->loop_id,
 					    fcport->login_retry);
 				}
-				fcport->scan_needed = 0;
+
+				if (qla_ok_to_clear_rscn(vha, fcport))
+					fcport->scan_needed = 0;
 				qla24xx_fcport_handle_login(vha, fcport);
 			}
 		}
drivers/scsi/qla2xxx/qla_init.c +19 -5
index 8377624d76c9..d88f05ea55cb 100644
@@ -1842,10 +1842,18 @@ int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
 	return qla2x00_post_work(vha, e);
 }
 
+static void qla_rscn_gen_tick(scsi_qla_host_t *vha, u32 *ret_rscn_gen)
+{
+	*ret_rscn_gen = atomic_inc_return(&vha->rscn_gen);
+	/* memory barrier */
+	wmb();
+}
+
 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 {
 	fc_port_t *fcport;
 	unsigned long flags;
+	u32 rscn_gen;
 
 	switch (ea->id.b.rsvd_1) {
 	case RSCN_PORT_ADDR:
@@ -1875,15 +1883,16 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 					 * Otherwise we're already in the middle of a relogin
 					 */
 					fcport->scan_needed = 1;
-					fcport->rscn_gen++;
+					qla_rscn_gen_tick(vha, &fcport->rscn_gen);
 				}
 			} else {
 				fcport->scan_needed = 1;
-				fcport->rscn_gen++;
+				qla_rscn_gen_tick(vha, &fcport->rscn_gen);
 			}
 		}
 		break;
 	case RSCN_AREA_ADDR:
+		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
@@ -1891,11 +1900,12 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 
 			if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
 				fcport->scan_needed = 1;
-				fcport->rscn_gen++;
+				fcport->rscn_gen = rscn_gen;
 			}
 		}
 		break;
 	case RSCN_DOM_ADDR:
+		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
@@ -1903,19 +1913,20 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 
 			if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
 				fcport->scan_needed = 1;
-				fcport->rscn_gen++;
+				fcport->rscn_gen = rscn_gen;
 			}
 		}
 		break;
 	case RSCN_FAB_ADDR:
 	default:
+		qla_rscn_gen_tick(vha, &rscn_gen);
 		list_for_each_entry(fcport, &vha->vp_fcports, list) {
 			if (fcport->flags & FCF_FCP2_DEVICE &&
 			    atomic_read(&fcport->state) == FCS_ONLINE)
 				continue;
 
 			fcport->scan_needed = 1;
-			fcport->rscn_gen++;
+			fcport->rscn_gen = rscn_gen;
 		}
 		break;
 	}
@@ -1924,6 +1935,7 @@ void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
 	if (vha->scan.scan_flags == 0) {
 		ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
 		vha->scan.scan_flags |= SF_QUEUED;
+		vha->scan.rscn_gen_start = atomic_read(&vha->rscn_gen);
 		schedule_delayed_work(&vha->scan.scan_work, 5);
 	}
 	spin_unlock_irqrestore(&vha->work_lock, flags);
@@ -6393,6 +6405,8 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
 		qlt_do_generation_tick(vha, &discovery_gen);
 
 		if (USE_ASYNC_SCAN(ha)) {
+			/* start of scan begins here */
+			vha->scan.rscn_gen_end = atomic_read(&vha->rscn_gen);
 			rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
 			    NULL);
 			if (rval)
drivers/scsi/qla2xxx/qla_inline.h +18 -0
index a4a56ab0ba74..30e332806f86 100644
@@ -631,3 +631,21 @@ static inline int qla_mapq_alloc_qp_cpu_map(struct qla_hw_data *ha)
 	}
 	return 0;
 }
+
+static inline bool val_is_in_range(u32 val, u32 start, u32 end)
+{
+	if (start < end) {
+		if (val >= start && val <= end)
+			return true;
+		else
+			return false;
+	}
+
+	/* @end has wrapped */
+	if (val >= start  && val <= 0xffffffffu)
+		return true;
+	if (val <= end)
+		return true;
+	else
+		return false;
+}
Signature · 1 line
2.23.1
#2 lore raw

Re: [PATCH 01/11] qla2xxx: unable to act on RSCN for port online

kernel test robot noticed the following build warnings:

Hi Nilesh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on e8a1d87b7983b461d1d625e2973cdaadc0bd8ff5]

url:    https://github.com/intel-lab-lkp/linux/commits/Nilesh-Javali/qla2xxx-unable-to-act-on-RSCN-for-port-online/20240618-223303
base:   e8a1d87b7983b461d1d625e2973cdaadc0bd8ff5
patch link:    https://lore.kernel.org/r/20240618133739.35456-2-njavali%40marvell.com
patch subject: [PATCH 01/11] qla2xxx: unable to act on RSCN for port online
config: x86_64-randconfig-161-20240620 (https://download.01.org/0day-ci/archive/20240621/[email protected]/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

smatch warnings:
drivers/scsi/qla2xxx/qla_inline.h:645 val_is_in_range() warn: always true condition '(val <= 4294967295) => (0-u32max <= u32max)'

vim +645 drivers/scsi/qla2xxx/qla_inline.h

634
635 static inline bool val_is_in_range(u32 val, u32 start, u32 end)
636 {
637 if (start < end) {
638 if (val >= start && val <= end)
639 return true;
640 else
641 return false;
642 }
643
644 /* @end has wrapped */

 > 645		if (val >= start  && val <= 0xffffffffu)
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#3 lore raw

PATCH 2/11 qla2xxx: validate nvme_local_port correctly

In reply to Nilesh Javali

The driver load failed with error message,

qla2xxx [0000:04:00.0]-ffff:0: register_localport failed: ret=ffffffef

and with a kernel crash,

	BUG: unable to handle kernel NULL pointer dereference at 0000000000000070
	Workqueue: events_unbound qla_register_fcport_fn [qla2xxx]
	RIP: 0010:nvme_fc_register_remoteport+0x16/0x430 [nvme_fc]
	RSP: 0018:ffffaaa040eb3d98 EFLAGS: 00010282
	RAX: 0000000000000000 RBX: ffff9dfb46b78c00 RCX: 0000000000000000
	RDX: ffff9dfb46b78da8 RSI: ffffaaa040eb3e08 RDI: 0000000000000000
	RBP: ffff9dfb612a0a58 R08: ffffffffaf1d6270 R09: 3a34303a30303030
	R10: 34303a303030305b R11: 2078787832616c71 R12: ffff9dfb46b78dd4
	R13: ffff9dfb46b78c24 R14: ffff9dfb41525300 R15: ffff9dfb46b78da8
	FS:  0000000000000000(0000) GS:ffff9dfc67c00000(0000) knlGS:0000000000000000
	CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
	CR2: 0000000000000070 CR3: 000000018da10004 CR4: 00000000000206f0
	Call Trace:
	qla_nvme_register_remote+0xeb/0x1f0 [qla2xxx]
	? qla2x00_dfs_create_rport+0x231/0x270 [qla2xxx]
	qla2x00_update_fcport+0x2a1/0x3c0 [qla2xxx]
	qla_register_fcport_fn+0x54/0xc0 [qla2xxx]

Exit the qla_nvme_register_remote function when qla_nvme_register_hba fails and correctly validate nvme_local_port.

---
 drivers/scsi/qla2xxx/qla_nvme.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_nvme.c +4 -1
index a8ddf356e662..8f4cc136a9c9 100644
@@ -49,7 +49,10 @@ int qla_nvme_register_remote(struct scsi_qla_host *vha, struct fc_port *fcport)
 		return 0;
 	}
 
-	if (!vha->nvme_local_port && qla_nvme_register_hba(vha))
+	if (qla_nvme_register_hba(vha))
+		return 0;
+
+	if (!vha->nvme_local_port)
 		return 0;
 
 	if (!(fcport->nvme_prli_service_param &
Signature · 1 line
2.23.1
author maintainer
#4 lore raw

PATCH 3/11 qla2xxx: Fix for possible memory corruption

In reply to Nilesh Javali

From: Shreyas Deodhar <[email protected]>

Init Control Block is dereferenced incorrectly.
Correctly dereference ICB

---
 drivers/scsi/qla2xxx/qla_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_os.c +1 -1
index fcb06df2ce4e..70f43eab3f01 100644
@@ -4689,7 +4689,7 @@ static void
 qla2x00_number_of_exch(scsi_qla_host_t *vha, u32 *ret_cnt, u16 max_cnt)
 {
 	u32 temp;
-	struct init_cb_81xx *icb = (struct init_cb_81xx *)&vha->hw->init_cb;
+	struct init_cb_81xx *icb = (struct init_cb_81xx *)vha->hw->init_cb;
 	*ret_cnt = FW_DEF_EXCHANGES_CNT;
 
 	if (max_cnt > vha->hw->max_exchg)
Signature · 1 line
2.23.1
author maintainer
#5 lore raw

PATCH 4/11 qla2xxx: Return ENOBUFS if sg_cnt is more than one for ELS cmds

In reply to Nilesh Javali

From: Saurav Kashyap <[email protected]>

Firmware only supports single DSDs in ELS Pass-through IOCB (0x53h), sg cnt is decided by the SCSI ML. User is not aware of the cause of an acutal error.

Return the appropriate return code that will be decoded by API and application and proper error message will be displayed to user.

Fixes 6e98016ca077 ("[SCSI] qla2xxx: Re-organized BSG interface specific code.")
---
 drivers/scsi/qla2xxx/qla_bsg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_bsg.c +1 -1
index 19bb64bdd88b..8d1e45b883cd 100644
@@ -324,7 +324,7 @@ qla2x00_process_els(struct bsg_job *bsg_job)
 		    "request_sg_cnt=%x reply_sg_cnt=%x.\n",
 		    bsg_job->request_payload.sg_cnt,
 		    bsg_job->reply_payload.sg_cnt);
-		rval = -EPERM;
+		rval = -ENOBUFS;
 		goto done;
 	}
 
Signature · 1 line
2.23.1
author maintainer
#6 lore raw

PATCH 5/11 qla2xxx: Fix flash read failure

In reply to Nilesh Javali

From: Quinn Tran <[email protected]>

Link up failure is observed as a result of flash read failure. Current code does not check flash read return code where it relies on FW checksum to detect the problem.

Add check of flash read failure to detect the problem sooner.

---
 drivers/scsi/qla2xxx/qla_init.c |  63 +++++++++++++++-----
 drivers/scsi/qla2xxx/qla_sup.c  | 100 +++++++++++++++++++++++---------
 2 files changed, 121 insertions(+), 42 deletions(-)
drivers/scsi/qla2xxx/qla_init.c +50 -13
index d88f05ea55cb..5ff017546540 100644
@@ -8221,15 +8221,21 @@ qla28xx_get_aux_images(
 	struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
 	bool valid_pri_image = false, valid_sec_image = false;
 	bool active_pri_image = false, active_sec_image = false;
+	int rc;
 
 	if (!ha->flt_region_aux_img_status_pri) {
 		ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
 		goto check_sec_image;
 	}
 
-	qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
+	rc = qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
 	    ha->flt_region_aux_img_status_pri,
 	    sizeof(pri_aux_image_status) >> 2);
+	if (rc) {
+		ql_log(ql_log_info, vha, 0x01a1,
+		    "Unable to read Primary aux image(%x).\n", rc);
+		goto check_sec_image;
+	}
 	qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
 
 	if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
@@ -8260,9 +8266,15 @@ qla28xx_get_aux_images(
 		goto check_valid_image;
 	}
 
-	qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
+	rc = qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
 	    ha->flt_region_aux_img_status_sec,
 	    sizeof(sec_aux_image_status) >> 2);
+	if (rc) {
+		ql_log(ql_log_info, vha, 0x01a2,
+		    "Unable to read Secondary aux image(%x).\n", rc);
+		goto check_valid_image;
+	}
+
 	qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
 
 	if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
@@ -8320,6 +8332,7 @@ qla27xx_get_active_image(struct scsi_qla_host *vha,
 	struct qla27xx_image_status pri_image_status, sec_image_status;
 	bool valid_pri_image = false, valid_sec_image = false;
 	bool active_pri_image = false, active_sec_image = false;
+	int rc;
 
 	if (!ha->flt_region_img_status_pri) {
 		ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
@@ -8361,8 +8374,14 @@ qla27xx_get_active_image(struct scsi_qla_host *vha,
 		goto check_valid_image;
 	}
 
-	qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
+	rc = qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
 	    ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
+	if (rc) {
+		ql_log(ql_log_info, vha, 0x01a3,
+		    "Unable to read Secondary image status(%x).\n", rc);
+		goto check_valid_image;
+	}
+
 	qla27xx_print_image(vha, "Secondary image", &sec_image_status);
 
 	if (qla27xx_check_image_status_signature(&sec_image_status)) {
@@ -8434,11 +8453,10 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 	    "FW: Loading firmware from flash (%x).\n", faddr);
 
 	dcode = (uint32_t *)req->ring;
-	qla24xx_read_flash_data(vha, dcode, faddr, 8);
-	if (qla24xx_risc_firmware_invalid(dcode)) {
+	rval = qla24xx_read_flash_data(vha, dcode, faddr, 8);
+	if (rval || qla24xx_risc_firmware_invalid(dcode)) {
 		ql_log(ql_log_fatal, vha, 0x008c,
-		    "Unable to verify the integrity of flash firmware "
-		    "image.\n");
+		    "Unable to verify the integrity of flash firmware image (rval %x).\n", rval);
 		ql_log(ql_log_fatal, vha, 0x008d,
 		    "Firmware data: %08x %08x %08x %08x.\n",
 		    dcode[0], dcode[1], dcode[2], dcode[3]);
@@ -8452,7 +8470,12 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 	for (j = 0; j < segments; j++) {
 		ql_dbg(ql_dbg_init, vha, 0x008d,
 		    "-> Loading segment %u...\n", j);
-		qla24xx_read_flash_data(vha, dcode, faddr, 10);
+		rval = qla24xx_read_flash_data(vha, dcode, faddr, 10);
+		if (rval) {
+			ql_log(ql_log_fatal, vha, 0x016a,
+			    "-> Unable to read segment addr + size .\n");
+			return QLA_FUNCTION_FAILED;
+		}
 		risc_addr = be32_to_cpu((__force __be32)dcode[2]);
 		risc_size = be32_to_cpu((__force __be32)dcode[3]);
 		if (!*srisc_addr) {
@@ -8468,7 +8491,13 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 			ql_dbg(ql_dbg_init, vha, 0x008e,
 			    "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
 			    fragment, risc_addr, faddr, dlen);
-			qla24xx_read_flash_data(vha, dcode, faddr, dlen);
+			rval = qla24xx_read_flash_data(vha, dcode, faddr, dlen);
+			if (rval) {
+				ql_log(ql_log_fatal, vha, 0x016b,
+				    "-> Unable to read fragment(faddr %#x dlen %#lx).\n",
+				    faddr, dlen);
+				return QLA_FUNCTION_FAILED;
+			}
 			for (i = 0; i < dlen; i++)
 				dcode[i] = swab32(dcode[i]);
 
@@ -8497,7 +8526,14 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 		fwdt->length = 0;
 
 		dcode = (uint32_t *)req->ring;
-		qla24xx_read_flash_data(vha, dcode, faddr, 7);
+
+		rval = qla24xx_read_flash_data(vha, dcode, faddr, 7);
+		if (rval) {
+			ql_log(ql_log_fatal, vha, 0x016c,
+			    "-> Unable to read template size.\n");
+			goto failed;
+		}
+
 		risc_size = be32_to_cpu((__force __be32)dcode[2]);
 		ql_dbg(ql_dbg_init, vha, 0x0161,
 		    "-> fwdt%u template array at %#x (%#x dwords)\n",
@@ -8523,11 +8559,12 @@ qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
 		}
 
 		dcode = fwdt->template;
-		qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
+		rval = qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
 
-		if (!qla27xx_fwdt_template_valid(dcode)) {
+		if (rval || !qla27xx_fwdt_template_valid(dcode)) {
 			ql_log(ql_log_warn, vha, 0x0165,
-			    "-> fwdt%u failed template validate\n", j);
+			    "-> fwdt%u failed template validate (rval %x)\n",
+			    j, rval);
 			goto failed;
 		}
 
drivers/scsi/qla2xxx/qla_sup.c +71 -29

163 lines not on this page · raw message

Signature · 1 line
2.23.1
#7 lore raw

Re: [PATCH 05/11] qla2xxx: Fix flash read failure

Hi Nilesh,

kernel test robot noticed the following build warnings:

url:    https://github.com/intel-lab-lkp/linux/commits/Nilesh-Javali/qla2xxx-unable-to-act-on-RSCN-for-port-online/20240618-223303
base:   e8a1d87b7983b461d1d625e2973cdaadc0bd8ff5
patch link:    https://lore.kernel.org/r/20240618133739.35456-6-njavali%40marvell.com
patch subject: [PATCH 05/11] qla2xxx: Fix flash read failure
config: x86_64-randconfig-161-20240620 (https://download.01.org/0day-ci/archive/20240621/[email protected]/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
drivers/scsi/qla2xxx/qla_sup.c:3581 qla24xx_get_flash_version() warn: missing error code? 'ret'

vim +/ret +3581 drivers/scsi/qla2xxx/qla_sup.c

30c4766213aeb6 Andrew Vasquez      2007-01-29  3422  int
7b867cf76fbcc8 Anirban Chakraborty 2008-11-06  3423  qla24xx_get_flash_version(scsi_qla_host_t *vha, void *mbuf)
30c4766213aeb6 Andrew Vasquez      2007-01-29  3424  {
30c4766213aeb6 Andrew Vasquez      2007-01-29  3425  	int ret = QLA_SUCCESS;
3695310e37b4e5 Joe Carnuccio       2019-03-12  3426  	uint32_t pcihdr = 0, pcids = 0;
3695310e37b4e5 Joe Carnuccio       2019-03-12  3427  	uint32_t *dcode = mbuf;
3695310e37b4e5 Joe Carnuccio       2019-03-12  3428  	uint8_t *bcode = mbuf;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3429  	uint8_t code_type, last_image;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3430  	int i;
7b867cf76fbcc8 Anirban Chakraborty 2008-11-06  3431  	struct qla_hw_data *ha = vha->hw;
4243c115f47757 Sawan Chandak       2016-01-27  3432  	uint32_t faddr = 0;
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3433  	struct active_regions active_regions = { };
4243c115f47757 Sawan Chandak       2016-01-27  3434  
7ec0effd30bb4b Atul Deshmukh       2013-08-27  3435  	if (IS_P3P_TYPE(ha))
a9083016a5314b Giridhar Malavali   2010-04-12  3436  		return ret;

You didn't introduce this and it doesn't generate a static checker warning but it's always so much better to return the actual value instead of making people scroll to the top of the function so see if it's a success path or a failure path.

a9083016a5314b Giridhar Malavali   2010-04-12  3437  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3438  	if (!mbuf)
30c4766213aeb6 Andrew Vasquez      2007-01-29  3439  		return QLA_FUNCTION_FAILED;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3440  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3441  	memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
30c4766213aeb6 Andrew Vasquez      2007-01-29  3442  	memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
30c4766213aeb6 Andrew Vasquez      2007-01-29  3443  	memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
30c4766213aeb6 Andrew Vasquez      2007-01-29  3444  	memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
30c4766213aeb6 Andrew Vasquez      2007-01-29  3445  
6315a5f810d8cf Harish Zunjarrao    2009-03-24  3446  	pcihdr = ha->flt_region_boot << 2;
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3447  	if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3448  		qla27xx_get_active_image(vha, &active_regions);
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3449  		if (active_regions.global == QLA27XX_SECONDARY_IMAGE) {
4243c115f47757 Sawan Chandak       2016-01-27  3450  			pcihdr = ha->flt_region_boot_sec << 2;
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3451  		}
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3452  	}
4243c115f47757 Sawan Chandak       2016-01-27  3453  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3454  	do {
30c4766213aeb6 Andrew Vasquez      2007-01-29  3455  		/* Verify PCI expansion ROM header. */
7aa8fb6727f57f Quinn Tran          2024-06-18  3456  		ret = qla24xx_read_flash_data(vha, dcode, pcihdr >> 2, 0x20);
7aa8fb6727f57f Quinn Tran          2024-06-18  3457  		if (ret) {
7aa8fb6727f57f Quinn Tran          2024-06-18  3458  			ql_log(ql_log_info, vha, 0x017d,
7aa8fb6727f57f Quinn Tran          2024-06-18  3459  			    "Unable to read PCI EXP Rom Header(%x).\n", ret);
7aa8fb6727f57f Quinn Tran          2024-06-18  3460  			break;
7aa8fb6727f57f Quinn Tran          2024-06-18  3461  		}
7aa8fb6727f57f Quinn Tran          2024-06-18  3462  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3463  		bcode = mbuf + (pcihdr % 4);
3695310e37b4e5 Joe Carnuccio       2019-03-12  3464  		if (memcmp(bcode, "\x55\xaa", 2)) {
30c4766213aeb6 Andrew Vasquez      2007-01-29  3465  			/* No signature */
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3466  			ql_log(ql_log_fatal, vha, 0x0059,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3467  			    "No matching ROM signature.\n");
30c4766213aeb6 Andrew Vasquez      2007-01-29  3468  			ret = QLA_FUNCTION_FAILED;

You didn't introduce this either, but it will trigger a static checker warning for some checkers and it seems like probably a bug. This assignment is never used.

30c4766213aeb6 Andrew Vasquez      2007-01-29  3469  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3470  		}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3471  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3472  		/* Locate PCI data structure. */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3473  		pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3474  
7aa8fb6727f57f Quinn Tran          2024-06-18  3475  		ret = qla24xx_read_flash_data(vha, dcode, pcids >> 2, 0x20);
7aa8fb6727f57f Quinn Tran          2024-06-18  3476  		if (ret) {
7aa8fb6727f57f Quinn Tran          2024-06-18  3477  			ql_log(ql_log_info, vha, 0x018e,
7aa8fb6727f57f Quinn Tran          2024-06-18  3478  			    "Unable to read PCI Data Structure (%x).\n", ret);
7aa8fb6727f57f Quinn Tran          2024-06-18  3479  			break;
7aa8fb6727f57f Quinn Tran          2024-06-18  3480  		}
7aa8fb6727f57f Quinn Tran          2024-06-18  3481  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3482  		bcode = mbuf + (pcihdr % 4);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3483  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3484  		/* Validate signature of PCI data structure. */
3695310e37b4e5 Joe Carnuccio       2019-03-12  3485  		if (memcmp(bcode, "PCIR", 4)) {
30c4766213aeb6 Andrew Vasquez      2007-01-29  3486  			/* Incorrect header. */
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3487  			ql_log(ql_log_fatal, vha, 0x005a,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3488  			    "PCI data struct not found pcir_adr=%x.\n", pcids);
3695310e37b4e5 Joe Carnuccio       2019-03-12  3489  			ql_dump_buffer(ql_dbg_init, vha, 0x0059, dcode, 32);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3490  			ret = QLA_FUNCTION_FAILED;

Never used.

30c4766213aeb6 Andrew Vasquez      2007-01-29  3491  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3492  		}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3493  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3494  		/* Read version */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3495  		code_type = bcode[0x14];
30c4766213aeb6 Andrew Vasquez      2007-01-29  3496  		switch (code_type) {
30c4766213aeb6 Andrew Vasquez      2007-01-29  3497  		case ROM_CODE_TYPE_BIOS:
30c4766213aeb6 Andrew Vasquez      2007-01-29  3498  			/* Intel x86, PC-AT compatible. */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3499  			ha->bios_revision[0] = bcode[0x12];
30c4766213aeb6 Andrew Vasquez      2007-01-29  3500  			ha->bios_revision[1] = bcode[0x13];
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3501  			ql_dbg(ql_dbg_init, vha, 0x005b,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3502  			    "Read BIOS %d.%d.\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3503  			    ha->bios_revision[1], ha->bios_revision[0]);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3504  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3505  		case ROM_CODE_TYPE_FCODE:
30c4766213aeb6 Andrew Vasquez      2007-01-29  3506  			/* Open Firmware standard for PCI (FCode). */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3507  			ha->fcode_revision[0] = bcode[0x12];
30c4766213aeb6 Andrew Vasquez      2007-01-29  3508  			ha->fcode_revision[1] = bcode[0x13];
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3509  			ql_dbg(ql_dbg_init, vha, 0x005c,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3510  			    "Read FCODE %d.%d.\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3511  			    ha->fcode_revision[1], ha->fcode_revision[0]);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3512  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3513  		case ROM_CODE_TYPE_EFI:
30c4766213aeb6 Andrew Vasquez      2007-01-29  3514  			/* Extensible Firmware Interface (EFI). */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3515  			ha->efi_revision[0] = bcode[0x12];
30c4766213aeb6 Andrew Vasquez      2007-01-29  3516  			ha->efi_revision[1] = bcode[0x13];
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3517  			ql_dbg(ql_dbg_init, vha, 0x005d,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3518  			    "Read EFI %d.%d.\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3519  			    ha->efi_revision[1], ha->efi_revision[0]);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3520  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3521  		default:
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3522  			ql_log(ql_log_warn, vha, 0x005e,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3523  			    "Unrecognized code type %x at pcids %x.\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3524  			    code_type, pcids);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3525  			break;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3526  		}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3527  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3528  		last_image = bcode[0x15] & BIT_7;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3529  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3530  		/* Locate next PCI expansion ROM. */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3531  		pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3532  	} while (!last_image);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3533  
30c4766213aeb6 Andrew Vasquez      2007-01-29  3534  	/* Read firmware image information. */
30c4766213aeb6 Andrew Vasquez      2007-01-29  3535  	memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
4243c115f47757 Sawan Chandak       2016-01-27  3536  	faddr = ha->flt_region_fw;
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3537  	if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3f006ac342c033 Michael Hernandez   2019-03-12  3538  		qla27xx_get_active_image(vha, &active_regions);
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3539  		if (active_regions.global == QLA27XX_SECONDARY_IMAGE)
4243c115f47757 Sawan Chandak       2016-01-27  3540  			faddr = ha->flt_region_fw_sec;
5fa8774c7f38c7 Joe Carnuccio       2019-03-12  3541  	}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3542  
7aa8fb6727f57f Quinn Tran          2024-06-18  3543  	ret = qla24xx_read_flash_data(vha, dcode, faddr, 8);
7aa8fb6727f57f Quinn Tran          2024-06-18  3544  	if (ret) {
7aa8fb6727f57f Quinn Tran          2024-06-18  3545  		ql_log(ql_log_info, vha, 0x019e,
7aa8fb6727f57f Quinn Tran          2024-06-18  3546  		    "Unable to read FW version (%x).\n", ret);

This should return immediately.

7aa8fb6727f57f Quinn Tran          2024-06-18  3547  	} else {
f8f97b0c5b7f7c Joe Carnuccio       2019-03-12  3548  		if (qla24xx_risc_firmware_invalid(dcode)) {
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3549  			ql_log(ql_log_warn, vha, 0x005f,
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3550  			    "Unrecognized fw revision at %x.\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3551  			    ha->flt_region_fw * 4);
3695310e37b4e5 Joe Carnuccio       2019-03-12  3552  			ql_dump_buffer(ql_dbg_init, vha, 0x005f, dcode, 32);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3553  		} else {
f8f97b0c5b7f7c Joe Carnuccio       2019-03-12  3554  			for (i = 0; i < 4; i++)
7ffa5b939751b6 Bart Van Assche     2020-05-18  3555  				ha->fw_revision[i] =
7ffa5b939751b6 Bart Van Assche     2020-05-18  3556  				be32_to_cpu((__force __be32)dcode[4+i]);
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3557  			ql_dbg(ql_dbg_init, vha, 0x0060,
3695310e37b4e5 Joe Carnuccio       2019-03-12  3558  			    "Firmware revision (flash) %u.%u.%u (%x).\n",
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3559  			    ha->fw_revision[0], ha->fw_revision[1],
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3560  			    ha->fw_revision[2], ha->fw_revision[3]);
30c4766213aeb6 Andrew Vasquez      2007-01-29  3561  		}
7aa8fb6727f57f Quinn Tran          2024-06-18  3562  	}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3563  
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3564  	/* Check for golden firmware and get version if available */
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3565  	if (!IS_QLA81XX(ha)) {
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3566  		/* Golden firmware is not present in non 81XX adapters */
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3567  		return ret;

Ugh...

0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3568  	}
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3569  
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3570  	memset(ha->gold_fw_version, 0, sizeof(ha->gold_fw_version));
3695310e37b4e5 Joe Carnuccio       2019-03-12  3571  	faddr = ha->flt_region_gold_fw;
7aa8fb6727f57f Quinn Tran          2024-06-18  3572  	ret = qla24xx_read_flash_data(vha, dcode, ha->flt_region_gold_fw, 8);
7aa8fb6727f57f Quinn Tran          2024-06-18  3573  	if (ret) {
7aa8fb6727f57f Quinn Tran          2024-06-18  3574  		ql_log(ql_log_info, vha, 0x019f,
7aa8fb6727f57f Quinn Tran          2024-06-18  3575  		    "Unable to read Gold FW version (%x).\n", ret);

It's better to return immediately then you can pull the else path in one tab.

7aa8fb6727f57f Quinn Tran          2024-06-18  3576  	} else {
f8f97b0c5b7f7c Joe Carnuccio       2019-03-12  3577  		if (qla24xx_risc_firmware_invalid(dcode)) {
7c3df1320e5e87 Saurav Kashyap      2011-07-14  3578  			ql_log(ql_log_warn, vha, 0x0056,
3695310e37b4e5 Joe Carnuccio       2019-03-12  3579  			    "Unrecognized golden fw at %#x.\n", faddr);
3695310e37b4e5 Joe Carnuccio       2019-03-12  3580  			ql_dump_buffer(ql_dbg_init, vha, 0x0056, dcode, 32);
0f2d962f4d120e Madhuranath Iyengar 2010-07-23 @3581  			return ret;

This is the static checker warning. This should probably be return QLA_FUNCTION_FAILED or return -EINVAL or something.

0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3582  		}
0f2d962f4d120e Madhuranath Iyengar 2010-07-23  3583  
f8f97b0c5b7f7c Joe Carnuccio       2019-03-12  3584  		for (i = 0; i < 4; i++)
7ffa5b939751b6 Bart Van Assche     2020-05-18  3585  			ha->gold_fw_version[i] =
7ffa5b939751b6 Bart Van Assche     2020-05-18  3586  			   be32_to_cpu((__force __be32)dcode[4+i]);
7aa8fb6727f57f Quinn Tran          2024-06-18  3587  	}
30c4766213aeb6 Andrew Vasquez      2007-01-29  3588  	return ret;
30c4766213aeb6 Andrew Vasquez      2007-01-29  3589  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#8 lore raw

PATCH 6/11 qla2xxx: complete command early within lock

In reply to Nilesh Javali

From: Shreyas Deodhar <[email protected]>

A crash was observed while performing NPIV and FW reset,

 BUG: kernel NULL pointer dereference, address: 000000000000001c
 #PF: supervisor read access in kernel mode
 #PF: error_code(0x0000) - not-present page
 PGD 0 P4D 0
 Oops: 0000 1 PREEMPT_RT SMP NOPTI
 RIP: 0010:dma_direct_unmap_sg+0x51/0x1e0
 RSP: 0018:ffffc90026f47b88 EFLAGS: 00010246
 RAX: 0000000000000000 RBX: 0000000000000021 RCX: 0000000000000002
 RDX: 0000000000000021 RSI: 0000000000000000 RDI: ffff8881041130d0
 RBP: ffff8881041130d0 R08: 0000000000000000 R09: 0000000000000034
 R10: ffffc90026f47c48 R11: 0000000000000031 R12: 0000000000000000
 R13: 0000000000000000 R14: ffff8881565e4a20 R15: 0000000000000000
 FS: 00007f4c69ed3d00(0000) GS:ffff889faac80000(0000) knlGS:0000000000000000
 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 000000000000001c CR3: 0000000288a50002 CR4: 00000000007706e0
 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
 PKRU: 55555554
 Call Trace:
 <TASK>
 ? __die_body+0x1a/0x60
 ? page_fault_oops+0x16f/0x4a0
 ? do_user_addr_fault+0x174/0x7f0
 ? exc_page_fault+0x69/0x1a0
 ? asm_exc_page_fault+0x22/0x30
 ? dma_direct_unmap_sg+0x51/0x1e0
 ? preempt_count_sub+0x96/0xe0
 qla2xxx_qpair_sp_free_dma+0x29f/0x3b0 [qla2xxx]
 qla2xxx_qpair_sp_compl+0x60/0x80 [qla2xxx]
 __qla2x00_abort_all_cmds+0xa2/0x450 [qla2xxx]

The command completion was done early while aborting the commands in driver unload path but outside lock to avoid the WARN_ON condition of performing dma_free_attr within the lock. However this caused race condition while command completion via multiple paths causing system crash.

Hence complete the command early in unload path but within the lock to avoid race condition.

Fixes 0367076b0817 ("scsi: qla2xxx: Perform lockless command completion in abort path")
---
 drivers/scsi/qla2xxx/qla_os.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/scsi/qla2xxx/qla_os.c +0 -5
index 70f43eab3f01..e4056cddb727 100644
@@ -1875,14 +1875,9 @@ __qla2x00_abort_all_cmds(struct qla_qpair *qp, int res)
 	for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
 		sp = req->outstanding_cmds[cnt];
 		if (sp) {
-			/*
-			 * perform lockless completion during driver unload
-			 */
 			if (qla2x00_chip_is_down(vha)) {
 				req->outstanding_cmds[cnt] = NULL;
-				spin_unlock_irqrestore(qp->qp_lock_ptr, flags);
 				sp->done(sp, res);
-				spin_lock_irqsave(qp->qp_lock_ptr, flags);
 				continue;
 			}
 
Signature · 1 line
2.23.1
author maintainer
#9 lore raw

PATCH 7/11 qla2xxx: During vport delete send async logout explicitly

In reply to Nilesh Javali

From: Manish Rangankar <[email protected]>

During vport delete, it is observed that during unload we hit a crash because of stale entries in outstanding command array. For all these stale I/O entries, eh_abort was issued and aborted (fast_fail_io = 2009h) but I/Os could not complete while vport delete is in process of deleting.

  BUG: kernel NULL pointer dereference, address: 000000000000001c
  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  PGD 0 P4D 0
  Oops: 0000 [#1] PREEMPT SMP NOPTI
  Workqueue: qla2xxx_wq qla_do_work [qla2xxx]
  RIP: 0010:dma_direct_unmap_sg+0x51/0x1e0
  RSP: 0018:ffffa1e1e150fc68 EFLAGS: 00010046
  RAX: 0000000000000000 RBX: 0000000000000021 RCX: 0000000000000001
  RDX: 0000000000000021 RSI: 0000000000000000 RDI: ffff8ce208a7a0d0
  RBP: ffff8ce208a7a0d0 R08: 0000000000000000 R09: ffff8ce378aac9c8
  R10: ffff8ce378aac8a0 R11: ffffa1e1e150f9d8 R12: 0000000000000000
  R13: 0000000000000000 R14: ffff8ce378aac9c8 R15: 0000000000000000
  FS:  0000000000000000(0000) GS:ffff8d217f000000(0000) knlGS:0000000000000000
  CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  CR2: 000000000000001c CR3: 0000002089acc000 CR4: 0000000000350ee0
  Call Trace:
  <TASK>
  qla2xxx_qpair_sp_free_dma+0x417/0x4e0
  ? qla2xxx_qpair_sp_compl+0x10d/0x1a0
  ? qla2x00_status_entry+0x768/0x2830
  ? newidle_balance+0x2f0/0x430
  ? dequeue_entity+0x100/0x3c0
  ? qla24xx_process_response_queue+0x6a1/0x19e0
  ? __schedule+0x2d5/0x1140
  ? qla_do_work+0x47/0x60
  ? process_one_work+0x267/0x440
  ? process_one_work+0x440/0x440
  ? worker_thread+0x2d/0x3d0
  ? process_one_work+0x440/0x440
  ? kthread+0x156/0x180
  ? set_kthread_struct+0x50/0x50
  ? ret_from_fork+0x22/0x30
  </TASK>

Send out async logout explicitly for all the ports during vport delete.

---
 drivers/scsi/qla2xxx/qla_mid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_mid.c +1 -1
index b67416951a5f..76703f2706b8 100644
@@ -180,7 +180,7 @@ qla24xx_disable_vp(scsi_qla_host_t *vha)
 	atomic_set(&vha->loop_state, LOOP_DOWN);
 	atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
 	list_for_each_entry(fcport, &vha->vp_fcports, list)
-		fcport->logout_on_delete = 0;
+		fcport->logout_on_delete = 1;
 
 	if (!vha->hw->flags.edif_enabled)
 		qla2x00_wait_for_sess_deletion(vha);
Signature · 1 line
2.23.1
author maintainer
#10 lore raw

PATCH 8/11 qla2xxx: Fix optrom version displayed in FDMI

In reply to Nilesh Javali

From: Shreyas Deodhar <[email protected]>

Bios version was popluated for FDMI response. Systems with EFI would show optrom version as 0.
EFI version is populated here and BIOS version is already displayed under FDMI_HBA_BOOT_BIOS_NAME.

---
 drivers/scsi/qla2xxx/qla_gs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_gs.c +1 -1
index e801cd9e2345..caa9a3cd2580 100644
@@ -1710,7 +1710,7 @@ qla2x00_hba_attributes(scsi_qla_host_t *vha, void *entries,
 	eiter->type = cpu_to_be16(FDMI_HBA_OPTION_ROM_VERSION);
 	alen = scnprintf(
 		eiter->a.orom_version, sizeof(eiter->a.orom_version),
-		"%d.%02d", ha->bios_revision[1], ha->bios_revision[0]);
+		"%d.%02d", ha->efi_revision[1], ha->efi_revision[0]);
 	alen += FDMI_ATTR_ALIGNMENT(alen);
 	alen += FDMI_ATTR_TYPELEN(eiter);
 	eiter->len = cpu_to_be16(alen);
Signature · 1 line
2.23.1
author maintainer
#11 lore raw

PATCH 9/11 qla2xxx: Reduce fabric scan duplicate code

In reply to Nilesh Javali

From: Quinn Tran <[email protected]>

For fabric scan, current code uses switch scan opcode and flags as the method to iterate through different commands to carry out the process. This makes it hard to read. This patch convert those opcode and flags into steps. In addition, this help reduce some duplicate code.

Consolidate routines that handle GPNFT & GNNFT.

---
 drivers/scsi/qla2xxx/qla_def.h  |  14 +-
 drivers/scsi/qla2xxx/qla_gbl.h  |   6 +-
 drivers/scsi/qla2xxx/qla_gs.c   | 432 +++++++++++++-------------------
 drivers/scsi/qla2xxx/qla_init.c |   5 +-
 drivers/scsi/qla2xxx/qla_os.c   |  12 +-
 5 files changed, 200 insertions(+), 269 deletions(-)
drivers/scsi/qla2xxx/qla_def.h +11 -3
index ba134f6237b8..7cf998e3cc68 100644
@@ -3309,11 +3309,20 @@ struct fab_scan_rp {
 	u8 node_name[8];
 };
 
+enum scan_step {
+	FAB_SCAN_START,
+	FAB_SCAN_GPNFT_FCP,
+	FAB_SCAN_GNNFT_FCP,
+	FAB_SCAN_GPNFT_NVME,
+	FAB_SCAN_GNNFT_NVME,
+};
+
 struct fab_scan {
 	struct fab_scan_rp *l;
 	u32 size;
 	u32 rscn_gen_start;
 	u32 rscn_gen_end;
+	enum scan_step step;
 	u16 scan_retry;
 #define MAX_SCAN_RETRIES 5
 	enum scan_flags_t scan_flags;
@@ -3539,9 +3548,8 @@ enum qla_work_type {
 	QLA_EVT_RELOGIN,
 	QLA_EVT_ASYNC_PRLO,
 	QLA_EVT_ASYNC_PRLO_DONE,
-	QLA_EVT_GPNFT,
-	QLA_EVT_GPNFT_DONE,
-	QLA_EVT_GNNFT_DONE,
+	QLA_EVT_SCAN_CMD,
+	QLA_EVT_SCAN_FINISH,
 	QLA_EVT_GFPNID,
 	QLA_EVT_SP_RETRY,
 	QLA_EVT_IIDMA,
drivers/scsi/qla2xxx/qla_gbl.h +3 -3
index 7309310d2ab9..cededfda9d0e 100644
@@ -728,9 +728,9 @@ int qla24xx_async_gpsc(scsi_qla_host_t *, fc_port_t *);
 void qla24xx_handle_gpsc_event(scsi_qla_host_t *, struct event_arg *);
 int qla2x00_mgmt_svr_login(scsi_qla_host_t *);
 int qla24xx_async_gffid(scsi_qla_host_t *vha, fc_port_t *fcport, bool);
-int qla24xx_async_gpnft(scsi_qla_host_t *, u8, srb_t *);
-void qla24xx_async_gpnft_done(scsi_qla_host_t *, srb_t *);
-void qla24xx_async_gnnft_done(scsi_qla_host_t *, srb_t *);
+int qla_fab_async_scan(scsi_qla_host_t *, srb_t *);
+void qla_fab_scan_start(struct scsi_qla_host *);
+void qla_fab_scan_finish(scsi_qla_host_t *, srb_t *);
 int qla24xx_post_gfpnid_work(struct scsi_qla_host *, fc_port_t *);
 int qla24xx_async_gfpnid(scsi_qla_host_t *, fc_port_t *);
 void qla24xx_handle_gfpnid_event(scsi_qla_host_t *, struct event_arg *);
drivers/scsi/qla2xxx/qla_gs.c +181 -251

578 lines not on this page · raw message

drivers/scsi/qla2xxx/qla_init.c +1 -4
index 5ff017546540..eda3bdab934d 100644
@@ -6407,10 +6407,7 @@ qla2x00_configure_fabric(scsi_qla_host_t *vha)
 		if (USE_ASYNC_SCAN(ha)) {
 			/* start of scan begins here */
 			vha->scan.rscn_gen_end = atomic_read(&vha->rscn_gen);
-			rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
-			    NULL);
-			if (rval)
-				set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
+			qla_fab_scan_start(vha);
 		} else  {
 			list_for_each_entry(fcport, &vha->vp_fcports, list)
 				fcport->scan_state = QLA_FCPORT_SCAN;
drivers/scsi/qla2xxx/qla_os.c +4 -8
index e4056cddb727..bc3b2aea3f8b 100644
@@ -5558,15 +5558,11 @@ qla2x00_do_work(struct scsi_qla_host *vha)
 			qla2x00_async_prlo_done(vha, e->u.logio.fcport,
 			    e->u.logio.data);
 			break;
-		case QLA_EVT_GPNFT:
-			qla24xx_async_gpnft(vha, e->u.gpnft.fc4_type,
-			    e->u.gpnft.sp);
+		case QLA_EVT_SCAN_CMD:
+			qla_fab_async_scan(vha, e->u.iosb.sp);
 			break;
-		case QLA_EVT_GPNFT_DONE:
-			qla24xx_async_gpnft_done(vha, e->u.iosb.sp);
-			break;
-		case QLA_EVT_GNNFT_DONE:
-			qla24xx_async_gnnft_done(vha, e->u.iosb.sp);
+		case QLA_EVT_SCAN_FINISH:
+			qla_fab_scan_finish(vha, e->u.iosb.sp);
 			break;
 		case QLA_EVT_GFPNID:
 			qla24xx_async_gfpnid(vha, e->u.fcport.fcport);
Signature · 1 line
2.23.1
author maintainer
#12 lore raw

PATCH 10/11 qla2xxx: Use QP lock to search for bsg

In reply to Nilesh Javali

From: Quinn Tran <[email protected]>

On bsg timeout, hardware_lock is used as part of search for the srb. Instead, qpair lock should be used to iterate through different qpair.

---
 drivers/scsi/qla2xxx/qla_bsg.c | 96 ++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 39 deletions(-)
drivers/scsi/qla2xxx/qla_bsg.c +57 -39
index 8d1e45b883cd..52dc9604f567 100644
@@ -3059,17 +3059,61 @@ qla24xx_bsg_request(struct bsg_job *bsg_job)
 	return ret;
 }
 
-int
-qla24xx_bsg_timeout(struct bsg_job *bsg_job)
+static bool qla_bsg_found(struct qla_qpair *qpair, struct bsg_job *bsg_job)
 {
+	bool found = false;
 	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
 	scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
 	struct qla_hw_data *ha = vha->hw;
-	srb_t *sp;
-	int cnt, que;
+	srb_t *sp = NULL;
+	int cnt;
 	unsigned long flags;
 	struct req_que *req;
 
+	spin_lock_irqsave(qpair->qp_lock_ptr, flags);
+	req = qpair->req;
+
+	for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
+		sp = req->outstanding_cmds[cnt];
+		if (sp &&
+		    (sp->type == SRB_CT_CMD ||
+		     sp->type == SRB_ELS_CMD_HST ||
+		     sp->type == SRB_ELS_CMD_HST_NOLOGIN) &&
+		    sp->u.bsg_job == bsg_job) {
+			req->outstanding_cmds[cnt] = NULL;
+			spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
+
+			if (!ha->flags.eeh_busy && ha->isp_ops->abort_command(sp)) {
+				ql_log(ql_log_warn, vha, 0x7089,
+						"mbx abort_command failed.\n");
+				bsg_reply->result = -EIO;
+			} else {
+				ql_dbg(ql_dbg_user, vha, 0x708a,
+						"mbx abort_command success.\n");
+				bsg_reply->result = 0;
+			}
+			/* ref: INIT */
+			kref_put(&sp->cmd_kref, qla2x00_sp_release);
+
+			found = true;
+			goto done;
+		}
+	}
+	spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
+
+done:
+	return found;
+}
+
+int
+qla24xx_bsg_timeout(struct bsg_job *bsg_job)
+{
+	struct fc_bsg_reply *bsg_reply = bsg_job->reply;
+	scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
+	struct qla_hw_data *ha = vha->hw;
+	int i;
+	struct qla_qpair *qpair;
+
 	ql_log(ql_log_info, vha, 0x708b, "%s CMD timeout. bsg ptr %p.\n",
 	    __func__, bsg_job);
 
@@ -3079,48 +3123,22 @@ qla24xx_bsg_timeout(struct bsg_job *bsg_job)
 		qla_pci_set_eeh_busy(vha);
 	}
 
+	if (qla_bsg_found(ha->base_qpair, bsg_job))
+		goto done;
+
 	/* find the bsg job from the active list of commands */
-	spin_lock_irqsave(&ha->hardware_lock, flags);
-	for (que = 0; que < ha->max_req_queues; que++) {
-		req = ha->req_q_map[que];
-		if (!req)
+	for (i = 0; i < ha->max_qpairs; i++) {
+		qpair = vha->hw->queue_pair_map[i];
+		if (!qpair)
 			continue;
-
-		for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
-			sp = req->outstanding_cmds[cnt];
-			if (sp &&
-			    (sp->type == SRB_CT_CMD ||
-			     sp->type == SRB_ELS_CMD_HST ||
-			     sp->type == SRB_ELS_CMD_HST_NOLOGIN ||
-			     sp->type == SRB_FXIOCB_BCMD) &&
-			    sp->u.bsg_job == bsg_job) {
-				req->outstanding_cmds[cnt] = NULL;
-				spin_unlock_irqrestore(&ha->hardware_lock, flags);
-
-				if (!ha->flags.eeh_busy && ha->isp_ops->abort_command(sp)) {
-					ql_log(ql_log_warn, vha, 0x7089,
-					    "mbx abort_command failed.\n");
-					bsg_reply->result = -EIO;
-				} else {
-					ql_dbg(ql_dbg_user, vha, 0x708a,
-					    "mbx abort_command success.\n");
-					bsg_reply->result = 0;
-				}
-				spin_lock_irqsave(&ha->hardware_lock, flags);
-				goto done;
-
-			}
-		}
+		if (qla_bsg_found(qpair, bsg_job))
+			goto done;
 	}
-	spin_unlock_irqrestore(&ha->hardware_lock, flags);
+
 	ql_log(ql_log_info, vha, 0x708b, "SRB not found to abort.\n");
 	bsg_reply->result = -ENXIO;
-	return 0;
 
 done:
-	spin_unlock_irqrestore(&ha->hardware_lock, flags);
-	/* ref: INIT */
-	kref_put(&sp->cmd_kref, qla2x00_sp_release);
 	return 0;
 }
 
Signature · 1 line
2.23.1
author maintainer
#13 lore raw

PATCH 11/11 qla2xxx: Update version to 10.02.09.300-k

In reply to Nilesh Javali
---
 drivers/scsi/qla2xxx/qla_version.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_version.h +2 -2
index 7627fd807bc3..cf0f9d9db645 100644
@@ -6,9 +6,9 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION      "10.02.09.200-k"
+#define QLA2XXX_VERSION      "10.02.09.300-k"
 
 #define QLA_DRIVER_MAJOR_VER	10
 #define QLA_DRIVER_MINOR_VER	2
 #define QLA_DRIVER_PATCH_VER	9
-#define QLA_DRIVER_BETA_VER	200
+#define QLA_DRIVER_BETA_VER	300
Signature · 1 line
2.23.1