6 #include <linux/device.h>
7 #include <linux/cdev.h>
8 #include <linux/errno.h>
9 #include <linux/percpu.h>
11 #include <linux/uaccess.h>
12 #include <linux/poll.h>
13 #include <linux/anon_inodes.h>
14 #include <linux/sched.h>
16 #include <linux/smp_lock.h>
17 #include <linux/file.h>
18 #include <linux/spinlock.h>
20 #ifdef CONFIG_DEBUG_FS
21 #include <linux/debugfs.h>
24 #include <palacios/vmm.h>
27 #include "palacios-console.h"
28 #include "palacios-serial.h"
29 #include "palacios-vm.h"
32 extern struct class * v3_class;
33 #define STREAM_NAME_LEN 128
35 static long v3_vm_ioctl(struct file * filp,
36 unsigned int ioctl, unsigned long arg) {
37 void __user * argp = (void __user *)arg;
38 char path_name[STREAM_NAME_LEN];
40 struct v3_guest * guest = filp->private_data;
42 printk("V3 IOCTL %d\n", ioctl);
46 case V3_VM_CONSOLE_CONNECT: {
47 return connect_console(guest);
50 case V3_VM_SERIAL_CONNECT: {
51 if (copy_from_user(path_name, argp, STREAM_NAME_LEN)) {
52 printk("copy from user error getting guest image...\n");
56 return open_serial(path_name);
60 printk("Stopping VM\n");
61 stop_palacios_vm(guest);
65 printk("\tUnhandled\n");
72 static int v3_vm_open(struct inode * inode, struct file * filp) {
73 struct v3_guest * guest = container_of(inode->i_cdev, struct v3_guest, cdev);
74 filp->private_data = guest;
79 static ssize_t v3_vm_read(struct file * filp, char __user * buf, size_t size, loff_t * offset) {
85 static ssize_t v3_vm_write(struct file * filp, const char __user * buf, size_t size, loff_t * offset) {
92 static struct file_operations v3_vm_fops = {
94 .unlocked_ioctl = v3_vm_ioctl,
95 .compat_ioctl = v3_vm_ioctl,
103 extern int vm_running;
104 extern u32 pg_allocs;
109 #include <palacios/vmm_inspector.h>
111 int start_palacios_vm(void * arg) {
112 struct v3_guest * guest = (struct v3_guest *)arg;
116 daemonize(guest->name);
117 // allow_signal(SIGKILL);
121 guest->v3_ctx = v3_create_vm(guest->img, (void *)guest, guest->name);
123 if (guest->v3_ctx == NULL) {
124 printk("palacios: failed to create vm\n");
128 printk("Creating VM device: Major %d, Minor %d\n", MAJOR(guest->vm_dev), MINOR(guest->vm_dev));
130 cdev_init(&(guest->cdev), &v3_vm_fops);
132 guest->cdev.owner = THIS_MODULE;
133 guest->cdev.ops = &v3_vm_fops;
136 printk("Adding VM device\n");
137 err = cdev_add(&(guest->cdev), guest->vm_dev, 1);
140 printk("Fails to add cdev\n");
144 if (device_create(v3_class, NULL, guest->vm_dev, guest, "v3-vm%d", MINOR(guest->vm_dev)) == NULL){
145 printk("Fails to create device\n");
149 complete(&(guest->start_done));
151 printk("palacios: launching vm\n");
158 struct v3_inspection_value rax;
159 v3_inspect_node_t * core = NULL;
160 v3_inspect_node_t * gprs = NULL;
161 v3_inspect_node_t * root = v3_get_inspection_root(guest->v3_ctx);
164 printk("NULL root inspection tree\n");
167 core = v3_get_inspection_subtree(root, "core.0");
169 printk("NULL core inspection tree\n");
172 gprs = v3_get_inspection_subtree(core, "GPRS");
174 printk("NULL gprs inspection tree\n");
177 v3_get_inspection_value(gprs, "RAX", &rax);
179 debugfs_create_u64("RAX", 0644, NULL, (u64 *)rax.value);
184 if (v3_start_vm(guest->v3_ctx, 0xffffffff) < 0) {
185 printk("palacios: launch of vm failed\n");
189 complete(&(guest->thread_done));
191 printk("palacios: vm completed. returning.\n");
199 int stop_palacios_vm(struct v3_guest * guest) {
201 v3_stop_vm(guest->v3_ctx);
203 wait_for_completion(&(guest->thread_done));
205 v3_free_vm(guest->v3_ctx);
207 device_destroy(v3_class, guest->vm_dev);
209 cdev_del(&(guest->cdev));