How can I map physical memory into a contiguous chunk of a virtual memory that is larger than 4GB?

MDL can describe no more than 4GB - PAGE_SIZE of physical memory. But I can chain them together to hypothetically define any size of DDR.

I know that MmMapLockedPagesSpecifyCache can map MDL into a virtual address space of a process. (In my case it's just the system/kernel. I need it for a test.)

But when I give it a chain of MDLs, it seems like MmMapLockedPagesSpecifyCache takes only the first MDL in the chain and ignores the rest.

So my question, how can I map a chunk of physical memory larger than 4GB into a contiguous virtual space?

PS. I'm testing this on an ARM64 device that has way more memory than 4GB and MSFT can do it themselves via ExAllocatePool2.

PS2. I know that the 4th parameter for MmMapLockedPagesSpecifyCache can specify "requested" virtual address, that I can adjust to point at the tail end of my previous call to that function for a previous MDL in the chain, but there's no gurarantee that MmMapLockedPagesSpecifyCache will honor that request.

1 Like

I believe you can allocate a large chunk of address space with MmAllocateMappingAddress and then map pages into it with MmMapLockedPagesWithReservedMapping. You can map pages multiple times if needed to cover whatever size of address space you need, MmMapLockedPagesWithReservedMapping takes a starting address. You might also try MmMapIoSpaceEx with PAGE_NOCACHE not set, if your pages are physically contiguous.

Thanks @Jan_Bottorff and sorry for my delayed response.

Sure, I can use MmAllocateMappingAddress to reserve a virtual address range of required (large) size, and then also use a series of calls to MmAllocatePagesForMdlEx to allocate the matching number of physical pages.

But the issue is how to link them into a contiguous virtual address buffer? I tried using MmMapLockedPagesWithReservedMapping or MmMapLockedPagesSpecifyCache but they only work on the first MDL, and that is limited to 4GB - PAGE_SIZE.

I also tried linking several MDLs together but that has no effect on those functions.