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

Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging

virtio, pci, pc: bugfixes, checkpatch, maintainers

Bugfixes all over the place.
Add a new balloon maintainer.
A checkpatch enhancement to enforce ACPI change rules.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

# gpg: Signature made Tue 31 Mar 2020 15:54:36 BST
# gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469
# gpg: issuer "mst@redhat.com"
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>" [full]
# gpg: aka "Michael S. Tsirkin <mst@redhat.com>" [full]
# Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67
# Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469

* remotes/mst/tags/for_upstream:
vhost-vsock: fix double close() in the realize() error path
acpi: add acpi=OnOffAuto machine property to x86 and arm virt
fix vhost_user_blk_watch crash
hw/i386/amd_iommu.c: Fix corruption of log events passed to guest
virtio-iommu: avoid memleak in the unrealize
virtio-blk: delete vqs on the error path in realize()
acpi: pcihp: fix left shift undefined behavior in acpi_pcihp_eject_slot()
virtio-serial-bus: Plug memory leak on realize() error paths
MAINTAINERS: Add myself as virtio-balloon co-maintainer
checkpatch: enforce process for expected files

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+126 -34
+9
MAINTAINERS
··· 1634 1634 F: net/vhost-user.c 1635 1635 F: include/hw/virtio/ 1636 1636 1637 + virtio-balloon 1638 + M: Michael S. Tsirkin <mst@redhat.com> 1639 + M: David Hildenbrand <david@redhat.com> 1640 + S: Maintained 1641 + F: hw/virtio/virtio-balloon*.c 1642 + F: include/hw/virtio/virtio-balloon.h 1643 + F: balloon.c 1644 + F: include/sysemu/balloon.h 1645 + 1637 1646 virtio-9p 1638 1647 M: Greg Kurz <groug@kaod.org> 1639 1648 R: Christian Schoenebeck <qemu_oss@crudebyte.com>
+1 -1
hw/acpi/pcihp.c
··· 154 154 155 155 trace_acpi_pci_eject_slot(bsel, slot); 156 156 157 - if (!bus) { 157 + if (!bus || slot > 31) { 158 158 return; 159 159 } 160 160
+1 -1
hw/arm/virt-acpi-build.c
··· 910 910 return; 911 911 } 912 912 913 - if (!acpi_enabled) { 913 + if (!virt_is_acpi_enabled(vms)) { 914 914 trace_virt_acpi_setup(); 915 915 return; 916 916 }
+34 -2
hw/arm/virt.c
··· 67 67 #include "kvm_arm.h" 68 68 #include "hw/firmware/smbios.h" 69 69 #include "qapi/visitor.h" 70 + #include "qapi/qapi-visit-common.h" 70 71 #include "standard-headers/linux/input.h" 71 72 #include "hw/arm/smmuv3.h" 72 73 #include "hw/acpi/acpi.h" ··· 1844 1845 1845 1846 create_pcie(vms); 1846 1847 1847 - if (has_ged && aarch64 && firmware_loaded && acpi_enabled) { 1848 + if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) { 1848 1849 vms->acpi_dev = create_acpi_ged(vms); 1849 1850 } else { 1850 1851 create_gpio(vms); ··· 1934 1935 vms->its = value; 1935 1936 } 1936 1937 1938 + bool virt_is_acpi_enabled(VirtMachineState *vms) 1939 + { 1940 + if (vms->acpi == ON_OFF_AUTO_OFF) { 1941 + return false; 1942 + } 1943 + return true; 1944 + } 1945 + 1946 + static void virt_get_acpi(Object *obj, Visitor *v, const char *name, 1947 + void *opaque, Error **errp) 1948 + { 1949 + VirtMachineState *vms = VIRT_MACHINE(obj); 1950 + OnOffAuto acpi = vms->acpi; 1951 + 1952 + visit_type_OnOffAuto(v, name, &acpi, errp); 1953 + } 1954 + 1955 + static void virt_set_acpi(Object *obj, Visitor *v, const char *name, 1956 + void *opaque, Error **errp) 1957 + { 1958 + VirtMachineState *vms = VIRT_MACHINE(obj); 1959 + 1960 + visit_type_OnOffAuto(v, name, &vms->acpi, errp); 1961 + } 1962 + 1937 1963 static char *virt_get_gic_version(Object *obj, Error **errp) 1938 1964 { 1939 1965 VirtMachineState *vms = VIRT_MACHINE(obj); ··· 2113 2139 if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { 2114 2140 VirtMachineState *vms = VIRT_MACHINE(machine); 2115 2141 2116 - if (!vms->bootinfo.firmware_loaded || !acpi_enabled) { 2142 + if (!vms->bootinfo.firmware_loaded || !virt_is_acpi_enabled(vms)) { 2117 2143 return HOTPLUG_HANDLER(machine); 2118 2144 } 2119 2145 } ··· 2184 2210 mc->numa_mem_supported = true; 2185 2211 mc->auto_enable_numa_with_memhp = true; 2186 2212 mc->default_ram_id = "mach-virt.ram"; 2213 + 2214 + object_class_property_add(oc, "acpi", "OnOffAuto", 2215 + virt_get_acpi, virt_set_acpi, 2216 + NULL, NULL, &error_abort); 2217 + object_class_property_set_description(oc, "acpi", 2218 + "Enable ACPI", &error_abort); 2187 2219 } 2188 2220 2189 2221 static void virt_instance_init(Object *obj)
-19
hw/block/vhost-user-blk.c
··· 349 349 vhost_dev_cleanup(&s->dev); 350 350 } 351 351 352 - static gboolean vhost_user_blk_watch(GIOChannel *chan, GIOCondition cond, 353 - void *opaque) 354 - { 355 - DeviceState *dev = opaque; 356 - VirtIODevice *vdev = VIRTIO_DEVICE(dev); 357 - VHostUserBlk *s = VHOST_USER_BLK(vdev); 358 - 359 - qemu_chr_fe_disconnect(&s->chardev); 360 - 361 - return true; 362 - } 363 - 364 352 static void vhost_user_blk_event(void *opaque, QEMUChrEvent event) 365 353 { 366 354 DeviceState *dev = opaque; ··· 373 361 qemu_chr_fe_disconnect(&s->chardev); 374 362 return; 375 363 } 376 - s->watch = qemu_chr_fe_add_watch(&s->chardev, G_IO_HUP, 377 - vhost_user_blk_watch, dev); 378 364 break; 379 365 case CHR_EVENT_CLOSED: 380 366 vhost_user_blk_disconnect(dev); 381 - if (s->watch) { 382 - g_source_remove(s->watch); 383 - s->watch = 0; 384 - } 385 367 break; 386 368 case CHR_EVENT_BREAK: 387 369 case CHR_EVENT_MUX_IN: ··· 428 410 429 411 s->inflight = g_new0(struct vhost_inflight, 1); 430 412 s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues); 431 - s->watch = 0; 432 413 s->connected = false; 433 414 434 415 qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event,
+3
hw/block/virtio-blk.c
··· 1204 1204 virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err); 1205 1205 if (err != NULL) { 1206 1206 error_propagate(errp, err); 1207 + for (i = 0; i < conf->num_queues; i++) { 1208 + virtio_del_queue(vdev, i); 1209 + } 1207 1210 virtio_cleanup(vdev); 1208 1211 return; 1209 1212 }
+1 -1
hw/char/virtio-serial-bus.c
··· 943 943 Error *err = NULL; 944 944 945 945 port->vser = bus->vser; 946 - port->bh = qemu_bh_new(flush_queued_data_bh, port); 947 946 948 947 assert(vsc->have_data); 949 948 ··· 992 991 return; 993 992 } 994 993 994 + port->bh = qemu_bh_new(flush_queued_data_bh, port); 995 995 port->elem = NULL; 996 996 } 997 997
+1 -1
hw/i386/acpi-build.c
··· 3024 3024 return; 3025 3025 } 3026 3026 3027 - if (!acpi_enabled) { 3027 + if (!x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) { 3028 3028 ACPI_BUILD_DPRINTF("ACPI disabled. Bailing out.\n"); 3029 3029 return; 3030 3030 }
+1 -1
hw/i386/amd_iommu.c
··· 181 181 } 182 182 183 183 if (dma_memory_write(&address_space_memory, s->evtlog + s->evtlog_tail, 184 - &evt, AMDVI_EVENT_LEN)) { 184 + evt, AMDVI_EVENT_LEN)) { 185 185 trace_amdvi_evntlog_fail(s->evtlog, s->evtlog_tail); 186 186 } 187 187
+2 -2
hw/i386/pc.c
··· 1297 1297 * but pcms->acpi_dev is still created. Check !acpi_enabled in 1298 1298 * addition to cover this case. 1299 1299 */ 1300 - if (!pcms->acpi_dev || !acpi_enabled) { 1300 + if (!pcms->acpi_dev || !x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) { 1301 1301 error_setg(errp, 1302 1302 "memory hotplug is not enabled: missing acpi device or acpi disabled"); 1303 1303 return; ··· 1351 1351 * but pcms->acpi_dev is still created. Check !acpi_enabled in 1352 1352 * addition to cover this case. 1353 1353 */ 1354 - if (!pcms->acpi_dev || !acpi_enabled) { 1354 + if (!pcms->acpi_dev || !x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) { 1355 1355 error_setg(&local_err, 1356 1356 "memory hotplug is not enabled: missing acpi device or acpi disabled"); 1357 1357 goto out;
+1 -1
hw/i386/pc_piix.c
··· 275 275 pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci"); 276 276 } 277 277 278 - if (pcmc->pci_enabled && acpi_enabled) { 278 + if (pcmc->pci_enabled && x86_machine_is_acpi_enabled(X86_MACHINE(pcms))) { 279 279 DeviceState *piix4_pm; 280 280 281 281 smi_irq = qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0);
+32
hw/i386/x86.c
··· 904 904 visit_type_OnOffAuto(v, name, &x86ms->smm, errp); 905 905 } 906 906 907 + bool x86_machine_is_acpi_enabled(X86MachineState *x86ms) 908 + { 909 + if (x86ms->acpi == ON_OFF_AUTO_OFF) { 910 + return false; 911 + } 912 + return true; 913 + } 914 + 915 + static void x86_machine_get_acpi(Object *obj, Visitor *v, const char *name, 916 + void *opaque, Error **errp) 917 + { 918 + X86MachineState *x86ms = X86_MACHINE(obj); 919 + OnOffAuto acpi = x86ms->acpi; 920 + 921 + visit_type_OnOffAuto(v, name, &acpi, errp); 922 + } 923 + 924 + static void x86_machine_set_acpi(Object *obj, Visitor *v, const char *name, 925 + void *opaque, Error **errp) 926 + { 927 + X86MachineState *x86ms = X86_MACHINE(obj); 928 + 929 + visit_type_OnOffAuto(v, name, &x86ms->acpi, errp); 930 + } 931 + 907 932 static void x86_machine_initfn(Object *obj) 908 933 { 909 934 X86MachineState *x86ms = X86_MACHINE(obj); 910 935 911 936 x86ms->smm = ON_OFF_AUTO_AUTO; 937 + x86ms->acpi = ON_OFF_AUTO_AUTO; 912 938 x86ms->max_ram_below_4g = 0; /* use default */ 913 939 x86ms->smp_dies = 1; 914 940 } ··· 937 963 NULL, NULL, &error_abort); 938 964 object_class_property_set_description(oc, X86_MACHINE_SMM, 939 965 "Enable SMM", &error_abort); 966 + 967 + object_class_property_add(oc, X86_MACHINE_ACPI, "OnOffAuto", 968 + x86_machine_get_acpi, x86_machine_set_acpi, 969 + NULL, NULL, &error_abort); 970 + object_class_property_set_description(oc, X86_MACHINE_ACPI, 971 + "Enable ACPI", &error_abort); 940 972 } 941 973 942 974 static const TypeInfo x86_machine_info = {
+5 -1
hw/virtio/vhost-vsock.c
··· 364 364 365 365 err_vhost_dev: 366 366 vhost_dev_cleanup(&vsock->vhost_dev); 367 + /* vhost_dev_cleanup() closes the vhostfd passed to vhost_dev_init() */ 368 + vhostfd = -1; 367 369 err_virtio: 368 370 virtio_delete_queue(vsock->recv_vq); 369 371 virtio_delete_queue(vsock->trans_vq); 370 372 virtio_delete_queue(vsock->event_vq); 371 373 virtio_cleanup(vdev); 372 - close(vhostfd); 374 + if (vhostfd >= 0) { 375 + close(vhostfd); 376 + } 373 377 return; 374 378 } 375 379
+3
hw/virtio/virtio-iommu.c
··· 693 693 VirtIODevice *vdev = VIRTIO_DEVICE(dev); 694 694 VirtIOIOMMU *s = VIRTIO_IOMMU(dev); 695 695 696 + g_hash_table_destroy(s->as_by_busptr); 696 697 g_tree_destroy(s->domains); 697 698 g_tree_destroy(s->endpoints); 698 699 700 + virtio_delete_queue(s->req_vq); 701 + virtio_delete_queue(s->event_vq); 699 702 virtio_cleanup(vdev); 700 703 } 701 704
-1
include/hw/acpi/acpi.h
··· 181 181 void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq); 182 182 183 183 /* acpi.c */ 184 - extern int acpi_enabled; 185 184 extern char unsigned *acpi_tables; 186 185 extern size_t acpi_tables_len; 187 186
+2
include/hw/arm/virt.h
··· 131 131 bool highmem_ecam; 132 132 bool its; 133 133 bool virt; 134 + OnOffAuto acpi; 134 135 VirtGICType gic_version; 135 136 VirtIOMMUType iommu; 136 137 uint16_t virtio_iommu_bdf; ··· 163 164 OBJECT_CLASS_CHECK(VirtMachineClass, klass, TYPE_VIRT_MACHINE) 164 165 165 166 void virt_acpi_setup(VirtMachineState *vms); 167 + bool virt_is_acpi_enabled(VirtMachineState *vms); 166 168 167 169 /* Return the number of used redistributor regions */ 168 170 static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
+3
include/hw/i386/x86.h
··· 64 64 unsigned smp_dies; 65 65 66 66 OnOffAuto smm; 67 + OnOffAuto acpi; 67 68 68 69 /* 69 70 * Address space used by IOAPIC device. All IOAPIC interrupts ··· 74 75 75 76 #define X86_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" 76 77 #define X86_MACHINE_SMM "smm" 78 + #define X86_MACHINE_ACPI "acpi" 77 79 78 80 #define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86") 79 81 #define X86_MACHINE(obj) \ ··· 104 106 bool linuxboot_dma_enabled); 105 107 106 108 bool x86_machine_is_smm_enabled(X86MachineState *x86ms); 109 + bool x86_machine_is_acpi_enabled(X86MachineState *x86ms); 107 110 108 111 /* Global System Interrupts */ 109 112
-1
include/hw/virtio/vhost-user-blk.h
··· 38 38 VhostUserState vhost_user; 39 39 struct vhost_virtqueue *vhost_vqs; 40 40 VirtQueue **virtqs; 41 - guint watch; 42 41 bool connected; 43 42 } VHostUserBlk; 44 43
+25
scripts/checkpatch.pl
··· 35 35 my $root; 36 36 my %debug; 37 37 my $help = 0; 38 + my $acpi_testexpected; 39 + my $acpi_nontestexpected; 38 40 39 41 sub help { 40 42 my ($exitcode) = @_; ··· 1256 1258 } 1257 1259 } 1258 1260 1261 + # According to tests/qtest/bios-tables-test.c: do not 1262 + # change expected file in the same commit with adding test 1263 + sub checkfilename { 1264 + my ($name) = @_; 1265 + if ($name =~ m#^tests/data/acpi/# and 1266 + # make exception for a shell script that rebuilds the files 1267 + not $name =~ m#^\.sh$# or 1268 + $name =~ m#^tests/qtest/bios-tables-test-allowed-diff.h$#) { 1269 + $acpi_testexpected = $name; 1270 + } else { 1271 + $acpi_nontestexpected = $name; 1272 + } 1273 + if (defined $acpi_testexpected and defined $acpi_nontestexpected) { 1274 + ERROR("Do not add expected files together with tests, " . 1275 + "follow instructions in " . 1276 + "tests/qtest/bios-tables-test.c: both " . 1277 + $acpi_testexpected . " and " . 1278 + $acpi_nontestexpected . " found\n"); 1279 + } 1280 + } 1281 + 1259 1282 sub process { 1260 1283 my $filename = shift; 1261 1284 ··· 1431 1454 if ($line =~ /^diff --git.*?(\S+)$/) { 1432 1455 $realfile = $1; 1433 1456 $realfile =~ s@^([^/]*)/@@ if (!$file); 1457 + checkfilename($realfile); 1434 1458 } elsif ($line =~ /^\+\+\+\s+(\S+)/) { 1435 1459 $realfile = $1; 1436 1460 $realfile =~ s@^([^/]*)/@@ if (!$file); 1461 + checkfilename($realfile); 1437 1462 1438 1463 $p1_prefix = $1; 1439 1464 if (!$file && $tree && $p1_prefix ne '' &&
+2 -2
softmmu/vl.c
··· 144 144 Chardev *parallel_hds[MAX_PARALLEL_PORTS]; 145 145 int win2k_install_hack = 0; 146 146 int singlestep = 0; 147 - int acpi_enabled = 1; 148 147 int no_hpet = 0; 149 148 int fd_bootchk = 1; 150 149 static int no_reboot; ··· 3516 3515 vnc_parse(optarg, &error_fatal); 3517 3516 break; 3518 3517 case QEMU_OPTION_no_acpi: 3519 - acpi_enabled = 0; 3518 + olist = qemu_find_opts("machine"); 3519 + qemu_opts_parse_noisily(olist, "acpi=off", false); 3520 3520 break; 3521 3521 case QEMU_OPTION_no_hpet: 3522 3522 no_hpet = 1;