Retrieving a list of physical pages describing a user-mode buffer

Hi,

This is the scenario:

A user-mode application sends down the virtual address of its buffer to my driver, and i need to extract the corresponding physical addresses and send down this list to another custom driver. Basically, something like calling GetScatterGatherList(), but i’m not doing DMA so i can’t call that. I’m building an MDL and probing and locking the memory, but there doesn’t seem any way in which i can read that list that the MDL built, so i need to recreate that. Something like calling MmGetPhysicalAddress() repeatedly, where pUserBufferAddress will be the next virtual address after adding the byteOffset… This doesn’t seem clean to me, but i haven’t found an alternate way yet. How do i do this?

Thanks,
Aruna

The physical pages follow the MDL. Look at the MDL description in wdm.h

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, October 10, 2011 2:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Retrieving a list of physical pages describing a user-mode
buffer

Hi,

This is the scenario:

A user-mode application sends down the virtual address of its buffer to my
driver, and i need to extract the corresponding physical addresses and send
down this list to another custom driver. Basically, something like calling
GetScatterGatherList(), but i’m not doing DMA so i can’t call that. I’m
building an MDL and probing and locking the memory, but there doesn’t seem
any way in which i can read that list that the MDL built, so i need to
recreate that. Something like calling MmGetPhysicalAddress() repeatedly,
where pUserBufferAddress will be the next virtual address after adding the
byteOffset… This doesn’t seem clean to me, but i haven’t found an
alternate way yet. How do i do this?

Thanks,
Aruna


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

What are you going to do with the physical pages once you get them? As
I sure will be pointed out you can get the pages from the MDL though
this is not documented, but the bigger question is why do you think you
need these. Under any circumstance why are you passing the physical
pages to the lower driver (I assume you have control over both) rather
than the MDL? At least if you do this all in one driver, there is only
one place to cleanup when someone decides it was a bad idea.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@gmail.com” wrote in message
news:xxxxx@ntdev:

> Hi,
>
> This is the scenario:
>
> A user-mode application sends down the virtual address of its buffer to my driver, and i need to extract the corresponding physical addresses and send down this list to another custom driver. Basically, something like calling GetScatterGatherList(), but i’m not doing DMA so i can’t call that. I’m building an MDL and probing and locking the memory, but there doesn’t seem any way in which i can read that list that the MDL built, so i need to recreate that. Something like calling MmGetPhysicalAddress() repeatedly, where pUserBufferAddress will be the next virtual address after adding the byteOffset… This doesn’t seem clean to me, but i haven’t found an alternate way yet. How do i do this?
>
> Thanks,
> Aruna

Right, but how i access that? Is there an Mm* API that i can call, to retrieve all PHYSICAL_ADDRESSes in the MDL array? From what i’ve read so far, the MDL structure is supposed to be fully opaque and so i don’t want to access any of the fields directly.

What are you doing with the physical addresses if you aren’t doing DMA?

-p

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, October 10, 2011 11:54 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Retrieving a list of physical pages describing a user-mode buffer

Hi,

This is the scenario:

A user-mode application sends down the virtual address of its buffer to my driver, and i need to extract the corresponding physical addresses and send down this list to another custom driver. Basically, something like calling GetScatterGatherList(), but i’m not doing DMA so i can’t call that. I’m building an MDL and probing and locking the memory, but there doesn’t seem any way in which i can read that list that the MDL built, so i need to recreate that. Something like calling MmGetPhysicalAddress() repeatedly, where pUserBufferAddress will be the next virtual address after adding the byteOffset… This doesn’t seem clean to me, but i haven’t found an alternate way yet. How do i do this?

Thanks,
Aruna


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

I’m afraid i really cannot talk about the bigger use case of why i need this. :frowning:

How can i access the physical pages list that follows an MDL?

If you need processor accessible physical addresses, you can lock the pages down and then use MmGetPhysicalAddress on the original buffer to get the physical address.

If you need to have addresses accessible by a device through DMA lower in your stack then you need to go through the DMA abstraction. On X86 you can just call HalGetDmaAdapter() or IoGetDmaAdapter() on a root enumerated device. On AMD64 you’d need to have a device your driver is loading on.

-p

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, October 10, 2011 1:21 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Retrieving a list of physical pages describing a user-mode buffer

I’m afraid i really cannot talk about the bigger use case of why i need this. :frowning:

How can i access the physical pages list that follows an MDL?


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

Just use GetScatterGatherList. Why do you think you can’t use it?

From wdm.h:

Pages = (PPFN_NUMBER) (Mdl+1);

Not being able to talk about what you are really trying to accomplish makes
it hard for you to get help from this list.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, October 10, 2011 4:21 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Retrieving a list of physical pages describing a
user-mode buffer

I’m afraid i really cannot talk about the bigger use case of why i need
this. :frowning:

How can i access the physical pages list that follows an MDL?


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

See also MmGetMdlPfnArray

xxxxx@gmail.com wrote:

I’m afraid i really cannot talk about the bigger use case of why i need this. :frowning:

You may be thinking that we are just being nosy. That is certainly not
the case. Perhaps the most common question scenario we see here is a
developer who has a problem to solve, who does just a little bit of
digging and comes up with what he thinks will be a magical solution. He
then asks here how he can go about implementing his magical solution,
instead of asking us about the broader problem. Often, the magical
solution is a semi-documented hack that is entirely the wrong approach
to the actual problem. The more we know about what you’re doing, the
better our advice will be.

There are very few legitimate uses for physical addresses, other than
DMA. Your question sets off alarm bells in our head, warning that you
may not understand what you are asking for.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

I’ve never looked inside a MDL, but my impression was the PFNs were not
physical addresses, but something which mapped to a physical address based
on an undocumented and possibly platform-specific algorithm, which is why
there is a documented interface for obtaining physical addresses from a
MDL. Am I wrong in this understanding? (I have this vague memory from an
evening WinHEC session many years ago).
joe

What are you going to do with the physical pages once you get them? As
I sure will be pointed out you can get the pages from the MDL though
this is not documented, but the bigger question is why do you think you
need these. Under any circumstance why are you passing the physical
pages to the lower driver (I assume you have control over both) rather
than the MDL? At least if you do this all in one driver, there is only
one place to cleanup when someone decides it was a bad idea.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@gmail.com” wrote in message
> news:xxxxx@ntdev:
>
>> Hi,
>>
>> This is the scenario:
>>
>> A user-mode application sends down the virtual address of its buffer to
>> my driver, and i need to extract the corresponding physical addresses
>> and send down this list to another custom driver. Basically, something
>> like calling GetScatterGatherList(), but i’m not doing DMA so i can’t
>> call that. I’m building an MDL and probing and locking the memory, but
>> there doesn’t seem any way in which i can read that list that the MDL
>> built, so i need to recreate that. Something like calling
>> MmGetPhysicalAddress() repeatedly, where pUserBufferAddress will be the
>> next virtual address after adding the byteOffset… This doesn’t seem
>> clean to me, but i haven’t found an alternate way yet. How do i do this?
>>
>> Thanks,
>> Aruna
>
>
> —
> 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
>

Please use MmGetMdlPfnArray as opposed to directly accessing the page frame numbers from
(PPFN_NUMBER) (Mdl+1)…

Peter
OSR