diff --git a/examples/simple/vmm.c b/examples/simple/vmm.c index 7fabc883..bb0fa4a8 100644 --- a/examples/simple/vmm.c +++ b/examples/simple/vmm.c @@ -76,7 +76,8 @@ extern char _guest_initrd_image_end[]; /* Microkit will set this variable to the start of the guest RAM memory region. */ uintptr_t guest_ram_vaddr; -static void serial_ack(size_t vcpu_id, int irq, void *cookie) { +static void serial_ack(size_t vcpu_id, int irq, void *cookie) +{ /* * For now we by default simply ack the serial IRQ, we have not * come across a case yet where more than this needs to be done. @@ -84,7 +85,8 @@ static void serial_ack(size_t vcpu_id, int irq, void *cookie) { microkit_irq_ack(SERIAL_IRQ_CH); } -void init(void) { +void init(void) +{ /* Initialise the VMM, the VCPU(s), and start the guest */ LOG_VMM("starting \"%s\"\n", microkit_name); /* Place all the binaries in the right locations before starting the guest */ @@ -92,15 +94,15 @@ void init(void) { size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image; size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image; uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr, - (uintptr_t) _guest_kernel_image, - kernel_size, - (uintptr_t) _guest_dtb_image, - GUEST_DTB_VADDR, - dtb_size, - (uintptr_t) _guest_initrd_image, - GUEST_INIT_RAM_DISK_VADDR, - initrd_size - ); + (uintptr_t) _guest_kernel_image, + kernel_size, + (uintptr_t) _guest_dtb_image, + GUEST_DTB_VADDR, + dtb_size, + (uintptr_t) _guest_initrd_image, + GUEST_INIT_RAM_DISK_VADDR, + initrd_size + ); if (!kernel_pc) { LOG_VMM_ERR("Failed to initialise guest images\n"); return; @@ -118,17 +120,18 @@ void init(void) { guest_start(kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR); } -void notified(microkit_channel ch) { +void notified(microkit_channel ch) +{ switch (ch) { - case SERIAL_IRQ_CH: { - bool success = virq_inject(SERIAL_IRQ); - if (!success) { - LOG_VMM_ERR("IRQ %d dropped\n", SERIAL_IRQ); - } - break; + case SERIAL_IRQ_CH: { + bool success = virq_inject(SERIAL_IRQ); + if (!success) { + LOG_VMM_ERR("IRQ %d dropped\n", SERIAL_IRQ); } - default: - printf("Unexpected channel, ch: 0x%lx\n", ch); + break; + } + default: + printf("Unexpected channel, ch: 0x%lx\n", ch); } } @@ -137,7 +140,8 @@ void notified(microkit_channel ch) { * Whenever our guest causes an exception, it gets delivered to this entry point for * the VMM to handle. */ -seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) { +seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) +{ bool success = fault_handle(child, msginfo); if (success) { /* Now that we have handled the fault successfully, we reply to it so diff --git a/examples/virtio-snd/client_vmm.c b/examples/virtio-snd/client_vmm.c index 95f4b2cb..ca844501 100644 --- a/examples/virtio-snd/client_vmm.c +++ b/examples/virtio-snd/client_vmm.c @@ -72,7 +72,8 @@ static struct virtio_snd_device virtio_sound; uintptr_t kernel_pc = 0; -void init(void) { +void init(void) +{ /* Initialise the VMM, the VCPU(s), and start the guest */ LOG_VMM("starting \"%s\"\n", microkit_name); /* Place all the binaries in the right locations before starting the guest */ @@ -80,15 +81,15 @@ void init(void) { size_t dtb_size = _guest_dtb_image_end - _guest_dtb_image; size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image; kernel_pc = linux_setup_images(guest_ram_vaddr, - (uintptr_t) _guest_kernel_image, - kernel_size, - (uintptr_t) _guest_dtb_image, - GUEST_DTB_VADDR, - dtb_size, - (uintptr_t) _guest_initrd_image, - GUEST_INIT_RAM_DISK_VADDR, - initrd_size - ); + (uintptr_t) _guest_kernel_image, + kernel_size, + (uintptr_t) _guest_dtb_image, + GUEST_DTB_VADDR, + dtb_size, + (uintptr_t) _guest_initrd_image, + GUEST_INIT_RAM_DISK_VADDR, + initrd_size + ); if (!kernel_pc) { LOG_VMM_ERR("Failed to initialise guest images\n"); return; @@ -103,15 +104,16 @@ void init(void) { /* Initialise our sDDF ring buffers for the serial device */ serial_queue_handle_t serial_rxq, serial_txq; - serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data); + serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, + serial_tx_data); /* Initialise virtIO console device */ success = virtio_mmio_console_init(&virtio_console, - VIRTIO_CONSOLE_BASE, - VIRTIO_CONSOLE_SIZE, - VIRTIO_CONSOLE_IRQ, - &serial_rxq, &serial_txq, - SERIAL_VIRT_TX_CH); + VIRTIO_CONSOLE_BASE, + VIRTIO_CONSOLE_SIZE, + VIRTIO_CONSOLE_IRQ, + &serial_rxq, &serial_txq, + SERIAL_VIRT_TX_CH); assert(success); assert(sound_cmd_req); @@ -138,37 +140,39 @@ void init(void) { while (!ATOMIC_LOAD(&shared_state->ready, __ATOMIC_ACQUIRE)); success = virtio_mmio_snd_init(&virtio_sound, - VIRTIO_SOUND_BASE, - VIRTIO_SOUND_SIZE, - VIRTIO_SOUND_IRQ, - shared_state, - &sound_queues, - sound_data, - SOUND_DRIVER_CH); + VIRTIO_SOUND_BASE, + VIRTIO_SOUND_SIZE, + VIRTIO_SOUND_IRQ, + shared_state, + &sound_queues, + sound_data, + SOUND_DRIVER_CH); assert(success); success = guest_start(GUEST_BOOT_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR); assert(success); } -void notified(microkit_channel ch) { +void notified(microkit_channel ch) +{ switch (ch) { - case SERIAL_VIRT_RX_CH: { - /* We have received an event from the serial virtualiser, so we - * call the virtIO console handling */ - virtio_console_handle_rx(&virtio_console); - break; - } - case SOUND_DRIVER_CH: { - virtio_snd_notified(&virtio_sound); - break; - } - default: - printf("Unexpected channel, ch: 0x%lx\n", ch); + case SERIAL_VIRT_RX_CH: { + /* We have received an event from the serial virtualiser, so we + * call the virtIO console handling */ + virtio_console_handle_rx(&virtio_console); + break; + } + case SOUND_DRIVER_CH: { + virtio_snd_notified(&virtio_sound); + break; + } + default: + printf("Unexpected channel, ch: 0x%lx\n", ch); } } -seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) { +seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) +{ bool success = fault_handle(child, msginfo); if (success) { /* Now that we have handled the fault successfully, we reply to it so diff --git a/examples/virtio-snd/snd_driver_vmm.c b/examples/virtio-snd/snd_driver_vmm.c index 46fc3468..73441396 100644 --- a/examples/virtio-snd/snd_driver_vmm.c +++ b/examples/virtio-snd/snd_driver_vmm.c @@ -72,12 +72,14 @@ uintptr_t sound_data_paddr; static struct virtio_console_device virtio_console; -static void passthrough_device_ack(size_t vcpu_id, int irq, void *cookie) { +static void passthrough_device_ack(size_t vcpu_id, int irq, void *cookie) +{ microkit_channel irq_ch = (microkit_channel)(int64_t)cookie; microkit_irq_ack(irq_ch); } -static void register_passthrough_irq(int irq, microkit_channel irq_ch) { +static void register_passthrough_irq(int irq, microkit_channel irq_ch) +{ LOG_VMM("Register passthrough IRQ %d (channel: 0x%lx)\n", irq, irq_ch); assert(irq_ch < MAX_IRQ_CH); passthrough_irq_map[irq_ch] = irq; @@ -90,17 +92,19 @@ static void register_passthrough_irq(int irq, microkit_channel irq_ch) { } static bool uio_sound_fault_handler(size_t vcpu_id, - size_t offset, - size_t fsr, - seL4_UserContext *regs, - void *data) { + size_t offset, + size_t fsr, + seL4_UserContext *regs, + void *data) +{ microkit_notify(SND_CLIENT_CH); return true; } static void uio_sound_virq_ack(size_t vcpu_id, int irq, void *cookie) {} -void init(void) { +void init(void) +{ /* Initialise the VMM, the VCPU(s), and start the guest */ LOG_VMM("starting \"%s\"\n", microkit_name); /* Place all the binaries in the right locations before starting the guest */ @@ -109,15 +113,15 @@ void init(void) { size_t initrd_size = _guest_initrd_image_end - _guest_initrd_image; uintptr_t kernel_pc = linux_setup_images(guest_ram_vaddr, - (uintptr_t) _guest_kernel_image, - kernel_size, - (uintptr_t) _guest_dtb_image, - GUEST_DTB_VADDR, - dtb_size, - (uintptr_t) _guest_initrd_image, - GUEST_INIT_RAM_DISK_VADDR, - initrd_size - ); + (uintptr_t) _guest_kernel_image, + kernel_size, + (uintptr_t) _guest_dtb_image, + GUEST_DTB_VADDR, + dtb_size, + (uintptr_t) _guest_initrd_image, + GUEST_INIT_RAM_DISK_VADDR, + initrd_size + ); if (!kernel_pc) { LOG_VMM_ERR("Failed to initialise guest images\n"); return; @@ -137,15 +141,16 @@ void init(void) { /* Initialise our sDDF ring buffers for the serial device */ serial_queue_handle_t serial_rxq, serial_txq; - serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data); + serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, + serial_tx_data); /* Initialise virtIO console device */ success = virtio_mmio_console_init(&virtio_console, - VIRTIO_CONSOLE_BASE, - VIRTIO_CONSOLE_SIZE, - VIRTIO_CONSOLE_IRQ, - &serial_rxq, &serial_txq, - SERIAL_TX_CH); + VIRTIO_CONSOLE_BASE, + VIRTIO_CONSOLE_SIZE, + VIRTIO_CONSOLE_IRQ, + &serial_rxq, &serial_txq, + SERIAL_TX_CH); assert(success); success = virq_register(GUEST_BOOT_VCPU_ID, UIO_SND_IRQ, &uio_sound_virq_ack, NULL); @@ -175,7 +180,8 @@ void init(void) { guest_start(GUEST_BOOT_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR); } -void notified(microkit_channel ch) { +void notified(microkit_channel ch) +{ bool success; switch (ch) { @@ -202,7 +208,8 @@ void notified(microkit_channel ch) { } } -seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) { +seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) +{ bool success = fault_handle(child, msginfo); if (success) { /* Now that we have handled the fault successfully, we reply to it so diff --git a/examples/virtio/blk_driver_vmm.c b/examples/virtio/blk_driver_vmm.c index b74eb229..8baa6f9a 100644 --- a/examples/virtio/blk_driver_vmm.c +++ b/examples/virtio/blk_driver_vmm.c @@ -108,16 +108,16 @@ void init(void) /* Initialise our sDDF ring buffers for the serial device */ serial_queue_handle_t serial_rxq, serial_txq; - serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data); - + serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, + serial_tx_data); /* Initialise virtIO console device */ success = virtio_mmio_console_init(&virtio_console, - VIRTIO_CONSOLE_BASE, - VIRTIO_CONSOLE_SIZE, - VIRTIO_CONSOLE_IRQ, - &serial_rxq, &serial_txq, - SERIAL_VIRT_TX_CH); + VIRTIO_CONSOLE_BASE, + VIRTIO_CONSOLE_SIZE, + VIRTIO_CONSOLE_IRQ, + &serial_rxq, &serial_txq, + SERIAL_VIRT_TX_CH); assert(success); /* Register the UIO IRQ */ @@ -162,7 +162,8 @@ void notified(microkit_channel ch) } } -seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) { +seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) +{ bool success = fault_handle(child, msginfo); if (success) { /* Now that we have handled the fault successfully, we reply to it so diff --git a/examples/virtio/client_vmm.c b/examples/virtio/client_vmm.c index afe85ad6..c65542b9 100644 --- a/examples/virtio/client_vmm.c +++ b/examples/virtio/client_vmm.c @@ -41,7 +41,6 @@ extern char _guest_initrd_image_end[]; /* Microkit will set this variable to the start of the guest RAM memory region. */ uintptr_t guest_ram_vaddr; - /* Virtio Console */ #define SERIAL_VIRT_TX_CH 1 #define SERIAL_VIRT_RX_CH 2 @@ -111,15 +110,16 @@ void init(void) /* Initialise our sDDF ring buffers for the serial device */ serial_queue_handle_t serial_rxq, serial_txq; - serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, serial_tx_data); + serial_cli_queue_init_sys(microkit_name, &serial_rxq, serial_rx_queue, serial_rx_data, &serial_txq, serial_tx_queue, + serial_tx_data); /* Initialise virtIO console device */ success = virtio_mmio_console_init(&virtio_console, - VIRTIO_CONSOLE_BASE, - VIRTIO_CONSOLE_SIZE, - VIRTIO_CONSOLE_IRQ, - &serial_rxq, &serial_txq, - SERIAL_VIRT_TX_CH); + VIRTIO_CONSOLE_BASE, + VIRTIO_CONSOLE_SIZE, + VIRTIO_CONSOLE_IRQ, + &serial_rxq, &serial_txq, + SERIAL_VIRT_TX_CH); /* virtIO block */ /* Initialise our sDDF queues for the block device */ @@ -131,12 +131,12 @@ void init(void) /* Initialise virtIO block device */ success = virtio_mmio_blk_init(&virtio_blk, - VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ, - blk_data, - BLK_DATA_SIZE, - storage_info, - &blk_queue_h, - BLK_CH); + VIRTIO_BLK_BASE, VIRTIO_BLK_SIZE, VIRTIO_BLK_IRQ, + blk_data, + BLK_DATA_SIZE, + storage_info, + &blk_queue_h, + BLK_CH); assert(success); /* Finally start the guest */ @@ -161,7 +161,8 @@ void notified(microkit_channel ch) } } -seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) { +seL4_Bool fault(microkit_child child, microkit_msginfo msginfo, microkit_msginfo *reply_msginfo) +{ bool success = fault_handle(child, msginfo); if (success) { /* Now that we have handled the fault successfully, we reply to it so diff --git a/include/libvmm/arch/aarch64/vgic/vdist.h b/include/libvmm/arch/aarch64/vgic/vdist.h index 71bd5f19..5c253c9a 100644 --- a/include/libvmm/arch/aarch64/vgic/vdist.h +++ b/include/libvmm/arch/aarch64/vgic/vdist.h @@ -247,7 +247,8 @@ static void vgic_dist_clr_pending_irq(struct gic_dist_map *dist, size_t vcpu_id, // @ivanv } -static bool vgic_handle_fault_dist_read(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, seL4_UserContext *regs) +static bool vgic_handle_fault_dist_read(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, + seL4_UserContext *regs) { struct gic_dist_map *gic_dist = vgic_get_dist(vgic->registers); uint32_t reg = 0; @@ -359,7 +360,8 @@ static bool vgic_handle_fault_dist_read(size_t vcpu_id, vgic_t *vgic, uint64_t o case RANGE32(0xDE8, 0xEFC): /* Reserved [0xDE8 - 0xE00) */ /* GIC_DIST_NSACR [0xE00 - 0xF00) - Not supported */ - break; case RANGE32(GIC_DIST_SGIR, GIC_DIST_SGIR): + break; + case RANGE32(GIC_DIST_SGIR, GIC_DIST_SGIR): reg = gic_dist->sgir; break; case RANGE32(0xF04, 0xF0C): @@ -414,7 +416,8 @@ static inline void emulate_reg_write_access(seL4_UserContext *regs, uint64_t add *reg = fault_emulate(regs, *reg, addr, fsr, fault_get_data(regs, fsr)); } -static bool vgic_handle_fault_dist_write(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, seL4_UserContext *regs) +static bool vgic_handle_fault_dist_write(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, + seL4_UserContext *regs) { bool success = true; struct gic_dist_map *gic_dist = vgic_get_dist(vgic->registers); @@ -599,7 +602,7 @@ static bool vgic_handle_fault_dist_write(size_t vcpu_id, vgic_t *vgic, uint64_t #if defined(GIC_V3) // @ivanv: explain GICv3 specific stuff, and also don't use the hardcoded valuees case RANGE32(0x6100, 0x7F00): - // @ivanv revisit + // @ivanv revisit // data = fault_get_data(fault); // ZF_LOGF_IF(data, "bad dist: 0x%x 0x%x", offset, data); break; @@ -616,4 +619,3 @@ static bool vgic_handle_fault_dist_write(size_t vcpu_id, vgic_t *vgic, uint64_t return success; } - diff --git a/src/arch/aarch64/fault.c b/src/arch/aarch64/fault.c index 2362ac90..30e03ee2 100644 --- a/src/arch/aarch64/fault.c +++ b/src/arch/aarch64/fault.c @@ -22,7 +22,8 @@ // return !CPSR_IS_THUMB(regs->spsr); // } -bool fault_advance_vcpu(size_t vcpu_id, seL4_UserContext *regs) { +bool fault_advance_vcpu(size_t vcpu_id, seL4_UserContext *regs) +{ // For now we just ignore it and continue // Assume 32-bit instruction regs->pc += 4; @@ -32,15 +33,23 @@ bool fault_advance_vcpu(size_t vcpu_id, seL4_UserContext *regs) { return (err == seL4_NoError); } -char *fault_to_string(seL4_Word fault_label) { +char *fault_to_string(seL4_Word fault_label) +{ switch (fault_label) { - case seL4_Fault_VMFault: return "virtual memory"; - case seL4_Fault_UnknownSyscall: return "unknown syscall"; - case seL4_Fault_UserException: return "user exception"; - case seL4_Fault_VGICMaintenance: return "VGIC maintenance"; - case seL4_Fault_VCPUFault: return "VCPU"; - case seL4_Fault_VPPIEvent: return "VPPI event"; - default: return "unknown fault"; + case seL4_Fault_VMFault: + return "virtual memory"; + case seL4_Fault_UnknownSyscall: + return "unknown syscall"; + case seL4_Fault_UserException: + return "user exception"; + case seL4_Fault_VGICMaintenance: + return "VGIC maintenance"; + case seL4_Fault_VCPUFault: + return "VCPU"; + case seL4_Fault_VPPIEvent: + return "VPPI event"; + default: + return "unknown fault"; } } @@ -59,7 +68,7 @@ enum fault_width { static enum fault_width fault_get_width(uint64_t fsr) { if (HSR_IS_SYNDROME_VALID(fsr) && HSR_SYNDROME_WIDTH(fsr) <= WIDTH_DOUBLEWORD) { - return (enum fault_width) (HSR_SYNDROME_WIDTH(fsr)); + return (enum fault_width)(HSR_SYNDROME_WIDTH(fsr)); } else { LOG_VMM_ERR("Received invalid FSR: 0x%lx\n", fsr); // @ivanv: reviist @@ -74,26 +83,26 @@ uint64_t fault_get_data_mask(uint64_t addr, uint64_t fsr) { uint64_t mask = 0; switch (fault_get_width(fsr)) { - case WIDTH_BYTE: - mask = 0x000000ff; - assert(!(addr & 0x0)); - break; - case WIDTH_HALFWORD: - mask = 0x0000ffff; - assert(!(addr & 0x1)); - break; - case WIDTH_WORD: - mask = 0xffffffff; - assert(!(addr & 0x3)); - break; - case WIDTH_DOUBLEWORD: - mask = ~mask; - break; - default: - LOG_VMM_ERR("unknown width: 0x%lx, from FSR: 0x%lx, addr: 0x%lx\n", - fault_get_width(fsr), fsr, addr); - assert(0); - return 0; + case WIDTH_BYTE: + mask = 0x000000ff; + assert(!(addr & 0x0)); + break; + case WIDTH_HALFWORD: + mask = 0x0000ffff; + assert(!(addr & 0x1)); + break; + case WIDTH_WORD: + mask = 0xffffffff; + assert(!(addr & 0x3)); + break; + case WIDTH_DOUBLEWORD: + mask = ~mask; + break; + default: + LOG_VMM_ERR("unknown width: 0x%lx, from FSR: 0x%lx, addr: 0x%lx\n", + fault_get_width(fsr), fsr, addr); + assert(0); + return 0; } mask <<= (addr & 0x3) * 8; return mask; @@ -108,41 +117,73 @@ seL4_Word *decode_rt(size_t reg_idx, seL4_UserContext *regs) * encodes the Syndrome Register transfer. */ switch (reg_idx) { - case 0: return ®s->x0; - case 1: return ®s->x1; - case 2: return ®s->x2; - case 3: return ®s->x3; - case 4: return ®s->x4; - case 5: return ®s->x5; - case 6: return ®s->x6; - case 7: return ®s->x7; - case 8: return ®s->x8; - case 9: return ®s->x9; - case 10: return ®s->x10; - case 11: return ®s->x11; - case 12: return ®s->x12; - case 13: return ®s->x13; - case 14: return ®s->x14; - case 15: return ®s->x15; - case 16: return ®s->x16; - case 17: return ®s->x17; - case 18: return ®s->x18; - case 19: return ®s->x19; - case 20: return ®s->x20; - case 21: return ®s->x21; - case 22: return ®s->x22; - case 23: return ®s->x23; - case 24: return ®s->x24; - case 25: return ®s->x25; - case 26: return ®s->x26; - case 27: return ®s->x27; - case 28: return ®s->x28; - case 29: return ®s->x29; - case 30: return ®s->x30; - case 31: return &wzr; - default: - LOG_VMM_ERR("failed to decode Rt, attempted to access invalid register index 0x%lx\n", reg_idx); - return NULL; + case 0: + return ®s->x0; + case 1: + return ®s->x1; + case 2: + return ®s->x2; + case 3: + return ®s->x3; + case 4: + return ®s->x4; + case 5: + return ®s->x5; + case 6: + return ®s->x6; + case 7: + return ®s->x7; + case 8: + return ®s->x8; + case 9: + return ®s->x9; + case 10: + return ®s->x10; + case 11: + return ®s->x11; + case 12: + return ®s->x12; + case 13: + return ®s->x13; + case 14: + return ®s->x14; + case 15: + return ®s->x15; + case 16: + return ®s->x16; + case 17: + return ®s->x17; + case 18: + return ®s->x18; + case 19: + return ®s->x19; + case 20: + return ®s->x20; + case 21: + return ®s->x21; + case 22: + return ®s->x22; + case 23: + return ®s->x23; + case 24: + return ®s->x24; + case 25: + return ®s->x25; + case 26: + return ®s->x26; + case 27: + return ®s->x27; + case 28: + return ®s->x28; + case 29: + return ®s->x29; + case 30: + return ®s->x30; + case 31: + return &wzr; + default: + LOG_VMM_ERR("failed to decode Rt, attempted to access invalid register index 0x%lx\n", reg_idx); + return NULL; } } @@ -195,7 +236,8 @@ uint64_t fault_emulate(seL4_UserContext *regs, uint64_t reg, uint64_t addr, uint } } -void fault_emulate_write(seL4_UserContext *regs, size_t addr, size_t fsr, size_t reg_val) { +void fault_emulate_write(seL4_UserContext *regs, size_t addr, size_t fsr, size_t reg_val) +{ // @ivanv: audit /* Get register opearand */ int rt = get_rt(fsr); @@ -219,14 +261,14 @@ bool fault_handle_vcpu_exception(size_t vcpu_id) uint32_t hsr = microkit_mr_get(seL4_VCPUFault_HSR); uint64_t hsr_ec_class = HSR_EXCEPTION_CLASS(hsr); switch (hsr_ec_class) { - case HSR_SMC_64_EXCEPTION: - return handle_smc(vcpu_id, hsr); - case HSR_WFx_EXCEPTION: - // If we get a WFI exception, we just do nothing in the VMM. - return true; - default: - LOG_VMM_ERR("unknown SMC exception, EC class: 0x%lx, HSR: 0x%lx\n", hsr_ec_class, hsr); - return false; + case HSR_SMC_64_EXCEPTION: + return handle_smc(vcpu_id, hsr); + case HSR_WFx_EXCEPTION: + // If we get a WFI exception, we just do nothing in the VMM. + return true; + default: + LOG_VMM_ERR("unknown SMC exception, EC class: 0x%lx, HSR: 0x%lx\n", hsr_ec_class, hsr); + return false; } } @@ -270,17 +312,17 @@ bool fault_handle_unknown_syscall(size_t vcpu_id) LOG_VMM("Received syscall 0x%lx\n", syscall); switch (syscall) { - case SYSCALL_PA_TO_IPA: - // @ivanv: why do we not do anything here? - // @ivanv, how to get the physical address to translate? - LOG_VMM("Received PA translation syscall\n"); - break; - case SYSCALL_NOP: - LOG_VMM("Received NOP syscall\n"); - break; - default: - LOG_VMM_ERR("Unknown syscall: syscall number: 0x%lx, PC: 0x%lx\n", syscall, fault_ip); - return false; + case SYSCALL_PA_TO_IPA: + // @ivanv: why do we not do anything here? + // @ivanv, how to get the physical address to translate? + LOG_VMM("Received PA translation syscall\n"); + break; + case SYSCALL_NOP: + LOG_VMM("Received NOP syscall\n"); + break; + default: + LOG_VMM_ERR("Unknown syscall: syscall number: 0x%lx, PC: 0x%lx\n", syscall, fault_ip); + return false; } seL4_UserContext regs; @@ -304,7 +346,8 @@ struct vm_exception_handler { struct vm_exception_handler registered_vm_exception_handlers[MAX_VM_EXCEPTION_HANDLERS]; size_t vm_exception_handler_index = 0; -bool fault_register_vm_exception_handler(uintptr_t base, size_t size, vm_exception_handler_t callback, void *data) { +bool fault_register_vm_exception_handler(uintptr_t base, size_t size, vm_exception_handler_t callback, void *data) +{ // @ivanv audit necessary here since this code was written very quickly. Other things to check such // as the region of memory is not overlapping with other regions, also should have GIC_DIST regions // use this API. @@ -327,7 +370,8 @@ bool fault_register_vm_exception_handler(uintptr_t base, size_t size, vm_excepti return true; } -static bool fault_handle_registered_vm_exceptions(size_t vcpu_id, uintptr_t addr, size_t fsr, seL4_UserContext *regs) { +static bool fault_handle_registered_vm_exceptions(size_t vcpu_id, uintptr_t addr, size_t fsr, seL4_UserContext *regs) +{ for (int i = 0; i < MAX_VM_EXCEPTION_HANDLERS; i++) { uintptr_t base = registered_vm_exception_handlers[i].base; uintptr_t end = registered_vm_exception_handlers[i].end; @@ -337,7 +381,8 @@ static bool fault_handle_registered_vm_exceptions(size_t vcpu_id, uintptr_t addr bool success = callback(vcpu_id, addr - base, fsr, regs, data); if (!success) { // @ivanv: improve error message - LOG_VMM_ERR("registered virtual memory exception handler for region [0x%lx..0x%lx) at address 0x%lx failed\n", base, end, addr); + LOG_VMM_ERR("registered virtual memory exception handler for region [0x%lx..0x%lx) at address 0x%lx failed\n", base, + end, addr); } /* Whether or not the callback actually successfully handled the * exception, we return true to say that we at least found a handler @@ -371,7 +416,7 @@ bool fault_handle_vm_exception(size_t vcpu_id) size_t is_prefetch = seL4_GetMR(seL4_VMFault_PrefetchFault); bool is_write = fault_is_write(fsr); LOG_VMM_ERR("unexpected memory fault on address: 0x%lx, FSR: 0x%lx, IP: 0x%lx, is_prefetch: %s, is_write: %s\n", - addr, fsr, ip, is_prefetch ? "true" : "false", is_write ? "true" : "false"); + addr, fsr, ip, is_prefetch ? "true" : "false", is_write ? "true" : "false"); tcb_print_regs(vcpu_id); vcpu_print_regs(vcpu_id); } else { @@ -381,36 +426,37 @@ bool fault_handle_vm_exception(size_t vcpu_id) return success; } -bool fault_handle(size_t vcpu_id, microkit_msginfo msginfo) { +bool fault_handle(size_t vcpu_id, microkit_msginfo msginfo) +{ size_t label = microkit_msginfo_get_label(msginfo); bool success = false; switch (label) { - case seL4_Fault_VMFault: - success = fault_handle_vm_exception(vcpu_id); - break; - case seL4_Fault_UnknownSyscall: - success = fault_handle_unknown_syscall(vcpu_id); - break; - case seL4_Fault_UserException: - success = fault_handle_user_exception(vcpu_id); - break; - case seL4_Fault_VGICMaintenance: - success = vgic_handle_fault_maintenance(vcpu_id); - break; - case seL4_Fault_VCPUFault: - success = fault_handle_vcpu_exception(vcpu_id); - break; - case seL4_Fault_VPPIEvent: - success = fault_handle_vppi_event(vcpu_id); - break; - default: - /* We have reached a genuinely unexpected case, stop the guest. */ - LOG_VMM_ERR("unknown fault label 0x%lx, stopping guest with ID 0x%lx\n", label, vcpu_id); - microkit_vcpu_stop(vcpu_id); - /* Dump the TCB and vCPU registers to hopefully get information as - * to what has gone wrong. */ - tcb_print_regs(vcpu_id); - vcpu_print_regs(vcpu_id); + case seL4_Fault_VMFault: + success = fault_handle_vm_exception(vcpu_id); + break; + case seL4_Fault_UnknownSyscall: + success = fault_handle_unknown_syscall(vcpu_id); + break; + case seL4_Fault_UserException: + success = fault_handle_user_exception(vcpu_id); + break; + case seL4_Fault_VGICMaintenance: + success = vgic_handle_fault_maintenance(vcpu_id); + break; + case seL4_Fault_VCPUFault: + success = fault_handle_vcpu_exception(vcpu_id); + break; + case seL4_Fault_VPPIEvent: + success = fault_handle_vppi_event(vcpu_id); + break; + default: + /* We have reached a genuinely unexpected case, stop the guest. */ + LOG_VMM_ERR("unknown fault label 0x%lx, stopping guest with ID 0x%lx\n", label, vcpu_id); + microkit_vcpu_stop(vcpu_id); + /* Dump the TCB and vCPU registers to hopefully get information as + * to what has gone wrong. */ + tcb_print_regs(vcpu_id); + vcpu_print_regs(vcpu_id); } if (!success) { diff --git a/src/arch/aarch64/psci.c b/src/arch/aarch64/psci.c index 3f9577b5..e4e4d832 100644 --- a/src/arch/aarch64/psci.c +++ b/src/arch/aarch64/psci.c @@ -38,97 +38,98 @@ bool handle_psci(size_t vcpu_id, seL4_UserContext *regs, uint64_t fn_number, uin // @ivanv: write a note about what convention we assume, should we be checking // the convention? switch (fn_number) { - case PSCI_VERSION: { - /* We support PSCI version 1.2 */ - uint32_t version = PSCI_MAJOR_VERSION(1) | PSCI_MINOR_VERSION(2); - smc_set_return_value(regs, version); - break; - } - case PSCI_CPU_ON: { - size_t target_vcpu = smc_get_arg(regs, 1); - if (target_vcpu < GUEST_NUM_VCPUS && target_vcpu >= 0) { - /* The guest has given a valid target vCPU */ - if (vcpu_is_on(target_vcpu)) { - smc_set_return_value(regs, PSCI_ALREADY_ON); - } else { - /* We have a valid target vCPU, that is not started yet. So let's turn it on. */ - uintptr_t vcpu_entry_point = smc_get_arg(regs, 2); - size_t context_id = smc_get_arg(regs, 3); + case PSCI_VERSION: { + /* We support PSCI version 1.2 */ + uint32_t version = PSCI_MAJOR_VERSION(1) | PSCI_MINOR_VERSION(2); + smc_set_return_value(regs, version); + break; + } + case PSCI_CPU_ON: { + size_t target_vcpu = smc_get_arg(regs, 1); + if (target_vcpu < GUEST_NUM_VCPUS && target_vcpu >= 0) { + /* The guest has given a valid target vCPU */ + if (vcpu_is_on(target_vcpu)) { + smc_set_return_value(regs, PSCI_ALREADY_ON); + } else { + /* We have a valid target vCPU, that is not started yet. So let's turn it on. */ + uintptr_t vcpu_entry_point = smc_get_arg(regs, 2); + size_t context_id = smc_get_arg(regs, 3); - seL4_UserContext vcpu_regs = {0}; - vcpu_regs.x0 = context_id; - vcpu_regs.spsr = 5; // PMODE_EL1h - vcpu_regs.pc = vcpu_entry_point; + seL4_UserContext vcpu_regs = {0}; + vcpu_regs.x0 = context_id; + vcpu_regs.spsr = 5; // PMODE_EL1h + vcpu_regs.pc = vcpu_entry_point; - microkit_vcpu_arm_write_reg(target_vcpu, seL4_VCPUReg_VMPIDR_EL2, target_vcpu); + microkit_vcpu_arm_write_reg(target_vcpu, seL4_VCPUReg_VMPIDR_EL2, target_vcpu); - seL4_Error err = seL4_TCB_WriteRegisters( - BASE_VM_TCB_CAP + target_vcpu, - false, // We'll explcitly start the guest below rather than in this call - 0, // No flags - SEL4_USER_CONTEXT_SIZE, - &vcpu_regs - ); - assert(err == seL4_NoError); - if (err != seL4_NoError) { - return err; - } + seL4_Error err = seL4_TCB_WriteRegisters( + BASE_VM_TCB_CAP + target_vcpu, + false, // We'll explcitly start the guest below rather than in this call + 0, // No flags + SEL4_USER_CONTEXT_SIZE, + &vcpu_regs + ); + assert(err == seL4_NoError); + if (err != seL4_NoError) { + return err; + } - /* Now that we have started the vCPU, we can set is as turned on. */ - vcpu_set_on(target_vcpu, true); + /* Now that we have started the vCPU, we can set is as turned on. */ + vcpu_set_on(target_vcpu, true); - LOG_VMM("starting guest vCPU (0x%lx) with entry point 0x%lx, context ID: 0x%lx\n", target_vcpu, vcpu_regs.pc, context_id); - microkit_vcpu_restart(target_vcpu, vcpu_regs.pc); + LOG_VMM("starting guest vCPU (0x%lx) with entry point 0x%lx, context ID: 0x%lx\n", target_vcpu, vcpu_regs.pc, + context_id); + microkit_vcpu_restart(target_vcpu, vcpu_regs.pc); - smc_set_return_value(regs, PSCI_SUCCESS); - } - } else { - // The guest has requested to turn on a virtual CPU that does - // not exist. - smc_set_return_value(regs, PSCI_INVALID_PARAMETERS); + smc_set_return_value(regs, PSCI_SUCCESS); } - break; + } else { + // The guest has requested to turn on a virtual CPU that does + // not exist. + smc_set_return_value(regs, PSCI_INVALID_PARAMETERS); } - case PSCI_MIGRATE_INFO_TYPE: - /* - * There are multiple possible return values for MIGRATE_INFO_TYPE. - * In this case returning 2 will tell the guest that this is a - * system that does not use a "Trusted OS" as the PSCI - * specification says. - */ - smc_set_return_value(regs, 2); - break; - case PSCI_FEATURES: - // @ivanv: seems weird that we just return nothing here. - smc_set_return_value(regs, PSCI_NOT_SUPPORTED); - break; - case PSCI_SYSTEM_RESET: { - // @refactor come back to - // bool success = guest_restart(); - // if (!success) { - // LOG_VMM_ERR("Failed to restart guest\n"); - // smc_set_return_value(regs, PSCI_INTERNAL_FAILURE); - // } else { - - // * If we've successfully restarted the guest, all we want to do - // * is reply to the fault that caused us to handle the PSCI call - // * so that the guest can continue executing. We do not need to - // * advance the vCPU program counter as we typically do when - // * handling a fault since the correct PC has been set when we - // * call guest_restart(). - - // return true; - // } - break; - } - case PSCI_SYSTEM_OFF: - // @refactor, is it guaranteed that the CPU that does the vCPU request - // is the boot vcpu? - guest_stop(); - return true; - default: - LOG_VMM_ERR("Unhandled PSCI function ID 0x%lx\n", fn_number); - return false; + break; + } + case PSCI_MIGRATE_INFO_TYPE: + /* + * There are multiple possible return values for MIGRATE_INFO_TYPE. + * In this case returning 2 will tell the guest that this is a + * system that does not use a "Trusted OS" as the PSCI + * specification says. + */ + smc_set_return_value(regs, 2); + break; + case PSCI_FEATURES: + // @ivanv: seems weird that we just return nothing here. + smc_set_return_value(regs, PSCI_NOT_SUPPORTED); + break; + case PSCI_SYSTEM_RESET: { + // @refactor come back to + // bool success = guest_restart(); + // if (!success) { + // LOG_VMM_ERR("Failed to restart guest\n"); + // smc_set_return_value(regs, PSCI_INTERNAL_FAILURE); + // } else { + + // * If we've successfully restarted the guest, all we want to do + // * is reply to the fault that caused us to handle the PSCI call + // * so that the guest can continue executing. We do not need to + // * advance the vCPU program counter as we typically do when + // * handling a fault since the correct PC has been set when we + // * call guest_restart(). + + // return true; + // } + break; + } + case PSCI_SYSTEM_OFF: + // @refactor, is it guaranteed that the CPU that does the vCPU request + // is the boot vcpu? + guest_stop(); + return true; + default: + LOG_VMM_ERR("Unhandled PSCI function ID 0x%lx\n", fn_number); + return false; } bool success = fault_advance_vcpu(vcpu_id, regs); diff --git a/src/arch/aarch64/smc.c b/src/arch/aarch64/smc.c index cd305d5b..a0c8ad6f 100644 --- a/src/arch/aarch64/smc.c +++ b/src/arch/aarch64/smc.c @@ -63,30 +63,48 @@ inline void smc_set_return_value(seL4_UserContext *u, uint64_t val) uint64_t smc_get_arg(seL4_UserContext *u, uint64_t arg) { switch (arg) { - case 1: return u->x1; - case 2: return u->x2; - case 3: return u->x3; - case 4: return u->x4; - case 5: return u->x5; - case 6: return u->x6; - default: - LOG_VMM_ERR("trying to get SMC arg: 0x%lx, SMC only has 6 argument registers\n", arg); - // @ivanv: come back to this - return 0; + case 1: + return u->x1; + case 2: + return u->x2; + case 3: + return u->x3; + case 4: + return u->x4; + case 5: + return u->x5; + case 6: + return u->x6; + default: + LOG_VMM_ERR("trying to get SMC arg: 0x%lx, SMC only has 6 argument registers\n", arg); + // @ivanv: come back to this + return 0; } } static void smc_set_arg(seL4_UserContext *u, size_t arg, size_t val) { switch (arg) { - case 1: u->x1 = val; break; - case 2: u->x2 = val; break; - case 3: u->x3 = val; break; - case 4: u->x4 = val; break; - case 5: u->x5 = val; break; - case 6: u->x6 = val; break; - default: - LOG_VMM_ERR("trying to set SMC arg: 0x%lx, with val: 0x%lx, SMC only has 6 argument registers\n", arg, val); + case 1: + u->x1 = val; + break; + case 2: + u->x2 = val; + break; + case 3: + u->x3 = val; + break; + case 4: + u->x4 = val; + break; + case 5: + u->x5 = val; + break; + case 6: + u->x6 = val; + break; + default: + LOG_VMM_ERR("trying to set SMC arg: 0x%lx, with val: 0x%lx, SMC only has 6 argument registers\n", arg, val); } } @@ -103,15 +121,15 @@ bool handle_smc(size_t vcpu_id, uint32_t hsr) smc_call_id_t service = smc_get_call(regs.x0); switch (service) { - case SMC_CALL_STD_SERVICE: - if (fn_number < PSCI_MAX) { - return handle_psci(vcpu_id, ®s, fn_number, hsr); - } - LOG_VMM_ERR("Unhandled SMC: standard service call %lu\n", fn_number); - break; - default: - LOG_VMM_ERR("Unhandled SMC: unknown value service: 0x%lx, function number: 0x%lx\n", service, fn_number); - break; + case SMC_CALL_STD_SERVICE: + if (fn_number < PSCI_MAX) { + return handle_psci(vcpu_id, ®s, fn_number, hsr); + } + LOG_VMM_ERR("Unhandled SMC: standard service call %lu\n", fn_number); + break; + default: + LOG_VMM_ERR("Unhandled SMC: unknown value service: 0x%lx, function number: 0x%lx\n", service, fn_number); + break; } return false; diff --git a/src/arch/aarch64/tcb.c b/src/arch/aarch64/tcb.c index 2357b102..86c896db 100644 --- a/src/arch/aarch64/tcb.c +++ b/src/arch/aarch64/tcb.c @@ -9,7 +9,8 @@ #include #include -void tcb_print_regs(size_t vcpu_id) { +void tcb_print_regs(size_t vcpu_id) +{ /* * While we are potentially doing an extra system call in order to read the * TCB registers (as the VMM may have already read the TCB registers before diff --git a/src/arch/aarch64/vcpu.c b/src/arch/aarch64/vcpu.c index 0a565611..eb090dfe 100644 --- a/src/arch/aarch64/vcpu.c +++ b/src/arch/aarch64/vcpu.c @@ -27,7 +27,8 @@ bool vcpu_on_state[GUEST_NUM_VCPUS]; -bool vcpu_is_on(size_t vcpu_id) { +bool vcpu_is_on(size_t vcpu_id) +{ assert(vcpu_id < GUEST_NUM_VCPUS); if (vcpu_id >= GUEST_NUM_VCPUS) { return false; @@ -36,7 +37,8 @@ bool vcpu_is_on(size_t vcpu_id) { return vcpu_on_state[vcpu_id]; } -void vcpu_set_on(size_t vcpu_id, bool on) { +void vcpu_set_on(size_t vcpu_id, bool on) +{ assert(vcpu_id < GUEST_NUM_VCPUS); if (vcpu_id >= GUEST_NUM_VCPUS) { return; @@ -45,7 +47,8 @@ void vcpu_set_on(size_t vcpu_id, bool on) { vcpu_on_state[vcpu_id] = on; } -void vcpu_reset(size_t vcpu_id) { +void vcpu_reset(size_t vcpu_id) +{ // @ivanv this is an incredible amount of system calls // Reset registers // @ivanv: double check, shouldn't we be setting sctlr? @@ -83,7 +86,8 @@ void vcpu_reset(size_t vcpu_id) { microkit_vcpu_arm_write_reg(vcpu_id, seL4_VCPUReg_CNTKCTL_EL1, 0); } -void vcpu_print_regs(size_t vcpu_id) { +void vcpu_print_regs(size_t vcpu_id) +{ // @ivanv this is an incredible amount of system calls LOG_VMM("dumping VCPU (ID 0x%lx) registers:\n", vcpu_id); /* VM control registers EL1 */ diff --git a/src/arch/aarch64/vgic/vgic.c b/src/arch/aarch64/vgic/vgic.c index debca543..86abdd9a 100644 --- a/src/arch/aarch64/vgic/vgic.c +++ b/src/arch/aarch64/vgic/vgic.c @@ -84,7 +84,8 @@ bool vgic_handle_fault_dist(size_t vcpu_id, size_t offset, size_t fsr, seL4_User return success; } -bool vgic_register_irq(size_t vcpu_id, int virq_num, virq_ack_fn_t ack_fn, void *ack_data) { +bool vgic_register_irq(size_t vcpu_id, int virq_num, virq_ack_fn_t ack_fn, void *ack_data) +{ assert(virq_num >= 0 && virq_num != VIRQ_INVALID); struct virq_handle virq = { .virq = virq_num, diff --git a/src/arch/aarch64/vgic/vgic_v3.c b/src/arch/aarch64/vgic/vgic_v3.c index 63efe504..056487e9 100644 --- a/src/arch/aarch64/vgic/vgic_v3.c +++ b/src/arch/aarch64/vgic/vgic_v3.c @@ -45,7 +45,8 @@ vgic_t vgic; -static bool vgic_handle_fault_redist_read(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, seL4_UserContext *regs) +static bool vgic_handle_fault_redist_read(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, + seL4_UserContext *regs) { struct gic_dist_map *gic_dist = vgic_get_dist(vgic->registers); struct gic_redist_map *gic_redist = vgic_get_redist(vgic->registers); @@ -96,8 +97,8 @@ static bool vgic_handle_fault_redist_read(size_t vcpu_id, vgic_t *vgic, uint64_t return true; } - -static bool vgic_handle_fault_redist_write(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, seL4_UserContext *regs) +static bool vgic_handle_fault_redist_write(size_t vcpu_id, vgic_t *vgic, uint64_t offset, uint64_t fsr, + seL4_UserContext *regs) { // @ivanv: why is this not reading from the redist? uintptr_t fault_addr = GIC_REDIST_PADDR + offset; @@ -134,8 +135,8 @@ static bool vgic_handle_fault_redist_write(size_t vcpu_id, vgic_t *vgic, uint64_ } break; case RANGE32(GICR_ICACTIVER0, GICR_ICACTIVER0): - // @ivanv: understand, this is a comment left over from kent - // TODO fix this + // @ivanv: understand, this is a comment left over from kent + // TODO fix this emulate_reg_write_access(regs, fault_addr, fsr, &gic_dist->active0[vcpu_id]); break; case RANGE32(GICR_IPRIORITYR0, GICR_IPRIORITYRN): @@ -147,7 +148,8 @@ static bool vgic_handle_fault_redist_write(size_t vcpu_id, vgic_t *vgic, uint64_ return true; } -bool vgic_handle_fault_redist(size_t vcpu_id, size_t offset, size_t fsr, seL4_UserContext *regs, void *data) { +bool vgic_handle_fault_redist(size_t vcpu_id, size_t offset, size_t fsr, seL4_UserContext *regs, void *data) +{ if (fault_is_read(fsr)) { return vgic_handle_fault_redist_read(vcpu_id, &vgic, offset, fsr, regs); } else { @@ -179,7 +181,8 @@ static void vgic_dist_reset(struct gic_dist_map *dist) dist->cidrn[3] = 0xB1; /* RO */ } -static void vgic_redist_reset(struct gic_redist_map *redist) { +static void vgic_redist_reset(struct gic_redist_map *redist) +{ // @ivanv: come back to, right now it's a global so we don't need to init the memory to zero // memset(redist, 0, sizeof(*redist)); redist->typer = 0x11; /* RO */ diff --git a/src/arch/aarch64/virq.c b/src/arch/aarch64/virq.c index 6dfa9e02..63b4251f 100644 --- a/src/arch/aarch64/virq.c +++ b/src/arch/aarch64/virq.c @@ -24,7 +24,8 @@ static void vppi_event_ack(size_t vcpu_id, int irq, void *cookie) static void sgi_ack(size_t vcpu_id, int irq, void *cookie) {} -bool virq_controller_init() { +bool virq_controller_init() +{ bool success; vgic_init(); @@ -71,24 +72,29 @@ bool virq_controller_init() { return true; } -bool virq_inject_vcpu(size_t vcpu_id, int irq) { +bool virq_inject_vcpu(size_t vcpu_id, int irq) +{ return vgic_inject_irq(vcpu_id, irq); } -bool virq_inject(int irq) { +bool virq_inject(int irq) +{ return vgic_inject_irq(GUEST_BOOT_VCPU_ID, irq); } -bool virq_register(size_t vcpu_id, size_t virq_num, virq_ack_fn_t ack_fn, void *ack_data) { +bool virq_register(size_t vcpu_id, size_t virq_num, virq_ack_fn_t ack_fn, void *ack_data) +{ return vgic_register_irq(vcpu_id, virq_num, ack_fn, ack_data); } -static void virq_passthrough_ack(size_t vcpu_id, int irq, void *cookie) { +static void virq_passthrough_ack(size_t vcpu_id, int irq, void *cookie) +{ /* We are down-casting to microkit_channel so must first cast to size_t */ microkit_irq_ack((microkit_channel)(size_t)cookie); } -bool virq_register_passthrough(size_t vcpu_id, size_t irq, microkit_channel irq_ch) { +bool virq_register_passthrough(size_t vcpu_id, size_t irq, microkit_channel irq_ch) +{ assert(irq_ch < MICROKIT_MAX_CHANNELS); if (irq_ch >= MICROKIT_MAX_CHANNELS) { LOG_VMM_ERR("Invalid channel number given '0x%lx' for passthrough vIRQ 0x%lx\n", irq_ch, irq); @@ -108,7 +114,8 @@ bool virq_register_passthrough(size_t vcpu_id, size_t irq, microkit_channel irq_ return true; } -bool virq_handle_passthrough(microkit_channel irq_ch) { +bool virq_handle_passthrough(microkit_channel irq_ch) +{ assert(virq_passthrough_map[irq_ch] >= 0); if (virq_passthrough_map[irq_ch] < 0) { LOG_VMM_ERR("attempted to handle invalid passthrough IRQ channel 0x%lx\n", irq_ch); @@ -117,7 +124,8 @@ bool virq_handle_passthrough(microkit_channel irq_ch) { bool success = vgic_inject_irq(GUEST_BOOT_VCPU_ID, virq_passthrough_map[irq_ch]); if (!success) { - LOG_VMM_ERR("could not inject passthrough vIRQ 0x%lx, dropped on vCPU 0x%lx\n", virq_passthrough_map[irq_ch], GUEST_BOOT_VCPU_ID); + LOG_VMM_ERR("could not inject passthrough vIRQ 0x%lx, dropped on vCPU 0x%lx\n", virq_passthrough_map[irq_ch], + GUEST_BOOT_VCPU_ID); return false; } diff --git a/src/guest.c b/src/guest.c index 8f94ac5d..d43d8a0d 100644 --- a/src/guest.c +++ b/src/guest.c @@ -8,7 +8,8 @@ #include #include -bool guest_start(uintptr_t kernel_pc, uintptr_t dtb, uintptr_t initrd) { +bool guest_start(uintptr_t kernel_pc, uintptr_t dtb, uintptr_t initrd) +{ /* * Set the TCB registers to what the virtual machine expects to be started with. * You will note that this is currently Linux specific as we currently do not support @@ -21,19 +22,19 @@ bool guest_start(uintptr_t kernel_pc, uintptr_t dtb, uintptr_t initrd) { regs.pc = kernel_pc; /* Write out all the TCB registers */ seL4_Word err = seL4_TCB_WriteRegisters( - BASE_VM_TCB_CAP + GUEST_BOOT_VCPU_ID, - false, // We'll explcitly start the guest below rather than in this call - 0, // No flags - 4, // Writing to x0, pc, and spsr. Due to the ordering of seL4_UserContext the count must be 4. - ®s - ); + BASE_VM_TCB_CAP + GUEST_BOOT_VCPU_ID, + false, // We'll explcitly start the guest below rather than in this call + 0, // No flags + 4, // Writing to x0, pc, and spsr. Due to the ordering of seL4_UserContext the count must be 4. + ®s + ); assert(err == seL4_NoError); if (err != seL4_NoError) { LOG_VMM_ERR("Failed to write registers to boot vCPU's TCB (id is 0x%lx), error is: 0x%lx\n", GUEST_BOOT_VCPU_ID, err); return false; } LOG_VMM("starting guest at 0x%lx, DTB at 0x%lx, initial RAM disk at 0x%lx\n", - regs.pc, regs.x0, initrd); + regs.pc, regs.x0, initrd); vcpu_set_on(GUEST_BOOT_VCPU_ID, true); /* Restart the boot vCPU to the program counter of the TCB associated with it */ @@ -42,13 +43,15 @@ bool guest_start(uintptr_t kernel_pc, uintptr_t dtb, uintptr_t initrd) { return true; } -void guest_stop() { +void guest_stop() +{ LOG_VMM("Stopping guest\n"); microkit_vcpu_stop(GUEST_BOOT_VCPU_ID); LOG_VMM("Stopped guest\n"); } -bool guest_restart(uintptr_t guest_ram_vaddr, size_t guest_ram_size) { +bool guest_restart(uintptr_t guest_ram_vaddr, size_t guest_ram_size) +{ LOG_VMM("Attempting to restart guest\n"); // First, stop the guest microkit_vcpu_stop(GUEST_BOOT_VCPU_ID);