Re: Interesting KMDF Gotcha

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



this is great feedback, I will fwd it to the team.

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Tim Roberts" <timr@xxxxxxxxx> wrote in message
news:gsusm2h2vh97p02ge319eb9ngbe3kdmi0q@xxxxxxxxxx
I encountered an interesting problem today. It was entirely of my own
doing, but I wanted to present the story as a "bad example".

I did a KMDF driver for a client, who has a DMA-based PCI device that also
accepts a bunch of commands. I started from plx9x5x sample, radically
altered.

As I was going through the sample, I came to the routine that creates the
interrupt. When I saw the code was setting AutomaticSerialization to
TRUE,
I read the description, and said "gosh, that sounds like a good idea".

Last week, the client complained that, during testing, on some
motherboards, certain commands caused the machine to lock up tight --
power
cycle required.

As it turns out, some of the commands I have to execute take a couple of
milliseconds to complete. I block (using KeDelayExecutionThread) waiting
for the "command complete" bit to set. What happened in this particular
case is that I got an interrupt while I was waiting. Because
AutomaticSerialization was set, the framework's interrupt handler tried to
acquire the framework device spinlock, which, of course, I was already
holding in my blocked dispatch callback. This caused a nice, tight,
efficient infinite loop, with interrupts disabled, at DIRQL.

I've now gone through the driver from top to bottom with a new
appreciation
for the synchronization settings. The fact that I have the framework
acquiring spinlocks on my behalf makes it way too easy to violate the
"never block with a spinlock held" rule.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.


.



Relevant Pages

  • Re: Interesting KMDF Gotcha
    ... What is the execution level and synchronization you specified on the device? ... When you opt for AutomaticSerialization on the interrupt object, ... cannot acquire the spinlock when it calls the ISR. ... accepts a bunch of commands. ...
    (microsoft.public.development.device.drivers)
  • Re: Interesting KMDF Gotcha
    ... accepts a bunch of commands. ... case is that I got an interrupt while I was waiting. ... acquire the framework device spinlock, which, of course, I was already ... "never block with a spinlock held" rule. ...
    (microsoft.public.development.device.drivers)
  • Interesting KMDF Gotcha
    ... accepts a bunch of commands. ... case is that I got an interrupt while I was waiting. ... acquire the framework device spinlock, which, of course, I was already ... "never block with a spinlock held" rule. ...
    (microsoft.public.development.device.drivers)
  • Re: Interesting KMDF Gotcha
    ... What is the execution level and synchronization you specified on the device? ... When you opt for AutomaticSerialization on the interrupt object, ... cannot acquire the spinlock when it calls the ISR. ... accepts a bunch of commands. ...
    (microsoft.public.development.device.drivers)
  • [patch 02/33] m68k: Reformat the Atari SCSI driver
    ... NCR 5380 generic driver routines. ... SCSI Protocol Controller ... * commands were hacked on rather than designed in from the start. ... which is started when not running by the interrupt handler, ...
    (Linux-Kernel)