Re: MmGetSystemAddressForMdlSafe



Hi mate

What's better about MmGetPhysicalAddress + MmMapIoSpace that makes you
mention it as a solution (before then pointing out that it's not going to
help)?

The only reason why I mentioned MmGetPhysicalAddress + MmMapIoSpace is
because
the OP asked if there is any alternative to
MmGetSystemAddressForMdlSafe().Therefore, I showed him that there is
one more way to run into exactly the same problem that he had described
- as they say, there is more than one way to skin a cat

The call to MmGetSystemAddressForMdlSafe doesn't allocate memory from
non-paged pool".

Both MmGetSystemAddressForMdlSafe() and MmMapIoSpace() map pages to
non-paged memory. It is understandable that there is no need to
allocate new pages of memory once we just map the existing ones into
the kernel address space. Therefore, I should have said "maps to
non-paged area", rather than "allocates from non-paged pool" - I have
expressed myself the wrong way, I admit. Non-paged area starts at
0xEB000000 and ends at 0xFFB00000. Therefore, if the system fails to
find contigious space in this range that is sufficient for mapping MDL,
the call fails. This is what I meant to say

I would say that the problem may arise only if you map more than 4MB of
space, i.e. more than one page table can map (in such case the system
has to find adjacent free
entries in page directories)


Anton Bassov





peterwie@xxxxxxxxxxxxxxxxxxxx wrote:
What's better about MmGetPhysicalAddress + MmMapIoSpace that makes you
mention it as a solution (before then pointing out that it's not going to
help)?

The call to MmGetSystemAddressForMdlSafe doesn't allocate memory from
non-paged pool". It's failing because there isn't a contiguous range of
free kernel VA PTEs with which the pages can be mapped.

-p

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"anton bassov" <soviet_bloke@xxxxxxxxxxx> wrote in message
news:1152672496.895027.235370@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi mate

If you are not happy with MmGetSystemAddressForMdlSafe(), you can try
MmGetPhysicalAddress() - MmMapIoSpace() sequence in order to map
user-mode address to the kernel address space. Just keep in mind that
the page, corresponding to the virtual address in question, has to be
present in RAM at the time of your call to MmGetPhysicalAddress().


However, this hardly solves your problem, because both MmMapIoSpace()
and MmGetSystemAddressForMdlSafe() allocate memory from non-paged pool.
Therefore, if your buffer is large, these calls may fail (in fact, I
believe your call to MmGetSystemAddressForMdlSafe() fails just because
there is not enough non-paged memory to map your buffer) .


Actually, as long as you access memory in the context of the process
where user-mode address resides and your code runs at
IRQL<DISPATCH_LEVEL, you can access it directly from the kernel mode
(this is how METHOD_NEITHER works). Are you 100% sure you need to map
memory to the kernel address space, in the first place????? If you
don't mind, could you please tell us a little bit more about your
driver and your objectives, so that we can try to find an optimal
solution to your problem



Anton Bassov




Michael wrote:
Hi

We are using MmGetSystemAddressForMdlSafe function to convert address
from user space to kernel space, we call it with priority parameter set
to High.

When we call this function is sometimes fails and returns NULL.

What can be the reason for this function to fail?

Do i need to lock and MDL before calling this function?

Do i need to unlock the MDL after calling this function?

Is there any other way to convert user mode address to kernel mode
address?

Thanks,
Michael


.



Relevant Pages

  • Re: p_vmspace in syscall
    ... In general, I prefer mapping user pages into kernel instead of kernel pages into user space, as it reduces the chances of leakage of kernel data to user space, and there are some useful primitives for making this easier. ... map the buffer to user process ... The pages allocated by mallocbelong to the kernel memory allocator, and are generally managed by the slab allocator. ...
    (freebsd-hackers)
  • Re: Allocating kernel memory
    ... high memory should even work for low memory, ... > Havinf worked on a variety of OS's at kernel level with a theoretical ... The kernel did map all physical memory back in the ... Oh but wait, paging is there to ...
    (comp.os.linux.development.system)
  • Re: [crash] Re: Latest brk patchset
    ... leaves the space under the kernel avaliable for allocating pagetable ... make sure we map enough to fit linear map pagetables ... that mm/init.c can allocate space from the e820 allocator ... for the linear map of low memory. ...
    (Linux-Kernel)
  • Re: Crash while mapping memory in pagetable_init() (Was: Re: .config)
    ... head.S maps the kernel size plus INIT_MAP_BEYOND_END, which is currently set to 128K. ... all memory into the kernel address space. ... It tries to map kernelsize+initial_pagetables+128k ... The initrd is supposed to be loaded as far away from the kernel as possible. ...
    (Linux-Kernel)
  • Re: MmGetSystemAddressForMdlSafe
    ... What's better about MmGetPhysicalAddress + MmMapIoSpace that makes you mention it as a solution? ... The call to MmGetSystemAddressForMdlSafe doesn't allocate memory from non-paged pool". ... It's failing because there isn't a contiguous range of free kernel VA PTEs with which the pages can be mapped. ...
    (microsoft.public.win32.programmer.kernel)

Quantcast