<HTML xmlns:v = "urn:schemas-microsoft-com:vml" xmlns:o = "urn:schemas-microsoft-com:office:office" xmlns:w = "urn:schemas-microsoft-com:office:word" xmlns:m = "http://schemas.microsoft.com/office/2004/12/omml"><HEAD><TITLE>Samsung Enterprise Portal mySingle</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>P {
MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
TD {
MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
LI {
MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
BODY {
FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN: 10px; LINE-HEIGHT: 1.4
}
</STYLE>
<META content=IE=5 http-equiv=X-UA-Compatible>
<META content=IE=5 http-equiv=X-UA-Compatible>
<META name=GENERATOR content="MSHTML 11.00.9600.18212"></HEAD>
<BODY>
<P> </P>
<P><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri">Thanks Tom.</SPAN></P>
<P><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"></SPAN> </P>
<P><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri">To other reviewers: Please let me know if there is any comments/concerns.</SPAN></P>
<P><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"></SPAN> </P>
<P><SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri">- Suman</SPAN></P>
<P> </P>
<P>------- <B>Original Message</B> -------</P>
<P><B>Sender</B> : Thomas Freeman<thomas.freeman@hgst.com></P>
<P><B>Date</B> : May 27, 2016 02:45 (GMT+05:30)</P>
<P><B>Title</B> : RE: [nvmewin] Patch for handling surprise removal in IOCTL path</P>
<P> </P>
<META name=Generator content=ActiveSquare>
<STYLE>@font-face {
font-family: Cambria Math;
}
@font-face {
font-family: Calibri;
}
@page WordSection1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
FONT-SIZE: 12pt; FONT-FAMILY: "Times New Roman",serif; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-believe-normal-left: yes
}
LI.MsoNormal {
FONT-SIZE: 12pt; FONT-FAMILY: "Times New Roman",serif; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-believe-normal-left: yes
}
DIV.MsoNormal {
FONT-SIZE: 12pt; FONT-FAMILY: "Times New Roman",serif; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-believe-normal-left: yes
}
A:link {
TEXT-DECORATION: underline; COLOR: #0563c1; mso-style-priority: 99
}
SPAN.MsoHyperlink {
TEXT-DECORATION: underline; COLOR: #0563c1; mso-style-priority: 99
}
A:visited {
TEXT-DECORATION: underline; COLOR: #954f72; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
TEXT-DECORATION: underline; COLOR: #954f72; mso-style-priority: 99
}
P {
FONT-SIZE: 9pt; FONT-FAMILY: "Arial",sans-serif; MARGIN: 3.75pt 0in; mso-style-priority: 99
}
SPAN.EmailStyle19 {
FONT-FAMILY: "Calibri",sans-serif; FONT-WEIGHT: normal; COLOR: #1f497d; FONT-STYLE: normal; mso-style-type: personal-reply
}
.MsoChpDefault {
FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.WordSection1 {
page: WordSection1
}
</STYLE>
<META content=IE=5 http-equiv=X-UA-Compatible><X-BODY lang=EN-US style="MARGIN: 7.5pt" link="#0563C1" vlink="#954F72">
<DIV class=WordSection1>
<P class=MsoNormal><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif; COLOR: #1f497d'>Suman,<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif; COLOR: #1f497d'>I’ve reviewed changes and have no comments/concerns.<o:p></o:p></SPAN></P>
<DIV>
<P class=MsoNormal><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif; COLOR: #1f497d'>Thank you,<o:p></o:p></SPAN></P>
<P class=MsoNormal><B><SPAN style='FONT-SIZE: 10pt; FONT-FAMILY: "Arial",sans-serif; COLOR: #1f497d'>Tom Freeman<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B><SPAN style='FONT-SIZE: 10pt; FONT-FAMILY: "Arial",sans-serif; COLOR: #1f497d'>Software Engineer, Device Manager and Driver Development<o:p></o:p></SPAN></B></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style='FONT-SIZE: 10pt; FONT-FAMILY: "Arial",sans-serif; COLOR: #1f497d'>Western Digital Corporation<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style='FONT-SIZE: 10pt; FONT-FAMILY: "Arial",sans-serif; COLOR: #1f497d'>e. Thomas.freeman@hgst.com<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style='FONT-SIZE: 10pt; FONT-FAMILY: "Arial",sans-serif; COLOR: #1f497d'>o. +1-507-322-2311<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif; COLOR: #1f497d'><o:p> </o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif; COLOR: #1f497d'><o:p> </o:p></SPAN></P></DIV>
<DIV>
<DIV style="BORDER-TOP: #e1e1e1 1pt solid; BORDER-RIGHT: medium none; BORDER-BOTTOM: medium none; PADDING-BOTTOM: 0in; PADDING-TOP: 3pt; PADDING-LEFT: 0in; BORDER-LEFT: medium none; PADDING-RIGHT: 0in">
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>From:</SPAN></B><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'> nvmewin [mailto:nvmewin-bounces@lists.openfabrics.org] <B>On Behalf Of </B>SUMAN PRAKASH B<BR><B>Sent:</B> Monday, May 16, 2016 8:21 AM<BR><B>To:</B> nvmewin@lists.openfabrics.org; raymond.c.robles@intel.com<BR><B>Subject:</B> [nvmewin] Patch for handling surprise removal in IOCTL path<o:p></o:p></SPAN></P></DIV></DIV>
<P class=MsoNormal><o:p> </o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>Hi All,</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>This patch includes changes for supporting device surprise removal in IOCTL path. Samsung already submitted a patch to handle surprise removal during normal I/O in 2014. This patch is an extention to the previous patch.</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>I have made a detailed overview of the changes in the attached doc file(the contents are also copied here below) and the attached zip file contains the source code.</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>Password is samsungnvme<BR> <BR>Please let me know if you have any questions.<BR> <BR>Thanks,<BR>Suman<BR><BR>***************************************</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><STRONG><U><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>Handling device Surprise removal in IOCTL path:</SPAN></U></STRONG><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'> Current OFA driver does not need any change to support surprise removal when no I/Os are outstanding. But when I/Os are outstanding and the device is surprise removed, the tool(lets say IOMeter) hangs and the device is not removed from the device manager for very long time. Since NVMe is suprise remove capable device, user expectation is that the tool should exit/stop gracefully and the device should be removed from the device manage immediately.</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'> The Windows storage stack currently does not handle surprise removal during outstanding I/Os. To handle this scenario, we have submitted a patch in 2014. But this patch was handling surprise removal during normal I/O commands and not when IOCTL commands from proprietary tools were outstanding.<BR> In the previous patch, we had implemented the StorPortNotification(RequestTimerCall,…) to handle surprise removal durign I/O. This API does not detect surprise removal when executing IOCTL commands. For example, when executing Format NVM command with Secure erase or Cryptographic erase, when device is surprise removed, the device is not removed from the device manager and system hangs.</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'> To fix this issue, in Windows 8 and later versions, there is support for StorPortRequestTimer() which does the same as StorPortNotification(RequestTimerCall,…). When StorPortRequestTimer() is used, device surprise removal during IOCTL commands is also detected. Hence for Win 7 kernel, StorPortNotification(RequestTimerCall,…) and for Win 8 and above kernels, StorPortRequestTimer() can be used.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><STRONG><U><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>Code changes:</SPAN></U></STRONG><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>1. In NVMeFindAdapter(), initialize the timer routine using StorPortInitializeTimer() API.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>2. In NVMeRunning(), in NVMeStartComplete, start the surprise removal timer routine.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>3. Stop the timer routine using StorPortRequestTimer() in following functions:<BR> a. In NVMeAdapterControl(), in ScsiStopAdapter, when shutting down the device<BR> b. In NVMeBuildIo(), for SRB_FUNCTION_SHUTDOWN<BR> c. In NVMeBuildIo(), for SRB_FUNCTION_PNP, if PnPAction is StorRemoveDevice or StorSurpriseRemoval and ntldrDump is FALSE</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>4. Free the timer routine using StorPortFreeTimer() in following functions:<BR> a. In NVMePassiveInitialize(), when the initialization state machine fails<BR> b. In NVMeAdapterControl(), in ScsiStopAdapter, when shutting down the device<BR> c. In NVMeBuildIo(), for SRB_FUNCTION_SHUTDOWN,<BR> d. In NVMeBuildIo(), for SRB_FUNCTION_PNP, if PnPAction is StorRemoveDevice or StorSurpriseRemoval and ntldrDump is FALSE<BR> e. In NVMeStartIo(), when NextDriverState is not NVMeStartComplete<BR> f. In RecoveryDpcRoutine()</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>5. New Surprise removal timer routine IsDeviceRemoved() for kernels above Windows 8 which uses StorPortFreeTimer() and StorPortRequestTimer().</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>6. In FormatNVMGetIdentify(), when the structure to retrieve is Identify namespace, the lunId is set to INVALID_LUN_EXTN, because of which BSOD is observed. Invoked the function NVMeIsNamespaceVisible() to correct this. We observed this when secure erase in IOCTL is in progress, and device is surprise removed.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>7. In NVMeBuildIo(), to block read/write commands when format nvm is in progress, we have a check. But when formatNVM is in progress, we get requests other than SRB_FUNCTION_EXECUTE_SCSI, like SRB_FUNCTION_PNP or SRB_FUNCTION_IO_CONTROL, in which case opCode = GET_OPCODE(Srb) in line number 1125 results in BSOD. This is observed when secure erase is executed in IOCTL path, and system is hibernated and then device is surprise removed. Hence moved the blocking of Read/Write commands while Format NVM is in progress code inside SRB_FUNCTION_EXECUTE_SCSI.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>8. Changes in inf file:<BR> a. Following line has been included to allow interrupts on processors beyond group 0. For the StorPortInitializePerfOpts() MessageTargets to work correctly when a system has multiple groups are, the following line is required, otherwise we observe BSOD. Also, when we tested in a system which has 1 group by default and 32 logical processors in Server 2012R2, some WHQL tests create multiple groups after which the driver does not work properly if the below line is not included in inf file.<BR> HKR, Interrupt Management\Affinity Policy, GroupPolicy, %REG_DWORD%, 1</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'> b. Following line has been included to specifies that the device's interrupts are of high priority.<BR> HKR, Interrupt Management\Affinity Policy, DevicePriority, %REG_DWORD%, 3</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>9. As requested by HGST, the MAX_NAMESPACES is changed to 128. Correspondingly, the DUMP_BUFFER_SIZE is also changed from (5*64*1024) to ((5*64*1024) + (sizeof(NVME_LUN_EXTENSION)*MAX_NAMESPACES)). If DUMP_BUFFER_SIZE is not increased, in dump mode, in NVMeInitialize(), memory allocation for pAE->pLunExtensionTable will fail.</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>Also, the correct method to implement the above would be to allocate memory for pAE->pLunExtensionTable in NVMeInitCallback() in the NVMeWaitOnIdentifyCtrl state, where we get the number of Namespaces supported by the device, and remove the memory allocated for pAE->pLunExtensionTable in dump mode(NVMeInitialize()) and in normal mode(NVMePassiveInitialize()).</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>For this patch, we have set DUMP_BUFFER_SIZE to ((5*64*1024) + (sizeof(NVME_LUN_EXTENSION) * MAX_NAMESPACES)). Please note that as per MSDN, we should not allocate more than 32 KB for RequestedDumpBufferSize.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>10. Implemented ScsiAdapterPower controltype in NVMeAdapterControl(). ScsiAdapterPower executes in <= DISPATCH_IRQL. This is supported only from Windows 8. Since we need to free the buffer and stop the timer only at IRQL <= DISPATCH_IRQL, this is implemented. Also, this will avoid executing initialization state machine in NVMeReInitializeController in ScsiRestartAdapter(DIRQL) during resume from hibernation.</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P><STRONG><U><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>We have tested following:</SPAN></U></STRONG><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>a. WHQL tests</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>b. Connect device -> execute secure erase in IOCTL path -> during secure erase execution remove device -> expectation: disk should be removed and tool(executing the secure erase) should exit gracefully</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>c. Connect device -> hibernation -> remove device -> resume -> expectation: disk should be removed</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>d. Connect device -> run IOMeter -> execute secure erase in IOCTL path -> hibernation -> remove device -> resume -> expectation: disk should be removed and tools should exit gracefully</SPAN><o:p></o:p></P>
<P><SPAN style='FONT-SIZE: 11pt; FONT-FAMILY: "Calibri",sans-serif'>c. OS installation</SPAN><o:p></o:p></P>
<P> <o:p></o:p></P>
<P> </P></DIV></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=e7bc4897eaf7ac7a189c3eecb549349dcf4c3e2988f127767d9badbdf7e30042d1afaaba7860cdcd9564217c646641ad61e16949eaa607501b20909a04efd4d2748cfe1d4e847419cf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>