Hi all,
I have a driver reading files from a file system (here called somefs.sys), but when I open these files for asynchronous I/O, which means not using FILE_SYNCHRONOUS_IO_ALERT flag on IoCreateFile, I?m seeing a hang. I ended up finding eight threads stuck at the same point as described below:
0: kd> kc
*** Stack trace for last set context - .thread/.cxr resets it
Call Site
00 nt!KiSwapContext
01 nt!KiCommitThreadWait
02 nt!KeWaitForSingleObject
03 nt!MiWaitForInPageComplete
04 nt!CcFetchDataForRead
05 nt!CcCopyRead
06 somefs+0x4d49c
07 somefs+0x29c6a
08 nt!PspSystemThreadStartup
09 nt!KiStartSystemThread
All these eight threads have their special APC disabled as follows:
0: kd> dt nt!_KTHREAD @$thread SpecialApcDisable
+0x1c6 SpecialApcDisable : 0n-1
After some investigation, I saw that at the time CcCopyRead was called, special APC was still enabled, but during its execution, the same driver received a paging I/O read request (as expected), but this time the special APC was disabled.
This driver then creates new IRPs using IoMakeAssociatedIrp and call IoCallDriver routine still having special APC disabled.
0: kd> kc
*** Stack trace for last set context - .thread/.cxr resets it
Call Site
00 nt!IoMakeAssociatedIrp
01 somefs+0x4ca6b
02 somefs!DispatchRead+0x60
03 mup!MupiCallUncProvider+0x169
04 mup!MupStateMachine+0x165
05 mup!MupFsdIrpPassThrough+0x12d
06 fltmgr!FltpLegacyProcessingAfterPreCallbacksCompleted+0x24f
07 fltmgr!FltpDispatch+0xcf
08 nt!IoPageRead+0x2a9
09 nt!MiPfExecuteReadList+0xff
10 nt!MmPrefetchForCacheManager+0xb5
11 nt!CcFetchDataForRead+0x17d
12 nt!CcCopyRead+0x180
13 somefs+0x4d49c
14 somefs+0x29c6a
15 nt!PspSystemThreadStartup+0x5a
16 nt!KxStartSystemThread+0x16
These threads then return to Cache Manager routines as shown at the first stack trace and they keep waiting for the paging I/O to complete, but they never complete.
I read from the documentation that special APC is used for I/O completion. When handling paging I/O, a driver should check for APCs using KeAreAllApcDisabled routine before creating new IRPs with IoBuildSynchronousFsdRequest, but I?m not sure about using IoMakeAssociatedIrp.
Just to mention, the hang never happens when I open files for synchronous I/O. I don’t think there are special requirements for opening files for asynchronous I/O, right?
Any idea is welcome.
Thanks in advance,
?
Fernando Roberto da Silva
DriverEntry Kernel Development
http:\www.DriverEntry.com.br