Skip to contentSkip to conversation

megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

PATCH Superseded [email protected] 3 participants 4 messages Nov 10, 2014 – Nov 13, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/7 megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

Do not process any SCSI and IOCTL command further(return them with appropriate return values to callers), while driver removal is in progress/PCI shutdown is invoked.

---
 drivers/scsi/megaraid/megaraid_sas_base.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +16 -4
index f6a69a3..7754eeb 100644
@@ -1572,6 +1572,12 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
 	instance = (struct megasas_instance *)
 	    scmd->device->host->hostdata;
 
+	if (instance->unload == 1) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		return 0;
+	}
+
 	if (instance->issuepend_done == 0)
 		return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -4957,10 +4963,6 @@ static int megasas_io_attach(struct megasas_instance *instance)
 		return -ENODEV;
 	}
 
-	/*
-	 * Trigger SCSI to scan our drives
-	 */
-	scsi_scan_host(host);
 	return 0;
 }
 
@@ -5288,6 +5290,10 @@ retry_irq_register:
 		goto fail_io_attach;
 
 	instance->unload = 0;
+	/*
+	 * Trigger SCSI to scan our drives
+	 */
+	scsi_scan_host(host);
 
 	/*
 	 * Initiate AEN (Asynchronous Event Notification)
@@ -6051,6 +6057,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
 	megasas_issue_blocked_cmd(instance, cmd, 0);
 	cmd->sync_cmd = 0;
 
+	if (instance->unload == 1) {
+		dev_info(&instance->pdev->dev, "we are doing unload so no need"
+			"to submit data to application. This may be force exit"
+			"from driver\n");
+		goto out;
+	}
 	/*
 	 * copy out the kernel buffers to user buffers
 	 */
Signature · 1 line
1.7.1
#1 lore raw
Quoted 49 lines · On 11/10/2014 01:21 PM, [email protected] wrote:

Do not process any SCSI and IOCTL command further(return them with appropriate return values to callers), while driver removal is in progress/PCI shutdown is invoked.

---
 drivers/scsi/megaraid/megaraid_sas_base.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +10 -4
index f6a69a3..7754eeb 100644
@@ -1572,6 +1572,12 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
 	instance = (struct megasas_instance *)
 	    scmd->device->host->hostdata;
 
+	if (instance->unload == 1) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		return 0;
+	}
+
 	if (instance->issuepend_done == 0)
 		return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -4957,10 +4963,6 @@ static int megasas_io_attach(struct megasas_instance *instance)
 		return -ENODEV;
 	}
 
-	/*
-	 * Trigger SCSI to scan our drives
-	 */
-	scsi_scan_host(host);
 	return 0;
 }
 
@@ -5288,6 +5290,10 @@ retry_irq_register:
 		goto fail_io_attach;
 
 	instance->unload = 0;
+	/*
+	 * Trigger SCSI to scan our drives
+	 */
+	scsi_scan_host(host);
 
 	/*
 	 * Initiate AEN (Asynchronous Event Notification)

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6058

Quoted 2 lines
drivers/scsi/megaraid/megaraid_sas_base.c +0 -0
@@ -6051,6 +6057,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
 	megasas_issue_blocked_cmd(instance, cmd, 0);
 	cmd->sync_cmd = 0;

I've expected that you'll not send the command to the card, you first issue blocked command and after that test unload state. Shouldn't it be reversed?

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6063

Quoted 5 lines
drivers/scsi/megaraid/megaraid_sas_base.c +4 -0
+	if (instance->unload == 1) {
+		dev_info(&instance->pdev->dev, "we are doing unload so no need"
+			"to submit data to application. This may be force exit"
+			"from driver\n");

I'm not a native speaker, so I'll not comment on the wording, but you should add a space at the line breaks.
+ dev_info(&instance->pdev->dev, "we are doing unload so no need "
+ "to submit data to application. This may be force exit "
+ "from driver\n");

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6068

Quoted 5 lines
drivers/scsi/megaraid/megaraid_sas_base.c +2 -0
+		goto out;
+	}
 	/*
 	 * copy out the kernel buffers to user buffers
 	 */

Aren't there other ioctl paths too - for example megasas_mgmt_ioctl_aen - isn't a block needed there too?

#2 lore raw
Quoted 10 lines

-----Original Message-----
From: Tomas Henzl [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 7:13 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 3/7] megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

Quoted 3 lines
Quoted 2 lines · On 11/10/2014 01:21 PM, [email protected] wrote:

Do not process any SCSI and IOCTL command further(return them with appropriate return values to callers), while driver removal is in

progress/PCI

Quoted 48 lines

shutdown is invoked.

drivers/scsi/megaraid/megaraid_sas_base.c megasas_queue_command(struct Scsi_Host

Quoted 13 lines
---
 drivers/scsi/megaraid/megaraid_sas_base.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +0 -0
index f6a69a3..7754eeb 100644
@@ -1572,6 +1572,12 @@ megasas_queue_command(struct Scsi_Host

*shost, struct scsi_cmnd *scmd)

drivers/scsi/megaraid/megaraid_sas_base.c static int megasas_io_attach(struct

Quoted 13 lines
drivers/scsi/megaraid/megaraid_sas_base.c +6 -0
 	instance = (struct megasas_instance *)
 	    scmd->device->host->hostdata;
 
+	if (instance->unload == 1) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		return 0;
+	}
+
 	if (instance->issuepend_done == 0)
 		return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -4957,10 +4963,6 @@ static int megasas_io_attach(struct

megasas_instance *instance)

Quoted 19 lines
drivers/scsi/megaraid/megaraid_sas_base.c +4 -4
 		return -ENODEV;
 	}
 
-	/*
-	 * Trigger SCSI to scan our drives
-	 */
-	scsi_scan_host(host);
 	return 0;
 }
 
@@ -5288,6 +5290,10 @@ retry_irq_register:
 		goto fail_io_attach;
 
 	instance->unload = 0;
+	/*
+	 * Trigger SCSI to scan our drives
+	 */
+	scsi_scan_host(host);
 
Quoted 8 lines

drivers/scsi/megaraid/megaraid_sas_base.c retry_irq_register:

Quoted 3 lines
drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
 	/*
 	 * Initiate AEN (Asynchronous Event Notification) @@ -6051,6
+6057,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance

*instance,

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6058

Quoted 2 lines
drivers/scsi/megaraid/megaraid_sas_base.c +0 -0
 	megasas_issue_blocked_cmd(instance, cmd, 0);
 	cmd->sync_cmd = 0;

I've expected that you'll not send the command to the card, you first

issue

Quoted 2 lines

blocked command and after that test unload state.
Shouldn't it be reversed?

Actually, there was a two part of this Patch for IOCTL path. One will not allow to send IOCTL while driver removal.
Another will not use already return IOCTL from FW to avoid illegal memory access on MFI frame.
Driver wakeup all blocked command in unload path and MFI/MPT frames are freed as well, so this check is good to have.

As you suggested, we missed to have another check in IOCTL path, before driver takes semaphore. It was planned, but somehow we missed while submitting this patch set.
We will send incremental patch for that part.

Quoted 6 lines

drivers/scsi/megaraid/megaraid_sas_base.c

Quoted 4 lines
drivers/scsi/megaraid/megaraid_sas_base.c +2 -0
+	if (instance->unload == 1) {
+		dev_info(&instance->pdev->dev, "we are doing unload so no

need"

drivers/scsi/megaraid/megaraid_sas_base.c

Quoted 1 line
drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"to submit data to application. This may be force

exit"

Quoted 3 lines

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6063

Quoted 1 line
drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"from driver\n");

I'm not a native speaker, so I'll not comment on the wording, but you

should

Quoted 1 line

add a space at the line breaks.

Agree. will address this part.

Review

Quoted 3 lines
(quoted diff) +1 -0
+		dev_info(&instance->pdev->dev, "we are doing unload so no

need "

(quoted diff) +1 -0
+			"to submit data to application. This may be force

exit

Quoted 10 lines

"

drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"from driver\n");

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6068

Quoted 6 lines
drivers/scsi/megaraid/megaraid_sas_base.c +2 -0
+		goto out;
+	}
 	/*
 	 * copy out the kernel buffers to user buffers
 	 */

Aren't there other ioctl paths too - for example megasas_mgmt_ioctl_aen

-

Quoted 1 line

isn't a block needed there too?

This path will be cleanup from megasas_shutdown_controller() call. AEN
and MAP SYNC command will be aborted explicitly.

Quoted 1 line
#3 lore raw
Quoted 78 lines

-----Original Message-----
From: Kashyap Desai [mailto:[email protected]]
Sent: Wednesday, November 12, 2014 4:39 PM
To: 'Tomas Henzl'; Sumit Saxena; '[email protected]'
Cc: '[email protected]'; '[email protected]'; '[email protected]'; '[email protected]'
Subject: RE: [PATCH 3/7] megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

Quoted 10 lines

-----Original Message-----
From: Tomas Henzl [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 7:13 PM
To: [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 3/7] megaraid_sas : Do not process IOCTLs and SCSI commands during driver removal

Quoted 10 lines
Quoted 3 lines · On 11/10/2014 01:21 PM, [email protected] wrote:

Do not process any SCSI and IOCTL command further(return them with appropriate return values to callers), while driver removal is in progress/PCI

shutdown is invoked.

Quoted 5 lines
---
 drivers/scsi/megaraid/megaraid_sas_base.c |   20 ++++++++++++++++--

--

Quoted 46 lines

drivers/scsi/megaraid/megaraid_sas_base.c megasas_queue_command(struct Scsi_Host

Quoted 8 lines
 1 files changed, 16 insertions(+), 4 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +0 -0
index f6a69a3..7754eeb 100644
@@ -1572,6 +1572,12 @@ megasas_queue_command(struct Scsi_Host

*shost, struct scsi_cmnd *scmd)

drivers/scsi/megaraid/megaraid_sas_base.c static int megasas_io_attach(struct

Quoted 13 lines
drivers/scsi/megaraid/megaraid_sas_base.c +6 -0
 	instance = (struct megasas_instance *)
 	    scmd->device->host->hostdata;
 
+	if (instance->unload == 1) {
+		scmd->result = DID_NO_CONNECT << 16;
+		scmd->scsi_done(scmd);
+		return 0;
+	}
+
 	if (instance->issuepend_done == 0)
 		return SCSI_MLQUEUE_HOST_BUSY;
 
@@ -4957,10 +4963,6 @@ static int megasas_io_attach(struct

megasas_instance *instance)

Quoted 12 lines
drivers/scsi/megaraid/megaraid_sas_base.c +0 -4
 		return -ENODEV;
 	}
 
-	/*
-	 * Trigger SCSI to scan our drives
-	 */
-	scsi_scan_host(host);
 	return 0;
 }
 
@@ -5288,6 +5290,10 @@ retry_irq_register:
 		goto fail_io_attach;

drivers/scsi/megaraid/megaraid_sas_base.c retry_irq_register:

Quoted 10 lines
drivers/scsi/megaraid/megaraid_sas_base.c +5 -0
 
 	instance->unload = 0;
+	/*
+	 * Trigger SCSI to scan our drives
+	 */
+	scsi_scan_host(host);
 
 	/*
 	 * Initiate AEN (Asynchronous Event Notification) @@ -6051,6
+6057,12 @@ megasas_mgmt_fw_ioctl(struct megasas_instance

*instance,

Quoted 7 lines
Quoted 6 lines

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6058

Quoted 2 lines
drivers/scsi/megaraid/megaraid_sas_base.c +0 -0
 	megasas_issue_blocked_cmd(instance, cmd, 0);
 	cmd->sync_cmd = 0;

I've expected that you'll not send the command to the card, you first issue blocked command and after that test unload state. Shouldn't it be reversed?

Actually, there was a two part of this Patch for IOCTL path. One will

not allow

Quoted 2 lines

to send IOCTL while driver removal.
Another will not use already return IOCTL from FW to avoid illegal

memory

Quoted 8 lines

access on MFI frame.
Driver wakeup all blocked command in unload path and MFI/MPT frames are freed as well, so this check is good to have.

As you suggested, we missed to have another check in IOCTL path, before driver takes semaphore. It was planned, but somehow we missed while submitting this patch set.
We will send incremental patch for that part.

Correction - First of all sorry for confusion. megasas_mgmt_ioctl_fw and megasas_mgmt_ioctl_aen already has a check for instance->unload. We don't need any changes for this patch.

Tomas -
We are planning to provide resend patch series which will have changes for below two patch.
[PATCH 1/7] megaraid_sas : Driver version upgrade and
[PATCH 4/7] megaraid_sas : Online Firmware upgrade support for Extended VD feature

` Kashyap

Quoted 7 lines
Quoted 7 lines

drivers/scsi/megaraid/megaraid_sas_base.c

Quoted 5 lines
drivers/scsi/megaraid/megaraid_sas_base.c +2 -0
+	if (instance->unload == 1) {
+		dev_info(&instance->pdev->dev, "we are doing unload so no

need"

drivers/scsi/megaraid/megaraid_sas_base.c

Quoted 1 line
drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"to submit data to application. This may be force

exit"

Quoted 10 lines
Quoted 4 lines

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6063

Quoted 1 line
drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"from driver\n");

I'm not a native speaker, so I'll not comment on the wording, but you should add a space at the line breaks.

Agree. will address this part.

Review

Quoted 3 lines
(quoted diff) +1 -0
+		dev_info(&instance->pdev->dev, "we are doing unload so no

need "

(quoted diff) +1 -0
+			"to submit data to application. This may be force

exit

Quoted 15 lines
Quoted 11 lines

"

drivers/scsi/megaraid/megaraid_sas_base.c +1 -0
+			"from driver\n");

drivers/scsi/megaraid/megaraid_sas_base.c megasas_mgmt_fw_ioctl(struct megasas_instance *instance, · line 6068

Quoted 6 lines
drivers/scsi/megaraid/megaraid_sas_base.c +2 -0
+		goto out;
+	}
 	/*
 	 * copy out the kernel buffers to user buffers
 	 */

Aren't there other ioctl paths too - for example megasas_mgmt_ioctl_aen - isn't a block needed there too?

This path will be cleanup from megasas_shutdown_controller() call. AEN
and MAP SYNC command will be aborted explicitly.

Quoted 1 line