AdapterControl thread context and spinlock acquisition

Hi,

Theory:
When I make a call to AllocateAdapterChannel the AdapterControl routine “is called when the bus-master adapter becomes available”. I notice that sometimes it gets called immediately, sometimes (under load) after a little while.

Questions:
When it gets called immediately does it run on the same thread that called AllocateAdapterChannel?
My actual question is the following: If the caller of AllocateAdapterChannel is holding some spinlock, is it safe for the AdapterControl routine to try and acquire the same spinlock?

Thanks,
Dimitris Staikos

To answer my own question, I did some testing and it seems that it is not safe to try and acquire the same spinlock inside the AdapterControl routine.
The funny thing is that I used KeAcquireSpinLockAtDpcLevel and everything worked fine… on a single CPU machine. The function is actually a nop in the single processor HAL. On the MP machine we tried, when the spinlock is “reentered” either the system freezes completely, or the test process hungs (and if you try to kill it from the task manager then the system freezes).

Dimitris Staikos

In general you to ask yourself this every time you are holding a lock
and calling outside of your driver: “can this call cause the current
thread to reenter my driver?” If the answer is yes under any
circumstance, the you must not hold the lock while making the call. The
same logic would apply to holding a lock while calling IoCallDriver

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@staikos.name
Sent: Thursday, August 10, 2006 7:15 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] AdapterControl thread context and spinlock
acquisition

To answer my own question, I did some testing and it seems that it is
not safe to try and acquire the same spinlock inside the AdapterControl
routine.
The funny thing is that I used KeAcquireSpinLockAtDpcLevel and
everything worked fine… on a single CPU machine. The function is
actually a nop in the single processor HAL. On the MP machine we tried,
when the spinlock is “reentered” either the system freezes completely,
or the test process hungs (and if you try to kill it from the task
manager then the system freezes).

Dimitris Staikos


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

> When it gets called immediately does it run on the same thread that called

AllocateAdapterChannel?

No guarantees at all.

My actual question is the following: If the caller of AllocateAdapterChannel
is
holding some spinlock

Very, very bad idea. Call AllocateAdapterChannel without holding any locks.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com