Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW validation on a new HW graphics device. While I’m not focused on created production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated graphics memory, rather the device addresses the same system RAM as the CPU. The device has a 4Gb address range with a PT/PD based MMU so the device is not dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to be addressed by it. More specifically, I need to be able to allocate nonpaged, uncached memory in kernelmode which can then be arbitrarily mapped to N usermode process address spaces. I know the nonpagedpool is a scarce resource in XP-32bit and would ideally prefer to allocate from the pagedpool, probe/locking the pages first. Unfortunately, I haven’t had any success changing the cachetype to uncached (MmMapLockedPagesSpecifyCache) so opted to explicitly allocate noncached, nonpaged memory via the DDI, MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE, IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU PTEs and the device’s driver may access the memory via the uncached CPU virtual addresss.

Subsequently, one or more usermode client processes will request a mapping to the original kernel MDL allocation. I’ve assumed I need to create a new MDL for each process mapping of the original kernel MDL. Here’s the sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE, IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was from the nonpagedpool. From what I’ve read I think I need the call to MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need to call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:

  1. is it possible to achieve what I’ve described in XP using MDLs to create 1 Kernel mapping and N concurrent usermode MDL mappings of the same underlying physical memory (where the memory is allocated from the paged or nonpagepools)?
  2. If the answer to 1) is yes, is the code I’ve provided look OK and, if not, could anyone provide guidance towards a sensible solution?

regards
Dave

Since you don’t seem to care if the pages are physically contiguous (since you’re not using one of the Contiguous memory apis) you could also consider using MmAllocatePagesForMdl() to reserve a set of pages and then map it where you need it by calling MmMapLockedPagesSpecifyCache(…)

-p

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 1:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW validation on a new HW graphics device. While I’m not focused on created production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated graphics memory, rather the device addresses the same system RAM as the CPU. The device has a 4Gb address range with a PT/PD based MMU so the device is not dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to be addressed by it. More specifically, I need to be able to allocate nonpaged, uncached memory in kernelmode which can then be arbitrarily mapped to N usermode process address spaces. I know the nonpagedpool is a scarce resource in XP-32bit and would ideally prefer to allocate from the pagedpool, probe/locking the pages first. Unfortunately, I haven’t had any success changing the cachetype to uncached (MmMapLockedPagesSpecifyCache) so opted to explicitly allocate noncached, nonpaged memory via the DDI, MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE, IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU PTEs and the device’s driver may access the memory via the uncached CPU virtual addresss.

Subsequently, one or more usermode client processes will request a mapping to the original kernel MDL allocation. I’ve assumed I need to create a new MDL for each process mapping of the original kernel MDL. Here’s the sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE, IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL, UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was from the nonpagedpool. From what I’ve read I think I need the call to MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need to call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:

  1. is it possible to achieve what I’ve described in XP using MDLs to create 1 Kernel mapping and N concurrent usermode MDL mappings of the same underlying physical memory (where the memory is allocated from the paged or nonpagepools)?
  2. If the answer to 1) is yes, is the code I’ve provided look OK and, if not, could anyone provide guidance towards a sensible solution?

regards
Dave


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

Hi Peter

How would the OP choose the LowAddress, HighAddress parameters for
MmAllocatePagesForMdl()? The OP has no a priori address range to choose.and
MmGetPhysicalMemoryRanges is in the “reserved for system use” group.

Thanks
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Since you don’t seem to care if the pages are physically contiguous (since
you’re not using one of the Contiguous memory apis) you could also consider
using MmAllocatePagesForMdl() to reserve a set of pages and then map it
where you need it by calling MmMapLockedPagesSpecifyCache(…)

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 1:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW
validation on a new HW graphics device. While I’m not focused on created
production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated graphics
memory, rather the device addresses the same system RAM as the CPU. The
device has a 4Gb address range with a PT/PD based MMU so the device is not
dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to be
addressed by it. More specifically, I need to be able to allocate nonpaged,
uncached memory in kernelmode which can then be arbitrarily mapped to N
usermode process address spaces. I know the nonpagedpool is a scarce
resource in XP-32bit and would ideally prefer to allocate from the
pagedpool, probe/locking the pages first. Unfortunately, I haven’t had any
success changing the cachetype to uncached (MmMapLockedPagesSpecifyCache) so
opted to explicitly allocate noncached, nonpaged memory via the DDI,
MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE,
IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU PTEs
and the device’s driver may access the memory via the uncached CPU virtual
addresss.

Subsequently, one or more usermode client processes will request a mapping
to the original kernel MDL allocation. I’ve assumed I need to create a new
MDL for each process mapping of the original kernel MDL. Here’s the
sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE,
IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL,
UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was from
the nonpagedpool. From what I’ve read I think I need the call to
MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need to
call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:
1) is it possible to achieve what I’ve described in XP using MDLs to create
1 Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged or
nonpagepools)?
2) If the answer to 1) is yes, is the code I’ve provided look OK and, if
not, could anyone provide guidance towards a sensible solution?

regards
Dave


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

Presumably his device has access to all 64-bit worth of memory, or his
original plan of using non-paged pool for this wouldn’t work either. So
0 -> 0xffffffffffffffff should work.

He could be prudent and use 0x0 -> 0xffffffff. That still won’t cover
weird NUMA configurations, but it seems like an acceptable choice for
the purposes he described which involve testing a graphics device -
constrained environment always allows more flexibility with the “rules”.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Wednesday, February 28, 2007 1:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Complex MDL use case

Hi Peter

How would the OP choose the LowAddress, HighAddress parameters for
MmAllocatePagesForMdl()? The OP has no a priori address range to
choose.and
MmGetPhysicalMemoryRanges is in the “reserved for system use” group.

Thanks
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Since you don’t seem to care if the pages are physically contiguous
(since
you’re not using one of the Contiguous memory apis) you could also
consider
using MmAllocatePagesForMdl() to reserve a set of pages and then map it
where you need it by calling MmMapLockedPagesSpecifyCache(…)

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 1:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW
validation on a new HW graphics device. While I’m not focused on
created
production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated
graphics
memory, rather the device addresses the same system RAM as the CPU. The

device has a 4Gb address range with a PT/PD based MMU so the device is
not
dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to
be
addressed by it. More specifically, I need to be able to allocate
nonpaged,
uncached memory in kernelmode which can then be arbitrarily mapped to N
usermode process address spaces. I know the nonpagedpool is a scarce
resource in XP-32bit and would ideally prefer to allocate from the
pagedpool, probe/locking the pages first. Unfortunately, I haven’t had
any
success changing the cachetype to uncached
(MmMapLockedPagesSpecifyCache) so
opted to explicitly allocate noncached, nonpaged memory via the DDI,
MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE,

IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU
PTEs
and the device’s driver may access the memory via the uncached CPU
virtual
addresss.

Subsequently, one or more usermode client processes will request a
mapping
to the original kernel MDL allocation. I’ve assumed I need to create a
new
MDL for each process mapping of the original kernel MDL. Here’s the
sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE,
IMG_FALSE,
IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL,

UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was
from
the nonpagedpool. From what I’ve read I think I need the call to
MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need
to
call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:
1) is it possible to achieve what I’ve described in XP using MDLs to
create
1 Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged
or
nonpagepools)?
2) If the answer to 1) is yes, is the code I’ve provided look OK and, if

not, could anyone provide guidance towards a sensible solution?

regards
Dave


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


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

The device only has 32bit physical address range. To be clear, this is a ‘development’ (hw validation only) driver and the device will only address system memory. Assuming I’m never interested in testing the device in a system with more than 4Gb of physical RAM then am I right in thinking 64bit is a non-issue given the device is UMA and RAM starts at 0?

thanks
Dave

Slightly less than 4GB (since often some of that lower memory range is stolen for PCI address) but for the purposes of validation this is an okay assumption.

But you can also limit yourself to the lower 4GB of the physical address space with the bounds parameters you pass to MmAllocatePagesForMdl

-p
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 2:29 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Complex MDL use case

The device only has 32bit physical address range. To be clear, this is a ‘development’ (hw validation only) driver and the device will only address system memory. Assuming I’m never interested in testing the device in a system with more than 4Gb of physical RAM then am I right in thinking 64bit is a non-issue given the device is UMA and RAM starts at 0?

thanks
Dave


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

Hi Peter

My bad; I had missed the point about this being for internal test purposes.
I wonder what advice you’d have given if this was for production purposes?

Cheers
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Presumably his device has access to all 64-bit worth of memory, or his
original plan of using non-paged pool for this wouldn’t work either. So
0 -> 0xffffffffffffffff should work.

He could be prudent and use 0x0 -> 0xffffffff. That still won’t cover
weird NUMA configurations, but it seems like an acceptable choice for
the purposes he described which involve testing a graphics device -
constrained environment always allows more flexibility with the “rules”.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Wednesday, February 28, 2007 1:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Complex MDL use case

Hi Peter

How would the OP choose the LowAddress, HighAddress parameters for
MmAllocatePagesForMdl()? The OP has no a priori address range to
choose.and
MmGetPhysicalMemoryRanges is in the “reserved for system use” group.

Thanks
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Since you don’t seem to care if the pages are physically contiguous
(since
you’re not using one of the Contiguous memory apis) you could also
consider
using MmAllocatePagesForMdl() to reserve a set of pages and then map it
where you need it by calling MmMapLockedPagesSpecifyCache(…)

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 1:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW
validation on a new HW graphics device. While I’m not focused on
created
production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated
graphics
memory, rather the device addresses the same system RAM as the CPU. The

device has a 4Gb address range with a PT/PD based MMU so the device is
not
dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to
be
addressed by it. More specifically, I need to be able to allocate
nonpaged,
uncached memory in kernelmode which can then be arbitrarily mapped to N
usermode process address spaces. I know the nonpagedpool is a scarce
resource in XP-32bit and would ideally prefer to allocate from the
pagedpool, probe/locking the pages first. Unfortunately, I haven’t had
any
success changing the cachetype to uncached
(MmMapLockedPagesSpecifyCache) so
opted to explicitly allocate noncached, nonpaged memory via the DDI,
MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE,

IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU
PTEs
and the device’s driver may access the memory via the uncached CPU
virtual
addresss.

Subsequently, one or more usermode client processes will request a
mapping
to the original kernel MDL allocation. I’ve assumed I need to create a
new
MDL for each process mapping of the original kernel MDL. Here’s the
sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE,
IMG_FALSE,
IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL,

UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was
from
the nonpagedpool. From what I’ve read I think I need the call to
MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need
to
call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:
1) is it possible to achieve what I’ve described in XP using MDLs to
create
1 Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged
or
nonpagepools)?
2) If the answer to 1) is yes, is the code I’ve provided look OK and, if

not, could anyone provide guidance towards a sensible solution?

regards
Dave


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


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

Common Buffer :slight_smile:

There’s no great solution there. You can always try the loop of
AllocatePagesForMdl, GetScatterGatherList, BuildMdlForScatterGatherList,
MmMapLockedPagesSpecifyCache but I don’t know what caching attributes
the HAL applies to bounce buffers and your buffer size would be limited
by the number of map registers you could allocate.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Thursday, March 01, 2007 1:29 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Complex MDL use case

Hi Peter

My bad; I had missed the point about this being for internal test
purposes.
I wonder what advice you’d have given if this was for production
purposes?

Cheers
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Presumably his device has access to all 64-bit worth of memory, or his
original plan of using non-paged pool for this wouldn’t work either. So
0 -> 0xffffffffffffffff should work.

He could be prudent and use 0x0 -> 0xffffffff. That still won’t cover
weird NUMA configurations, but it seems like an acceptable choice for
the purposes he described which involve testing a graphics device -
constrained environment always allows more flexibility with the “rules”.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Wednesday, February 28, 2007 1:40 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Complex MDL use case

Hi Peter

How would the OP choose the LowAddress, HighAddress parameters for
MmAllocatePagesForMdl()? The OP has no a priori address range to
choose.and
MmGetPhysicalMemoryRanges is in the “reserved for system use” group.

Thanks
Lyndon

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Since you don’t seem to care if the pages are physically contiguous
(since
you’re not using one of the Contiguous memory apis) you could also
consider
using MmAllocatePagesForMdl() to reserve a set of pages and then map it
where you need it by calling MmMapLockedPagesSpecifyCache(…)

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Wednesday, February 28, 2007 1:12 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Complex MDL use case

I’m working on an XP ‘development’ driver as a means of performing HW
validation on a new HW graphics device. While I’m not focused on
created
production quality drivers, I do care that I’m not ‘hacking’ a solution.

The graphics device is part of a UMA style SOC and has no dedicated
graphics
memory, rather the device addresses the same system RAM as the CPU. The

device has a 4Gb address range with a PT/PD based MMU so the device is
not
dependent on physically contiguous memory.

There is a kernel driver to manage the device as well as the memory to
be
addressed by it. More specifically, I need to be able to allocate
nonpaged,
uncached memory in kernelmode which can then be arbitrarily mapped to N
usermode process address spaces. I know the nonpagedpool is a scarce
resource in XP-32bit and would ideally prefer to allocate from the
pagedpool, probe/locking the pages first. Unfortunately, I haven’t had
any
success changing the cachetype to uncached
(MmMapLockedPagesSpecifyCache) so
opted to explicitly allocate noncached, nonpaged memory via the DDI,
MmAllocateNonCachedMemory. Here’s the sequence:

pvLinAddrKM = MmAllocateNonCachedMemory(uiSize)
psKernelMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE, IMG_FALSE,

IMG_NULL)
MmBuildMdlForNonPagedPool(psKernelMDL)

The physical pages backing the MDL are programmed into the device’s MMU
PTEs
and the device’s driver may access the memory via the uncached CPU
virtual
addresss.

Subsequently, one or more usermode client processes will request a
mapping
to the original kernel MDL allocation. I’ve assumed I need to create a
new
MDL for each process mapping of the original kernel MDL. Here’s the
sequence:

psProcessMDL = IoAllocateMdl(pvLinAddrKM, ui32Size, IMG_FALSE,
IMG_FALSE,
IMG_NULL)
MmBuildMdlForNonPagedPool(psProcessMDL)
__try
{
pvLinAddrUM = MmMapLockedPagesSpecifyCache(psMapping->psMDL,

UserMode, MmNonCached, NULL, FALSE, NormalPagePriority)
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
goto cleanup_mdl;
}

I’m pretty sure I don’t need to probe/lock pages as the allocation was
from
the nonpagedpool. From what I’ve read I think I need the call to
MmBuildMdlForNonPagedPool as it’s a new MDL for each process and I need
to
call MmMapLockedPagesSpecifyCache() to ensure the mapping is uncached.

I have two questions:
1) is it possible to achieve what I’ve described in XP using MDLs to
create
1 Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged
or
nonpagepools)?
2) If the answer to 1) is yes, is the code I’ve provided look OK and, if

not, could anyone provide guidance towards a sensible solution?

regards
Dave


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


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


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

> 1) is it possible to achieve what I’ve described in XP using MDLs to create 1

Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged or
nonpagepools)?

Possible, but the cache type of all mappings must be the same.


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

> 1) is it possible to achieve what I’ve described in XP using MDLs to create 1

Kernel mapping and N concurrent usermode MDL mappings of the same
underlying physical memory (where the memory is allocated from the paged or
nonpagepools)?
>Possible, but the cache type of all mappings must be the same
Allocations/mappings of this type would be consistently uncached. Alternatively, if the device supported Host CPU Cache snooping then they could be made cached. In either case, the cache type would be the same for all mappings to the same physical memory.

thanks for your input.
Dave