find physical address allignment

Hi all,

I want to know that physical address that is allocated for my buffer is quadword alligned or not?

To do so i am mapping my virtual address (returned by exallocatepool function) to physical address by MmGetPhysicalAddress() and then mod this physical address with sizeof(u64)[paddress%sizeof(u64) == 0] to find whether this physical address is quadword alligned.

It’s quite tadious so is there any other way by which i can achieve my objective?

Thanks in anticipation!

Why are you mapping it, the alignment of the virtual address is the same as
the physical address? More importantly AFAIK ExAllocatePool will allocate
with at least a quadword alignment for items of this size.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntdev…
> Hi all,
>
> I want to know that physical address that is allocated for my buffer is
> quadword alligned or not?
>
> To do so i am mapping my virtual address (returned by exallocatepool
> function) to physical address by MmGetPhysicalAddress() and then mod this
> physical address with sizeof(u64)[paddress%sizeof(u64) == 0] to find
> whether this physical address is quadword alligned.
>
> It’s quite tadious so is there any other way by which i can achieve my
> objective?
>
> Thanks in anticipation!
>

Thanks don.
Mine is 64 bit architecture.
Do you mean to say virtual address for buffer of size greater than quadword are always alligned on quadword boundry?

What about buffers less than quadword, are they alligned on quadword boundry? if yes, then can i assume that this virtual address will always quadword alligned? if no then do i need to check explicitly for allignment?

Reason i am mapping virtual address to physical address is that i have to give this physical address to interface which will read from device. This interface takes physical address as parameter so device can do I/O directly.

Hopefully someone can confirm this, but AFAIK you will get your quadword
alignment automatically. On the mapping then that is not part of the
alignment question.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

wrote in message news:xxxxx@ntdev…
> Thanks don.
> Mine is 64 bit architecture.
> Do you mean to say virtual address for buffer of size greater than
> quadword are always alligned on quadword boundry?
>
> What about buffers less than quadword, are they alligned on quadword
> boundry? if yes, then can i assume that this virtual address will always
> quadword alligned? if no then do i need to check explicitly for
> allignment?
>
> Reason i am mapping virtual address to physical address is that i have to
> give this physical address to interface which will read from device. This
> interface takes physical address as parameter so device can do I/O
> directly.
>
>

This is just in the docs, “Memory allocations of less than PAGE_SIZE are not
necessarily page-aligned but are aligned on an 8-byte boundary.”

/Daniel

“Don Burn” wrote in message news:xxxxx@ntdev…
> Hopefully someone can confirm this, but AFAIK you will get your quadword
> alignment automatically. On the mapping then that is not part of the
> alignment question.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
> wrote in message news:xxxxx@ntdev…
>> Thanks don.
>> Mine is 64 bit architecture.
>> Do you mean to say virtual address for buffer of size greater than
>> quadword are always alligned on quadword boundry?
>>
>> What about buffers less than quadword, are they alligned on quadword
>> boundry? if yes, then can i assume that this virtual address will always
>> quadword alligned? if no then do i need to check explicitly for
>> allignment?
>>
>> Reason i am mapping virtual address to physical address is that i have to
>> give this physical address to interface which will read from device. This
>> interface takes physical address as parameter so device can do I/O
>> directly.
>>
>>
>
>
>

xxxxx@hotmail.com wrote:

Thanks don.
Mine is 64 bit architecture.
Do you mean to say virtual address for buffer of size greater than quadword are always alligned on quadword boundry?

What Don was saying is that you don’t have to do the virtual-to-physical
mapping to check the alignment. In Win32 and Win64 systems, the bottom
12 bits of any virtual/linear address is exactly the same as the bottom
12 bits of its physical address. This is simply a manifestation of the
paging scheme. When large pages are used, the bottom 22 bits are the same.

What about buffers less than quadword, are they alligned on quadword boundry? if yes, then can i assume that this virtual address will always quadword alligned? if no then do i need to check explicitly for allignment?

What are you using to allocate the buffer?

Reason i am mapping virtual address to physical address is that i have to give this physical address to interface which will read from device. This interface takes physical address as parameter so device can do I/O directly.

This is a common limitation.


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

  1. so in any case u have to map virtual address to physical address to
    do use the device.
  2. check for alignment as !((VA) & 0x7)

-----Original Message-----
From: Tim Roberts [mailto:xxxxx@probo.com]
Sent: Monday, March 31, 2008 10:21 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] find physical address allignment

xxxxx@hotmail.com wrote:

Thanks don.
Mine is 64 bit architecture.
Do you mean to say virtual address for buffer of size greater than
quadword are always alligned on quadword boundry?

What Don was saying is that you don’t have to do the virtual-to-physical
mapping to check the alignment. In Win32 and Win64 systems, the bottom
12 bits of any virtual/linear address is exactly the same as the bottom
12 bits of its physical address. This is simply a manifestation of the
paging scheme. When large pages are used, the bottom 22 bits are the
same.

What about buffers less than quadword, are they alligned on quadword
boundry? if yes, then can i assume that this virtual address will always
quadword alligned? if no then do i need to check explicitly for
allignment?

What are you using to allocate the buffer?

Reason i am mapping virtual address to physical address is that i have
to give this physical address to interface which will read from device.
This interface takes physical address as parameter so device can do I/O
directly.

This is a common limitation.


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


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

Hmmm… I get the feeling that one or two of you are actually describing DMA
mechanisms that you intend to implement by using a call to
MmGetPhysicalAddress, completely ignoring the clear warning in the
documentation that this is the wrong way to do this. Please do not do this.
Read the documentation on how to perform DMA operations.

On Mon, Mar 31, 2008 at 3:18 PM, Arora,Harish
wrote:

> 1. so in any case u have to map virtual address to physical address to
> do use the device.
> 2. check for alignment as !((VA) & 0x7)
>
> -----Original Message-----
> From: Tim Roberts [mailto:xxxxx@probo.com]
> Sent: Monday, March 31, 2008 10:21 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] find physical address allignment
>
> xxxxx@hotmail.com wrote:
> > Thanks don.
> > Mine is 64 bit architecture.
> > Do you mean to say virtual address for buffer of size greater than
> quadword are always alligned on quadword boundry?
> >
>
> What Don was saying is that you don’t have to do the virtual-to-physical
> mapping to check the alignment. In Win32 and Win64 systems, the bottom
> 12 bits of any virtual/linear address is exactly the same as the bottom
> 12 bits of its physical address. This is simply a manifestation of the
> paging scheme. When large pages are used, the bottom 22 bits are the
> same.
>
> > What about buffers less than quadword, are they alligned on quadword
> boundry? if yes, then can i assume that this virtual address will always
> quadword alligned? if no then do i need to check explicitly for
> allignment?
> >
>
> What are you using to allocate the buffer?
>
> > Reason i am mapping virtual address to physical address is that i have
> to give this physical address to interface which will read from device.
> This interface takes physical address as parameter so device can do I/O
> directly.
> >
>
> This is a common limitation.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> 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
>
> —
> 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
>


Mark Roddy

Any pool allocations are 8byte aligned.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Hi all,
>
> I want to know that physical address that is allocated for my buffer is
quadword alligned or not?
>
> To do so i am mapping my virtual address (returned by exallocatepool
function) to physical address by MmGetPhysicalAddress() and then mod this
physical address with sizeof(u64)[paddress%sizeof(u64) == 0] to find whether
this physical address is quadword alligned.
>
> It’s quite tadious so is there any other way by which i can achieve my
objective?
>
> Thanks in anticipation!
>

Thanks maxim and all for your reply.

This is one thing that you have to rely on rock solid documentation for.
Unless a function is guaranteed to produce some known alignment you have to
assume it is not aligned. A small wrapper function is worth writing that can
guarantee you any alignment you want. It’s probably not safe to to take an
average of a number of experts opinions, as even if they wrote the OS, if it
is not clearly and unambiguously documented it may change in the next
update. M