diff options
author | Andrew G. Harvey <agh@cisco.com> | 2008-09-24 03:10:02 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-10-16 20:24:54 +0400 |
commit | 02683ffdf655b4ae15245376ba6fea6d9e5829a6 (patch) | |
tree | 9b66a97df10db3d09be94e90b90f1e3b6eaa4934 /drivers | |
parent | a6030fcc608bd333c80eab3bfc72f63906476c61 (diff) | |
download | linux-02683ffdf655b4ae15245376ba6fea6d9e5829a6.tar.xz |
UIO: Fix mapping of logical and virtual memory
mmap() doesn't work as expected for UIO_MEM_LOGICAL or UIO_MEM_VIRTUAL
mappings. The offset into the memory needs to be added, otherwise
uio_vma_fault always returns the first page only. Note that for UIO
userspace calls mmap() with offset = N * getpagesize() to access
mapping N. This must be compensated when calculating the offset. A
comment was added to explain this since it is not obvious.
Signed-off-by: Andrew G. Harvey <agh@cisco.com>
Signed-off-by: Hans J. Koch <hjk@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/uio/uio.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 557e73ef5884..5dccf057a7dd 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -490,15 +490,23 @@ static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { struct uio_device *idev = vma->vm_private_data; struct page *page; + unsigned long offset; int mi = uio_find_mem_index(vma); if (mi < 0) return VM_FAULT_SIGBUS; + /* + * We need to subtract mi because userspace uses offset = N*PAGE_SIZE + * to use mem[N]. + */ + offset = (vmf->pgoff - mi) << PAGE_SHIFT; + if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL) - page = virt_to_page(idev->info->mem[mi].addr); + page = virt_to_page(idev->info->mem[mi].addr + offset); else - page = vmalloc_to_page((void*)idev->info->mem[mi].addr); + page = vmalloc_to_page((void *)idev->info->mem[mi].addr + + offset); get_page(page); vmf->page = page; return 0; |