[Openib-windows] [PATCH] HCA: Allocate MDLs for memory registrationmanually - complete message

Jan Bottorff jbottorff at xsigo.com
Fri Oct 7 12:56:39 PDT 2005


>Instead of calling IoAllocateMdl to setup the MDL for a memory region,
the >code will manually allocate a buffer large enough for the MDL and
call >MmInitializeMdl instead.
>This is needed to allow buffers that exceed the limits of IoAllocateMdl
to >be registered.  The DDK docs detail the limitations on size of
>IoAllocateMdl.

The buffer size limitation that can be described by an MDL is because
the size field in the MDL structure is only 16-bits (on 32-bit Windows).
The calculation shown in the DDK docs for IoAllocateMdl is based on this
16-bit field.

I don't see how allocating some non-paged pool and then calling
MmInitializeMdl helps, the size field in the MDL structure is still the
same size. MmInitializeMdl has exactly the same limits as IoAllocateMdl,
although the DDK docs don't mention this. 

If you look at ntddk.h, you find MmInitializeMdl is a macro and sets the
size field with

(MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) +
(sizeof(PFN_NUMBER) *
ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa),(Length))))

Which is essentially the same formula as the size limit in the DDK docs
for IoAllocateMdl:

PAGE_SIZE * (65535 - sizeof(MDL)) / sizeof(ULONG_PTR)

The result of this change is you will now be able to create invalid
MDL's, and NOT get a failure status like IoAllocateMdl would give. The
short size field will just get truncated when it overflows, and the MDL
structure will be corrupt.

- Jan




More information about the ofw mailing list