Re: mlockall and mmap of IO devices don't mix

From: Andrew Morton
Date: Fri Oct 03 2003 - 19:30:37 EST


Joe Korty <joe.korty@xxxxxxxx> wrote:
>
> Your third patch worked perfectly for all the tested cases:
> o /dev/mem at offset fd000000 (my video card mem addr)
> o /dev/mem at offset 0
> o with an mmapable device driver.

OK, thanks.

> I did have to make two changes to get it to compile:


> --- mm/memory.c.am3 2003-10-03 19:44:17.000000000 -0400
> +++ mm/memory.c 2003-10-03 19:43:47.000000000 -0400
> @@ -738,7 +738,7 @@
> #endif
>
> special = vma->vm_flags & (VM_IO | VM_RESERVED);
> - if (!vma || (pages && vm_io) || !(flags & vma->vm_flags))
> + if (!vma || (pages && special) || !(flags & vma->vm_flags))
> return i ? : -EFAULT;
>
> if (is_vm_hugetlb_page(vma)) {
> @@ -755,7 +755,7 @@
> * mappings of /dev/mem - they may have no pageframes.
> * And the caller passed NULL for `pages' anyway.
> */
> - while (!special && !(map=follow_page(mm,start,write)) {
> + while (!special && !(map=follow_page(mm,start,write))) {
> spin_unlock(&mm->page_table_lock);
> switch (handle_mm_fault(mm,vma,start,write)) {
> case VM_FAULT_MINOR:
>
> In the first change, 'special' != '(vma->vma_flags & VM_IO)' which
> was what was originally being tested. Could that cause a problem?

Yes, this is saying that you cannot extract pageframes from a mapping of
/dev/mem. It means that you can no longer, for example, do a direct-IO
write of a chunk of /dev/mem onto disk. I seem to recall that this is
disallowed for other reasons anwyay.

> Also, could the use of VM_RESERVED cause in some cases memory with
> pageframes to skip adjustment/use of those pageframes?

Could be so, if someone is trying to (say) do a direct-IO write of some
sound card's DMA buffer to disk. Which is a pretty reasonable thing to do.

Maybe it's best to not overload VM_RESERVED in this manner, but to always
mark /dev/mem as VM_IO.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/