MmUnmapIoSpace

Hi there,

A quick question. In a function, I call MmMapIoSpace to get a virtual
address but didn’t call MmUnmapIoSpace when function is out. And this
function is call many times. What does this impact to my system?

Thanks
Wayne

You leak virtual address space, it will eventually be exhausted and cause a whole bunch of alloc failures throughout the system. Fix it, end of story. No debate.

d

Thanks Doron.

Actually I meet a 0x7F (0x8…) BSOD when migrating a Windows 7 with my
Windows PV drivers under Oracle VM after 600 times. Xen hypervisor will
share some memory to Windows guest VM to transfer some date between
them. PV driver will call MmMapIoSpace to get virtual address of that
memory and store data in it then use a hyper call to notify the
hypervisor. When I debug this issue, I found that my code didn’t call
MmUnmapIoSpace when system is suspended but call MmMapIoSpace again when
system is resumed. Then the notify hyper call cause system BSOD at some
place (not the first one) when system is resuming from suspend. I doube
it’s the route problem, will do more test to confirm it.

BTW, I attach verifier to all driver in system, didn’t get any
assertion. MmMapIoSpace always return success even system will BSOD in
the next several functions.

Thanks
Wayne

think about it. what would DV catch you doing? you are not doing anything wrong but leak VA. since DV has no idea when you should release VA, it cannot tell you that you made a mistake.

d

xxxxx@Microsoft.com wrote:

You leak virtual address space, it will eventually be exhausted and cause a whole bunch of alloc failures throughout the system. Fix it, end of story. No debate.

Is that mean if I call MmMapIoSpace twice for the same physical memory,
they will return different virtual address to me. That’s why it will
leak virtual address space, right?

Wayne

You are using precious non paged pool … If you dont free it,
ultimately your system will crash as ultimately kernel will be left
with no no-paged pool memory for its purpose.

On 4/13/10, wayne gong wrote:
> Hi there,
>
> A quick question. In a function, I call MmMapIoSpace to get a virtual
> address but didn’t call MmUnmapIoSpace when function is out. And this
> function is call many times. What does this impact to my system?
>
> Thanks
> Wayne
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Thanks
Anshul Makkar
justkernel.com
xxxxx@justkernel.com

> A quick question. In a function, I call MmMapIoSpace to get a virtual

address but didn’t call MmUnmapIoSpace when function is out. And this
function is call many times. What does this impact to my system?

Leak of System PTEs, can be noticed in Perfmon I think.

When the leak will be major, the next MmMapIoSpace calls will fail, so are MmGetSystemAddressForMdlSafe, and this will ruin the OS.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> Is that mean if I call MmMapIoSpace twice for the same physical memory,

they will return different virtual address to me. That’s why it will
leak virtual address space, right?

No.

In Windows, there are “system PTEs”, each describes a page of kernel-mode addresses.

MmMapIoSpace is:

a) allocate the range of system PTEs (can fail)
b) set them to describe these physical addresses (cannot fail)

MmUnmapIoSpace is:

a) flush these PTEs from the TLB
b) free the system PTEs.

I think in XP+ there are public APIs which are the separate steps of MmMapIoSpace, google for “reserved mapping”.

Also, MmMapLockedPages(KernelMode) aka MmGetSystemAddressForMdlSafe uses the same system PTEs.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> BTW, I attach verifier to all driver in system

IIRC Verifier can catch the leaks only on driver binary unload, and I’m not sure it can catch system PTE leak.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com