By adding pio_i8042_allowed boolean flag to arch cell fields.

With this, we don't need to directly access the pio_bitmap in i8042.c. This
does not only simplify (and speed up) the decision, it will also be helpful in
future patches.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 hypervisor/arch/x86/i8042.c            | 6 +-----
 hypervisor/arch/x86/include/asm/cell.h | 2 ++
 hypervisor/arch/x86/vcpu.c             | 8 +++++++-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/hypervisor/arch/x86/i8042.c b/hypervisor/arch/x86/i8042.c
index a7d7f19a..d98b6903 100644
--- a/hypervisor/arch/x86/i8042.c
+++ b/hypervisor/arch/x86/i8042.c
@@ -21,13 +21,9 @@
 int i8042_access_handler(u16 port, bool dir_in, unsigned int size)
 {
        union registers *guest_regs = &this_cpu_data()->guest_regs;
-       const struct jailhouse_cell_desc *config = this_cell()->config;
-       const u8 *pio_bitmap = jailhouse_cell_pio_bitmap(config);
        u8 val;
 
-       if (port == I8042_CMD_REG &&
-           config->pio_bitmap_size >= (I8042_CMD_REG + 7) / 8 &&
-           !(pio_bitmap[I8042_CMD_REG / 8] & (1 << (I8042_CMD_REG % 8)))) {
+       if (port == I8042_CMD_REG && this_cell()->arch.pio_i8042_allowed) {
                if (size != 1)
                        goto invalid_access;
                if (dir_in) {
diff --git a/hypervisor/arch/x86/include/asm/cell.h 
b/hypervisor/arch/x86/include/asm/cell.h
index 71bd9976..33697498 100644
--- a/hypervisor/arch/x86/include/asm/cell.h
+++ b/hypervisor/arch/x86/include/asm/cell.h
@@ -26,6 +26,8 @@ struct arch_cell {
        /** Buffer for the EPT/NPT root-level page table. */
        u8 __attribute__((aligned(PAGE_SIZE))) root_table_page[PAGE_SIZE];
 
+       bool pio_i8042_allowed;
+
        /* Intel: PIO access bitmap.
         * AMD: I/O Permissions Map. */
        u8 *io_bitmap;
diff --git a/hypervisor/arch/x86/vcpu.c b/hypervisor/arch/x86/vcpu.c
index 8588d399..9caba92f 100644
--- a/hypervisor/arch/x86/vcpu.c
+++ b/hypervisor/arch/x86/vcpu.c
@@ -114,9 +114,15 @@ int vcpu_cell_init(struct cell *cell)
                        cell_iobm.size : pio_bitmap_size;
        memcpy(cell_iobm.data, pio_bitmap, size);
 
-       /* moderate access to i8042 command register */
+       /* always intercept access to i8042 command register */
        cell_iobm.data[I8042_CMD_REG / 8] |= 1 << (I8042_CMD_REG % 8);
 
+       /* but moderate only if the config allows i8042 access */
+       cell->arch.pio_i8042_allowed =
+               pio_bitmap_size >= (I8042_CMD_REG + 7) / 8 ?
+               !(pio_bitmap[I8042_CMD_REG / 8] & (1 << (I8042_CMD_REG % 8))) :
+               false;
+
        if (cell != &root_cell) {
                /*
                 * Shrink PIO access of root cell corresponding to new cell's
-- 
2.22.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190713181037.4358-9-ralf.ramsauer%40oth-regensburg.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to