user mode virtual address sometimes invalid

Hello ,
I’m developing a Windows 2000 pnp function driver. I use Buffered I/O data
transfer mode.
I allocate a page in driver by using MmAllocateContiguousMemory & DMA writes
data onto the page. My application has to access the data on that page.
Therefore to map the page to user mode,
I allocated a mdl by IoAllocateMdl() & MmBuildMdlForNonPagesPool(). Then by
using MmMapLockedPagesSpecifyCache(), I get user mode virutal address for
the page. I store the address in device extension. Lateron when my
application requires the data, I call the driver function & get the user
mode address stored in device extension.
However I’ve observed that sometimes the address is invalid. After few
retries , it gives valid address. What may be the reason ?
Thanks in advance for the help,

Aparna
Member Technical Staff
NitAl Computer Systems Pvt. Ltd

Hi Aparna,
From your mail what I feel is that you have lots of misconceptions regarding
virtual memory usage on Windows-NT. First of all, you shouldn’t be using the
virtual memory pointer returned by MmAllocateContiguousMemory() to program your
device for DMA access, since there is no guarantee that it will be same as the
logical memory address you need to program your device with, for DMA access. If
you are using Common Buffer DMA you should be using the logical address returned
by AllocateCommonBuffer() to program your device for DMA access.
Second, even though you are using Buffered I/O I am not sure why you want to
call the routines IoAllocateMdl(), MmBuildMdlForNonPagesPool() and
MmMapLockedPagesSpecifyCache() with the SystemBuffer which you receive in your
IRP since this SystemBuffer doesn’t specify any user mode virtual address, but
is a system mode memory allocated from the non-paged pool by the I/O manager,
before the IRP comes to the dispatch routine. When this IRP is completed the
contents of the SystemBuffer will again be copied to the user mode buffer. So,
in any of your routines which copy the data from the common buffer, you can
directly use the SystemBuffer pointer passed in your IRP.

Hope this is of some help…

Regards,
Neelay

Aparna Argade wrote:

Hello ,
I’m developing a Windows 2000 pnp function driver. I use Buffered I/O data
transfer mode.
I allocate a page in driver by using MmAllocateContiguousMemory & DMA writes
data onto the page. My application has to access the data on that page.
Therefore to map the page to user mode,
I allocated a mdl by IoAllocateMdl() & MmBuildMdlForNonPagesPool(). Then by
using MmMapLockedPagesSpecifyCache(), I get user mode virutal address for
the page. I store the address in device extension. Lateron when my
application requires the data, I call the driver function & get the user
mode address stored in device extension.
However I’ve observed that sometimes the address is invalid. After few
retries , it gives valid address. What may be the reason ?
Thanks in advance for the help,

Aparna
Member Technical Staff
NitAl Computer Systems Pvt. Ltd


You are currently subscribed to ntdev as: xxxxx@netlab.hcltech.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Hello Neelay,
I’ve given the logical address to DMA. In the ISR, I copy the data to this
page.
Secondly, I don’t associate mdl with any IRP, otherwise all those things
were not at all needed.
My requirement is that I’ve allocated a page & in the ISR I get data onto
the page. Now when my application comes to know that the interrupt has
occured then I want to read the contents of tha page Therefore I want to
pass the user mode virtual address of the page. The application should
access the whole 4K data.
Therefore I built an mdl & got the address by MmMapLockedPagesSpecifyCache.
However sometimes getting invalid address.
Aparna

----- Original Message -----
From: Neelay Das
To: NT Developers Interest List
Sent: Monday, March 20, 2000 12:36 PM
Subject: [ntdev] Re: user mode virtual address sometimes invalid

> Hi Aparna,
> From your mail what I feel is that you have lots of misconceptions
regarding
> virtual memory usage on Windows-NT. First of all, you shouldn’t be using
the
> virtual memory pointer returned by MmAllocateContiguousMemory() to program
your
> device for DMA access, since there is no guarantee that it will be same as
the
> logical memory address you need to program your device with, for DMA
access. If
> you are using Common Buffer DMA you should be using the logical address
returned
> by AllocateCommonBuffer() to program your device for DMA access.
> Second, even though you are using Buffered I/O I am not sure why you
want to
> call the routines IoAllocateMdl(), MmBuildMdlForNonPagesPool() and
> MmMapLockedPagesSpecifyCache() with the SystemBuffer which you receive in
your
> IRP since this SystemBuffer doesn’t specify any user mode virtual address,
but
> is a system mode memory allocated from the non-paged pool by the I/O
manager,
> before the IRP comes to the dispatch routine. When this IRP is completed
the
> contents of the SystemBuffer will again be copied to the user mode buffer.
So,
> in any of your routines which copy the data from the common buffer, you
can
> directly use the SystemBuffer pointer passed in your IRP.
>
> Hope this is of some help…
>
> Regards,
> Neelay
>
> Aparna Argade wrote:
>
> > Hello ,
> > I’m developing a Windows 2000 pnp function driver. I use Buffered I/O
data
> > transfer mode.
> > I allocate a page in driver by using MmAllocateContiguousMemory & DMA
writes
> > data onto the page. My application has to access the data on that page.
> > Therefore to map the page to user mode,
> > I allocated a mdl by IoAllocateMdl() & MmBuildMdlForNonPagesPool(). Then
by
> > using MmMapLockedPagesSpecifyCache(), I get user mode virutal address
for
> > the page. I store the address in device extension. Lateron when my
> > application requires the data, I call the driver function & get the user
> > mode address stored in device extension.
> > However I’ve observed that sometimes the address is invalid. After few
> > retries , it gives valid address. What may be the reason ?
> > Thanks in advance for the help,
> >
> > Aparna
> > Member Technical Staff
> > NitAl Computer Systems Pvt. Ltd
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@netlab.hcltech.com
> > To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@nital.stpp.soft.net
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Hi Aparna,
From your mail, it is not clear whether your DMA device uses packet based
DMA or common buffer DMA. If your device uses packet based DMA, you can set your
device for Direct I/O, so that in each of your read requests the MDL in your
Irp->MdlAddress, maps the pages of the user mode buffer and these pages are
already locked by the I/O manager before the IRP comes to the dispatch routine.
Then you can call MapTransfer() passing the virtual address got by calling
MmGetMdlVirtualAddress() with Irp->MdlAddress as a result of which you can get
the logical address needed to program your device. If you plan to call
MmMapLockedPagesSpecifyCache() you need to ensure that the corresponding pages
have previously been locked using MmProbeAndLockPages(). The reason you are
getting an invalid address might be because you haven’t called
MmProbeAndLockPages().
However, if your device is a common buffer DMA device you need to call
AllocateCommonBuffer() and use the logical address got as a result to program
your device.

Hope this is of some help…

Regards,
Neelay

Aparna Argade wrote:

Hello Neelay,
I’ve given the logical address to DMA. In the ISR, I copy the data to this
page.
Secondly, I don’t associate mdl with any IRP, otherwise all those things
were not at all needed.
My requirement is that I’ve allocated a page & in the ISR I get data onto
the page. Now when my application comes to know that the interrupt has
occured then I want to read the contents of tha page Therefore I want to
pass the user mode virtual address of the page. The application should
access the whole 4K data.
Therefore I built an mdl & got the address by MmMapLockedPagesSpecifyCache.
However sometimes getting invalid address.
Aparna

----- Original Message -----
From: Neelay Das
> To: NT Developers Interest List
> Sent: Monday, March 20, 2000 12:36 PM
> Subject: [ntdev] Re: user mode virtual address sometimes invalid
>
> > Hi Aparna,
> > From your mail what I feel is that you have lots of misconceptions
> regarding
> > virtual memory usage on Windows-NT. First of all, you shouldn’t be using
> the
> > virtual memory pointer returned by MmAllocateContiguousMemory() to program
> your
> > device for DMA access, since there is no guarantee that it will be same as
> the
> > logical memory address you need to program your device with, for DMA
> access. If
> > you are using Common Buffer DMA you should be using the logical address
> returned
> > by AllocateCommonBuffer() to program your device for DMA access.
> > Second, even though you are using Buffered I/O I am not sure why you
> want to
> > call the routines IoAllocateMdl(), MmBuildMdlForNonPagesPool() and
> > MmMapLockedPagesSpecifyCache() with the SystemBuffer which you receive in
> your
> > IRP since this SystemBuffer doesn’t specify any user mode virtual address,
> but
> > is a system mode memory allocated from the non-paged pool by the I/O
> manager,
> > before the IRP comes to the dispatch routine. When this IRP is completed
> the
> > contents of the SystemBuffer will again be copied to the user mode buffer.
> So,
> > in any of your routines which copy the data from the common buffer, you
> can
> > directly use the SystemBuffer pointer passed in your IRP.
> >
> > Hope this is of some help…
> >
> > Regards,
> > Neelay
> >
> > Aparna Argade wrote:
> >
> > > Hello ,
> > > I’m developing a Windows 2000 pnp function driver. I use Buffered I/O
> data
> > > transfer mode.
> > > I allocate a page in driver by using MmAllocateContiguousMemory & DMA
> writes
> > > data onto the page. My application has to access the data on that page.
> > > Therefore to map the page to user mode,
> > > I allocated a mdl by IoAllocateMdl() & MmBuildMdlForNonPagesPool(). Then
> by
> > > using MmMapLockedPagesSpecifyCache(), I get user mode virutal address
> for
> > > the page. I store the address in device extension. Lateron when my
> > > application requires the data, I call the driver function & get the user
> > > mode address stored in device extension.
> > > However I’ve observed that sometimes the address is invalid. After few
> > > retries , it gives valid address. What may be the reason ?
> > > Thanks in advance for the help,
> > >
> > > Aparna
> > > Member Technical Staff
> > > NitAl Computer Systems Pvt. Ltd
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@netlab.hcltech.com
> > > To unsubscribe send a blank email to $subst(‘Email.Unsub’)
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@nital.stpp.soft.net
> > To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
> —
> You are currently subscribed to ntdev as: xxxxx@netlab.hcltech.com
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)

What exactly do you mean by: “However I’ve observed that sometimes the
address is invalid. After few retries , it gives valid address”?

=
Mark Roddy

Windows 2000/Windows NT Consulting:

xxxxx@hollistech.com
www.hollistech.com

=

Hi Mark ,
I allocate Mdl at application initialization. Lateron whenever my
application needs the data, I call driver function to get its user mode
address (given by MmMapLockedPagesSpecifyCache()). It’s not guranteed to get
valid address everytime. sometimes I get correct results , however sometimes
the address or its contens are invalid. After getting failure , I
immediately call the same function. Then I may get valid results.
This means for the same mdl, sometimes I get valid address & sometimes
invalid.
The behaviour is random.
I use Buffered I/O , therefore I can not use MmProbeAndLockPages call.
Regards,
Aparna
----- Original Message -----
From: Mark Roddy
To: NT Developers Interest List
Sent: Monday, March 20, 2000 5:03 PM
Subject: [ntdev] RE: user mode virtual address sometimes invalid

> What exactly do you mean by: “However I’ve observed that sometimes the
> address is invalid. After few retries , it gives valid address”?
>
> =
> Mark Roddy
>
> Windows 2000/Windows NT Consulting:
>
> xxxxx@hollistech.com
> www.hollistech.com
>
> =
>
>
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@nital.stpp.soft.net
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Hi Aparna,
But, you can call MmMapLockedPagesSpecifyCache() only on a virtual address
whose pages have already been locked in the Physical Memory space. I still don’t
understand, why you can’t use MmProbeAndLockPages() on the user mode virtual
address you are using. Can you be more specific as to how you are getting this
virtual address from the application ? In my opinion, the best option for you
would be to use Direct I/O where, the I/O manager itself locks the user mode
pages for you.

Regards,
Neelay

Aparna Argade wrote:

Hi Mark ,
I allocate Mdl at application initialization. Lateron whenever my
application needs the data, I call driver function to get its user mode
address (given by MmMapLockedPagesSpecifyCache()). It’s not guranteed to get
valid address everytime. sometimes I get correct results , however sometimes
the address or its contens are invalid. After getting failure , I
immediately call the same function. Then I may get valid results.
This means for the same mdl, sometimes I get valid address & sometimes
invalid.
The behaviour is random.
I use Buffered I/O , therefore I can not use MmProbeAndLockPages call.
Regards,
Aparna
----- Original Message -----
From: Mark Roddy
> To: NT Developers Interest List
> Sent: Monday, March 20, 2000 5:03 PM
> Subject: [ntdev] RE: user mode virtual address sometimes invalid
>
> > What exactly do you mean by: “However I’ve observed that sometimes the
> > address is invalid. After few retries , it gives valid address”?
> >
> > =
> > Mark Roddy
> >
> > Windows 2000/Windows NT Consulting:
> >
> > xxxxx@hollistech.com
> > www.hollistech.com
> >
> > =
> >
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@nital.stpp.soft.net
> > To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
> —
> You are currently subscribed to ntdev as: xxxxx@netlab.hcltech.com
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)