Dangerous idea...

I would like to implement a dangerous idea – for the best possible reason, of course: performance.

I use an IOCTL to initiate a request packet/message to go outbound via DMA over PCIe to my custom device. In the output buffer of the IOCTL I get passed a fixed length section that is a counted Unicode string naming a target. That is followed by a mostly-filled-out message packet. That is followed by data for some of the commands. This is all working fine. The driver keeps internal structures to translate the name to an internal ID. It then fills in all of the critical parts of the packet for security reasons. Then it gets a MDL for the output buffer and initiates an outbound DMA using the offset and length parameters to skip the header as well as round the transmission size to the correct byte multiple the hardware demands.

My dangerous idea is to avoid the caller having to copy the outbound data for those commands that require data. Less copying is always better, right?

The thought is to the the input buffer of the IOCTL to describe the data. This can be done without copying any data; it would just span the needed data directly. I can get a MDL for the input buffer with a call similar to getting the output buffer MDL. The dangerous part is that I want to link the input buffer’s MDL to the output buffer’s MDL and then initiate the outbound DMA transaction. The code is simple – just set the last in the output buffer’s MDL chain Next to point to the input buffer’s chain and ensure the specified length when calling the transaction initialization is correct for the whole thing. Simple, huh? From what I have read the DMA’s scatter/gather would have no trouble handling just a list.

But, it is cheating behind the OS’s back. I could reset that Next to the original NULL to re-separate the lists, but when? After initialize? After Start? There is little I can find on reference lifetimes.

Of course, if there is an approved/legitimate way to do this type of combination then I would be happy to use it!

I am soliciting comments as I have much less Windows driver experience than many here in this forum. (My DMA driver experience goes back to 1970, which is why I tend to have dangerous ideas.)

(empty message)