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

pc: bugfixes, maintainers

A couple of bugfixes.
Add a new vhost-user-blk maintainer.

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

# gpg: Signature made Mon 13 Apr 2020 11:57:17 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:
exec: Fix for qemu_ram_resize() callback
fw_cfg: Migrate ACPI table mr sizes separately
acpi: Use macro for table-loader file name
MAINTAINERS: Add myself as vhost-user-blk maintainer

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

+126 -5
+12
MAINTAINERS
··· 1853 1853 F: hw/display/virtio-vga.* 1854 1854 F: include/hw/virtio/virtio-gpu.h 1855 1855 1856 + vhost-user-blk 1857 + M: Raphael Norwitz <raphael.norwitz@nutanix.com> 1858 + S: Maintained 1859 + F: contrib/vhost-user-blk/ 1860 + F: contrib/vhost-user-scsi/ 1861 + F: hw/block/vhost-user-blk.c 1862 + F: hw/scsi/vhost-user-scsi.c 1863 + F: hw/virtio/vhost-user-blk-pci.c 1864 + F: hw/virtio/vhost-user-scsi-pci.c 1865 + F: include/hw/virtio/vhost-user-blk.h 1866 + F: include/hw/virtio/vhost-user-scsi.h 1867 + 1856 1868 vhost-user-gpu 1857 1869 M: Marc-André Lureau <marcandre.lureau@redhat.com> 1858 1870 M: Gerd Hoffmann <kraxel@redhat.com>
+14 -2
exec.c
··· 2074 2074 */ 2075 2075 int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp) 2076 2076 { 2077 + const ram_addr_t unaligned_size = newsize; 2078 + 2077 2079 assert(block); 2078 2080 2079 2081 newsize = HOST_PAGE_ALIGN(newsize); 2080 2082 2081 2083 if (block->used_length == newsize) { 2084 + /* 2085 + * We don't have to resize the ram block (which only knows aligned 2086 + * sizes), however, we have to notify if the unaligned size changed. 2087 + */ 2088 + if (unaligned_size != memory_region_size(block->mr)) { 2089 + memory_region_set_size(block->mr, unaligned_size); 2090 + if (block->resized) { 2091 + block->resized(block->idstr, unaligned_size, block->host); 2092 + } 2093 + } 2082 2094 return 0; 2083 2095 } 2084 2096 ··· 2102 2114 block->used_length = newsize; 2103 2115 cpu_physical_memory_set_dirty_range(block->offset, block->used_length, 2104 2116 DIRTY_CLIENTS_ALL); 2105 - memory_region_set_size(block->mr, newsize); 2117 + memory_region_set_size(block->mr, unaligned_size); 2106 2118 if (block->resized) { 2107 - block->resized(block->idstr, newsize, block->host); 2119 + block->resized(block->idstr, unaligned_size, block->host); 2108 2120 } 2109 2121 return 0; 2110 2122 }
+1 -1
hw/arm/virt-acpi-build.c
··· 929 929 930 930 build_state->linker_mr = 931 931 acpi_add_rom_blob(virt_acpi_build_update, build_state, 932 - tables.linker->cmd_blob, "etc/table-loader", 0); 932 + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, 0); 933 933 934 934 fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, 935 935 acpi_data_len(tables.tcpalog));
+1
hw/core/machine.c
··· 39 39 { "usb-redir", "suppress-remote-wake", "off" }, 40 40 { "qxl", "revision", "4" }, 41 41 { "qxl-vga", "revision", "4" }, 42 + { "fw_cfg", "acpi-mr-restore", "false" }, 42 43 }; 43 44 const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2); 44 45
+1 -1
hw/i386/acpi-build.c
··· 3043 3043 3044 3044 build_state->linker_mr = 3045 3045 acpi_add_rom_blob(acpi_build_update, build_state, 3046 - tables.linker->cmd_blob, "etc/table-loader", 0); 3046 + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE, 0); 3047 3047 3048 3048 fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, 3049 3049 tables.tcpalog->data, acpi_data_len(tables.tcpalog));
+90 -1
hw/nvram/fw_cfg.c
··· 39 39 #include "qemu/config-file.h" 40 40 #include "qemu/cutils.h" 41 41 #include "qapi/error.h" 42 + #include "hw/acpi/aml-build.h" 42 43 43 44 #define FW_CFG_FILE_SLOTS_DFLT 0x20 44 45 ··· 610 611 return s->dma_enabled; 611 612 } 612 613 614 + static bool fw_cfg_acpi_mr_restore(void *opaque) 615 + { 616 + FWCfgState *s = opaque; 617 + bool mr_aligned; 618 + 619 + mr_aligned = QEMU_IS_ALIGNED(s->table_mr_size, qemu_real_host_page_size) && 620 + QEMU_IS_ALIGNED(s->linker_mr_size, qemu_real_host_page_size) && 621 + QEMU_IS_ALIGNED(s->rsdp_mr_size, qemu_real_host_page_size); 622 + return s->acpi_mr_restore && !mr_aligned; 623 + } 624 + 625 + static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size) 626 + { 627 + MemoryRegion *mr; 628 + ram_addr_t offset; 629 + int arch = !!(key & FW_CFG_ARCH_LOCAL); 630 + void *ptr; 631 + 632 + key &= FW_CFG_ENTRY_MASK; 633 + assert(key < fw_cfg_max_entry(s)); 634 + 635 + ptr = s->entries[arch][key].data; 636 + mr = memory_region_from_host(ptr, &offset); 637 + 638 + memory_region_ram_resize(mr, size, &error_abort); 639 + } 640 + 641 + static int fw_cfg_acpi_mr_restore_post_load(void *opaque, int version_id) 642 + { 643 + FWCfgState *s = opaque; 644 + int i, index; 645 + 646 + assert(s->files); 647 + 648 + index = be32_to_cpu(s->files->count); 649 + 650 + for (i = 0; i < index; i++) { 651 + if (!strcmp(s->files->f[i].name, ACPI_BUILD_TABLE_FILE)) { 652 + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->table_mr_size); 653 + } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_LOADER_FILE)) { 654 + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->linker_mr_size); 655 + } else if (!strcmp(s->files->f[i].name, ACPI_BUILD_RSDP_FILE)) { 656 + fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->rsdp_mr_size); 657 + } 658 + } 659 + 660 + return 0; 661 + } 662 + 613 663 static const VMStateDescription vmstate_fw_cfg_dma = { 614 664 .name = "fw_cfg/dma", 615 665 .needed = fw_cfg_dma_enabled, ··· 619 669 }, 620 670 }; 621 671 672 + static const VMStateDescription vmstate_fw_cfg_acpi_mr = { 673 + .name = "fw_cfg/acpi_mr", 674 + .version_id = 1, 675 + .minimum_version_id = 1, 676 + .needed = fw_cfg_acpi_mr_restore, 677 + .post_load = fw_cfg_acpi_mr_restore_post_load, 678 + .fields = (VMStateField[]) { 679 + VMSTATE_UINT64(table_mr_size, FWCfgState), 680 + VMSTATE_UINT64(linker_mr_size, FWCfgState), 681 + VMSTATE_UINT64(rsdp_mr_size, FWCfgState), 682 + VMSTATE_END_OF_LIST() 683 + }, 684 + }; 685 + 622 686 static const VMStateDescription vmstate_fw_cfg = { 623 687 .name = "fw_cfg", 624 688 .version_id = 2, ··· 631 695 }, 632 696 .subsections = (const VMStateDescription*[]) { 633 697 &vmstate_fw_cfg_dma, 698 + &vmstate_fw_cfg_acpi_mr, 634 699 NULL, 635 700 } 636 701 }; ··· 815 880 #define FW_CFG_ORDER_OVERRIDE_LAST 200 816 881 }; 817 882 883 + /* 884 + * Any sub-page size update to these table MRs will be lost during migration, 885 + * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path. 886 + * In order to avoid the inconsistency in sizes save them seperately and 887 + * migrate over in vmstate post_load(). 888 + */ 889 + static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t len) 890 + { 891 + if (!strcmp(filename, ACPI_BUILD_TABLE_FILE)) { 892 + s->table_mr_size = len; 893 + } else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) { 894 + s->linker_mr_size = len; 895 + } else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) { 896 + s->rsdp_mr_size = len; 897 + } 898 + } 899 + 818 900 static int get_fw_cfg_order(FWCfgState *s, const char *name) 819 901 { 820 902 int i; ··· 914 996 trace_fw_cfg_add_file(s, index, s->files->f[index].name, len); 915 997 916 998 s->files->count = cpu_to_be32(count+1); 999 + fw_cfg_acpi_mr_save(s, filename, len); 917 1000 } 918 1001 919 1002 void fw_cfg_add_file(FWCfgState *s, const char *filename, ··· 937 1020 ptr = fw_cfg_modify_bytes_read(s, FW_CFG_FILE_FIRST + i, 938 1021 data, len); 939 1022 s->files->f[i].size = cpu_to_be32(len); 1023 + fw_cfg_acpi_mr_save(s, filename, len); 940 1024 return ptr; 941 1025 } 942 1026 } ··· 973 1057 qemu_register_reset(fw_cfg_machine_reset, s); 974 1058 } 975 1059 976 - 1060 + static Property fw_cfg_properties[] = { 1061 + DEFINE_PROP_BOOL("acpi-mr-restore", FWCfgState, acpi_mr_restore, true), 1062 + DEFINE_PROP_END_OF_LIST(), 1063 + }; 977 1064 978 1065 static void fw_cfg_common_realize(DeviceState *dev, Error **errp) 979 1066 { ··· 1097 1184 1098 1185 dc->reset = fw_cfg_reset; 1099 1186 dc->vmsd = &vmstate_fw_cfg; 1187 + 1188 + device_class_set_props(dc, fw_cfg_properties); 1100 1189 } 1101 1190 1102 1191 static const TypeInfo fw_cfg_info = {
+1
include/hw/acpi/aml-build.h
··· 13 13 #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" 14 14 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp" 15 15 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log" 16 + #define ACPI_BUILD_LOADER_FILE "etc/table-loader" 16 17 17 18 #define AML_NOTIFY_METHOD "NTFY" 18 19
+6
include/hw/nvram/fw_cfg.h
··· 53 53 dma_addr_t dma_addr; 54 54 AddressSpace *dma_as; 55 55 MemoryRegion dma_iomem; 56 + 57 + /* restore during migration */ 58 + bool acpi_mr_restore; 59 + uint64_t table_mr_size; 60 + uint64_t linker_mr_size; 61 + uint64_t rsdp_mr_size; 56 62 }; 57 63 58 64 struct FWCfgIoState {