Skip to content

Commit

Permalink
UIO: Fix mapping of logical and virtual memory
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Hans J. Koch <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Andrew G. Harvey authored and gregkh committed Oct 16, 2008
1 parent a6030fc commit 02683ff
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/uio/uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 02683ff

Please sign in to comment.