]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
core: Avoid exposing register set to pci_mmio_access_handler
authorJan Kiszka <jan.kiszka@siemens.com>
Mon, 5 May 2014 17:21:06 +0000 (19:21 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Wed, 7 May 2014 11:29:25 +0000 (13:29 +0200)
This handler is generic and should not assume anything about how
registers can be accessed. At this chance, replace the open-coded MMIO
accesses with the appropriate helpers.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/vmx.c
hypervisor/include/jailhouse/pci.h
hypervisor/pci.c

index fd06b48c102e0790822886ad196ceb15b06aee49..47ac35949d8bda9a6d235a59840ed88d7d14e9ec 100644 (file)
@@ -1034,6 +1034,7 @@ static bool vmx_handle_ept_violation(struct registers *guest_regs,
        struct guest_paging_structures pg_structs;
        struct mmio_access access;
        bool is_write;
+       u32 val;
 
        /* We don't enable dirty/accessed bit updated in EPTP, so only read
         * of write flags can be set, not both. */
@@ -1041,14 +1042,20 @@ static bool vmx_handle_ept_violation(struct registers *guest_regs,
 
        if (!vmx_get_guest_paging_structs(&pg_structs))
                return false;
+
        access = mmio_parse(cpu_data, vmcs_read64(GUEST_RIP),
                            &pg_structs, is_write);
        if (!access.inst_len || access.size != 4)
                return false;
 
+       if (is_write)
+               val = ((unsigned long *)guest_regs)[access.reg];
+
        /* Filter out requests to PCI configuration space */
-       if (pci_mmio_access_handler(guest_regs, cpu_data->cell,
-                                   is_write, phys_addr, access.reg) == 1) {
+       if (pci_mmio_access_handler(cpu_data->cell, is_write,
+                                   phys_addr, &val) == 1) {
+               if (!is_write)
+                       ((unsigned long *)guest_regs)[access.reg] = val;
                vmx_skip_emulated_instruction(
                                vmcs_read64(VM_EXIT_INSTRUCTION_LEN));
                return true;
index 485dab5a8da0b868cd92053fb2b61963bb3c346b..0cff9fc9c3668a24fe92b5079a6ba7ba1d39aefe 100644 (file)
@@ -25,8 +25,7 @@ pci_get_assigned_device(const struct cell *cell, u16 bdf);
 bool pci_cfg_write_allowed(u32 type, u8 reg_num, unsigned int reg_bias,
                           unsigned int size);
 
-int pci_mmio_access_handler(struct registers *guest_regs,
-                           const struct cell *cell, bool is_write,
-                           u64 addr, u32 reg);
+int pci_mmio_access_handler(const struct cell *cell, bool is_write, u64 addr,
+                           u32 *value);
 
 #endif /* !_JAILHOUSE_PCI_H */
index 0eff21a481bbbdbe2671d985bfc2eaeea7495e4b..9309d0576d3fbd6a252af733251ea1fbcc2f7d60 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <jailhouse/acpi.h>
+#include <jailhouse/mmio.h>
 #include <jailhouse/pci.h>
 #include <jailhouse/printk.h>
 #include <jailhouse/utils.h>
@@ -142,13 +143,12 @@ int pci_init(void)
  * @cell:      Request issuing cell
  * @is_write:  True if write access
  * @addr:      Address accessed
- * @value:     Value to write (for write operations only)
+ * @value:     Pointer to value for reading/writing
  *
  * Return: 1 if handled successfully, 0 if unhandled, -1 on access error
  */
-int pci_mmio_access_handler(struct registers *guest_regs,
-                           const struct cell *cell, bool is_write,
-                           u64 addr, u32 reg)
+int pci_mmio_access_handler(const struct cell *cell, bool is_write,
+                           u64 addr, u32 *value)
 {
        const struct jailhouse_pci_device *device;
        u32 mmcfg_offset;
@@ -172,14 +172,12 @@ int pci_mmio_access_handler(struct registers *guest_regs,
                        if (pci_cfg_write_allowed(device->type,
                                                  (reg_num - reg_bias),
                                                  reg_bias, 4))
-                               *(volatile u32 *)(pci_space + mmcfg_offset) =
-                                       ((u64 *)guest_regs)[reg];
+                               mmio_write32(pci_space + mmcfg_offset, *value);
        } else
                if (device)
-                       ((u64 *)guest_regs)[reg] =
-                               *(volatile u32 *)(pci_space + mmcfg_offset);
+                       *value = mmio_read32(pci_space + mmcfg_offset);
                else
-                       ((u64 *)guest_regs)[reg] = BYTE_MASK(4);
+                       *value = -1;
 
        return 1;
 }