Role of MDL

When a driver requests direct I/O, what role does a MDL play while
accessing user space buffers? Why can’t I/O be performed as the case
in buffered I/O mode? (With use of pointer to buffered space directly)
–Sachin

The MDL provides a mechanism for mapping the pages. You can get a pointer
to this buffer when needed.

From your questions I would recomend you consider taking a good training
class, or at a mimimum get “Programming the Windows Driver Model Second
Edition” by Walter Oney, and taking the time to read it thoroughly.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Sachin” wrote in message news:xxxxx@ntdev…
> When a driver requests direct I/O, what role does a MDL play while
> accessing user space buffers? Why can’t I/O be performed as the case
> in buffered I/O mode? (With use of pointer to buffered space directly)
> --Sachin
>

You could use a pointer to the user address space directly. However
there are a few complications:

  1. Since NT is multithreaded, one thread in a process could be
    invalidating or changing the mappings of pages while another is calling
    your driver. If you just use the user-space address you need to protect
    every access in a try-except block (which is easy to forget, or to
    forget to test)

  2. Since drivers often run in arbitrary thread contexts, the user-space
    address wouldn’t always be valid. NT driver stacks are often very
    deeply layered and requests could get deferred by any driver in the
    stack (according to various stack-specific rules). Since the
    user-address is only valid in the context of the original process, it’s
    of little use once your driver is running in a worker thread.

  3. The user-address space is paged, so the user-address refers to page
    mappings that could be invlaidated as the pages are flushed out to disk.
    Note that these mappings can be invalidated even if the pages are
    physically locked in memory. If your driver needs to access the buffer
    at raised IRQL, it has to be able to map them to a virtual address range
    that isn’t subject to working set trimming - hence
    MmGetSystemAddressForMdl[Safe]

  4. Direct I/O is commonly used for DMA transfers. Here the pages need
    to be physically locked, but no virtual address is needed. The NTIO
    manager saves the driver writer from needing to build its own MDL for
    each request.

The MDL provides a very useful abstraction of a locked buffer which
encapsulates all of the information about which process the memory came
from, what address it’s been remapped at, and protects the driver from a
host of attacks where the client screws with its address space while
calling the driver.

-p

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Sachin
Sent: Thursday, August 19, 2004 5:32 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Role of MDL

When a driver requests direct I/O, what role does a MDL play while
accessing user space buffers? Why can’t I/O be performed as the case in
buffered I/O mode? (With use of pointer to buffered space directly)
–Sachin


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

MDL is a collection of the physical pages which underlies the app’s buffer.

The usual purpose of the MDLs are:

  • to run DMA over these pages
  • to remap the pages to the kernel space which will be accessible from any
    context, including the ISR.

In these cases, there is no additional data copy (which occurs in buffered
IO). You can either run DMA immediately over the app’s buffer, or run the
interrupt-based PIO over it.

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

----- Original Message -----
From: “Sachin”
To: “Windows System Software Devs Interest List”
Sent: Thursday, August 19, 2004 4:32 PM
Subject: [ntdev] Role of MDL

> When a driver requests direct I/O, what role does a MDL play while
> accessing user space buffers? Why can’t I/O be performed as the case
> in buffered I/O mode? (With use of pointer to buffered space directly)
> --Sachin
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com