1 #include "kvm/builtin-run.h" 2 3 #include "kvm/builtin-setup.h" 4 #include "kvm/virtio-balloon.h" 5 #include "kvm/virtio-console.h" 6 #include "kvm/parse-options.h" 7 #include "kvm/8250-serial.h" 8 #include "kvm/framebuffer.h" 9 #include "kvm/disk-image.h" 10 #include "kvm/threadpool.h" 11 #include "kvm/virtio-scsi.h" 12 #include "kvm/virtio-blk.h" 13 #include "kvm/virtio-net.h" 14 #include "kvm/virtio-rng.h" 15 #include "kvm/ioeventfd.h" 16 #include "kvm/virtio-9p.h" 17 #include "kvm/barrier.h" 18 #include "kvm/kvm-cpu.h" 19 #include "kvm/ioport.h" 20 #include "kvm/symbol.h" 21 #include "kvm/i8042.h" 22 #include "kvm/mutex.h" 23 #include "kvm/term.h" 24 #include "kvm/util.h" 25 #include "kvm/strbuf.h" 26 #include "kvm/vesa.h" 27 #include "kvm/irq.h" 28 #include "kvm/kvm.h" 29 #include "kvm/pci.h" 30 #include "kvm/rtc.h" 31 #include "kvm/sdl.h" 32 #include "kvm/vnc.h" 33 #include "kvm/guest_compat.h" 34 #include "kvm/pci-shmem.h" 35 #include "kvm/kvm-ipc.h" 36 #include "kvm/builtin-debug.h" 37 38 #include <linux/types.h> 39 #include <linux/err.h> 40 41 #include <sys/utsname.h> 42 #include <sys/types.h> 43 #include <sys/stat.h> 44 #include <termios.h> 45 #include <signal.h> 46 #include <stdlib.h> 47 #include <string.h> 48 #include <unistd.h> 49 #include <ctype.h> 50 #include <stdio.h> 51 52 #define MB_SHIFT (20) 53 #define KB_SHIFT (10) 54 #define GB_SHIFT (30) 55 56 __thread struct kvm_cpu *current_kvm_cpu; 57 58 static int kvm_run_wrapper; 59 60 bool do_debug_print = false; 61 62 static const char * const run_usage[] = { 63 "lkvm run [<options>] [<kernel image>]", 64 NULL 65 }; 66 67 enum { 68 KVM_RUN_DEFAULT, 69 KVM_RUN_SANDBOX, 70 }; 71 72 static int img_name_parser(const struct option *opt, const char *arg, int unset) 73 { 74 char path[PATH_MAX]; 75 struct stat st; 76 77 snprintf(path, PATH_MAX, "%s%s", kvm__get_dir(), arg); 78 79 if ((stat(arg, &st) == 0 && S_ISDIR(st.st_mode)) || 80 (stat(path, &st) == 0 && S_ISDIR(st.st_mode))) 81 return virtio_9p_img_name_parser(opt, arg, unset); 82 return disk_img_name_parser(opt, arg, unset); 83 } 84 85 void kvm_run_set_wrapper_sandbox(void) 86 { 87 kvm_run_wrapper = KVM_RUN_SANDBOX; 88 } 89 90 #ifndef OPT_ARCH_RUN 91 #define OPT_ARCH_RUN(...) 92 #endif 93 94 #define BUILD_OPTIONS(name, cfg, kvm) \ 95 struct option name[] = { \ 96 OPT_GROUP("Basic options:"), \ 97 OPT_STRING('\0', "name", &(cfg)->guest_name, "guest name", \ 98 "A name for the guest"), \ 99 OPT_INTEGER('c', "cpus", &(cfg)->nrcpus, "Number of CPUs"), \ 100 OPT_U64('m', "mem", &(cfg)->ram_size, "Virtual machine memory" \ 101 " size in MiB."), \ 102 OPT_CALLBACK('\0', "shmem", NULL, \ 103 "[pci:]<addr>:<size>[:handle=<handle>][:create]", \ 104 "Share host shmem with guest via pci device", \ 105 shmem_parser, NULL), \ 106 OPT_CALLBACK('d', "disk", kvm, "image or rootfs_dir", "Disk " \ 107 " image or rootfs directory", img_name_parser, \ 108 kvm), \ 109 OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio" \ 110 " balloon"), \ 111 OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\ 112 OPT_BOOLEAN('\0', "gtk", &(cfg)->gtk, "Enable GTK framebuffer"),\ 113 OPT_BOOLEAN('\0', "sdl", &(cfg)->sdl, "Enable SDL framebuffer"),\ 114 OPT_BOOLEAN('\0', "rng", &(cfg)->virtio_rng, "Enable virtio" \ 115 " Random Number Generator"), \ 116 OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \ 117 "Enable virtio 9p to share files between host and" \ 118 " guest", virtio_9p_rootdir_parser, kvm), \ 119 OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or"\ 120 " hv", "Console to use"), \ 121 OPT_STRING('\0', "dev", &(cfg)->dev, "device_file", \ 122 "KVM device file"), \ 123 OPT_CALLBACK('\0', "tty", NULL, "tty id", \ 124 "Remap guest TTY into a pty on the host", \ 125 tty_parser, NULL), \ 126 OPT_STRING('\0', "sandbox", &(cfg)->sandbox, "script", \ 127 "Run this script when booting into custom" \ 128 " rootfs"), \ 129 OPT_STRING('\0', "hugetlbfs", &(cfg)->hugetlbfs_path, "path", \ 130 "Hugetlbfs path"), \ 131 \ 132 OPT_GROUP("Kernel options:"), \ 133 OPT_STRING('k', "kernel", &(cfg)->kernel_filename, "kernel", \ 134 "Kernel to boot in virtual machine"), \ 135 OPT_STRING('i', "initrd", &(cfg)->initrd_filename, "initrd", \ 136 "Initial RAM disk image"), \ 137 OPT_STRING('p', "params", &(cfg)->kernel_cmdline, "params", \ 138 "Kernel command line arguments"), \ 139 OPT_STRING('f', "firmware", &(cfg)->firmware_filename, "firmware",\ 140 "Firmware image to boot in virtual machine"), \ 141 \ 142 OPT_GROUP("Networking options:"), \ 143 OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params", \ 144 "Create a new guest NIC", \ 145 netdev_parser, NULL, kvm), \ 146 OPT_BOOLEAN('\0', "no-dhcp", &(cfg)->no_dhcp, "Disable kernel" \ 147 " DHCP in rootfs mode"), \ 148 \ 149 OPT_GROUP("Debug options:"), \ 150 OPT_BOOLEAN('\0', "debug", &do_debug_print, \ 151 "Enable debug messages"), \ 152 OPT_BOOLEAN('\0', "debug-single-step", &(cfg)->single_step, \ 153 "Enable single stepping"), \ 154 OPT_BOOLEAN('\0', "debug-ioport", &(cfg)->ioport_debug, \ 155 "Enable ioport debugging"), \ 156 OPT_BOOLEAN('\0', "debug-mmio", &(cfg)->mmio_debug, \ 157 "Enable MMIO debugging"), \ 158 OPT_INTEGER('\0', "debug-iodelay", &(cfg)->debug_iodelay, \ 159 "Delay IO by millisecond"), \ 160 \ 161 OPT_ARCH(RUN, cfg) \ 162 OPT_END() \ 163 }; 164 165 static void *kvm_cpu_thread(void *arg) 166 { 167 char name[16]; 168 169 current_kvm_cpu = arg; 170 171 sprintf(name, "kvm-vcpu-%lu", current_kvm_cpu->cpu_id); 172 kvm__set_thread_name(name); 173 174 if (kvm_cpu__start(current_kvm_cpu)) 175 goto panic_kvm; 176 177 return (void *) (intptr_t) 0; 178 179 panic_kvm: 180 fprintf(stderr, "KVM exit reason: %u (\"%s\")\n", 181 current_kvm_cpu->kvm_run->exit_reason, 182 kvm_exit_reasons[current_kvm_cpu->kvm_run->exit_reason]); 183 if (current_kvm_cpu->kvm_run->exit_reason == KVM_EXIT_UNKNOWN) 184 fprintf(stderr, "KVM exit code: 0x%llu\n", 185 (unsigned long long)current_kvm_cpu->kvm_run->hw.hardware_exit_reason); 186 187 kvm_cpu__set_debug_fd(STDOUT_FILENO); 188 kvm_cpu__show_registers(current_kvm_cpu); 189 kvm_cpu__show_code(current_kvm_cpu); 190 kvm_cpu__show_page_tables(current_kvm_cpu); 191 192 return (void *) (intptr_t) 1; 193 } 194 195 static char kernel[PATH_MAX]; 196 197 static const char *host_kernels[] = { 198 "/boot/vmlinuz", 199 "/boot/bzImage", 200 NULL 201 }; 202 203 static const char *default_kernels[] = { 204 "./bzImage", 205 "arch/" BUILD_ARCH "/boot/bzImage", 206 "../../arch/" BUILD_ARCH "/boot/bzImage", 207 NULL 208 }; 209 210 static const char *default_vmlinux[] = { 211 "vmlinux", 212 "../../../vmlinux", 213 "../../vmlinux", 214 NULL 215 }; 216 217 static void kernel_usage_with_options(void) 218 { 219 const char **k; 220 struct utsname uts; 221 222 fprintf(stderr, "Fatal: could not find default kernel image in:\n"); 223 k = &default_kernels[0]; 224 while (*k) { 225 fprintf(stderr, "\t%s\n", *k); 226 k++; 227 } 228 229 if (uname(&uts) < 0) 230 return; 231 232 k = &host_kernels[0]; 233 while (*k) { 234 if (snprintf(kernel, PATH_MAX, "%s-%s", *k, uts.release) < 0) 235 return; 236 fprintf(stderr, "\t%s\n", kernel); 237 k++; 238 } 239 fprintf(stderr, "\nPlease see '%s run --help' for more options.\n\n", 240 KVM_BINARY_NAME); 241 } 242 243 static u64 host_ram_size(void) 244 { 245 long page_size; 246 long nr_pages; 247 248 nr_pages = sysconf(_SC_PHYS_PAGES); 249 if (nr_pages < 0) { 250 pr_warning("sysconf(_SC_PHYS_PAGES) failed"); 251 return 0; 252 } 253 254 page_size = sysconf(_SC_PAGE_SIZE); 255 if (page_size < 0) { 256 pr_warning("sysconf(_SC_PAGE_SIZE) failed"); 257 return 0; 258 } 259 260 return (nr_pages * page_size) >> MB_SHIFT; 261 } 262 263 /* 264 * If user didn't specify how much memory it wants to allocate for the guest, 265 * avoid filling the whole host RAM. 266 */ 267 #define RAM_SIZE_RATIO 0.8 268 269 static u64 get_ram_size(int nr_cpus) 270 { 271 u64 available; 272 u64 ram_size; 273 274 ram_size = 64 * (nr_cpus + 3); 275 276 available = host_ram_size() * RAM_SIZE_RATIO; 277 if (!available) 278 available = MIN_RAM_SIZE_MB; 279 280 if (ram_size > available) 281 ram_size = available; 282 283 return ram_size; 284 } 285 286 static const char *find_kernel(void) 287 { 288 const char **k; 289 struct stat st; 290 struct utsname uts; 291 292 k = &default_kernels[0]; 293 while (*k) { 294 if (stat(*k, &st) < 0 || !S_ISREG(st.st_mode)) { 295 k++; 296 continue; 297 } 298 strncpy(kernel, *k, PATH_MAX); 299 return kernel; 300 } 301 302 if (uname(&uts) < 0) 303 return NULL; 304 305 k = &host_kernels[0]; 306 while (*k) { 307 if (snprintf(kernel, PATH_MAX, "%s-%s", *k, uts.release) < 0) 308 return NULL; 309 310 if (stat(kernel, &st) < 0 || !S_ISREG(st.st_mode)) { 311 k++; 312 continue; 313 } 314 return kernel; 315 316 } 317 return NULL; 318 } 319 320 static const char *find_vmlinux(void) 321 { 322 const char **vmlinux; 323 324 vmlinux = &default_vmlinux[0]; 325 while (*vmlinux) { 326 struct stat st; 327 328 if (stat(*vmlinux, &st) < 0 || !S_ISREG(st.st_mode)) { 329 vmlinux++; 330 continue; 331 } 332 return *vmlinux; 333 } 334 return NULL; 335 } 336 337 void kvm_run_help(void) 338 { 339 struct kvm *kvm = NULL; 340 341 BUILD_OPTIONS(options, &kvm->cfg, kvm); 342 usage_with_options(run_usage, options); 343 } 344 345 static int kvm_run_set_sandbox(struct kvm *kvm) 346 { 347 const char *guestfs_name = kvm->cfg.custom_rootfs_name; 348 char path[PATH_MAX], script[PATH_MAX], *tmp; 349 350 snprintf(path, PATH_MAX, "%s%s/virt/sandbox.sh", kvm__get_dir(), guestfs_name); 351 352 remove(path); 353 354 if (kvm->cfg.sandbox == NULL) 355 return 0; 356 357 tmp = realpath(kvm->cfg.sandbox, NULL); 358 if (tmp == NULL) 359 return -ENOMEM; 360 361 snprintf(script, PATH_MAX, "/host/%s", tmp); 362 free(tmp); 363 364 return symlink(script, path); 365 } 366 367 static void kvm_write_sandbox_cmd_exactly(int fd, const char *arg) 368 { 369 const char *single_quote; 370 371 if (!*arg) { /* zero length string */ 372 if (write(fd, "''", 2) <= 0) 373 die("Failed writing sandbox script"); 374 return; 375 } 376 377 while (*arg) { 378 single_quote = strchrnul(arg, '\''); 379 380 /* write non-single-quote string as #('string') */ 381 if (arg != single_quote) { 382 if (write(fd, "'", 1) <= 0 || 383 write(fd, arg, single_quote - arg) <= 0 || 384 write(fd, "'", 1) <= 0) 385 die("Failed writing sandbox script"); 386 } 387 388 /* write single quote as #("'") */ 389 if (*single_quote) { 390 if (write(fd, "\"'\"", 3) <= 0) 391 die("Failed writing sandbox script"); 392 } else 393 break; 394 395 arg = single_quote + 1; 396 } 397 } 398 399 static void resolve_program(const char *src, char *dst, size_t len) 400 { 401 struct stat st; 402 int err; 403 404 err = stat(src, &st); 405 406 if (!err && S_ISREG(st.st_mode)) { 407 char resolved_path[PATH_MAX]; 408 409 if (!realpath(src, resolved_path)) 410 die("Unable to resolve program %s: %s\n", src, strerror(errno)); 411 412 snprintf(dst, len, "/host%s", resolved_path); 413 } else 414 strncpy(dst, src, len); 415 } 416 417 static void kvm_run_write_sandbox_cmd(struct kvm *kvm, const char **argv, int argc) 418 { 419 const char script_hdr[] = "#! /bin/bash\n\n"; 420 char program[PATH_MAX]; 421 int fd; 422 423 remove(kvm->cfg.sandbox); 424 425 fd = open(kvm->cfg.sandbox, O_RDWR | O_CREAT, 0777); 426 if (fd < 0) 427 die("Failed creating sandbox script"); 428 429 if (write(fd, script_hdr, sizeof(script_hdr) - 1) <= 0) 430 die("Failed writing sandbox script"); 431 432 resolve_program(argv[0], program, PATH_MAX); 433 kvm_write_sandbox_cmd_exactly(fd, program); 434 435 argv++; 436 argc--; 437 438 while (argc) { 439 if (write(fd, " ", 1) <= 0) 440 die("Failed writing sandbox script"); 441 442 kvm_write_sandbox_cmd_exactly(fd, argv[0]); 443 argv++; 444 argc--; 445 } 446 if (write(fd, "\n", 1) <= 0) 447 die("Failed writing sandbox script"); 448 449 close(fd); 450 } 451 452 static struct kvm *kvm_cmd_run_init(int argc, const char **argv) 453 { 454 static char real_cmdline[2048], default_name[20]; 455 unsigned int nr_online_cpus; 456 struct kvm *kvm = kvm__new(); 457 458 if (IS_ERR(kvm)) 459 return kvm; 460 461 nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); 462 kvm->cfg.custom_rootfs_name = "default"; 463 464 while (argc != 0) { 465 BUILD_OPTIONS(options, &kvm->cfg, kvm); 466 argc = parse_options(argc, argv, options, run_usage, 467 PARSE_OPT_STOP_AT_NON_OPTION | 468 PARSE_OPT_KEEP_DASHDASH); 469 if (argc != 0) { 470 /* Cusrom options, should have been handled elsewhere */ 471 if (strcmp(argv[0], "--") == 0) { 472 if (kvm_run_wrapper == KVM_RUN_SANDBOX) { 473 kvm->cfg.sandbox = DEFAULT_SANDBOX_FILENAME; 474 kvm_run_write_sandbox_cmd(kvm, argv+1, argc-1); 475 break; 476 } 477 } 478 479 if ((kvm_run_wrapper == KVM_RUN_DEFAULT && kvm->cfg.kernel_filename) || 480 (kvm_run_wrapper == KVM_RUN_SANDBOX && kvm->cfg.sandbox)) { 481 fprintf(stderr, "Cannot handle parameter: " 482 "%s\n", argv[0]); 483 usage_with_options(run_usage, options); 484 free(kvm); 485 return ERR_PTR(-EINVAL); 486 } 487 if (kvm_run_wrapper == KVM_RUN_SANDBOX) { 488 /* 489 * first unhandled parameter is treated as 490 * sandbox command 491 */ 492 kvm->cfg.sandbox = DEFAULT_SANDBOX_FILENAME; 493 kvm_run_write_sandbox_cmd(kvm, argv, argc); 494 } else { 495 /* 496 * first unhandled parameter is treated as a kernel 497 * image 498 */ 499 kvm->cfg.kernel_filename = argv[0]; 500 } 501 argv++; 502 argc--; 503 } 504 505 } 506 507 kvm->nr_disks = kvm->cfg.image_count; 508 509 if (!kvm->cfg.kernel_filename) 510 kvm->cfg.kernel_filename = find_kernel(); 511 512 if (!kvm->cfg.kernel_filename) { 513 kernel_usage_with_options(); 514 return ERR_PTR(-EINVAL); 515 } 516 517 kvm->cfg.vmlinux_filename = find_vmlinux(); 518 kvm->vmlinux = kvm->cfg.vmlinux_filename; 519 520 if (kvm->cfg.nrcpus == 0) 521 kvm->cfg.nrcpus = nr_online_cpus; 522 523 if (!kvm->cfg.ram_size) 524 kvm->cfg.ram_size = get_ram_size(kvm->cfg.nrcpus); 525 526 if (kvm->cfg.ram_size > host_ram_size()) 527 pr_warning("Guest memory size %lluMB exceeds host physical RAM size %lluMB", 528 (unsigned long long)kvm->cfg.ram_size, 529 (unsigned long long)host_ram_size()); 530 531 kvm->cfg.ram_size <<= MB_SHIFT; 532 533 if (!kvm->cfg.dev) 534 kvm->cfg.dev = DEFAULT_KVM_DEV; 535 536 if (!kvm->cfg.console) 537 kvm->cfg.console = DEFAULT_CONSOLE; 538 539 if (!strncmp(kvm->cfg.console, "virtio", 6)) 540 kvm->cfg.active_console = CONSOLE_VIRTIO; 541 else if (!strncmp(kvm->cfg.console, "serial", 6)) 542 kvm->cfg.active_console = CONSOLE_8250; 543 else if (!strncmp(kvm->cfg.console, "hv", 2)) 544 kvm->cfg.active_console = CONSOLE_HV; 545 else 546 pr_warning("No console!"); 547 548 if (!kvm->cfg.host_ip) 549 kvm->cfg.host_ip = DEFAULT_HOST_ADDR; 550 551 if (!kvm->cfg.guest_ip) 552 kvm->cfg.guest_ip = DEFAULT_GUEST_ADDR; 553 554 if (!kvm->cfg.guest_mac) 555 kvm->cfg.guest_mac = DEFAULT_GUEST_MAC; 556 557 if (!kvm->cfg.host_mac) 558 kvm->cfg.host_mac = DEFAULT_HOST_MAC; 559 560 if (!kvm->cfg.script) 561 kvm->cfg.script = DEFAULT_SCRIPT; 562 563 if (!kvm->cfg.network) 564 kvm->cfg.network = DEFAULT_NETWORK; 565 566 memset(real_cmdline, 0, sizeof(real_cmdline)); 567 kvm__arch_set_cmdline(real_cmdline, kvm->cfg.vnc || kvm->cfg.sdl || kvm->cfg.gtk); 568 569 if (!kvm->cfg.guest_name) { 570 if (kvm->cfg.custom_rootfs) { 571 kvm->cfg.guest_name = kvm->cfg.custom_rootfs_name; 572 } else { 573 sprintf(default_name, "guest-%u", getpid()); 574 kvm->cfg.guest_name = default_name; 575 } 576 } 577 578 if (!kvm->cfg.using_rootfs && !kvm->cfg.disk_image[0].filename && !kvm->cfg.initrd_filename) { 579 char tmp[PATH_MAX]; 580 581 kvm_setup_create_new(kvm->cfg.custom_rootfs_name); 582 kvm_setup_resolv(kvm->cfg.custom_rootfs_name); 583 584 snprintf(tmp, PATH_MAX, "%s%s", kvm__get_dir(), "default"); 585 if (virtio_9p__register(kvm, tmp, "/dev/root") < 0) 586 die("Unable to initialize virtio 9p"); 587 if (virtio_9p__register(kvm, "/", "hostfs") < 0) 588 die("Unable to initialize virtio 9p"); 589 kvm->cfg.using_rootfs = kvm->cfg.custom_rootfs = 1; 590 } 591 592 if (kvm->cfg.using_rootfs) { 593 strcat(real_cmdline, " rw rootflags=trans=virtio,version=9p2000.L,cache=loose rootfstype=9p"); 594 if (kvm->cfg.custom_rootfs) { 595 kvm_run_set_sandbox(kvm); 596 597 #ifdef CONFIG_GUEST_PRE_INIT 598 strcat(real_cmdline, " init=/virt/pre_init"); 599 #else 600 strcat(real_cmdline, " init=/virt/init"); 601 #endif 602 603 if (!kvm->cfg.no_dhcp) 604 strcat(real_cmdline, " ip=dhcp"); 605 if (kvm_setup_guest_init(kvm->cfg.custom_rootfs_name)) 606 die("Failed to setup init for guest."); 607 } 608 } else if (!kvm->cfg.kernel_cmdline || !strstr(kvm->cfg.kernel_cmdline, "root=")) { 609 strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); 610 } 611 612 if (kvm->cfg.kernel_cmdline) { 613 strcat(real_cmdline, " "); 614 strlcat(real_cmdline, kvm->cfg.kernel_cmdline, sizeof(real_cmdline)); 615 } 616 617 kvm->cfg.real_cmdline = real_cmdline; 618 619 printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME, 620 kvm->cfg.kernel_filename, 621 (unsigned long long)kvm->cfg.ram_size / 1024 / 1024, 622 kvm->cfg.nrcpus, kvm->cfg.guest_name); 623 624 if (init_list__init(kvm) < 0) 625 die ("Initialisation failed"); 626 627 return kvm; 628 } 629 630 static int kvm_cmd_run_work(struct kvm *kvm) 631 { 632 int i; 633 void *ret = NULL; 634 635 for (i = 0; i < kvm->nrcpus; i++) { 636 if (pthread_create(&kvm->cpus[i]->thread, NULL, kvm_cpu_thread, kvm->cpus[i]) != 0) 637 die("unable to create KVM VCPU thread"); 638 } 639 640 /* Only VCPU #0 is going to exit by itself when shutting down */ 641 return pthread_join(kvm->cpus[0]->thread, &ret); 642 } 643 644 static void kvm_cmd_run_exit(struct kvm *kvm, int guest_ret) 645 { 646 compat__print_all_messages(); 647 648 init_list__exit(kvm); 649 650 if (guest_ret == 0) 651 printf("\n # KVM session ended normally.\n"); 652 } 653 654 int kvm_cmd_run(int argc, const char **argv, const char *prefix) 655 { 656 int ret = -EFAULT; 657 struct kvm *kvm; 658 659 kvm = kvm_cmd_run_init(argc, argv); 660 if (IS_ERR(kvm)) 661 return PTR_ERR(kvm); 662 663 ret = kvm_cmd_run_work(kvm); 664 kvm_cmd_run_exit(kvm, ret); 665 666 return ret; 667 } 668