All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 00/53] virtio,pc,pci: features, cleanups, fixes
@ 2023-03-02  8:24 Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 01/53] hw/smbios: fix field corruption in type 4 table Michael S. Tsirkin
                   ` (54 more replies)
  0 siblings, 55 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

The following changes since commit 627634031092e1514f363fd8659a579398de0f0e:

  Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 65888be0d4da746e2f99930e21018d801bf8995e:

  tests/data/acpi/virt: drop (most) duplicate files. (2023-03-02 03:16:26 -0500)

----------------------------------------------------------------
virtio,pc,pci: features, cleanups, fixes

vhost-user support without ioeventfd
word replacements in vhost user spec
shpc improvements

cleanups, fixes all over the place

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

----------------------------------------------------------------
Akihiko Odaki (4):
      vhost-user-gpio: Configure vhost_dev when connecting
      vhost-user-i2c: Back up vqs before cleaning up vhost_dev
      vhost-user-rng: Back up vqs before cleaning up vhost_dev
      hw/timer/hpet: Fix expiration time overflow

Alex Bennée (1):
      backends/vhost-user: remove the ioeventfd check

Carlos López (2):
      vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
      libvhost-user: check for NULL when allocating a virtqueue element

Dr. David Alan Gilbert (1):
      virtio-rng-pci: fix transitional migration compat for vectors

Eugenio Pérez (2):
      virtio-net: clear guest_announce feature if no cvq backend
      vdpa: stop all svq on device deletion

Gregory Price (2):
      hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL
      hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition

Ira Weiny (3):
      qemu/bswap: Add const_le64()
      qemu/uuid: Add UUID static initializer
      hw/cxl/mailbox: Use new UUID network order define for cel_uuid

Jason Wang (4):
      intel-iommu: fail MAP notifier without caching mode
      intel-iommu: fail DEVIOTLB_UNMAP without dt mode
      memory: introduce memory_region_unmap_iommu_notifier_range()
      smmu: switch to use memory_region_unmap_iommu_notifier_range()

Jonathan Cameron (6):
      MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer
      hw/mem/cxl_type3: Improve error handling in realize()
      hw/pci-bridge/cxl_downstream: Fix type naming mismatch
      tests/acpi: Allow update of q35/DSDT.cxl
      hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge
      tests: acpi: Update q35/DSDT.cxl for removed duplicate UID

Julia Suvorova (1):
      hw/smbios: fix field corruption in type 4 table

Maxime Coquelin (3):
      docs: vhost-user: replace _SLAVE_ with _BACKEND_
      libvhost-user: Adopt new backend naming
      vhost-user: Adopt new backend naming

Michael S. Tsirkin (8):
      Revert "x86: don't let decompressed kernel image clobber setup_data"
      Revert "x86: do not re-randomize RNG seed on snapshot load"
      Revert "x86: re-initialize RNG seed when selecting kernel"
      Revert "x86: reinitialize RNG seed on system reboot"
      Revert "x86: use typedef for SetupData struct"
      Revert "x86: return modified setup_data only if read as memory, not as file"
      Revert "hw/i386: pass RNG seed via setup_data entry"
      tests/data/acpi/virt: drop (most) duplicate files.

Peter Xu (1):
      intel-iommu: send UNMAP notifications for domain or global inv desc

Philippe Mathieu-Daudé (1):
      hw/pci: Trace IRQ routing on PCI topology

Vladimir Sementsov-Ogievskiy (12):
      pci/shpc: set attention led to OFF on reset
      pci/shpc: change shpc_get_status() return type to uint8_t
      pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition
      pci/shpc: more generic handle hot-unplug in shpc_slot_command()
      pci/shpc: pass PCIDevice pointer to shpc_slot_command()
      pci/shpc: refactor shpc_device_plug_common()
      pcie: pcie_cap_slot_write_config(): use correct macro
      pcie_regs: drop duplicated indicator value macros
      pcie: drop unused PCIExpressIndicator
      pcie: pcie_cap_slot_enable_power() use correct helper
      pcie: introduce pcie_sltctl_powered_off() helper
      pcie: set power indicator to off on reset by default

Yajun Wu (1):
      chardev/char-socket: set s->listener = NULL in char_socket_finalize

Zhenzhong Duan (1):
      memory: Optimize replay of guest mapping

 include/exec/memory.h                     |  10 +++
 include/hw/cxl/cxl_device.h               |   2 +-
 include/hw/i386/microvm.h                 |   5 +-
 include/hw/i386/pc.h                      |   3 -
 include/hw/i386/x86.h                     |   3 +-
 include/hw/nvram/fw_cfg.h                 |  31 --------
 include/hw/pci/pcie.h                     |   8 --
 include/hw/pci/pcie_regs.h                |  14 ----
 include/hw/virtio/vhost-user-gpio.h       |   2 +-
 include/qemu/bswap.h                      |  12 ++-
 include/qemu/uuid.h                       |  12 +++
 subprojects/libvhost-user/libvhost-user.h |  20 ++---
 backends/vhost-user.c                     |  11 ---
 chardev/char-socket.c                     |   1 +
 hw/arm/smmu-common.c                      |  16 +---
 hw/core/machine.c                         |   2 +
 hw/cxl/cxl-device-utils.c                 |   2 +-
 hw/cxl/cxl-mailbox-utils.c                |  28 +++----
 hw/i386/acpi-build.c                      |   1 -
 hw/i386/intel_iommu.c                     |  31 ++++++--
 hw/i386/microvm.c                         |  17 ++---
 hw/i386/pc.c                              |   4 +-
 hw/i386/pc_piix.c                         |   2 -
 hw/i386/pc_q35.c                          |   2 -
 hw/i386/x86.c                             | 122 ++++++++----------------------
 hw/mem/cxl_type3.c                        |  15 +++-
 hw/net/virtio-net.c                       |  15 ++++
 hw/nvram/fw_cfg.c                         |  21 ++---
 hw/pci-bridge/cxl_downstream.c            |   2 +-
 hw/pci/pci.c                              |   8 ++
 hw/pci/pcie.c                             |  30 +++++---
 hw/pci/shpc.c                             | 107 ++++++++++++++------------
 hw/smbios/smbios.c                        |   8 +-
 hw/timer/hpet.c                           |  19 +++--
 hw/virtio/vhost-shadow-virtqueue.c        |   2 +-
 hw/virtio/vhost-user-gpio.c               |  10 ++-
 hw/virtio/vhost-user-i2c.c                |   5 +-
 hw/virtio/vhost-user-rng.c                |   5 +-
 hw/virtio/vhost-user.c                    |  30 ++++----
 hw/virtio/vhost-vdpa.c                    |  17 +----
 hw/virtio/virtio-qmp.c                    |  12 +--
 softmmu/memory.c                          |  17 ++++-
 subprojects/libvhost-user/libvhost-user.c |  27 ++++---
 MAINTAINERS                               |   1 +
 docs/interop/vhost-user.rst               |  40 +++++-----
 hw/pci/trace-events                       |   1 +
 tests/data/acpi/q35/DSDT.cxl              | Bin 9578 -> 9564 bytes
 tests/data/acpi/virt/APIC.memhp           | Bin 172 -> 0 bytes
 tests/data/acpi/virt/APIC.numamem         | Bin 172 -> 0 bytes
 tests/data/acpi/virt/DSDT.numamem         | Bin 5196 -> 0 bytes
 tests/data/acpi/virt/FACP.memhp           | Bin 276 -> 0 bytes
 tests/data/acpi/virt/FACP.numamem         | Bin 276 -> 0 bytes
 tests/data/acpi/virt/GTDT.memhp           | Bin 96 -> 0 bytes
 tests/data/acpi/virt/GTDT.numamem         | Bin 96 -> 0 bytes
 tests/data/acpi/virt/IORT.memhp           | Bin 128 -> 0 bytes
 tests/data/acpi/virt/IORT.numamem         | Bin 128 -> 0 bytes
 tests/data/acpi/virt/IORT.pxb             | Bin 128 -> 0 bytes
 tests/data/acpi/virt/MCFG.memhp           | Bin 60 -> 0 bytes
 tests/data/acpi/virt/MCFG.numamem         | Bin 60 -> 0 bytes
 tests/data/acpi/virt/SPCR.memhp           | Bin 80 -> 0 bytes
 tests/data/acpi/virt/SPCR.numamem         | Bin 80 -> 0 bytes
 61 files changed, 357 insertions(+), 396 deletions(-)
 delete mode 100644 tests/data/acpi/virt/APIC.memhp
 delete mode 100644 tests/data/acpi/virt/APIC.numamem
 delete mode 100644 tests/data/acpi/virt/DSDT.numamem
 delete mode 100644 tests/data/acpi/virt/FACP.memhp
 delete mode 100644 tests/data/acpi/virt/FACP.numamem
 delete mode 100644 tests/data/acpi/virt/GTDT.memhp
 delete mode 100644 tests/data/acpi/virt/GTDT.numamem
 delete mode 100644 tests/data/acpi/virt/IORT.memhp
 delete mode 100644 tests/data/acpi/virt/IORT.numamem
 delete mode 100644 tests/data/acpi/virt/IORT.pxb
 delete mode 100644 tests/data/acpi/virt/MCFG.memhp
 delete mode 100644 tests/data/acpi/virt/MCFG.numamem
 delete mode 100644 tests/data/acpi/virt/SPCR.memhp
 delete mode 100644 tests/data/acpi/virt/SPCR.numamem



^ permalink raw reply	[flat|nested] 72+ messages in thread

* [PULL 01/53] hw/smbios: fix field corruption in type 4 table
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 02/53] Revert "x86: don't let decompressed kernel image clobber setup_data" Michael S. Tsirkin
                   ` (53 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Julia Suvorova, Igor Mammedov, Ani Sinha

From: Julia Suvorova <jusual@redhat.com>

Since table type 4 of SMBIOS version 2.6 is shorter than 3.0, the
strings which follow immediately after the struct fields have been
overwritten by unconditional filling of later fields such as core_count2.
Make these fields dependent on the SMBIOS version.

Fixes: 05e27d74c7 ("hw/smbios: add core_count2 to smbios table type 4")
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2169904

Signed-off-by: Julia Suvorova <jusual@redhat.com>
Message-Id: <20230223125747.254914-1-jusual@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/smbios/smbios.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 4869566cf5..d2007e70fb 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -750,14 +750,16 @@ static void smbios_build_type_4_table(MachineState *ms, unsigned instance)
     t->core_count = (ms->smp.cores > 255) ? 0xFF : ms->smp.cores;
     t->core_enabled = t->core_count;
 
-    t->core_count2 = t->core_enabled2 = cpu_to_le16(ms->smp.cores);
-
     t->thread_count = (ms->smp.threads > 255) ? 0xFF : ms->smp.threads;
-    t->thread_count2 = cpu_to_le16(ms->smp.threads);
 
     t->processor_characteristics = cpu_to_le16(0x02); /* Unknown */
     t->processor_family2 = cpu_to_le16(0x01); /* Other */
 
+    if (tbl_len == SMBIOS_TYPE_4_LEN_V30) {
+        t->core_count2 = t->core_enabled2 = cpu_to_le16(ms->smp.cores);
+        t->thread_count2 = cpu_to_le16(ms->smp.threads);
+    }
+
     SMBIOS_BUILD_TABLE_POST;
     smbios_type4_count++;
 }
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 02/53] Revert "x86: don't let decompressed kernel image clobber setup_data"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 01/53] hw/smbios: fix field corruption in type 4 table Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 03/53] Revert "x86: do not re-randomize RNG seed on snapshot load" Michael S. Tsirkin
                   ` (52 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Sergio Lopez, Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Gerd Hoffmann

This reverts commit eac7a7791bb6d719233deed750034042318ffd56.

Fixes: eac7a7791b ("x86: don't let decompressed kernel image clobber setup_data")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/hw/i386/microvm.h |  5 ++--
 include/hw/nvram/fw_cfg.h |  9 -------
 hw/i386/microvm.c         | 15 ++++-------
 hw/i386/x86.c             | 52 ++++++++++++++++++---------------------
 hw/nvram/fw_cfg.c         |  9 -------
 5 files changed, 31 insertions(+), 59 deletions(-)

diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h
index e8af61f194..fad97a891d 100644
--- a/include/hw/i386/microvm.h
+++ b/include/hw/i386/microvm.h
@@ -50,9 +50,8 @@
  */
 
 /* Platform virtio definitions */
-#define VIRTIO_MMIO_BASE                0xfeb00000
-#define VIRTIO_CMDLINE_MAXLEN           64
-#define VIRTIO_CMDLINE_TOTAL_MAX_LEN    ((VIRTIO_CMDLINE_MAXLEN + 1) * 16)
+#define VIRTIO_MMIO_BASE      0xfeb00000
+#define VIRTIO_CMDLINE_MAXLEN 64
 
 #define GED_MMIO_BASE         0xfea00000
 #define GED_MMIO_BASE_MEMHP   (GED_MMIO_BASE + 0x100)
diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 990dcdbb2e..2e503904dc 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -139,15 +139,6 @@ void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
                                void *data, size_t len,
                                bool read_only);
 
-/**
- * fw_cfg_read_bytes_ptr:
- * @s: fw_cfg device being modified
- * @key: selector key value for new fw_cfg item
- *
- * Reads an existing fw_cfg data pointer.
- */
-void *fw_cfg_read_bytes_ptr(FWCfgState *s, uint16_t key);
-
 /**
  * fw_cfg_add_string:
  * @s: fw_cfg device being modified
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 68c22016d2..6680530555 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -376,8 +376,7 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)
     MicrovmMachineState *mms = MICROVM_MACHINE(machine);
     BusState *bus;
     BusChild *kid;
-    char *cmdline, *existing_cmdline;
-    size_t len;
+    char *cmdline;
 
     /*
      * Find MMIO transports with attached devices, and add them to the kernel
@@ -386,8 +385,7 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)
      * Yes, this is a hack, but one that heavily improves the UX without
      * introducing any significant issues.
      */
-    existing_cmdline = fw_cfg_read_bytes_ptr(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA);
-    cmdline = g_strdup(existing_cmdline);
+    cmdline = g_strdup(machine->kernel_cmdline);
     bus = sysbus_get_default();
     QTAILQ_FOREACH(kid, &bus->children, sibling) {
         DeviceState *dev = kid->child;
@@ -411,12 +409,9 @@ static void microvm_fix_kernel_cmdline(MachineState *machine)
         }
     }
 
-    len = strlen(cmdline);
-    if (len > VIRTIO_CMDLINE_TOTAL_MAX_LEN + strlen(existing_cmdline)) {
-        fprintf(stderr, "qemu: virtio mmio cmdline too large, skipping\n");
-    } else {
-        memcpy(existing_cmdline, cmdline, len + 1);
-    }
+    fw_cfg_modify_i32(x86ms->fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(cmdline) + 1);
+    fw_cfg_modify_string(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA, cmdline);
+
     g_free(cmdline);
 }
 
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index c44846f47b..9b7476158c 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -49,7 +49,6 @@
 #include "hw/intc/i8259.h"
 #include "hw/rtc/mc146818rtc.h"
 #include "target/i386/sev.h"
-#include "hw/i386/microvm.h"
 
 #include "hw/acpi/cpu_hotplug.h"
 #include "hw/irq.h"
@@ -815,18 +814,12 @@ void x86_load_linux(X86MachineState *x86ms,
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     const char *dtb_filename = machine->dtb;
-    char *kernel_cmdline;
+    const char *kernel_cmdline = machine->kernel_cmdline;
     SevKernelLoaderContext sev_load_ctx = {};
     enum { RNG_SEED_LENGTH = 32 };
 
-    /*
-     * Add the NUL terminator, some padding for the microvm cmdline fiddling
-     * hack, and then align to 16 bytes as a paranoia measure
-     */
-    cmdline_size = (strlen(machine->kernel_cmdline) + 1 +
-                    VIRTIO_CMDLINE_TOTAL_MAX_LEN + 16) & ~15;
-    /* Make a copy, since we might append arbitrary bytes to it later. */
-    kernel_cmdline = g_strndup(machine->kernel_cmdline, cmdline_size);
+    /* Align to 16 bytes as a paranoia measure */
+    cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
 
     /* load the kernel header */
     f = fopen(kernel_filename, "rb");
@@ -967,6 +960,12 @@ void x86_load_linux(X86MachineState *x86ms,
         initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1;
     }
 
+    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1);
+    fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
+    sev_load_ctx.cmdline_data = (char *)kernel_cmdline;
+    sev_load_ctx.cmdline_size = strlen(kernel_cmdline) + 1;
+
     if (protocol >= 0x202) {
         stl_p(header + 0x228, cmdline_addr);
     } else {
@@ -1093,24 +1092,27 @@ void x86_load_linux(X86MachineState *x86ms,
             exit(1);
         }
 
-        setup_data_offset = cmdline_size;
-        cmdline_size += sizeof(SetupData) + dtb_size;
-        kernel_cmdline = g_realloc(kernel_cmdline, cmdline_size);
-        setup_data = (void *)kernel_cmdline + setup_data_offset;
+        setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
+        kernel_size = setup_data_offset + sizeof(SetupData) + dtb_size;
+        kernel = g_realloc(kernel, kernel_size);
+
+
+        setup_data = (SetupData *)(kernel + setup_data_offset);
         setup_data->next = cpu_to_le64(first_setup_data);
-        first_setup_data = cmdline_addr + setup_data_offset;
+        first_setup_data = prot_addr + setup_data_offset;
         setup_data->type = cpu_to_le32(SETUP_DTB);
         setup_data->len = cpu_to_le32(dtb_size);
+
         load_image_size(dtb_filename, setup_data->data, dtb_size);
     }
 
-    if (!legacy_no_rng_seed && protocol >= 0x209) {
-        setup_data_offset = cmdline_size;
-        cmdline_size += sizeof(SetupData) + RNG_SEED_LENGTH;
-        kernel_cmdline = g_realloc(kernel_cmdline, cmdline_size);
-        setup_data = (void *)kernel_cmdline + setup_data_offset;
+    if (!legacy_no_rng_seed) {
+        setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
+        kernel_size = setup_data_offset + sizeof(SetupData) + RNG_SEED_LENGTH;
+        kernel = g_realloc(kernel, kernel_size);
+        setup_data = (SetupData *)(kernel + setup_data_offset);
         setup_data->next = cpu_to_le64(first_setup_data);
-        first_setup_data = cmdline_addr + setup_data_offset;
+        first_setup_data = prot_addr + setup_data_offset;
         setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
         setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
@@ -1121,12 +1123,6 @@ void x86_load_linux(X86MachineState *x86ms,
         fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
     }
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, cmdline_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline, cmdline_size);
-    sev_load_ctx.cmdline_data = (char *)kernel_cmdline;
-    sev_load_ctx.cmdline_size = cmdline_size;
-
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
     sev_load_ctx.kernel_data = (char *)kernel;
@@ -1139,7 +1135,7 @@ void x86_load_linux(X86MachineState *x86ms,
      * kernel on the other side of the fw_cfg interface matches the hash of the
      * file the user passed in.
      */
-    if (!sev_enabled() && first_setup_data) {
+    if (!sev_enabled()) {
         SetupDataFixup *fixup = g_malloc(sizeof(*fixup));
 
         memcpy(setup, header, MIN(sizeof(header), setup_size));
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 432754eda4..a00881bc64 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -741,15 +741,6 @@ void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len)
     fw_cfg_add_bytes_callback(s, key, NULL, NULL, NULL, data, len, true);
 }
 
-void *fw_cfg_read_bytes_ptr(FWCfgState *s, uint16_t key)
-{
-    int arch = !!(key & FW_CFG_ARCH_LOCAL);
-
-    key &= FW_CFG_ENTRY_MASK;
-    assert(key < fw_cfg_max_entry(s));
-    return s->entries[arch][key].data;
-}
-
 void fw_cfg_add_string(FWCfgState *s, uint16_t key, const char *value)
 {
     size_t sz = strlen(value) + 1;
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 03/53] Revert "x86: do not re-randomize RNG seed on snapshot load"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 01/53] hw/smbios: fix field corruption in type 4 table Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 02/53] Revert "x86: don't let decompressed kernel image clobber setup_data" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 04/53] Revert "x86: re-initialize RNG seed when selecting kernel" Michael S. Tsirkin
                   ` (51 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum

This reverts commit 14b29fea742034186403914b4d013d0e83f19e78.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Fixes: 14b29fea74 ("x86: do not re-randomize RNG seed on snapshot load")
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/i386/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 9b7476158c..7a128a2899 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -1116,7 +1116,7 @@ void x86_load_linux(X86MachineState *x86ms,
         setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
         setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
-        qemu_register_reset_nosnapshotload(reset_rng_seed, setup_data);
+        qemu_register_reset(reset_rng_seed, setup_data);
         fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_KERNEL_DATA, reset_rng_seed, NULL,
                                   setup_data, kernel, kernel_size, true);
     } else {
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 04/53] Revert "x86: re-initialize RNG seed when selecting kernel"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (2 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 03/53] Revert "x86: do not re-randomize RNG seed on snapshot load" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 05/53] Revert "x86: reinitialize RNG seed on system reboot" Michael S. Tsirkin
                   ` (50 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum

This reverts commit cc63374a5a7c240b7d3be734ef589dabbefc7527.

Fixes: cc63374a5a ("x86: re-initialize RNG seed when selecting kernel")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/i386/x86.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 7a128a2899..ec9c343cdb 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -1117,14 +1117,11 @@ void x86_load_linux(X86MachineState *x86ms,
         setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
         qemu_register_reset(reset_rng_seed, setup_data);
-        fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_KERNEL_DATA, reset_rng_seed, NULL,
-                                  setup_data, kernel, kernel_size, true);
-    } else {
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
     }
 
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
     sev_load_ctx.kernel_data = (char *)kernel;
     sev_load_ctx.kernel_size = kernel_size;
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 05/53] Revert "x86: reinitialize RNG seed on system reboot"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (3 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 04/53] Revert "x86: re-initialize RNG seed when selecting kernel" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 06/53] Revert "x86: use typedef for SetupData struct" Michael S. Tsirkin
                   ` (49 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost

This reverts commit 763a2828bf313ed55878b09759dc435355035f2e.

Fixes: 763a2828bf ("x86: reinitialize RNG seed on system reboot")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/i386/x86.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index ec9c343cdb..278dd54830 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -788,12 +788,6 @@ static void reset_setup_data(void *opaque)
     stq_p(fixup->pos, fixup->orig_val);
 }
 
-static void reset_rng_seed(void *opaque)
-{
-    SetupData *setup_data = opaque;
-    qemu_guest_getrandom_nofail(setup_data->data, le32_to_cpu(setup_data->len));
-}
-
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
@@ -1116,7 +1110,6 @@ void x86_load_linux(X86MachineState *x86ms,
         setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
         setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
-        qemu_register_reset(reset_rng_seed, setup_data);
     }
 
     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 06/53] Revert "x86: use typedef for SetupData struct"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (4 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 05/53] Revert "x86: reinitialize RNG seed on system reboot" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 07/53] Revert "x86: return modified setup_data only if read as memory, not as file" Michael S. Tsirkin
                   ` (48 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost

This reverts commit eebb38a5633a77f5fa79d6486d5b2fcf8fbe3c07.

Fixes: eebb38a563 ("x86: use typedef for SetupData struct")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 hw/i386/x86.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 278dd54830..66cf171ace 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -658,12 +658,12 @@ DeviceState *ioapic_init_secondary(GSIState *gsi_state)
     return dev;
 }
 
-typedef struct SetupData {
+struct setup_data {
     uint64_t next;
     uint32_t type;
     uint32_t len;
     uint8_t data[];
-} __attribute__((packed)) SetupData;
+} __attribute__((packed));
 
 
 /*
@@ -804,7 +804,7 @@ void x86_load_linux(X86MachineState *x86ms,
     FILE *f;
     char *vmode;
     MachineState *machine = MACHINE(x86ms);
-    SetupData *setup_data;
+    struct setup_data *setup_data;
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     const char *dtb_filename = machine->dtb;
@@ -1087,11 +1087,11 @@ void x86_load_linux(X86MachineState *x86ms,
         }
 
         setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
-        kernel_size = setup_data_offset + sizeof(SetupData) + dtb_size;
+        kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size;
         kernel = g_realloc(kernel, kernel_size);
 
 
-        setup_data = (SetupData *)(kernel + setup_data_offset);
+        setup_data = (struct setup_data *)(kernel + setup_data_offset);
         setup_data->next = cpu_to_le64(first_setup_data);
         first_setup_data = prot_addr + setup_data_offset;
         setup_data->type = cpu_to_le32(SETUP_DTB);
@@ -1102,9 +1102,9 @@ void x86_load_linux(X86MachineState *x86ms,
 
     if (!legacy_no_rng_seed) {
         setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
-        kernel_size = setup_data_offset + sizeof(SetupData) + RNG_SEED_LENGTH;
+        kernel_size = setup_data_offset + sizeof(struct setup_data) + RNG_SEED_LENGTH;
         kernel = g_realloc(kernel, kernel_size);
-        setup_data = (SetupData *)(kernel + setup_data_offset);
+        setup_data = (struct setup_data *)(kernel + setup_data_offset);
         setup_data->next = cpu_to_le64(first_setup_data);
         first_setup_data = prot_addr + setup_data_offset;
         setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 07/53] Revert "x86: return modified setup_data only if read as memory, not as file"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (5 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 06/53] Revert "x86: use typedef for SetupData struct" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 08/53] Revert "hw/i386: pass RNG seed via setup_data entry" Michael S. Tsirkin
                   ` (47 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, Philippe Mathieu-Daudé,
	Gerd Hoffmann

This reverts commit e935b735085dfa61d8e6d276b6f9e7687796a3c7.

Fixes: e935b73508 ("x86: return modified setup_data only if read as memory, not as file")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/hw/nvram/fw_cfg.h | 22 -------------------
 hw/i386/x86.c             | 46 +++++++++------------------------------
 hw/nvram/fw_cfg.c         | 12 +++++-----
 3 files changed, 16 insertions(+), 64 deletions(-)

diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
index 2e503904dc..c1f81a5f13 100644
--- a/include/hw/nvram/fw_cfg.h
+++ b/include/hw/nvram/fw_cfg.h
@@ -117,28 +117,6 @@ struct FWCfgMemState {
  */
 void fw_cfg_add_bytes(FWCfgState *s, uint16_t key, void *data, size_t len);
 
-/**
- * fw_cfg_add_bytes_callback:
- * @s: fw_cfg device being modified
- * @key: selector key value for new fw_cfg item
- * @select_cb: callback function when selecting
- * @write_cb: callback function after a write
- * @callback_opaque: argument to be passed into callback function
- * @data: pointer to start of item data
- * @len: size of item data
- * @read_only: is file read only
- *
- * Add a new fw_cfg item, available by selecting the given key, as a raw
- * "blob" of the given size. The data referenced by the starting pointer
- * is only linked, NOT copied, into the data structure of the fw_cfg device.
- */
-void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
-                               FWCfgCallback select_cb,
-                               FWCfgWriteCallback write_cb,
-                               void *callback_opaque,
-                               void *data, size_t len,
-                               bool read_only);
-
 /**
  * fw_cfg_add_string:
  * @s: fw_cfg device being modified
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 66cf171ace..ed161a3409 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -36,7 +36,6 @@
 #include "sysemu/whpx.h"
 #include "sysemu/numa.h"
 #include "sysemu/replay.h"
-#include "sysemu/reset.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/cpu-timers.h"
 #include "sysemu/xen.h"
@@ -770,24 +769,6 @@ static bool load_elfboot(const char *kernel_filename,
     return true;
 }
 
-typedef struct SetupDataFixup {
-    void *pos;
-    hwaddr orig_val, new_val;
-    uint32_t addr;
-} SetupDataFixup;
-
-static void fixup_setup_data(void *opaque)
-{
-    SetupDataFixup *fixup = opaque;
-    stq_p(fixup->pos, fixup->new_val);
-}
-
-static void reset_setup_data(void *opaque)
-{
-    SetupDataFixup *fixup = opaque;
-    stq_p(fixup->pos, fixup->orig_val);
-}
-
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
@@ -1112,11 +1093,8 @@ void x86_load_linux(X86MachineState *x86ms,
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
     }
 
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
-    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
-    sev_load_ctx.kernel_data = (char *)kernel;
-    sev_load_ctx.kernel_size = kernel_size;
+    /* Offset 0x250 is a pointer to the first setup_data link. */
+    stq_p(header + 0x250, first_setup_data);
 
     /*
      * If we're starting an encrypted VM, it will be OVMF based, which uses the
@@ -1126,20 +1104,16 @@ void x86_load_linux(X86MachineState *x86ms,
      * file the user passed in.
      */
     if (!sev_enabled()) {
-        SetupDataFixup *fixup = g_malloc(sizeof(*fixup));
-
         memcpy(setup, header, MIN(sizeof(header), setup_size));
-        /* Offset 0x250 is a pointer to the first setup_data link. */
-        fixup->pos = setup + 0x250;
-        fixup->orig_val = ldq_p(fixup->pos);
-        fixup->new_val = first_setup_data;
-        fixup->addr = cpu_to_le32(real_addr);
-        fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_SETUP_ADDR, fixup_setup_data, NULL,
-                                  fixup, &fixup->addr, sizeof(fixup->addr), true);
-        qemu_register_reset(reset_setup_data, fixup);
-    } else {
-        fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
     }
+
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
+    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+    sev_load_ctx.kernel_data = (char *)kernel;
+    sev_load_ctx.kernel_size = kernel_size;
+
+    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
     fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
     sev_load_ctx.setup_data = (char *)setup;
diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index a00881bc64..29a5bef1d5 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -693,12 +693,12 @@ static const VMStateDescription vmstate_fw_cfg = {
     }
 };
 
-void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
-                               FWCfgCallback select_cb,
-                               FWCfgWriteCallback write_cb,
-                               void *callback_opaque,
-                               void *data, size_t len,
-                               bool read_only)
+static void fw_cfg_add_bytes_callback(FWCfgState *s, uint16_t key,
+                                      FWCfgCallback select_cb,
+                                      FWCfgWriteCallback write_cb,
+                                      void *callback_opaque,
+                                      void *data, size_t len,
+                                      bool read_only)
 {
     int arch = !!(key & FW_CFG_ARCH_LOCAL);
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 08/53] Revert "hw/i386: pass RNG seed via setup_data entry"
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (6 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 07/53] Revert "x86: return modified setup_data only if read as memory, not as file" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:24 ` [PULL 09/53] virtio-net: clear guest_announce feature if no cvq backend Michael S. Tsirkin
                   ` (46 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Nathan Chancellor, Dov Murik,
	Daniel P . Berrangé,
	Sergio Lopez, Paolo Bonzini, Marcel Apfelbaum, Richard Henderson,
	Eduardo Habkost

This reverts commit 67f7e426e53833a5db75b0d813e8d537b8a75bd2.

Additionally to the automatic revert, I went over the code
and dropped all mentions of legacy_no_rng_seed manually,
effectively reverting a combination of 2 additional commits:

    commit ffe2d2382e5f1aae1abc4081af407905ef380311
    Author: Jason A. Donenfeld <Jason@zx2c4.com>
    Date:   Wed Sep 21 11:31:34 2022 +0200

        x86: re-enable rng seeding via SetupData

    commit 3824e25db1a84fadc50b88dfbe27047aa2f7f85d
    Author: Gerd Hoffmann <kraxel@redhat.com>
    Date:   Wed Aug 17 10:39:40 2022 +0200

        x86: disable rng seeding via setup_data

Fixes: 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/hw/i386/pc.h  |  3 ---
 include/hw/i386/x86.h |  3 +--
 hw/i386/microvm.c     |  2 +-
 hw/i386/pc.c          |  4 ++--
 hw/i386/pc_piix.c     |  2 --
 hw/i386/pc_q35.c      |  2 --
 hw/i386/x86.c         | 26 ++++----------------------
 7 files changed, 8 insertions(+), 34 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 66e3d059ef..44b08554fa 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -127,9 +127,6 @@ struct PCMachineClass {
 
     /* create kvmclock device even when KVM PV features are not exposed */
     bool kvmclock_create_always;
-
-    /* skip passing an rng seed for legacy machines */
-    bool legacy_no_rng_seed;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
index 890dfad23e..0b337a036c 100644
--- a/include/hw/i386/x86.h
+++ b/include/hw/i386/x86.h
@@ -123,8 +123,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed);
+                    bool pvh_enabled);
 
 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 6680530555..3d606a20b4 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -328,7 +328,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
     rom_set_fw(fw_cfg);
 
     if (machine->kernel_filename != NULL) {
-        x86_load_linux(x86ms, fw_cfg, 0, true, false);
+        x86_load_linux(x86ms, fw_cfg, 0, true);
     }
 
     if (mms->option_roms) {
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 992951c107..8b1ddc8d99 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -806,7 +806,7 @@ void xen_load_linux(PCMachineState *pcms)
     rom_set_fw(fw_cfg);
 
     x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                   pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                   pcmc->pvh_enabled);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
                !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1126,7 +1126,7 @@ void pc_memory_init(PCMachineState *pcms,
 
     if (linux_boot) {
         x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                       pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                       pcmc->pvh_enabled);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 126b6c11df..2f16011bab 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -477,9 +477,7 @@ DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,
 
 static void pc_i440fx_7_1_machine_options(MachineClass *m)
 {
-    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_i440fx_7_2_machine_options(m);
-    pcmc->legacy_no_rng_seed = true;
     compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
     compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
 }
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 09004f3f1f..797ba347fd 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -395,9 +395,7 @@ DEFINE_Q35_MACHINE(v7_2, "pc-q35-7.2", NULL,
 
 static void pc_q35_7_1_machine_options(MachineClass *m)
 {
-    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     pc_q35_7_2_machine_options(m);
-    pcmc->legacy_no_rng_seed = true;
     compat_props_add(m->compat_props, hw_compat_7_1, hw_compat_7_1_len);
     compat_props_add(m->compat_props, pc_compat_7_1, pc_compat_7_1_len);
 }
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index ed161a3409..a33c879598 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -26,7 +26,6 @@
 #include "qemu/cutils.h"
 #include "qemu/units.h"
 #include "qemu/datadir.h"
-#include "qemu/guest-random.h"
 #include "qapi/error.h"
 #include "qapi/qapi-visit-common.h"
 #include "qapi/clone-visitor.h"
@@ -772,8 +771,7 @@ static bool load_elfboot(const char *kernel_filename,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed)
+                    bool pvh_enabled)
 {
     bool linuxboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled;
     uint16_t protocol;
@@ -781,7 +779,7 @@ void x86_load_linux(X86MachineState *x86ms,
     int dtb_size, setup_data_offset;
     uint32_t initrd_max;
     uint8_t header[8192], *setup, *kernel;
-    hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0, first_setup_data = 0;
+    hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
     FILE *f;
     char *vmode;
     MachineState *machine = MACHINE(x86ms);
@@ -791,7 +789,6 @@ void x86_load_linux(X86MachineState *x86ms,
     const char *dtb_filename = machine->dtb;
     const char *kernel_cmdline = machine->kernel_cmdline;
     SevKernelLoaderContext sev_load_ctx = {};
-    enum { RNG_SEED_LENGTH = 32 };
 
     /* Align to 16 bytes as a paranoia measure */
     cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
@@ -1071,31 +1068,16 @@ void x86_load_linux(X86MachineState *x86ms,
         kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size;
         kernel = g_realloc(kernel, kernel_size);
 
+        stq_p(header + 0x250, prot_addr + setup_data_offset);
 
         setup_data = (struct setup_data *)(kernel + setup_data_offset);
-        setup_data->next = cpu_to_le64(first_setup_data);
-        first_setup_data = prot_addr + setup_data_offset;
+        setup_data->next = 0;
         setup_data->type = cpu_to_le32(SETUP_DTB);
         setup_data->len = cpu_to_le32(dtb_size);
 
         load_image_size(dtb_filename, setup_data->data, dtb_size);
     }
 
-    if (!legacy_no_rng_seed) {
-        setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
-        kernel_size = setup_data_offset + sizeof(struct setup_data) + RNG_SEED_LENGTH;
-        kernel = g_realloc(kernel, kernel_size);
-        setup_data = (struct setup_data *)(kernel + setup_data_offset);
-        setup_data->next = cpu_to_le64(first_setup_data);
-        first_setup_data = prot_addr + setup_data_offset;
-        setup_data->type = cpu_to_le32(SETUP_RNG_SEED);
-        setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
-        qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
-    }
-
-    /* Offset 0x250 is a pointer to the first setup_data link. */
-    stq_p(header + 0x250, first_setup_data);
-
     /*
      * If we're starting an encrypted VM, it will be OVMF based, which uses the
      * efi stub for booting and doesn't require any values to be placed in the
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 09/53] virtio-net: clear guest_announce feature if no cvq backend
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (7 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 08/53] Revert "hw/i386: pass RNG seed via setup_data entry" Michael S. Tsirkin
@ 2023-03-02  8:24 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 10/53] backends/vhost-user: remove the ioeventfd check Michael S. Tsirkin
                   ` (45 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Eugenio Pérez, Dawar, Gautam,
	David Edmondson, Lei Yang, Jason Wang

From: Eugenio Pérez <eperezma@redhat.com>

Since GUEST_ANNOUNCE is emulated the feature bit could be set without
backend support.  This happens in the vDPA case.

However, backend vDPA parent may not have CVQ support.  This causes an
incoherent feature set, and the driver may refuse to start.  This
happens in virtio-net Linux driver.

This may be solved differently in the future.  Qemu is able to emulate a
CVQ just for guest_announce purposes, helping guest to notify the new
location with vDPA devices that does not support it.  However, this is
left as a TODO as it is way more complex to backport.

Tested with vdpa_net_sim, toggling manually VIRTIO_NET_F_CTRL_VQ in the
driver and migrating it with x-svq=on.

Fixes: 980003debddd ("vdpa: do not handle VIRTIO_NET_F_GUEST_ANNOUNCE in vhost-vdpa")
Reported-by: Dawar, Gautam <gautam.dawar@amd.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Message-Id: <20230124161159.2182117-1-eperezma@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Edmondson <david.edmondson@oracle.com>
Reviewed-by: Gautam Dawar <gautam.dawar@amd.com>
Tested-by: Gautam Dawar <gautam.dawar@amd.com>
Tested-by: Lei Yang <leiyang@redhat.com>
---
 hw/net/virtio-net.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 3ae909041a..09d5c7a664 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -820,6 +820,21 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
         features |= (1ULL << VIRTIO_NET_F_MTU);
     }
 
+    /*
+     * Since GUEST_ANNOUNCE is emulated the feature bit could be set without
+     * enabled. This happens in the vDPA case.
+     *
+     * Make sure the feature set is not incoherent, as the driver could refuse
+     * to start.
+     *
+     * TODO: QEMU is able to emulate a CVQ just for guest_announce purposes,
+     * helping guest to notify the new location with vDPA devices that does not
+     * support it.
+     */
+    if (!virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_CTRL_VQ)) {
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE);
+    }
+
     return features;
 }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 10/53] backends/vhost-user: remove the ioeventfd check
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (8 preceding siblings ...)
  2023-03-02  8:24 ` [PULL 09/53] virtio-net: clear guest_announce feature if no cvq backend Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 11/53] vhost-user-gpio: Configure vhost_dev when connecting Michael S. Tsirkin
                   ` (44 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Alex Bennée, Gerd Hoffmann, Stefan Hajnoczi

From: Alex Bennée <alex.bennee@linaro.org>

While ioeventfds are needed for good performance with KVM guests it
should not be a gating requirement. We can run vhost-user backends using
simulated ioeventfds or inband signalling.

With this change I can run:

  $QEMU $OPTS \
    -display gtk,gl=on \
    -device vhost-user-gpu-pci,chardev=vhgpu \
    -chardev socket,id=vhgpu,path=vhgpu.sock

with:

  ./contrib/vhost-user-gpu/vhost-user-gpu \
    -s vhgpu.sock \
    -v

and at least see things start-up - although the display gets rotated by
180 degrees. Once lightdm takes over we never make it to the login
prompt and just get a blank screen.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Message-Id: <20221202132231.1048669-1-alex.bennee@linaro.org>

Message-Id: <20230130124728.175610-1-alex.bennee@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 backends/vhost-user.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/backends/vhost-user.c b/backends/vhost-user.c
index 0596223ac4..94c6a82d52 100644
--- a/backends/vhost-user.c
+++ b/backends/vhost-user.c
@@ -20,12 +20,6 @@
 #include "io/channel-command.h"
 #include "hw/virtio/virtio-bus.h"
 
-static bool
-ioeventfd_enabled(void)
-{
-    return kvm_enabled() && kvm_eventfds_enabled();
-}
-
 int
 vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev,
                             unsigned nvqs, Error **errp)
@@ -34,11 +28,6 @@ vhost_user_backend_dev_init(VhostUserBackend *b, VirtIODevice *vdev,
 
     assert(!b->vdev && vdev);
 
-    if (!ioeventfd_enabled()) {
-        error_setg(errp, "vhost initialization failed: requires kvm");
-        return -1;
-    }
-
     if (!vhost_user_init(&b->vhost_user, &b->chr, errp)) {
         return -1;
     }
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 11/53] vhost-user-gpio: Configure vhost_dev when connecting
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (9 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 10/53] backends/vhost-user: remove the ioeventfd check Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 12/53] vhost-user-i2c: Back up vqs before cleaning up vhost_dev Michael S. Tsirkin
                   ` (43 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Akihiko Odaki, Viresh Kumar, Alex Bennée

From: Akihiko Odaki <akihiko.odaki@daynix.com>

vhost_dev_cleanup(), called from vu_gpio_disconnect(), clears vhost_dev
so vhost-user-gpio must set the members of vhost_dev each time
connecting.

do_vhost_user_cleanup() should also acquire the pointer to vqs directly
from VHostUserGPIO instead of referring to vhost_dev as it can be called
after vhost_dev_cleanup().

Fixes: 27ba7b027f ("hw/virtio: add boilerplate for vhost-user-gpio device")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230130140320.77999-1-akihiko.odaki@daynix.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/virtio/vhost-user-gpio.h |  2 +-
 hw/virtio/vhost-user-gpio.c         | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/hw/virtio/vhost-user-gpio.h b/include/hw/virtio/vhost-user-gpio.h
index a9305c5e6c..a9d3f9b049 100644
--- a/include/hw/virtio/vhost-user-gpio.h
+++ b/include/hw/virtio/vhost-user-gpio.h
@@ -23,7 +23,7 @@ struct VHostUserGPIO {
     VirtIODevice parent_obj;
     CharBackend chardev;
     struct virtio_gpio_config config;
-    struct vhost_virtqueue *vhost_vq;
+    struct vhost_virtqueue *vhost_vqs;
     struct vhost_dev vhost_dev;
     VhostUserState vhost_user;
     VirtQueue *command_vq;
diff --git a/hw/virtio/vhost-user-gpio.c b/hw/virtio/vhost-user-gpio.c
index fe3da32c74..d6927b610a 100644
--- a/hw/virtio/vhost-user-gpio.c
+++ b/hw/virtio/vhost-user-gpio.c
@@ -16,6 +16,7 @@
 #include "trace.h"
 
 #define REALIZE_CONNECTION_RETRIES 3
+#define VHOST_NVQS 2
 
 /* Features required from VirtIO */
 static const int feature_bits[] = {
@@ -208,8 +209,7 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserGPIO *gpio)
 {
     virtio_delete_queue(gpio->command_vq);
     virtio_delete_queue(gpio->interrupt_vq);
-    g_free(gpio->vhost_dev.vqs);
-    gpio->vhost_dev.vqs = NULL;
+    g_free(gpio->vhost_vqs);
     virtio_cleanup(vdev);
     vhost_user_cleanup(&gpio->vhost_user);
 }
@@ -229,6 +229,9 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)
     vhost_dev_set_config_notifier(vhost_dev, &gpio_ops);
     gpio->vhost_user.supports_config = true;
 
+    gpio->vhost_dev.nvqs = VHOST_NVQS;
+    gpio->vhost_dev.vqs = gpio->vhost_vqs;
+
     ret = vhost_dev_init(vhost_dev, &gpio->vhost_user,
                          VHOST_BACKEND_TYPE_USER, 0, errp);
     if (ret < 0) {
@@ -347,10 +350,9 @@ static void vu_gpio_device_realize(DeviceState *dev, Error **errp)
 
     virtio_init(vdev, VIRTIO_ID_GPIO, sizeof(gpio->config));
 
-    gpio->vhost_dev.nvqs = 2;
     gpio->command_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
     gpio->interrupt_vq = virtio_add_queue(vdev, 256, vu_gpio_handle_output);
-    gpio->vhost_dev.vqs = g_new0(struct vhost_virtqueue, gpio->vhost_dev.nvqs);
+    gpio->vhost_vqs = g_new0(struct vhost_virtqueue, VHOST_NVQS);
 
     gpio->connected = false;
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 12/53] vhost-user-i2c: Back up vqs before cleaning up vhost_dev
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (10 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 11/53] vhost-user-gpio: Configure vhost_dev when connecting Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 13/53] vhost-user-rng: " Michael S. Tsirkin
                   ` (42 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Akihiko Odaki

From: Akihiko Odaki <akihiko.odaki@daynix.com>

vhost_dev_cleanup() clears vhost_dev so back up its vqs member to free
the memory pointed by the member.

Fixes: 7221d3b634 ("hw/virtio: add boilerplate for vhost-user-i2c device")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230130140435.78049-1-akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-user-i2c.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
index dc5c828ba6..60eaf0d95b 100644
--- a/hw/virtio/vhost-user-i2c.c
+++ b/hw/virtio/vhost-user-i2c.c
@@ -143,8 +143,6 @@ static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserI2C *i2c)
     vhost_user_cleanup(&i2c->vhost_user);
     virtio_delete_queue(i2c->vq);
     virtio_cleanup(vdev);
-    g_free(i2c->vhost_dev.vqs);
-    i2c->vhost_dev.vqs = NULL;
 }
 
 static int vu_i2c_connect(DeviceState *dev)
@@ -228,6 +226,7 @@ static void vu_i2c_device_realize(DeviceState *dev, Error **errp)
     ret = vhost_dev_init(&i2c->vhost_dev, &i2c->vhost_user,
                          VHOST_BACKEND_TYPE_USER, 0, errp);
     if (ret < 0) {
+        g_free(i2c->vhost_dev.vqs);
         do_vhost_user_cleanup(vdev, i2c);
     }
 
@@ -239,10 +238,12 @@ static void vu_i2c_device_unrealize(DeviceState *dev)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VHostUserI2C *i2c = VHOST_USER_I2C(dev);
+    struct vhost_virtqueue *vhost_vqs = i2c->vhost_dev.vqs;
 
     /* This will stop vhost backend if appropriate. */
     vu_i2c_set_status(vdev, 0);
     vhost_dev_cleanup(&i2c->vhost_dev);
+    g_free(vhost_vqs);
     do_vhost_user_cleanup(vdev, i2c);
 }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 13/53] vhost-user-rng: Back up vqs before cleaning up vhost_dev
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (11 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 12/53] vhost-user-i2c: Back up vqs before cleaning up vhost_dev Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors Michael S. Tsirkin
                   ` (41 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Akihiko Odaki, Mathieu Poirier

From: Akihiko Odaki <akihiko.odaki@daynix.com>

vhost_dev_cleanup() clears vhost_dev so back up its vqs member to free
the memory pointed by the member.

Fixes: 821d28b88f ("vhost-user-rng: Add vhost-user-rng implementation")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230130140516.78078-1-akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-user-rng.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c
index 201a39e220..efc54cd3fb 100644
--- a/hw/virtio/vhost-user-rng.c
+++ b/hw/virtio/vhost-user-rng.c
@@ -229,6 +229,7 @@ static void vu_rng_device_realize(DeviceState *dev, Error **errp)
     return;
 
 vhost_dev_init_failed:
+    g_free(rng->vhost_dev.vqs);
     virtio_delete_queue(rng->req_vq);
 virtio_add_queue_failed:
     virtio_cleanup(vdev);
@@ -239,12 +240,12 @@ static void vu_rng_device_unrealize(DeviceState *dev)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VHostUserRNG *rng = VHOST_USER_RNG(dev);
+    struct vhost_virtqueue *vhost_vqs = rng->vhost_dev.vqs;
 
     vu_rng_set_status(vdev, 0);
 
     vhost_dev_cleanup(&rng->vhost_dev);
-    g_free(rng->vhost_dev.vqs);
-    rng->vhost_dev.vqs = NULL;
+    g_free(vhost_vqs);
     virtio_delete_queue(rng->req_vq);
     virtio_cleanup(vdev);
     vhost_user_cleanup(&rng->vhost_user);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (12 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 13/53] vhost-user-rng: " Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-04 20:03   ` Michael Tokarev
  2023-03-02  8:25 ` [PULL 15/53] hw/timer/hpet: Fix expiration time overflow Michael S. Tsirkin
                   ` (40 subsequent siblings)
  54 siblings, 1 reply; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Dr. David Alan Gilbert, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang

From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

In bad9c5a516 ("virtio-rng-pci: fix migration compat for vectors") I
fixed the virtio-rng-pci migration compatibility, but it was discovered
that we also need to fix the other aliases of the device for the
transitional cases.

Fixes: 9ea02e8f1 ('virtio-rng-pci: Allow setting nvectors, so we can use MSI-X')
bz: https://bugzilla.redhat.com/show_bug.cgi?id=2162569
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20230207174944.138255-1-dgilbert@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/core/machine.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index f29e700ee4..1cf6822e06 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -47,6 +47,8 @@ const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
 GlobalProperty hw_compat_7_1[] = {
     { "virtio-device", "queue_reset", "false" },
     { "virtio-rng-pci", "vectors", "0" },
+    { "virtio-rng-pci-transitional", "vectors", "0" },
+    { "virtio-rng-pci-non-transitional", "vectors", "0" },
 };
 const size_t hw_compat_7_1_len = G_N_ELEMENTS(hw_compat_7_1);
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 15/53] hw/timer/hpet: Fix expiration time overflow
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (13 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 16/53] docs: vhost-user: replace _SLAVE_ with _BACKEND_ Michael S. Tsirkin
                   ` (39 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Akihiko Odaki, Paolo Bonzini

From: Akihiko Odaki <akihiko.odaki@daynix.com>

The expiration time provided for timer_mod() can overflow if a
ridiculously large value is set to the comparator register. The
resulting value can represent a past time after rounded, forcing the
timer to fire immediately. If the timer is configured as periodic, it
will rearm the timer again, and form an endless loop.

Check if the expiration value will overflow, and if it will, stop the
timer instead of rearming the timer with the overflowed time.

This bug was found by Alexander Bulekov when fuzzing igb, a new
network device emulation:
https://patchew.org/QEMU/20230129053316.1071513-1-alxndr@bu.edu/

The fixed test case is:
fuzz/crash_2d7036941dcda1ad4380bb8a9174ed0c949bcefd

Fixes: 16b29ae180 ("Add HPET emulation to qemu (Beth Kon)")
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20230131030037.18856-1-akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/timer/hpet.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 214d6a0501..6998094233 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -353,6 +353,16 @@ static const VMStateDescription vmstate_hpet = {
     }
 };
 
+static void hpet_arm(HPETTimer *t, uint64_t ticks)
+{
+    if (ticks < ns_to_ticks(INT64_MAX / 2)) {
+        timer_mod(t->qemu_timer,
+                  qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ticks_to_ns(ticks));
+    } else {
+        timer_del(t->qemu_timer);
+    }
+}
+
 /*
  * timer expiration callback
  */
@@ -375,13 +385,11 @@ static void hpet_timer(void *opaque)
             }
         }
         diff = hpet_calculate_diff(t, cur_tick);
-        timer_mod(t->qemu_timer,
-                       qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (int64_t)ticks_to_ns(diff));
+        hpet_arm(t, diff);
     } else if (t->config & HPET_TN_32BIT && !timer_is_periodic(t)) {
         if (t->wrap_flag) {
             diff = hpet_calculate_diff(t, cur_tick);
-            timer_mod(t->qemu_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-                           (int64_t)ticks_to_ns(diff));
+            hpet_arm(t, diff);
             t->wrap_flag = 0;
         }
     }
@@ -408,8 +416,7 @@ static void hpet_set_timer(HPETTimer *t)
             t->wrap_flag = 1;
         }
     }
-    timer_mod(t->qemu_timer,
-                   qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + (int64_t)ticks_to_ns(diff));
+    hpet_arm(t, diff);
 }
 
 static void hpet_del_timer(HPETTimer *t)
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 16/53] docs: vhost-user: replace _SLAVE_ with _BACKEND_
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (14 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 15/53] hw/timer/hpet: Fix expiration time overflow Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 17/53] libvhost-user: Adopt new backend naming Michael S. Tsirkin
                   ` (38 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Maxime Coquelin, Philippe Mathieu-Daudé

From: Maxime Coquelin <maxime.coquelin@redhat.com>

Backend's message and protocol features names were still
using "_SLAVE_" naming. For consistency with the new naming
convention, replace it with _BACKEND_.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Message-Id: <20230208203259.381326-2-maxime.coquelin@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 docs/interop/vhost-user.rst | 40 ++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/docs/interop/vhost-user.rst b/docs/interop/vhost-user.rst
index 3f18ab424e..8a5924ea75 100644
--- a/docs/interop/vhost-user.rst
+++ b/docs/interop/vhost-user.rst
@@ -315,7 +315,7 @@ in the ancillary data:
 * ``VHOST_USER_SET_VRING_KICK``
 * ``VHOST_USER_SET_VRING_CALL``
 * ``VHOST_USER_SET_VRING_ERR``
-* ``VHOST_USER_SET_SLAVE_REQ_FD``
+* ``VHOST_USER_SET_BACKEND_REQ_FD`` (previous name ``VHOST_USER_SET_SLAVE_REQ_FD``)
 * ``VHOST_USER_SET_INFLIGHT_FD`` (if ``VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD``)
 
 If *front-end* is unable to send the full message or receives a wrong
@@ -516,7 +516,7 @@ expected to reply with a zero payload, non-zero otherwise.
 
 The back-end relies on the back-end communication channel (see :ref:`Back-end
 communication <backend_communication>` section below) to send IOTLB miss
-and access failure events, by sending ``VHOST_USER_SLAVE_IOTLB_MSG``
+and access failure events, by sending ``VHOST_USER_BACKEND_IOTLB_MSG``
 requests to the front-end with a ``struct vhost_iotlb_msg`` as
 payload. For miss events, the iotlb payload has to be filled with the
 miss message type (1), the I/O virtual address and the permissions
@@ -540,15 +540,15 @@ Back-end communication
 ----------------------
 
 An optional communication channel is provided if the back-end declares
-``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` protocol feature, to allow the
+``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` protocol feature, to allow the
 back-end to make requests to the front-end.
 
-The fd is provided via ``VHOST_USER_SET_SLAVE_REQ_FD`` ancillary data.
+The fd is provided via ``VHOST_USER_SET_BACKEND_REQ_FD`` ancillary data.
 
-A back-end may then send ``VHOST_USER_SLAVE_*`` messages to the front-end
+A back-end may then send ``VHOST_USER_BACKEND_*`` messages to the front-end
 using this fd communication channel.
 
-If ``VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD`` protocol feature is
+If ``VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD`` protocol feature is
 negotiated, back-end can send file descriptors (at most 8 descriptors in
 each message) to front-end via ancillary data using this fd communication
 channel.
@@ -835,7 +835,7 @@ Note that due to the fact that too many messages on the sockets can
 cause the sending application(s) to block, it is not advised to use
 this feature unless absolutely necessary. It is also considered an
 error to negotiate this feature without also negotiating
-``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``,
+``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` and ``VHOST_USER_PROTOCOL_F_REPLY_ACK``,
 the former is necessary for getting a message channel from the back-end
 to the front-end, while the latter needs to be used with the in-band
 notification messages to block until they are processed, both to avoid
@@ -855,12 +855,12 @@ Protocol features
   #define VHOST_USER_PROTOCOL_F_RARP                  2
   #define VHOST_USER_PROTOCOL_F_REPLY_ACK             3
   #define VHOST_USER_PROTOCOL_F_MTU                   4
-  #define VHOST_USER_PROTOCOL_F_SLAVE_REQ             5
+  #define VHOST_USER_PROTOCOL_F_BACKEND_REQ           5
   #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN          6
   #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION        7
   #define VHOST_USER_PROTOCOL_F_PAGEFAULT             8
   #define VHOST_USER_PROTOCOL_F_CONFIG                9
-  #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD        10
+  #define VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD      10
   #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER        11
   #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD       12
   #define VHOST_USER_PROTOCOL_F_RESET_DEVICE         13
@@ -1059,8 +1059,8 @@ Front-end message types
   in the ancillary data. This signals that polling will be used
   instead of waiting for the call. Note that if the protocol features
   ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and
-  ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` have been negotiated this message
-  isn't necessary as the ``VHOST_USER_SLAVE_VRING_CALL`` message can be
+  ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` have been negotiated this message
+  isn't necessary as the ``VHOST_USER_BACKEND_VRING_CALL`` message can be
   used, it may however still be used to set an event file descriptor
   or to enable polling.
 
@@ -1077,8 +1077,8 @@ Front-end message types
   invalid FD flag. This flag is set when there is no file descriptor
   in the ancillary data. Note that if the protocol features
   ``VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS`` and
-  ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` have been negotiated this message
-  isn't necessary as the ``VHOST_USER_SLAVE_VRING_ERR`` message can be
+  ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` have been negotiated this message
+  isn't necessary as the ``VHOST_USER_BACKEND_VRING_ERR`` message can be
   used, it may however still be used to set an event file descriptor
   (which will be preferred over the message).
 
@@ -1139,7 +1139,7 @@ Front-end message types
   respond with zero in case the specified MTU is valid, or non-zero
   otherwise.
 
-``VHOST_USER_SET_SLAVE_REQ_FD``
+``VHOST_USER_SET_BACKEND_REQ_FD`` (previous name ``VHOST_USER_SET_SLAVE_REQ_FD``)
   :id: 21
   :equivalent ioctl: N/A
   :request payload: N/A
@@ -1150,7 +1150,7 @@ Front-end message types
 
   This request should be sent only when
   ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, and protocol
-  feature bit ``VHOST_USER_PROTOCOL_F_SLAVE_REQ`` bit is present in
+  feature bit ``VHOST_USER_PROTOCOL_F_BACKEND_REQ`` bit is present in
   ``VHOST_USER_GET_PROTOCOL_FEATURES``.  If
   ``VHOST_USER_PROTOCOL_F_REPLY_ACK`` is negotiated, the back-end must
   respond with zero for success, non-zero otherwise.
@@ -1429,7 +1429,7 @@ Back-end message types
 For this type of message, the request is sent by the back-end and the reply
 is sent by the front-end.
 
-``VHOST_USER_SLAVE_IOTLB_MSG``
+``VHOST_USER_BACKEND_IOTLB_MSG`` (previous name ``VHOST_USER_SLAVE_IOTLB_MSG``)
   :id: 1
   :equivalent ioctl: N/A (equivalent to ``VHOST_IOTLB_MSG`` message type)
   :request payload: ``struct vhost_iotlb_msg``
@@ -1444,7 +1444,7 @@ is sent by the front-end.
   ``VIRTIO_F_IOMMU_PLATFORM`` feature has been successfully
   negotiated.
 
-``VHOST_USER_SLAVE_CONFIG_CHANGE_MSG``
+``VHOST_USER_BACKEND_CONFIG_CHANGE_MSG`` (previous name ``VHOST_USER_SLAVE_CONFIG_CHANGE_MSG``)
   :id: 2
   :equivalent ioctl: N/A
   :request payload: N/A
@@ -1459,7 +1459,7 @@ is sent by the front-end.
   ``VHOST_USER_NEED_REPLY`` flag, the front-end must respond with zero when
   operation is successfully completed, or non-zero otherwise.
 
-``VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG``
+``VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG`` (previous name ``VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG``)
   :id: 3
   :equivalent ioctl: N/A
   :request payload: vring area description
@@ -1482,7 +1482,7 @@ is sent by the front-end.
   ``VHOST_USER_PROTOCOL_F_HOST_NOTIFIER`` protocol feature has been
   successfully negotiated.
 
-``VHOST_USER_SLAVE_VRING_CALL``
+``VHOST_USER_BACKEND_VRING_CALL`` (previous name ``VHOST_USER_SLAVE_VRING_CALL``)
   :id: 4
   :equivalent ioctl: N/A
   :request payload: vring state description
@@ -1496,7 +1496,7 @@ is sent by the front-end.
 
   The state.num field is currently reserved and must be set to 0.
 
-``VHOST_USER_SLAVE_VRING_ERR``
+``VHOST_USER_BACKEND_VRING_ERR`` (previous name ``VHOST_USER_SLAVE_VRING_ERR``)
   :id: 5
   :equivalent ioctl: N/A
   :request payload: vring state description
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 17/53] libvhost-user: Adopt new backend naming
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (15 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 16/53] docs: vhost-user: replace _SLAVE_ with _BACKEND_ Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 18/53] vhost-user: " Michael S. Tsirkin
                   ` (37 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Maxime Coquelin, Philippe Mathieu-Daudé

From: Maxime Coquelin <maxime.coquelin@redhat.com>

The Vhost-user specification changed feature and request
naming from _SLAVE_ to _BACKEND_.

This patch adopts the new naming convention.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Message-Id: <20230208203259.381326-3-maxime.coquelin@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 subprojects/libvhost-user/libvhost-user.h | 20 ++++++++++----------
 subprojects/libvhost-user/libvhost-user.c | 20 ++++++++++----------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvhost-user/libvhost-user.h
index 8cda9b8f57..8c5a2719e3 100644
--- a/subprojects/libvhost-user/libvhost-user.h
+++ b/subprojects/libvhost-user/libvhost-user.h
@@ -54,12 +54,12 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_RARP = 2,
     VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
     VHOST_USER_PROTOCOL_F_NET_MTU = 4,
-    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_BACKEND_REQ = 5,
     VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
     VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
     VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
     VHOST_USER_PROTOCOL_F_CONFIG = 9,
-    VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
+    VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD = 10,
     VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
     VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
     VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14,
@@ -92,7 +92,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_VRING_ENABLE = 18,
     VHOST_USER_SEND_RARP = 19,
     VHOST_USER_NET_SET_MTU = 20,
-    VHOST_USER_SET_SLAVE_REQ_FD = 21,
+    VHOST_USER_SET_BACKEND_REQ_FD = 21,
     VHOST_USER_IOTLB_MSG = 22,
     VHOST_USER_SET_VRING_ENDIAN = 23,
     VHOST_USER_GET_CONFIG = 24,
@@ -113,13 +113,13 @@ typedef enum VhostUserRequest {
 } VhostUserRequest;
 
 typedef enum VhostUserSlaveRequest {
-    VHOST_USER_SLAVE_NONE = 0,
-    VHOST_USER_SLAVE_IOTLB_MSG = 1,
-    VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
-    VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
-    VHOST_USER_SLAVE_VRING_CALL = 4,
-    VHOST_USER_SLAVE_VRING_ERR = 5,
-    VHOST_USER_SLAVE_MAX
+    VHOST_USER_BACKEND_NONE = 0,
+    VHOST_USER_BACKEND_IOTLB_MSG = 1,
+    VHOST_USER_BACKEND_CONFIG_CHANGE_MSG = 2,
+    VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG = 3,
+    VHOST_USER_BACKEND_VRING_CALL = 4,
+    VHOST_USER_BACKEND_VRING_ERR = 5,
+    VHOST_USER_BACKEND_MAX
 }  VhostUserSlaveRequest;
 
 typedef struct VhostUserMemoryRegion {
diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index fc69783d2b..f661af7c85 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -140,7 +140,7 @@ vu_request_to_string(unsigned int req)
         REQ(VHOST_USER_SET_VRING_ENABLE),
         REQ(VHOST_USER_SEND_RARP),
         REQ(VHOST_USER_NET_SET_MTU),
-        REQ(VHOST_USER_SET_SLAVE_REQ_FD),
+        REQ(VHOST_USER_SET_BACKEND_REQ_FD),
         REQ(VHOST_USER_IOTLB_MSG),
         REQ(VHOST_USER_SET_VRING_ENDIAN),
         REQ(VHOST_USER_GET_CONFIG),
@@ -1365,7 +1365,7 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
     int qidx = vq - dev->vq;
     int fd_num = 0;
     VhostUserMsg vmsg = {
-        .request = VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG,
+        .request = VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG,
         .flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY_MASK,
         .size = sizeof(vmsg.payload.area),
         .payload.area = {
@@ -1383,7 +1383,7 @@ bool vu_set_queue_host_notifier(VuDev *dev, VuVirtq *vq, int fd,
 
     vmsg.fd_num = fd_num;
 
-    if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD)) {
+    if (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD)) {
         return false;
     }
 
@@ -1461,9 +1461,9 @@ vu_get_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
      */
     uint64_t features = 1ULL << VHOST_USER_PROTOCOL_F_MQ |
                         1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD |
-                        1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ |
+                        1ULL << VHOST_USER_PROTOCOL_F_BACKEND_REQ |
                         1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER |
-                        1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD |
+                        1ULL << VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD |
                         1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK |
                         1ULL << VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS;
 
@@ -1494,7 +1494,7 @@ vu_set_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
 
     if (vu_has_protocol_feature(dev,
                                 VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS) &&
-        (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ) ||
+        (!vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ) ||
          !vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_REPLY_ACK))) {
         /*
          * The use case for using messages for kick/call is simulation, to make
@@ -1507,7 +1507,7 @@ vu_set_protocol_features_exec(VuDev *dev, VhostUserMsg *vmsg)
          * that actually enables the simulation case.
          */
         vu_panic(dev,
-                 "F_IN_BAND_NOTIFICATIONS requires F_SLAVE_REQ && F_REPLY_ACK");
+                 "F_IN_BAND_NOTIFICATIONS requires F_BACKEND_REQ && F_REPLY_ACK");
         return false;
     }
 
@@ -1910,7 +1910,7 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)
         return vu_get_queue_num_exec(dev, vmsg);
     case VHOST_USER_SET_VRING_ENABLE:
         return vu_set_vring_enable_exec(dev, vmsg);
-    case VHOST_USER_SET_SLAVE_REQ_FD:
+    case VHOST_USER_SET_BACKEND_REQ_FD:
         return vu_set_slave_req_fd(dev, vmsg);
     case VHOST_USER_GET_CONFIG:
         return vu_get_config(dev, vmsg);
@@ -2416,9 +2416,9 @@ static void _vu_queue_notify(VuDev *dev, VuVirtq *vq, bool sync)
     if (vq->call_fd < 0 &&
         vu_has_protocol_feature(dev,
                                 VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS) &&
-        vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_SLAVE_REQ)) {
+        vu_has_protocol_feature(dev, VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
         VhostUserMsg vmsg = {
-            .request = VHOST_USER_SLAVE_VRING_CALL,
+            .request = VHOST_USER_BACKEND_VRING_CALL,
             .flags = VHOST_USER_VERSION,
             .size = sizeof(vmsg.payload.state),
             .payload.state = {
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 18/53] vhost-user: Adopt new backend naming
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (16 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 17/53] libvhost-user: Adopt new backend naming Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 19/53] vdpa: stop all svq on device deletion Michael S. Tsirkin
                   ` (36 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Maxime Coquelin, Philippe Mathieu-Daudé

From: Maxime Coquelin <maxime.coquelin@redhat.com>

The Vhost-user specification changed feature and request
naming from _SLAVE_ to _BACKEND_.

This patch adopts the new naming convention.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Message-Id: <20230208203259.381326-4-maxime.coquelin@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-user.c | 30 +++++++++++++++---------------
 hw/virtio/virtio-qmp.c | 12 ++++++------
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index e68daa35d4..8968541514 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -40,7 +40,7 @@
 
 #define VHOST_MEMORY_BASELINE_NREGIONS    8
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
-#define VHOST_USER_SLAVE_MAX_FDS     8
+#define VHOST_USER_BACKEND_MAX_FDS     8
 
 /*
  * Set maximum number of RAM slots supported to
@@ -71,12 +71,12 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_RARP = 2,
     VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
     VHOST_USER_PROTOCOL_F_NET_MTU = 4,
-    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_BACKEND_REQ = 5,
     VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
     VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
     VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
     VHOST_USER_PROTOCOL_F_CONFIG = 9,
-    VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
+    VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD = 10,
     VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
     VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
     VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
@@ -110,7 +110,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_VRING_ENABLE = 18,
     VHOST_USER_SEND_RARP = 19,
     VHOST_USER_NET_SET_MTU = 20,
-    VHOST_USER_SET_SLAVE_REQ_FD = 21,
+    VHOST_USER_SET_BACKEND_REQ_FD = 21,
     VHOST_USER_IOTLB_MSG = 22,
     VHOST_USER_SET_VRING_ENDIAN = 23,
     VHOST_USER_GET_CONFIG = 24,
@@ -134,11 +134,11 @@ typedef enum VhostUserRequest {
 } VhostUserRequest;
 
 typedef enum VhostUserSlaveRequest {
-    VHOST_USER_SLAVE_NONE = 0,
-    VHOST_USER_SLAVE_IOTLB_MSG = 1,
-    VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
-    VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
-    VHOST_USER_SLAVE_MAX
+    VHOST_USER_BACKEND_NONE = 0,
+    VHOST_USER_BACKEND_IOTLB_MSG = 1,
+    VHOST_USER_BACKEND_CONFIG_CHANGE_MSG = 2,
+    VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG = 3,
+    VHOST_USER_BACKEND_MAX
 }  VhostUserSlaveRequest;
 
 typedef struct VhostUserMemoryRegion {
@@ -1638,13 +1638,13 @@ static gboolean slave_read(QIOChannel *ioc, GIOCondition condition,
     }
 
     switch (hdr.request) {
-    case VHOST_USER_SLAVE_IOTLB_MSG:
+    case VHOST_USER_BACKEND_IOTLB_MSG:
         ret = vhost_backend_handle_iotlb_msg(dev, &payload.iotlb);
         break;
-    case VHOST_USER_SLAVE_CONFIG_CHANGE_MSG :
+    case VHOST_USER_BACKEND_CONFIG_CHANGE_MSG:
         ret = vhost_user_slave_handle_config_change(dev);
         break;
-    case VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG:
+    case VHOST_USER_BACKEND_VRING_HOST_NOTIFIER_MSG:
         ret = vhost_user_slave_handle_vring_host_notifier(dev, &payload.area,
                                                           fd ? fd[0] : -1);
         break;
@@ -1696,7 +1696,7 @@ fdcleanup:
 static int vhost_setup_slave_channel(struct vhost_dev *dev)
 {
     VhostUserMsg msg = {
-        .hdr.request = VHOST_USER_SET_SLAVE_REQ_FD,
+        .hdr.request = VHOST_USER_SET_BACKEND_REQ_FD,
         .hdr.flags = VHOST_USER_VERSION,
     };
     struct vhost_user *u = dev->opaque;
@@ -1707,7 +1707,7 @@ static int vhost_setup_slave_channel(struct vhost_dev *dev)
     QIOChannel *ioc;
 
     if (!virtio_has_feature(dev->protocol_features,
-                            VHOST_USER_PROTOCOL_F_SLAVE_REQ)) {
+                            VHOST_USER_PROTOCOL_F_BACKEND_REQ)) {
         return 0;
     }
 
@@ -2065,7 +2065,7 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
 
         if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) &&
                 !(virtio_has_feature(dev->protocol_features,
-                    VHOST_USER_PROTOCOL_F_SLAVE_REQ) &&
+                    VHOST_USER_PROTOCOL_F_BACKEND_REQ) &&
                  virtio_has_feature(dev->protocol_features,
                     VHOST_USER_PROTOCOL_F_REPLY_ACK))) {
             error_setg(errp, "IOMMU support requires reply-ack and "
diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c
index e4d4bece2d..b70148aba9 100644
--- a/hw/virtio/virtio-qmp.c
+++ b/hw/virtio/virtio-qmp.c
@@ -42,12 +42,12 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_RARP = 2,
     VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
     VHOST_USER_PROTOCOL_F_NET_MTU = 4,
-    VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
+    VHOST_USER_PROTOCOL_F_BACKEND_REQ = 5,
     VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
     VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
     VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
     VHOST_USER_PROTOCOL_F_CONFIG = 9,
-    VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD = 10,
+    VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD = 10,
     VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
     VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
     VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
@@ -101,8 +101,8 @@ static const qmp_virtio_feature_map_t vhost_user_protocol_map[] = {
             "supported"),
     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_NET_MTU, \
             "VHOST_USER_PROTOCOL_F_NET_MTU: Expose host MTU to guest supported"),
-    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_SLAVE_REQ, \
-            "VHOST_USER_PROTOCOL_F_SLAVE_REQ: Socket fd for back-end initiated "
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_BACKEND_REQ, \
+            "VHOST_USER_PROTOCOL_F_BACKEND_REQ: Socket fd for back-end initiated "
             "requests supported"),
     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CROSS_ENDIAN, \
             "VHOST_USER_PROTOCOL_F_CROSS_ENDIAN: Endianness of VQs for legacy "
@@ -116,8 +116,8 @@ static const qmp_virtio_feature_map_t vhost_user_protocol_map[] = {
     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CONFIG, \
             "VHOST_USER_PROTOCOL_F_CONFIG: Vhost-user messaging for virtio "
             "device configuration space supported"),
-    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD, \
-            "VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD: Slave fd communication "
+    FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD, \
+            "VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD: Slave fd communication "
             "channel supported"),
     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_HOST_NOTIFIER, \
             "VHOST_USER_PROTOCOL_F_HOST_NOTIFIER: Host notifiers for specified "
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 19/53] vdpa: stop all svq on device deletion
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (17 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 18/53] vhost-user: " Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 20/53] pci/shpc: set attention led to OFF on reset Michael S. Tsirkin
                   ` (35 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Eugenio Pérez, Lei Yang, Laurent Vivier, Jason Wang

From: Eugenio Pérez <eperezma@redhat.com>

Not stopping them leave the device in a bad state when virtio-net
fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown
because cleanup is called right after vhost_vdpa_dev_start(false).  But
devices hot unplug does not call vdpa device cleanups.  This lead to all
the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with
vhost_vdpa_svqs_start.

Fixes: dff4426fa656 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
Reported-by: Lei Yang <leiyang@redhat.com>
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Message-Id: <20230209170004.899472-1-eperezma@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/vhost-vdpa.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 542e003101..df3a1e92ac 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -689,26 +689,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
     return ret;
 }
 
-static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
-{
-    if (!v->shadow_vqs_enabled) {
-        return;
-    }
-
-    for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
-        VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
-        vhost_svq_stop(svq);
-    }
-}
-
 static int vhost_vdpa_reset_device(struct vhost_dev *dev)
 {
-    struct vhost_vdpa *v = dev->opaque;
     int ret;
     uint8_t status = 0;
 
-    vhost_vdpa_reset_svq(v);
-
     ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
     trace_vhost_vdpa_reset_device(dev, status);
     return ret;
@@ -1100,6 +1085,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
 
     for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
         VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
+
+        vhost_svq_stop(svq);
         vhost_vdpa_svq_unmap_rings(dev, svq);
 
         event_notifier_cleanup(&svq->hdev_kick);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 20/53] pci/shpc: set attention led to OFF on reset
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (18 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 19/53] vdpa: stop all svq on device deletion Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 21/53] pci/shpc: change shpc_get_status() return type to uint8_t Michael S. Tsirkin
                   ` (34 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

0 is not a valid state for the led. Let's start with OFF.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-2-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index fca7f6691a..1b3f619dc9 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -223,6 +223,7 @@ void shpc_reset(PCIDevice *d)
                             SHPC_SLOT_STATUS_PRSNT_MASK);
             shpc_set_status(shpc, i, SHPC_LED_OFF, SHPC_SLOT_PWR_LED_MASK);
         }
+        shpc_set_status(shpc, i, SHPC_LED_OFF, SHPC_SLOT_ATTN_LED_MASK);
         shpc_set_status(shpc, i, 0, SHPC_SLOT_STATUS_66);
     }
     shpc_set_sec_bus_speed(shpc, SHPC_SEC_BUS_33);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 21/53] pci/shpc: change shpc_get_status() return type to uint8_t
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (19 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 20/53] pci/shpc: set attention led to OFF on reset Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 22/53] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Michael S. Tsirkin
                   ` (33 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

The result of the function is always one byte. The result is always
assigned to uint8_t variable. Also, shpc_get_status() should be
symmetric to shpc_set_status() which has uint8_t value argument.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-3-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 1b3f619dc9..5d71569b13 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -123,10 +123,13 @@
 #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1)
 #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1)
 
-static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
+static uint8_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk)
 {
     uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot);
-    return (pci_get_word(status) & msk) >> ctz32(msk);
+    uint16_t result = (pci_get_word(status) & msk) >> ctz32(msk);
+
+    assert(result <= UINT8_MAX);
+    return result;
 }
 
 static void shpc_set_status(SHPCDevice *shpc,
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 22/53] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (20 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 21/53] pci/shpc: change shpc_get_status() return type to uint8_t Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 23/53] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Michael S. Tsirkin
                   ` (32 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

ENABLED -> PWRONLY transition is not allowed and we handle it by
shpc_invalid_command(). But PWRONLY -> ENABLED transition is silently
ignored, which seems wrong. Let's handle it as correct.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-4-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 5d71569b13..25e4172382 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -273,28 +273,22 @@ static void shpc_slot_command(SHPCDevice *shpc, uint8_t target,
         return;
     }
 
-    switch (power) {
-    case SHPC_LED_NO:
-        break;
-    default:
+    if (power != SHPC_LED_NO) {
         /* TODO: send event to monitor */
         shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK);
     }
-    switch (attn) {
-    case SHPC_LED_NO:
-        break;
-    default:
+    if (attn != SHPC_LED_NO) {
         /* TODO: send event to monitor */
         shpc_set_status(shpc, slot, attn, SHPC_SLOT_ATTN_LED_MASK);
     }
+    if (state != SHPC_STATE_NO) {
+        shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK);
+    }
 
-    if ((current_state == SHPC_STATE_DISABLED && state == SHPC_STATE_PWRONLY) ||
-        (current_state == SHPC_STATE_DISABLED && state == SHPC_STATE_ENABLED)) {
-        shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK);
-    } else if ((current_state == SHPC_STATE_ENABLED ||
-                current_state == SHPC_STATE_PWRONLY) &&
-               state == SHPC_STATE_DISABLED) {
-        shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK);
+    if ((current_state == SHPC_STATE_ENABLED ||
+         current_state == SHPC_STATE_PWRONLY) &&
+        state == SHPC_STATE_DISABLED)
+    {
         power = shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK);
         /* TODO: track what monitor requested. */
         /* Look at LED to figure out whether it's ok to remove the device. */
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 23/53] pci/shpc: more generic handle hot-unplug in shpc_slot_command()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (21 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 22/53] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 24/53] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Michael S. Tsirkin
                   ` (31 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Free slot if both conditions (power-led = OFF and state = DISABLED)
becomes true regardless of the sequence. It is similar to how PCIe
hotplug works.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-5-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 52 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 25e4172382..959dc470f3 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -258,49 +258,59 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
     }
 }
 
+static bool shpc_slot_is_off(uint8_t state, uint8_t power, uint8_t attn)
+{
+    return state == SHPC_STATE_DISABLED && power == SHPC_LED_OFF;
+}
+
 static void shpc_slot_command(SHPCDevice *shpc, uint8_t target,
                               uint8_t state, uint8_t power, uint8_t attn)
 {
-    uint8_t current_state;
     int slot = SHPC_LOGICAL_TO_IDX(target);
+    uint8_t old_state = shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK);
+    uint8_t old_power = shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK);
+    uint8_t old_attn = shpc_get_status(shpc, slot, SHPC_SLOT_ATTN_LED_MASK);
+
     if (target < SHPC_CMD_TRGT_MIN || slot >= shpc->nslots) {
         shpc_invalid_command(shpc);
         return;
     }
-    current_state = shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK);
-    if (current_state == SHPC_STATE_ENABLED && state == SHPC_STATE_PWRONLY) {
+
+    if (old_state == SHPC_STATE_ENABLED && state == SHPC_STATE_PWRONLY) {
         shpc_invalid_command(shpc);
         return;
     }
 
-    if (power != SHPC_LED_NO) {
+    if (power == SHPC_LED_NO) {
+        power = old_power;
+    } else {
         /* TODO: send event to monitor */
         shpc_set_status(shpc, slot, power, SHPC_SLOT_PWR_LED_MASK);
     }
-    if (attn != SHPC_LED_NO) {
+
+    if (attn == SHPC_LED_NO) {
+        attn = old_attn;
+    } else {
         /* TODO: send event to monitor */
         shpc_set_status(shpc, slot, attn, SHPC_SLOT_ATTN_LED_MASK);
     }
-    if (state != SHPC_STATE_NO) {
+
+    if (state == SHPC_STATE_NO) {
+        state = old_state;
+    } else {
         shpc_set_status(shpc, slot, state, SHPC_SLOT_STATE_MASK);
     }
 
-    if ((current_state == SHPC_STATE_ENABLED ||
-         current_state == SHPC_STATE_PWRONLY) &&
-        state == SHPC_STATE_DISABLED)
+    if (!shpc_slot_is_off(old_state, old_power, old_attn) &&
+        shpc_slot_is_off(state, power, attn))
     {
-        power = shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK);
-        /* TODO: track what monitor requested. */
-        /* Look at LED to figure out whether it's ok to remove the device. */
-        if (power == SHPC_LED_OFF) {
-            shpc_free_devices_in_slot(shpc, slot);
-            shpc_set_status(shpc, slot, 1, SHPC_SLOT_STATUS_MRL_OPEN);
-            shpc_set_status(shpc, slot, SHPC_SLOT_STATUS_PRSNT_EMPTY,
-                            SHPC_SLOT_STATUS_PRSNT_MASK);
-            shpc->config[SHPC_SLOT_EVENT_LATCH(slot)] |=
-                SHPC_SLOT_EVENT_MRL |
-                SHPC_SLOT_EVENT_PRESENCE;
-        }
+        shpc_free_devices_in_slot(shpc, slot);
+        shpc_set_status(shpc, slot, 1, SHPC_SLOT_STATUS_MRL_OPEN);
+        shpc_set_status(shpc, slot, SHPC_SLOT_STATUS_PRSNT_EMPTY,
+                        SHPC_SLOT_STATUS_PRSNT_MASK);
+        shpc->config[SHPC_SLOT_EVENT_LATCH(slot)] |=
+            SHPC_SLOT_EVENT_MRL |
+            SHPC_SLOT_EVENT_PRESENCE;
     }
 }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 24/53] pci/shpc: pass PCIDevice pointer to shpc_slot_command()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (22 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 23/53] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 25/53] pci/shpc: refactor shpc_device_plug_common() Michael S. Tsirkin
                   ` (30 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

We'll need it in further patch to report bridge in QAPI event.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-6-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 959dc470f3..9f964b1d70 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -263,9 +263,10 @@ static bool shpc_slot_is_off(uint8_t state, uint8_t power, uint8_t attn)
     return state == SHPC_STATE_DISABLED && power == SHPC_LED_OFF;
 }
 
-static void shpc_slot_command(SHPCDevice *shpc, uint8_t target,
+static void shpc_slot_command(PCIDevice *d, uint8_t target,
                               uint8_t state, uint8_t power, uint8_t attn)
 {
+    SHPCDevice *shpc = d->shpc;
     int slot = SHPC_LOGICAL_TO_IDX(target);
     uint8_t old_state = shpc_get_status(shpc, slot, SHPC_SLOT_STATE_MASK);
     uint8_t old_power = shpc_get_status(shpc, slot, SHPC_SLOT_PWR_LED_MASK);
@@ -314,8 +315,9 @@ static void shpc_slot_command(SHPCDevice *shpc, uint8_t target,
     }
 }
 
-static void shpc_command(SHPCDevice *shpc)
+static void shpc_command(PCIDevice *d)
 {
+    SHPCDevice *shpc = d->shpc;
     uint8_t code = pci_get_byte(shpc->config + SHPC_CMD_CODE);
     uint8_t speed;
     uint8_t target;
@@ -336,7 +338,7 @@ static void shpc_command(SHPCDevice *shpc)
         state = (code & SHPC_SLOT_STATE_MASK) >> SHPC_SLOT_STATE_SHIFT;
         power = (code & SHPC_SLOT_PWR_LED_MASK) >> SHPC_SLOT_PWR_LED_SHIFT;
         attn = (code & SHPC_SLOT_ATTN_LED_MASK) >> SHPC_SLOT_ATTN_LED_SHIFT;
-        shpc_slot_command(shpc, target, state, power, attn);
+        shpc_slot_command(d, target, state, power, attn);
         break;
     case 0x40 ... 0x47:
         speed = code & SHPC_SEC_BUS_MASK;
@@ -354,10 +356,10 @@ static void shpc_command(SHPCDevice *shpc)
         }
         for (i = 0; i < shpc->nslots; ++i) {
             if (!(shpc_get_status(shpc, i, SHPC_SLOT_STATUS_MRL_OPEN))) {
-                shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN,
+                shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN,
                                   SHPC_STATE_PWRONLY, SHPC_LED_ON, SHPC_LED_NO);
             } else {
-                shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN,
+                shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN,
                                   SHPC_STATE_NO, SHPC_LED_OFF, SHPC_LED_NO);
             }
         }
@@ -375,10 +377,10 @@ static void shpc_command(SHPCDevice *shpc)
         }
         for (i = 0; i < shpc->nslots; ++i) {
             if (!(shpc_get_status(shpc, i, SHPC_SLOT_STATUS_MRL_OPEN))) {
-                shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN,
+                shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN,
                                   SHPC_STATE_ENABLED, SHPC_LED_ON, SHPC_LED_NO);
             } else {
-                shpc_slot_command(shpc, i + SHPC_CMD_TRGT_MIN,
+                shpc_slot_command(d, i + SHPC_CMD_TRGT_MIN,
                                   SHPC_STATE_NO, SHPC_LED_OFF, SHPC_LED_NO);
             }
         }
@@ -410,7 +412,7 @@ static void shpc_write(PCIDevice *d, unsigned addr, uint64_t val, int l)
         shpc->config[a] &= ~(val & w1cmask); /* W1C: Write 1 to Clear */
     }
     if (ranges_overlap(addr, l, SHPC_CMD_CODE, 2)) {
-        shpc_command(shpc);
+        shpc_command(d);
     }
     shpc_interrupt_update(d);
 }
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 25/53] pci/shpc: refactor shpc_device_plug_common()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (23 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 24/53] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 26/53] pcie: pcie_cap_slot_write_config(): use correct macro Michael S. Tsirkin
                   ` (29 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Rename it to shpc_device_get_slot(), to mention what it does rather
than how it is used. It also helps to reuse it in further commit.

Also, add a return value and get rid of local_err.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-7-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/shpc.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c
index 9f964b1d70..e7bc7192f1 100644
--- a/hw/pci/shpc.c
+++ b/hw/pci/shpc.c
@@ -496,8 +496,9 @@ static const MemoryRegionOps shpc_mmio_ops = {
         .max_access_size = 4,
     },
 };
-static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
-                                    SHPCDevice *shpc, Error **errp)
+
+static bool shpc_device_get_slot(PCIDevice *affected_dev, int *slot,
+                                 SHPCDevice *shpc, Error **errp)
 {
     int pci_slot = PCI_SLOT(affected_dev->devfn);
     *slot = SHPC_PCI_TO_IDX(pci_slot);
@@ -507,21 +508,20 @@ static void shpc_device_plug_common(PCIDevice *affected_dev, int *slot,
                    "controller. Valid slots are between %d and %d.",
                    pci_slot, SHPC_IDX_TO_PCI(0),
                    SHPC_IDX_TO_PCI(shpc->nslots) - 1);
-        return;
+        return false;
     }
+
+    return true;
 }
 
 void shpc_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
                             Error **errp)
 {
-    Error *local_err = NULL;
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
     SHPCDevice *shpc = pci_hotplug_dev->shpc;
     int slot;
 
-    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
         return;
     }
 
@@ -563,16 +563,13 @@ void shpc_device_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
 void shpc_device_unplug_request_cb(HotplugHandler *hotplug_dev,
                                    DeviceState *dev, Error **errp)
 {
-    Error *local_err = NULL;
     PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev);
     SHPCDevice *shpc = pci_hotplug_dev->shpc;
     uint8_t state;
     uint8_t led;
     int slot;
 
-    shpc_device_plug_common(PCI_DEVICE(dev), &slot, shpc, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!shpc_device_get_slot(PCI_DEVICE(dev), &slot, shpc, errp)) {
         return;
     }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 26/53] pcie: pcie_cap_slot_write_config(): use correct macro
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (24 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 25/53] pci/shpc: refactor shpc_device_plug_common() Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 27/53] pcie_regs: drop duplicated indicator value macros Michael S. Tsirkin
                   ` (28 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy,
	Philippe Mathieu-Daudé,
	Anton Kuchin, Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

PCI_EXP_SLTCTL_PIC_OFF is a value, and PCI_EXP_SLTCTL_PIC is a mask.
Happily PCI_EXP_SLTCTL_PIC_OFF is a maximum value for this mask and is
equal to the mask itself. Still the code looks like a bug. Let's make
it more reader-friendly.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-8-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pcie.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 924fdabd15..82ef723983 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -770,9 +770,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
      * control of powered off slots before powering them on.
      */
     if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) &&
-        (val & PCI_EXP_SLTCTL_PIC_OFF) == PCI_EXP_SLTCTL_PIC_OFF &&
+        (val & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PIC_OFF &&
         (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) ||
-        (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) != PCI_EXP_SLTCTL_PIC_OFF)) {
+        (old_slt_ctl & PCI_EXP_SLTCTL_PIC) != PCI_EXP_SLTCTL_PIC_OFF)) {
         pcie_cap_slot_do_unplug(dev);
     }
     pcie_cap_update_power(dev);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 27/53] pcie_regs: drop duplicated indicator value macros
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (25 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 26/53] pcie: pcie_cap_slot_write_config(): use correct macro Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 28/53] pcie: drop unused PCIExpressIndicator Michael S. Tsirkin
                   ` (27 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy,
	Philippe Mathieu-Daudé,
	Anton Kuchin, Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

We already have indicator values in
include/standard-headers/linux/pci_regs.h , no reason to reinvent them
in include/hw/pci/pcie_regs.h. (and we already have usage of
PCI_EXP_SLTCTL_PWR_IND_BLINK and PCI_EXP_SLTCTL_PWR_IND_OFF in
hw/pci/pcie.c, so let's be consistent)

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-9-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/pci/pcie_regs.h |  9 ---------
 hw/pci/pcie.c              | 13 +++++++------
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h
index 963dc2e170..00b595a82e 100644
--- a/include/hw/pci/pcie_regs.h
+++ b/include/hw/pci/pcie_regs.h
@@ -70,15 +70,6 @@ typedef enum PCIExpLinkWidth {
 #define PCI_EXP_SLTCTL_IND_ON           0x1
 #define PCI_EXP_SLTCTL_IND_BLINK        0x2
 #define PCI_EXP_SLTCTL_IND_OFF          0x3
-#define PCI_EXP_SLTCTL_AIC_SHIFT        ctz32(PCI_EXP_SLTCTL_AIC)
-#define PCI_EXP_SLTCTL_AIC_OFF                          \
-    (PCI_EXP_SLTCTL_IND_OFF << PCI_EXP_SLTCTL_AIC_SHIFT)
-
-#define PCI_EXP_SLTCTL_PIC_SHIFT        ctz32(PCI_EXP_SLTCTL_PIC)
-#define PCI_EXP_SLTCTL_PIC_OFF                          \
-    (PCI_EXP_SLTCTL_IND_OFF << PCI_EXP_SLTCTL_PIC_SHIFT)
-#define PCI_EXP_SLTCTL_PIC_ON                          \
-    (PCI_EXP_SLTCTL_IND_ON << PCI_EXP_SLTCTL_PIC_SHIFT)
 
 #define PCI_EXP_SLTCTL_SUPPORTED        \
             (PCI_EXP_SLTCTL_ABPE |      \
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 82ef723983..ccdb2377e1 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -634,8 +634,8 @@ void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s)
                                  PCI_EXP_SLTCTL_PIC |
                                  PCI_EXP_SLTCTL_AIC);
     pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCTL,
-                               PCI_EXP_SLTCTL_PIC_OFF |
-                               PCI_EXP_SLTCTL_AIC_OFF);
+                               PCI_EXP_SLTCTL_PWR_IND_OFF |
+                               PCI_EXP_SLTCTL_ATTN_IND_OFF);
     pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL,
                                PCI_EXP_SLTCTL_PIC |
                                PCI_EXP_SLTCTL_AIC |
@@ -679,7 +679,7 @@ void pcie_cap_slot_reset(PCIDevice *dev)
                                  PCI_EXP_SLTCTL_PDCE |
                                  PCI_EXP_SLTCTL_ABPE);
     pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
-                               PCI_EXP_SLTCTL_AIC_OFF);
+                               PCI_EXP_SLTCTL_ATTN_IND_OFF);
 
     if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {
         /* Downstream ports enforce device number 0. */
@@ -694,7 +694,8 @@ void pcie_cap_slot_reset(PCIDevice *dev)
                                        PCI_EXP_SLTCTL_PCC);
         }
 
-        pic = populated ? PCI_EXP_SLTCTL_PIC_ON : PCI_EXP_SLTCTL_PIC_OFF;
+        pic = populated ?
+                PCI_EXP_SLTCTL_PWR_IND_ON : PCI_EXP_SLTCTL_PWR_IND_OFF;
         pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL, pic);
     }
 
@@ -770,9 +771,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
      * control of powered off slots before powering them on.
      */
     if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) &&
-        (val & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PIC_OFF &&
+        (val & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF &&
         (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) ||
-        (old_slt_ctl & PCI_EXP_SLTCTL_PIC) != PCI_EXP_SLTCTL_PIC_OFF)) {
+        (old_slt_ctl & PCI_EXP_SLTCTL_PIC) != PCI_EXP_SLTCTL_PWR_IND_OFF)) {
         pcie_cap_slot_do_unplug(dev);
     }
     pcie_cap_update_power(dev);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 28/53] pcie: drop unused PCIExpressIndicator
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (26 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 27/53] pcie_regs: drop duplicated indicator value macros Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:25 ` [PULL 29/53] pcie: pcie_cap_slot_enable_power() use correct helper Michael S. Tsirkin
                   ` (26 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy,
	Philippe Mathieu-Daudé,
	Anton Kuchin, Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

The structure type is unused. Also, it's the only user of corresponding
macros, so drop them too.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-10-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/pci/pcie.h      | 8 --------
 include/hw/pci/pcie_regs.h | 5 -----
 2 files changed, 13 deletions(-)

diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
index 798a262a0a..3cc2b15957 100644
--- a/include/hw/pci/pcie.h
+++ b/include/hw/pci/pcie.h
@@ -27,14 +27,6 @@
 #include "hw/pci/pcie_sriov.h"
 #include "hw/hotplug.h"
 
-typedef enum {
-    /* for attention and power indicator */
-    PCI_EXP_HP_IND_RESERVED     = PCI_EXP_SLTCTL_IND_RESERVED,
-    PCI_EXP_HP_IND_ON           = PCI_EXP_SLTCTL_IND_ON,
-    PCI_EXP_HP_IND_BLINK        = PCI_EXP_SLTCTL_IND_BLINK,
-    PCI_EXP_HP_IND_OFF          = PCI_EXP_SLTCTL_IND_OFF,
-} PCIExpressIndicator;
-
 typedef enum {
     /* these bits must match the bits in Slot Control/Status registers.
      * PCI_EXP_HP_EV_xxx = PCI_EXP_SLTCTL_xxxE = PCI_EXP_SLTSTA_xxx
diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h
index 00b595a82e..1fe0bdd25b 100644
--- a/include/hw/pci/pcie_regs.h
+++ b/include/hw/pci/pcie_regs.h
@@ -66,11 +66,6 @@ typedef enum PCIExpLinkWidth {
 
 #define PCI_EXP_SLTCAP_PSN_SHIFT        ctz32(PCI_EXP_SLTCAP_PSN)
 
-#define PCI_EXP_SLTCTL_IND_RESERVED     0x0
-#define PCI_EXP_SLTCTL_IND_ON           0x1
-#define PCI_EXP_SLTCTL_IND_BLINK        0x2
-#define PCI_EXP_SLTCTL_IND_OFF          0x3
-
 #define PCI_EXP_SLTCTL_SUPPORTED        \
             (PCI_EXP_SLTCTL_ABPE |      \
              PCI_EXP_SLTCTL_PDCE |      \
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 29/53] pcie: pcie_cap_slot_enable_power() use correct helper
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (27 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 28/53] pcie: drop unused PCIExpressIndicator Michael S. Tsirkin
@ 2023-03-02  8:25 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 30/53] pcie: introduce pcie_sltctl_powered_off() helper Michael S. Tsirkin
                   ` (25 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:25 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

*_by_mask() helpers shouldn't be used here (and that's the only one).
*_by_mask() helpers do shift their value argument, but in pcie.c code
we use values that are already shifted appropriately.
Happily, PCI_EXP_SLTCTL_PWR_ON is zero, so shift doesn't matter. But if
we apply same helper for PCI_EXP_SLTCTL_PWR_OFF constant it will do
wrong thing.

So, let's use instead pci_word_test_and_clear_mask() which is already
used in the file to clear PCI_EXP_SLTCTL_PWR_OFF bit in
pcie_cap_slot_init() and pcie_cap_slot_reset().

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-11-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pcie.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index ccdb2377e1..db8360226f 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -373,8 +373,8 @@ void pcie_cap_slot_enable_power(PCIDevice *dev)
     uint32_t sltcap = pci_get_long(exp_cap + PCI_EXP_SLTCAP);
 
     if (sltcap & PCI_EXP_SLTCAP_PCP) {
-        pci_set_word_by_mask(exp_cap + PCI_EXP_SLTCTL,
-                             PCI_EXP_SLTCTL_PCC, PCI_EXP_SLTCTL_PWR_ON);
+        pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTCTL,
+                                     PCI_EXP_SLTCTL_PCC);
     }
 }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 30/53] pcie: introduce pcie_sltctl_powered_off() helper
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (28 preceding siblings ...)
  2023-03-02  8:25 ` [PULL 29/53] pcie: pcie_cap_slot_enable_power() use correct helper Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 31/53] pcie: set power indicator to off on reset by default Michael S. Tsirkin
                   ` (24 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy,
	Philippe Mathieu-Daudé,
	Anton Kuchin, Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

In pcie_cap_slot_write_config() we check for PCI_EXP_SLTCTL_PWR_OFF in
a bad form. We should distinguish PCI_EXP_SLTCTL_PWR which is a "mask"
and PCI_EXP_SLTCTL_PWR_OFF which is value for that mask.

Better code is in pcie_cap_slot_unplug_request_cb() and in
pcie_cap_update_power(). Let's use same pattern everywhere. To simplify
things add also a helper.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-12-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pcie.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index db8360226f..90faf0710a 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -39,6 +39,11 @@
 #define PCIE_DEV_PRINTF(dev, fmt, ...)                                  \
     PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__)
 
+static bool pcie_sltctl_powered_off(uint16_t sltctl)
+{
+    return (sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF
+        && (sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF;
+}
 
 /***************************************************************************
  * pci express capability helper functions
@@ -395,6 +400,7 @@ static void pcie_cap_update_power(PCIDevice *hotplug_dev)
 
     if (sltcap & PCI_EXP_SLTCAP_PCP) {
         power = (sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_ON;
+        /* Don't we need to check also (sltctl & PCI_EXP_SLTCTL_PIC) ? */
     }
 
     pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
@@ -579,8 +585,7 @@ void pcie_cap_slot_unplug_request_cb(HotplugHandler *hotplug_dev,
         return;
     }
 
-    if (((sltctl & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF) &&
-        ((sltctl & PCI_EXP_SLTCTL_PCC) == PCI_EXP_SLTCTL_PWR_OFF)) {
+    if (pcie_sltctl_powered_off(sltctl)) {
         /* slot is powered off -> unplug without round-trip to the guest */
         pcie_cap_slot_do_unplug(hotplug_pdev);
         hotplug_event_notify(hotplug_pdev);
@@ -770,10 +775,9 @@ void pcie_cap_slot_write_config(PCIDevice *dev,
      * this is a work around for guests that overwrite
      * control of powered off slots before powering them on.
      */
-    if ((sltsta & PCI_EXP_SLTSTA_PDS) && (val & PCI_EXP_SLTCTL_PCC) &&
-        (val & PCI_EXP_SLTCTL_PIC) == PCI_EXP_SLTCTL_PWR_IND_OFF &&
-        (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) ||
-        (old_slt_ctl & PCI_EXP_SLTCTL_PIC) != PCI_EXP_SLTCTL_PWR_IND_OFF)) {
+    if ((sltsta & PCI_EXP_SLTSTA_PDS) && pcie_sltctl_powered_off(val) &&
+        !pcie_sltctl_powered_off(old_slt_ctl))
+    {
         pcie_cap_slot_do_unplug(dev);
     }
     pcie_cap_update_power(dev);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 31/53] pcie: set power indicator to off on reset by default
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (29 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 30/53] pcie: introduce pcie_sltctl_powered_off() helper Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02 11:34   ` Vladimir Sementsov-Ogievskiy
  2023-03-02  8:26 ` [PULL 32/53] vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll() Michael S. Tsirkin
                   ` (23 subsequent siblings)
  54 siblings, 1 reply; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Vladimir Sementsov-Ogievskiy, Anton Kuchin,
	Marcel Apfelbaum

From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

It should be zero, the only valid values are ON, OFF and BLINK.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
Message-Id: <20230216180356.156832-13-vsementsov@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pcie.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 90faf0710a..b8c24cf45f 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -684,6 +684,7 @@ void pcie_cap_slot_reset(PCIDevice *dev)
                                  PCI_EXP_SLTCTL_PDCE |
                                  PCI_EXP_SLTCTL_ABPE);
     pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
+                               PCI_EXP_SLTCTL_PWR_IND_OFF |
                                PCI_EXP_SLTCTL_ATTN_IND_OFF);
 
     if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 32/53] vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (30 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 31/53] pcie: set power indicator to off on reset by default Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 33/53] libvhost-user: check for NULL when allocating a virtqueue element Michael S. Tsirkin
                   ` (22 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Carlos López

From: Carlos López <clopez@suse.de>

In vhost_svq_poll(), if vhost_svq_get_buf() fails due to a device
providing invalid descriptors, len is left uninitialized and returned
to the caller, potentally leaking stack data or causing undefined
behavior.

Fix this by initializing len to 0.

Found with GCC 13 and -fanalyzer (abridged):

../hw/virtio/vhost-shadow-virtqueue.c: In function ‘vhost_svq_poll’:
../hw/virtio/vhost-shadow-virtqueue.c:538:12: warning: use of uninitialized value ‘len’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
  538 |     return len;
      |            ^~~
  ‘vhost_svq_poll’: events 1-4
    |
    |  522 | size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
    |      |        ^~~~~~~~~~~~~~
    |      |        |
    |      |        (1) entry to ‘vhost_svq_poll’
    |......
    |  525 |     uint32_t len;
    |      |              ~~~
    |      |              |
    |      |              (2) region created on stack here
    |      |              (3) capacity: 4 bytes
    |......
    |  528 |         if (vhost_svq_more_used(svq)) {
    |      |             ~
    |      |             |
    |      |             (4) inlined call to ‘vhost_svq_more_used’ from ‘vhost_svq_poll’

    (...)

    |  528 |         if (vhost_svq_more_used(svq)) {
    |      |            ^~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            ||
    |      |            |(8) ...to here
    |      |            (7) following ‘true’ branch...
    |......
    |  537 |     vhost_svq_get_buf(svq, &len);
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (9) calling ‘vhost_svq_get_buf’ from ‘vhost_svq_poll’
    |
    +--> ‘vhost_svq_get_buf’: events 10-11
           |
           |  416 | static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
           |      |                          ^~~~~~~~~~~~~~~~~
           |      |                          |
           |      |                          (10) entry to ‘vhost_svq_get_buf’
           |......
           |  423 |     if (!vhost_svq_more_used(svq)) {
           |      |          ~
           |      |          |
           |      |          (11) inlined call to ‘vhost_svq_more_used’ from ‘vhost_svq_get_buf’
           |

           (...)

           |
         ‘vhost_svq_get_buf’: event 14
           |
           |  423 |     if (!vhost_svq_more_used(svq)) {
           |      |        ^
           |      |        |
           |      |        (14) following ‘false’ branch...
           |
         ‘vhost_svq_get_buf’: event 15
           |
           |cc1:
           | (15): ...to here
           |
    <------+
    |
  ‘vhost_svq_poll’: events 16-17
    |
    |  537 |     vhost_svq_get_buf(svq, &len);
    |      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (16) returning to ‘vhost_svq_poll’ from ‘vhost_svq_get_buf’
    |  538 |     return len;
    |      |            ~~~
    |      |            |
    |      |            (17) use of uninitialized value ‘len’ here

Note by  Laurent Vivier <lvivier@redhat.com>:

    The return value is only used to detect an error:

    vhost_svq_poll
        vhost_vdpa_net_cvq_add
            vhost_vdpa_net_load_cmd
                vhost_vdpa_net_load_mac
                  -> a negative return is only used to detect error
                vhost_vdpa_net_load_mq
                  -> a negative return is only used to detect error
            vhost_vdpa_net_handle_ctrl_avail
              -> a negative return is only used to detect error

Fixes: d368c0b052ad ("vhost: Do not depend on !NULL VirtQueueElement on vhost_svq_flush")
Signed-off-by: Carlos López <clopez@suse.de>
Message-Id: <20230213085747.19956-1-clopez@suse.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 4307296358..515ccf870d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -522,7 +522,7 @@ static void vhost_svq_flush(VhostShadowVirtqueue *svq,
 size_t vhost_svq_poll(VhostShadowVirtqueue *svq)
 {
     int64_t start_us = g_get_monotonic_time();
-    uint32_t len;
+    uint32_t len = 0;
 
     do {
         if (vhost_svq_more_used(svq)) {
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 33/53] libvhost-user: check for NULL when allocating a virtqueue element
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (31 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 32/53] vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll() Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 34/53] hw/pci: Trace IRQ routing on PCI topology Michael S. Tsirkin
                   ` (21 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Carlos López

From: Carlos López <clopez@suse.de>

Check the return value for malloc(), avoiding a NULL pointer
dereference, and propagate error in function callers.

Found with GCC 13 and -fanalyzer:

../subprojects/libvhost-user/libvhost-user.c: In function ‘virtqueue_alloc_element’:
../subprojects/libvhost-user/libvhost-user.c:2556:19: error: dereference of possibly-NULL ‘elem’ [CWE-690] [-Werror=analyzer-possible-null-dereference]
 2556 |     elem->out_num = out_num;
      |     ~~~~~~~~~~~~~~^~~~~~~~~
  ‘virtqueue_alloc_element’: event 1
    |
    | 2554 |     assert(sz >= sizeof(VuVirtqElement));
    |      |     ^~~~~~
    |      |     |
    |      |     (1) following ‘true’ branch (when ‘sz > 31’)...
    |
  ‘virtqueue_alloc_element’: events 2-4
    |
    | 2555 |     elem = malloc(out_sg_end);
    |      |     ^~~~   ~~~~~~~~~~~~~~~~~~
    |      |     |      |
    |      |     |      (3) this call could return NULL
    |      |     (2) ...to here
    | 2556 |     elem->out_num = out_num;
    |      |     ~~~~~~~~~~~~~~~~~~~~~~~
    |      |                   |
    |      |                   (4) ‘elem’ could be NULL: unchecked value from (3)
    |

Signed-off-by: Carlos López <clopez@suse.de>
Message-Id: <20230210112514.16858-1-clopez@suse.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 subprojects/libvhost-user/libvhost-user.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c
index f661af7c85..0200b78e8e 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -2553,6 +2553,10 @@ virtqueue_alloc_element(size_t sz,
 
     assert(sz >= sizeof(VuVirtqElement));
     elem = malloc(out_sg_end);
+    if (!elem) {
+        DPRINT("%s: failed to malloc virtqueue element\n", __func__);
+        return NULL;
+    }
     elem->out_num = out_num;
     elem->in_num = in_num;
     elem->in_sg = (void *)elem + in_sg_ofs;
@@ -2639,6 +2643,9 @@ vu_queue_map_desc(VuDev *dev, VuVirtq *vq, unsigned int idx, size_t sz)
 
     /* Now copy what we have collected and mapped */
     elem = virtqueue_alloc_element(sz, out_num, in_num);
+    if (!elem) {
+        return NULL;
+    }
     elem->index = idx;
     for (i = 0; i < out_num; i++) {
         elem->out_sg[i] = iov[i];
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 34/53] hw/pci: Trace IRQ routing on PCI topology
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (32 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 33/53] libvhost-user: check for NULL when allocating a virtqueue element Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize Michael S. Tsirkin
                   ` (20 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Philippe Mathieu-Daudé, Marcel Apfelbaum

From: Philippe Mathieu-Daudé <philmd@linaro.org>

Trace how IRQ are rooted from EP to RC.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230211152239.88106-3-philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pci.c        | 8 ++++++++
 hw/pci/trace-events | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index bad8e63db3..08060b3e88 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -279,9 +279,13 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
 {
     PCIBus *bus;
     for (;;) {
+        int dev_irq = irq_num;
         bus = pci_get_bus(pci_dev);
         assert(bus->map_irq);
         irq_num = bus->map_irq(pci_dev, irq_num);
+        trace_pci_route_irq(dev_irq, DEVICE(pci_dev)->canonical_path, irq_num,
+                            pci_bus_is_root(bus) ? "root-complex"
+                                    : DEVICE(bus->parent_dev)->canonical_path);
         if (bus->set_irq)
             break;
         pci_dev = bus->parent_dev;
@@ -1600,8 +1604,12 @@ PCIINTxRoute pci_device_route_intx_to_irq(PCIDevice *dev, int pin)
     PCIBus *bus;
 
     do {
+        int dev_irq = pin;
         bus = pci_get_bus(dev);
         pin = bus->map_irq(dev, pin);
+        trace_pci_route_irq(dev_irq, DEVICE(dev)->canonical_path, pin,
+                            pci_bus_is_root(bus) ? "root-complex"
+                                    : DEVICE(bus->parent_dev)->canonical_path);
         dev = bus->parent_dev;
     } while (dev);
 
diff --git a/hw/pci/trace-events b/hw/pci/trace-events
index aaf46bc92d..42430869ce 100644
--- a/hw/pci/trace-events
+++ b/hw/pci/trace-events
@@ -3,6 +3,7 @@
 # pci.c
 pci_update_mappings_del(const char *dev, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size) "%s %02x:%02x.%x %d,0x%"PRIx64"+0x%"PRIx64
 pci_update_mappings_add(const char *dev, uint32_t bus, uint32_t slot, uint32_t func, int bar, uint64_t addr, uint64_t size) "%s %02x:%02x.%x %d,0x%"PRIx64"+0x%"PRIx64
+pci_route_irq(int dev_irq, const char *dev_path, int parent_irq, const char *parent_path) "IRQ %d @%s -> IRQ %d @%s"
 
 # pci_host.c
 pci_cfg_read(const char *dev, uint32_t bus, uint32_t slot, uint32_t func, unsigned offs, unsigned val) "%s %02x:%02x.%x @0x%x -> 0x%x"
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (33 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 34/53] hw/pci: Trace IRQ routing on PCI topology Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02 11:49   ` Michael Tokarev
  2023-03-02  8:26 ` [PULL 36/53] memory: Optimize replay of guest mapping Michael S. Tsirkin
                   ` (19 subsequent siblings)
  54 siblings, 1 reply; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Yajun Wu, Jiri Pirko, Marc-André Lureau,
	Yajun, Wu, &lt, Jiri, Pirko, Paolo Bonzini

From: Yajun Wu <yajunw@nvidia.com>

After live migration with virtio block device, qemu crash at:

	#0  0x000055914f46f795 in object_dynamic_cast_assert (obj=0x559151b7b090, typename=0x55914f80fbc4 "qio-channel", file=0x55914f80fb90 "/images/testvfe/sw/qemu.gerrit/include/io/channel.h", line=30, func=0x55914f80fcb8 <__func__.17257> "QIO_CHANNEL") at ../qom/object.c:872
	#1  0x000055914f480d68 in QIO_CHANNEL (obj=0x559151b7b090) at /images/testvfe/sw/qemu.gerrit/include/io/channel.h:29
	#2  0x000055914f4812f8 in qio_net_listener_set_client_func_full (listener=0x559151b7a720, func=0x55914f580b97 <tcp_chr_accept>, data=0x5591519f4ea0, notify=0x0, context=0x0) at ../io/net-listener.c:166
	#3  0x000055914f580059 in tcp_chr_update_read_handler (chr=0x5591519f4ea0) at ../chardev/char-socket.c:637
	#4  0x000055914f583dca in qemu_chr_be_update_read_handlers (s=0x5591519f4ea0, context=0x0) at ../chardev/char.c:226
	#5  0x000055914f57b7c9 in qemu_chr_fe_set_handlers_full (b=0x559152bf23a0, fd_can_read=0x0, fd_read=0x0, fd_event=0x0, be_change=0x0, opaque=0x0, context=0x0, set_open=false, sync_state=true) at ../chardev/char-fe.c:279
	#6  0x000055914f57b86d in qemu_chr_fe_set_handlers (b=0x559152bf23a0, fd_can_read=0x0, fd_read=0x0, fd_event=0x0, be_change=0x0, opaque=0x0, context=0x0, set_open=false) at ../chardev/char-fe.c:304
	#7  0x000055914f378caf in vhost_user_async_close (d=0x559152bf21a0, chardev=0x559152bf23a0, vhost=0x559152bf2420, cb=0x55914f2fb8c1 <vhost_user_blk_disconnect>) at ../hw/virtio/vhost-user.c:2725
	#8  0x000055914f2fba40 in vhost_user_blk_event (opaque=0x559152bf21a0, event=CHR_EVENT_CLOSED) at ../hw/block/vhost-user-blk.c:395
	#9  0x000055914f58388c in chr_be_event (s=0x5591519f4ea0, event=CHR_EVENT_CLOSED) at ../chardev/char.c:61
	#10 0x000055914f583905 in qemu_chr_be_event (s=0x5591519f4ea0, event=CHR_EVENT_CLOSED) at ../chardev/char.c:81
	#11 0x000055914f581275 in char_socket_finalize (obj=0x5591519f4ea0) at ../chardev/char-socket.c:1083
	#12 0x000055914f46f073 in object_deinit (obj=0x5591519f4ea0, type=0x5591519055c0) at ../qom/object.c:680
	#13 0x000055914f46f0e5 in object_finalize (data=0x5591519f4ea0) at ../qom/object.c:694
	#14 0x000055914f46ff06 in object_unref (objptr=0x5591519f4ea0) at ../qom/object.c:1202
	#15 0x000055914f4715a4 in object_finalize_child_property (obj=0x559151b76c50, name=0x559151b7b250 "char3", opaque=0x5591519f4ea0) at ../qom/object.c:1747
	#16 0x000055914f46ee86 in object_property_del_all (obj=0x559151b76c50) at ../qom/object.c:632
	#17 0x000055914f46f0d2 in object_finalize (data=0x559151b76c50) at ../qom/object.c:693
	#18 0x000055914f46ff06 in object_unref (objptr=0x559151b76c50) at ../qom/object.c:1202
	#19 0x000055914f4715a4 in object_finalize_child_property (obj=0x559151b6b560, name=0x559151b76630 "chardevs", opaque=0x559151b76c50) at ../qom/object.c:1747
	#20 0x000055914f46ef67 in object_property_del_child (obj=0x559151b6b560, child=0x559151b76c50) at ../qom/object.c:654
	#21 0x000055914f46f042 in object_unparent (obj=0x559151b76c50) at ../qom/object.c:673
	#22 0x000055914f58632a in qemu_chr_cleanup () at ../chardev/char.c:1189
	#23 0x000055914f16c66c in qemu_cleanup () at ../softmmu/runstate.c:830
	#24 0x000055914eee7b9e in qemu_default_main () at ../softmmu/main.c:38
	#25 0x000055914eee7bcc in main (argc=86, argv=0x7ffc97cb8d88) at ../softmmu/main.c:48

In char_socket_finalize after s->listener freed, event callback function
vhost_user_blk_event will be called to handle CHR_EVENT_CLOSED.
vhost_user_blk_event is calling qio_net_listener_set_client_func_full which
is still using s->listener.

Setting s->listener = NULL after object_unref(OBJECT(s->listener)) can
solve this issue.

Signed-off-by: Yajun Wu <yajunw@nvidia.com>
Acked-by: Jiri Pirko <jiri@nvidia.com>

Message-Id: <20230214021430.3638579-1-yajunw@nvidia.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Yajun Wu &lt;<a href="mailto:yajunw@nvidia.com" target="_blank">yajunw@nvidia.com</a>&gt;<br>
Acked-by: Jiri Pirko &lt;<a href="mailto:jiri@nvidia.com" target="_blank">jiri@nvidia.com</a>&gt;<br></blockquote><div><br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 chardev/char-socket.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index c2265436ac..8c58532171 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -1065,6 +1065,7 @@ static void char_socket_finalize(Object *obj)
         qio_net_listener_set_client_func_full(s->listener, NULL, NULL,
                                               NULL, chr->gcontext);
         object_unref(OBJECT(s->listener));
+        s->listener = NULL;
     }
     if (s->tls_creds) {
         object_unref(OBJECT(s->tls_creds));
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 36/53] memory: Optimize replay of guest mapping
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (34 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-04-04 18:00   ` Peter Maydell
  2023-03-02  8:26 ` [PULL 37/53] intel-iommu: fail MAP notifier without caching mode Michael S. Tsirkin
                   ` (18 subsequent siblings)
  54 siblings, 1 reply; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Zhenzhong Duan, Peter Xu, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

From: Zhenzhong Duan <zhenzhong.duan@intel.com>

On x86, there are two notifiers registered due to vtd-ir memory region
splitting the whole address space. During replay of the address space
for each notifier, the whole address space is scanned which is
unnecessory.

We only need to scan the space belong to notifier montiored space.

Assert when notifier is used to monitor beyond iommu memory region's
address space.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Message-Id: <20230215065238.713041-1-zhenzhong.duan@intel.com>
Acked-by: Peter Xu <peterx@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/intel_iommu.c | 2 +-
 softmmu/memory.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 98a5c304a7..6b1de80e85 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3831,7 +3831,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
                 .domain_id = vtd_get_domain_id(s, &ce, vtd_as->pasid),
             };
 
-            vtd_page_walk(s, &ce, 0, ~0ULL, &info, vtd_as->pasid);
+            vtd_page_walk(s, &ce, n->start, n->end, &info, vtd_as->pasid);
         }
     } else {
         trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn),
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 9d64efca26..da7d846619 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1900,6 +1900,7 @@ int memory_region_register_iommu_notifier(MemoryRegion *mr,
     iommu_mr = IOMMU_MEMORY_REGION(mr);
     assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
     assert(n->start <= n->end);
+    assert(n->end <= memory_region_size(mr));
     assert(n->iommu_idx >= 0 &&
            n->iommu_idx < memory_region_iommu_num_indexes(iommu_mr));
 
@@ -1923,7 +1924,6 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUMemoryRegion *iommu_mr)
 
 void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 {
-    MemoryRegion *mr = MEMORY_REGION(iommu_mr);
     IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr);
     hwaddr addr, granularity;
     IOMMUTLBEntry iotlb;
@@ -1936,7 +1936,7 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 
     granularity = memory_region_iommu_get_min_page_size(iommu_mr);
 
-    for (addr = 0; addr < memory_region_size(mr); addr += granularity) {
+    for (addr = n->start; addr < n->end; addr += granularity) {
         iotlb = imrc->translate(iommu_mr, addr, IOMMU_NONE, n->iommu_idx);
         if (iotlb.perm != IOMMU_NONE) {
             n->notify(n, &iotlb);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 37/53] intel-iommu: fail MAP notifier without caching mode
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (35 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 36/53] memory: Optimize replay of guest mapping Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 38/53] intel-iommu: fail DEVIOTLB_UNMAP without dt mode Michael S. Tsirkin
                   ` (17 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jason Wang, Eric Auger, Viktor Prutyanov,
	Peter Xu, Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost

From: Jason Wang <jasowang@redhat.com>

Without caching mode, MAP notifier won't work correctly since guest
won't send IOTLB update event when it establishes new mappings in the
I/O page tables. Let's fail the IOMMU notifiers early instead of
misbehaving silently.

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Viktor Prutyanov <viktor@daynix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230223065924.42503-2-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/intel_iommu.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 6b1de80e85..b520542c47 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3186,6 +3186,13 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
                          "Snoop Control with vhost or VFIO is not supported");
         return -ENOTSUP;
     }
+    if (!s->caching_mode && (new & IOMMU_NOTIFIER_MAP)) {
+        error_setg_errno(errp, ENOTSUP,
+                         "device %02x.%02x.%x requires caching mode",
+                         pci_bus_num(vtd_as->bus), PCI_SLOT(vtd_as->devfn),
+                         PCI_FUNC(vtd_as->devfn));
+        return -ENOTSUP;
+    }
 
     /* Update per-address-space notifier flags */
     vtd_as->notifier_flags = new;
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 38/53] intel-iommu: fail DEVIOTLB_UNMAP without dt mode
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (36 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 37/53] intel-iommu: fail MAP notifier without caching mode Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
                   ` (16 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jason Wang, Laurent Vivier, Viktor Prutyanov,
	Peter Xu, Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	Marcel Apfelbaum

From: Jason Wang <jasowang@redhat.com>

Without dt mode, device IOTLB notifier won't work since guest won't
send device IOTLB invalidation descriptor in this case. Let's fail
early instead of misbehaving silently.

Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Tested-by: Laurent Vivier <lvivier@redhat.com>
Tested-by: Viktor Prutyanov <viktor@daynix.com>
Buglink: https://bugzilla.redhat.com/2156876
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230223065924.42503-3-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/intel_iommu.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index b520542c47..a6b35b07d2 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3179,6 +3179,7 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
 {
     VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
     IntelIOMMUState *s = vtd_as->iommu_state;
+    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s);
 
     /* TODO: add support for VFIO and vhost users */
     if (s->snoop_control) {
@@ -3193,6 +3194,13 @@ static int vtd_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
                          PCI_FUNC(vtd_as->devfn));
         return -ENOTSUP;
     }
+    if (!x86_iommu->dt_supported && (new & IOMMU_NOTIFIER_DEVIOTLB_UNMAP)) {
+        error_setg_errno(errp, ENOTSUP,
+                         "device %02x.%02x.%x requires device IOTLB mode",
+                         pci_bus_num(vtd_as->bus), PCI_SLOT(vtd_as->devfn),
+                         PCI_FUNC(vtd_as->devfn));
+        return -ENOTSUP;
+    }
 
     /* Update per-address-space notifier flags */
     vtd_as->notifier_flags = new;
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (37 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 38/53] intel-iommu: fail DEVIOTLB_UNMAP without dt mode Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 40/53] smmu: switch to use memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
                   ` (15 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jason Wang, Peter Xu, Paolo Bonzini,
	David Hildenbrand, Philippe Mathieu-Daudé

From: Jason Wang <jasowang@redhat.com>

This patch introduces a new helper to unmap the range of a specific
IOMMU notifier.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230223065924.42503-4-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/exec/memory.h | 10 ++++++++++
 softmmu/memory.c      | 13 +++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2e602a2fad..6fa0b071f0 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1731,6 +1731,16 @@ void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr,
 void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
                                     IOMMUTLBEvent *event);
 
+/**
+ * memory_region_unmap_iommu_notifier_range: notify a unmap for an IOMMU
+ *                                           translation that covers the
+ *                                           range of a notifier
+ *
+ * @notifier: the notifier to be notified
+ */
+void memory_region_unmap_iommu_notifier_range(IOMMUNotifier *n);
+
+
 /**
  * memory_region_register_iommu_notifier: register a notifier for changes to
  * IOMMU translation entries.
diff --git a/softmmu/memory.c b/softmmu/memory.c
index da7d846619..4699ba55ec 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1996,6 +1996,19 @@ void memory_region_notify_iommu_one(IOMMUNotifier *notifier,
     }
 }
 
+void memory_region_unmap_iommu_notifier_range(IOMMUNotifier *n)
+{
+    IOMMUTLBEvent event;
+
+    event.type = IOMMU_NOTIFIER_UNMAP;
+    event.entry.target_as = &address_space_memory;
+    event.entry.iova = n->start;
+    event.entry.perm = IOMMU_NONE;
+    event.entry.addr_mask = n->end - n->start;
+
+    memory_region_notify_iommu_one(n, &event);
+}
+
 void memory_region_notify_iommu(IOMMUMemoryRegion *iommu_mr,
                                 int iommu_idx,
                                 IOMMUTLBEvent event)
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 40/53] smmu: switch to use memory_region_unmap_iommu_notifier_range()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (38 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 41/53] intel-iommu: send UNMAP notifications for domain or global inv desc Michael S. Tsirkin
                   ` (14 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Jason Wang, Peter Xu, Eric Auger, qemu-arm

From: Jason Wang <jasowang@redhat.com>

Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230223065924.42503-5-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/arm/smmu-common.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
index 0a5a60ca1e..e7f1c1f219 100644
--- a/hw/arm/smmu-common.c
+++ b/hw/arm/smmu-common.c
@@ -467,20 +467,6 @@ IOMMUMemoryRegion *smmu_iommu_mr(SMMUState *s, uint32_t sid)
     return NULL;
 }
 
-/* Unmap the whole notifier's range */
-static void smmu_unmap_notifier_range(IOMMUNotifier *n)
-{
-    IOMMUTLBEvent event;
-
-    event.type = IOMMU_NOTIFIER_UNMAP;
-    event.entry.target_as = &address_space_memory;
-    event.entry.iova = n->start;
-    event.entry.perm = IOMMU_NONE;
-    event.entry.addr_mask = n->end - n->start;
-
-    memory_region_notify_iommu_one(n, &event);
-}
-
 /* Unmap all notifiers attached to @mr */
 static void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr)
 {
@@ -488,7 +474,7 @@ static void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr)
 
     trace_smmu_inv_notifiers_mr(mr->parent_obj.name);
     IOMMU_NOTIFIER_FOREACH(n, mr) {
-        smmu_unmap_notifier_range(n);
+        memory_region_unmap_iommu_notifier_range(n);
     }
 }
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 41/53] intel-iommu: send UNMAP notifications for domain or global inv desc
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (39 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 40/53] smmu: switch to use memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 42/53] MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer Michael S. Tsirkin
                   ` (13 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Peter Xu, Jason Wang, Marcel Apfelbaum,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost

From: Peter Xu <peterx@redhat.com>

We don't send UNMAP notification upon domain or global invalidation
which will lead the notifier can't work correctly. One example is to
use vhost remote IOTLB without enabling device IOTLB.

Fixing this by sending UNMAP notification.

Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20230223065924.42503-6-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/intel_iommu.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index a6b35b07d2..faade7def8 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1530,13 +1530,17 @@ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as,
     return vtd_page_walk(s, ce, addr, addr + size, &info, vtd_as->pasid);
 }
 
-static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as)
+static int vtd_address_space_sync(VTDAddressSpace *vtd_as)
 {
     int ret;
     VTDContextEntry ce;
     IOMMUNotifier *n;
 
-    if (!(vtd_as->iommu.iommu_notify_flags & IOMMU_NOTIFIER_IOTLB_EVENTS)) {
+    /* If no MAP notifier registered, we simply invalidate all the cache */
+    if (!vtd_as_has_map_notifier(vtd_as)) {
+        IOMMU_NOTIFIER_FOREACH(n, &vtd_as->iommu) {
+            memory_region_unmap_iommu_notifier_range(n);
+        }
         return 0;
     }
 
@@ -2000,7 +2004,7 @@ static void vtd_iommu_replay_all(IntelIOMMUState *s)
     VTDAddressSpace *vtd_as;
 
     QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) {
-        vtd_sync_shadow_page_table(vtd_as);
+        vtd_address_space_sync(vtd_as);
     }
 }
 
@@ -2082,7 +2086,7 @@ static void vtd_context_device_invalidate(IntelIOMMUState *s,
              * framework will skip MAP notifications if that
              * happened.
              */
-            vtd_sync_shadow_page_table(vtd_as);
+            vtd_address_space_sync(vtd_as);
         }
     }
 }
@@ -2140,7 +2144,7 @@ static void vtd_iotlb_domain_invalidate(IntelIOMMUState *s, uint16_t domain_id)
         if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus),
                                       vtd_as->devfn, &ce) &&
             domain_id == vtd_get_domain_id(s, &ce, vtd_as->pasid)) {
-            vtd_sync_shadow_page_table(vtd_as);
+            vtd_address_space_sync(vtd_as);
         }
     }
 }
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 42/53] MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (40 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 41/53] intel-iommu: send UNMAP notifications for domain or global inv desc Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 43/53] hw/mem/cxl_type3: Improve error handling in realize() Michael S. Tsirkin
                   ` (12 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Philippe Mathieu-Daudé,
	Markus Armbruster, Fan Ni, Richard Henderson, Thomas Huth,
	Stefan Hajnoczi

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Fan Ni has offered to help out with QEMU CXL emulation reviewing.
Add him as a designated reviewer.

Thanks to Fan for stepping up after I requested help following Ben
stepping down as co-maintainer. Fan base been active in testing
and review recently so great to have Fan on board.

Based on patch [PATCH] MAINTAINERS: Remove CXL maintainer Ben Widawsky

Message-id: <20230220212437.1462314-1-armbru@redhat.com>
Message-Id: <20230228113926.11485-1-Jonathan.Cameron@huawei.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e96e9dbfe6..a4647dd1c4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2637,6 +2637,7 @@ T: git https://gitlab.com/vsementsov/qemu.git block
 Compute Express Link
 M: Ben Widawsky <ben.widawsky@intel.com>
 M: Jonathan Cameron <jonathan.cameron@huawei.com>
+R: Fan Ni <fan.ni@samsung.com>
 S: Supported
 F: hw/cxl/
 F: hw/mem/cxl_type3.c
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 43/53] hw/mem/cxl_type3: Improve error handling in realize()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (41 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 42/53] MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 44/53] hw/pci-bridge/cxl_downstream: Fix type naming mismatch Michael S. Tsirkin
                   ` (11 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Ira Weiny, Gregory Price,
	Fan Ni, Ben Widawsky

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

msix_init_exclusive_bar() can fail, so if it does cleanup the address space.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-2-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/mem/cxl_type3.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index dae4fd89ca..252822bd82 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -401,7 +401,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
     MemoryRegion *mr = &regs->component_registers;
     uint8_t *pci_conf = pci_dev->config;
     unsigned short msix_num = 1;
-    int i;
+    int i, rc;
 
     if (!cxl_setup_memory(ct3d, errp)) {
         return;
@@ -438,7 +438,10 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
                      &ct3d->cxl_dstate.device_registers);
 
     /* MSI(-X) Initailization */
-    msix_init_exclusive_bar(pci_dev, msix_num, 4, NULL);
+    rc = msix_init_exclusive_bar(pci_dev, msix_num, 4, NULL);
+    if (rc) {
+        goto err_address_space_free;
+    }
     for (i = 0; i < msix_num; i++) {
         msix_vector_use(pci_dev, i);
     }
@@ -450,6 +453,11 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
     cxl_cstate->cdat.free_cdat_table = ct3_free_cdat_table;
     cxl_cstate->cdat.private = ct3d;
     cxl_doe_cdat_init(cxl_cstate, errp);
+    return;
+
+err_address_space_free:
+    address_space_destroy(&ct3d->hostmem_as);
+    return;
 }
 
 static void ct3_exit(PCIDevice *pci_dev)
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 44/53] hw/pci-bridge/cxl_downstream: Fix type naming mismatch
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (42 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 43/53] hw/mem/cxl_type3: Improve error handling in realize() Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 45/53] hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL Michael S. Tsirkin
                   ` (10 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Philippe Mathieu-Daudé,
	Ira Weiny, Gregory Price, Fan Ni, Marcel Apfelbaum

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Fix capitalization difference between struct name and typedef.

Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-3-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci-bridge/cxl_downstream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci-bridge/cxl_downstream.c b/hw/pci-bridge/cxl_downstream.c
index 3d4e6b59cd..54f507318f 100644
--- a/hw/pci-bridge/cxl_downstream.c
+++ b/hw/pci-bridge/cxl_downstream.c
@@ -15,7 +15,7 @@
 #include "hw/pci/pcie_port.h"
 #include "qapi/error.h"
 
-typedef struct CXLDownStreamPort {
+typedef struct CXLDownstreamPort {
     /*< private >*/
     PCIESlot parent_obj;
 
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 45/53] hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (43 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 44/53] hw/pci-bridge/cxl_downstream: Fix type naming mismatch Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 46/53] hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition Michael S. Tsirkin
                   ` (9 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gregory Price, Davidlohr Bueso, Ira Weiny,
	Gregory Price, Jonathan Cameron, Fan Ni, Ben Widawsky

From: Gregory Price <gourry.memverge@gmail.com>

Current code sets to STORAGE_EXPRESS and then overrides it.

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-4-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/mem/cxl_type3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index 252822bd82..217a5e639b 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -408,7 +408,6 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
     }
 
     pci_config_set_prog_interface(pci_conf, 0x10);
-    pci_config_set_class(pci_conf, PCI_CLASS_MEMORY_CXL);
 
     pcie_endpoint_cap_init(pci_dev, 0x80);
     if (ct3d->sn != UI64_NULL) {
@@ -627,7 +626,7 @@ static void ct3_class_init(ObjectClass *oc, void *data)
 
     pc->realize = ct3_realize;
     pc->exit = ct3_exit;
-    pc->class_id = PCI_CLASS_STORAGE_EXPRESS;
+    pc->class_id = PCI_CLASS_MEMORY_CXL;
     pc->vendor_id = PCI_VENDOR_ID_INTEL;
     pc->device_id = 0xd93; /* LVF for now */
     pc->revision = 1;
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 46/53] hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (44 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 45/53] hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:26 ` [PULL 47/53] tests/acpi: Allow update of q35/DSDT.cxl Michael S. Tsirkin
                   ` (8 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Gregory Price, Gregory Price, Davidlohr Bueso,
	Jonathan Cameron, Fan Ni, Ben Widawsky

From: Gregory Price <gourry.memverge@gmail.com>

Remove usage of magic numbers when accessing capacity fields and replace
with CXL_CAPACITY_MULTIPLIER, matching the kernel definition.

Signed-off-by: Gregory Price <gregory.price@memverge.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Message-Id: <20230206172816.8201-5-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/cxl/cxl-mailbox-utils.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index bc1bb18844..3f67b665f5 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -12,8 +12,11 @@
 #include "hw/pci/pci.h"
 #include "qemu/cutils.h"
 #include "qemu/log.h"
+#include "qemu/units.h"
 #include "qemu/uuid.h"
 
+#define CXL_CAPACITY_MULTIPLIER   (256 * MiB)
+
 /*
  * How to add a new command, example. The command set FOO, with cmd BAR.
  *  1. Add the command set and cmd to the enum.
@@ -138,7 +141,7 @@ static ret_code cmd_firmware_update_get_info(struct cxl_cmd *cmd,
     } QEMU_PACKED *fw_info;
     QEMU_BUILD_BUG_ON(sizeof(*fw_info) != 0x50);
 
-    if (cxl_dstate->pmem_size < (256 << 20)) {
+    if (cxl_dstate->pmem_size < CXL_CAPACITY_MULTIPLIER) {
         return CXL_MBOX_INTERNAL_ERROR;
     }
 
@@ -283,7 +286,7 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd,
     CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
     uint64_t size = cxl_dstate->pmem_size;
 
-    if (!QEMU_IS_ALIGNED(size, 256 << 20)) {
+    if (!QEMU_IS_ALIGNED(size, CXL_CAPACITY_MULTIPLIER)) {
         return CXL_MBOX_INTERNAL_ERROR;
     }
 
@@ -293,8 +296,8 @@ static ret_code cmd_identify_memory_device(struct cxl_cmd *cmd,
     /* PMEM only */
     snprintf(id->fw_revision, 0x10, "BWFW VERSION %02d", 0);
 
-    id->total_capacity = size / (256 << 20);
-    id->persistent_capacity = size / (256 << 20);
+    id->total_capacity = size / CXL_CAPACITY_MULTIPLIER;
+    id->persistent_capacity = size / CXL_CAPACITY_MULTIPLIER;
     id->lsa_size = cvc->get_lsa_size(ct3d);
 
     *len = sizeof(*id);
@@ -314,14 +317,14 @@ static ret_code cmd_ccls_get_partition_info(struct cxl_cmd *cmd,
     QEMU_BUILD_BUG_ON(sizeof(*part_info) != 0x20);
     uint64_t size = cxl_dstate->pmem_size;
 
-    if (!QEMU_IS_ALIGNED(size, 256 << 20)) {
+    if (!QEMU_IS_ALIGNED(size, CXL_CAPACITY_MULTIPLIER)) {
         return CXL_MBOX_INTERNAL_ERROR;
     }
 
     /* PMEM only */
     part_info->active_vmem = 0;
     part_info->next_vmem = 0;
-    part_info->active_pmem = size / (256 << 20);
+    part_info->active_pmem = size / CXL_CAPACITY_MULTIPLIER;
     part_info->next_pmem = 0;
 
     *len = sizeof(*part_info);
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 47/53] tests/acpi: Allow update of q35/DSDT.cxl
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (45 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 46/53] hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition Michael S. Tsirkin
@ 2023-03-02  8:26 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 48/53] hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge Michael S. Tsirkin
                   ` (7 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:26 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Gregory Price, Fan Ni,
	Igor Mammedov, Ani Sinha

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Next patch will drop duplicate _UID entry so allow update.

Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-6-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/qtest/bios-tables-test-allowed-diff.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h
index dfb8523c8b..9ce0f596cc 100644
--- a/tests/qtest/bios-tables-test-allowed-diff.h
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
@@ -1 +1,2 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/q35/DSDT.cxl",
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 48/53] hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (46 preceding siblings ...)
  2023-03-02  8:26 ` [PULL 47/53] tests/acpi: Allow update of q35/DSDT.cxl Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 49/53] tests: acpi: Update q35/DSDT.cxl for removed duplicate UID Michael S. Tsirkin
                   ` (6 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Ira Weiny, Gregory Price,
	Fan Ni, Igor Mammedov, Ani Sinha, Marcel Apfelbaum,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Noticed as this prevents iASL disasembling the DSDT table.

Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-7-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/i386/acpi-build.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index d27921fd8f..b19fb4259e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1514,7 +1514,6 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
                 aml_append(pkg, aml_eisaid("PNP0A03"));
                 aml_append(dev, aml_name_decl("_CID", pkg));
                 aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
-                aml_append(dev, aml_name_decl("_UID", aml_int(bus_num)));
                 build_cxl_osc_method(dev);
             } else if (pci_bus_is_express(bus)) {
                 aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A08")));
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 49/53] tests: acpi: Update q35/DSDT.cxl for removed duplicate UID
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (47 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 48/53] hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 50/53] qemu/bswap: Add const_le64() Michael S. Tsirkin
                   ` (5 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Jonathan Cameron, Gregory Price, Fan Ni,
	Igor Mammedov, Ani Sinha

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Dropping the ID effects this table in trivial fashion.

Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-8-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/qtest/bios-tables-test-allowed-diff.h |   1 -
 tests/data/acpi/q35/DSDT.cxl                | Bin 9578 -> 9564 bytes
 2 files changed, 1 deletion(-)

diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h
index 9ce0f596cc..dfb8523c8b 100644
--- a/tests/qtest/bios-tables-test-allowed-diff.h
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
@@ -1,2 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/q35/DSDT.cxl",
diff --git a/tests/data/acpi/q35/DSDT.cxl b/tests/data/acpi/q35/DSDT.cxl
index 3d18b9672d124a0cf11a79e92c396a1b883d0589..4586b9a18b24acd946cd32c7e3e3a70891a246d2 100644
GIT binary patch
delta 65
zcmaFmb;pa#CD<h-MwNkqQEMaDUKwr|m6-Tor}*e5Z{^9CWUMyF%dcjfyiYC^MM6#<
IB*D!F0I~xVRsaA1

delta 79
zcmccP^~#IOCD<h-OO=6vv2P>SUKwt0m6-Tor}*e5CzZ*UWUScYLp@!%?rjc`U&A<g
SyId%Wytq76o(Cw;!v+8Y7Z@l2

-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 50/53] qemu/bswap: Add const_le64()
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (48 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 49/53] tests: acpi: Update q35/DSDT.cxl for removed duplicate UID Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 51/53] qemu/uuid: Add UUID static initializer Michael S. Tsirkin
                   ` (4 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Ira Weiny, Philippe Mathieu-Daudé,
	Gregory Price, Jonathan Cameron, Fan Ni, Richard Henderson,
	Thomas Huth, Paolo Bonzini

From: Ira Weiny <ira.weiny@intel.com>

Gcc requires constant versions of cpu_to_le* calls.

Add a 64 bit version.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Message-Id: <20230206172816.8201-9-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/qemu/bswap.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index b1650daedf..15a78c0db5 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -125,11 +125,20 @@ CPU_CONVERT(le, 32, uint32_t)
 CPU_CONVERT(le, 64, uint64_t)
 
 /*
- * Same as cpu_to_le{16,32}, except that gcc will figure the result is
+ * Same as cpu_to_le{16,32,64}, except that gcc will figure the result is
  * a compile-time constant if you pass in a constant.  So this can be
  * used to initialize static variables.
  */
 #if HOST_BIG_ENDIAN
+# define const_le64(_x)                          \
+    ((((_x) & 0x00000000000000ffU) << 56) |      \
+     (((_x) & 0x000000000000ff00U) << 40) |      \
+     (((_x) & 0x0000000000ff0000U) << 24) |      \
+     (((_x) & 0x00000000ff000000U) <<  8) |      \
+     (((_x) & 0x000000ff00000000U) >>  8) |      \
+     (((_x) & 0x0000ff0000000000U) >> 24) |      \
+     (((_x) & 0x00ff000000000000U) >> 40) |      \
+     (((_x) & 0xff00000000000000U) >> 56))
 # define const_le32(_x)                          \
     ((((_x) & 0x000000ffU) << 24) |              \
      (((_x) & 0x0000ff00U) <<  8) |              \
@@ -139,6 +148,7 @@ CPU_CONVERT(le, 64, uint64_t)
     ((((_x) & 0x00ff) << 8) |                    \
      (((_x) & 0xff00) >> 8))
 #else
+# define const_le64(_x) (_x)
 # define const_le32(_x) (_x)
 # define const_le16(_x) (_x)
 #endif
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 51/53] qemu/uuid: Add UUID static initializer
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (49 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 50/53] qemu/bswap: Add const_le64() Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 52/53] hw/cxl/mailbox: Use new UUID network order define for cel_uuid Michael S. Tsirkin
                   ` (3 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Ira Weiny, Gregory Price, Jonathan Cameron,
	Fan Ni, Fam Zheng

From: Ira Weiny <ira.weiny@intel.com>

UUID's are defined as network byte order fields.  No static initializer
was available for UUID's in their standard big endian format.

Define a big endian initializer for UUIDs.

Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230206172816.8201-10-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/qemu/uuid.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
index 9925febfa5..dc40ee1fc9 100644
--- a/include/qemu/uuid.h
+++ b/include/qemu/uuid.h
@@ -61,6 +61,18 @@ typedef struct {
     (clock_seq_hi_and_reserved), (clock_seq_low), (node0), (node1), (node2),\
     (node3), (node4), (node5) }
 
+/* Normal (network byte order) UUID */
+#define UUID(time_low, time_mid, time_hi_and_version,                    \
+  clock_seq_hi_and_reserved, clock_seq_low, node0, node1, node2,         \
+  node3, node4, node5)                                                   \
+  { ((time_low) >> 24) & 0xff, ((time_low) >> 16) & 0xff,                \
+    ((time_low) >> 8) & 0xff, (time_low) & 0xff,                         \
+    ((time_mid) >> 8) & 0xff, (time_mid) & 0xff,                         \
+    ((time_hi_and_version) >> 8) & 0xff, (time_hi_and_version) & 0xff,   \
+    (clock_seq_hi_and_reserved), (clock_seq_low),                        \
+    (node0), (node1), (node2), (node3), (node4), (node5)                 \
+  }
+
 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-" \
                  "%02hhx%02hhx-%02hhx%02hhx-" \
                  "%02hhx%02hhx-" \
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 52/53] hw/cxl/mailbox: Use new UUID network order define for cel_uuid
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (50 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 51/53] qemu/uuid: Add UUID static initializer Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02  8:27 ` [PULL 53/53] tests/data/acpi/virt: drop (most) duplicate files Michael S. Tsirkin
                   ` (2 subsequent siblings)
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Ira Weiny, Philippe Mathieu-Daudé,
	Gregory Price, Jonathan Cameron, Fan Ni, Ben Widawsky

From: Ira Weiny <ira.weiny@intel.com>

The cel_uuid was programatically generated previously because there was
no static initializer for network order UUIDs.

Use the new network order initializer for cel_uuid.  Adjust
cxl_initialize_mailbox() because it can't fail now.

Update specification reference.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Gregory Price <gregory.price@memverge.com>
Tested-by: Gregory Price <gregory.price@memverge.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Message-Id: <20230206172816.8201-11-Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 include/hw/cxl/cxl_device.h |  2 +-
 hw/cxl/cxl-device-utils.c   |  2 +-
 hw/cxl/cxl-mailbox-utils.c  | 13 ++++++-------
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h
index 250adf18b2..7e5ad65c1d 100644
--- a/include/hw/cxl/cxl_device.h
+++ b/include/hw/cxl/cxl_device.h
@@ -170,7 +170,7 @@ CXL_DEVICE_CAPABILITY_HEADER_REGISTER(MEMORY_DEVICE,
                                       CXL_DEVICE_CAP_HDR1_OFFSET +
                                           CXL_DEVICE_CAP_REG_SIZE * 2)
 
-int cxl_initialize_mailbox(CXLDeviceState *cxl_dstate);
+void cxl_initialize_mailbox(CXLDeviceState *cxl_dstate);
 void cxl_process_mailbox(CXLDeviceState *cxl_dstate);
 
 #define cxl_device_cap_init(dstate, reg, cap_id)                           \
diff --git a/hw/cxl/cxl-device-utils.c b/hw/cxl/cxl-device-utils.c
index 83ce7a8270..4c5e88aaf5 100644
--- a/hw/cxl/cxl-device-utils.c
+++ b/hw/cxl/cxl-device-utils.c
@@ -267,5 +267,5 @@ void cxl_device_register_init_common(CXLDeviceState *cxl_dstate)
     cxl_device_cap_init(cxl_dstate, MEMORY_DEVICE, 0x4000);
     memdev_reg_init_common(cxl_dstate);
 
-    assert(cxl_initialize_mailbox(cxl_dstate) == 0);
+    cxl_initialize_mailbox(cxl_dstate);
 }
diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
index 3f67b665f5..206e04a4b8 100644
--- a/hw/cxl/cxl-mailbox-utils.c
+++ b/hw/cxl/cxl-mailbox-utils.c
@@ -193,7 +193,11 @@ static ret_code cmd_timestamp_set(struct cxl_cmd *cmd,
     return CXL_MBOX_SUCCESS;
 }
 
-static QemuUUID cel_uuid;
+/* CXL 3.0 8.2.9.5.2.1 Command Effects Log (CEL) */
+static const QemuUUID cel_uuid = {
+    .data = UUID(0x0da9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79,
+                 0x96, 0xb1, 0x62, 0x3b, 0x3f, 0x17)
+};
 
 /* 8.2.9.4.1 */
 static ret_code cmd_logs_get_supported(struct cxl_cmd *cmd,
@@ -458,11 +462,8 @@ void cxl_process_mailbox(CXLDeviceState *cxl_dstate)
                      DOORBELL, 0);
 }
 
-int cxl_initialize_mailbox(CXLDeviceState *cxl_dstate)
+void cxl_initialize_mailbox(CXLDeviceState *cxl_dstate)
 {
-    /* CXL 2.0: Table 169 Get Supported Logs Log Entry */
-    const char *cel_uuidstr = "0da9c0b5-bf41-4b78-8f79-96b1623b3f17";
-
     for (int set = 0; set < 256; set++) {
         for (int cmd = 0; cmd < 256; cmd++) {
             if (cxl_cmd_set[set][cmd].handler) {
@@ -476,6 +477,4 @@ int cxl_initialize_mailbox(CXLDeviceState *cxl_dstate)
             }
         }
     }
-
-    return qemu_uuid_parse(cel_uuidstr, &cel_uuid);
 }
-- 
MST



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PULL 53/53] tests/data/acpi/virt: drop (most) duplicate files.
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (51 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 52/53] hw/cxl/mailbox: Use new UUID network order define for cel_uuid Michael S. Tsirkin
@ 2023-03-02  8:27 ` Michael S. Tsirkin
  2023-03-02 12:16 ` [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael Tokarev
  2023-03-03  0:15 ` Michael S. Tsirkin
  54 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02  8:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

When virt ACPI files were added, lots of duplicates were created because
we forgot that there's a no-prefix fallback: e.g. if
tests/data/acpi/virt/APIC.memhp is not there then test will use
tests/data/acpi/virt/APIC.

Drop these.

These were found with
$find tests/data/acpi/ -type f -exec sha256sum '{}' ';'|sort -d|uniq -w 64 --all-repeated=separate
(trick: -d does a dictionary sort so a no-suffix file ends up first).

Note: there are still a bunch of issues with duplicates left even after this.

First pc and q35 are often identical.
Second, sometimes files are identical but not identical to the default
fallback, e.g.
tests/data/acpi/pc/SLIT.cphp and tests/data/acpi/pc/SLIT.memhp
or
tests/data/acpi/q35/HMAT.acpihmat-noinitiator and tests/data/acpi/virt/HMAT.acpihmatvirt

Finding a way to deduplicate these is still a TODO item - softlinks
maybe?

We also need to make rebuild-expected-aml.sh smarter about not creating
these duplicates in the 1st place.

And maybe we should use softlinks instead of relying on a fallback
to make it explicit what version does each test expect?

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/data/acpi/virt/APIC.memhp   | Bin 172 -> 0 bytes
 tests/data/acpi/virt/APIC.numamem | Bin 172 -> 0 bytes
 tests/data/acpi/virt/DSDT.numamem | Bin 5196 -> 0 bytes
 tests/data/acpi/virt/FACP.memhp   | Bin 276 -> 0 bytes
 tests/data/acpi/virt/FACP.numamem | Bin 276 -> 0 bytes
 tests/data/acpi/virt/GTDT.memhp   | Bin 96 -> 0 bytes
 tests/data/acpi/virt/GTDT.numamem | Bin 96 -> 0 bytes
 tests/data/acpi/virt/IORT.memhp   | Bin 128 -> 0 bytes
 tests/data/acpi/virt/IORT.numamem | Bin 128 -> 0 bytes
 tests/data/acpi/virt/IORT.pxb     | Bin 128 -> 0 bytes
 tests/data/acpi/virt/MCFG.memhp   | Bin 60 -> 0 bytes
 tests/data/acpi/virt/MCFG.numamem | Bin 60 -> 0 bytes
 tests/data/acpi/virt/SPCR.memhp   | Bin 80 -> 0 bytes
 tests/data/acpi/virt/SPCR.numamem | Bin 80 -> 0 bytes
 14 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 tests/data/acpi/virt/APIC.memhp
 delete mode 100644 tests/data/acpi/virt/APIC.numamem
 delete mode 100644 tests/data/acpi/virt/DSDT.numamem
 delete mode 100644 tests/data/acpi/virt/FACP.memhp
 delete mode 100644 tests/data/acpi/virt/FACP.numamem
 delete mode 100644 tests/data/acpi/virt/GTDT.memhp
 delete mode 100644 tests/data/acpi/virt/GTDT.numamem
 delete mode 100644 tests/data/acpi/virt/IORT.memhp
 delete mode 100644 tests/data/acpi/virt/IORT.numamem
 delete mode 100644 tests/data/acpi/virt/IORT.pxb
 delete mode 100644 tests/data/acpi/virt/MCFG.memhp
 delete mode 100644 tests/data/acpi/virt/MCFG.numamem
 delete mode 100644 tests/data/acpi/virt/SPCR.memhp
 delete mode 100644 tests/data/acpi/virt/SPCR.numamem

diff --git a/tests/data/acpi/virt/APIC.memhp b/tests/data/acpi/virt/APIC.memhp
deleted file mode 100644
index 179d274770a23209b949c90a929525e22368568b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 172
zcmZ<^@N{0oz`(%b?&R<65v<@85#X!<1dKp25F13p0FMNW#lQh$F##Fe0Wcl|15CX*
gLI}uWgsNwO(#&xED9WH5UbsC>V09of9T)-_08#k}0RR91

diff --git a/tests/data/acpi/virt/APIC.numamem b/tests/data/acpi/virt/APIC.numamem
deleted file mode 100644
index 179d274770a23209b949c90a929525e22368568b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 172
zcmZ<^@N{0oz`(%b?&R<65v<@85#X!<1dKp25F13p0FMNW#lQh$F##Fe0Wcl|15CX*
gLI}uWgsNwO(#&xED9WH5UbsC>V09of9T)-_08#k}0RR91

diff --git a/tests/data/acpi/virt/DSDT.numamem b/tests/data/acpi/virt/DSDT.numamem
deleted file mode 100644
index c47503990715d389914fdf9c8bccb510761741ac..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 5196
zcmZvg%WoT16o>EFlh__VVmr>uc{qhq@vO#n^Jr;H?6H%$#EJ2w4N@w(5&}`OsYHcT
zDx{D_3)#^~Yza~%{tYBn?AWnj&4zz~9p>D*Gs*8LXQYhh%-r+M{l>@f@oo97-K~;R
zv7eed-lo6U{J7^W(q<{8^s#=;zie6$2Yz#~e^mBd*G&#KJFRTP>vbqtQOUvmPD||{
z-ST$2(Y1be({-!W@LF=<_5DKGnR<~@8kkafrM@3kmUV@qXOz3TzUQqQ?nmwJed5+A
z*WYb8X-f7QmO&JpoI%7=(_v=Ae$bDmw6)#eq12^|+n#4$+}u&I@a8Tes^;z-p>KN$
z5mOh4YKUm+S=1zi6O$M=FlxxCi;TF$7zIWh88<|REisb7xPgo%kuf4M9AGRVV_9U3
zN{kFJmXWa{G7=Ia2aFYDtcr}J#K;3<6&W{0MoMB7fpHTU)$qf?OU!X3MhO_VkRg^S
z|BytbJ_(HXks;S<Mw-VoFm5A5uG6f<C<EgTGUPhVNsKvQ+(m|5r(+Uh0T>@3L$1@j
z#8?Ez8ZzWMEl7;lfYCsPT&G2eaTOR%WXN?oE-|hF!vjW5uG5mlcoP^cWXN?oAu-+t
zMjIJ&olZ)OcY(2v47pCHB*t}MY#>9f(`kv}0%H>ya-Ggdj2bXH$dK!_EHQ2X;~p~P
zI-Qjm%fR>$8FHP@NsLusY#~Fg(|L(;3m9Es)a5!|kQldtv5gG5PAd}QE--dN#`Z5g
zuM^Irx7~9a?kY7O9<@g%s_QPMy+QkCbNjq4@pt=$iZj<!p6aMi)uM9guSG{+smJOQ
zdQ}<{G#<VF?)cW1&S5car-wte;dfkRjx9Q_s$xc;cVZOOq99H|T@|x-W;nEz&Y^K(
zq_b#X&Rh%fXlNAbOyUP)sY^0r!$@aFL#YMQcch^~CWSgPx=TFBjAjs5Ix`v?H<>gv
z$fQtb(u{(;*g<AA13So!hEmHES_YXEqUQ+n90@Wb&k>UuO`byZ9A%!=l+t{nq10lb
zCxz&lV4ex)nc$ujqGytMCYdL-WavpDdZw5swbSP51&<`fJt;&_hj}{8lUg|Rq!2yR
z%rnhA)7+Cn^vp2N4D+Ox4?QVF&n)xIGS4jcq!2xG%rnP4sYOIj3ej_nd5$s9G44qr
zdeYAsQ{zDu=b0z9l;}wzdKQ>xfq53VCxz%)WS&LlNi8UPQiz`8%yXQ1j&n~6(UX2C
zf@g_&Qp<{-6r$$@^PFIw6Wo(R^qgd#lgyJ^T=b+6J*SxG6!V<oo)n@d{kR0rY34~S
zF?v#no-@pIhI!6#PYThq%sk7?lUiu>q!2x4nddC?oaLSrqURj*oMWEUa-%1O=sC|k
z=b7g`_oNU#7ntV)^Q0CXJt;)b3iGTm&kFaX(0J}2b!`1snxAj_OWAYR&%cO!v@DTx
z(!o;1>%mt#eeYg6R~jAoecuXEVaLEwv`&Dis{+cLJ4fBqvkDtrhSKW=$a+IynRA>K
zHoBZe>jucWCa}!8kX6bLyk<k4(f?4DU!$FQ9GeN}>33NbqkreL4fW1?NuRC^br->w
z9}fT1Kg(zvUZ*QohI#<AQPV=(kgi(l_#MazE+6V^dJCe9oj(6eCH?!oo=SSV{Vi2m
zPYrf_&ptj-UTd#<x|ulnyfE(M_q%`9|E<ie{kZqE@#~#GKRZ5fY#LCb*Cf5xpXfky
z^g&&tp6i`c(fiZ<tCPppH*}>MjIN$ezB-A<nbUcF@rfR+&z~LqoHOV3O{!-HrS}Fc
zziXdfF|+w&<@dk+rLVg`O#RcH`OWK|rcS<4XN9<B=^ZU}b?tuJXVs_|x^&Ie9rx1n
z3El&GI+eAHN28DE`^K!BH4_i7>y^2Uc57ft+$_sgb>m6Pa#^|%@=cw`t+!0-VY^R#
zDZQh~lw<FIo7SP%_S;*FrTIbo!EWk_4j!H6Po6(=bienax7Tkvhx<n}`T##qp1GI$
EABWcyJpcdz

diff --git a/tests/data/acpi/virt/FACP.memhp b/tests/data/acpi/virt/FACP.memhp
deleted file mode 100644
index ac05c35a69451519bd1152c54d1e741af36390f5..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 276
zcmZ>BbPf<<WME(ub@F%i2v%^42yj*a0-z8Bhz+8t3j|P&V@Bl;Brnj_Hxy()0OQ~X
A0RR91

diff --git a/tests/data/acpi/virt/FACP.numamem b/tests/data/acpi/virt/FACP.numamem
deleted file mode 100644
index ac05c35a69451519bd1152c54d1e741af36390f5..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 276
zcmZ>BbPf<<WME(ub@F%i2v%^42yj*a0-z8Bhz+8t3j|P&V@Bl;Brnj_Hxy()0OQ~X
A0RR91

diff --git a/tests/data/acpi/virt/GTDT.memhp b/tests/data/acpi/virt/GTDT.memhp
deleted file mode 100644
index 6f8cb9b8f30b55f4c93fe515982621e3db50feb2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 96
zcmZ<{aS2IaU|?XH<K*w`5v<@85#X!<1dKp25F14QhXNpzK^8;+fgBLC0I@WP0|ZhK
J3PmkQ2mn(n7XbhO

diff --git a/tests/data/acpi/virt/GTDT.numamem b/tests/data/acpi/virt/GTDT.numamem
deleted file mode 100644
index 6f8cb9b8f30b55f4c93fe515982621e3db50feb2..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 96
zcmZ<{aS2IaU|?XH<K*w`5v<@85#X!<1dKp25F14QhXNpzK^8;+fgBLC0I@WP0|ZhK
J3PmkQ2mn(n7XbhO

diff --git a/tests/data/acpi/virt/IORT.memhp b/tests/data/acpi/virt/IORT.memhp
deleted file mode 100644
index 7efd0ce8a6b3928efa7e1373f688ab4c5f50543b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 128
zcmebD4+?2uU|?Y0?Bwt45v<@85#X!<1dKp25F11@0kHuPgMkDCNC*yK93~3}W)K^M
VRiHGGVg_O`aDdYP|3ers^8jQz3IPBB

diff --git a/tests/data/acpi/virt/IORT.numamem b/tests/data/acpi/virt/IORT.numamem
deleted file mode 100644
index 7efd0ce8a6b3928efa7e1373f688ab4c5f50543b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 128
zcmebD4+?2uU|?Y0?Bwt45v<@85#X!<1dKp25F11@0kHuPgMkDCNC*yK93~3}W)K^M
VRiHGGVg_O`aDdYP|3ers^8jQz3IPBB

diff --git a/tests/data/acpi/virt/IORT.pxb b/tests/data/acpi/virt/IORT.pxb
deleted file mode 100644
index 7efd0ce8a6b3928efa7e1373f688ab4c5f50543b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 128
zcmebD4+?2uU|?Y0?Bwt45v<@85#X!<1dKp25F11@0kHuPgMkDCNC*yK93~3}W)K^M
VRiHGGVg_O`aDdYP|3ers^8jQz3IPBB

diff --git a/tests/data/acpi/virt/MCFG.memhp b/tests/data/acpi/virt/MCFG.memhp
deleted file mode 100644
index f4ae3203a4e9258a397c9912332178640209637b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 60
scmeZuc5}C3U|?W;<K*w`5v<@85#X!<1dKp25F11z0RaaH=Rb%706Iko0RR91

diff --git a/tests/data/acpi/virt/MCFG.numamem b/tests/data/acpi/virt/MCFG.numamem
deleted file mode 100644
index f4ae3203a4e9258a397c9912332178640209637b..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 60
scmeZuc5}C3U|?W;<K*w`5v<@85#X!<1dKp25F11z0RaaH=Rb%706Iko0RR91

diff --git a/tests/data/acpi/virt/SPCR.memhp b/tests/data/acpi/virt/SPCR.memhp
deleted file mode 100644
index 24e0a579e7d73f432a614380e29aa95113344186..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 80
zcmWFza1IJ!U|?W6?d0$55v<@85#X!<1dKp25F11@12F>!1Bl59VJZSCW(Gzk28RDY
I01|@%0RBM>0RR91

diff --git a/tests/data/acpi/virt/SPCR.numamem b/tests/data/acpi/virt/SPCR.numamem
deleted file mode 100644
index 24e0a579e7d73f432a614380e29aa95113344186..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 80
zcmWFza1IJ!U|?W6?d0$55v<@85#X!<1dKp25F11@12F>!1Bl59VJZSCW(Gzk28RDY
I01|@%0RBM>0RR91

-- 
MST



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 31/53] pcie: set power indicator to off on reset by default
  2023-03-02  8:26 ` [PULL 31/53] pcie: set power indicator to off on reset by default Michael S. Tsirkin
@ 2023-03-02 11:34   ` Vladimir Sementsov-Ogievskiy
  2023-03-02 11:42     ` Michael S. Tsirkin
  2023-03-03  0:15     ` Michael S. Tsirkin
  0 siblings, 2 replies; 72+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2023-03-02 11:34 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Peter Maydell, Anton Kuchin, Marcel Apfelbaum

On 02.03.23 11:26, Michael S. Tsirkin wrote:
> From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> 
> It should be zero, the only valid values are ON, OFF and BLINK.

At any chance, fix s/should be/should not be/

> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
> Message-Id: <20230216180356.156832-13-vsementsov@yandex-team.ru>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   hw/pci/pcie.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 90faf0710a..b8c24cf45f 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -684,6 +684,7 @@ void pcie_cap_slot_reset(PCIDevice *dev)
>                                    PCI_EXP_SLTCTL_PDCE |
>                                    PCI_EXP_SLTCTL_ABPE);
>       pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
> +                               PCI_EXP_SLTCTL_PWR_IND_OFF |
>                                  PCI_EXP_SLTCTL_ATTN_IND_OFF);
>   
>       if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {

-- 
Best regards,
Vladimir



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 31/53] pcie: set power indicator to off on reset by default
  2023-03-02 11:34   ` Vladimir Sementsov-Ogievskiy
@ 2023-03-02 11:42     ` Michael S. Tsirkin
  2023-03-03  0:15     ` Michael S. Tsirkin
  1 sibling, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02 11:42 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: qemu-devel, Peter Maydell, Anton Kuchin, Marcel Apfelbaum

On Thu, Mar 02, 2023 at 02:34:02PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 02.03.23 11:26, Michael S. Tsirkin wrote:
> > From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > 
> > It should be zero, the only valid values are ON, OFF and BLINK.
> 
> At any chance, fix s/should be/should not be/


Unless there's a bigger issue I'm not redoing the pull just for this.

> > 
> > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
> > Message-Id: <20230216180356.156832-13-vsementsov@yandex-team.ru>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >   hw/pci/pcie.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> > index 90faf0710a..b8c24cf45f 100644
> > --- a/hw/pci/pcie.c
> > +++ b/hw/pci/pcie.c
> > @@ -684,6 +684,7 @@ void pcie_cap_slot_reset(PCIDevice *dev)
> >                                    PCI_EXP_SLTCTL_PDCE |
> >                                    PCI_EXP_SLTCTL_ABPE);
> >       pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
> > +                               PCI_EXP_SLTCTL_PWR_IND_OFF |
> >                                  PCI_EXP_SLTCTL_ATTN_IND_OFF);
> >       if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {
> 
> -- 
> Best regards,
> Vladimir



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize
  2023-03-02  8:26 ` [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize Michael S. Tsirkin
@ 2023-03-02 11:49   ` Michael Tokarev
  2023-03-03  0:15     ` Michael S. Tsirkin
  0 siblings, 1 reply; 72+ messages in thread
From: Michael Tokarev @ 2023-03-02 11:49 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel
  Cc: Peter Maydell, Yajun Wu, Jiri Pirko, Marc-André Lureau,
	Yajun, Wu, &lt, Jiri, Pirko, Paolo Bonzini

There are some url'ifications slipped into this one:

02.03.2023 11:26, Michael S. Tsirkin пишет:
..

> Message-Id: <20230214021430.3638579-1-yajunw@nvidia.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Yajun Wu &lt;<a href="mailto:yajunw@nvidia.com" target="_blank">yajunw@nvidia.com</a>&gt;<br>
> Acked-by: Jiri Pirko &lt;<a href="mailto:jiri@nvidia.com" target="_blank">jiri@nvidia.com</a>&gt;<br></blockquote><div><br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


Thanks,

/mjt


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (52 preceding siblings ...)
  2023-03-02  8:27 ` [PULL 53/53] tests/data/acpi/virt: drop (most) duplicate files Michael S. Tsirkin
@ 2023-03-02 12:16 ` Michael Tokarev
  2023-03-02 23:23   ` Michael S. Tsirkin
  2023-03-03  0:15 ` Michael S. Tsirkin
  54 siblings, 1 reply; 72+ messages in thread
From: Michael Tokarev @ 2023-03-02 12:16 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel; +Cc: Peter Maydell

02.03.2023 11:24, Michael S. Tsirkin wrote:
..
>    https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

It looks like this series contains quite a few changes which should be
applied to -stable as well. Here are the ones which I think should be
there, maybe others too:

  Julia Suvorova:
         hw/smbios: fix field corruption in type 4 table

  Michael S. Tsirkin:
         (Revert "x86: don't let decompressed kernel image clobber setup_data" -- not in 7.2)
         Revert "x86: do not re-randomize RNG seed on snapshot load"
         Revert "x86: re-initialize RNG seed when selecting kernel"
         Revert "x86: reinitialize RNG seed on system reboot"
         Revert "x86: use typedef for SetupData struct"
         Revert "x86: return modified setup_data only if read as memory, not as file"
         Revert "hw/i386: pass RNG seed via setup_data entry"

  Alex Bennée:
         backends/vhost-user: remove the ioeventfd check

  Akihiko Odaki:
         vhost-user-gpio: Configure vhost_dev when connecting
         vhost-user-i2c: Back up vqs before cleaning up vhost_dev
         vhost-user-rng: Back up vqs before cleaning up vhost_dev
         hw/timer/hpet: Fix expiration time overflow

  Dr. David Alan Gilbert (1):
         virtio-rng-pci: fix transitional migration compat for vectors


  Eugenio Pérez:
         vdpa: stop all svq on device deletion

  Carlos López:
         vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
         libvhost-user: check for NULL when allocating a virtqueue element

  Yajun Wu:
          chardev/char-socket: set s->listener = NULL in char_socket_finalize

  Jason Wang:
         intel-iommu: fail MAP notifier without caching mode
         intel-iommu: fail DEVIOTLB_UNMAP without dt mode


Does this make sense?

Thanks,

/mjt


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes
  2023-03-02 12:16 ` [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael Tokarev
@ 2023-03-02 23:23   ` Michael S. Tsirkin
  0 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-02 23:23 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel, Peter Maydell

On Thu, Mar 02, 2023 at 03:16:24PM +0300, Michael Tokarev wrote:
> 02.03.2023 11:24, Michael S. Tsirkin wrote:
> ..
> >    https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> 
> It looks like this series contains quite a few changes which should be
> applied to -stable as well. Here are the ones which I think should be
> there, maybe others too:
> 
>  Julia Suvorova:
>         hw/smbios: fix field corruption in type 4 table
> 
>  Michael S. Tsirkin:
>         (Revert "x86: don't let decompressed kernel image clobber setup_data" -- not in 7.2)
>         Revert "x86: do not re-randomize RNG seed on snapshot load"
>         Revert "x86: re-initialize RNG seed when selecting kernel"
>         Revert "x86: reinitialize RNG seed on system reboot"
>         Revert "x86: use typedef for SetupData struct"
>         Revert "x86: return modified setup_data only if read as memory, not as file"
>         Revert "hw/i386: pass RNG seed via setup_data entry"
> 
>  Alex Bennée:
>         backends/vhost-user: remove the ioeventfd check

not this one I think, it's a feature not a bugfix.

>  Akihiko Odaki:
>         vhost-user-gpio: Configure vhost_dev when connecting
>         vhost-user-i2c: Back up vqs before cleaning up vhost_dev
>         vhost-user-rng: Back up vqs before cleaning up vhost_dev
>         hw/timer/hpet: Fix expiration time overflow
> 
>  Dr. David Alan Gilbert (1):
>         virtio-rng-pci: fix transitional migration compat for vectors
> 
> 
>  Eugenio Pérez:
>         vdpa: stop all svq on device deletion
> 
>  Carlos López:
>         vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
>         libvhost-user: check for NULL when allocating a virtqueue element
> 
>  Yajun Wu:
>          chardev/char-socket: set s->listener = NULL in char_socket_finalize
> 
>  Jason Wang:
>         intel-iommu: fail MAP notifier without caching mode
>         intel-iommu: fail DEVIOTLB_UNMAP without dt mode


others ok

> 
> Does this make sense?
> 
> Thanks,
> 
> /mjt



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes
  2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
                   ` (53 preceding siblings ...)
  2023-03-02 12:16 ` [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael Tokarev
@ 2023-03-03  0:15 ` Michael S. Tsirkin
  2023-03-03 17:09   ` Peter Maydell
  54 siblings, 1 reply; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-03  0:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell

On Thu, Mar 02, 2023 at 03:24:28AM -0500, Michael S. Tsirkin wrote:
> The following changes since commit 627634031092e1514f363fd8659a579398de0f0e:
> 
>   Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)
> 
> are available in the Git repository at:
> 
>   https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> 
> for you to fetch changes up to 65888be0d4da746e2f99930e21018d801bf8995e:


I re-pushed after fixing two commit log (same files):
commit ee92a56b08d0b59016a4a9bc1bf3a3de1fbe3956
now.

Thanks!


>   tests/data/acpi/virt: drop (most) duplicate files. (2023-03-02 03:16:26 -0500)
> 
> ----------------------------------------------------------------
> virtio,pc,pci: features, cleanups, fixes
> 
> vhost-user support without ioeventfd
> word replacements in vhost user spec
> shpc improvements
> 
> cleanups, fixes all over the place
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> ----------------------------------------------------------------
> Akihiko Odaki (4):
>       vhost-user-gpio: Configure vhost_dev when connecting
>       vhost-user-i2c: Back up vqs before cleaning up vhost_dev
>       vhost-user-rng: Back up vqs before cleaning up vhost_dev
>       hw/timer/hpet: Fix expiration time overflow
> 
> Alex Bennée (1):
>       backends/vhost-user: remove the ioeventfd check
> 
> Carlos López (2):
>       vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll()
>       libvhost-user: check for NULL when allocating a virtqueue element
> 
> Dr. David Alan Gilbert (1):
>       virtio-rng-pci: fix transitional migration compat for vectors
> 
> Eugenio Pérez (2):
>       virtio-net: clear guest_announce feature if no cvq backend
>       vdpa: stop all svq on device deletion
> 
> Gregory Price (2):
>       hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL
>       hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition
> 
> Ira Weiny (3):
>       qemu/bswap: Add const_le64()
>       qemu/uuid: Add UUID static initializer
>       hw/cxl/mailbox: Use new UUID network order define for cel_uuid
> 
> Jason Wang (4):
>       intel-iommu: fail MAP notifier without caching mode
>       intel-iommu: fail DEVIOTLB_UNMAP without dt mode
>       memory: introduce memory_region_unmap_iommu_notifier_range()
>       smmu: switch to use memory_region_unmap_iommu_notifier_range()
> 
> Jonathan Cameron (6):
>       MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer
>       hw/mem/cxl_type3: Improve error handling in realize()
>       hw/pci-bridge/cxl_downstream: Fix type naming mismatch
>       tests/acpi: Allow update of q35/DSDT.cxl
>       hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge
>       tests: acpi: Update q35/DSDT.cxl for removed duplicate UID
> 
> Julia Suvorova (1):
>       hw/smbios: fix field corruption in type 4 table
> 
> Maxime Coquelin (3):
>       docs: vhost-user: replace _SLAVE_ with _BACKEND_
>       libvhost-user: Adopt new backend naming
>       vhost-user: Adopt new backend naming
> 
> Michael S. Tsirkin (8):
>       Revert "x86: don't let decompressed kernel image clobber setup_data"
>       Revert "x86: do not re-randomize RNG seed on snapshot load"
>       Revert "x86: re-initialize RNG seed when selecting kernel"
>       Revert "x86: reinitialize RNG seed on system reboot"
>       Revert "x86: use typedef for SetupData struct"
>       Revert "x86: return modified setup_data only if read as memory, not as file"
>       Revert "hw/i386: pass RNG seed via setup_data entry"
>       tests/data/acpi/virt: drop (most) duplicate files.
> 
> Peter Xu (1):
>       intel-iommu: send UNMAP notifications for domain or global inv desc
> 
> Philippe Mathieu-Daudé (1):
>       hw/pci: Trace IRQ routing on PCI topology
> 
> Vladimir Sementsov-Ogievskiy (12):
>       pci/shpc: set attention led to OFF on reset
>       pci/shpc: change shpc_get_status() return type to uint8_t
>       pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition
>       pci/shpc: more generic handle hot-unplug in shpc_slot_command()
>       pci/shpc: pass PCIDevice pointer to shpc_slot_command()
>       pci/shpc: refactor shpc_device_plug_common()
>       pcie: pcie_cap_slot_write_config(): use correct macro
>       pcie_regs: drop duplicated indicator value macros
>       pcie: drop unused PCIExpressIndicator
>       pcie: pcie_cap_slot_enable_power() use correct helper
>       pcie: introduce pcie_sltctl_powered_off() helper
>       pcie: set power indicator to off on reset by default
> 
> Yajun Wu (1):
>       chardev/char-socket: set s->listener = NULL in char_socket_finalize
> 
> Zhenzhong Duan (1):
>       memory: Optimize replay of guest mapping
> 
>  include/exec/memory.h                     |  10 +++
>  include/hw/cxl/cxl_device.h               |   2 +-
>  include/hw/i386/microvm.h                 |   5 +-
>  include/hw/i386/pc.h                      |   3 -
>  include/hw/i386/x86.h                     |   3 +-
>  include/hw/nvram/fw_cfg.h                 |  31 --------
>  include/hw/pci/pcie.h                     |   8 --
>  include/hw/pci/pcie_regs.h                |  14 ----
>  include/hw/virtio/vhost-user-gpio.h       |   2 +-
>  include/qemu/bswap.h                      |  12 ++-
>  include/qemu/uuid.h                       |  12 +++
>  subprojects/libvhost-user/libvhost-user.h |  20 ++---
>  backends/vhost-user.c                     |  11 ---
>  chardev/char-socket.c                     |   1 +
>  hw/arm/smmu-common.c                      |  16 +---
>  hw/core/machine.c                         |   2 +
>  hw/cxl/cxl-device-utils.c                 |   2 +-
>  hw/cxl/cxl-mailbox-utils.c                |  28 +++----
>  hw/i386/acpi-build.c                      |   1 -
>  hw/i386/intel_iommu.c                     |  31 ++++++--
>  hw/i386/microvm.c                         |  17 ++---
>  hw/i386/pc.c                              |   4 +-
>  hw/i386/pc_piix.c                         |   2 -
>  hw/i386/pc_q35.c                          |   2 -
>  hw/i386/x86.c                             | 122 ++++++++----------------------
>  hw/mem/cxl_type3.c                        |  15 +++-
>  hw/net/virtio-net.c                       |  15 ++++
>  hw/nvram/fw_cfg.c                         |  21 ++---
>  hw/pci-bridge/cxl_downstream.c            |   2 +-
>  hw/pci/pci.c                              |   8 ++
>  hw/pci/pcie.c                             |  30 +++++---
>  hw/pci/shpc.c                             | 107 ++++++++++++++------------
>  hw/smbios/smbios.c                        |   8 +-
>  hw/timer/hpet.c                           |  19 +++--
>  hw/virtio/vhost-shadow-virtqueue.c        |   2 +-
>  hw/virtio/vhost-user-gpio.c               |  10 ++-
>  hw/virtio/vhost-user-i2c.c                |   5 +-
>  hw/virtio/vhost-user-rng.c                |   5 +-
>  hw/virtio/vhost-user.c                    |  30 ++++----
>  hw/virtio/vhost-vdpa.c                    |  17 +----
>  hw/virtio/virtio-qmp.c                    |  12 +--
>  softmmu/memory.c                          |  17 ++++-
>  subprojects/libvhost-user/libvhost-user.c |  27 ++++---
>  MAINTAINERS                               |   1 +
>  docs/interop/vhost-user.rst               |  40 +++++-----
>  hw/pci/trace-events                       |   1 +
>  tests/data/acpi/q35/DSDT.cxl              | Bin 9578 -> 9564 bytes
>  tests/data/acpi/virt/APIC.memhp           | Bin 172 -> 0 bytes
>  tests/data/acpi/virt/APIC.numamem         | Bin 172 -> 0 bytes
>  tests/data/acpi/virt/DSDT.numamem         | Bin 5196 -> 0 bytes
>  tests/data/acpi/virt/FACP.memhp           | Bin 276 -> 0 bytes
>  tests/data/acpi/virt/FACP.numamem         | Bin 276 -> 0 bytes
>  tests/data/acpi/virt/GTDT.memhp           | Bin 96 -> 0 bytes
>  tests/data/acpi/virt/GTDT.numamem         | Bin 96 -> 0 bytes
>  tests/data/acpi/virt/IORT.memhp           | Bin 128 -> 0 bytes
>  tests/data/acpi/virt/IORT.numamem         | Bin 128 -> 0 bytes
>  tests/data/acpi/virt/IORT.pxb             | Bin 128 -> 0 bytes
>  tests/data/acpi/virt/MCFG.memhp           | Bin 60 -> 0 bytes
>  tests/data/acpi/virt/MCFG.numamem         | Bin 60 -> 0 bytes
>  tests/data/acpi/virt/SPCR.memhp           | Bin 80 -> 0 bytes
>  tests/data/acpi/virt/SPCR.numamem         | Bin 80 -> 0 bytes
>  61 files changed, 357 insertions(+), 396 deletions(-)
>  delete mode 100644 tests/data/acpi/virt/APIC.memhp
>  delete mode 100644 tests/data/acpi/virt/APIC.numamem
>  delete mode 100644 tests/data/acpi/virt/DSDT.numamem
>  delete mode 100644 tests/data/acpi/virt/FACP.memhp
>  delete mode 100644 tests/data/acpi/virt/FACP.numamem
>  delete mode 100644 tests/data/acpi/virt/GTDT.memhp
>  delete mode 100644 tests/data/acpi/virt/GTDT.numamem
>  delete mode 100644 tests/data/acpi/virt/IORT.memhp
>  delete mode 100644 tests/data/acpi/virt/IORT.numamem
>  delete mode 100644 tests/data/acpi/virt/IORT.pxb
>  delete mode 100644 tests/data/acpi/virt/MCFG.memhp
>  delete mode 100644 tests/data/acpi/virt/MCFG.numamem
>  delete mode 100644 tests/data/acpi/virt/SPCR.memhp
>  delete mode 100644 tests/data/acpi/virt/SPCR.numamem
> 



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize
  2023-03-02 11:49   ` Michael Tokarev
@ 2023-03-03  0:15     ` Michael S. Tsirkin
  0 siblings, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-03  0:15 UTC (permalink / raw)
  To: Michael Tokarev
  Cc: qemu-devel, Peter Maydell, Yajun Wu, Jiri Pirko,
	Marc-André Lureau, Yajun, Wu, &lt, Jiri, Pirko,
	Paolo Bonzini

On Thu, Mar 02, 2023 at 02:49:56PM +0300, Michael Tokarev wrote:
> There are some url'ifications slipped into this one:
> 
> 02.03.2023 11:26, Michael S. Tsirkin пишет:
> ..
> 
> > Message-Id: <20230214021430.3638579-1-yajunw@nvidia.com>
> > Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > Signed-off-by: Yajun Wu &lt;<a href="mailto:yajunw@nvidia.com" target="_blank">yajunw@nvidia.com</a>&gt;<br>
> > Acked-by: Jiri Pirko &lt;<a href="mailto:jiri@nvidia.com" target="_blank">jiri@nvidia.com</a>&gt;<br></blockquote><div><br></div><div>Reviewed-by: Marc-André Lureau &lt;<a href="mailto:marcandre.lureau@redhat.com">marcandre.lureau@redhat.com</a>&gt;<br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> 
> 
> Thanks,
> 
> /mjt

Ugh yack. how did this happen - no idea.
Fixed now thanks!



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 31/53] pcie: set power indicator to off on reset by default
  2023-03-02 11:34   ` Vladimir Sementsov-Ogievskiy
  2023-03-02 11:42     ` Michael S. Tsirkin
@ 2023-03-03  0:15     ` Michael S. Tsirkin
  1 sibling, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-03  0:15 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy
  Cc: qemu-devel, Peter Maydell, Anton Kuchin, Marcel Apfelbaum

On Thu, Mar 02, 2023 at 02:34:02PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> On 02.03.23 11:26, Michael S. Tsirkin wrote:
> > From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > 
> > It should be zero, the only valid values are ON, OFF and BLINK.
> 
> At any chance, fix s/should be/should not be/

fixed now thanks!
> > 
> > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> > Reviewed-by: Anton Kuchin <antonkuchin@yandex-team.ru>
> > Message-Id: <20230216180356.156832-13-vsementsov@yandex-team.ru>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >   hw/pci/pcie.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> > index 90faf0710a..b8c24cf45f 100644
> > --- a/hw/pci/pcie.c
> > +++ b/hw/pci/pcie.c
> > @@ -684,6 +684,7 @@ void pcie_cap_slot_reset(PCIDevice *dev)
> >                                    PCI_EXP_SLTCTL_PDCE |
> >                                    PCI_EXP_SLTCTL_ABPE);
> >       pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
> > +                               PCI_EXP_SLTCTL_PWR_IND_OFF |
> >                                  PCI_EXP_SLTCTL_ATTN_IND_OFF);
> >       if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) {
> 
> -- 
> Best regards,
> Vladimir



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 00/53] virtio,pc,pci: features, cleanups, fixes
  2023-03-03  0:15 ` Michael S. Tsirkin
@ 2023-03-03 17:09   ` Peter Maydell
  0 siblings, 0 replies; 72+ messages in thread
From: Peter Maydell @ 2023-03-03 17:09 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel

On Fri, 3 Mar 2023 at 00:15, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Thu, Mar 02, 2023 at 03:24:28AM -0500, Michael S. Tsirkin wrote:
> > The following changes since commit 627634031092e1514f363fd8659a579398de0f0e:
> >
> >   Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000)
> >
> > are available in the Git repository at:
> >
> >   https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> >
> > for you to fetch changes up to 65888be0d4da746e2f99930e21018d801bf8995e:
>
>
> I re-pushed after fixing two commit log (same files):
> commit ee92a56b08d0b59016a4a9bc1bf3a3de1fbe3956
> now.
>
> Thanks!


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/8.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors
  2023-03-02  8:25 ` [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors Michael S. Tsirkin
@ 2023-03-04 20:03   ` Michael Tokarev
  2023-03-05 10:25     ` Michael S. Tsirkin
  2023-03-06 12:12     ` Dr. David Alan Gilbert
  0 siblings, 2 replies; 72+ messages in thread
From: Michael Tokarev @ 2023-03-04 20:03 UTC (permalink / raw)
  To: Michael S. Tsirkin, qemu-devel; +Cc: Dr. David Alan Gilbert

02.03.2023 11:25, Michael S. Tsirkin wrote:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> 
> In bad9c5a516 ("virtio-rng-pci: fix migration compat for vectors") I
> fixed the virtio-rng-pci migration compatibility, but it was discovered
> that we also need to fix the other aliases of the device for the
> transitional cases.
> 
> Fixes: 9ea02e8f1 ('virtio-rng-pci: Allow setting nvectors, so we can use MSI-X')
> bz: https://bugzilla.redhat.com/show_bug.cgi?id=2162569
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Message-Id: <20230207174944.138255-1-dgilbert@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   hw/core/machine.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index f29e700ee4..1cf6822e06 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -47,6 +47,8 @@ const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
>   GlobalProperty hw_compat_7_1[] = {
>       { "virtio-device", "queue_reset", "false" },
>       { "virtio-rng-pci", "vectors", "0" },
> +    { "virtio-rng-pci-transitional", "vectors", "0" },
> +    { "virtio-rng-pci-non-transitional", "vectors", "0" },
>   };

If we consider this one for 7.2 stable, the previous change here, which
added "virtio-rng-pci" right before the lines being added, should also
be picked up, which is bad9c5a5166fd5e3a892b7b0477cf2f4bd3a959a:
  From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
  Date: Mon, 9 Jan 2023 10:58:09 +0000
  Subject: virtio-rng-pci: fix migration compat for vectors

Should the two both be included in -stable, or both omitted?

Thanks,

/mjt


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors
  2023-03-04 20:03   ` Michael Tokarev
@ 2023-03-05 10:25     ` Michael S. Tsirkin
  2023-03-06 12:12     ` Dr. David Alan Gilbert
  1 sibling, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-03-05 10:25 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: qemu-devel, Dr. David Alan Gilbert

On Sat, Mar 04, 2023 at 11:03:20PM +0300, Michael Tokarev wrote:
> 02.03.2023 11:25, Michael S. Tsirkin wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > In bad9c5a516 ("virtio-rng-pci: fix migration compat for vectors") I
> > fixed the virtio-rng-pci migration compatibility, but it was discovered
> > that we also need to fix the other aliases of the device for the
> > transitional cases.
> > 
> > Fixes: 9ea02e8f1 ('virtio-rng-pci: Allow setting nvectors, so we can use MSI-X')
> > bz: https://bugzilla.redhat.com/show_bug.cgi?id=2162569
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > Message-Id: <20230207174944.138255-1-dgilbert@redhat.com>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >   hw/core/machine.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > index f29e700ee4..1cf6822e06 100644
> > --- a/hw/core/machine.c
> > +++ b/hw/core/machine.c
> > @@ -47,6 +47,8 @@ const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
> >   GlobalProperty hw_compat_7_1[] = {
> >       { "virtio-device", "queue_reset", "false" },
> >       { "virtio-rng-pci", "vectors", "0" },
> > +    { "virtio-rng-pci-transitional", "vectors", "0" },
> > +    { "virtio-rng-pci-non-transitional", "vectors", "0" },
> >   };
> 
> If we consider this one for 7.2 stable, the previous change here, which
> added "virtio-rng-pci" right before the lines being added, should also
> be picked up, which is bad9c5a5166fd5e3a892b7b0477cf2f4bd3a959a:
>  From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>  Date: Mon, 9 Jan 2023 10:58:09 +0000
>  Subject: virtio-rng-pci: fix migration compat for vectors
> 
> Should the two both be included in -stable, or both omitted?
> 
> Thanks,
> 
> /mjt

I'd say include.

-- 
MST



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors
  2023-03-04 20:03   ` Michael Tokarev
  2023-03-05 10:25     ` Michael S. Tsirkin
@ 2023-03-06 12:12     ` Dr. David Alan Gilbert
  1 sibling, 0 replies; 72+ messages in thread
From: Dr. David Alan Gilbert @ 2023-03-06 12:12 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: Michael S. Tsirkin, qemu-devel

* Michael Tokarev (mjt@tls.msk.ru) wrote:
> 02.03.2023 11:25, Michael S. Tsirkin wrote:
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> > 
> > In bad9c5a516 ("virtio-rng-pci: fix migration compat for vectors") I
> > fixed the virtio-rng-pci migration compatibility, but it was discovered
> > that we also need to fix the other aliases of the device for the
> > transitional cases.
> > 
> > Fixes: 9ea02e8f1 ('virtio-rng-pci: Allow setting nvectors, so we can use MSI-X')
> > bz: https://bugzilla.redhat.com/show_bug.cgi?id=2162569
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > Message-Id: <20230207174944.138255-1-dgilbert@redhat.com>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >   hw/core/machine.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/hw/core/machine.c b/hw/core/machine.c
> > index f29e700ee4..1cf6822e06 100644
> > --- a/hw/core/machine.c
> > +++ b/hw/core/machine.c
> > @@ -47,6 +47,8 @@ const size_t hw_compat_7_2_len = G_N_ELEMENTS(hw_compat_7_2);
> >   GlobalProperty hw_compat_7_1[] = {
> >       { "virtio-device", "queue_reset", "false" },
> >       { "virtio-rng-pci", "vectors", "0" },
> > +    { "virtio-rng-pci-transitional", "vectors", "0" },
> > +    { "virtio-rng-pci-non-transitional", "vectors", "0" },
> >   };
> 
> If we consider this one for 7.2 stable, the previous change here, which
> added "virtio-rng-pci" right before the lines being added, should also
> be picked up, which is bad9c5a5166fd5e3a892b7b0477cf2f4bd3a959a:
>  From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>  Date: Mon, 9 Jan 2023 10:58:09 +0000
>  Subject: virtio-rng-pci: fix migration compat for vectors
> 
> Should the two both be included in -stable, or both omitted?

I think both included; however note the warning in the original patch
(that's also true in this one); live migration from an unpatched world
to the patched would will break, but it fixes live migration from older
Qemu; you get to pick your favourite breakage.

Dave

> Thanks,
> 
> /mjt
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-03-02  8:26 ` [PULL 36/53] memory: Optimize replay of guest mapping Michael S. Tsirkin
@ 2023-04-04 18:00   ` Peter Maydell
  2023-04-04 19:13     ` Michael S. Tsirkin
  0 siblings, 1 reply; 72+ messages in thread
From: Peter Maydell @ 2023-04-04 18:00 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: qemu-devel, Zhenzhong Duan, Peter Xu, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> From: Zhenzhong Duan <zhenzhong.duan@intel.com>
>
> On x86, there are two notifiers registered due to vtd-ir memory region
> splitting the whole address space. During replay of the address space
> for each notifier, the whole address space is scanned which is
> unnecessory.
>
> We only need to scan the space belong to notifier montiored space.
>
> Assert when notifier is used to monitor beyond iommu memory region's
> address space.

Hi. This patch seems to have regressed the mps3-an547 board,
which now asserts on startup:

$ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
-kernel /tmp/an547-mwe/build/test.elf
qemu-system-arm: ../../softmmu/memory.c:1903:
memory_region_register_iommu_notifier: Assertion `n->end <=
memory_region_size(mr)' failed.
Aborted (core dumped)

(reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)

Since this commit says it's just an optimization, for the 8.0
release can we simply revert it without breaking anything?

> diff --git a/softmmu/memory.c b/softmmu/memory.c
> index 9d64efca26..da7d846619 100644
> --- a/softmmu/memory.c
> +++ b/softmmu/memory.c
> @@ -1900,6 +1900,7 @@ int memory_region_register_iommu_notifier(MemoryRegion *mr,
>      iommu_mr = IOMMU_MEMORY_REGION(mr);
>      assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
>      assert(n->start <= n->end);
> +    assert(n->end <= memory_region_size(mr));

In the mps3-an547 case we assert here because n->end is -1.
This is because tcg_register_iommu_notifier() registers an iommu
notifier that covers the entire address space:

        iommu_notifier_init(&notifier->n,
                            tcg_iommu_unmap_notify,
                            IOMMU_NOTIFIER_UNMAP,
                            0,
                            HWADDR_MAX,
                            iommu_idx);
        memory_region_register_iommu_notifier(notifier->mr, &notifier->n,
                                              &error_fatal);

thanks
-- PMM


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-04-04 18:00   ` Peter Maydell
@ 2023-04-04 19:13     ` Michael S. Tsirkin
  2023-04-04 20:23       ` Peter Maydell
  2023-04-06  3:46       ` Duan, Zhenzhong
  0 siblings, 2 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-04-04 19:13 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Zhenzhong Duan, Peter Xu, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

On Tue, Apr 04, 2023 at 07:00:04PM +0100, Peter Maydell wrote:
> On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > From: Zhenzhong Duan <zhenzhong.duan@intel.com>
> >
> > On x86, there are two notifiers registered due to vtd-ir memory region
> > splitting the whole address space. During replay of the address space
> > for each notifier, the whole address space is scanned which is
> > unnecessory.
> >
> > We only need to scan the space belong to notifier montiored space.
> >
> > Assert when notifier is used to monitor beyond iommu memory region's
> > address space.
> 
> Hi. This patch seems to have regressed the mps3-an547 board,
> which now asserts on startup:
> 
> $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> -kernel /tmp/an547-mwe/build/test.elf
> qemu-system-arm: ../../softmmu/memory.c:1903:
> memory_region_register_iommu_notifier: Assertion `n->end <=
> memory_region_size(mr)' failed.
> Aborted (core dumped)
> 
> (reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)
> 
> Since this commit says it's just an optimization, for the 8.0
> release can we simply revert it without breaking anything?
> 
> > diff --git a/softmmu/memory.c b/softmmu/memory.c
> > index 9d64efca26..da7d846619 100644
> > --- a/softmmu/memory.c
> > +++ b/softmmu/memory.c
> > @@ -1900,6 +1900,7 @@ int memory_region_register_iommu_notifier(MemoryRegion *mr,
> >      iommu_mr = IOMMU_MEMORY_REGION(mr);
> >      assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
> >      assert(n->start <= n->end);
> > +    assert(n->end <= memory_region_size(mr));
> 
> In the mps3-an547 case we assert here because n->end is -1.
> This is because tcg_register_iommu_notifier() registers an iommu
> notifier that covers the entire address space:
> 
>         iommu_notifier_init(&notifier->n,
>                             tcg_iommu_unmap_notify,
>                             IOMMU_NOTIFIER_UNMAP,
>                             0,
>                             HWADDR_MAX,
>                             iommu_idx);
>         memory_region_register_iommu_notifier(notifier->mr, &notifier->n,
>                                               &error_fatal);
> 
> thanks
> -- PMM


Fine to revert by me.  Zhenzhong Duan  can you pls fix up
this regression and repost? Maybe fix typos in commit log
when reposting. Thanks!

-- 
MST



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-04-04 19:13     ` Michael S. Tsirkin
@ 2023-04-04 20:23       ` Peter Maydell
  2023-04-04 20:37         ` Peter Xu
  2023-04-04 20:38         ` Michael S. Tsirkin
  2023-04-06  3:46       ` Duan, Zhenzhong
  1 sibling, 2 replies; 72+ messages in thread
From: Peter Maydell @ 2023-04-04 20:23 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: qemu-devel, Zhenzhong Duan, Peter Xu, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

On Tue, 4 Apr 2023 at 20:13, Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Apr 04, 2023 at 07:00:04PM +0100, Peter Maydell wrote:
> > On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > From: Zhenzhong Duan <zhenzhong.duan@intel.com>
> > >
> > > On x86, there are two notifiers registered due to vtd-ir memory region
> > > splitting the whole address space. During replay of the address space
> > > for each notifier, the whole address space is scanned which is
> > > unnecessory.
> > >
> > > We only need to scan the space belong to notifier montiored space.
> > >
> > > Assert when notifier is used to monitor beyond iommu memory region's
> > > address space.
> >
> > Hi. This patch seems to have regressed the mps3-an547 board,
> > which now asserts on startup:
> >
> > $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> > -kernel /tmp/an547-mwe/build/test.elf
> > qemu-system-arm: ../../softmmu/memory.c:1903:
> > memory_region_register_iommu_notifier: Assertion `n->end <=
> > memory_region_size(mr)' failed.
> > Aborted (core dumped)
> >
> > (reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)
> >
> > Since this commit says it's just an optimization, for the 8.0
> > release can we simply revert it without breaking anything?

> Fine to revert by me.  Zhenzhong Duan  can you pls fix up
> this regression and repost? Maybe fix typos in commit log
> when reposting. Thanks!

Would somebody also like to send the 'revert' patch, please?
I had that all ready to go, but my git send-email setup
seems to have mysteriously broken and I don't have time to
fix it this evening :-(

This is the commit message I wrote:


Revert "memory: Optimize replay of guest mapping"

This reverts commit 6da24341866fa940fd7d575788a2319514941c77
("memory: Optimize replay of guest mapping").

This change breaks the mps3-an547 board under TCG (and
probably other TCG boards using an IOMMU), which now
assert:

$ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
-kernel /tmp/an547-mwe/build/test.elf
qemu-system-arm: ../../softmmu/memory.c:1903:
memory_region_register_iommu_notifier: Assertion `n->end <=
memory_region_size(mr)' failed.

This is because tcg_register_iommu_notifier() registers
an IOMMU notifier which covers the entire address space,
so the assertion added in this commit is not correct.

For the 8.0 release, just revert this commit as it is
only an optimization.

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


thanks
-- PMM


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-04-04 20:23       ` Peter Maydell
@ 2023-04-04 20:37         ` Peter Xu
  2023-04-04 20:38         ` Michael S. Tsirkin
  1 sibling, 0 replies; 72+ messages in thread
From: Peter Xu @ 2023-04-04 20:37 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Michael S. Tsirkin, qemu-devel, Zhenzhong Duan, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

[-- Attachment #1: Type: text/plain, Size: 2762 bytes --]

On Tue, Apr 04, 2023 at 09:23:21PM +0100, Peter Maydell wrote:
> On Tue, 4 Apr 2023 at 20:13, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Tue, Apr 04, 2023 at 07:00:04PM +0100, Peter Maydell wrote:
> > > On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
> > > >
> > > > From: Zhenzhong Duan <zhenzhong.duan@intel.com>
> > > >
> > > > On x86, there are two notifiers registered due to vtd-ir memory region
> > > > splitting the whole address space. During replay of the address space
> > > > for each notifier, the whole address space is scanned which is
> > > > unnecessory.
> > > >
> > > > We only need to scan the space belong to notifier montiored space.
> > > >
> > > > Assert when notifier is used to monitor beyond iommu memory region's
> > > > address space.
> > >
> > > Hi. This patch seems to have regressed the mps3-an547 board,
> > > which now asserts on startup:
> > >
> > > $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> > > -kernel /tmp/an547-mwe/build/test.elf
> > > qemu-system-arm: ../../softmmu/memory.c:1903:
> > > memory_region_register_iommu_notifier: Assertion `n->end <=
> > > memory_region_size(mr)' failed.
> > > Aborted (core dumped)
> > >
> > > (reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)
> > >
> > > Since this commit says it's just an optimization, for the 8.0
> > > release can we simply revert it without breaking anything?
> 
> > Fine to revert by me.  Zhenzhong Duan  can you pls fix up
> > this regression and repost? Maybe fix typos in commit log
> > when reposting. Thanks!
> 
> Would somebody also like to send the 'revert' patch, please?
> I had that all ready to go, but my git send-email setup
> seems to have mysteriously broken and I don't have time to
> fix it this evening :-(

Attached.

> 
> This is the commit message I wrote:
> 
> 
> Revert "memory: Optimize replay of guest mapping"
> 
> This reverts commit 6da24341866fa940fd7d575788a2319514941c77
> ("memory: Optimize replay of guest mapping").
> 
> This change breaks the mps3-an547 board under TCG (and
> probably other TCG boards using an IOMMU), which now
> assert:
> 
> $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> -kernel /tmp/an547-mwe/build/test.elf
> qemu-system-arm: ../../softmmu/memory.c:1903:
> memory_region_register_iommu_notifier: Assertion `n->end <=
> memory_region_size(mr)' failed.
> 
> This is because tcg_register_iommu_notifier() registers
> an IOMMU notifier which covers the entire address space,
> so the assertion added in this commit is not correct.
> 
> For the 8.0 release, just revert this commit as it is
> only an optimization.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> 
> 
> thanks
> -- PMM
> 

-- 
Peter Xu

[-- Attachment #2: 0001-Revert-memory-Optimize-replay-of-guest-mapping.patch --]
[-- Type: text/plain, Size: 3066 bytes --]

From 8fd48876a6910341dfcbe1b8bf1185d2cea851cd Mon Sep 17 00:00:00 2001
From: Peter Maydell <peter.maydell@linaro.org>
Date: Tue, 4 Apr 2023 16:34:22 -0400
Subject: [PATCH] Revert "memory: Optimize replay of guest mapping"

This reverts commit 6da24341866fa940fd7d575788a2319514941c77
("memory: Optimize replay of guest mapping").

This change breaks the mps3-an547 board under TCG (and
probably other TCG boards using an IOMMU), which now
assert:

$ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
-kernel /tmp/an547-mwe/build/test.elf
qemu-system-arm: ../../softmmu/memory.c:1903:
memory_region_register_iommu_notifier: Assertion `n->end <=
memory_region_size(mr)' failed.

This is because tcg_register_iommu_notifier() registers
an IOMMU notifier which covers the entire address space,
so the assertion added in this commit is not correct.

For the 8.0 release, just revert this commit as it is
only an optimization.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/intel_iommu.c | 2 +-
 softmmu/memory.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index faade7def8..a62896759c 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3850,7 +3850,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
                 .domain_id = vtd_get_domain_id(s, &ce, vtd_as->pasid),
             };
 
-            vtd_page_walk(s, &ce, n->start, n->end, &info, vtd_as->pasid);
+            vtd_page_walk(s, &ce, 0, ~0ULL, &info, vtd_as->pasid);
         }
     } else {
         trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn),
diff --git a/softmmu/memory.c b/softmmu/memory.c
index 5305aca7ca..b1a6cae6f5 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1900,7 +1900,6 @@ int memory_region_register_iommu_notifier(MemoryRegion *mr,
     iommu_mr = IOMMU_MEMORY_REGION(mr);
     assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
     assert(n->start <= n->end);
-    assert(n->end <= memory_region_size(mr));
     assert(n->iommu_idx >= 0 &&
            n->iommu_idx < memory_region_iommu_num_indexes(iommu_mr));
 
@@ -1924,6 +1923,7 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUMemoryRegion *iommu_mr)
 
 void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 {
+    MemoryRegion *mr = MEMORY_REGION(iommu_mr);
     IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr);
     hwaddr addr, granularity;
     IOMMUTLBEntry iotlb;
@@ -1936,7 +1936,7 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
 
     granularity = memory_region_iommu_get_min_page_size(iommu_mr);
 
-    for (addr = n->start; addr < n->end; addr += granularity) {
+    for (addr = 0; addr < memory_region_size(mr); addr += granularity) {
         iotlb = imrc->translate(iommu_mr, addr, IOMMU_NONE, n->iommu_idx);
         if (iotlb.perm != IOMMU_NONE) {
             n->notify(n, &iotlb);
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 72+ messages in thread

* Re: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-04-04 20:23       ` Peter Maydell
  2023-04-04 20:37         ` Peter Xu
@ 2023-04-04 20:38         ` Michael S. Tsirkin
  1 sibling, 0 replies; 72+ messages in thread
From: Michael S. Tsirkin @ 2023-04-04 20:38 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Zhenzhong Duan, Peter Xu, Jason Wang,
	Marcel Apfelbaum, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost, David Hildenbrand, Philippe Mathieu-Daudé

On Tue, Apr 04, 2023 at 09:23:21PM +0100, Peter Maydell wrote:
> On Tue, 4 Apr 2023 at 20:13, Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Tue, Apr 04, 2023 at 07:00:04PM +0100, Peter Maydell wrote:
> > > On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
> > > >
> > > > From: Zhenzhong Duan <zhenzhong.duan@intel.com>
> > > >
> > > > On x86, there are two notifiers registered due to vtd-ir memory region
> > > > splitting the whole address space. During replay of the address space
> > > > for each notifier, the whole address space is scanned which is
> > > > unnecessory.
> > > >
> > > > We only need to scan the space belong to notifier montiored space.
> > > >
> > > > Assert when notifier is used to monitor beyond iommu memory region's
> > > > address space.
> > >
> > > Hi. This patch seems to have regressed the mps3-an547 board,
> > > which now asserts on startup:
> > >
> > > $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> > > -kernel /tmp/an547-mwe/build/test.elf
> > > qemu-system-arm: ../../softmmu/memory.c:1903:
> > > memory_region_register_iommu_notifier: Assertion `n->end <=
> > > memory_region_size(mr)' failed.
> > > Aborted (core dumped)
> > >
> > > (reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)
> > >
> > > Since this commit says it's just an optimization, for the 8.0
> > > release can we simply revert it without breaking anything?
> 
> > Fine to revert by me.  Zhenzhong Duan  can you pls fix up
> > this regression and repost? Maybe fix typos in commit log
> > when reposting. Thanks!
> 
> Would somebody also like to send the 'revert' patch, please?

Assuming it's just the technicality of sending it I sent it but it's
night here, didn't test at all. Just check it's same as yours and we
are good to go ;)

> I had that all ready to go, but my git send-email setup
> seems to have mysteriously broken and I don't have time to
> fix it this evening :-(
> 
> This is the commit message I wrote:
> 
> 
> Revert "memory: Optimize replay of guest mapping"
> 
> This reverts commit 6da24341866fa940fd7d575788a2319514941c77
> ("memory: Optimize replay of guest mapping").
> 
> This change breaks the mps3-an547 board under TCG (and
> probably other TCG boards using an IOMMU), which now
> assert:
> 
> $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
> -kernel /tmp/an547-mwe/build/test.elf
> qemu-system-arm: ../../softmmu/memory.c:1903:
> memory_region_register_iommu_notifier: Assertion `n->end <=
> memory_region_size(mr)' failed.
> 
> This is because tcg_register_iommu_notifier() registers
> an IOMMU notifier which covers the entire address space,
> so the assertion added in this commit is not correct.
> 
> For the 8.0 release, just revert this commit as it is
> only an optimization.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> 
> 
> thanks
> -- PMM



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PULL 36/53] memory: Optimize replay of guest mapping
  2023-04-04 19:13     ` Michael S. Tsirkin
  2023-04-04 20:23       ` Peter Maydell
@ 2023-04-06  3:46       ` Duan, Zhenzhong
  1 sibling, 0 replies; 72+ messages in thread
From: Duan, Zhenzhong @ 2023-04-06  3:46 UTC (permalink / raw)
  To: Michael S. Tsirkin, Peter Maydell
  Cc: qemu-devel, Peter Xu, Jason Wang, Marcel Apfelbaum,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost,
	David Hildenbrand, Philippe Mathieu-Daudé



>-----Original Message-----
>From: Michael S. Tsirkin <mst@redhat.com>
>Sent: Wednesday, April 5, 2023 3:13 AM
>To: Peter Maydell <peter.maydell@linaro.org>
>Cc: qemu-devel@nongnu.org; Duan, Zhenzhong
><zhenzhong.duan@intel.com>; Peter Xu <peterx@redhat.com>; Jason Wang
><jasowang@redhat.com>; Marcel Apfelbaum
><marcel.apfelbaum@gmail.com>; Paolo Bonzini <pbonzini@redhat.com>;
>Richard Henderson <richard.henderson@linaro.org>; Eduardo Habkost
><eduardo@habkost.net>; David Hildenbrand <david@redhat.com>; Philippe
>Mathieu-Daudé <philmd@linaro.org>
>Subject: Re: [PULL 36/53] memory: Optimize replay of guest mapping
>
>On Tue, Apr 04, 2023 at 07:00:04PM +0100, Peter Maydell wrote:
>> On Thu, 2 Mar 2023 at 08:26, Michael S. Tsirkin <mst@redhat.com> wrote:
>> >
>> > From: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> >
>> > On x86, there are two notifiers registered due to vtd-ir memory
>> > region splitting the whole address space. During replay of the
>> > address space for each notifier, the whole address space is scanned
>> > which is unnecessory.
>> >
>> > We only need to scan the space belong to notifier montiored space.
>> >
>> > Assert when notifier is used to monitor beyond iommu memory region's
>> > address space.
>>
>> Hi. This patch seems to have regressed the mps3-an547 board, which now
>> asserts on startup:
>>
>> $ ./build/x86/qemu-system-arm --machine mps3-an547 -serial stdio
>> -kernel /tmp/an547-mwe/build/test.elf
>> qemu-system-arm: ../../softmmu/memory.c:1903:
>> memory_region_register_iommu_notifier: Assertion `n->end <=
>> memory_region_size(mr)' failed.
>> Aborted (core dumped)
>>
>> (reported under https://gitlab.com/qemu-project/qemu/-/issues/1488)
>>
>> Since this commit says it's just an optimization, for the 8.0 release
>> can we simply revert it without breaking anything?
>>
>> > diff --git a/softmmu/memory.c b/softmmu/memory.c index
>> > 9d64efca26..da7d846619 100644
>> > --- a/softmmu/memory.c
>> > +++ b/softmmu/memory.c
>> > @@ -1900,6 +1900,7 @@ int
>memory_region_register_iommu_notifier(MemoryRegion *mr,
>> >      iommu_mr = IOMMU_MEMORY_REGION(mr);
>> >      assert(n->notifier_flags != IOMMU_NOTIFIER_NONE);
>> >      assert(n->start <= n->end);
>> > +    assert(n->end <= memory_region_size(mr));
>>
>> In the mps3-an547 case we assert here because n->end is -1.
>> This is because tcg_register_iommu_notifier() registers an iommu
>> notifier that covers the entire address space:
>>
>>         iommu_notifier_init(&notifier->n,
>>                             tcg_iommu_unmap_notify,
>>                             IOMMU_NOTIFIER_UNMAP,
>>                             0,
>>                             HWADDR_MAX,
>>                             iommu_idx);
>>         memory_region_register_iommu_notifier(notifier->mr, &notifier->n,
>>                                               &error_fatal);
>>
>> thanks
>> -- PMM
>
>
>Fine to revert by me.  Zhenzhong Duan  can you pls fix up this regression and
>repost? Maybe fix typos in commit log when reposting. Thanks!

Sorry for the trouble, I'll fix and repost a new version later with wider test.
Initial thought is to pick the intersection of iommu_mr and iommu notifier
in memory_region_iommu_replay(), then the assert() could be dropped.

Regards
Zhenzhong


^ permalink raw reply	[flat|nested] 72+ messages in thread

end of thread, other threads:[~2023-04-06  3:47 UTC | newest]

Thread overview: 72+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02  8:24 [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 01/53] hw/smbios: fix field corruption in type 4 table Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 02/53] Revert "x86: don't let decompressed kernel image clobber setup_data" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 03/53] Revert "x86: do not re-randomize RNG seed on snapshot load" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 04/53] Revert "x86: re-initialize RNG seed when selecting kernel" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 05/53] Revert "x86: reinitialize RNG seed on system reboot" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 06/53] Revert "x86: use typedef for SetupData struct" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 07/53] Revert "x86: return modified setup_data only if read as memory, not as file" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 08/53] Revert "hw/i386: pass RNG seed via setup_data entry" Michael S. Tsirkin
2023-03-02  8:24 ` [PULL 09/53] virtio-net: clear guest_announce feature if no cvq backend Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 10/53] backends/vhost-user: remove the ioeventfd check Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 11/53] vhost-user-gpio: Configure vhost_dev when connecting Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 12/53] vhost-user-i2c: Back up vqs before cleaning up vhost_dev Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 13/53] vhost-user-rng: " Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 14/53] virtio-rng-pci: fix transitional migration compat for vectors Michael S. Tsirkin
2023-03-04 20:03   ` Michael Tokarev
2023-03-05 10:25     ` Michael S. Tsirkin
2023-03-06 12:12     ` Dr. David Alan Gilbert
2023-03-02  8:25 ` [PULL 15/53] hw/timer/hpet: Fix expiration time overflow Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 16/53] docs: vhost-user: replace _SLAVE_ with _BACKEND_ Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 17/53] libvhost-user: Adopt new backend naming Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 18/53] vhost-user: " Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 19/53] vdpa: stop all svq on device deletion Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 20/53] pci/shpc: set attention led to OFF on reset Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 21/53] pci/shpc: change shpc_get_status() return type to uint8_t Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 22/53] pci/shpc: shpc_slot_command(): handle PWRONLY -> ENABLED transition Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 23/53] pci/shpc: more generic handle hot-unplug in shpc_slot_command() Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 24/53] pci/shpc: pass PCIDevice pointer to shpc_slot_command() Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 25/53] pci/shpc: refactor shpc_device_plug_common() Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 26/53] pcie: pcie_cap_slot_write_config(): use correct macro Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 27/53] pcie_regs: drop duplicated indicator value macros Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 28/53] pcie: drop unused PCIExpressIndicator Michael S. Tsirkin
2023-03-02  8:25 ` [PULL 29/53] pcie: pcie_cap_slot_enable_power() use correct helper Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 30/53] pcie: introduce pcie_sltctl_powered_off() helper Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 31/53] pcie: set power indicator to off on reset by default Michael S. Tsirkin
2023-03-02 11:34   ` Vladimir Sementsov-Ogievskiy
2023-03-02 11:42     ` Michael S. Tsirkin
2023-03-03  0:15     ` Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 32/53] vhost: avoid a potential use of an uninitialized variable in vhost_svq_poll() Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 33/53] libvhost-user: check for NULL when allocating a virtqueue element Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 34/53] hw/pci: Trace IRQ routing on PCI topology Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 35/53] chardev/char-socket: set s->listener = NULL in char_socket_finalize Michael S. Tsirkin
2023-03-02 11:49   ` Michael Tokarev
2023-03-03  0:15     ` Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 36/53] memory: Optimize replay of guest mapping Michael S. Tsirkin
2023-04-04 18:00   ` Peter Maydell
2023-04-04 19:13     ` Michael S. Tsirkin
2023-04-04 20:23       ` Peter Maydell
2023-04-04 20:37         ` Peter Xu
2023-04-04 20:38         ` Michael S. Tsirkin
2023-04-06  3:46       ` Duan, Zhenzhong
2023-03-02  8:26 ` [PULL 37/53] intel-iommu: fail MAP notifier without caching mode Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 38/53] intel-iommu: fail DEVIOTLB_UNMAP without dt mode Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 39/53] memory: introduce memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 40/53] smmu: switch to use memory_region_unmap_iommu_notifier_range() Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 41/53] intel-iommu: send UNMAP notifications for domain or global inv desc Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 42/53] MAINTAINERS: Add Fan Ni as Compute eXpress Link QEMU reviewer Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 43/53] hw/mem/cxl_type3: Improve error handling in realize() Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 44/53] hw/pci-bridge/cxl_downstream: Fix type naming mismatch Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 45/53] hw/cxl: set cxl-type3 device type to PCI_CLASS_MEMORY_CXL Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 46/53] hw/cxl: Add CXL_CAPACITY_MULTIPLIER definition Michael S. Tsirkin
2023-03-02  8:26 ` [PULL 47/53] tests/acpi: Allow update of q35/DSDT.cxl Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 48/53] hw/i386/acpi: Drop duplicate _UID entry for CXL root bridge Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 49/53] tests: acpi: Update q35/DSDT.cxl for removed duplicate UID Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 50/53] qemu/bswap: Add const_le64() Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 51/53] qemu/uuid: Add UUID static initializer Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 52/53] hw/cxl/mailbox: Use new UUID network order define for cel_uuid Michael S. Tsirkin
2023-03-02  8:27 ` [PULL 53/53] tests/data/acpi/virt: drop (most) duplicate files Michael S. Tsirkin
2023-03-02 12:16 ` [PULL 00/53] virtio,pc,pci: features, cleanups, fixes Michael Tokarev
2023-03-02 23:23   ` Michael S. Tsirkin
2023-03-03  0:15 ` Michael S. Tsirkin
2023-03-03 17:09   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.