]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
x86: fix erroneous sizeof() usage
authorValentine Sinitsyn <valentine.sinitsyn@gmail.com>
Wed, 4 Nov 2015 09:06:11 +0000 (14:06 +0500)
committerJan Kiszka <jan.kiszka@siemens.com>
Fri, 13 Nov 2015 15:29:14 +0000 (16:29 +0100)
vcpu functions were using sizeof() to determine the size of dynamically
allocated I/O bitmap, which won't work. Assign this value statically per
sub-architecture (Intel or AMD).

Reported-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/svm.c
hypervisor/arch/x86/vmx.c

index 4d77baccf567ea17a78dcb6d4b3883e2fb06da16..0af5786c8f77a03f86572194cf3a6b467afc6a75 100644 (file)
@@ -39,6 +39,9 @@
  */
 #define SVM_CR0_ALLOWED_BITS   (~X86_CR0_NW)
 
+/* IOPM size: two 4-K pages + 3 bits */
+#define IOPM_PAGES             3
+
 static bool has_avic, has_assists, has_flush_by_asid;
 
 static const struct segment invalid_seg;
@@ -292,8 +295,8 @@ int vcpu_vendor_cell_init(struct cell *cell)
        int err = -ENOMEM;
        u64 flags;
 
-       /* allocate iopm (two 4-K pages + 3 bits) */
-       cell->arch.svm.iopm = page_alloc(&mem_pool, 3);
+       /* allocate iopm  */
+       cell->arch.svm.iopm = page_alloc(&mem_pool, IOPM_PAGES);
        if (!cell->arch.svm.iopm)
                return err;
 
@@ -984,7 +987,7 @@ void vcpu_vendor_get_cell_io_bitmap(struct cell *cell,
                                    struct vcpu_io_bitmap *iobm)
 {
        iobm->data = cell->arch.svm.iopm;
-       iobm->size = sizeof(cell->arch.svm.iopm);
+       iobm->size = IOPM_PAGES * PAGE_SIZE;
 }
 
 void vcpu_vendor_get_execution_state(struct vcpu_execution_state *x_state)
index c38ad2eb55cac37a04bb331aa2d89be2430399ab..00acd027634d4d571fcae878ef8ac385d38b46a3 100644 (file)
 #include <asm/vcpu.h>
 #include <asm/vmx.h>
 
-#define CR0_IDX                0
-#define CR4_IDX                1
+#define CR0_IDX                        0
+#define CR4_IDX                        1
+
+#define PIO_BITMAP_PAGES       2
 
 static const struct segment invalid_seg = {
        .access_rights = 0x10000
@@ -326,7 +328,7 @@ int vcpu_vendor_cell_init(struct cell *cell)
        int err = -ENOMEM;
 
        /* allocate io_bitmap */
-       cell->arch.vmx.io_bitmap = page_alloc(&mem_pool, 2);
+       cell->arch.vmx.io_bitmap = page_alloc(&mem_pool, PIO_BITMAP_PAGES);
        if (!cell->arch.vmx.io_bitmap)
                return err;
 
@@ -1133,7 +1135,7 @@ void vcpu_vendor_get_cell_io_bitmap(struct cell *cell,
                                    struct vcpu_io_bitmap *iobm)
 {
        iobm->data = cell->arch.vmx.io_bitmap;
-       iobm->size = sizeof(cell->arch.vmx.io_bitmap);
+       iobm->size = PIO_BITMAP_PAGES * PAGE_SIZE;
 }
 
 void vcpu_vendor_get_execution_state(struct vcpu_execution_state *x_state)