Problems with buffer splitting

Dear All!

I’m developing lower volume filter and have faced one interesting problem which i don’t know how to solve.

Description:
My volume filter driver receives a buffer for READ/WRITE. Some parts of that buffer are obtained from disk and other from the storage file. I do it using following steps:

buffer = GetSystemBufferForMdlSafe(Irp->Mdl);

  1. calculate Offset from which next part of that buffer will be used
  2. Irp1 = IoBuildSynchronousFsdRequest(buffer+Offset, Length,Event…)
  3. IoCallDriver(Irp1);
  4. Waiting for Event

Following steps are used for all parts of the buffer and after all subparts of original buffer were processed, i complete the original Irp.

So, generally, i map original MDL to SystemVirtual Address and split it onto different parts and send all of them to different devices.

It finely works for XP, …but SOMETIMES on W2k3 and Vista it doesn’t work.

I investigated why it doesn’t work and the problem is with Completing sub Irps
When sub Irps were made they are made using IoBuildSynchronousFsdRequest(buffer+Offset, Length,Event…), where buffer+Offset are not PAGE allignt. So when one of sub Irps are completed I see that whole PAGE, on which some part of buffer resides, is changed. And if one of earlier sub Irps was already finished and written the data to according part of buffer, other sub Irps during completing changes all data on all pages on which following sub buffer resides.

So, i’m stuck in that problem… why it hapens???

Could somebody, please, answer why it hapens and only sometimes and only on W2K3 and on Vista.

I still don’t understand why completing sub Irp with one part of buffer received from main IRP affects on another parts…

So, after debugging i found the in W2K3 during boot start thread CcPfBootWorker which uses funciton MmPrefetchPages and wait for completion… So, my volume filter recieves MDL and when i call MmGetSystemBufferForMdlSafe(MDL) in debugger i see that 3 continious memory pages described by one PFN and that’s why it BSODs… Is there any ideas???

I have no idea what the above means.

How can 3 contiguous physical pages be described by one PFN (entry). By definition, there’s one Page Frame Number for each physical page… given a “page frame” == a “physical page.”

Can you be a bit more descriptive in what you’re observing?

Also, as usual, post the bugcheck, the analyze -v output you’re getting. There’s really no other way we’re likely to be able to figure out the problem.

Peter
OSR

MmGetSystemAddressForMdlSafe(MDL) returnts buffer of System Virtual Address, not physical.
What i see is that several virtual memory pages of buffer obtained calling above API points to the same PFN.

And when i write to that buffer contigious data array, all that virtual memory pages are with the same data inside…

This is expected behavior. See the MmPrefetchPages documentation:

“'The pages are read with a single read, using a dummy page to bridge small
gaps. If the gap is “large”, then separate reads are issued.”

If you care about the buffer contents you need to read into a separate
buffer.

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

Looking forward to seeing you at the next OSR Kernel Debugging Class April
6, 2009 in Portland, OR!

wrote in message news:xxxxx@ntdev…
> MmGetSystemAddressForMdlSafe(MDL) returnts buffer of System Virtual
> Address, not physical.
> What i see is that several virtual memory pages of buffer obtained calling
> above API points to the same PFN.
>
> And when i write to that buffer contigious data array, all that virtual
> memory pages are with the same data inside…
>

Scott, thank you, but can you please describe it more … As i understand MmPrefetchPages issues the request to read several pages and if they are not contiguous, i.e. has a gaps between pages, it fills this gaps using dummy pages… Am i right?

So, and

  1. how can i determine that dummy pages(bridges)??
  2. and what do i need to do with them, do i need just to ignore them or something other?

Thank you, Scott, for you answer in advance!

>Am i right?

Yup, you got it.

  1. how can i determine that dummy pages(bridges)??

You don’t. If the data contents matter to you, you need to perform the read
with your own buffer and then satisfy the original read. It’s a potential
drag on performance, but there’s not much else you can do.

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

Looking forward to seeing you at the next OSR Kernel Debugging Class April
6, 2009 in Portland, OR!

wrote in message news:xxxxx@ntdev…
> Scott, thank you, but can you please describe it more … As i understand
> MmPrefetchPages issues the request to read several pages and if they are
> not contiguous, i.e. has a gaps between pages, it fills this gaps using
> dummy pages… Am i right?
>
> So, and
> 1) how can i determine that dummy pages(bridges)??
> 2) and what do i need to do with them, do i need just to ignore them or
> something other?
>
> Thank you, Scott, for you answer in advance!
>
>
>
>

> 2) Irp1 = IoBuildSynchronousFsdRequest(buffer+Offset, Length,Event…)

Try using IoAllocateIrp and IoBuildPartialMdl for this IRP instead of the high-level call you’re using (BTW - I hate this call :slight_smile: )


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Look at /kmdf/usbsamp/sys/bulkrwr.c. I use the same technique and able to partition the input buffer to smaller junks to pass to different target devices.

xxxxx@yahoo.com wrote:

Look at /kmdf/usbsamp/sys/bulkrwr.c. I use the same technique and able to partition the input buffer to smaller *junks* to pass to different target devices.

Now, there’s a Freudian slip if ever I heard one.


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

> Now, there’s a Freudian slip if ever I heard one.

I suspect “CH” and 'J" sound identically in the poster’s mother tongue, so that it may be not always easy for him to make a distinction between “chunk” and “junk”.Furthermore, it can be totally unrelated to his mother tongue. For example, I have already lost any hope to ever learn which nuclear process in described by the term “fusion” and which one by “fission” - I know what fusion and fission are, but somehow I always forget which is which…

Anton Bassov

>

> Now, there’s a Freudian slip if ever I heard one.

I suspect “CH” and 'J" sound identically in the poster’s mother
tongue,
so that it may be not always easy for him to make a distinction
between
“chunk” and “junk”.Furthermore, it can be totally unrelated to his
mother
tongue. For example, I have already lost any hope to ever learn which
nuclear process in described by the term “fusion” and which one by
“fission” - I know what fusion and fission are, but somehow I always
forget which is which…

OT of course, I’ve always meant to ask you Anton… are you
‘soviet_bloke’ because you are Russian, or is there some in-joke going
on that is before my time? Just curious, I won’t be offended if you
don’t answer for any reason.

If the former, then maybe this doesn’t help due to the aforementioned
language issues, but fusion comes from the word fuse, as in join
together, so fusion is the one the sun does, and fission is the one our
current nuclear plants do.

There was a cold-war era cartoon book I had once called “Can’t you
bastards read?” which was about nuclear weapon proliferation and nuclear
war in general. One was a cartoon of a guy fishing downstream from a
nuclear power plant, and the caption was ‘nuclear fission’ (as in
‘nuclear fishing’). As bad as the pun was, it’s another way to remember
:slight_smile:

James

James,

OT of course, I’ve always meant to ask you Anton… are you ‘soviet_bloke’ because you are
Russian, or is there some in-joke going on that is before my time?

Both. “Soviet bloke” has been my nickname for around 15 years or even more. Someone in the pub said “soviet bloc” (because I am Russian); I asked “bloc or bloke?”, and that was it - “Soviet bloke” got stuck to me since. Therefore, no wonder my email account is soviet_bloke…

If the former, then maybe this doesn’t help due to the aforementioned language issues,
but fusion comes from the word fuse, as in join together, so fusion is the one the sun does,
and fission is the one our current nuclear plants do.

Actually, I did suspect that the terms “fuse” and "fusion"are related. However, instead of clarifying things, it was contributing to my confusion even more,. AFAIK, fusion and fission processes are used in “conventional” nukes and H-bombs, and, in order to make the latter go off you need to set off the former, i.e. to use it as a fuse…

Anton Bassov

Hint hint: Posts that start “OT… I’ve always meant to ask you…” are probably better off sent directly to the person you always meant to ask, as opposed to shared with your friends on this list who, strangely, wonder about things like Windows system software development. I know, it’s a crazy idea, but…

Peter
OSR

Hi,

Purhaps another good book to read would be ‘Gone fission’ by ‘J.R Hartley’
(note the J). hehe

Steve

----- Original Message -----
From: “James Harper”
To: “Windows System Software Devs Interest List”
Sent: Saturday, February 28, 2009 12:14 PM
Subject: RE: [ntdev] Problems with buffer splitting

>>
>> > Now, there’s a Freudian slip if ever I heard one.
>>
>> I suspect “CH” and 'J" sound identically in the poster’s mother
> tongue,
>> so that it may be not always easy for him to make a distinction
> between
>> “chunk” and “junk”.Furthermore, it can be totally unrelated to his
> mother
>> tongue. For example, I have already lost any hope to ever learn which
>> nuclear process in described by the term “fusion” and which one by
>> “fission” - I know what fusion and fission are, but somehow I always
>> forget which is which…
>>
>
> OT of course, I’ve always meant to ask you Anton… are you
> ‘soviet_bloke’ because you are Russian, or is there some in-joke going
> on that is before my time? Just curious, I won’t be offended if you
> don’t answer for any reason.
>
> If the former, then maybe this doesn’t help due to the aforementioned
> language issues, but fusion comes from the word fuse, as in join
> together, so fusion is the one the sun does, and fission is the one our
> current nuclear plants do.
>
> There was a cold-war era cartoon book I had once called “Can’t you
> bastards read?” which was about nuclear weapon proliferation and nuclear
> war in general. One was a cartoon of a guy fishing downstream from a
> nuclear power plant, and the caption was ‘nuclear fission’ (as in
> ‘nuclear fishing’). As bad as the pun was, it’s another way to remember
> :slight_smile:
>
> James
>
>
> —
> 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
>
>

Ok, thank you, guys. Let’s close this thread, the problem was solved.

Krom,
can you please explain how your problem was solved.
Just to conclude the thread.

Yurii.