for (i = 0; i < size; i++) {
- if (copy_from_user(&(event.scan_code), buf + i, 1)) {
+ if (copy_from_user(&(event.scan_code), buf++, 1)) {
printk("Console Write fault\n");
return -EFAULT;
}
return -1;
}
- cons_fd = anon_inode_getfd("v3-cons", &cons_fops, cons, O_RDWR);
+ cons_fd = anon_inode_getfd("v3-cons", &cons_fops, cons, 0);
if (cons_fd < 0) {
printk("Error creating console inode\n");
static int v3_major_num = 0;
-static u8 v3_minor_map[MAX_VMS / 8] = {[0 ... (MAX_VMS / 8) - 1] = 0};
-
+static struct v3_guest * guest_map[MAX_VMS] = {[0 ... MAX_VMS - 1] = 0};
struct class * v3_class = NULL;
static struct cdev ctrl_dev;
-static int register_vm( void ) {
- int i, j = 0;
- int avail = 0;
-
- for (i = 0; i < sizeof(v3_minor_map); i++) {
- if (v3_minor_map[i] != 0xff) {
- for (j = 0; j < 8; j++) {
- if (!(v3_minor_map[i] & (0x1 << j))) {
- avail = 1;
- v3_minor_map[i] |= (0x1 << j);
- break;
- }
- }
-
- if (avail == 1) {
- break;
- }
+static int register_vm(struct v3_guest * guest) {
+ int i = 0;
+
+ for (i = 0; i < MAX_VMS; i++) {
+ if (guest_map[i] == NULL) {
+ guest_map[i] = guest;
+ return i;
}
}
- if (avail == 0) {
- return -1;
- }
-
- return (i * 8) + j;
+ return -1;
}
memset(guest, 0, sizeof(struct v3_guest));
- printk("Starting V3 Guest...\n");
+ printk("Starting V3 Guest... (%p)\n", guest);
- vm_minor = register_vm();
+ vm_minor = register_vm(guest);
if (vm_minor == -1) {
printk("Too many VMs are currently running\n");
return guest->vm_dev;
break;
}
+ case V3_STOP_GUEST: {
+ unsigned long vm_idx = arg;
+ struct v3_guest * guest = guest_map[vm_idx];
+
+ printk("Stopping VM idx=%d\n", vm_idx);
+ printk("Stopping VM (%s) (%p)\n", guest->name, guest);
+
+
+ if (irqs_disabled()) {
+ printk("WHAT!!?? IRQs are disabled??\n");
+ break;
+ }
+
+ stop_palacios_vm(guest);
+ guest_map[vm_idx] = NULL;
+ break;
+ }
case V3_ADD_MEMORY: {
struct v3_mem_region mem;
/* Global Control IOCTLs */
#define V3_START_GUEST 10
+#define V3_STOP_GUEST 11
#define V3_ADD_MEMORY 50
/* VM Specific IOCTLs */
#define V3_VM_CONSOLE_CONNECT 20
-#define V3_VM_STOP 22
+
#define V3_VM_PAUSE 23
#define V3_VM_CONTINUE 24
printk("V3 IOCTL %d\n", ioctl);
switch (ioctl) {
-
- case V3_VM_STOP: {
- printk("Stopping VM (%s)\n", guest->name);
- stop_palacios_vm(guest);
- break;
- }
case V3_VM_PAUSE: {
printk("Pausing VM (%s)\n", guest->name);
v3_pause_vm(guest->v3_ctx);
int stop_palacios_vm(struct v3_guest * guest) {
+
v3_stop_vm(guest->v3_ctx);
wait_for_completion(&(guest->thread_done));
v3_free_vm(guest->v3_ctx);
-
+
device_destroy(v3_class, guest->vm_dev);
cdev_del(&(guest->cdev));
#define _v3_ctrl_h
#define V3_START_GUEST 10
+#define V3_STOP_GUEST 11
#define V3_ADD_MEMORY 50
#define V3_START_NETWORK 60
#define V3_VM_CONSOLE_CONNECT 20
#define V3_VM_SERIAL_CONNECT 21
-#define V3_VM_STOP 22
#define V3_VM_MOVE_CORE 33
int read_file(int fd, int size, unsigned char * buf);
int main(int argc, char* argv[]) {
- char * filename = argv[1];
int vm_fd = 0;
-
+ unsigned long vm_idx = 0;
+
if (argc <= 1) {
- printf("Usage: ./v3_stop <vm-dev>\n");
+ printf("Usage: ./v3_stop <vm-dev-idx>\n");
return -1;
}
+
+ vm_idx = atoi(argv[1]);
+
printf("Stopping VM\n");
- vm_fd = open(filename, O_RDONLY);
+ vm_fd = open("/dev/v3vee", O_RDONLY);
if (vm_fd == -1) {
printf("Error opening V3Vee VM device\n");
return -1;
}
- ioctl(vm_fd, V3_VM_STOP, NULL);
+ ioctl(vm_fd, V3_STOP_GUEST, vm_idx);
#if KEYBOARD_DEBUG_80H
-static int keyboard_write_delay(ushort_t port, void * src, uint_t length, void * priv_data) {
+static int keyboard_write_delay(struct guest_info *core, ushort_t port, void * src, uint_t length, void * priv_data) {
if (length == 1) {
PrintDebug("keyboard: write of 0x%x to 80h\n", *((uint8_t*)src));
V3_ASSERT(stream_hooks != NULL);
V3_ASSERT(stream_hooks->open != NULL);
- stream = V3_Malloc(sizeof(struct v3_stream *));
+ stream = V3_Malloc(sizeof(struct v3_stream));
stream->input = input;
stream->guest_stream_data = guest_stream_data;
if (v3_vmx_enter(info) == -1) {
- addr_t host_addr;
+ addr_t host_addr;
addr_t linear_addr = 0;
info->vm_info->run_state = VM_ERROR;
v3_print_guest_state(info);
V3_Print("VMX core %u\n", info->vcpu_id);
-
-
linear_addr = get_addr_linear(info, info->rip, &(info->segments.cs));
if (info->mem_mode == PHYSICAL_MEM) {