Why do you need to map any kernel pages into user space? This is
generally a design error that arises because someone wants to make Windows
work like some embedded RTOS once seen by the questioner.
Here’s a very simple rule: if your design requires mapping kernel pages
into user space, reconsider the design.
Do NOT be driven from the bottom up. This way lies frustration,
heartbreak, and disaster. Instead, pay more attention to how you can map
user pages into the kernel. You will find yourself with a much easier
problem.
And before you run away, saying, “I could do that, but it would require an
inefficient copy operation”, please pay attention to the fact that we are
no longer running on PDP-11s or 8088s. We are running with gigahertz
clocks on machines with pipelining of both instructions and data, an
asynchronous opportunistic execution engine, and multilevel caches.
Unless you have actual performance numbers on the cost of a copy, you have
no rationale for declaring it “inefficient”.
When you ask questions like this, you must not omit critical data that
makes a sensible answer possible. How many bytes do you need to copy?
How many times per second do you need to do this? A “gut feeling” about
performance is not data. Measured performance data is data. Quantities
are crucial. You asked an undefined question involving a problematic
solution that has several catastrophic failure modes if not done
PERFECTLY. As an engineer, you need to assess the Return On Investment of
a fragile, complex, and quite possibly unsupportable solution that may
take weeks or months to get “right enough” to ship (at which point,
unfortunately, you begin to discover the not-inconsiderable gulf between
“right enough” and “actually right”, which tends to annoy your customers),
or a simple, straightforward, supported, and robust interface that
violates your “gut feeling” about performance in the absence of any
supporting data.
It may be that for the number of terabytes per second you have to transfer
that copying IS too slow. But all we see here is a request to explain te
best way to pluck feathers so you can glue them to your pig, without
explaining the nature of the bird, the size of the pig, or why you think a
flying pig actually solves your problem.
There is no clean way of doing this. If you look at the routine
MmAllocatePagesForMdlEx for example, it shows you the necessary steps to
build up an MDL with a range of PFNs.
I would not recommend this approach for any release code.
Pete
On 8/8/2013 7:33 PM, Suman Saraf wrote:
> Hello All,
>
> I have a slightly strange requirement. I am in a hypervisor environment
> where I receive a bunch of contiguous guest PFN’s. These translate to
> arbitrary PFN’s on the host (Windows 7). I need a way to map these
> arbitrary PFN’s into user space of a process in the context of a
> DeviceIoControl.
>
> So far, I have been unable to find a documented way to construct a Mdl
> by specifying arbitrary PFN’s. If it was possible, I would have been
> able to map it via MmMapLockedPagesSpecifyCache.
>
> Just now, I am mapping each of these PFN’s one by one using
> MmMapIoSpace, constructing an Mdl for that page and then mapping it into
> user space by reserving some prior user space range and unmapping it
> page by page. This approach is just for testing purposes, but it has
> some serious problems.
>
> Is there a way to do it cleanly i.e. is there a simple way to construct
> an Mdl by specifying a bunch of PFN’s (which are not contiguous?). Are
> there any examples of people doing something like this by hand?
>
> Thanks
> screwgauge
>
> — NTFSD is sponsored by OSR OSR is hiring!! Info at
> http://www.osr.com/careers For our schedule of debugging and file system
> 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
–
Kernel Drivers
Windows File System and Device Driver Consulting
www.KernelDrivers.com
866.263.9295
NTFSD is sponsored by OSR
OSR is hiring!! Info at http://www.osr.com/careers
For our schedule of debugging and file system 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