vmap: Handle unaligned vaddrs on vunmap_vmem()
authorBarret Rhoden <brho@cs.berkeley.edu>
Sat, 26 Nov 2016 22:03:20 +0000 (17:03 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 29 Nov 2016 16:27:40 +0000 (11:27 -0500)
vmap_pmem() allows the user to give us an unaligned paddr and it maps
enough pages to cover the requested region.  However, for the unmap, we
incorrectly thought we were given the vaddr of the overall mapping - not
the vaddr we returned to the caller (which was vaddr + PGOFF(paddr).

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/src/mm.c

index db355ea..b8f27e1 100644 (file)
@@ -1290,8 +1290,11 @@ uintptr_t vmap_pmem_writecomb(uintptr_t paddr, size_t nr_bytes)
 
 int vunmap_vmem(uintptr_t vaddr, size_t nr_bytes)
 {
-       unsigned long nr_pages = ROUNDUP(nr_bytes, PGSIZE) >> PGSHIFT;
-       unmap_vmap_segment(vaddr, nr_pages);
-       put_vmap_segment(vaddr, nr_pages);
+       unsigned long nr_pages;
+
+       nr_bytes += PGOFF(vaddr);
+       nr_pages = ROUNDUP(nr_bytes, PGSIZE) >> PGSHIFT;
+       unmap_vmap_segment(PG_ADDR(vaddr), nr_pages);
+       put_vmap_segment(PG_ADDR(vaddr), nr_pages);
        return 0;
 }