Skip to contentSkip to conversation

use MTRR for write combining if PAT is not available

RFC PATCH Thomas Schlichter 3 participants 4 messages Oct 22, 2009

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Suresh Siddha
Quoted 2 lines · Thomas Schlichter

OK, so I think the attached patches should do it. Hopefully I have addressed all your comments.

Thomas,

I have couple of issues with this patchset still. pci_mmap_page_range() doesn't get called for each fork(). So, we won't be ref counting the mtrr usage properly.

When forking, what happens with the "struct file"? If it is being copied, then the processes share the same private data which would be freed during the first release(). I think this would be a problem whereever file-private data are used.

So I think it must be shared between the forked processes and some reference counting must exist. This reference counting must ensure that release() is only called when all processes did close() their file.

And in that case (shared "struct file", one single release() call in the end) this implementation should be completely safe...

Quoted 3 lines

I need to think a bit more carefully on this. Can I get back to you early next week on this, as I am traveling and need to think through this?

Of course you can. But as I do this just in my spare time, I can only work on this in the evenings...

Quoted 5 lines

We already keep track of some of the PAT ref counting using track_pfn_vma_copy(). And we need to extend/use something similar here.

Even if we need to extend sysfs or pci vma ops, we need to increment and decrement the ref count of the mtrr register that gets used.

The MTRR register ref count is already incremented with each mtrr_add() or mtrr_add_page() that has the "increment" parameter set to true. Which is the case in my implementation.

Quoted 1 line

There is no need to go through num_var_ranges etc.

Well I have to remember wich file added which MTRR entries. Because I have to remove them if the file is being closed. Therefore I need an array of size "num_var_ranges" (or MTRR_MAX_VAR_RANGES which is the uper bound).

Btw. if there really is a problem in my reference counting code, it also exists in the current code in:
arch/x86/kernel/cpu/mtrr/if.c

My patch borrows its ref-counting parts from there...

Kind regards,
Thomas

#1 lore raw
Quoted 9 lines · Thomas Schlichter
Quoted 4 lines

I have couple of issues with this patchset still. pci_mmap_page_range() doesn't get called for each fork(). So, we won't be ref counting the mtrr usage properly.

When forking, what happens with the "struct file"? If it is being copied, then the processes share the same private data which would be freed during the first release(). I think this would be a problem whereever file-private data are used.

Quoted 7 lines

So I think it must be shared between the forked processes and some reference counting must exist. This reference counting must ensure that release() is only called when all processes did close() their file.

And in that case (shared "struct file", one single release() call in the end) this implementation should be completely safe...

struct file is shared between forked processes.

-hpa

#3 lore raw
In reply to Thomas Schlichter
Quoted 10 lines · Thomas Schlichter

When forking, what happens with the "struct file"? If it is being copied, then the processes share the same private data which would be freed during the first release(). I think this would be a problem whereever file-private data are used.

So I think it must be shared between the forked processes and some reference counting must exist. This reference counting must ensure that release() is only called when all processes did close() their file.

And in that case (shared "struct file", one single release() call in the end) this implementation should be completely safe...

I am referring to the refcount getting incremented. Also, let me think about your direction (as the pci_mmap_page_rane() is explicitly adding the mtrr, we should perhaps do the ref counting there, perhaps)

Quoted 5 lines
Quoted 1 line

There is no need to go through num_var_ranges etc.

Well I have to remember wich file added which MTRR entries. Because I have to remove them if the file is being closed. Therefore I need an array of size "num_var_ranges" (or MTRR_MAX_VAR_RANGES which is the uper bound).

No. the private data for example can keep track of a struct containing mtrr number and ref count etc. Exporting var_ranges and going through var ranges elements in an array is not clean, especially when you are populating only one element.

thanks
suresh

#2 lore raw
In reply to H. Peter Anvin
Quoted 14 lines · H. Peter Anvin
Quoted 13 lines · Thomas Schlichter
Quoted 4 lines

I have couple of issues with this patchset still. pci_mmap_page_range() doesn't get called for each fork(). So, we won't be ref counting the mtrr usage properly.

When forking, what happens with the "struct file"? If it is being copied, then the processes share the same private data which would be freed during the first release(). I think this would be a problem whereever file-private data are used.

So I think it must be shared between the forked processes and some reference counting must exist. This reference counting must ensure that release() is only called when all processes did close() their file.

Quoted 5 lines
Quoted 3 lines

And in that case (shared "struct file", one single release() call in the end) this implementation should be completely safe...

struct file is shared between forked processes.

That is correct. But I am referring to the ref-count getting incremented in Thomas's patch only in the pci_mmap_page_range() which will be called only during first mmap.

We need to keep track of the counts of later forks too. For PAT, we keep track of this ref counting in track_pfn_vma_copy(). We shouldn't use different tracking mechanisms for PAT and non-PAT. We should cleanly tap into track_pfn_vma_copy() or extend that to cover this case aswell.

thanks,
suresh