IRQL question

Hi, Guys!

I did some “research” about IRQ levels etc., and I think I understand it
better now.
Just one thing that I still do not understand:

Let’s say that I read from my driver using ReadFile().
This function is called in IRQ_PASSIVE_LEVEL.

Now, why should I check the IRQL in the function that takes care of ReadFile
inside
the driver? I mean - is there a chance that this function would be called in
IRQL > IRQ_PASSIVE_LEVEL ?
How?

If it cannot happen - can you please give an example of when it CAN happen
(A general case, with any kind of IoCtl )?

Now, let’s say that I check IRQL, and it’s not the correct level - what
should I do next?
After all - I should return an answer to the user, and I don’t think that a
“failure” message is the correct one to return.

thanks in advance,

  • Barak

Barak Mandelovich xxxxx@mercury.co.il
Mercury Interactive ltd.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

In the case of a standalone or topmost driver, and assuming that we are not
discussing filesystem drivers here, your dispatch routines will always be
called at PASSIVE_LEVEL. However, not all drivers are at the top of the
stack, and even if they are, somebody else could install a filter driver
above your ‘topmost’ driver. Once there is another driver above you then it
is not true that you must always be called at PASSIVE_LEVEL, it is instead
the much weaker: you will generally be called at less than DISPATCH_LEVEL.
There are a few examples of driver stacks where some IRP dispatching occurs
at DISPATCH_LEVEL, although in my opinion, despite the terminology
relationship, this is rather rude.

If you have your own standalone monolithic topmost driver, then you can
simply enforce your own rule that IO requests must arrive at PASSIVE_LEVEL.
This may screw up a filter driver that acquires one of the synchronization
primitives that raise to APC_LEVEL, but that is a problem for the filter
driver. How to enforce this? Just complete the incoming irp with an error if
the IRQL is too high.

Another, ‘nicer’ approach is to test the IRQL level and if it is
inappropriate for your requirements, queue the IRP for background processing
by a worker thread (running at PASSIVE_LEVEL,) mark the IRP pending, setup a
cancel routine (etc. etc. and not in the order stated here,) and return
STATUS_PENDING to the caller.

Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
WindowsNT Windows 2000 Consulting Services

-----Original Message-----
From: Barak Mandelovich [mailto:xxxxx@mercury.co.il]
Sent: Tuesday, January 09, 2001 9:05 AM
To: NT Developers Interest List
Subject: [ntdev] IRQL question

Hi, Guys!

I did some “research” about IRQ levels etc., and I think I
understand it
better now.
Just one thing that I still do not understand:

Let’s say that I read from my driver using ReadFile().
This function is called in IRQ_PASSIVE_LEVEL.

Now, why should I check the IRQL in the function that takes
care of ReadFile
inside
the driver? I mean - is there a chance that this function
would be called in
IRQL > IRQ_PASSIVE_LEVEL ?
How?

If it cannot happen - can you please give an example of when
it CAN happen
(A general case, with any kind of IoCtl )?

Now, let’s say that I check IRQL, and it’s not the correct
level - what
should I do next?
After all - I should return an answer to the user, and I
don’t think that a
“failure” message is the correct one to return.

thanks in advance,

  • Barak


Barak Mandelovich xxxxx@mercury.co.il
Mercury Interactive ltd.



You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Sure …

Suppose Windgit Inc, sells a device driver that attaches to your driver so
they can control their Frammis 4000. Now, Widget’s driver writer, being the
genius that the boss’s sister said her son was, decides that his driver just
has to call IoCallDriver from DISPATCH_LEVEL. If your read dispatch routine
then does a simple ExAllocatePool(PagedPool, …) you will be looking at a
BSOD and everything points to you. You can test IRQL and allocate from
NonPagedPool, but I’d rather return an error code, since we all know that
Widget’s boss’s sister’s son is a pimply faced nerd.

Seriously, testing IRQL levels is really up to you and how you foresee your
driver being used. The general feeling is that your dispatch routines such
as Read/Write should be transparent to a call originating from a driver or
an application, and calling IoCallDriver at elevated IRQL is NOT
transparent. That means the third scenario is to field the support call and
then tell Widget that their call is out of spec since your documentation
specifically states that inter-driver communication must be done at
PASSIVE_LEVEL.

Gary

-----Original Message-----
From: Barak Mandelovich [mailto:xxxxx@mercury.co.il]
Sent: Tuesday, January 09, 2001 6:05 AM
To: NT Developers Interest List
Subject: [ntdev] IRQL question

Hi, Guys!

I did some “research” about IRQ levels etc., and I think I understand it
better now.
Just one thing that I still do not understand:

Let’s say that I read from my driver using ReadFile().
This function is called in IRQ_PASSIVE_LEVEL.

Now, why should I check the IRQL in the function that takes care of ReadFile
inside
the driver? I mean - is there a chance that this function would be called in
IRQL > IRQ_PASSIVE_LEVEL ?
How?

If it cannot happen - can you please give an example of when it CAN happen
(A general case, with any kind of IoCtl )?

Now, let’s say that I check IRQL, and it’s not the correct level - what
should I do next?
After all - I should return an answer to the user, and I don’t think that a
“failure” message is the correct one to return.

thanks in advance,

  • Barak

Barak Mandelovich xxxxx@mercury.co.il
Mercury Interactive ltd.


You are currently subscribed to ntdev as: xxxxx@delphieng.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Some APIs like IoRequestDpc(), as the DDK says, must be specifically invoked at an IRQL >= DISPATCH_LEVEL. Has anyone ever tried invoking them at PASSIVE_LEVEL? What could be the result?

Thanks
Matteo


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

At 08:13 PM 1/27/01 +0100, you wrote:

Some APIs like IoRequestDpc(), as the DDK says, must be specifically
invoked at an IRQL >= DISPATCH_LEVEL. Has anyone ever tried invoking them
at PASSIVE_LEVEL? What could be the result?

Thanks
Matteo

You just call your routine from your passive code. No need to queue it.
Your code should
be able to run in passive mode. If not, you can raise the IRQL before
calling it and lower it
just after. A spinlock will do just that.

George


George Blat
BRD Corp
8016 188th SW, Edmonds, WA 98026

phone: 425-775-7475
fax: 781-998-5940
mailto:xxxxx@brd.com
http://www.brd.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

“Matteo Pelati” wrote in message news:xxxxx@ntdev…
Some APIs like IoRequestDpc(), as the DDK says, must be specifically invoked
at an IRQL >= DISPATCH_LEVEL. Has anyone ever tried invoking them at
PASSIVE_LEVEL? What could be the result?

The result could be VERY UGLY. Like, unpredictable system behavior.

If the DDI is documented to be called at IRQL’s >= DISPATCH_LEVEL, then the
code you are calling is relying on that level of synchronization. You can
NOT call the function at lower IRQLs.

If you’re running at a lower IRQL, and you need to call a function with a
higher IRQL requirement, just KeRaiseIrql() to the IRQL you need, call the
function, and then KeLowerIrql() afterwards. No need to take a spin lock.

PeterGV
OSR Open Systems Resources, Inc.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,

What I meant to say is that if you Acquire a spinlock you don’t need to
call KeRaiseIrql()
to DISPATCH_LEVEL because the spinlock will do that for you. In fact in
single processor
machines that’s the only thing that happens when you call
KeAcquireSpinLock(). In
SMP systems the spinlock does also the atomic lock (spinning/looping) that
we read about.

Sorry I was not clear.

George

At 06:43 PM 1/29/01 -0500, you wrote:

“Matteo Pelati” wrote in message news:xxxxx@ntdev…
>Some APIs like IoRequestDpc(), as the DDK says, must be specifically invoked
>at an IRQL >= DISPATCH_LEVEL. Has anyone ever tried invoking them at
>PASSIVE_LEVEL? What could be the result?
>
>The result could be VERY UGLY. Like, unpredictable system behavior.
>
>If the DDI is documented to be called at IRQL’s >= DISPATCH_LEVEL, then the
>code you are calling is relying on that level of synchronization. You can
>NOT call the function at lower IRQLs.
>
>If you’re running at a lower IRQL, and you need to call a function with a
>higher IRQL requirement, just KeRaiseIrql() to the IRQL you need, call the
>function, and then KeLowerIrql() afterwards. No need to take a spin lock.
>
>PeterGV
>OSR Open Systems Resources, Inc.
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@brd.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Yes, but as a general solution it is WRONG on MP systems, so why not do it
right? If you don’t need a lock, don’t acquire a lock. If all you are trying
to do is raise IRQL to dispatch level, why not use the direct approach and
raise irql to dispatch level by calling KeRaiseIrql as Peter suggested?

Mark Roddy
Windows 2000/NT Consultant
Hollis Technology Solutions
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of George Blat
Sent: Monday, January 29, 2001 7:17 PM
To: NT Developers Interest List
Subject: [ntdev] Re: IRQL question

Hi,

What I meant to say is that if you Acquire a spinlock you don’t need to
call KeRaiseIrql()
to DISPATCH_LEVEL because the spinlock will do that for you. In fact in
single processor
machines that’s the only thing that happens when you call
KeAcquireSpinLock(). In
SMP systems the spinlock does also the atomic lock
(spinning/looping) that
we read about.

Sorry I was not clear.

George

At 06:43 PM 1/29/01 -0500, you wrote:

>“Matteo Pelati” wrote in message news:xxxxx@ntdev…
> >Some APIs like IoRequestDpc(), as the DDK says, must be
> specifically invoked
> >at an IRQL >= DISPATCH_LEVEL. Has anyone ever tried invoking them at
> >PASSIVE_LEVEL? What could be the result?
> >
> >The result could be VERY UGLY. Like, unpredictable system behavior.
> >
> >If the DDI is documented to be called at IRQL’s >=
> DISPATCH_LEVEL, then the
> >code you are calling is relying on that level of
> synchronization. You can
> >NOT call the function at lower IRQLs.
> >
> >If you’re running at a lower IRQL, and you need to call a function with a
> >higher IRQL requirement, just KeRaiseIrql() to the IRQL you
> need, call the
> >function, and then KeLowerIrql() afterwards. No need to take a
> spin lock.
> >
> >PeterGV
> >OSR Open Systems Resources, Inc.
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: xxxxx@brd.com
> >To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@wattanuck.mv.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com