locking and FltXXX API

Hi all,

I’m studying and learning minifilter recently. I learn there are several locking mechanisms disable normal APC delivery, such as FltAcquirePushLockExclusive etc. And there are so many FltXXX APIs only can be called at PASSIVE_LEVEL, such as FltReadFile. Is it okay to call FltAcquirePushLockExclusive and then call FltReadFile inside the locking scope for example?

Thanks,
Ziv

  1. I would ignore all the funky locking primitives and use ERESOURCES,
    KSPINLOCKS if you have to. There is significant more support for debugging
    ERESOURCES than any other locking primitive and the nanoseconds you save are
    unlikely to ever turn up in the cost of the IO you are probably about to
    issue, making it difficult to justify the extra cost of debugging with no
    support.

  2. In general you should *never* call into a layer below you with any lock
    held. At its simplest, this is because you can never tell whether something
    you do will cause you to be called somewhere else and you can cause a
    deadlock before you even think about it.

  3. There will be many cases when you think you need a lock, but often you
    don’t - it will require some careful thought and attention to detail (lock
    free operation can be challenging).

  4. Notwithstanding (3) you may need a lock. Apply (2 & 3) again.

  5. As a final answer to your query is a firm “it depends”. In general, the
    mechanics allow most of the FltXXX functions to be called mechanically with
    a resource held (which means with APCs blocked), but don’t forget those
    deadlocks. I cannot think of any FltXXX functions you can call with a
    spinlock held (there probably is one…)

Rod

Calling any long and complex operation under a lock is extremely bad idea anyway, regardless or IRQL requirements.

–
Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntfsd…
> Hi all,
>
> I’m studying and learning minifilter recently. I learn there are several locking mechanisms disable normal APC delivery, such as FltAcquirePushLockExclusive etc. And there are so many FltXXX APIs only can be called at PASSIVE_LEVEL, such as FltReadFile. Is it okay to call FltAcquirePushLockExclusive and then call FltReadFile inside the locking scope for example?
>
> Thanks,
> Ziv
>

Thanks for all of your advices. It’s really a challenge to make my implementation lock free because I have to sync up with remote scanning server’s commands, sync up with shared memory access with remote scanning server and even more, deal with unintentional service broken up. @@a

I’ll take your advices into consideration and think how to improve/redesign the current implementation.

Thanks,
Ziv