]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
driver: Fix image loading at unaligned addresses
authorJan Kiszka <jan.kiszka@siemens.com>
Sun, 10 May 2015 13:27:08 +0000 (15:27 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Mon, 11 May 2015 15:09:50 +0000 (17:09 +0200)
Make sure that images are loaded at the correct location if the target
address is not aligned on a page boundary.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver/cell.c

index 527a3f090dc38c2ebbfcd981428951cd8b2891f0..d88d1eceac511ce05da3319ca4f4785bfb98d576 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <linux/cpu.h>
+#include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
@@ -269,8 +270,8 @@ static int load_image(struct cell *cell,
 {
        struct jailhouse_preload_image image;
        const struct jailhouse_memory *mem;
-       unsigned int regions;
-       u64 image_offset;
+       unsigned int regions, page_offs;
+       u64 image_offset, phys_start;
        void *image_mem;
        int err = 0;
 
@@ -292,8 +293,10 @@ static int load_image(struct cell *cell,
        if (regions == 0)
                return -EINVAL;
 
-       image_mem = jailhouse_ioremap(mem->phys_start + image_offset, 0,
-                                     image.size);
+       phys_start = (mem->phys_start + image_offset) & PAGE_MASK;
+       page_offs = offset_in_page(image_offset);
+       image_mem = jailhouse_ioremap(phys_start, 0,
+                                     PAGE_ALIGN(image.size + page_offs));
        if (!image_mem) {
                pr_err("jailhouse: Unable to map cell RAM at %08llx "
                       "for image loading\n",
@@ -301,7 +304,7 @@ static int load_image(struct cell *cell,
                return -EBUSY;
        }
 
-       if (copy_from_user(image_mem,
+       if (copy_from_user(image_mem + page_offs,
                           (void __user *)(unsigned long)image.source_address,
                           image.size))
                err = -EFAULT;