Make that “out of your driver and into user mode”.
-p
This posting is provided “AS IS” with no warranties, and confers no rights
-----Original Message-----
From: Peter Wieland [mailto:xxxxx@windows.microsoft.com]
Sent: Thursday, April 24, 2003 11:54 AM
To: NT Developers Interest List
The cost of the spinlock acquisition is probably going to pale in comparison to your encryption/decryption. And most of the other synchronization mechansims use some sort of spinlock to protect their internal state anyway.
On the note of not wanting external programs - personally I think you should move as much code as possible out of your driver and into kernel mode. I suggest this because all code has the potential for bugs, because the code you’re writing doesn’t sound trivial, and because bugs in user-mode apps have a significantly less drastic effect on system stability.
-p
This posting is provided “AS IS” with no warranties, and confers no rights
-----Original Message-----
From: Jose Vicente Sanchez Ortega [mailto:xxxxx@secuware.com]
Sent: Thursday, April 24, 2003 11:40 AM
To: NT Developers Interest List
Peter:
I have been thinking about using spin-locks but I have doubts. Using this mechanism, every READ and WRITE request will raise processing level to DISPATCH thus making the systemt to respond “heavily” to disk access (I have not made tests, it’s only a guess). In relation with the posibility of caching requests, I must say that one of the premises is that initial ciphering process would be as quick as posible and I feel that it could not be a great idea to enque requests (again I’m guessing based only in my experience). The other solution that you describe (that by using an external app/service which can send IOCTL’s to the driver) I must say that I have thought about it some time ago but I would like to avoid using external applications.
Than you very much for your valuable help and your interest in this project.
Regards,
Jose Vicente.
-----Mensaje original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]En nombre de Peter Wieland Enviado el: jueves, 24 de abril de 2003 17:56
Para: NT Developers Interest List
Asunto: [ntdev] RE: Disk filter driver synchronization issue
all drivers are equal, but some are more equal than others.
the DDK documentation is probably talking about top-level drivers. Storage drivers are about as bottom-level as you can get in the IO stacks.
file systems occasionally retry request in their completion routines, which can be running at DPC level. Upper-level drivers can do the same. They could also issue new IRPs in timers, DPCs, etc …
additionally, storage drivers which are in the paging path (which could be just about any storage driver) cannot cause page-faults when servicing read or write requests, and cannot contend with any thread in such a path or it risks deadlock. This rules out touching paged pool, blocking, using the registry, etc… It’s also dangerous to use blocking locks since those locks could be acquired by your IOCTL routine which does cause page faults (which then issues a paging read to your driver which attempts to acquire the already acquired lock and you deadlock)
Just use spinlocks. As someone previously suggested, you should use them to protect a data structure which tells you which blocks are in progress and a queue of requests that are waiting for those blocks to be finished. when a read or write comes in you grab the lock, see if the block is busy (ie.
encryption in progress) and either (a) queue the operation until the block is no longer busy or (b) service the request using the unencrypted data that you have cached while doing your encryption.
It may be sufficient to ensure your driver thread doesn’t take page faults.
However i’m always a bit worried about adding threads into the paging path.
You might think about putting in a set of IOCTLs that your driver supports which allow some component to read a disk range and get back a token they can use when writing the encrypted data. If the block range has changed due to a normal write then the corresponding write IOCTL (which took the token supplied by the read) would fail indiciating to the encryptor that it should redo the encryption.
Another option woudl be to have one “encrypt block/range” ioctl which your thread sends to the driver which does the read/modify/write in chained completion routines (lock block, send read, in completion routine encrypt it and send write, in completion routine unlock block). This is more complex code split up across multiple routines but would avoid the inevitable case in my first suggestion where a disk block is too frequently written for you to manage to encrypt it. You might look at classpnp/cdrom’s IOCTL_CDROM_RAW_READ support for an example of this sort of chaining. On older CD’s each RAW_READ requires a cd command to switch the mode of the drive into larger sectors, a read and a subsequent command to switch it back.
In the latter case you might not even need a system thread and could have a formatter process which sends the IOCTLS from user-mode.
What do you do if the power to the machine is lost during the encryption process? Do you have metadata somewhere which records which blocks have been encrypted so you don’t reboot after only encrypting half the disk and think you’ve encrypted it all?
sounds like a fun project.
-p
-----Original Message-----
From: Jose Vicente Sanchez Ortega [mailto:xxxxx@secuware.com]
Sent: Thursday, April 24, 2003 3:21 AM
To: NT Developers Interest List
I’m not sure that is right. Reading DDK documentation (“Dispatching
Routines and IRLQ” article), both Read and Write dispatch routines can
be called at most at APC_LEVEL (actually at PASSIVE_LEVEL for most
drivers). Peter, can you confirm this issue, please?
Given this additional data, KeAcquireResourceLite can be called ay
APC_LEVEL and KeReleseResourceLite can be called at DISPATCH_LEVEL so
I wouldn’t have problems since I call KeReleseResourceLite in the
Completion routine.
Best regards,
Jose Vicente.
-----Mensaje original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]En nombre de Peter Wieland
Enviado el: mi?rcoles, 23 de abril de 2003 20:15
Para: NT Developers Interest List
Asunto: [ntdev] RE: Disk filter driver synchronization issue
Storage drivers must be prepared for read and write requests to come
in at DISPATCH_LEVEL. You cannot use a resource at dispatch level so
you will have problems with this mechanism.
You need to use another mechanism for your synchronization, or you
need to push your work off to a dedicated worker thread which cannot
cause page faults itself (by using paged-pool, by allowing itself to
get paged out during a wait, by calling code you’ve made pagable,
etc…)
-p
This posting is provided “AS IS” with no warranties, and confers no
rights
-----Original Message-----
From: Jos? Vicente S?nchez Ortega [mailto:xxxxx@terra.es]
Sent: Wednesday, April 23, 2003 11:06 AM
To: NT Developers Interest List
I have a HD upper filter driver for real-time ciphering/unciphering
and in the background, I have a system thread which opens the disk and
begins the initial ciphering process concurrently with normal OS
operation. I need to synchronize both processes to avoid garbaging
disk and I’m using ERESOURCE (lite version). I acquire the ERESOURCE
every time I receive and process a IRP_MJ_READ or IRP_MJ_WRITE and I’m
a little bit confused about reentrancy (re-acquiring ERESOURCE). Is it
safe to use this mechanism? Could I have any problem? I’m using both
Windows 2000 & XP.
Thanks a lot.
Jose Vicente.
You are currently subscribed to ntdev as:
xxxxx@microsoft.com To unsubscribe send a blank email to
xxxxx@lists.osr.com
You are currently subscribed to ntdev as:
xxxxx@secuware.com To unsubscribe send a blank email to
xxxxx@lists.osr.com
You are currently subscribed to ntdev as:
xxxxx@microsoft.com To unsubscribe send a blank email to
xxxxx@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@secuware.com To unsubscribe send a blank email to xxxxx@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com