MmMapLockedPagesSpecifyCache: Blue dump under Server 2003-32

On 06-Dec-2011 20:14, Zvi Vered wrote:

Dear Joe,

My code has #define BLOCK_SIZE (32*1024*1024)
I also checked each step in the allocation.

Under XP, all the tests are OK and MmMapLockedPagesSpecifyCache works fine.
Under Server2003-32 and Server2008-64, cause a crash.

Thanks,
Zvika

Now this gets interesting…
Do you by chance call MmMapLockedPagesSpecifyCache under a spinlock (or
equivalent KMDF lock)?
Check this by calling KeGetCurrentIrql
(yes there is “CURRENT_IRQL: 0” in your dump decode, but IIRC it is not
always reliable, especially with wrong symbols.)
– pa

wrote in message news:xxxxx@ntdev…
> Hello,
>
> If I wrap MmMapLockedPagesSpecifyCache with try/except, windows will not
> crash but MmMapLockedPagesSpecifyCache will fail.
>
> I want to map a preallocated buffer to a user space address upon IOCTL
> request.
>
> Can you help ?
>

In your exception handler use GetExceptionCode macro to see why it failed.

//Daniel

Also, your machine seems to have 24 processors (from the same dump).
If it is NUMA or something else unusual, try to disable
suspicious things in the BIOS if possible - such as strange video
modes, strange PCI settings, RAM holes and so on.
– pa

On 06-Dec-2011 20:33, Pavel A wrote:

Now this gets interesting…
Do you by chance call MmMapLockedPagesSpecifyCache under a spinlock (or
equivalent KMDF lock)?
Check this by calling KeGetCurrentIrql
(yes there is “CURRENT_IRQL: 0” in your dump decode, but IIRC it is not
always reliable, especially with wrong symbols.)
– pa

On 06-Dec-2011 20:51, xxxxx@resplendence.com wrote:

wrote in message news:xxxxx@ntdev…
>> Hello,
>>
>> If I wrap MmMapLockedPagesSpecifyCache with try/except, windows will not
>> crash but MmMapLockedPagesSpecifyCache will fail.
>>
>> I want to map a preallocated buffer to a user space address upon IOCTL
>> request.
>>
>> Can you help ?
>>
>
> In your exception handler use GetExceptionCode macro to see why it failed.
>
> //Daniel

It was in the dump he’d posted:



Is arg4 (c0006000) indeed the VA being in-paged? It is not a good
usermode VA. If it is a kernel VA, why the kernel wants to page it in?

–pa

I see a problem here:

PPHYSICAL_ADDRESS LogicalAddress

//Allocate common buffer and return its kernel virtual address
DevExt->KernelCommonBuffer = AllocateCommonBuffer(DmaAdapter,
COMMON_BUFFER_SIZE,
&LogicalAddress,
FALSE);

&LogicalAddress is a double pointer and wrong indirection for a
PPHYSICAL_ADDRESS parameter, declare LogicalAddress as PHYSICAL_ADDRESS.

//Daniel

“Zvi Vered” wrote in message news:xxxxx@ntdev…
> Hello,
>
> I’m using:
>
> AllocateCommonBuffer
> IoAllocateMdl
> MmBuildMdlForNonPagedPool
>
> to allocate a continuous physical buffer by kernel driver.
>
> I’m aware that this is wrong and I was warned here about it.
>
> But I have to rewrite an old WDM driver without changing FPGA (which does
> not support scatter-gather).
>
> The 32MB allocation works fine.
>
> Then upon IOCTL request from user space I call to:
>
> PVOID Address = MmMapLockedPagesSpecifyCache (devExt->Mdl, UserMode,
> MmNonCached , NULL, FALSE, NormalPagePriority)
>
> Under XP-32, the allocation and MmMapLockedPagesSpecifyCache works great
> and user space gets the virtual address of the physical buffer.
>
> But under Server 2003-32, allocation works OK but
> MmMapLockedPagesSpecifyCache causes blue dump.
>
> I’m not using the same sys.
>
> For Server 2003-32 I used: Windows Server 2003 x86 Checked Build
> Environment.lnk
>
> Can you help ?
>
> Why there is a difference between writing a kernel driver for XP-32 to
> Server 2003-32 ?
>
> Thanks,
> Zvika.
>
>
>
>
>

On 06-Dec-2011 21:30, xxxxx@resplendence.com wrote:

I see a problem here:

PPHYSICAL_ADDRESS LogicalAddress

//Allocate common buffer and return its kernel virtual address
DevExt->KernelCommonBuffer = AllocateCommonBuffer(DmaAdapter,
COMMON_BUFFER_SIZE,
&LogicalAddress,
FALSE);

&LogicalAddress is a double pointer and wrong indirection for a
PPHYSICAL_ADDRESS parameter, declare LogicalAddress as PHYSICAL_ADDRESS.

//Daniel

Applause!
– pa

“Zvi Vered” wrote in message news:xxxxx@ntdev…
>> Hello,
>>
>> I’m using:
>>
>> AllocateCommonBuffer
>> IoAllocateMdl
>> MmBuildMdlForNonPagedPool
>>
>> to allocate a continuous physical buffer by kernel driver.
>>
>> I’m aware that this is wrong and I was warned here about it.
>>
>> But I have to rewrite an old WDM driver without changing FPGA (which does
>> not support scatter-gather).
>>
>> The 32MB allocation works fine.
>>
>> Then upon IOCTL request from user space I call to:
>>
>> PVOID Address = MmMapLockedPagesSpecifyCache (devExt->Mdl, UserMode,
>> MmNonCached , NULL, FALSE, NormalPagePriority)
>>
>> Under XP-32, the allocation and MmMapLockedPagesSpecifyCache works great
>> and user space gets the virtual address of the physical buffer.
>>
>> But under Server 2003-32, allocation works OK but
>> MmMapLockedPagesSpecifyCache causes blue dump.
>>
>> I’m not using the same sys.
>>
>> For Server 2003-32 I used: Windows Server 2003 x86 Checked Build
>> Environment.lnk
>>
>> Can you help ?
>>
>> Why there is a difference between writing a kernel driver for XP-32 to
>> Server 2003-32 ?
>>
>> Thanks,
>> Zvika.
>>
>>
>>
>>
>>
>
>
>

Dear Paval,

I call to MmMapLockedPagesSpecifyCache upon an IOCTL request from user
driver.
Currently I’m not using any spinlock in my code.
The IOCTL request is sent from the main thread in one process only.
I will check KeGetCurrentIrql and let you know soon.

Thanks,
Zvika.

----- Original Message -----
From: “Pavel A”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Tuesday, December 06, 2011 20:33
Subject: Re:[ntdev] MmMapLockedPagesSpecifyCache: Blue dump under Server
2003-32

> On 06-Dec-2011 20:14, Zvi Vered wrote:
>> Dear Joe,
>>
>> My code has #define BLOCK_SIZE (3210241024)
>> I also checked each step in the allocation.
>>
>> Under XP, all the tests are OK and MmMapLockedPagesSpecifyCache works
>> fine.
>> Under Server2003-32 and Server2008-64, cause a crash.
>>
>> Thanks,
>> Zvika
>
> Now this gets interesting…
> Do you by chance call MmMapLockedPagesSpecifyCache under a spinlock (or
> equivalent KMDF lock)?
> Check this by calling KeGetCurrentIrql
> (yes there is “CURRENT_IRQL: 0” in your dump decode, but IIRC it is not
> always reliable, especially with wrong symbols.)
> – pa
>
> —
> 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

Zvi,

Have you read the last reply of Daniel? I believe he has pinpointed the bug.
– pa

On 06-Dec-2011 23:12, Zvi Vered wrote:

Dear Paval,

I call to MmMapLockedPagesSpecifyCache upon an IOCTL request from user
driver.
Currently I’m not using any spinlock in my code.
The IOCTL request is sent from the main thread in one process only.
I will check KeGetCurrentIrql and let you know soon.

Thanks,
Zvika.

----- Original Message ----- From: “Pavel A”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, December 06, 2011 20:33
> Subject: Re:[ntdev] MmMapLockedPagesSpecifyCache: Blue dump under Server
> 2003-32
>
>
>> On 06-Dec-2011 20:14, Zvi Vered wrote:
>>> Dear Joe,
>>>
>>> My code has #define BLOCK_SIZE (3210241024)
>>> I also checked each step in the allocation.
>>>
>>> Under XP, all the tests are OK and MmMapLockedPagesSpecifyCache works
>>> fine.
>>> Under Server2003-32 and Server2008-64, cause a crash.
>>>
>>> Thanks,
>>> Zvika
>>
>> Now this gets interesting…
>> Do you by chance call MmMapLockedPagesSpecifyCache under a spinlock
>> (or equivalent KMDF lock)?
>> Check this by calling KeGetCurrentIrql
>> (yes there is “CURRENT_IRQL: 0” in your dump decode, but IIRC it is
>> not always reliable, especially with wrong symbols.)
>> – pa
>>
>> —
>> 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
>
>

Hi All,

The code now is:

PHYSICAL_ADDRESS LogicalAddress

DevExt->KernelCommonBuffer = AllocateCommonBuffer(DmaAdapter,COMMON_BUFFER_SIZE,&LogicalAddress,FALSE);

But there is still a crash.

Thanks,
Zvika

My next suggestions are:

-fix the warnings in your code and compile with /w4 or /wAll
-enable verifier on your driver
-post the code of the routine in which you called
MmMapLockedPagesSpecifyCache

//Daniel

wrote in message news:xxxxx@ntdev…
> Hi All,
>
> The code now is:
>
> PHYSICAL_ADDRESS LogicalAddress
>
> DevExt->KernelCommonBuffer =
> AllocateCommonBuffer(DmaAdapter,COMMON_BUFFER_SIZE,&LogicalAddress,FALSE);
>
> But there is still a crash.
>
> Thanks,
> Zvika
>

Hi Daniel,

Is it possible to add files to my reply or should I paste the code in the
message body ?

Thanks,
Zvika.

----- Original Message -----
From:
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Wednesday, December 07, 2011 16:20
Subject: Re:[ntdev] MmMapLockedPagesSpecifyCache: Blue dump under Server
2003-32

> My next suggestions are:
>
> -fix the warnings in your code and compile with /w4 or /wAll
> -enable verifier on your driver
> -post the code of the routine in which you called
> MmMapLockedPagesSpecifyCache
>
> //Daniel
>
>
>
> wrote in message news:xxxxx@ntdev…
>> Hi All,
>>
>> The code now is:
>>
>> PHYSICAL_ADDRESS LogicalAddress
>>
>> DevExt->KernelCommonBuffer =
>> AllocateCommonBuffer(DmaAdapter,COMMON_BUFFER_SIZE,&LogicalAddress,FALSE);
>>
>> But there is still a crash.
>>
>> Thanks,
>> Zvika
>>
>
>
>
> —
> 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

I think attachments are not supported.

//Daniel

“Zvi Vered” wrote in message news:xxxxx@ntdev…
> Hi Daniel,
>
> Is it possible to add files to my reply or should I paste the code in the
> message body ?
>
> Thanks,
> Zvika.
>

Hi Zvika,
Could you resend your new dump after you change PPHYSICAL_ADDRESS to
PHYSICAL_ADDRESS. BTW, you’d better configure your correct OS symbol. It
will make us to help you to analyze.
Thanks.
Marvin

On Wed, Dec 7, 2011 at 11:41 PM, wrote:

> I think attachments are not supported.
>
> //Daniel
>
>
> “Zvi Vered” wrote in message news:xxxxx@ntdev…
> > Hi Daniel,
> >
> > Is it possible to add files to my reply or should I paste the code in the
> > message body ?
> >
> > Thanks,
> > Zvika.
> >
>
>
>
> —
> 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
>