qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Remove broken Xen PV domain builder

It is broken since Xen 4.9 [1] and it will not build in Xen 4.12. Also,
it is not built by default since QEMU 2.6.

[1] https://lists.xenproject.org/archives/html/xen-devel/2018-09/msg00313.html

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>

-379
-17
configure
··· 357 357 xkbcommon="" 358 358 xen="" 359 359 xen_ctrl_version="" 360 - xen_pv_domain_build="no" 361 360 xen_pci_passthrough="" 362 361 linux_aio="" 363 362 cap_ng="" ··· 1119 1118 ;; 1120 1119 --enable-xen-pci-passthrough) xen_pci_passthrough="yes" 1121 1120 ;; 1122 - --disable-xen-pv-domain-build) xen_pv_domain_build="no" 1123 - ;; 1124 - --enable-xen-pv-domain-build) xen_pv_domain_build="yes" 1125 - ;; 1126 1121 --disable-brlapi) brlapi="no" 1127 1122 ;; 1128 1123 --enable-brlapi) brlapi="yes" ··· 1685 1680 --tls-priority default TLS protocol/cipher priority string 1686 1681 --enable-gprof QEMU profiling with gprof 1687 1682 --enable-profiler profiler support 1688 - --enable-xen-pv-domain-build 1689 - xen pv domain builder 1690 1683 --enable-debug-stack-usage 1691 1684 track the maximum stack usage of stacks created by qemu_alloc_stack 1692 1685 ··· 2676 2669 fi 2677 2670 xen_pci_passthrough=no 2678 2671 fi 2679 - fi 2680 - 2681 - if test "$xen_pv_domain_build" = "yes" && 2682 - test "$xen" != "yes"; then 2683 - error_exit "User requested Xen PV domain builder support" \ 2684 - "which requires Xen support." 2685 2672 fi 2686 2673 2687 2674 ########################################## ··· 6069 6056 echo "xen support $xen" 6070 6057 if test "$xen" = "yes" ; then 6071 6058 echo "xen ctrl version $xen_ctrl_version" 6072 - echo "pv dom build $xen_pv_domain_build" 6073 6059 fi 6074 6060 echo "brlapi support $brlapi" 6075 6061 echo "bluez support $bluez" ··· 6539 6525 if test "$xen" = "yes" ; then 6540 6526 echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak 6541 6527 echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak 6542 - if test "$xen_pv_domain_build" = "yes" ; then 6543 - echo "CONFIG_XEN_PV_DOMAIN_BUILD=y" >> $config_host_mak 6544 - fi 6545 6528 fi 6546 6529 if test "$linux_aio" = "yes" ; then 6547 6530 echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
-2
hw/xenpv/Makefile.objs
··· 1 1 # Xen PV machine support 2 2 obj-$(CONFIG_XEN) += xen_machine_pv.o 3 - # Xen PV machine builder support 4 - obj-$(CONFIG_XEN_PV_DOMAIN_BUILD) += xen_domainbuild.o
-299
hw/xenpv/xen_domainbuild.c
··· 1 - #include "qemu/osdep.h" 2 - #include "qemu/units.h" 3 - #include "hw/xen/xen-legacy-backend.h" 4 - #include "xen_domainbuild.h" 5 - #include "qemu/timer.h" 6 - #include "qemu/log.h" 7 - 8 - #include <xenguest.h> 9 - 10 - static int xenstore_domain_mkdir(char *path) 11 - { 12 - struct xs_permissions perms_ro[] = {{ 13 - .id = 0, /* set owner: dom0 */ 14 - },{ 15 - .id = xen_domid, 16 - .perms = XS_PERM_READ, 17 - }}; 18 - struct xs_permissions perms_rw[] = {{ 19 - .id = 0, /* set owner: dom0 */ 20 - },{ 21 - .id = xen_domid, 22 - .perms = XS_PERM_READ | XS_PERM_WRITE, 23 - }}; 24 - const char *writable[] = { "device", "control", "error", NULL }; 25 - char subpath[256]; 26 - int i; 27 - 28 - if (!xs_mkdir(xenstore, 0, path)) { 29 - fprintf(stderr, "%s: xs_mkdir %s: failed\n", __func__, path); 30 - return -1; 31 - } 32 - if (!xs_set_permissions(xenstore, 0, path, perms_ro, 2)) { 33 - fprintf(stderr, "%s: xs_set_permissions failed\n", __func__); 34 - return -1; 35 - } 36 - 37 - for (i = 0; writable[i]; i++) { 38 - snprintf(subpath, sizeof(subpath), "%s/%s", path, writable[i]); 39 - if (!xs_mkdir(xenstore, 0, subpath)) { 40 - fprintf(stderr, "%s: xs_mkdir %s: failed\n", __func__, subpath); 41 - return -1; 42 - } 43 - if (!xs_set_permissions(xenstore, 0, subpath, perms_rw, 2)) { 44 - fprintf(stderr, "%s: xs_set_permissions failed\n", __func__); 45 - return -1; 46 - } 47 - } 48 - return 0; 49 - } 50 - 51 - int xenstore_domain_init1(const char *kernel, const char *ramdisk, 52 - const char *cmdline) 53 - { 54 - char *dom, uuid_string[42], vm[256], path[256]; 55 - int i; 56 - 57 - qemu_uuid_unparse(&qemu_uuid, uuid_string); 58 - dom = xs_get_domain_path(xenstore, xen_domid); 59 - snprintf(vm, sizeof(vm), "/vm/%s", uuid_string); 60 - 61 - xenstore_domain_mkdir(dom); 62 - 63 - xenstore_write_str(vm, "image/ostype", "linux"); 64 - if (kernel) 65 - xenstore_write_str(vm, "image/kernel", kernel); 66 - if (ramdisk) 67 - xenstore_write_str(vm, "image/ramdisk", ramdisk); 68 - if (cmdline) 69 - xenstore_write_str(vm, "image/cmdline", cmdline); 70 - 71 - /* name + id */ 72 - xenstore_write_str(vm, "name", qemu_name ? qemu_name : "no-name"); 73 - xenstore_write_str(vm, "uuid", uuid_string); 74 - xenstore_write_str(dom, "name", qemu_name ? qemu_name : "no-name"); 75 - xenstore_write_int(dom, "domid", xen_domid); 76 - xenstore_write_str(dom, "vm", vm); 77 - 78 - /* memory */ 79 - xenstore_write_int(dom, "memory/target", ram_size / KiB); 80 - xenstore_write_int(vm, "memory", ram_size / MiB); 81 - xenstore_write_int(vm, "maxmem", ram_size / MiB); 82 - 83 - /* cpus */ 84 - for (i = 0; i < smp_cpus; i++) { 85 - snprintf(path, sizeof(path), "cpu/%d/availability",i); 86 - xenstore_write_str(dom, path, "online"); 87 - } 88 - xenstore_write_int(vm, "vcpu_avail", smp_cpus); 89 - xenstore_write_int(vm, "vcpus", smp_cpus); 90 - 91 - /* vnc password */ 92 - xenstore_write_str(vm, "vncpassword", "" /* FIXME */); 93 - 94 - free(dom); 95 - return 0; 96 - } 97 - 98 - int xenstore_domain_init2(int xenstore_port, int xenstore_mfn, 99 - int console_port, int console_mfn) 100 - { 101 - char *dom; 102 - 103 - dom = xs_get_domain_path(xenstore, xen_domid); 104 - 105 - /* signal new domain */ 106 - xs_introduce_domain(xenstore, 107 - xen_domid, 108 - xenstore_mfn, 109 - xenstore_port); 110 - 111 - /* xenstore */ 112 - xenstore_write_int(dom, "store/ring-ref", xenstore_mfn); 113 - xenstore_write_int(dom, "store/port", xenstore_port); 114 - 115 - /* console */ 116 - xenstore_write_str(dom, "console/type", "ioemu"); 117 - xenstore_write_int(dom, "console/limit", 128 * KiB); 118 - xenstore_write_int(dom, "console/ring-ref", console_mfn); 119 - xenstore_write_int(dom, "console/port", console_port); 120 - xen_config_dev_console(0); 121 - 122 - free(dom); 123 - return 0; 124 - } 125 - 126 - /* ------------------------------------------------------------- */ 127 - 128 - static QEMUTimer *xen_poll; 129 - 130 - /* check domain state once per second */ 131 - static void xen_domain_poll(void *opaque) 132 - { 133 - struct xc_dominfo info; 134 - int rc; 135 - 136 - rc = xc_domain_getinfo(xen_xc, xen_domid, 1, &info); 137 - if ((rc != 1) || (info.domid != xen_domid)) { 138 - qemu_log("xen: domain %d is gone\n", xen_domid); 139 - goto quit; 140 - } 141 - if (info.dying) { 142 - qemu_log("xen: domain %d is dying (%s%s)\n", xen_domid, 143 - info.crashed ? "crashed" : "", 144 - info.shutdown ? "shutdown" : ""); 145 - goto quit; 146 - } 147 - 148 - timer_mod(xen_poll, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 149 - return; 150 - 151 - quit: 152 - qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); 153 - } 154 - 155 - static int xen_domain_watcher(void) 156 - { 157 - int qemu_running = 1; 158 - int fd[2], i, n, rc; 159 - char byte; 160 - 161 - if (pipe(fd) != 0) { 162 - qemu_log("%s: Huh? pipe error: %s\n", __func__, strerror(errno)); 163 - return -1; 164 - } 165 - if (fork() != 0) 166 - return 0; /* not child */ 167 - 168 - /* close all file handles, except stdio/out/err, 169 - * our watch pipe and the xen interface handle */ 170 - n = getdtablesize(); 171 - for (i = 3; i < n; i++) { 172 - if (i == fd[0]) 173 - continue; 174 - close(i); 175 - } 176 - 177 - /* 178 - * Reopen xc interface, since the original is unsafe after fork 179 - * and was closed above. 180 - */ 181 - xen_xc = xc_interface_open(0, 0, 0); 182 - 183 - /* ignore term signals */ 184 - signal(SIGINT, SIG_IGN); 185 - signal(SIGTERM, SIG_IGN); 186 - 187 - /* wait for qemu exiting */ 188 - while (qemu_running) { 189 - rc = read(fd[0], &byte, 1); 190 - switch (rc) { 191 - case -1: 192 - if (errno == EINTR) 193 - continue; 194 - qemu_log("%s: Huh? read error: %s\n", __func__, strerror(errno)); 195 - qemu_running = 0; 196 - break; 197 - case 0: 198 - /* EOF -> qemu exited */ 199 - qemu_running = 0; 200 - break; 201 - default: 202 - qemu_log("%s: Huh? data on the watch pipe?\n", __func__); 203 - break; 204 - } 205 - } 206 - 207 - /* cleanup */ 208 - qemu_log("%s: destroy domain %d\n", __func__, xen_domid); 209 - xc_domain_destroy(xen_xc, xen_domid); 210 - _exit(0); 211 - } 212 - 213 - /* normal cleanup */ 214 - static void xen_domain_cleanup(void) 215 - { 216 - char *dom; 217 - 218 - dom = xs_get_domain_path(xenstore, xen_domid); 219 - if (dom) { 220 - xs_rm(xenstore, 0, dom); 221 - free(dom); 222 - } 223 - xs_release_domain(xenstore, xen_domid); 224 - } 225 - 226 - int xen_domain_build_pv(const char *kernel, const char *ramdisk, 227 - const char *cmdline) 228 - { 229 - uint32_t ssidref = 0; 230 - uint32_t flags = 0; 231 - xen_domain_handle_t uuid; 232 - unsigned int xenstore_port = 0, console_port = 0; 233 - unsigned long xenstore_mfn = 0, console_mfn = 0; 234 - int rc; 235 - 236 - memcpy(uuid, &qemu_uuid, sizeof(uuid)); 237 - rc = xen_domain_create(xen_xc, ssidref, uuid, flags, &xen_domid); 238 - if (rc < 0) { 239 - fprintf(stderr, "xen: xc_domain_create() failed\n"); 240 - goto err; 241 - } 242 - qemu_log("xen: created domain %d\n", xen_domid); 243 - atexit(xen_domain_cleanup); 244 - if (xen_domain_watcher() == -1) { 245 - goto err; 246 - } 247 - 248 - xenstore_domain_init1(kernel, ramdisk, cmdline); 249 - 250 - rc = xc_domain_max_vcpus(xen_xc, xen_domid, smp_cpus); 251 - if (rc < 0) { 252 - fprintf(stderr, "xen: xc_domain_max_vcpus() failed\n"); 253 - goto err; 254 - } 255 - 256 - #if 0 257 - rc = xc_domain_setcpuweight(xen_xc, xen_domid, 256); 258 - if (rc < 0) { 259 - fprintf(stderr, "xen: xc_domain_setcpuweight() failed\n"); 260 - goto err; 261 - } 262 - #endif 263 - 264 - rc = xc_domain_setmaxmem(xen_xc, xen_domid, ram_size / KiB); 265 - if (rc < 0) { 266 - fprintf(stderr, "xen: xc_domain_setmaxmem() failed\n"); 267 - goto err; 268 - } 269 - 270 - xenstore_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0); 271 - console_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0); 272 - 273 - rc = xc_linux_build(xen_xc, xen_domid, ram_size / MiB, 274 - kernel, ramdisk, cmdline, 275 - 0, flags, 276 - xenstore_port, &xenstore_mfn, 277 - console_port, &console_mfn); 278 - if (rc < 0) { 279 - fprintf(stderr, "xen: xc_linux_build() failed\n"); 280 - goto err; 281 - } 282 - 283 - xenstore_domain_init2(xenstore_port, xenstore_mfn, 284 - console_port, console_mfn); 285 - 286 - qemu_log("xen: unpausing domain %d\n", xen_domid); 287 - rc = xc_domain_unpause(xen_xc, xen_domid); 288 - if (rc < 0) { 289 - fprintf(stderr, "xen: xc_domain_unpause() failed\n"); 290 - goto err; 291 - } 292 - 293 - xen_poll = timer_new_ms(QEMU_CLOCK_REALTIME, xen_domain_poll, NULL); 294 - timer_mod(xen_poll, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 295 - return 0; 296 - 297 - err: 298 - return -1; 299 - }
-13
hw/xenpv/xen_domainbuild.h
··· 1 - #ifndef QEMU_HW_XEN_DOMAINBUILD_H 2 - #define QEMU_HW_XEN_DOMAINBUILD_H 3 - 4 - #include "hw/xen/xen_common.h" 5 - 6 - int xenstore_domain_init1(const char *kernel, const char *ramdisk, 7 - const char *cmdline); 8 - int xenstore_domain_init2(int xenstore_port, int xenstore_mfn, 9 - int console_port, int console_mfn); 10 - int xen_domain_build_pv(const char *kernel, const char *ramdisk, 11 - const char *cmdline); 12 - 13 - #endif /* QEMU_HW_XEN_DOMAINBUILD_H */
-14
hw/xenpv/xen_machine_pv.c
··· 28 28 #include "hw/boards.h" 29 29 #include "hw/xen/xen-legacy-backend.h" 30 30 #include "hw/xen/xen-bus.h" 31 - #include "xen_domainbuild.h" 32 31 #include "sysemu/block-backend.h" 33 32 34 33 static void xen_init_pv(MachineState *machine) ··· 46 45 case XEN_ATTACH: 47 46 /* nothing to do, xend handles everything */ 48 47 break; 49 - #ifdef CONFIG_XEN_PV_DOMAIN_BUILD 50 - case XEN_CREATE: { 51 - const char *kernel_filename = machine->kernel_filename; 52 - const char *kernel_cmdline = machine->kernel_cmdline; 53 - const char *initrd_filename = machine->initrd_filename; 54 - if (xen_domain_build_pv(kernel_filename, initrd_filename, 55 - kernel_cmdline) < 0) { 56 - error_report("xen pv domain creation failed"); 57 - exit(1); 58 - } 59 - break; 60 - } 61 - #endif 62 48 case XEN_EMULATE: 63 49 error_report("xen emulation not implemented (yet)"); 64 50 exit(1);
-1
include/hw/xen/xen.h
··· 15 15 /* xen-machine.c */ 16 16 enum xen_mode { 17 17 XEN_EMULATE = 0, // xen emulation, using xenner (default) 18 - XEN_CREATE, // create xen domain 19 18 XEN_ATTACH // attach to xen domain created by xend 20 19 }; 21 20
-18
include/hw/xen/xen_common.h
··· 662 662 663 663 #endif 664 664 665 - #ifdef CONFIG_XEN_PV_DOMAIN_BUILD 666 - #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40700 667 - static inline int xen_domain_create(xc_interface *xc, uint32_t ssidref, 668 - xen_domain_handle_t handle, uint32_t flags, 669 - uint32_t *pdomid) 670 - { 671 - return xc_domain_create(xc, ssidref, handle, flags, pdomid); 672 - } 673 - #else 674 - static inline int xen_domain_create(xc_interface *xc, uint32_t ssidref, 675 - xen_domain_handle_t handle, uint32_t flags, 676 - uint32_t *pdomid) 677 - { 678 - return xc_domain_create(xc, ssidref, handle, flags, pdomid, NULL); 679 - } 680 - #endif 681 - #endif 682 - 683 665 /* Xen before 4.8 */ 684 666 685 667 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40800
-8
qemu-options.hx
··· 3394 3394 3395 3395 DEF("xen-domid", HAS_ARG, QEMU_OPTION_xen_domid, 3396 3396 "-xen-domid id specify xen guest domain id\n", QEMU_ARCH_ALL) 3397 - DEF("xen-create", 0, QEMU_OPTION_xen_create, 3398 - "-xen-create create domain using xen hypercalls, bypassing xend\n" 3399 - " warning: should not be used when xend is in use\n", 3400 - QEMU_ARCH_ALL) 3401 3397 DEF("xen-attach", 0, QEMU_OPTION_xen_attach, 3402 3398 "-xen-attach attach to existing xen domain\n" 3403 3399 " xend will use this when starting QEMU\n", ··· 3411 3407 @item -xen-domid @var{id} 3412 3408 @findex -xen-domid 3413 3409 Specify xen guest domain @var{id} (XEN only). 3414 - @item -xen-create 3415 - @findex -xen-create 3416 - Create domain using xen hypercalls, bypassing xend. 3417 - Warning: should not be used when xend is in use (XEN only). 3418 3410 @item -xen-attach 3419 3411 @findex -xen-attach 3420 3412 Attach to existing xen domain.
-7
vl.c
··· 3856 3856 } 3857 3857 xen_domid = atoi(optarg); 3858 3858 break; 3859 - case QEMU_OPTION_xen_create: 3860 - if (!(xen_available())) { 3861 - error_report("Option not supported for this target"); 3862 - exit(1); 3863 - } 3864 - xen_mode = XEN_CREATE; 3865 - break; 3866 3859 case QEMU_OPTION_xen_attach: 3867 3860 if (!(xen_available())) { 3868 3861 error_report("Option not supported for this target");