Skip to contentSkip to conversation

pc and misc cleanups and fixes, virtio optimizations

GIT PULL Michael S. Tsirkin 8 participants 75 messages Feb 4, 2016 – Feb 17, 2016

lore
Share & tools
lore
#0 lore raw

The following changes since commit 382d34ff9fcc534db32d54eb82590de7c04f9b33:

Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging (2016-02-03 19:00:33 +0000)

are available in the git repository at:

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

for you to fetch changes up to 32db7f56a0df015362fabd73c2d43dab7196fa64:

acpi: update expected DSDT (2016-02-04 20:54:21 +0200)

----------------------------------------------------------------
pc and misc cleanups and fixes, virtio optimizations

Included here:
Refactoring and bugfix patches in PC/ACPI.
New commands for ipmi.
Virtio optimizations.

----------------------------------------------------------------
Cédric Le Goater (8):
ipmi: replace goto by a return statement
ipmi: replace *_MAXCMD defines
ipmi: cleanup error_report messages
ipmi: fix SDR length value
ipmi: introduce a struct ipmi_sdr_compact
ipmi: add get and set SENSOR_TYPE commands
ipmi: add GET_SYS_RESTART_CAUSE chassis command
ipmi: add ACPI power and GUID commands

David Gibson (1):

      dimm: Correct type of MemoryHotplugState->base

Dr. David Alan Gilbert (1):
Fix virtio migration

Eduardo Habkost (12):
pc: Move PcGuestInfo declaration to top of file
pc: Eliminate struct PcGuestInfoState
pc: Simplify pc_memory_init() signature
pc: Simplify xen_load_linux() signature
acpi: Remove guest_info parameters from functions
acpi: Don't save PcGuestInfo on AcpiBuildState
pc: Remove compat fields from PcGuestInfo
pc: Remove RAM size fields from PcGuestInfo
pc: Remove PcGuestInfo.isapc_ram_fw field
pc: Move PcGuestInfo.fw_cfg to PCMachineState
pc: Move APIC and NUMA data from PcGuestInfo to PCMachineState
pc: Eliminate PcGuestInfo struct

Igor Mammedov (3):
pc: acpi: merge SSDT into DSDT
tests: pc: acpi: drop not needed 'expected SSDT' blobs
tests: pc: acpi: add expected DSDT.bridge blobs and update DSDT blobs

Jason Wang (1):
intel_iommu: large page support

Laszlo Ersek (4):
acpi: take oem_id in build_header(), optionally
acpi: expose oem_id and oem_table_id in build_rsdt()
acpi: add function to extract oem_id and oem_table_id from the user's SLIC
pc: set the OEM fields in the RSDT and the FADT from the SLIC

Laurent Vivier (1):
net: set endianness on all backend devices

Marcel Apfelbaum (2):
hw/pxb: add pxb devices to the bridge category
hw/pci: ensure that only PCI/PCIe bridges can be attached to pxb/pxb-pcie devices

Michael S. Tsirkin (1):
acpi: update expected DSDT

Paolo Bonzini (8):
virtio: move VirtQueueElement at the beginning of the structs
virtio: move allocation to virtqueue_pop/vring_pop
virtio: introduce qemu_get/put_virtqueue_element
virtio: introduce virtqueue_alloc_element
virtio: slim down allocation of VirtQueueElements
vring: slim down allocation of VirtQueueElements
virtio: combine the read of a descriptor
vhost-user-test: use correct ROM to speed up and avoid spurious failures

Roman Kagan (3):
i386/acpi: make floppy controller object dynamic expose floppy drive geometry and CMOS type
i386: populate floppy drive information in DSDT

Stefano Stabellini (1):
fix MSI injection on Xen

Vincenzo Maffione (3):
virtio: cache used_idx in a VirtQueue field
virtio: read avail_idx from VQ only when necessary
virtio: combine write of an entry into used ring

 hw/9pfs/virtio-9p.h                                |   2 +-
 hw/i386/acpi-build.h                               |   2 +-
 hw/i386/intel_iommu_internal.h                     |   6 +-
 include/hw/acpi/acpi.h                             |   7 +
 include/hw/acpi/aml-build.h                        |   5 +-
 include/hw/block/fdc.h                             |   2 +
 include/hw/i386/intel_iommu.h                      |   1 +
 include/hw/i386/pc.h                               |  41 +-
 include/hw/ipmi/ipmi.h                             |  45 +++
 include/hw/mem/pc-dimm.h                           |   2 +-
 include/hw/virtio/dataplane/vring.h                |   2 +-
 include/hw/virtio/virtio-balloon.h                 |   2 +-
 include/hw/virtio/virtio-blk.h                     |   5 +-
 include/hw/virtio/virtio-net.h                     |   2 +-
 include/hw/virtio/virtio-scsi.h                    |  15 +-
 include/hw/virtio/virtio-serial.h                  |   2 +-
 include/hw/virtio/virtio.h                         |  13 +-
 include/hw/xen/xen.h                               |   1 +
 include/migration/vmstate.h                        |  18 +-
 hw/9pfs/9p.c                                       |   2 +-
 hw/9pfs/virtio-9p-device.c                         |  17 +-
 hw/acpi/aml-build.c                                |  14 +-
 hw/acpi/core.c                                     |  16 +
 hw/acpi/nvdimm.c                                   |   4 +-
 hw/arm/virt-acpi-build.c                           |  14 +-
 hw/block/dataplane/virtio-blk.c                    |  11 +-
 hw/block/fdc.c                                     |  11 +
 hw/block/virtio-blk.c                              |  23 +-
 hw/char/virtio-serial-bus.c                        |  78 ++--
 hw/display/virtio-gpu.c                            |  21 +-
 hw/i386/acpi-build.c                               | 430 +++++++++++----------
 hw/i386/intel_iommu.c                              |  76 ++--
 hw/i386/pc.c                                       |  79 ++--
 hw/i386/pc_piix.c                                  |  14 +-
 hw/i386/pc_q35.c                                   |  14 +-
 hw/input/virtio-input.c                            |  24 +-
 hw/ipmi/ipmi_bmc_sim.c                             | 351 ++++++++++-------
 hw/net/vhost_net.c                                 |  23 +-
 hw/net/virtio-net.c                                |  69 ++--
 hw/pci-bridge/pci_expander_bridge.c                |   2 +
 hw/pci/msi.c                                       |   9 +-
 hw/pci/msix.c                                      |  12 +-
 hw/pci/pci.c                                       |   7 +
 hw/scsi/virtio-scsi-dataplane.c                    |  15 +-
 hw/scsi/virtio-scsi.c                              |  26 +-
 hw/virtio/dataplane/vring.c                        |  62 ++-
 hw/virtio/virtio-balloon.c                         |  22 +-
 hw/virtio/virtio-rng.c                             |  10 +-
 hw/virtio/virtio.c                                 | 348 +++++++++++------
 hw/xen/xen_pt_msi.c                                |   4 +-
 tests/vhost-user-test.c                            |   5 +-
 xen-hvm-stub.c                                     |   5 +
 xen-hvm.c                                          |   9 +
 qemu-options.hx                                    |   4 +
 roms/seabios                                       |   2 +-
 tests/acpi-test-data/pc/DSDT                       | Bin 3028 -> 5533 bytes
 .../acpi-test-data/pc/{SSDT.bridge => DSDT.bridge} | Bin 4345 -> 7392 bytes
 tests/acpi-test-data/pc/SSDT                       | Bin 2486 -> 0 bytes
 tests/acpi-test-data/q35/DSDT                      | Bin 7666 -> 8233 bytes
 tests/acpi-test-data/q35/DSDT.bridge               | Bin 0 -> 8250 bytes
 tests/acpi-test-data/q35/SSDT                      | Bin 691 -> 0 bytes
 tests/acpi-test-data/q35/SSDT.bridge               | Bin 708 -> 0 bytes
 62 files changed, 1204 insertions(+), 802 deletions(-)
 rename tests/acpi-test-data/pc/{SSDT.bridge => DSDT.bridge} (57%)
 delete mode 100644 tests/acpi-test-data/pc/SSDT
 create mode 100644 tests/acpi-test-data/q35/DSDT.bridge
 delete mode 100644 tests/acpi-test-data/q35/SSDT
 delete mode 100644 tests/acpi-test-data/q35/SSDT.bridge
#1 lore raw

[Qemu-devel] [PULL 14/49] virtio: combine write of an entry into used ring

From: Vincenzo Maffione <[email protected]>

Fill in an element of the used ring with a single combined access to the guest physical memory, rather than using two separated accesses. This reduces the overhead due to expensive address translation.

Message-Id: <e4a89a767a4a92cbb6bcc551e151487eb36e1722.1450218353.git.v.maffione@gmail.com>

---
 hw/virtio/virtio.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
hw/virtio/virtio.c +12 -13
index 9608358..90f2545 100644
@@ -153,18 +153,15 @@ static inline uint16_t vring_get_used_event(VirtQueue *vq)
     return vring_avail_ring(vq, vq->vring.num);
 }
 
-static inline void vring_used_ring_id(VirtQueue *vq, int i, uint32_t val)
+static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem,
+                                    int i)
 {
     hwaddr pa;
-    pa = vq->vring.used + offsetof(VRingUsed, ring[i].id);
-    virtio_stl_phys(vq->vdev, pa, val);
-}
-
-static inline void vring_used_ring_len(VirtQueue *vq, int i, uint32_t val)
-{
-    hwaddr pa;
-    pa = vq->vring.used + offsetof(VRingUsed, ring[i].len);
-    virtio_stl_phys(vq->vdev, pa, val);
+    virtio_tswap32s(vq->vdev, &uelem->id);
+    virtio_tswap32s(vq->vdev, &uelem->len);
+    pa = vq->vring.used + offsetof(VRingUsed, ring[i]);
+    address_space_write(&address_space_memory, pa, MEMTXATTRS_UNSPECIFIED,
+                       (void *)uelem, sizeof(VRingUsedElem));
 }
 
 static uint16_t vring_used_idx(VirtQueue *vq)
@@ -273,15 +270,17 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem,
 void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
                     unsigned int len, unsigned int idx)
 {
+    VRingUsedElem uelem;
+
     trace_virtqueue_fill(vq, elem, len, idx);
 
     virtqueue_unmap_sg(vq, elem, len);
 
     idx = (idx + vq->used_idx) % vq->vring.num;
 
-    /* Get a pointer to the next entry in the used ring. */
-    vring_used_ring_id(vq, idx, elem->index);
-    vring_used_ring_len(vq, idx, len);
+    uelem.id = elem->index;
+    uelem.len = len;
+    vring_used_write(vq, &uelem, idx);
 }
 
 void virtqueue_flush(VirtQueue *vq, unsigned int count)
Signature · 1 line
MST
#2 lore raw

[Qemu-devel] [PULL 01/49] Fix virtio migration

In reply to Michael S. Tsirkin

From: "Dr. David Alan Gilbert" <[email protected]>

I misunderstood the vmstate macro definition when I reworked the virtio .get/.put.
The VMSTATE_STRUCT_VARRAY_KNOWN, was described as being for "a variable length array (i.e. _type *_field) but we know the length". However it actually specified operation for arrays embedded in the struct (i.e. _type _field[]) since it lacked the VMS_POINTER flag. This caused offset calculation to be completely off, examining and potentially sending random data instead of the VirtQueue content.

Replace the otherwise unused VMSTATE_STRUCT_VARRAY_KNOWN with a VMSTATE_STRUCT_VARRAY_POINTER_KNOWN that includes the VMS_POINTER flag (so now actually doing what it advertises) and use it in the virtio migration code.

Fixes and description as per Sascha's suggestions/debug.

Fixes 50e5ae4dc3e4f21e874512f9e87b93b5472d26e0
Fixes 2cf0148674430b6693c60d42b7eef721bfa9509f
---
 include/migration/vmstate.h | 18 +++++++++---------
 hw/virtio/virtio.c          |  8 ++++----
 2 files changed, 13 insertions(+), 13 deletions(-)
include/migration/vmstate.h +9 -9
index a4b81bb..7246f29 100644
@@ -386,26 +386,26 @@ extern const VMStateInfo vmstate_info_bitmap;
     .offset       = vmstate_offset_array(_state, _field, _type, _num),\
 }
 
-/* a variable length array (i.e. _type *_field) but we know the
- * length
- */
-#define VMSTATE_STRUCT_VARRAY_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
+#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
     .name       = (stringify(_field)),                               \
-    .num          = (_num),                                          \
+    .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
     .version_id = (_version),                                        \
     .vmsd       = &(_vmsd),                                          \
     .size       = sizeof(_type),                                     \
-    .flags      = VMS_STRUCT|VMS_ARRAY,                              \
+    .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
     .offset     = offsetof(_state, _field),                          \
 }
 
-#define VMSTATE_STRUCT_VARRAY_UINT8(_field, _state, _field_num, _version, _vmsd, _type) { \
+/* a variable length array (i.e. _type *_field) but we know the
+ * length
+ */
+#define VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(_field, _state, _num, _version, _vmsd, _type) { \
     .name       = (stringify(_field)),                               \
-    .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
+    .num          = (_num),                                          \
     .version_id = (_version),                                        \
     .vmsd       = &(_vmsd),                                          \
     .size       = sizeof(_type),                                     \
-    .flags      = VMS_STRUCT|VMS_VARRAY_UINT8,                       \
+    .flags      = VMS_STRUCT|VMS_ARRAY|VMS_POINTER,                  \
     .offset     = offsetof(_state, _field),                          \
 }
 
hw/virtio/virtio.c +4 -4
index 63a7b6d..0603793 100644
@@ -1143,8 +1143,8 @@ static const VMStateDescription vmstate_virtio_virtqueues = {
     .minimum_version_id = 1,
     .needed = &virtio_virtqueue_needed,
     .fields = (VMStateField[]) {
-        VMSTATE_STRUCT_VARRAY_KNOWN(vq, struct VirtIODevice, VIRTIO_QUEUE_MAX,
-                      0, vmstate_virtqueue, VirtQueue),
+        VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(vq, struct VirtIODevice,
+                      VIRTIO_QUEUE_MAX, 0, vmstate_virtqueue, VirtQueue),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -1165,8 +1165,8 @@ static const VMStateDescription vmstate_virtio_ringsize = {
     .minimum_version_id = 1,
     .needed = &virtio_ringsize_needed,
     .fields = (VMStateField[]) {
-        VMSTATE_STRUCT_VARRAY_KNOWN(vq, struct VirtIODevice, VIRTIO_QUEUE_MAX,
-                      0, vmstate_ringsize, VirtQueue),
+        VMSTATE_STRUCT_VARRAY_POINTER_KNOWN(vq, struct VirtIODevice,
+                      VIRTIO_QUEUE_MAX, 0, vmstate_ringsize, VirtQueue),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
MST
#3 lore raw

[Qemu-devel] [PULL 02/49] pc: acpi: merge SSDT into DSDT

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

Since both tables are built dynamically now, there is no point in keeping ASL in them in separate tables.
So do the same as we do for ARM where we have only DSDT table, i.e. move SSDT ASL into DSDT and drop SSDT altogether.
This patch doesn't change moved SSDT ASL in any way, but it opens a way to relatively independently simplify generated ASL on per device/subsystem basis in followup series.
It also simplifies bios-tables-test where expected SSDT blobs could be dropped and only DSDT ones have to be maintained.

---
 hw/i386/acpi-build.c | 246 +++++++++++++++++++++++----------------------------
 1 file changed, 111 insertions(+), 135 deletions(-)
hw/i386/acpi-build.c +111 -135
index 739cfa3..2028ed7 100644
@@ -1935,24 +1935,113 @@ static Aml *build_q35_osc_method(void)
 }
 
 static void
-build_ssdt(GArray *table_data, GArray *linker,
+build_dsdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
            PcPciInfo *pci, PcGuestInfo *guest_info)
 {
+    CrsRangeEntry *entry;
+    Aml *dsdt, *sb_scope, *scope, *dev, *method, *field, *pkg, *crs;
+    GPtrArray *mem_ranges = g_ptr_array_new_with_free_func(crs_range_free);
+    GPtrArray *io_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     MachineState *machine = MACHINE(qdev_get_machine());
     uint32_t nr_mem = machine->ram_slots;
-    Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field;
-    PCIBus *bus = NULL;
-    GPtrArray *io_ranges = g_ptr_array_new_with_free_func(crs_range_free);
-    GPtrArray *mem_ranges = g_ptr_array_new_with_free_func(crs_range_free);
-    CrsRangeEntry *entry;
     int root_bus_limit = 0xFF;
+    PCIBus *bus = NULL;
     int i;
 
-    ssdt = init_aml_allocator();
+    dsdt = init_aml_allocator();
 
     /* Reserve space for header */
-    acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
+    acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
+
+    build_dbg_aml(dsdt);
+    if (misc->is_piix4) {
+        sb_scope = aml_scope("_SB");
+        dev = aml_device("PCI0");
+        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
+        aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
+        aml_append(dev, aml_name_decl("_UID", aml_int(1)));
+        aml_append(sb_scope, dev);
+        aml_append(dsdt, sb_scope);
+
+        build_hpet_aml(dsdt);
+        build_piix4_pm(dsdt);
+        build_piix4_isa_bridge(dsdt);
+        build_isa_devices_aml(dsdt);
+        build_piix4_pci_hotplug(dsdt);
+        build_piix4_pci0_int(dsdt);
+    } else {
+        sb_scope = aml_scope("_SB");
+        aml_append(sb_scope,
+            aml_operation_region("PCST", AML_SYSTEM_IO, 0xae00, 0x0c));
+        aml_append(sb_scope,
+            aml_operation_region("PCSB", AML_SYSTEM_IO, 0xae0c, 0x01));
+        field = aml_field("PCSB", AML_ANY_ACC, AML_NOLOCK, AML_WRITE_AS_ZEROS);
+        aml_append(field, aml_named_field("PCIB", 8));
+        aml_append(sb_scope, field);
+        aml_append(dsdt, sb_scope);
+
+        sb_scope = aml_scope("_SB");
+        dev = aml_device("PCI0");
+        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A08")));
+        aml_append(dev, aml_name_decl("_CID", aml_eisaid("PNP0A03")));
+        aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
+        aml_append(dev, aml_name_decl("_UID", aml_int(1)));
+        aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
+        aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
+        aml_append(dev, build_q35_osc_method());
+        aml_append(sb_scope, dev);
+        aml_append(dsdt, sb_scope);
+
+        build_hpet_aml(dsdt);
+        build_q35_isa_bridge(dsdt);
+        build_isa_devices_aml(dsdt);
+        build_q35_pci0_int(dsdt);
+    }
+
+    build_cpu_hotplug_aml(dsdt);
+    build_memory_hotplug_aml(dsdt, nr_mem, pm->mem_hp_io_base,
+                             pm->mem_hp_io_len);
+
+    scope =  aml_scope("_GPE");
+    {
+        aml_append(scope, aml_name_decl("_HID", aml_string("ACPI0006")));
+
+        aml_append(scope, aml_method("_L00", 0, AML_NOTSERIALIZED));
+
+        if (misc->is_piix4) {
+            method = aml_method("_E01", 0, AML_NOTSERIALIZED);
+            aml_append(method,
+                aml_acquire(aml_name("\\_SB.PCI0.BLCK"), 0xFFFF));
+            aml_append(method, aml_call0("\\_SB.PCI0.PCNT"));
+            aml_append(method, aml_release(aml_name("\\_SB.PCI0.BLCK")));
+            aml_append(scope, method);
+        } else {
+            aml_append(scope, aml_method("_L01", 0, AML_NOTSERIALIZED));
+        }
+
+        method = aml_method("_E02", 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_call0("\\_SB." CPU_SCAN_METHOD));
+        aml_append(scope, method);
+
+        method = aml_method("_E03", 0, AML_NOTSERIALIZED);
+        aml_append(method, aml_call0(MEMORY_HOTPLUG_HANDLER_PATH));
+        aml_append(scope, method);
+
+        aml_append(scope, aml_method("_L04", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L05", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L06", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L07", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L08", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L09", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0A", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0B", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0C", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0D", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0E", 0, AML_NOTSERIALIZED));
+        aml_append(scope, aml_method("_L0F", 0, AML_NOTSERIALIZED));
+    }
+    aml_append(dsdt, scope);
 
     bus = PC_MACHINE(machine)->bus;
     if (bus) {
@@ -1984,7 +2073,7 @@ build_ssdt(GArray *table_data, GArray *linker,
                             io_ranges, mem_ranges);
             aml_append(dev, aml_name_decl("_CRS", crs));
             aml_append(scope, dev);
-            aml_append(ssdt, scope);
+            aml_append(dsdt, scope);
         }
     }
 
@@ -2068,7 +2157,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(dev, aml_name_decl("_CRS", crs));
         aml_append(scope, dev);
     }
-    aml_append(ssdt, scope);
+    aml_append(dsdt, scope);
 
     /*  create S3_ / S4_ / S5_ packages if necessary */
     scope = aml_scope("\\");
@@ -2097,7 +2186,7 @@ build_ssdt(GArray *table_data, GArray *linker,
     aml_append(pkg, aml_int(0)); /* reserved */
     aml_append(pkg, aml_int(0)); /* reserved */
     aml_append(scope, aml_name_decl("_S5", pkg));
-    aml_append(ssdt, scope);
+    aml_append(dsdt, scope);
 
     if (misc->applesmc_io_base) {
         scope = aml_scope("\\_SB.PCI0.ISA");
@@ -2116,7 +2205,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(dev, aml_name_decl("_CRS", crs));
 
         aml_append(scope, dev);
-        aml_append(ssdt, scope);
+        aml_append(dsdt, scope);
     }
 
     if (misc->pvpanic_port) {
@@ -2150,7 +2239,7 @@ build_ssdt(GArray *table_data, GArray *linker,
         aml_append(dev, method);
 
         aml_append(scope, dev);
-        aml_append(ssdt, scope);
+        aml_append(dsdt, scope);
     }
 
     sb_scope = aml_scope("\\_SB");
@@ -2189,14 +2278,14 @@ build_ssdt(GArray *table_data, GArray *linker,
                 aml_append(sb_scope, scope);
             }
         }
-        aml_append(ssdt, sb_scope);
+        aml_append(dsdt, sb_scope);
     }
 
     /* copy AML table into ACPI tables blob and patch header there */
-    g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
+    g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
     build_header(linker, table_data,
-        (void *)(table_data->data + table_data->len - ssdt->buf->len),
-        "SSDT", ssdt->buf->len, 1, NULL);
+        (void *)(table_data->data + table_data->len - dsdt->buf->len),
+        "DSDT", dsdt->buf->len, 1, NULL);
     free_aml_allocator();
 }
 
@@ -2422,116 +2511,6 @@ build_dmar_q35(GArray *table_data, GArray *linker)
                  "DMAR", table_data->len - dmar_start, 1, NULL);
 }
 
-static void
-build_dsdt(GArray *table_data, GArray *linker,
-           AcpiPmInfo *pm, AcpiMiscInfo *misc)
-{
-    Aml *dsdt, *sb_scope, *scope, *dev, *method, *field;
-    MachineState *machine = MACHINE(qdev_get_machine());
-    uint32_t nr_mem = machine->ram_slots;
-
-    dsdt = init_aml_allocator();
-
-    /* Reserve space for header */
-    acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
-
-    build_dbg_aml(dsdt);
-    if (misc->is_piix4) {
-        sb_scope = aml_scope("_SB");
-        dev = aml_device("PCI0");
-        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
-        aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
-        aml_append(dev, aml_name_decl("_UID", aml_int(1)));
-        aml_append(sb_scope, dev);
-        aml_append(dsdt, sb_scope);
-
-        build_hpet_aml(dsdt);
-        build_piix4_pm(dsdt);
-        build_piix4_isa_bridge(dsdt);
-        build_isa_devices_aml(dsdt);
-        build_piix4_pci_hotplug(dsdt);
-        build_piix4_pci0_int(dsdt);
-    } else {
-        sb_scope = aml_scope("_SB");
-        aml_append(sb_scope,
-            aml_operation_region("PCST", AML_SYSTEM_IO, 0xae00, 0x0c));
-        aml_append(sb_scope,
-            aml_operation_region("PCSB", AML_SYSTEM_IO, 0xae0c, 0x01));
-        field = aml_field("PCSB", AML_ANY_ACC, AML_NOLOCK, AML_WRITE_AS_ZEROS);
-        aml_append(field, aml_named_field("PCIB", 8));
-        aml_append(sb_scope, field);
-        aml_append(dsdt, sb_scope);
-
-        sb_scope = aml_scope("_SB");
-        dev = aml_device("PCI0");
-        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A08")));
-        aml_append(dev, aml_name_decl("_CID", aml_eisaid("PNP0A03")));
-        aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
-        aml_append(dev, aml_name_decl("_UID", aml_int(1)));
-        aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
-        aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
-        aml_append(dev, build_q35_osc_method());
-        aml_append(sb_scope, dev);
-        aml_append(dsdt, sb_scope);
-
-        build_hpet_aml(dsdt);
-        build_q35_isa_bridge(dsdt);
-        build_isa_devices_aml(dsdt);
-        build_q35_pci0_int(dsdt);
-    }
-
-    build_cpu_hotplug_aml(dsdt);
-    build_memory_hotplug_aml(dsdt, nr_mem, pm->mem_hp_io_base,
-                             pm->mem_hp_io_len);
-
-    scope =  aml_scope("_GPE");
-    {
-        aml_append(scope, aml_name_decl("_HID", aml_string("ACPI0006")));
-
-        aml_append(scope, aml_method("_L00", 0, AML_NOTSERIALIZED));
-
-        if (misc->is_piix4) {
-            method = aml_method("_E01", 0, AML_NOTSERIALIZED);
-            aml_append(method,
-                aml_acquire(aml_name("\\_SB.PCI0.BLCK"), 0xFFFF));
-            aml_append(method, aml_call0("\\_SB.PCI0.PCNT"));
-            aml_append(method, aml_release(aml_name("\\_SB.PCI0.BLCK")));
-            aml_append(scope, method);
-        } else {
-            aml_append(scope, aml_method("_L01", 0, AML_NOTSERIALIZED));
-        }
-
-        method = aml_method("_E02", 0, AML_NOTSERIALIZED);
-        aml_append(method, aml_call0("\\_SB." CPU_SCAN_METHOD));
-        aml_append(scope, method);
-
-        method = aml_method("_E03", 0, AML_NOTSERIALIZED);
-        aml_append(method, aml_call0(MEMORY_HOTPLUG_HANDLER_PATH));
-        aml_append(scope, method);
-
-        aml_append(scope, aml_method("_L04", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L05", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L06", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L07", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L08", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L09", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0A", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0B", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0C", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0D", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0E", 0, AML_NOTSERIALIZED));
-        aml_append(scope, aml_method("_L0F", 0, AML_NOTSERIALIZED));
-    }
-    aml_append(dsdt, scope);
-
-    /* copy AML table into ACPI tables blob and patch header there */
-    g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
-    build_header(linker, table_data,
-        (void *)(table_data->data + table_data->len - dsdt->buf->len),
-        "DSDT", dsdt->buf->len, 1, NULL);
-    free_aml_allocator();
-}
-
 static GArray *
 build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
 {
@@ -2611,7 +2590,7 @@ static
 void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 {
     GArray *table_offsets;
-    unsigned facs, ssdt, dsdt, rsdt;
+    unsigned facs, dsdt, rsdt, fadt;
     AcpiCpuInfo cpu;
     AcpiPmInfo pm;
     AcpiMiscInfo misc;
@@ -2644,7 +2623,8 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
 
     /* DSDT is pointed to by FADT */
     dsdt = tables_blob->len;
-    build_dsdt(tables_blob, tables->linker, &pm, &misc);
+    build_dsdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
+               guest_info);
 
     /* Count the size of the DSDT and SSDT, we will need it for legacy
      * sizing of ACPI tables.
@@ -2652,14 +2632,10 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     aml_len += tables_blob->len - dsdt;
 
     /* ACPI tables pointed to by RSDT */
+    fadt = tables_blob->len;
     acpi_add_table(table_offsets, tables_blob);
     build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
-
-    ssdt = tables_blob->len;
-    acpi_add_table(table_offsets, tables_blob);
-    build_ssdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
-               guest_info);
-    aml_len += tables_blob->len - ssdt;
+    aml_len += tables_blob->len - fadt;
 
     acpi_add_table(table_offsets, tables_blob);
     build_madt(tables_blob, tables->linker, &cpu, guest_info);
Signature · 1 line
MST
#4 lore raw

[Qemu-devel] [PULL 03/49] tests: pc: acpi: drop not needed 'expected SSDT' blobs

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

---
 tests/acpi-test-data/pc/SSDT         | Bin 2486 -> 0 bytes
 tests/acpi-test-data/pc/SSDT.bridge  | Bin 4345 -> 0 bytes
 tests/acpi-test-data/q35/SSDT        | Bin 691 -> 0 bytes
 tests/acpi-test-data/q35/SSDT.bridge | Bin 708 -> 0 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 tests/acpi-test-data/pc/SSDT
 delete mode 100644 tests/acpi-test-data/pc/SSDT.bridge
 delete mode 100644 tests/acpi-test-data/q35/SSDT
 delete mode 100644 tests/acpi-test-data/q35/SSDT.bridge
tests/acpi-test-data/pc/SSDT deleted binary +0 -0
deleted file mode 100644
index 210d6a71e58aa34ce8e94121d25bcf58c3bd503c..0000000000000000000000000000000000000000
GIT binary patch
tests/acpi-test-data/pc/SSDT.bridge deleted binary +0 -0
deleted file mode 100644
index 6e6660b1fbe0bdb7fe0b257cb53c31fa9bb21a14..0000000000000000000000000000000000000000
GIT binary patch
tests/acpi-test-data/q35/SSDT deleted binary +0 -0
deleted file mode 100644
index 0970c67ddb1456707c0111f7e5e659ef385af408..0000000000000000000000000000000000000000
GIT binary patch
tests/acpi-test-data/q35/SSDT.bridge deleted binary +0 -0
deleted file mode 100644
index a77868861754ce0b3333b2b7bc8091c03a53754d..0000000000000000000000000000000000000000
GIT binary patch
Signature · 1 line
MST
#5 lore raw

[Qemu-devel] [PULL 04/49] tests: pc: acpi: add expected DSDT.bridge blobs and update DSDT blobs

In reply to Michael S. Tsirkin

From: Igor Mammedov <[email protected]>

---
 tests/acpi-test-data/pc/DSDT         | Bin 3028 -> 5478 bytes
 tests/acpi-test-data/pc/DSDT.bridge  | Bin 0 -> 7337 bytes
 tests/acpi-test-data/q35/DSDT        | Bin 7666 -> 8321 bytes
 tests/acpi-test-data/q35/DSDT.bridge | Bin 0 -> 8338 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/DSDT.bridge
 create mode 100644 tests/acpi-test-data/q35/DSDT.bridge
tests/acpi-test-data/pc/DSDT binary +0 -0
index c658203db94a7e7db7c36fde99a7075a8d75498d..ec0e642b06967d3ec4d7a7d252b82b916f37a5e0 100644
GIT binary patch
tests/acpi-test-data/pc/DSDT.bridge new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7b1c14b529f9f63fc3731c02225ce37c5cfbc0db
GIT binary patch
tests/acpi-test-data/q35/DSDT binary +0 -0
index 4723e5954dccb00995ccaf521b7daf6bf15cf1d4..b492f04b8866ae82eaded81aa0ea2d3a4969dc5c 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.bridge new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..3b72e250fa866ec34c315450643025e03c8c8cab
GIT binary patch
Signature · 1 line
MST
#6 lore raw

[Qemu-devel] [PULL 05/49] virtio: move VirtQueueElement at the beginning of the structs

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

The next patch will make virtqueue_pop/vring_pop allocate memory for the VirtQueueElement. In some cases (blk, scsi, gpu) the device wants to extend VirtQueueElement with device-specific fields and, until now, the place of the VirtQueueElement within the containing struct didn't matter. When allocating the entire block in virtqueue_pop/vring_pop, however, the containing struct must basically be a "subclass" of VirtQueueElement, with the VirtQueueElement as the first field. Make that the case for blk and scsi; gpu is already doing it.

---
 include/hw/virtio/virtio-blk.h  |  2 +-
 include/hw/virtio/virtio-scsi.h | 13 ++++++-------
 hw/scsi/virtio-scsi.c           |  3 +--
 3 files changed, 8 insertions(+), 10 deletions(-)
include/hw/virtio/virtio-blk.h +1 -1
index ae11a63..403ab86 100644
@@ -60,9 +60,9 @@ typedef struct VirtIOBlock {
 } VirtIOBlock;
 
 typedef struct VirtIOBlockReq {
+    VirtQueueElement elem;
     int64_t sector_num;
     VirtIOBlock *dev;
-    VirtQueueElement elem;
     struct virtio_blk_inhdr *in;
     struct virtio_blk_outhdr out;
     QEMUIOVector qiov;
include/hw/virtio/virtio-scsi.h +6 -7
index 0394eb2..eb9d25b 100644
@@ -112,18 +112,17 @@ typedef struct VirtIOSCSI {
 } VirtIOSCSI;
 
 typedef struct VirtIOSCSIReq {
+    /* Note:
+     * - fields up to resp_iov are initialized by virtio_scsi_init_req;
+     * - fields starting at vring are zeroed by virtio_scsi_init_req.
+     * */
+    VirtQueueElement elem;
+
     VirtIOSCSI *dev;
     VirtQueue *vq;
     QEMUSGList qsgl;
     QEMUIOVector resp_iov;
 
-    /* Note:
-     * - fields before elem are initialized by virtio_scsi_init_req;
-     * - elem is uninitialized at the time of allocation.
-     * - fields after elem are zeroed by virtio_scsi_init_req.
-     * */
-
-    VirtQueueElement elem;
     /* Set by dataplane code. */
     VirtIOSCSIVring *vring;
 
hw/scsi/virtio-scsi.c +1 -2
index 1500c42..7fdf6ad 100644
@@ -45,8 +45,7 @@ VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
 {
     VirtIOSCSIReq *req;
     VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
-    const size_t zero_skip = offsetof(VirtIOSCSIReq, elem)
-                             + sizeof(VirtQueueElement);
+    const size_t zero_skip = offsetof(VirtIOSCSIReq, vring);
 
     req = g_malloc(sizeof(*req) + vs->cdb_size);
     req->vq = vq;
Signature · 1 line
MST
#7 lore raw

[Qemu-devel] [PULL 07/49] virtio: introduce qemu_get/put_virtqueue_element

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

Move allocation to virtio functions also when loading/saving a VirtQueueElement. This will also let the load/save functions keep backwards compatibility when the VirtQueueElement layout is changed.

---
 include/hw/virtio/virtio.h  |  2 ++
 hw/block/virtio-blk.c       | 10 +++-------
 hw/char/virtio-serial-bus.c | 10 +++-------
 hw/scsi/virtio-scsi.c       |  7 ++-----
 hw/virtio/virtio.c          | 13 +++++++++++++
 5 files changed, 23 insertions(+), 19 deletions(-)
include/hw/virtio/virtio.h +2 -0
index 21fda17..44da9a8 100644
@@ -153,6 +153,8 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
 
 void virtqueue_map(VirtQueueElement *elem);
 void *virtqueue_pop(VirtQueue *vq, size_t sz);
+void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz);
+void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem);
 int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
                           unsigned int out_bytes);
 void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
hw/block/virtio-blk.c +3 -7
index bf70b52..c427698 100644
@@ -808,8 +808,7 @@ static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
 
     while (req) {
         qemu_put_sbyte(f, 1);
-        qemu_put_buffer(f, (unsigned char *)&req->elem,
-                        sizeof(VirtQueueElement));
+        qemu_put_virtqueue_element(f, &req->elem);
         req = req->next;
     }
     qemu_put_sbyte(f, 0);
@@ -832,14 +831,11 @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
     VirtIOBlock *s = VIRTIO_BLK(vdev);
 
     while (qemu_get_sbyte(f)) {
-        VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
+        VirtIOBlockReq *req;
+        req = qemu_get_virtqueue_element(f, sizeof(VirtIOBlockReq));
         virtio_blk_init_request(s, req);
-        qemu_get_buffer(f, (unsigned char *)&req->elem,
-                        sizeof(VirtQueueElement));
         req->next = s->rq;
         s->rq = req;
-
-        virtqueue_map(&req->elem);
     }
 
     return 0;
hw/char/virtio-serial-bus.c +3 -7
index cf3d12b..99cb683 100644
@@ -646,9 +646,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
         if (elem_popped) {
             qemu_put_be32s(f, &port->iov_idx);
             qemu_put_be64s(f, &port->iov_offset);
-
-            qemu_put_buffer(f, (unsigned char *)port->elem,
-                            sizeof(VirtQueueElement));
+            qemu_put_virtqueue_element(f, port->elem);
         }
     }
 }
@@ -723,10 +721,8 @@ static int fetch_active_ports_list(QEMUFile *f, int version_id,
                 qemu_get_be32s(f, &port->iov_idx);
                 qemu_get_be64s(f, &port->iov_offset);
 
-                port->elem = g_new(VirtQueueElement, 1);
-                qemu_get_buffer(f, (unsigned char *)port->elem,
-                                sizeof(VirtQueueElement));
-                virtqueue_map(port->elem);
+                port->elem =
+                    qemu_get_virtqueue_element(f, sizeof(VirtQueueElement));
 
                 /*
                  *  Port was throttled on source machine.  Let's
hw/scsi/virtio-scsi.c +2 -5
index 50a3cb2..5b29bac 100644
@@ -189,7 +189,7 @@ static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq)
 
     assert(n < vs->conf.num_queues);
     qemu_put_be32s(f, &n);
-    qemu_put_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
+    qemu_put_virtqueue_element(f, &req->elem);
 }
 
 static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
@@ -202,12 +202,9 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
 
     qemu_get_be32s(f, &n);
     assert(n < vs->conf.num_queues);
-    req = g_malloc(sizeof(VirtIOSCSIReq) + vs->cdb_size);
-    qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
+    req = qemu_get_virtqueue_element(f, sizeof(VirtIOSCSIReq) + vs->cdb_size);
     virtio_scsi_init_req(s, vs->cmd_vqs[n], req);
 
-    virtqueue_map(&req->elem);
-
     if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size,
                               sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) {
         error_report("invalid SCSI request migration data");
hw/virtio/virtio.c +13 -0
index 229a092..28fa7fe 100644
@@ -576,6 +576,19 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     return elem;
 }
 
+void *qemu_get_virtqueue_element(QEMUFile *f, size_t sz)
+{
+    VirtQueueElement *elem = g_malloc(sz);
+    qemu_get_buffer(f, (uint8_t *)elem, sizeof(VirtQueueElement));
+    virtqueue_map(elem);
+    return elem;
+}
+
+void qemu_put_virtqueue_element(QEMUFile *f, VirtQueueElement *elem)
+{
+    qemu_put_buffer(f, (uint8_t *)elem, sizeof(VirtQueueElement));
+}
+
 /* virtio device */
 static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
 {
Signature · 1 line
MST
#8 lore raw

[Qemu-devel] [PULL 06/49] virtio: move allocation to virtqueue_pop/vring_pop

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

The return code of virtqueue_pop/vring_pop is unused except to check for errors or 0. We can thus easily move allocation inside the functions and just return a pointer to the VirtQueueElement.

The advantage is that we will be able to allocate only the space that is needed for the actual size of the s/g list instead of the full VIRTQUEUE_MAX_SIZE items. Currently VirtQueueElement takes about 48K of memory, and this kind of allocation puts a lot of stress on malloc. By cutting the size by two or three orders of magnitude, malloc can use much more efficient algorithms.

The patch is pretty large, but changes to each device are testable more or less independently. Splitting it would mostly add churn.

---
 hw/9pfs/virtio-9p.h                 |  2 +-
 include/hw/virtio/dataplane/vring.h |  2 +-
 include/hw/virtio/virtio-balloon.h  |  2 +-
 include/hw/virtio/virtio-blk.h      |  3 +-
 include/hw/virtio/virtio-net.h      |  2 +-
 include/hw/virtio/virtio-scsi.h     |  2 +-
 include/hw/virtio/virtio-serial.h   |  2 +-
 include/hw/virtio/virtio.h          |  2 +-
 hw/9pfs/9p.c                        |  2 +-
 hw/9pfs/virtio-9p-device.c          | 17 ++++----
 hw/block/dataplane/virtio-blk.c     | 11 +++--
 hw/block/virtio-blk.c               | 15 +++----
 hw/char/virtio-serial-bus.c         | 80 +++++++++++++++++++++++--------------
 hw/display/virtio-gpu.c             | 21 ++++++----
 hw/input/virtio-input.c             | 24 +++++++----
 hw/net/virtio-net.c                 | 69 ++++++++++++++++++++------------
 hw/scsi/virtio-scsi-dataplane.c     | 15 +++----
 hw/scsi/virtio-scsi.c               | 18 ++++-----
 hw/virtio/dataplane/vring.c         | 18 +++++----
 hw/virtio/virtio-balloon.c          | 22 ++++++----
 hw/virtio/virtio-rng.c              | 10 +++--
 hw/virtio/virtio.c                  | 12 ++++--
 roms/seabios                        |  2 +-
 23 files changed, 210 insertions(+), 143 deletions(-)
hw/9pfs/virtio-9p.h +1 -1
index 1cdf0a2..7f6d885 100644
@@ -11,7 +11,7 @@ typedef struct V9fsVirtioState
     VirtQueue *vq;
     size_t config_size;
     V9fsPDU pdus[MAX_REQ];
-    VirtQueueElement elems[MAX_REQ];
+    VirtQueueElement *elems[MAX_REQ];
     V9fsState state;
 } V9fsVirtioState;
 
include/hw/virtio/dataplane/vring.h +1 -1
index a596e4c..e80985e 100644
@@ -44,7 +44,7 @@ void vring_teardown(Vring *vring, VirtIODevice *vdev, int n);
 void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring);
 bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
-int vring_pop(VirtIODevice *vdev, Vring *vring, VirtQueueElement *elem);
+void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz);
 void vring_push(VirtIODevice *vdev, Vring *vring, VirtQueueElement *elem,
                 int len);
 
include/hw/virtio/virtio-balloon.h +1 -1
index 09c2ce4..35f62ac 100644
@@ -37,7 +37,7 @@ typedef struct VirtIOBalloon {
     uint32_t num_pages;
     uint32_t actual;
     uint64_t stats[VIRTIO_BALLOON_S_NR];
-    VirtQueueElement stats_vq_elem;
+    VirtQueueElement *stats_vq_elem;
     size_t stats_vq_offset;
     QEMUTimer *stats_timer;
     int64_t stats_last_update;
include/hw/virtio/virtio-blk.h +1 -2
index 403ab86..199bb0e 100644
@@ -80,8 +80,7 @@ typedef struct MultiReqBuffer {
     bool is_write;
 } MultiReqBuffer;
 
-VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s);
-
+void virtio_blk_init_request(VirtIOBlock *s, VirtIOBlockReq *req);
 void virtio_blk_free_request(VirtIOBlockReq *req);
 
 void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb);
include/hw/virtio/virtio-net.h +1 -1
index f3cc25f..2ce3b03 100644
@@ -47,7 +47,7 @@ typedef struct VirtIONetQueue {
     QEMUBH *tx_bh;
     int tx_waiting;
     struct {
-        VirtQueueElement elem;
+        VirtQueueElement *elem;
     } async_tx;
     struct VirtIONet *n;
 } VirtIONetQueue;
include/hw/virtio/virtio-scsi.h +1 -1
index eb9d25b..a8029aa 100644
@@ -160,7 +160,7 @@ void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
 void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req);
 bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req);
 void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req);
-VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq);
+void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req);
 void virtio_scsi_free_req(VirtIOSCSIReq *req);
 void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
                             uint32_t event, uint32_t reason);
include/hw/virtio/virtio-serial.h +1 -1
index 527d0bf..12a55a1 100644
@@ -122,7 +122,7 @@ struct VirtIOSerialPort {
      * element popped and continue consuming it once the backend
      * becomes writable again.
      */
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
 
     /*
      * The index and the offset into the iov buffer that was popped in
include/hw/virtio/virtio.h +1 -1
index 205fadf..21fda17 100644
@@ -152,7 +152,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
                     unsigned int len, unsigned int idx);
 
 void virtqueue_map(VirtQueueElement *elem);
-int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
+void *virtqueue_pop(VirtQueue *vq, size_t sz);
 int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
                           unsigned int out_bytes);
 void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
hw/9pfs/9p.c +1 -1
index 15fb0ab..db5f478 100644
@@ -1587,7 +1587,7 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
     int read_count;
     int64_t xattr_len;
     V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
-    VirtQueueElement *elem = &v->elems[pdu->idx];
+    VirtQueueElement *elem = v->elems[pdu->idx];
 
     xattr_len = fidp->fs.xattr.len;
     read_count = xattr_len - off;
hw/9pfs/virtio-9p-device.c +10 -7
index c5f7b92..a38850e 100644
@@ -26,10 +26,12 @@ void virtio_9p_push_and_notify(V9fsPDU *pdu)
 {
     V9fsState *s = pdu->s;
     V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
-    VirtQueueElement *elem = &v->elems[pdu->idx];
+    VirtQueueElement *elem = v->elems[pdu->idx];
 
     /* push onto queue and notify */
     virtqueue_push(v->vq, elem, pdu->size);
+    g_free(elem);
+    v->elems[pdu->idx] = NULL;
 
     /* FIXME: we should batch these completions */
     virtio_notify(VIRTIO_DEVICE(v), v->vq);
@@ -48,10 +50,10 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
             uint8_t id;
             uint16_t tag_le;
         } QEMU_PACKED out;
-        VirtQueueElement *elem = &v->elems[pdu->idx];
+        VirtQueueElement *elem;
 
-        len = virtqueue_pop(vq, elem);
-        if (!len) {
+        elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+        if (!elem) {
             pdu_free(pdu);
             break;
         }
@@ -59,6 +61,7 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq)
         BUG_ON(elem->out_num == 0 || elem->in_num == 0);
         QEMU_BUILD_BUG_ON(sizeof out != 7);
 
+        v->elems[pdu->idx] = elem;
         len = iov_to_buf(elem->out_sg, elem->out_num, 0,
                          &out, sizeof out);
         BUG_ON(len != sizeof out);
@@ -141,7 +144,7 @@ ssize_t virtio_pdu_vmarshal(V9fsPDU *pdu, size_t offset,
 {
     V9fsState *s = pdu->s;
     V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
-    VirtQueueElement *elem = &v->elems[pdu->idx];
+    VirtQueueElement *elem = v->elems[pdu->idx];
 
     return v9fs_iov_vmarshal(elem->in_sg, elem->in_num, offset, 1, fmt, ap);
 }
@@ -151,7 +154,7 @@ ssize_t virtio_pdu_vunmarshal(V9fsPDU *pdu, size_t offset,
 {
     V9fsState *s = pdu->s;
     V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
-    VirtQueueElement *elem = &v->elems[pdu->idx];
+    VirtQueueElement *elem = v->elems[pdu->idx];
 
     return v9fs_iov_vunmarshal(elem->out_sg, elem->out_num, offset, 1, fmt, ap);
 }
@@ -161,7 +164,7 @@ void virtio_init_iov_from_pdu(V9fsPDU *pdu, struct iovec **piov,
 {
     V9fsState *s = pdu->s;
     V9fsVirtioState *v = container_of(s, V9fsVirtioState, state);
-    VirtQueueElement *elem = &v->elems[pdu->idx];
+    VirtQueueElement *elem = v->elems[pdu->idx];
 
     if (is_write) {
         *piov = elem->out_sg;
hw/block/dataplane/virtio-blk.c +5 -6
index ee0c4d4..0d99781 100644
@@ -100,20 +100,19 @@ static void handle_notify(EventNotifier *e)
     blk_io_plug(s->conf->conf.blk);
     for (;;) {
         MultiReqBuffer mrb = {};
-        int ret;
 
         /* Disable guest->host notifies to avoid unnecessary vmexits */
         vring_disable_notification(s->vdev, &s->vring);
 
         for (;;) {
-            VirtIOBlockReq *req = virtio_blk_alloc_request(vblk);
+            VirtIOBlockReq *req = vring_pop(s->vdev, &s->vring,
+                                            sizeof(VirtIOBlockReq));
 
-            ret = vring_pop(s->vdev, &s->vring, &req->elem);
-            if (ret < 0) {
-                virtio_blk_free_request(req);
+            if (req == NULL) {
                 break; /* no more requests */
             }
 
+            virtio_blk_init_request(vblk, req);
             trace_virtio_blk_data_plane_process_request(s, req->elem.out_num,
                                                         req->elem.in_num,
                                                         req->elem.index);
@@ -125,7 +124,7 @@ static void handle_notify(EventNotifier *e)
             virtio_blk_submit_multireq(s->conf->conf.blk, &mrb);
         }
 
-        if (likely(ret == -EAGAIN)) { /* vring emptied */
+        if (likely(!vring_more_avail(s->vdev, &s->vring))) { /* vring emptied */
             /* Re-enable guest->host notifies and stop processing the vring.
              * But if the guest has snuck in more descriptors, keep processing.
              */
hw/block/virtio-blk.c +6 -9
index 11bedff..bf70b52 100644
@@ -29,15 +29,13 @@
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-access.h"
 
-VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
+void virtio_blk_init_request(VirtIOBlock *s, VirtIOBlockReq *req)
 {
-    VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
     req->dev = s;
     req->qiov.size = 0;
     req->in_len = 0;
     req->next = NULL;
     req->mr_next = NULL;
-    return req;
 }
 
 void virtio_blk_free_request(VirtIOBlockReq *req)
@@ -193,13 +191,11 @@ out:
 
 static VirtIOBlockReq *virtio_blk_get_request(VirtIOBlock *s)
 {
-    VirtIOBlockReq *req = virtio_blk_alloc_request(s);
+    VirtIOBlockReq *req = virtqueue_pop(s->vq, sizeof(VirtIOBlockReq));
 
-    if (!virtqueue_pop(s->vq, &req->elem)) {
-        virtio_blk_free_request(req);
-        return NULL;
+    if (req) {
+        virtio_blk_init_request(s, req);
     }
-
     return req;
 }
 
@@ -836,7 +832,8 @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
     VirtIOBlock *s = VIRTIO_BLK(vdev);
 
     while (qemu_get_sbyte(f)) {
-        VirtIOBlockReq *req = virtio_blk_alloc_request(s);
+        VirtIOBlockReq *req = g_new(VirtIOBlockReq, 1);
+        virtio_blk_init_request(s, req);
         qemu_get_buffer(f, (unsigned char *)&req->elem,
                         sizeof(VirtQueueElement));
         req->next = s->rq;
hw/char/virtio-serial-bus.c +50 -30

194 lines not on this page · raw message

hw/display/virtio-gpu.c +13 -8
index 1cb4002..ddf3bfb 100644
@@ -804,16 +804,15 @@ static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
     }
 #endif
 
-    cmd = g_new(struct virtio_gpu_ctrl_command, 1);
-    while (virtqueue_pop(vq, &cmd->elem)) {
+    cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
+    while (cmd) {
         cmd->vq = vq;
         cmd->error = 0;
         cmd->finished = false;
         cmd->waiting = false;
         QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
-        cmd = g_new(struct virtio_gpu_ctrl_command, 1);
+        cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
     }
-    g_free(cmd);
 
     virtio_gpu_process_cmdq(g);
 
@@ -833,15 +832,20 @@ static void virtio_gpu_ctrl_bh(void *opaque)
 static void virtio_gpu_handle_cursor(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOGPU *g = VIRTIO_GPU(vdev);
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
     size_t s;
     struct virtio_gpu_update_cursor cursor_info;
 
     if (!virtio_queue_ready(vq)) {
         return;
     }
-    while (virtqueue_pop(vq, &elem)) {
-        s = iov_to_buf(elem.out_sg, elem.out_num, 0,
+    for (;;) {
+        elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+        if (!elem) {
+            break;
+        }
+
+        s = iov_to_buf(elem->out_sg, elem->out_num, 0,
                        &cursor_info, sizeof(cursor_info));
         if (s != sizeof(cursor_info)) {
             qemu_log_mask(LOG_GUEST_ERROR,
@@ -850,8 +854,9 @@ static void virtio_gpu_handle_cursor(VirtIODevice *vdev, VirtQueue *vq)
         } else {
             update_cursor(g, &cursor_info);
         }
-        virtqueue_push(vq, &elem, 0);
+        virtqueue_push(vq, elem, 0);
         virtio_notify(vdev, vq);
+        g_free(elem);
     }
 }
 
hw/input/virtio-input.c +16 -8
index f12ed8a..5061f4c 100644
@@ -17,7 +17,7 @@
 
 void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
 {
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
     unsigned have, need;
     int i, len;
 
@@ -50,14 +50,16 @@ void virtio_input_send(VirtIOInput *vinput, virtio_input_event *event)
 
     /* ... and finally pass them to the guest */
     for (i = 0; i < vinput->qindex; i++) {
-        if (!virtqueue_pop(vinput->evt, &elem)) {
+        elem = virtqueue_pop(vinput->evt, sizeof(VirtQueueElement));
+        if (!elem) {
             /* should not happen, we've checked for space beforehand */
             fprintf(stderr, "%s: Huh?  No vq elem available ...\n", __func__);
             return;
         }
-        len = iov_from_buf(elem.in_sg, elem.in_num,
+        len = iov_from_buf(elem->in_sg, elem->in_num,
                            0, vinput->queue+i, sizeof(virtio_input_event));
-        virtqueue_push(vinput->evt, &elem, len);
+        virtqueue_push(vinput->evt, elem, len);
+        g_free(elem);
     }
     virtio_notify(VIRTIO_DEVICE(vinput), vinput->evt);
     vinput->qindex = 0;
@@ -73,17 +75,23 @@ static void virtio_input_handle_sts(VirtIODevice *vdev, VirtQueue *vq)
     VirtIOInputClass *vic = VIRTIO_INPUT_GET_CLASS(vdev);
     VirtIOInput *vinput = VIRTIO_INPUT(vdev);
     virtio_input_event event;
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
     int len;
 
-    while (virtqueue_pop(vinput->sts, &elem)) {
+    for (;;) {
+        elem = virtqueue_pop(vinput->sts, sizeof(VirtQueueElement));
+        if (!elem) {
+            break;
+        }
+
         memset(&event, 0, sizeof(event));
-        len = iov_to_buf(elem.out_sg, elem.out_num,
+        len = iov_to_buf(elem->out_sg, elem->out_num,
                          0, &event, sizeof(event));
         if (vic->handle_status) {
             vic->handle_status(vinput, &event);
         }
-        virtqueue_push(vinput->sts, &elem, len);
+        virtqueue_push(vinput->sts, elem, len);
+        g_free(elem);
     }
     virtio_notify(vdev, vinput->sts);
 }
hw/net/virtio-net.c +43 -26

171 lines not on this page · raw message

hw/scsi/virtio-scsi-dataplane.c +8 -7
index c77b3a1..8340326 100644
@@ -81,15 +81,16 @@ fail_vring:
 VirtIOSCSIReq *virtio_scsi_pop_req_vring(VirtIOSCSI *s,
                                          VirtIOSCSIVring *vring)
 {
-    VirtIOSCSIReq *req = virtio_scsi_init_req(s, NULL);
-    int r;
+    VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
+    VirtIOSCSIReq *req;
 
-    req->vring = vring;
-    r = vring_pop((VirtIODevice *)s, &vring->vring, &req->elem);
-    if (r < 0) {
-        virtio_scsi_free_req(req);
-        req = NULL;
+    req = vring_pop((VirtIODevice *)s, &vring->vring,
+                    sizeof(VirtIOSCSIReq) + vs->cdb_size);
+    if (!req) {
+        return NULL;
     }
+    virtio_scsi_init_req(s, NULL, req);
+    req->vring = vring;
     return req;
 }
 
hw/scsi/virtio-scsi.c +9 -9
index 7fdf6ad..50a3cb2 100644
@@ -41,19 +41,15 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun)
     return scsi_device_find(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun));
 }
 
-VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq)
+void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req)
 {
-    VirtIOSCSIReq *req;
-    VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
     const size_t zero_skip = offsetof(VirtIOSCSIReq, vring);
 
-    req = g_malloc(sizeof(*req) + vs->cdb_size);
     req->vq = vq;
     req->dev = s;
     qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory);
     qemu_iovec_init(&req->resp_iov, 1);
     memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip);
-    return req;
 }
 
 void virtio_scsi_free_req(VirtIOSCSIReq *req)
@@ -174,11 +170,14 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
 
 static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq)
 {
-    VirtIOSCSIReq *req = virtio_scsi_init_req(s, vq);
-    if (!virtqueue_pop(vq, &req->elem)) {
-        virtio_scsi_free_req(req);
+    VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s;
+    VirtIOSCSIReq *req;
+
+    req = virtqueue_pop(vq, sizeof(VirtIOSCSIReq) + vs->cdb_size);
+    if (!req) {
         return NULL;
     }
+    virtio_scsi_init_req(s, vq, req);
     return req;
 }
 
@@ -203,8 +202,9 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
 
     qemu_get_be32s(f, &n);
     assert(n < vs->conf.num_queues);
-    req = virtio_scsi_init_req(s, vs->cmd_vqs[n]);
+    req = g_malloc(sizeof(VirtIOSCSIReq) + vs->cdb_size);
     qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem));
+    virtio_scsi_init_req(s, vs->cmd_vqs[n], req);
 
     virtqueue_map(&req->elem);
 
hw/virtio/dataplane/vring.c +11 -7
index 1a78df1..4fb84bb 100644
@@ -389,23 +389,26 @@ static void vring_unmap_element(VirtQueueElement *elem)
  *
  * Stolen from linux/drivers/vhost/vhost.c.
  */
-int vring_pop(VirtIODevice *vdev, Vring *vring,
-              VirtQueueElement *elem)
+void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
 {
     struct vring_desc desc;
     unsigned int i, head, found = 0, num = vring->vr.num;
     uint16_t avail_idx, last_avail_idx;
+    VirtQueueElement *elem = NULL;
     int ret;
 
-    /* Initialize elem so it can be safely unmapped */
-    elem->in_num = elem->out_num = 0;
-
     /* If there was a fatal error then refuse operation */
     if (vring->broken) {
         ret = -EFAULT;
         goto out;
     }
 
+    assert(sz >= sizeof(VirtQueueElement));
+    elem = g_malloc(sz);
+
+    /* Initialize elem so it can be safely unmapped */
+    elem->in_num = elem->out_num = 0;
+
     /* Check it isn't doing very strange things with descriptor numbers. */
     last_avail_idx = vring->last_avail_idx;
     avail_idx = vring_get_avail_idx(vdev, vring);
@@ -481,7 +484,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
             virtio_tswap16(vdev, vring->last_avail_idx);
     }
 
-    return head;
+    return elem;
 
 out:
     assert(ret < 0);
@@ -489,7 +492,8 @@ out:
         vring->broken = true;
     }
     vring_unmap_element(elem);
-    return ret;
+    g_free(elem);
+    return NULL;
 }
 
 /* After we've used one of their buffers, we tell them about it.
hw/virtio/virtio-balloon.c +15 -7
index f5f25a9..5c30203 100644
@@ -107,8 +107,10 @@ static void balloon_stats_poll_cb(void *opaque)
         return;
     }
 
-    virtqueue_push(s->svq, &s->stats_vq_elem, s->stats_vq_offset);
+    virtqueue_push(s->svq, s->stats_vq_elem, s->stats_vq_offset);
     virtio_notify(vdev, s->svq);
+    g_free(s->stats_vq_elem);
+    s->stats_vq_elem = NULL;
 }
 
 static void balloon_stats_get_all(Object *obj, struct Visitor *v,
@@ -206,14 +208,18 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
 static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
     MemoryRegionSection section;
 
-    while (virtqueue_pop(vq, &elem)) {
+    for (;;) {
         size_t offset = 0;
         uint32_t pfn;
+        elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+        if (!elem) {
+            return;
+        }
 
-        while (iov_to_buf(elem.out_sg, elem.out_num, offset, &pfn, 4) == 4) {
+        while (iov_to_buf(elem->out_sg, elem->out_num, offset, &pfn, 4) == 4) {
             ram_addr_t pa;
             ram_addr_t addr;
             int p = virtio_ldl_p(vdev, &pfn);
@@ -236,20 +242,22 @@ static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
             memory_region_unref(section.mr);
         }
 
-        virtqueue_push(vq, &elem, offset);
+        virtqueue_push(vq, elem, offset);
         virtio_notify(vdev, vq);
+        g_free(elem);
     }
 }
 
 static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
-    VirtQueueElement *elem = &s->stats_vq_elem;
+    VirtQueueElement *elem;
     VirtIOBalloonStat stat;
     size_t offset = 0;
     qemu_timeval tv;
 
-    if (!virtqueue_pop(vq, elem)) {
+    s->stats_vq_elem = elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
+    if (!elem) {
         goto out;
     }
 
hw/virtio/virtio-rng.c +6 -4
index a80fb89..17da2f8 100644
@@ -44,7 +44,7 @@ static void chr_read(void *opaque, const void *buf, size_t size)
 {
     VirtIORNG *vrng = opaque;
     VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
-    VirtQueueElement elem;
+    VirtQueueElement *elem;
     size_t len;
     int offset;
 
@@ -56,15 +56,17 @@ static void chr_read(void *opaque, const void *buf, size_t size)
 
     offset = 0;
     while (offset < size) {
-        if (!virtqueue_pop(vrng->vq, &elem)) {
+        elem = virtqueue_pop(vrng->vq, sizeof(VirtQueueElement));
+        if (!elem) {
             break;
         }
-        len = iov_from_buf(elem.in_sg, elem.in_num,
+        len = iov_from_buf(elem->in_sg, elem->in_num,
                            0, buf + offset, size - offset);
         offset += len;
 
-        virtqueue_push(vrng->vq, &elem, len);
+        virtqueue_push(vrng->vq, elem, len);
         trace_virtio_rng_pushed(vrng, len);
+        g_free(elem);
     }
     virtio_notify(vdev, vrng->vq);
 }
hw/virtio/virtio.c +8 -4
index 0603793..229a092 100644
@@ -501,16 +501,20 @@ void virtqueue_map(VirtQueueElement *elem)
                         0);
 }
 
-int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
+void *virtqueue_pop(VirtQueue *vq, size_t sz)
 {
     unsigned int i, head, max;
     hwaddr desc_pa = vq->vring.desc;
     VirtIODevice *vdev = vq->vdev;
+    VirtQueueElement *elem;
 
-    if (!virtqueue_num_heads(vq, vq->last_avail_idx))
-        return 0;
+    if (!virtqueue_num_heads(vq, vq->last_avail_idx)) {
+        return NULL;
+    }
 
     /* When we start there are none of either input nor output. */
+    assert(sz >= sizeof(VirtQueueElement));
+    elem = g_malloc(sz);
     elem->out_num = elem->in_num = 0;
 
     max = vq->vring.num;
@@ -569,7 +573,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
     vq->inuse++;
 
     trace_virtqueue_pop(vq, elem, elem->in_num, elem->out_num);
-    return elem->in_num + elem->out_num;
+    return elem;
 }
 
 /* virtio device */
roms/seabios +1 -1
index 01a84be..33fbe13 160000
@@ -1 +1 @@
-Subproject commit 01a84bea2d28a19d2405c1ecac4bdef17683cc0c
+Subproject commit 33fbe13a3e2a01e0ba1087a8feed801a0451db21
Signature · 1 line
MST
#9 lore raw

Re: [Qemu-devel] [PULL 06/49] virtio: move allocation to virtqueue_pop/vring_pop

Quoted 52 lines · Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

The return code of virtqueue_pop/vring_pop is unused except to check for errors or 0. We can thus easily move allocation inside the functions and just return a pointer to the VirtQueueElement.

The advantage is that we will be able to allocate only the space that is needed for the actual size of the s/g list instead of the full VIRTQUEUE_MAX_SIZE items. Currently VirtQueueElement takes about 48K of memory, and this kind of allocation puts a lot of stress on malloc. By cutting the size by two or three orders of magnitude, malloc can use much more efficient algorithms.

The patch is pretty large, but changes to each device are testable more or less independently. Splitting it would mostly add churn.

---
 hw/9pfs/virtio-9p.h                 |  2 +-
 include/hw/virtio/dataplane/vring.h |  2 +-
 include/hw/virtio/virtio-balloon.h  |  2 +-
 include/hw/virtio/virtio-blk.h      |  3 +-
 include/hw/virtio/virtio-net.h      |  2 +-
 include/hw/virtio/virtio-scsi.h     |  2 +-
 include/hw/virtio/virtio-serial.h   |  2 +-
 include/hw/virtio/virtio.h          |  2 +-
 hw/9pfs/9p.c                        |  2 +-
 hw/9pfs/virtio-9p-device.c          | 17 ++++----
 hw/block/dataplane/virtio-blk.c     | 11 +++--
 hw/block/virtio-blk.c               | 15 +++----
 hw/char/virtio-serial-bus.c         | 80 +++++++++++++++++++++++--------------
 hw/display/virtio-gpu.c             | 21 ++++++----
 hw/input/virtio-input.c             | 24 +++++++----
 hw/net/virtio-net.c                 | 69 ++++++++++++++++++++------------
 hw/scsi/virtio-scsi-dataplane.c     | 15 +++----
 hw/scsi/virtio-scsi.c               | 18 ++++-----
 hw/virtio/dataplane/vring.c         | 18 +++++----
 hw/virtio/virtio-balloon.c          | 22 ++++++----
 hw/virtio/virtio-rng.c              | 10 +++--
 hw/virtio/virtio.c                  | 12 ++++--
 roms/seabios                        |  2 +-
 23 files changed, 210 insertions(+), 143 deletions(-)
roms/seabios +1 -2
@@ -1 +1 @@
-Subproject commit 01a84bea2d28a19d2405c1ecac4bdef17683cc0c
+Subproject commit 33fbe13a3e2a01e0ba1087a8feed801a0451db21
--
Quoted 1 line

MST

Hi. This commit in this pull request includes a seabios submodule update, but the commit message says nothing about it. Is it really supposed to be here?

thanks
-- PMM

#10 lore raw

Re: [Qemu-devel] [PULL 06/49] virtio: move allocation to virtqueue_pop/vring_pop

Quoted 59 lines · Peter Maydell
Quoted 52 lines · Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

The return code of virtqueue_pop/vring_pop is unused except to check for errors or 0. We can thus easily move allocation inside the functions and just return a pointer to the VirtQueueElement.

The advantage is that we will be able to allocate only the space that is needed for the actual size of the s/g list instead of the full VIRTQUEUE_MAX_SIZE items. Currently VirtQueueElement takes about 48K of memory, and this kind of allocation puts a lot of stress on malloc. By cutting the size by two or three orders of magnitude, malloc can use much more efficient algorithms.

The patch is pretty large, but changes to each device are testable more or less independently. Splitting it would mostly add churn.

---
 hw/9pfs/virtio-9p.h                 |  2 +-
 include/hw/virtio/dataplane/vring.h |  2 +-
 include/hw/virtio/virtio-balloon.h  |  2 +-
 include/hw/virtio/virtio-blk.h      |  3 +-
 include/hw/virtio/virtio-net.h      |  2 +-
 include/hw/virtio/virtio-scsi.h     |  2 +-
 include/hw/virtio/virtio-serial.h   |  2 +-
 include/hw/virtio/virtio.h          |  2 +-
 hw/9pfs/9p.c                        |  2 +-
 hw/9pfs/virtio-9p-device.c          | 17 ++++----
 hw/block/dataplane/virtio-blk.c     | 11 +++--
 hw/block/virtio-blk.c               | 15 +++----
 hw/char/virtio-serial-bus.c         | 80 +++++++++++++++++++++++--------------
 hw/display/virtio-gpu.c             | 21 ++++++----
 hw/input/virtio-input.c             | 24 +++++++----
 hw/net/virtio-net.c                 | 69 ++++++++++++++++++++------------
 hw/scsi/virtio-scsi-dataplane.c     | 15 +++----
 hw/scsi/virtio-scsi.c               | 18 ++++-----
 hw/virtio/dataplane/vring.c         | 18 +++++----
 hw/virtio/virtio-balloon.c          | 22 ++++++----
 hw/virtio/virtio-rng.c              | 10 +++--
 hw/virtio/virtio.c                  | 12 ++++--
 roms/seabios                        |  2 +-
 23 files changed, 210 insertions(+), 143 deletions(-)
roms/seabios +1 -2
@@ -1 +1 @@
-Subproject commit 01a84bea2d28a19d2405c1ecac4bdef17683cc0c
+Subproject commit 33fbe13a3e2a01e0ba1087a8feed801a0451db21
--
Quoted 1 line

MST

Hi. This commit in this pull request includes a seabios submodule update, but the commit message says nothing about it. Is it really supposed to be here?

Quoted 2 lines

thanks
-- PMM

Not sure how it got here - I didn't notice.
I'll redo the pull request.

Signature · 1 line
MST
#11 lore raw

[Qemu-devel] [PULL 08/49] virtio: introduce virtqueue_alloc_element

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

Allocate the arrays for in_addr/out_addr/in_sg/out_sg outside the VirtQueueElement. For now, virtqueue_pop and vring_pop keep allocating a very large VirtQueueElement.

---
 include/hw/virtio/virtio.h  |   9 ++--
 hw/virtio/dataplane/vring.c |   3 +-
 hw/virtio/virtio.c          | 110 +++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 105 insertions(+), 17 deletions(-)
include/hw/virtio/virtio.h +5 -4
index 44da9a8..108cdb0 100644
@@ -46,10 +46,10 @@ typedef struct VirtQueueElement
     unsigned int index;
     unsigned int out_num;
     unsigned int in_num;
-    hwaddr in_addr[VIRTQUEUE_MAX_SIZE];
-    hwaddr out_addr[VIRTQUEUE_MAX_SIZE];
-    struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
-    struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
+    hwaddr *in_addr;
+    hwaddr *out_addr;
+    struct iovec *in_sg;
+    struct iovec *out_sg;
 } VirtQueueElement;
 
 #define VIRTIO_QUEUE_MAX 1024
@@ -143,6 +143,7 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
 
 void virtio_del_queue(VirtIODevice *vdev, int n);
 
+void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);
 void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
                     unsigned int len);
 void virtqueue_flush(VirtQueue *vq, unsigned int count);
hw/virtio/dataplane/vring.c +1 -2
index 4fb84bb..57ada3b 100644
@@ -403,8 +403,7 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
         goto out;
     }
 
-    assert(sz >= sizeof(VirtQueueElement));
-    elem = g_malloc(sz);
+    elem = virtqueue_alloc_element(sz, VIRTQUEUE_MAX_SIZE, VIRTQUEUE_MAX_SIZE);
 
     /* Initialize elem so it can be safely unmapped */
     elem->in_num = elem->out_num = 0;
hw/virtio/virtio.c +99 -11

149 lines not on this page · raw message

Signature · 1 line
MST
#12 lore raw

[Qemu-devel] [PULL 09/49] virtio: slim down allocation of VirtQueueElements

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

Build the addresses and s/g lists on the stack, and then copy them to a VirtQueueElement that is just as big as required to contain this particular s/g list. The cost of the copy is minimal compared to that of a large malloc.

When virtqueue_map is used on the destination side of migration or on loadvm, the iovecs have already been split at memory region boundary, so we can just reuse the out_num/in_num we find in the file.

---
 hw/virtio/virtio.c | 82 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 51 insertions(+), 31 deletions(-)
hw/virtio/virtio.c +51 -31
index 661a1e1..c3e00a8 100644
@@ -448,6 +448,32 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int in_bytes,
     return in_bytes <= in_total && out_bytes <= out_total;
 }
 
+static void virtqueue_map_desc(unsigned int *p_num_sg, hwaddr *addr, struct iovec *iov,
+                               unsigned int max_num_sg, bool is_write,
+                               hwaddr pa, size_t sz)
+{
+    unsigned num_sg = *p_num_sg;
+    assert(num_sg <= max_num_sg);
+
+    while (sz) {
+        hwaddr len = sz;
+
+        if (num_sg == max_num_sg) {
+            error_report("virtio: too many write descriptors in indirect table");
+            exit(1);
+        }
+
+        iov[num_sg].iov_base = cpu_physical_memory_map(pa, &len, is_write);
+        iov[num_sg].iov_len = len;
+        addr[num_sg] = pa;
+
+        sz -= len;
+        pa += len;
+        num_sg++;
+    }
+    *p_num_sg = num_sg;
+}
+
 static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr,
                                 unsigned int *num_sg, unsigned int max_size,
                                 int is_write)
@@ -474,20 +500,10 @@ static void virtqueue_map_iovec(struct iovec *sg, hwaddr *addr,
             error_report("virtio: error trying to map MMIO memory");
             exit(1);
         }
-        if (len == sg[i].iov_len) {
-            continue;
-        }
-        if (*num_sg >= max_size) {
-            error_report("virtio: memory split makes iovec too large");
+        if (len != sg[i].iov_len) {
+            error_report("virtio: unexpected memory split");
             exit(1);
         }
-        memmove(sg + i + 1, sg + i, sizeof(*sg) * (*num_sg - i));
-        memmove(addr + i + 1, addr + i, sizeof(*addr) * (*num_sg - i));
-        assert(len < sg[i + 1].iov_len);
-        sg[i].iov_len = len;
-        addr[i + 1] += len;
-        sg[i + 1].iov_len -= len;
-        ++*num_sg;
     }
 }
 
@@ -526,14 +542,16 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     hwaddr desc_pa = vq->vring.desc;
     VirtIODevice *vdev = vq->vdev;
     VirtQueueElement *elem;
+    unsigned out_num, in_num;
+    hwaddr addr[VIRTQUEUE_MAX_SIZE];
+    struct iovec iov[VIRTQUEUE_MAX_SIZE];
 
     if (!virtqueue_num_heads(vq, vq->last_avail_idx)) {
         return NULL;
     }
 
     /* When we start there are none of either input nor output. */
-    elem = virtqueue_alloc_element(sz, VIRTQUEUE_MAX_SIZE, VIRTQUEUE_MAX_SIZE);
-    elem->out_num = elem->in_num = 0;
+    out_num = in_num = 0;
 
     max = vq->vring.num;
 
@@ -556,37 +574,39 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
 
     /* Collect all the descriptors */
     do {
-        struct iovec *sg;
+        hwaddr pa = vring_desc_addr(vdev, desc_pa, i);
+        size_t len = vring_desc_len(vdev, desc_pa, i);
 
         if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) {
-            if (elem->in_num >= VIRTQUEUE_MAX_SIZE) {
-                error_report("Too many write descriptors in indirect table");
-                exit(1);
-            }
-            elem->in_addr[elem->in_num] = vring_desc_addr(vdev, desc_pa, i);
-            sg = &elem->in_sg[elem->in_num++];
+            virtqueue_map_desc(&in_num, addr + out_num, iov + out_num,
+                               VIRTQUEUE_MAX_SIZE - out_num, true, pa, len);
         } else {
-            if (elem->out_num >= VIRTQUEUE_MAX_SIZE) {
-                error_report("Too many read descriptors in indirect table");
+            if (in_num) {
+                error_report("Incorrect order for descriptors");
                 exit(1);
             }
-            elem->out_addr[elem->out_num] = vring_desc_addr(vdev, desc_pa, i);
-            sg = &elem->out_sg[elem->out_num++];
+            virtqueue_map_desc(&out_num, addr, iov,
+                               VIRTQUEUE_MAX_SIZE, false, pa, len);
         }
 
-        sg->iov_len = vring_desc_len(vdev, desc_pa, i);
-
         /* If we've got too many, that implies a descriptor loop. */
-        if ((elem->in_num + elem->out_num) > max) {
+        if ((in_num + out_num) > max) {
             error_report("Looped descriptor");
             exit(1);
         }
     } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max);
 
-    /* Now map what we have collected */
-    virtqueue_map(elem);
-
+    /* Now copy what we have collected and mapped */
+    elem = virtqueue_alloc_element(sz, out_num, in_num);
     elem->index = head;
+    for (i = 0; i < out_num; i++) {
+        elem->out_addr[i] = addr[i];
+        elem->out_sg[i] = iov[i];
+    }
+    for (i = 0; i < in_num; i++) {
+        elem->in_addr[i] = addr[out_num + i];
+        elem->in_sg[i] = iov[out_num + i];
+    }
 
     vq->inuse++;
 
Signature · 1 line
MST
#13 lore raw

[Qemu-devel] [PULL 10/49] vring: slim down allocation of VirtQueueElements

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

Build the addresses and s/g lists on the stack, and then copy them to a VirtQueueElement that is just as big as required to contain this particular s/g list. The cost of the copy is minimal compared to that of a large malloc.

---
 hw/virtio/dataplane/vring.c | 53 ++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 17 deletions(-)
hw/virtio/dataplane/vring.c +36 -17
index 57ada3b..4308d9f 100644
@@ -218,8 +218,14 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
                             new, old);
 }
 
-
-static int get_desc(Vring *vring, VirtQueueElement *elem,
+typedef struct VirtQueueCurrentElement {
+    unsigned in_num;
+    unsigned out_num;
+    hwaddr addr[VIRTQUEUE_MAX_SIZE];
+    struct iovec iov[VIRTQUEUE_MAX_SIZE];
+} VirtQueueCurrentElement;
+
+static int get_desc(Vring *vring, VirtQueueCurrentElement *elem,
                     struct vring_desc *desc)
 {
     unsigned *num;
@@ -230,12 +236,12 @@ static int get_desc(Vring *vring, VirtQueueElement *elem,
 
     if (desc->flags & VRING_DESC_F_WRITE) {
         num = &elem->in_num;
-        iov = &elem->in_sg[*num];
-        addr = &elem->in_addr[*num];
+        iov = &elem->iov[elem->out_num + *num];
+        addr = &elem->addr[elem->out_num + *num];
     } else {
         num = &elem->out_num;
-        iov = &elem->out_sg[*num];
-        addr = &elem->out_addr[*num];
+        iov = &elem->iov[*num];
+        addr = &elem->addr[*num];
 
         /* If it's an output descriptor, they're all supposed
          * to come before any input descriptors. */
@@ -299,7 +305,8 @@ static bool read_vring_desc(VirtIODevice *vdev,
 
 /* This is stolen from linux/drivers/vhost/vhost.c. */
 static int get_indirect(VirtIODevice *vdev, Vring *vring,
-                        VirtQueueElement *elem, struct vring_desc *indirect)
+                        VirtQueueCurrentElement *cur_elem,
+                        struct vring_desc *indirect)
 {
     struct vring_desc desc;
     unsigned int i = 0, count, found = 0;
@@ -351,7 +358,7 @@ static int get_indirect(VirtIODevice *vdev, Vring *vring,
             return -EFAULT;
         }
 
-        ret = get_desc(vring, elem, &desc);
+        ret = get_desc(vring, cur_elem, &desc);
         if (ret < 0) {
             vring->broken |= (ret == -EFAULT);
             return ret;
@@ -394,6 +401,7 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
     struct vring_desc desc;
     unsigned int i, head, found = 0, num = vring->vr.num;
     uint16_t avail_idx, last_avail_idx;
+    VirtQueueCurrentElement cur_elem;
     VirtQueueElement *elem = NULL;
     int ret;
 
@@ -403,10 +411,7 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
         goto out;
     }
 
-    elem = virtqueue_alloc_element(sz, VIRTQUEUE_MAX_SIZE, VIRTQUEUE_MAX_SIZE);
-
-    /* Initialize elem so it can be safely unmapped */
-    elem->in_num = elem->out_num = 0;
+    cur_elem.in_num = cur_elem.out_num = 0;
 
     /* Check it isn't doing very strange things with descriptor numbers. */
     last_avail_idx = vring->last_avail_idx;
@@ -433,8 +438,6 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
      * the index we've seen. */
     head = vring_get_avail_ring(vdev, vring, last_avail_idx % num);
 
-    elem->index = head;
-
     /* If their number is silly, that's an error. */
     if (unlikely(head >= num)) {
         error_report("Guest says index %u > %u is available", head, num);
@@ -461,14 +464,14 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
         barrier();
 
         if (desc.flags & VRING_DESC_F_INDIRECT) {
-            ret = get_indirect(vdev, vring, elem, &desc);
+            ret = get_indirect(vdev, vring, &cur_elem, &desc);
             if (ret < 0) {
                 goto out;
             }
             continue;
         }
 
-        ret = get_desc(vring, elem, &desc);
+        ret = get_desc(vring, &cur_elem, &desc);
         if (ret < 0) {
             goto out;
         }
@@ -483,6 +486,18 @@ void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz)
             virtio_tswap16(vdev, vring->last_avail_idx);
     }
 
+    /* Now copy what we have collected and mapped */
+    elem = virtqueue_alloc_element(sz, cur_elem.out_num, cur_elem.in_num);
+    elem->index = head;
+    for (i = 0; i < cur_elem.out_num; i++) {
+        elem->out_addr[i] = cur_elem.addr[i];
+        elem->out_sg[i] = cur_elem.iov[i];
+    }
+    for (i = 0; i < cur_elem.in_num; i++) {
+        elem->in_addr[i] = cur_elem.addr[cur_elem.out_num + i];
+        elem->in_sg[i] = cur_elem.iov[cur_elem.out_num + i];
+    }
+
     return elem;
 
 out:
@@ -490,7 +505,11 @@ out:
     if (ret == -EFAULT) {
         vring->broken = true;
     }
-    vring_unmap_element(elem);
+
+    for (i = 0; i < cur_elem.out_num + cur_elem.in_num; i++) {
+        vring_unmap(cur_elem.iov[i].iov_base, false);
+    }
+
     g_free(elem);
     return NULL;
 }
Signature · 1 line
MST
#14 lore raw

[Qemu-devel] [PULL 11/49] virtio: combine the read of a descriptor

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

Compared to vring, virtio has a performance penalty of 10%. Fix it by combining all the reads for a descriptor in a single address_space_read call. This also simplifies the code nicely.

---
 hw/virtio/virtio.c | 86 ++++++++++++++++++++++--------------------------------
 1 file changed, 35 insertions(+), 51 deletions(-)
hw/virtio/virtio.c +35 -51
index c3e00a8..225ee6d 100644
@@ -107,35 +107,15 @@ void virtio_queue_update_rings(VirtIODevice *vdev, int n)
                               vring->align);
 }
 
-static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,
-                                       int i)
+static void vring_desc_read(VirtIODevice *vdev, VRingDesc *desc,
+                            hwaddr desc_pa, int i)
 {
-    hwaddr pa;
-    pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, addr);
-    return virtio_ldq_phys(vdev, pa);
-}
-
-static inline uint32_t vring_desc_len(VirtIODevice *vdev, hwaddr desc_pa, int i)
-{
-    hwaddr pa;
-    pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, len);
-    return virtio_ldl_phys(vdev, pa);
-}
-
-static inline uint16_t vring_desc_flags(VirtIODevice *vdev, hwaddr desc_pa,
-                                        int i)
-{
-    hwaddr pa;
-    pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, flags);
-    return virtio_lduw_phys(vdev, pa);
-}
-
-static inline uint16_t vring_desc_next(VirtIODevice *vdev, hwaddr desc_pa,
-                                       int i)
-{
-    hwaddr pa;
-    pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, next);
-    return virtio_lduw_phys(vdev, pa);
+    address_space_read(&address_space_memory, desc_pa + i * sizeof(VRingDesc),
+                       MEMTXATTRS_UNSPECIFIED, (void *)desc, sizeof(VRingDesc));
+    virtio_tswap64s(vdev, &desc->addr);
+    virtio_tswap32s(vdev, &desc->len);
+    virtio_tswap16s(vdev, &desc->flags);
+    virtio_tswap16s(vdev, &desc->next);
 }
 
 static inline uint16_t vring_avail_flags(VirtQueue *vq)
@@ -345,18 +325,18 @@ static unsigned int virtqueue_get_head(VirtQueue *vq, unsigned int idx)
     return head;
 }
 
-static unsigned virtqueue_next_desc(VirtIODevice *vdev, hwaddr desc_pa,
-                                    unsigned int i, unsigned int max)
+static unsigned virtqueue_read_next_desc(VirtIODevice *vdev, VRingDesc *desc,
+                                         hwaddr desc_pa, unsigned int max)
 {
     unsigned int next;
 
     /* If this descriptor says it doesn't chain, we're done. */
-    if (!(vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_NEXT)) {
+    if (!(desc->flags & VRING_DESC_F_NEXT)) {
         return max;
     }
 
     /* Check they're not leading us off end of descriptors. */
-    next = vring_desc_next(vdev, desc_pa, i);
+    next = desc->next;
     /* Make sure compiler knows to grab that: we don't want it changing! */
     smp_wmb();
 
@@ -365,6 +345,7 @@ static unsigned virtqueue_next_desc(VirtIODevice *vdev, hwaddr desc_pa,
         exit(1);
     }
 
+    vring_desc_read(vdev, desc, desc_pa, next);
     return next;
 }
 
@@ -381,6 +362,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
     while (virtqueue_num_heads(vq, idx)) {
         VirtIODevice *vdev = vq->vdev;
         unsigned int max, num_bufs, indirect = 0;
+        VRingDesc desc;
         hwaddr desc_pa;
         int i;
 
@@ -388,9 +370,10 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
         num_bufs = total_bufs;
         i = virtqueue_get_head(vq, idx++);
         desc_pa = vq->vring.desc;
+        vring_desc_read(vdev, &desc, desc_pa, i);
 
-        if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
-            if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) {
+        if (desc.flags & VRING_DESC_F_INDIRECT) {
+            if (desc.len % sizeof(VRingDesc)) {
                 error_report("Invalid size for indirect buffer table");
                 exit(1);
             }
@@ -403,9 +386,10 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
 
             /* loop over the indirect descriptor table */
             indirect = 1;
-            max = vring_desc_len(vdev, desc_pa, i) / sizeof(VRingDesc);
-            desc_pa = vring_desc_addr(vdev, desc_pa, i);
+            max = desc.len / sizeof(VRingDesc);
+            desc_pa = desc.addr;
             num_bufs = i = 0;
+            vring_desc_read(vdev, &desc, desc_pa, i);
         }
 
         do {
@@ -415,15 +399,15 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
                 exit(1);
             }
 
-            if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) {
-                in_total += vring_desc_len(vdev, desc_pa, i);
+            if (desc.flags & VRING_DESC_F_WRITE) {
+                in_total += desc.len;
             } else {
-                out_total += vring_desc_len(vdev, desc_pa, i);
+                out_total += desc.len;
             }
             if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
                 goto done;
             }
-        } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max);
+        } while ((i = virtqueue_read_next_desc(vdev, &desc, desc_pa, max)) != max);
 
         if (!indirect)
             total_bufs = num_bufs;
@@ -545,6 +529,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     unsigned out_num, in_num;
     hwaddr addr[VIRTQUEUE_MAX_SIZE];
     struct iovec iov[VIRTQUEUE_MAX_SIZE];
+    VRingDesc desc;
 
     if (!virtqueue_num_heads(vq, vq->last_avail_idx)) {
         return NULL;
@@ -560,33 +545,32 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
         vring_set_avail_event(vq, vq->last_avail_idx);
     }
 
-    if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
-        if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) {
+    vring_desc_read(vdev, &desc, desc_pa, i);
+    if (desc.flags & VRING_DESC_F_INDIRECT) {
+        if (desc.len % sizeof(VRingDesc)) {
             error_report("Invalid size for indirect buffer table");
             exit(1);
         }
 
         /* loop over the indirect descriptor table */
-        max = vring_desc_len(vdev, desc_pa, i) / sizeof(VRingDesc);
-        desc_pa = vring_desc_addr(vdev, desc_pa, i);
+        max = desc.len / sizeof(VRingDesc);
+        desc_pa = desc.addr;
         i = 0;
+        vring_desc_read(vdev, &desc, desc_pa, i);
     }
 
     /* Collect all the descriptors */
     do {
-        hwaddr pa = vring_desc_addr(vdev, desc_pa, i);
-        size_t len = vring_desc_len(vdev, desc_pa, i);
-
-        if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) {
+        if (desc.flags & VRING_DESC_F_WRITE) {
             virtqueue_map_desc(&in_num, addr + out_num, iov + out_num,
-                               VIRTQUEUE_MAX_SIZE - out_num, true, pa, len);
+                               VIRTQUEUE_MAX_SIZE - out_num, true, desc.addr, desc.len);
         } else {
             if (in_num) {
                 error_report("Incorrect order for descriptors");
                 exit(1);
             }
             virtqueue_map_desc(&out_num, addr, iov,
-                               VIRTQUEUE_MAX_SIZE, false, pa, len);
+                               VIRTQUEUE_MAX_SIZE, false, desc.addr, desc.len);
         }
 
         /* If we've got too many, that implies a descriptor loop. */
@@ -594,7 +578,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
             error_report("Looped descriptor");
             exit(1);
         }
-    } while ((i = virtqueue_next_desc(vdev, desc_pa, i, max)) != max);
+    } while ((i = virtqueue_read_next_desc(vdev, &desc, desc_pa, max)) != max);
 
     /* Now copy what we have collected and mapped */
     elem = virtqueue_alloc_element(sz, out_num, in_num);
Signature · 1 line
MST
#15 lore raw

[Qemu-devel] [PULL 12/49] virtio: cache used_idx in a VirtQueue field

In reply to Michael S. Tsirkin

From: Vincenzo Maffione <[email protected]>

Accessing used_idx in the VQ requires an expensive access to guest physical memory. Before this patch, 3 accesses are normally done for each pop/push/notify call. However, since the used_idx is only written by us, we can track it in our internal data structure.

Message-Id: <3d062ec54e9a7bf9fb325c1fd693564951f2b319.1450218353.git.v.maffione@gmail.com>

---
 hw/virtio/virtio.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +9 -3
index 225ee6d..82e6414 100644
@@ -71,6 +71,9 @@ struct VirtQueue
 {
     VRing vring;
     uint16_t last_avail_idx;
+
+    uint16_t used_idx;
+
     /* Last used index value we have signalled on */
     uint16_t signalled_used;
 
@@ -170,6 +173,7 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val)
     hwaddr pa;
     pa = vq->vring.used + offsetof(VRingUsed, idx);
     virtio_stw_phys(vq->vdev, pa, val);
+    vq->used_idx = val;
 }
 
 static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask)
@@ -261,7 +265,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
 
     virtqueue_unmap_sg(vq, elem, len);
 
-    idx = (idx + vring_used_idx(vq)) % vq->vring.num;
+    idx = (idx + vq->used_idx) % vq->vring.num;
 
     /* Get a pointer to the next entry in the used ring. */
     vring_used_ring_id(vq, idx, elem->index);
@@ -274,7 +278,7 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count)
     /* Make sure buffer is written before we update index. */
     smp_wmb();
     trace_virtqueue_flush(vq, count);
-    old = vring_used_idx(vq);
+    old = vq->used_idx;
     new = old + count;
     vring_used_idx_set(vq, new);
     vq->inuse -= count;
@@ -782,6 +786,7 @@ void virtio_reset(void *opaque)
         vdev->vq[i].vring.avail = 0;
         vdev->vq[i].vring.used = 0;
         vdev->vq[i].last_avail_idx = 0;
+        vdev->vq[i].used_idx = 0;
         virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
         vdev->vq[i].signalled_used = 0;
         vdev->vq[i].signalled_used_valid = false;
@@ -1161,7 +1166,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
     v = vq->signalled_used_valid;
     vq->signalled_used_valid = true;
     old = vq->signalled_used;
-    new = vq->signalled_used = vring_used_idx(vq);
+    new = vq->signalled_used = vq->used_idx;
     return !v || vring_need_event(vring_get_used_event(vq), new, old);
 }
 
@@ -1573,6 +1578,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
                              vdev->vq[i].last_avail_idx, nheads);
                 return -1;
             }
+            vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);
         }
     }
 
Signature · 1 line
MST
#16 lore raw

[Qemu-devel] [PULL 13/49] virtio: read avail_idx from VQ only when necessary

In reply to Michael S. Tsirkin

From: Vincenzo Maffione <[email protected]>

The virtqueue_pop() implementation needs to check if the avail ring contains some pending buffers. To perform this check, it is not always necessary to fetch the avail_idx in the VQ memory, which is expensive. This patch introduces a shadow variable tracking avail_idx and modifies virtio_queue_empty() to access avail_idx in physical memory only when necessary.

Message-Id: <b617d6459902773d9f4ab843bfaca764f5af8eda.1450218353.git.v.maffione@gmail.com>

---
 hw/virtio/virtio.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
hw/virtio/virtio.c +22 -4
index 82e6414..9608358 100644
@@ -70,8 +70,13 @@ typedef struct VRing
 struct VirtQueue
 {
     VRing vring;
+
+    /* Next head to pop */
     uint16_t last_avail_idx;
 
+    /* Last avail_idx read from VQ. */
+    uint16_t shadow_avail_idx;
+
     uint16_t used_idx;
 
     /* Last used index value we have signalled on */
@@ -132,7 +137,8 @@ static inline uint16_t vring_avail_idx(VirtQueue *vq)
 {
     hwaddr pa;
     pa = vq->vring.avail + offsetof(VRingAvail, idx);
-    return virtio_lduw_phys(vq->vdev, pa);
+    vq->shadow_avail_idx = virtio_lduw_phys(vq->vdev, pa);
+    return vq->shadow_avail_idx;
 }
 
 static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
@@ -223,8 +229,14 @@ int virtio_queue_ready(VirtQueue *vq)
     return vq->vring.avail != 0;
 }
 
+/* Fetch avail_idx from VQ memory only when we really need to know if
+ * guest has added some buffers. */
 int virtio_queue_empty(VirtQueue *vq)
 {
+    if (vq->shadow_avail_idx != vq->last_avail_idx) {
+        return 0;
+    }
+
     return vring_avail_idx(vq) == vq->last_avail_idx;
 }
 
@@ -300,7 +312,7 @@ static int virtqueue_num_heads(VirtQueue *vq, unsigned int idx)
     /* Check it isn't doing very strange things with descriptor numbers. */
     if (num_heads > vq->vring.num) {
         error_report("Guest moved used index from %u to %u",
-                     idx, vring_avail_idx(vq));
+                     idx, vq->shadow_avail_idx);
         exit(1);
     }
     /* On success, callers read a descriptor at vq->last_avail_idx.
@@ -535,9 +547,12 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     struct iovec iov[VIRTQUEUE_MAX_SIZE];
     VRingDesc desc;
 
-    if (!virtqueue_num_heads(vq, vq->last_avail_idx)) {
+    if (virtio_queue_empty(vq)) {
         return NULL;
     }
+    /* Needed after virtio_queue_empty(), see comment in
+     * virtqueue_num_heads(). */
+    smp_rmb();
 
     /* When we start there are none of either input nor output. */
     out_num = in_num = 0;
@@ -786,6 +801,7 @@ void virtio_reset(void *opaque)
         vdev->vq[i].vring.avail = 0;
         vdev->vq[i].vring.used = 0;
         vdev->vq[i].last_avail_idx = 0;
+        vdev->vq[i].shadow_avail_idx = 0;
         vdev->vq[i].used_idx = 0;
         virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR);
         vdev->vq[i].signalled_used = 0;
@@ -1155,7 +1171,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
     smp_mb();
     /* Always notify when queue is empty (when feature acknowledge) */
     if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) &&
-        !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) {
+        !vq->inuse && virtio_queue_empty(vq)) {
         return true;
     }
 
@@ -1579,6 +1595,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
                 return -1;
             }
             vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);
+            vdev->vq[i].shadow_avail_idx = vring_avail_idx(&vdev->vq[i]);
         }
     }
 
@@ -1714,6 +1731,7 @@ uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n)
 void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx)
 {
     vdev->vq[n].last_avail_idx = idx;
+    vdev->vq[n].shadow_avail_idx = idx;
 }
 
 void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n)
Signature · 1 line
MST
#17 lore raw

[Qemu-devel] [PULL 15/49] hw/pxb: add pxb devices to the bridge category

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

---
 hw/pci-bridge/pci_expander_bridge.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/pci_expander_bridge.c +2 -0
index 62fd29d..d23b8da 100644
@@ -302,6 +302,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data)
 
     dc->desc = "PCI Expander Bridge";
     dc->props = pxb_dev_properties;
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 }
 
 static const TypeInfo pxb_dev_info = {
@@ -334,6 +335,7 @@ static void pxb_pcie_dev_class_init(ObjectClass *klass, void *data)
 
     dc->desc = "PCI Express Expander Bridge";
     dc->props = pxb_dev_properties;
+    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 }
 
 static const TypeInfo pxb_pcie_dev_info = {
Signature · 1 line
MST
#18 lore raw

[Qemu-devel] [PULL 16/49] vhost-user-test: use correct ROM to speed up and avoid spurious failures

In reply to Michael S. Tsirkin

From: Paolo Bonzini <[email protected]>

The mechanism to get the option ROM for virtio-net does not block the PCI ROM from being loaded. Therefore, in vhost-user-test there are two entries in the boot menu for the virtio-net card: one as an embedded option ROM, one from the ROM BAR.

The embedded option ROM in vhost-user-test is the non-EFI-enabled, while the ROM BAR has an EFI-enabled ROM. The two are compiled with slightly different parameters, where only the old BIOS-only one doesn't have a timeout for the "Press Ctrl-B" banner. When using a new machine type, therefore, the vhost-user-test has to wait for the EFI-enabled ROM's banner to go away. There are several ways to fix this:

1) fix the ROMs to have the same configuration

2) add ",romfile=" to the -device line

3) remove --option-rom and add the ROM file name to the -device line

4) use an old machine type

This patch chooses 3. In addition, the file name was wrong because qtest runs QEMU relative to the top build directory, not to the x86_64-softmmu/ subdirectory, which is fixed too.

---
 tests/vhost-user-test.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tests/vhost-user-test.c +2 -3
index 95f35af..e30b7f4 100644
@@ -35,11 +35,10 @@
                         "mem-path=%s,share=on -numa node,memdev=mem"
 #define QEMU_CMD_CHR    " -chardev socket,id=%s,path=%s"
 #define QEMU_CMD_NETDEV " -netdev vhost-user,id=net0,chardev=%s,vhostforce"
-#define QEMU_CMD_NET    " -device virtio-net-pci,netdev=net0 "
-#define QEMU_CMD_ROM    " -option-rom ../pc-bios/pxe-virtio.rom"
+#define QEMU_CMD_NET    " -device virtio-net-pci,netdev=net0,romfile=./pc-bios/pxe-virtio.rom"
 
 #define QEMU_CMD        QEMU_CMD_ACCEL QEMU_CMD_MEM QEMU_CMD_CHR \
-                        QEMU_CMD_NETDEV QEMU_CMD_NET QEMU_CMD_ROM
+                        QEMU_CMD_NETDEV QEMU_CMD_NET
 
 #define HUGETLBFS_MAGIC       0x958458f6
 
Signature · 1 line
MST
#19 lore raw

[Qemu-devel] [PULL 17/49] hw/pci: ensure that only PCI/PCIe bridges can be attached to pxb/pxb-pcie devices

In reply to Michael S. Tsirkin

From: Marcel Apfelbaum <[email protected]>

PCI devices can't be plugged directly into PCI extra root bridges because their resources can't be computed by firmware before the ACPI tables are loaded.

---
 hw/pci/pci.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/pci/pci.c +7 -0
index d940f79..b282120 100644
@@ -851,6 +851,13 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
     DeviceState *dev = DEVICE(pci_dev);
 
     pci_dev->bus = bus;
+    /* Only pci bridges can be attached to extra PCI root buses */
+    if (pci_bus_is_root(bus) && bus->parent_dev && !pc->is_bridge) {
+        error_setg(errp,
+                   "PCI: Only PCI/PCIe bridges can be plugged into %s",
+                    bus->parent_dev->name);
+        return NULL;
+    }
 
     if (devfn < 0) {
         for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
Signature · 1 line
MST
#20 lore raw

[Qemu-devel] [PULL 18/49] ipmi: replace goto by a return statement

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

Each routine using the IPMI_ADD_RSP_DATA, IPMI_CHECK_CMD_LEN or IPMI_CHECK_RESERVATION macros needs to define a goto label 'out' to handle hidden errors. Using directly a return statement has the same effect and it removes the fact that 'out' needs to be defined.

The code exits in ipmi_sim_handle_command() are a little different from the rest and a "possible" error in the macro IPMI_ADD_RSP_DATA is handled before making use of it. This might be a bit excessive as a minimum response len is currently 300 bytes and the patch checks that at least 3 are available.

---
 hw/ipmi/ipmi_bmc_sim.c | 140 +++++++++++++++----------------------------------
 1 file changed, 41 insertions(+), 99 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +41 -99
index dcdab03..1f06dfc 100644
@@ -256,7 +256,7 @@ struct IPMIBmcSim {
     do {                                                   \
         if (*rsp_len >= max_rsp_len) {                     \
             rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;       \
-            goto out;                                      \
+            return;                                        \
         }                                                  \
         rsp[(*rsp_len)++] = (b);                           \
     } while (0)
@@ -265,7 +265,7 @@ struct IPMIBmcSim {
 #define IPMI_CHECK_CMD_LEN(l) \
     if (cmd_len < l) {                                     \
         rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;      \
-        goto out; \
+        return; \
     }
 
 /* Check that the reservation in the command is valid. */
@@ -273,7 +273,7 @@ struct IPMIBmcSim {
     do {                                                   \
         if ((cmd[off] | (cmd[off + 1] << 8)) != r) {       \
             rsp[2] = IPMI_CC_INVALID_RESERVATION;          \
-            goto out;                                      \
+            return;                                        \
         }                                                  \
     } while (0)
 
@@ -451,14 +451,12 @@ static void gen_event(IPMIBmcSim *ibs, unsigned int sens_num, uint8_t deassert,
     }
 
     if (ibs->msg_flags & IPMI_BMC_MSG_FLAG_EVT_BUF_FULL) {
-        goto out;
+        return;
     }
 
     memcpy(ibs->evtbuf, evt, 16);
     ibs->msg_flags |= IPMI_BMC_MSG_FLAG_EVT_BUF_FULL;
     k->set_atn(s, 1, attn_irq_enabled(ibs));
- out:
-    return;
 }
 
 static void sensor_set_discrete_bit(IPMIBmcSim *ibs, unsigned int sensor,
@@ -579,6 +577,11 @@ static void ipmi_sim_handle_command(IPMIBmc *b,
 
     /* Set up the response, set the low bit of NETFN. */
     /* Note that max_rsp_len must be at least 3 */
+    if (max_rsp_len < 3) {
+        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;
+        goto out;
+    }
+
     IPMI_ADD_RSP_DATA(cmd[0] | 0x04);
     IPMI_ADD_RSP_DATA(cmd[1]);
     IPMI_ADD_RSP_DATA(0); /* Assume success */
@@ -696,8 +699,6 @@ static void chassis_capabilities(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA(ibs->parent.slave_addr);
     IPMI_ADD_RSP_DATA(ibs->parent.slave_addr);
     IPMI_ADD_RSP_DATA(ibs->parent.slave_addr);
- out:
-    return;
 }
 
 static void chassis_status(IPMIBmcSim *ibs,
@@ -709,8 +710,6 @@ static void chassis_status(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA(0);
     IPMI_ADD_RSP_DATA(0);
     IPMI_ADD_RSP_DATA(0);
- out:
-    return;
 }
 
 static void chassis_control(IPMIBmcSim *ibs,
@@ -744,10 +743,8 @@ static void chassis_control(IPMIBmcSim *ibs,
         break;
     default:
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
- out:
-    return;
 }
 
 static void get_device_id(IPMIBmcSim *ibs,
@@ -766,8 +763,6 @@ static void get_device_id(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA(ibs->mfg_id[2]);
     IPMI_ADD_RSP_DATA(ibs->product_id[0]);
     IPMI_ADD_RSP_DATA(ibs->product_id[1]);
- out:
-    return;
 }
 
 static void set_global_enables(IPMIBmcSim *ibs, uint8_t val)
@@ -820,8 +815,6 @@ static void set_bmc_global_enables(IPMIBmcSim *ibs,
 {
     IPMI_CHECK_CMD_LEN(3);
     set_global_enables(ibs, cmd[2]);
- out:
-    return;
 }
 
 static void get_bmc_global_enables(IPMIBmcSim *ibs,
@@ -830,8 +823,6 @@ static void get_bmc_global_enables(IPMIBmcSim *ibs,
                                    unsigned int max_rsp_len)
 {
     IPMI_ADD_RSP_DATA(ibs->bmc_global_enables);
- out:
-    return;
 }
 
 static void clr_msg_flags(IPMIBmcSim *ibs,
@@ -845,8 +836,6 @@ static void clr_msg_flags(IPMIBmcSim *ibs,
     IPMI_CHECK_CMD_LEN(3);
     ibs->msg_flags &= ~cmd[2];
     k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs));
- out:
-    return;
 }
 
 static void get_msg_flags(IPMIBmcSim *ibs,
@@ -855,8 +844,6 @@ static void get_msg_flags(IPMIBmcSim *ibs,
                           unsigned int max_rsp_len)
 {
     IPMI_ADD_RSP_DATA(ibs->msg_flags);
- out:
-    return;
 }
 
 static void read_evt_msg_buf(IPMIBmcSim *ibs,
@@ -870,15 +857,13 @@ static void read_evt_msg_buf(IPMIBmcSim *ibs,
 
     if (!(ibs->msg_flags & IPMI_BMC_MSG_FLAG_EVT_BUF_FULL)) {
         rsp[2] = 0x80;
-        goto out;
+        return;
     }
     for (i = 0; i < 16; i++) {
         IPMI_ADD_RSP_DATA(ibs->evtbuf[i]);
     }
     ibs->msg_flags &= ~IPMI_BMC_MSG_FLAG_EVT_BUF_FULL;
     k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs));
- out:
-    return;
 }
 
 static void get_msg(IPMIBmcSim *ibs,
@@ -909,7 +894,7 @@ static void get_msg(IPMIBmcSim *ibs,
         k->set_atn(s, attn_set(ibs), attn_irq_enabled(ibs));
     }
 
- out:
+out:
     qemu_mutex_unlock(&ibs->lock);
     return;
 }
@@ -940,14 +925,14 @@ static void send_msg(IPMIBmcSim *ibs,
     if (cmd[2] != 0) {
         /* We only handle channel 0 with no options */
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
 
     IPMI_CHECK_CMD_LEN(10);
     if (cmd[3] != 0x40) {
         /* We only emulate a MC at address 0x40. */
         rsp[2] = 0x83; /* NAK on write */
-        goto out;
+        return;
     }
 
     cmd += 3; /* Skip the header. */
@@ -959,7 +944,7 @@ static void send_msg(IPMIBmcSim *ibs,
      */
     if (ipmb_checksum(cmd, cmd_len, 0) != 0 ||
         cmd[3] != 0x20) { /* Improper response address */
-        goto out; /* No response */
+        return; /* No response */
     }
 
     netfn = cmd[1] >> 2;
@@ -969,7 +954,7 @@ static void send_msg(IPMIBmcSim *ibs,
 
     if (rqLun != 2) {
         /* We only support LUN 2 coming back to us. */
-        goto out;
+        return;
     }
 
     msg = g_malloc(sizeof(*msg));
@@ -1009,9 +994,6 @@ static void send_msg(IPMIBmcSim *ibs,
     ibs->msg_flags |= IPMI_BMC_MSG_FLAG_RCV_MSG_QUEUE;
     k->set_atn(s, 1, attn_irq_enabled(ibs));
     qemu_mutex_unlock(&ibs->lock);
-
- out:
-    return;
 }
 
 static void do_watchdog_reset(IPMIBmcSim *ibs)
@@ -1040,11 +1022,9 @@ static void reset_watchdog_timer(IPMIBmcSim *ibs,
 {
     if (!ibs->watchdog_initialized) {
         rsp[2] = 0x80;
-        goto out;
+        return;
     }
     do_watchdog_reset(ibs);
- out:
-    return;
 }
 
 static void set_watchdog_timer(IPMIBmcSim *ibs,
@@ -1060,7 +1040,7 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
     val = cmd[2] & 0x7; /* Validate use */
     if (val == 0 || val > 5) {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     val = cmd[3] & 0x7; /* Validate action */
     switch (val) {
@@ -1084,7 +1064,7 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
     }
     if (rsp[2]) {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
 
     val = (cmd[3] >> 4) & 0x7; /* Validate preaction */
@@ -1097,12 +1077,12 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
         if (!k->do_hw_op(s, IPMI_SEND_NMI, 1)) {
             /* NMI not supported. */
             rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-            goto out;
+            return;
         }
     default:
         /* We don't support PRE_SMI */
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
 
     ibs->watchdog_initialized = 1;
@@ -1116,8 +1096,6 @@ static void set_watchdog_timer(IPMIBmcSim *ibs,
     } else {
         ibs->watchdog_running = 0;
     }
- out:
-    return;
 }
 
 static void get_watchdog_timer(IPMIBmcSim *ibs,
@@ -1139,8 +1117,6 @@ static void get_watchdog_timer(IPMIBmcSim *ibs,
         IPMI_ADD_RSP_DATA(0);
         IPMI_ADD_RSP_DATA(0);
     }
- out:
-    return;
 }
 
 static void get_sdr_rep_info(IPMIBmcSim *ibs,
@@ -1163,8 +1139,6 @@ static void get_sdr_rep_info(IPMIBmcSim *ibs,
     }
     /* Only modal support, reserve supported */
     IPMI_ADD_RSP_DATA((ibs->sdr.overflow << 7) | 0x22);
- out:
-    return;
 }
 
 static void reserve_sdr_rep(IPMIBmcSim *ibs,
@@ -1174,8 +1148,6 @@ static void reserve_sdr_rep(IPMIBmcSim *ibs,
 {
     IPMI_ADD_RSP_DATA(ibs->sdr.reservation & 0xff);
     IPMI_ADD_RSP_DATA((ibs->sdr.reservation >> 8) & 0xff);
- out:
-    return;
 }
 
 static void get_sdr(IPMIBmcSim *ibs,
@@ -1194,11 +1166,11 @@ static void get_sdr(IPMIBmcSim *ibs,
     if (sdr_find_entry(&ibs->sdr, cmd[4] | (cmd[5] << 8),
                        &pos, &nextrec)) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     if (cmd[6] > (ibs->sdr.sdr[pos + 4])) {
         rsp[2] = IPMI_CC_PARM_OUT_OF_RANGE;
-        goto out;
+        return;
     }
 
     IPMI_ADD_RSP_DATA(nextrec & 0xff);
@@ -1210,12 +1182,10 @@ static void get_sdr(IPMIBmcSim *ibs,
 
     if ((cmd[7] + *rsp_len) > max_rsp_len) {
         rsp[2] = IPMI_CC_CANNOT_RETURN_REQ_NUM_BYTES;
-        goto out;
+        return;
     }
     memcpy(rsp + *rsp_len, ibs->sdr.sdr + pos + cmd[6], cmd[7]);
     *rsp_len += cmd[7];
- out:
-    return;
 }
 
 static void add_sdr(IPMIBmcSim *ibs,
@@ -1227,12 +1197,10 @@ static void add_sdr(IPMIBmcSim *ibs,
 
     if (sdr_add_entry(ibs, cmd + 2, cmd_len - 2, &recid)) {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     IPMI_ADD_RSP_DATA(recid & 0xff);
     IPMI_ADD_RSP_DATA((recid >> 8) & 0xff);
- out:
-    return;
 }
 
 static void clear_sdr_rep(IPMIBmcSim *ibs,
@@ -1244,7 +1212,7 @@ static void clear_sdr_rep(IPMIBmcSim *ibs,
     IPMI_CHECK_RESERVATION(2, ibs->sdr.reservation);
     if (cmd[4] != 'C' || cmd[5] != 'L' || cmd[6] != 'R') {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     if (cmd[7] == 0xaa) {
         ibs->sdr.next_free = 0;
@@ -1256,10 +1224,8 @@ static void clear_sdr_rep(IPMIBmcSim *ibs,
         IPMI_ADD_RSP_DATA(1); /* Erasure complete */
     } else {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
- out:
-    return;
 }
 
 static void get_sel_info(IPMIBmcSim *ibs,
@@ -1283,8 +1249,6 @@ static void get_sel_info(IPMIBmcSim *ibs,
     }
     /* Only support Reserve SEL */
     IPMI_ADD_RSP_DATA((ibs->sel.overflow << 7) | 0x02);
- out:
-    return;
 }
 
 static void reserve_sel(IPMIBmcSim *ibs,
@@ -1294,8 +1258,6 @@ static void reserve_sel(IPMIBmcSim *ibs,
 {
     IPMI_ADD_RSP_DATA(ibs->sel.reservation & 0xff);
     IPMI_ADD_RSP_DATA((ibs->sel.reservation >> 8) & 0xff);
- out:
-    return;
 }
 
 static void get_sel_entry(IPMIBmcSim *ibs,
@@ -1311,17 +1273,17 @@ static void get_sel_entry(IPMIBmcSim *ibs,
     }
     if (ibs->sel.next_free == 0) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     if (cmd[6] > 15) {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     if (cmd[7] == 0xff) {
         cmd[7] = 16;
     } else if ((cmd[7] + cmd[6]) > 16) {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     } else {
         cmd[7] += cmd[6];
     }
@@ -1331,7 +1293,7 @@ static void get_sel_entry(IPMIBmcSim *ibs,
         val = ibs->sel.next_free - 1;
     } else if (val >= ibs->sel.next_free) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     if ((val + 1) == ibs->sel.next_free) {
         IPMI_ADD_RSP_DATA(0xff);
@@ -1343,8 +1305,6 @@ static void get_sel_entry(IPMIBmcSim *ibs,
     for (; cmd[6] < cmd[7]; cmd[6]++) {
         IPMI_ADD_RSP_DATA(ibs->sel.sel[val][cmd[6]]);
     }
- out:
-    return;
 }
 
 static void add_sel_entry(IPMIBmcSim *ibs,
@@ -1355,13 +1315,11 @@ static void add_sel_entry(IPMIBmcSim *ibs,
     IPMI_CHECK_CMD_LEN(18);
     if (sel_add_event(ibs, cmd + 2)) {
         rsp[2] = IPMI_CC_OUT_OF_SPACE;
-        goto out;
+        return;
     }
     /* sel_add_event fills in the record number. */
     IPMI_ADD_RSP_DATA(cmd[2]);
     IPMI_ADD_RSP_DATA(cmd[3]);
- out:
-    return;
 }
 
 static void clear_sel(IPMIBmcSim *ibs,
@@ -1373,7 +1331,7 @@ static void clear_sel(IPMIBmcSim *ibs,
     IPMI_CHECK_RESERVATION(2, ibs->sel.reservation);
     if (cmd[4] != 'C' || cmd[5] != 'L' || cmd[6] != 'R') {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     if (cmd[7] == 0xaa) {
         ibs->sel.next_free = 0;
@@ -1385,10 +1343,8 @@ static void clear_sel(IPMIBmcSim *ibs,
         IPMI_ADD_RSP_DATA(1); /* Erasure complete */
     } else {
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
- out:
-    return;
 }
 
 static void get_sel_time(IPMIBmcSim *ibs,
@@ -1405,8 +1361,6 @@ static void get_sel_time(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA((val >> 8) & 0xff);
     IPMI_ADD_RSP_DATA((val >> 16) & 0xff);
     IPMI_ADD_RSP_DATA((val >> 24) & 0xff);
- out:
-    return;
 }
 
 static void set_sel_time(IPMIBmcSim *ibs,
@@ -1421,8 +1375,6 @@ static void set_sel_time(IPMIBmcSim *ibs,
     val = cmd[2] | (cmd[3] << 8) | (cmd[4] << 16) | (cmd[5] << 24);
     ipmi_gettime(&now);
     ibs->sel.time_offset = now.tv_sec - ((long) val);
- out:
-    return;
 }
 
 static void set_sensor_evt_enable(IPMIBmcSim *ibs,
@@ -1436,7 +1388,7 @@ static void set_sensor_evt_enable(IPMIBmcSim *ibs,
     if ((cmd[2] > MAX_SENSORS) ||
             !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     sens = ibs->sensors + cmd[2];
     switch ((cmd[3] >> 4) & 0x3) {
@@ -1472,11 +1424,9 @@ static void set_sensor_evt_enable(IPMIBmcSim *ibs,
         break;
     case 3:
         rsp[2] = IPMI_CC_INVALID_DATA_FIELD;
-        goto out;
+        return;
     }
     IPMI_SENSOR_SET_RET_STATUS(sens, cmd[3]);
- out:
-    return;
 }
 
 static void get_sensor_evt_enable(IPMIBmcSim *ibs,
@@ -1490,7 +1440,7 @@ static void get_sensor_evt_enable(IPMIBmcSim *ibs,
     if ((cmd[2] > MAX_SENSORS) ||
         !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     sens = ibs->sensors + cmd[2];
     IPMI_ADD_RSP_DATA(IPMI_SENSOR_GET_RET_STATUS(sens));
@@ -1498,8 +1448,6 @@ static void get_sensor_evt_enable(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA((sens->assert_enable >> 8) & 0xff);
     IPMI_ADD_RSP_DATA(sens->deassert_enable & 0xff);
     IPMI_ADD_RSP_DATA((sens->deassert_enable >> 8) & 0xff);
- out:
-    return;
 }
 
 static void rearm_sensor_evts(IPMIBmcSim *ibs,
@@ -1513,17 +1461,15 @@ static void rearm_sensor_evts(IPMIBmcSim *ibs,
     if ((cmd[2] > MAX_SENSORS) ||
         !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     sens = ibs->sensors + cmd[2];
 
     if ((cmd[3] & 0x80) == 0) {
         /* Just clear everything */
         sens->states = 0;
-        goto out;
+        return;
     }
- out:
-    return;
 }
 
 static void get_sensor_evt_status(IPMIBmcSim *ibs,
@@ -1537,7 +1483,7 @@ static void get_sensor_evt_status(IPMIBmcSim *ibs,
     if ((cmd[2] > MAX_SENSORS) ||
         !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     sens = ibs->sensors + cmd[2];
     IPMI_ADD_RSP_DATA(sens->reading);
@@ -1546,8 +1492,6 @@ static void get_sensor_evt_status(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA((sens->assert_states >> 8) & 0xff);
     IPMI_ADD_RSP_DATA(sens->deassert_states & 0xff);
     IPMI_ADD_RSP_DATA((sens->deassert_states >> 8) & 0xff);
- out:
-    return;
 }
 
 static void get_sensor_reading(IPMIBmcSim *ibs,
@@ -1561,7 +1505,7 @@ static void get_sensor_reading(IPMIBmcSim *ibs,
     if ((cmd[2] > MAX_SENSORS) ||
             !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
-        goto out;
+        return;
     }
     sens = ibs->sensors + cmd[2];
     IPMI_ADD_RSP_DATA(sens->reading);
@@ -1570,8 +1514,6 @@ static void get_sensor_reading(IPMIBmcSim *ibs,
     if (IPMI_SENSOR_IS_DISCRETE(sens)) {
         IPMI_ADD_RSP_DATA((sens->states >> 8) & 0xff);
     }
- out:
-    return;
 }
 
 static const IPMICmdHandler chassis_cmds[IPMI_NETFN_CHASSIS_MAXCMD] = {
Signature · 1 line
MST
#21 lore raw

[Qemu-devel] [PULL 19/49] ipmi: replace *_MAXCMD defines

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

ARRAY_SIZE() is simple to use and removes the need to pre-define the size of the command arrays.

---
 hw/ipmi/ipmi_bmc_sim.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +8 -13
index 1f06dfc..f7e87b4 100644
@@ -28,14 +28,12 @@
 #include "qemu/error-report.h"
 
 #define IPMI_NETFN_CHASSIS            0x00
-#define IPMI_NETFN_CHASSIS_MAXCMD         0x03
 
 #define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
 #define IPMI_CMD_GET_CHASSIS_STATUS       0x01
 #define IPMI_CMD_CHASSIS_CONTROL          0x02
 
 #define IPMI_NETFN_SENSOR_EVENT       0x04
-#define IPMI_NETFN_SENSOR_EVENT_MAXCMD    0x2e
 
 #define IPMI_CMD_SET_SENSOR_EVT_ENABLE    0x28
 #define IPMI_CMD_GET_SENSOR_EVT_ENABLE    0x29
@@ -44,7 +42,6 @@
 #define IPMI_CMD_GET_SENSOR_READING       0x2d
 
 /* #define IPMI_NETFN_APP             0x06 In ipmi.h */
-#define IPMI_NETFN_APP_MAXCMD             0x36
 
 #define IPMI_CMD_GET_DEVICE_ID            0x01
 #define IPMI_CMD_COLD_RESET               0x02
@@ -61,7 +58,6 @@
 #define IPMI_CMD_READ_EVT_MSG_BUF         0x35
 
 #define IPMI_NETFN_STORAGE            0x0a
-#define IPMI_NETFN_STORAGE_MAXCMD         0x4a
 
 #define IPMI_CMD_GET_SDR_REP_INFO         0x20
 #define IPMI_CMD_GET_SDR_REP_ALLOC_INFO   0x21
@@ -1516,18 +1512,17 @@ static void get_sensor_reading(IPMIBmcSim *ibs,
     }
 }
 
-static const IPMICmdHandler chassis_cmds[IPMI_NETFN_CHASSIS_MAXCMD] = {
+static const IPMICmdHandler chassis_cmds[] = {
     [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities,
     [IPMI_CMD_GET_CHASSIS_STATUS] = chassis_status,
     [IPMI_CMD_CHASSIS_CONTROL] = chassis_control
 };
 static const IPMINetfn chassis_netfn = {
-    .cmd_nums = IPMI_NETFN_CHASSIS_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(chassis_cmds),
     .cmd_handlers = chassis_cmds
 };
 
-static const IPMICmdHandler
-sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
+static const IPMICmdHandler sensor_event_cmds[] = {
     [IPMI_CMD_SET_SENSOR_EVT_ENABLE] = set_sensor_evt_enable,
     [IPMI_CMD_GET_SENSOR_EVT_ENABLE] = get_sensor_evt_enable,
     [IPMI_CMD_REARM_SENSOR_EVTS] = rearm_sensor_evts,
@@ -1535,11 +1530,11 @@ sensor_event_cmds[IPMI_NETFN_SENSOR_EVENT_MAXCMD] = {
     [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading
 };
 static const IPMINetfn sensor_event_netfn = {
-    .cmd_nums = IPMI_NETFN_SENSOR_EVENT_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(sensor_event_cmds),
     .cmd_handlers = sensor_event_cmds
 };
 
-static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
+static const IPMICmdHandler app_cmds[] = {
     [IPMI_CMD_GET_DEVICE_ID] = get_device_id,
     [IPMI_CMD_COLD_RESET] = cold_reset,
     [IPMI_CMD_WARM_RESET] = warm_reset,
@@ -1555,11 +1550,11 @@ static const IPMICmdHandler app_cmds[IPMI_NETFN_APP_MAXCMD] = {
     [IPMI_CMD_GET_WATCHDOG_TIMER] = get_watchdog_timer,
 };
 static const IPMINetfn app_netfn = {
-    .cmd_nums = IPMI_NETFN_APP_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(app_cmds),
     .cmd_handlers = app_cmds
 };
 
-static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
+static const IPMICmdHandler storage_cmds[] = {
     [IPMI_CMD_GET_SDR_REP_INFO] = get_sdr_rep_info,
     [IPMI_CMD_RESERVE_SDR_REP] = reserve_sdr_rep,
     [IPMI_CMD_GET_SDR] = get_sdr,
@@ -1575,7 +1570,7 @@ static const IPMICmdHandler storage_cmds[IPMI_NETFN_STORAGE_MAXCMD] = {
 };
 
 static const IPMINetfn storage_netfn = {
-    .cmd_nums = IPMI_NETFN_STORAGE_MAXCMD,
+    .cmd_nums = ARRAY_SIZE(storage_cmds),
     .cmd_handlers = storage_cmds
 };
 
Signature · 1 line
MST
#22 lore raw

[Qemu-devel] [PULL 20/49] ipmi: cleanup error_report messages

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

---
 hw/ipmi/ipmi_bmc_sim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +2 -2
index f7e87b4..d8ca76a 100644
@@ -1644,7 +1644,7 @@ static void ipmi_sim_init(Object *obj)
     for (i = 0;;) {
         int len;
         if ((i + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x: \n", i);
+            error_report("Problem with recid 0x%4.4x", i);
             return;
         }
         len = init_sdrs[i + 4];
@@ -1653,7 +1653,7 @@ static void ipmi_sim_init(Object *obj)
             break;
         }
         if ((i + len + 5) > sizeof(init_sdrs)) {
-            error_report("Problem with recid 0x%4.4x\n", i);
+            error_report("Problem with recid 0x%4.4x", i);
             return;
         }
         sdr_add_entry(ibs, init_sdrs + i, len, NULL);
Signature · 1 line
MST
#23 lore raw

[Qemu-devel] [PULL 21/49] ipmi: fix SDR length value

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

The IPMI BMC simulator populates the SDR table with a set of initial SDRs. The length of each SDR is taken from the record itself (byte 4) which does not include the size of the header. But, the full length (header + data) is required by the sdr_add_entry() routine.

---
 hw/ipmi/ipmi_bmc_sim.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/ipmi/ipmi_bmc_sim.c +6 -6
index d8ca76a..73a4f6a 100644
@@ -356,7 +356,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid,
 
     while (pos < sdr->next_free) {
         uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8);
-        unsigned int nextpos = pos + sdr->sdr[pos + 4];
+        unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5;
 
         if (trec == recid) {
             if (nextrec) {
@@ -1164,7 +1164,7 @@ static void get_sdr(IPMIBmcSim *ibs,
         rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
         return;
     }
-    if (cmd[6] > (ibs->sdr.sdr[pos + 4])) {
+    if (cmd[6] > (ibs->sdr.sdr[pos + 4] + 5)) {
         rsp[2] = IPMI_CC_PARM_OUT_OF_RANGE;
         return;
     }
@@ -1173,7 +1173,7 @@ static void get_sdr(IPMIBmcSim *ibs,
     IPMI_ADD_RSP_DATA((nextrec >> 8) & 0xff);
 
     if (cmd[7] == 0xff) {
-        cmd[7] = ibs->sdr.sdr[pos + 4] - cmd[6];
+        cmd[7] = ibs->sdr.sdr[pos + 4] + 5 - cmd[6];
     }
 
     if ((cmd[7] + *rsp_len) > max_rsp_len) {
@@ -1647,17 +1647,17 @@ static void ipmi_sim_init(Object *obj)
             error_report("Problem with recid 0x%4.4x", i);
             return;
         }
-        len = init_sdrs[i + 4];
+        len = init_sdrs[i + 4] + 5;
         recid = init_sdrs[i] | (init_sdrs[i + 1] << 8);
         if (recid == 0xffff) {
             break;
         }
-        if ((i + len + 5) > sizeof(init_sdrs)) {
+        if ((i + len) > sizeof(init_sdrs)) {
             error_report("Problem with recid 0x%4.4x", i);
             return;
         }
         sdr_add_entry(ibs, init_sdrs + i, len, NULL);
-        i += len + 5;
+        i += len;
     }
 
     ipmi_init_sensors_from_sdrs(ibs);
Signature · 1 line
MST
#24 lore raw

[Qemu-devel] [PULL 22/49] ipmi: introduce a struct ipmi_sdr_compact

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

Currently, sdr attributes are identified using byte offsets and this can be a bit confusing.

This patch adds a struct ipmi_sdr_compact conforming to the IPMI specs and replaces byte offsets with names. It also introduces and uses a struct ipmi_sdr_header in sections of the code where no assumption is made on the type of SDR. This leave rooms to potential usage of other types in the future.

---
 include/hw/ipmi/ipmi.h | 45 +++++++++++++++++++++++++++++++
 hw/ipmi/ipmi_bmc_sim.c | 72 ++++++++++++++++++++++++++++++--------------------
 2 files changed, 89 insertions(+), 28 deletions(-)
include/hw/ipmi/ipmi.h +45 -0
index 32bac0f..74a2b5a 100644
@@ -210,4 +210,49 @@ IPMIFwInfo *ipmi_next_fwinfo(IPMIFwInfo *current);
 #define ipmi_debug(fs, ...)
 #endif
 
+struct ipmi_sdr_header {
+    uint8_t  rec_id[2];
+    uint8_t  sdr_version;               /* 0x51 */
+    uint8_t  rec_type;
+    uint8_t  rec_length;
+};
+#define IPMI_SDR_HEADER_SIZE     sizeof(struct ipmi_sdr_header)
+
+#define ipmi_sdr_recid(sdr) ((sdr)->rec_id[0] | ((sdr)->rec_id[1] << 8))
+#define ipmi_sdr_length(sdr) ((sdr)->rec_length + IPMI_SDR_HEADER_SIZE)
+
+/*
+ * 43.2 SDR Type 02h. Compact Sensor Record
+ */
+#define IPMI_SDR_COMPACT_TYPE    2
+
+struct ipmi_sdr_compact {
+    struct ipmi_sdr_header header;
+
+    uint8_t  sensor_owner_id;
+    uint8_t  sensor_owner_lun;
+    uint8_t  sensor_owner_number;       /* byte 8 */
+    uint8_t  entity_id;
+    uint8_t  entity_instance;
+    uint8_t  sensor_init;
+    uint8_t  sensor_caps;
+    uint8_t  sensor_type;
+    uint8_t  reading_type;
+    uint8_t  assert_mask[2];            /* byte 16 */
+    uint8_t  deassert_mask[2];
+    uint8_t  discrete_mask[2];
+    uint8_t  sensor_unit1;
+    uint8_t  sensor_unit2;
+    uint8_t  sensor_unit3;
+    uint8_t  sensor_direction[2];       /* byte 24 */
+    uint8_t  positive_threshold;
+    uint8_t  negative_threshold;
+    uint8_t  reserved[3];
+    uint8_t  oem;
+    uint8_t  id_str_len;                /* byte 32 */
+    uint8_t  id_string[16];
+};
+
+typedef uint8_t ipmi_sdr_compact_buffer[sizeof(struct ipmi_sdr_compact)];
+
 #endif
hw/ipmi/ipmi_bmc_sim.c +44 -28

153 lines not on this page · raw message

Signature · 1 line
MST
#25 lore raw

[Qemu-devel] [PULL 23/49] ipmi: add get and set SENSOR_TYPE commands

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

---
 hw/ipmi/ipmi_bmc_sim.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +44 -1
index 84fbcd2..24a4b32 100644
@@ -40,6 +40,8 @@
 #define IPMI_CMD_REARM_SENSOR_EVTS        0x2a
 #define IPMI_CMD_GET_SENSOR_EVT_STATUS    0x2b
 #define IPMI_CMD_GET_SENSOR_READING       0x2d
+#define IPMI_CMD_SET_SENSOR_TYPE          0x2e
+#define IPMI_CMD_GET_SENSOR_TYPE          0x2f
 
 /* #define IPMI_NETFN_APP             0x06 In ipmi.h */
 
@@ -1526,6 +1528,45 @@ static void get_sensor_reading(IPMIBmcSim *ibs,
     }
 }
 
+static void set_sensor_type(IPMIBmcSim *ibs,
+                               uint8_t *cmd, unsigned int cmd_len,
+                               uint8_t *rsp, unsigned int *rsp_len,
+                               unsigned int max_rsp_len)
+{
+    IPMISensor *sens;
+
+
+    IPMI_CHECK_CMD_LEN(5);
+    if ((cmd[2] > MAX_SENSORS) ||
+            !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
+        rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
+        return;
+    }
+    sens = ibs->sensors + cmd[2];
+    sens->sensor_type = cmd[3];
+    sens->evt_reading_type_code = cmd[4] & 0x7f;
+}
+
+static void get_sensor_type(IPMIBmcSim *ibs,
+                               uint8_t *cmd, unsigned int cmd_len,
+                               uint8_t *rsp, unsigned int *rsp_len,
+                               unsigned int max_rsp_len)
+{
+    IPMISensor *sens;
+
+
+    IPMI_CHECK_CMD_LEN(3);
+    if ((cmd[2] > MAX_SENSORS) ||
+            !IPMI_SENSOR_GET_PRESENT(ibs->sensors + cmd[2])) {
+        rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT;
+        return;
+    }
+    sens = ibs->sensors + cmd[2];
+    IPMI_ADD_RSP_DATA(sens->sensor_type);
+    IPMI_ADD_RSP_DATA(sens->evt_reading_type_code);
+}
+
+
 static const IPMICmdHandler chassis_cmds[] = {
     [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities,
     [IPMI_CMD_GET_CHASSIS_STATUS] = chassis_status,
@@ -1541,7 +1582,9 @@ static const IPMICmdHandler sensor_event_cmds[] = {
     [IPMI_CMD_GET_SENSOR_EVT_ENABLE] = get_sensor_evt_enable,
     [IPMI_CMD_REARM_SENSOR_EVTS] = rearm_sensor_evts,
     [IPMI_CMD_GET_SENSOR_EVT_STATUS] = get_sensor_evt_status,
-    [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading
+    [IPMI_CMD_GET_SENSOR_READING] = get_sensor_reading,
+    [IPMI_CMD_SET_SENSOR_TYPE] = set_sensor_type,
+    [IPMI_CMD_GET_SENSOR_TYPE] = get_sensor_type,
 };
 static const IPMINetfn sensor_event_netfn = {
     .cmd_nums = ARRAY_SIZE(sensor_event_cmds),
Signature · 1 line
MST
#26 lore raw

[Qemu-devel] [PULL 24/49] ipmi: add GET_SYS_RESTART_CAUSE chassis command

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

This is a simulator. Just return an unknown cause (0).

---
 hw/ipmi/ipmi_bmc_sim.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +15 -1
index 24a4b32..29224dd 100644
@@ -32,6 +32,7 @@
 #define IPMI_CMD_GET_CHASSIS_CAPABILITIES 0x00
 #define IPMI_CMD_GET_CHASSIS_STATUS       0x01
 #define IPMI_CMD_CHASSIS_CONTROL          0x02
+#define IPMI_CMD_GET_SYS_RESTART_CAUSE    0x09
 
 #define IPMI_NETFN_SENSOR_EVENT       0x04
 
@@ -195,6 +196,8 @@ struct IPMIBmcSim {
     uint8_t mfg_id[3];
     uint8_t product_id[2];
 
+    uint8_t restart_cause;
+
     IPMISel sel;
     IPMISdr sdr;
     IPMISensor sensors[MAX_SENSORS];
@@ -754,6 +757,15 @@ static void chassis_control(IPMIBmcSim *ibs,
     }
 }
 
+static void chassis_get_sys_restart_cause(IPMIBmcSim *ibs,
+                           uint8_t *cmd, unsigned int cmd_len,
+                           uint8_t *rsp, unsigned int *rsp_len,
+                           unsigned int max_rsp_len)
+{
+    IPMI_ADD_RSP_DATA(ibs->restart_cause & 0xf); /* Restart Cause */
+    IPMI_ADD_RSP_DATA(0);  /* Channel 0 */
+}
+
 static void get_device_id(IPMIBmcSim *ibs,
                           uint8_t *cmd, unsigned int cmd_len,
                           uint8_t *rsp, unsigned int *rsp_len,
@@ -1570,7 +1582,8 @@ static void get_sensor_type(IPMIBmcSim *ibs,
 static const IPMICmdHandler chassis_cmds[] = {
     [IPMI_CMD_GET_CHASSIS_CAPABILITIES] = chassis_capabilities,
     [IPMI_CMD_GET_CHASSIS_STATUS] = chassis_status,
-    [IPMI_CMD_CHASSIS_CONTROL] = chassis_control
+    [IPMI_CMD_CHASSIS_CONTROL] = chassis_control,
+    [IPMI_CMD_GET_SYS_RESTART_CAUSE] = chassis_get_sys_restart_cause
 };
 static const IPMINetfn chassis_netfn = {
     .cmd_nums = ARRAY_SIZE(chassis_cmds),
@@ -1691,6 +1704,7 @@ static void ipmi_sim_init(Object *obj)
     ibs->bmc_global_enables = (1 << IPMI_BMC_EVENT_LOG_BIT);
     ibs->device_id = 0x20;
     ibs->ipmi_version = 0x02; /* IPMI 2.0 */
+    ibs->restart_cause = 0;
     for (i = 0; i < 4; i++) {
         ibs->sel.last_addition[i] = 0xff;
         ibs->sel.last_clear[i] = 0xff;
Signature · 1 line
MST
#27 lore raw

[Qemu-devel] [PULL 25/49] ipmi: add ACPI power and GUID commands

In reply to Michael S. Tsirkin

From: Cédric Le Goater <[email protected]>

Quoted 1 line

From the specs (20.8 Get Device GUID Command), the command needs to

return a GUID (Globally Unique ID), or UUID, that should never change over the lifetime of the device. qemu_uuid looked like a good candidate to start with but we could use a specific BMC property also if needed.

---
 hw/ipmi/ipmi_bmc_sim.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
hw/ipmi/ipmi_bmc_sim.c +49 -0
index 29224dd..e1ad19b 100644
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "sysemu/sysemu.h"
 #include "qemu/timer.h"
 #include "hw/ipmi/ipmi.h"
 #include "qemu/error-report.h"
@@ -49,6 +50,9 @@
 #define IPMI_CMD_GET_DEVICE_ID            0x01
 #define IPMI_CMD_COLD_RESET               0x02
 #define IPMI_CMD_WARM_RESET               0x03
+#define IPMI_CMD_SET_ACPI_POWER_STATE     0x06
+#define IPMI_CMD_GET_ACPI_POWER_STATE     0x07
+#define IPMI_CMD_GET_DEVICE_GUID          0x08
 #define IPMI_CMD_RESET_WATCHDOG_TIMER     0x22
 #define IPMI_CMD_SET_WATCHDOG_TIMER       0x24
 #define IPMI_CMD_GET_WATCHDOG_TIMER       0x25
@@ -198,6 +202,9 @@ struct IPMIBmcSim {
 
     uint8_t restart_cause;
 
+    uint8_t acpi_power_state[2];
+    uint8_t uuid[16];
+
     IPMISel sel;
     IPMISdr sdr;
     IPMISensor sensors[MAX_SENSORS];
@@ -826,6 +833,36 @@ static void warm_reset(IPMIBmcSim *ibs,
         k->reset(s, false);
     }
 }
+static void set_acpi_power_state(IPMIBmcSim *ibs,
+                          uint8_t *cmd, unsigned int cmd_len,
+                          uint8_t *rsp, unsigned int *rsp_len,
+                          unsigned int max_rsp_len)
+{
+    IPMI_CHECK_CMD_LEN(4);
+    ibs->acpi_power_state[0] = cmd[2];
+    ibs->acpi_power_state[1] = cmd[3];
+}
+
+static void get_acpi_power_state(IPMIBmcSim *ibs,
+                          uint8_t *cmd, unsigned int cmd_len,
+                          uint8_t *rsp, unsigned int *rsp_len,
+                          unsigned int max_rsp_len)
+{
+    IPMI_ADD_RSP_DATA(ibs->acpi_power_state[0]);
+    IPMI_ADD_RSP_DATA(ibs->acpi_power_state[1]);
+}
+
+static void get_device_guid(IPMIBmcSim *ibs,
+                          uint8_t *cmd, unsigned int cmd_len,
+                          uint8_t *rsp, unsigned int *rsp_len,
+                          unsigned int max_rsp_len)
+{
+    unsigned int i;
+
+    for (i = 0; i < 16; i++) {
+        IPMI_ADD_RSP_DATA(ibs->uuid[i]);
+    }
+}
 
 static void set_bmc_global_enables(IPMIBmcSim *ibs,
                                    uint8_t *cmd, unsigned int cmd_len,
@@ -1608,6 +1645,9 @@ static const IPMICmdHandler app_cmds[] = {
     [IPMI_CMD_GET_DEVICE_ID] = get_device_id,
     [IPMI_CMD_COLD_RESET] = cold_reset,
     [IPMI_CMD_WARM_RESET] = warm_reset,
+    [IPMI_CMD_SET_ACPI_POWER_STATE] = set_acpi_power_state,
+    [IPMI_CMD_GET_ACPI_POWER_STATE] = get_acpi_power_state,
+    [IPMI_CMD_GET_DEVICE_GUID] = get_device_guid,
     [IPMI_CMD_SET_BMC_GLOBAL_ENABLES] = set_bmc_global_enables,
     [IPMI_CMD_GET_BMC_GLOBAL_ENABLES] = get_bmc_global_enables,
     [IPMI_CMD_CLR_MSG_FLAGS] = clr_msg_flags,
@@ -1733,6 +1773,15 @@ static void ipmi_sim_init(Object *obj)
         i += len;
     }
 
+    ibs->acpi_power_state[0] = 0;
+    ibs->acpi_power_state[1] = 0;
+
+    if (qemu_uuid_set) {
+        memcpy(&ibs->uuid, qemu_uuid, 16);
+    } else {
+        memset(&ibs->uuid, 0, 16);
+    }
+
     ipmi_init_sensors_from_sdrs(ibs);
     register_cmds(ibs);
 
Signature · 1 line
MST
#28 lore raw

[Qemu-devel] [PULL 26/49] pc: Move PcGuestInfo declaration to top of file

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The struct will be used inside PCMachineState.

---
 include/hw/i386/pc.h | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)
include/hw/i386/pc.h +16 -15
index 65e8f24..212eb7d 100644
@@ -33,6 +33,22 @@
 #define kvm_ioapic_in_kernel()   0
 #endif
 
+/* Machine info for ACPI build: */
+struct PcGuestInfo {
+    bool isapc_ram_fw;
+    hwaddr ram_size, ram_size_below_4g;
+    unsigned apic_id_limit;
+    bool apic_xrupt_override;
+    uint64_t numa_nodes;
+    uint64_t *node_mem;
+    uint64_t *node_cpu;
+    FWCfgState *fw_cfg;
+    int legacy_acpi_table_size;
+    bool has_acpi_build;
+    bool has_reserved_memory;
+    bool rsdp_in_ram;
+};
+
 /**
  * PCMachineState:
  * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
@@ -151,21 +167,6 @@ typedef struct PcPciInfo {
 #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
 #define ACPI_PM_PROP_TCO_ENABLED "enable_tco"
 
-struct PcGuestInfo {
-    bool isapc_ram_fw;
-    hwaddr ram_size, ram_size_below_4g;
-    unsigned apic_id_limit;
-    bool apic_xrupt_override;
-    uint64_t numa_nodes;
-    uint64_t *node_mem;
-    uint64_t *node_cpu;
-    FWCfgState *fw_cfg;
-    int legacy_acpi_table_size;
-    bool has_acpi_build;
-    bool has_reserved_memory;
-    bool rsdp_in_ram;
-};
-
 /* parallel.c */
 
 void parallel_hds_isa_init(ISABus *bus, int n);
Signature · 1 line
MST
#29 lore raw

[Qemu-devel] [PULL 27/49] pc: Eliminate struct PcGuestInfoState

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

Instead of allocating a new struct just for PcGuestInfo and the mchine_done Notifier, place them inside PCMachineState.

---
 include/hw/i386/pc.h |  2 ++
 hw/i386/pc.c         | 27 ++++++++++-----------------
 2 files changed, 12 insertions(+), 17 deletions(-)
include/hw/i386/pc.h +2 -0
index 212eb7d..9d0b004 100644
@@ -61,6 +61,8 @@ struct PCMachineState {
 
     /* State for other subsystems/APIs: */
     MemoryHotplugState hotplug_memory;
+    PcGuestInfo acpi_guest_info;
+    Notifier machine_done;
 
     /* Pointers to devices and objects: */
     HotplugHandler *acpi_dev;
hw/i386/pc.c +10 -17
index 942ac06..c421d2c 100644
@@ -1156,18 +1156,12 @@ typedef struct PcRomPciInfo {
     uint64_t w64_max;
 } PcRomPciInfo;
 
-typedef struct PcGuestInfoState {
-    PcGuestInfo info;
-    Notifier machine_done;
-} PcGuestInfoState;
-
 static
-void pc_guest_info_machine_done(Notifier *notifier, void *data)
+void pc_machine_done(Notifier *notifier, void *data)
 {
-    PcGuestInfoState *guest_info_state = container_of(notifier,
-                                                      PcGuestInfoState,
-                                                      machine_done);
-    PCIBus *bus = PC_MACHINE(qdev_get_machine())->bus;
+    PCMachineState *pcms = container_of(notifier,
+                                        PCMachineState, machine_done);
+    PCIBus *bus = pcms->bus;
 
     if (bus) {
         int extra_hosts = 0;
@@ -1178,21 +1172,20 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)
                 extra_hosts++;
             }
         }
-        if (extra_hosts && guest_info_state->info.fw_cfg) {
+        if (extra_hosts && pcms->acpi_guest_info.fw_cfg) {
             uint64_t *val = g_malloc(sizeof(*val));
             *val = cpu_to_le64(extra_hosts);
-            fw_cfg_add_file(guest_info_state->info.fw_cfg,
+            fw_cfg_add_file(pcms->acpi_guest_info.fw_cfg,
                     "etc/extra-pci-roots", val, sizeof(*val));
         }
     }
 
-    acpi_setup(&guest_info_state->info);
+    acpi_setup(&pcms->acpi_guest_info);
 }
 
 PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
 {
-    PcGuestInfoState *guest_info_state = g_malloc0(sizeof *guest_info_state);
-    PcGuestInfo *guest_info = &guest_info_state->info;
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int i, j;
 
     guest_info->ram_size_below_4g = pcms->below_4g_mem_size;
@@ -1220,8 +1213,8 @@ PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
         }
     }
 
-    guest_info_state->machine_done.notify = pc_guest_info_machine_done;
-    qemu_add_machine_init_done_notifier(&guest_info_state->machine_done);
+    pcms->machine_done.notify = pc_machine_done;
+    qemu_add_machine_init_done_notifier(&pcms->machine_done);
     return guest_info;
 }
 
Signature · 1 line
MST
#30 lore raw

[Qemu-devel] [PULL 28/49] pc: Simplify pc_memory_init() signature

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

We can get the PcGuestInfo struct directly from PCMachineState, and the return value is not needed at all.

---
 include/hw/i386/pc.h |  9 ++++-----
 hw/i386/pc.c         | 11 +++++------
 hw/i386/pc_piix.c    |  2 +-
 hw/i386/pc_q35.c     |  2 +-
 4 files changed, 11 insertions(+), 13 deletions(-)
include/hw/i386/pc.h +4 -5
index 9d0b004..5b21d01 100644
@@ -250,11 +250,10 @@ void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory,
 
 FWCfgState *xen_load_linux(PCMachineState *pcms,
                            PcGuestInfo *guest_info);
-FWCfgState *pc_memory_init(PCMachineState *pcms,
-                           MemoryRegion *system_memory,
-                           MemoryRegion *rom_memory,
-                           MemoryRegion **ram_memory,
-                           PcGuestInfo *guest_info);
+void pc_memory_init(PCMachineState *pcms,
+                    MemoryRegion *system_memory,
+                    MemoryRegion *rom_memory,
+                    MemoryRegion **ram_memory);
 qemu_irq pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
 void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
hw/i386/pc.c +5 -6
index c421d2c..fbdad88 100644
@@ -1276,12 +1276,12 @@ FWCfgState *xen_load_linux(PCMachineState *pcms,
     return fw_cfg;
 }
 
-FWCfgState *pc_memory_init(PCMachineState *pcms,
-                           MemoryRegion *system_memory,
-                           MemoryRegion *rom_memory,
-                           MemoryRegion **ram_memory,
-                           PcGuestInfo *guest_info)
+void pc_memory_init(PCMachineState *pcms,
+                    MemoryRegion *system_memory,
+                    MemoryRegion *rom_memory,
+                    MemoryRegion **ram_memory)
 {
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
@@ -1403,7 +1403,6 @@ FWCfgState *pc_memory_init(PCMachineState *pcms,
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
     guest_info->fw_cfg = fw_cfg;
-    return fw_cfg;
 }
 
 qemu_irq pc_allocate_cpu_irq(void)
hw/i386/pc_piix.c +1 -1
index 9951d6e..ad51fd6 100644
@@ -162,7 +162,7 @@ static void pc_init1(MachineState *machine,
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
-                       rom_memory, &ram_memory, guest_info);
+                       rom_memory, &ram_memory);
     } else if (machine->kernel_filename != NULL) {
         /* For xen HVM direct kernel boot, load linux here */
         xen_load_linux(pcms, guest_info);
hw/i386/pc_q35.c +1 -1
index 56be9b1..0c156e2 100644
@@ -156,7 +156,7 @@ static void pc_q35_init(MachineState *machine)
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
         pc_memory_init(pcms, get_system_memory(),
-                       rom_memory, &ram_memory, guest_info);
+                       rom_memory, &ram_memory);
     }
 
     /* irq lines */
Signature · 1 line
MST
#31 lore raw

[Qemu-devel] [PULL 29/49] pc: Simplify xen_load_linux() signature

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

We can get the PcGuestInfo struct directly from PCMachineState, and the return value is not needed at all.

---
 include/hw/i386/pc.h | 3 +--
 hw/i386/pc.c         | 5 ++---
 hw/i386/pc_piix.c    | 2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)
include/hw/i386/pc.h +1 -2
index 5b21d01..223621a 100644
@@ -248,8 +248,7 @@ PcGuestInfo *pc_guest_info_init(PCMachineState *pcms);
 void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory,
                             MemoryRegion *pci_address_space);
 
-FWCfgState *xen_load_linux(PCMachineState *pcms,
-                           PcGuestInfo *guest_info);
+void xen_load_linux(PCMachineState *pcms);
 void pc_memory_init(PCMachineState *pcms,
                     MemoryRegion *system_memory,
                     MemoryRegion *rom_memory,
hw/i386/pc.c +2 -3
index fbdad88..9745dca 100644
@@ -1255,11 +1255,11 @@ void pc_acpi_init(const char *default_dsdt)
     }
 }
 
-FWCfgState *xen_load_linux(PCMachineState *pcms,
-                           PcGuestInfo *guest_info)
+void xen_load_linux(PCMachineState *pcms)
 {
     int i;
     FWCfgState *fw_cfg;
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
 
     assert(MACHINE(pcms)->kernel_filename != NULL);
 
@@ -1273,7 +1273,6 @@ FWCfgState *xen_load_linux(PCMachineState *pcms,
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
     guest_info->fw_cfg = fw_cfg;
-    return fw_cfg;
 }
 
 void pc_memory_init(PCMachineState *pcms,
hw/i386/pc_piix.c +1 -1
index ad51fd6..4262c32 100644
@@ -165,7 +165,7 @@ static void pc_init1(MachineState *machine,
                        rom_memory, &ram_memory);
     } else if (machine->kernel_filename != NULL) {
         /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms, guest_info);
+        xen_load_linux(pcms);
     }
 
     gsi_state = g_malloc0(sizeof(*gsi_state));
Signature · 1 line
MST
#32 lore raw

[Qemu-devel] [PULL 30/49] acpi: Remove guest_info parameters from functions

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

We can use PC_MACHINE(qdev_get_machine())->acpi_guest_info to get guest_info.

---
 hw/i386/acpi-build.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
hw/i386/acpi-build.c +21 -14
index 2028ed7..e41a2ae 100644
@@ -290,7 +290,7 @@ static void acpi_align_size(GArray *blob, unsigned align)
 
 /* FACS */
 static void
-build_facs(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
+build_facs(GArray *table_data, GArray *linker)
 {
     AcpiFacsDescriptorRev1 *facs = acpi_data_push(table_data, sizeof *facs);
     memcpy(&facs->signature, "FACS", 4);
@@ -361,9 +361,10 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
 }
 
 static void
-build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
-           PcGuestInfo *guest_info)
+build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
 {
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int madt_start = table_data->len;
 
     AcpiMultipleApicTable *madt;
@@ -1937,13 +1938,15 @@ static Aml *build_q35_osc_method(void)
 static void
 build_dsdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
-           PcPciInfo *pci, PcGuestInfo *guest_info)
+           PcPciInfo *pci)
 {
     CrsRangeEntry *entry;
     Aml *dsdt, *sb_scope, *scope, *dev, *method, *field, *pkg, *crs;
     GPtrArray *mem_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     GPtrArray *io_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     MachineState *machine = MACHINE(qdev_get_machine());
+    PCMachineState *pcms = PC_MACHINE(machine);
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     uint32_t nr_mem = machine->ram_slots;
     int root_bus_limit = 0xFF;
     PCIBus *bus = NULL;
@@ -2365,7 +2368,7 @@ acpi_build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
 }
 
 static void
-build_srat(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
+build_srat(GArray *table_data, GArray *linker)
 {
     AcpiSystemResourceAffinityTable *srat;
     AcpiSratProcessorAffinity *core;
@@ -2376,6 +2379,7 @@ build_srat(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
     int srat_start, numa_start, slots;
     uint64_t mem_len, mem_base, next_base;
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     ram_addr_t hotplugabble_address_space_size =
         object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE,
                                 NULL);
@@ -2587,8 +2591,10 @@ static bool acpi_has_nvdimm(void)
 }
 
 static
-void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
+void acpi_build(AcpiBuildTables *tables)
 {
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     GArray *table_offsets;
     unsigned facs, dsdt, rsdt, fadt;
     AcpiCpuInfo cpu;
@@ -2619,12 +2625,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
      * requirements.
      */
     facs = tables_blob->len;
-    build_facs(tables_blob, tables->linker, guest_info);
+    build_facs(tables_blob, tables->linker);
 
     /* DSDT is pointed to by FADT */
     dsdt = tables_blob->len;
-    build_dsdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci,
-               guest_info);
+    build_dsdt(tables_blob, tables->linker, &cpu, &pm, &misc, &pci);
 
     /* Count the size of the DSDT and SSDT, we will need it for legacy
      * sizing of ACPI tables.
@@ -2638,7 +2643,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     aml_len += tables_blob->len - fadt;
 
     acpi_add_table(table_offsets, tables_blob);
-    build_madt(tables_blob, tables->linker, &cpu, guest_info);
+    build_madt(tables_blob, tables->linker, &cpu);
 
     if (misc.has_hpet) {
         acpi_add_table(table_offsets, tables_blob);
@@ -2655,7 +2660,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
     }
     if (guest_info->numa_nodes) {
         acpi_add_table(table_offsets, tables_blob);
-        build_srat(tables_blob, tables->linker, guest_info);
+        build_srat(tables_blob, tables->linker);
     }
     if (acpi_get_mcfg(&mcfg)) {
         acpi_add_table(table_offsets, tables_blob);
@@ -2759,7 +2764,7 @@ static void acpi_build_update(void *build_opaque)
 
     acpi_build_tables_init(&tables);
 
-    acpi_build(build_state->guest_info, &tables);
+    acpi_build(&tables);
 
     acpi_ram_update(build_state->table_mr, tables.table_data);
 
@@ -2797,8 +2802,10 @@ static const VMStateDescription vmstate_acpi_build = {
     },
 };
 
-void acpi_setup(PcGuestInfo *guest_info)
+void acpi_setup(void)
 {
+    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
 
@@ -2824,7 +2831,7 @@ void acpi_setup(PcGuestInfo *guest_info)
     acpi_set_pci_info();
 
     acpi_build_tables_init(&tables);
-    acpi_build(build_state->guest_info, &tables);
+    acpi_build(&tables);
 
     /* Now expose it all to Guest */
     build_state->table_mr = acpi_add_rom_blob(build_state, tables.table_data,
Signature · 1 line
MST
#33 lore raw

[Qemu-devel] [PULL 31/49] acpi: Don't save PcGuestInfo on AcpiBuildState

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

We don't need to save the pointer on AcpiBuildState, as it is not used anymore.

---
 hw/i386/acpi-build.c | 3 ---
 1 file changed, 3 deletions(-)
hw/i386/acpi-build.c +0 -3
index e41a2ae..45c07ca 100644
@@ -2545,7 +2545,6 @@ struct AcpiBuildState {
     MemoryRegion *table_mr;
     /* Is table patched? */
     uint8_t patched;
-    PcGuestInfo *guest_info;
     void *rsdp;
     MemoryRegion *rsdp_mr;
     MemoryRegion *linker_mr;
@@ -2826,8 +2825,6 @@ void acpi_setup(void)
 
     build_state = g_malloc0(sizeof *build_state);
 
-    build_state->guest_info = guest_info;
-
     acpi_set_pci_info();
 
     acpi_build_tables_init(&tables);
Signature · 1 line
MST
#34 lore raw

[Qemu-devel] [PULL 32/49] pc: Remove compat fields from PcGuestInfo

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

Remove the fields: legacy_acpi_table_size, has_acpi_build, has_reserved_memory, and rsdp_in_ram from PcGuestInfo, and let the existing code use the PCMachineClass fields directly.

---
 hw/i386/acpi-build.h |  2 +-
 include/hw/i386/pc.h |  4 ----
 hw/i386/acpi-build.c | 10 ++++++----
 hw/i386/pc.c         |  8 ++++----
 hw/i386/pc_piix.c    |  5 -----
 hw/i386/pc_q35.c     |  8 --------
 6 files changed, 11 insertions(+), 26 deletions(-)
hw/i386/acpi-build.h +1 -1
index e57b1aa..148c0f9 100644
@@ -4,6 +4,6 @@
 
 #include "qemu/typedefs.h"
 
-void acpi_setup(PcGuestInfo *);
+void acpi_setup(void);
 
 #endif
include/hw/i386/pc.h +0 -4
index 223621a..4480409 100644
@@ -43,10 +43,6 @@ struct PcGuestInfo {
     uint64_t *node_mem;
     uint64_t *node_cpu;
     FWCfgState *fw_cfg;
-    int legacy_acpi_table_size;
-    bool has_acpi_build;
-    bool has_reserved_memory;
-    bool rsdp_in_ram;
 };
 
 /**
hw/i386/acpi-build.c +6 -4
index 45c07ca..7f574f2 100644
@@ -2593,6 +2593,7 @@ static
 void acpi_build(AcpiBuildTables *tables)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     GArray *table_offsets;
     unsigned facs, dsdt, rsdt, fadt;
@@ -2706,12 +2707,12 @@ void acpi_build(AcpiBuildTables *tables)
      *
      * All this is for PIIX4, since QEMU 2.0 didn't support Q35 migration.
      */
-    if (guest_info->legacy_acpi_table_size) {
+    if (pcmc->legacy_acpi_table_size) {
         /* Subtracting aml_len gives the size of fixed tables.  Then add the
          * size of the PIIX4 DSDT/SSDT in QEMU 2.0.
          */
         int legacy_aml_len =
-            guest_info->legacy_acpi_table_size +
+            pcmc->legacy_acpi_table_size +
             ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus;
         int legacy_table_size =
             ROUND_UP(tables_blob->len - aml_len + legacy_aml_len,
@@ -2804,6 +2805,7 @@ static const VMStateDescription vmstate_acpi_build = {
 void acpi_setup(void)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
+    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
@@ -2813,7 +2815,7 @@ void acpi_setup(void)
         return;
     }
 
-    if (!guest_info->has_acpi_build) {
+    if (!pcmc->has_acpi_build) {
         ACPI_BUILD_DPRINTF("ACPI build disabled. Bailing out.\n");
         return;
     }
@@ -2842,7 +2844,7 @@ void acpi_setup(void)
     fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
-    if (!guest_info->rsdp_in_ram) {
+    if (!pcmc->rsdp_in_ram) {
         /*
          * Keep for compatibility with old machine types.
          * Though RSDP is small, its contents isn't immutable, so
hw/i386/pc.c +4 -4
index 9745dca..3c59500 100644
@@ -1180,7 +1180,7 @@ void pc_machine_done(Notifier *notifier, void *data)
         }
     }
 
-    acpi_setup(&pcms->acpi_guest_info);
+    acpi_setup();
 }
 
 PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
@@ -1316,7 +1316,7 @@ void pc_memory_init(PCMachineState *pcms,
         e820_add_entry(0x100000000ULL, pcms->above_4g_mem_size, E820_RAM);
     }
 
-    if (!guest_info->has_reserved_memory &&
+    if (!pcmc->has_reserved_memory &&
         (machine->ram_slots ||
          (machine->maxram_size > machine->ram_size))) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -1327,7 +1327,7 @@ void pc_memory_init(PCMachineState *pcms,
     }
 
     /* initialize hotplug memory address space */
-    if (guest_info->has_reserved_memory &&
+    if (pcmc->has_reserved_memory &&
         (machine->ram_size < machine->maxram_size)) {
         ram_addr_t hotplug_mem_size =
             machine->maxram_size - machine->ram_size;
@@ -1382,7 +1382,7 @@ void pc_memory_init(PCMachineState *pcms,
 
     rom_set_fw(fw_cfg);
 
-    if (guest_info->has_reserved_memory && pcms->hotplug_memory.base) {
+    if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) {
         uint64_t *val = g_malloc(sizeof(*val));
         PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
         uint64_t res_mem_end = pcms->hotplug_memory.base;
hw/i386/pc_piix.c +0 -5
index 4262c32..584441a 100644
@@ -143,12 +143,7 @@ static void pc_init1(MachineState *machine,
 
     guest_info = pc_guest_info_init(pcms);
 
-    guest_info->has_acpi_build = pcmc->has_acpi_build;
-    guest_info->legacy_acpi_table_size = pcmc->legacy_acpi_table_size;
-
     guest_info->isapc_ram_fw = !pcmc->pci_enabled;
-    guest_info->has_reserved_memory = pcmc->has_reserved_memory;
-    guest_info->rsdp_in_ram = pcmc->rsdp_in_ram;
 
     if (pcmc->smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
hw/i386/pc_q35.c +0 -8
index 0c156e2..45e05f4 100644
@@ -136,14 +136,6 @@ static void pc_q35_init(MachineState *machine)
 
     guest_info = pc_guest_info_init(pcms);
     guest_info->isapc_ram_fw = false;
-    guest_info->has_acpi_build = pcmc->has_acpi_build;
-    guest_info->has_reserved_memory = pcmc->has_reserved_memory;
-    guest_info->rsdp_in_ram = pcmc->rsdp_in_ram;
-
-    /* Migration was not supported in 2.0 for Q35, so do not bother
-     * with this hack (see hw/i386/acpi-build.c).
-     */
-    guest_info->legacy_acpi_table_size = 0;
 
     if (pcmc->smbios_defaults) {
         /* These values are guest ABI, do not change */
Signature · 1 line
MST
#35 lore raw

[Qemu-devel] [PULL 33/49] pc: Remove RAM size fields from PcGuestInfo

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The ACPI code can use the PCMachineState fields directly.

---
 include/hw/i386/pc.h |  1 -
 hw/i386/acpi-build.c | 10 +++++-----
 hw/i386/pc.c         |  2 --
 3 files changed, 5 insertions(+), 8 deletions(-)
include/hw/i386/pc.h +0 -1
index 4480409..c27e680 100644
@@ -36,7 +36,6 @@
 /* Machine info for ACPI build: */
 struct PcGuestInfo {
     bool isapc_ram_fw;
-    hwaddr ram_size, ram_size_below_4g;
     unsigned apic_id_limit;
     bool apic_xrupt_override;
     uint64_t numa_nodes;
hw/i386/acpi-build.c +5 -5
index 7f574f2..dac7137 100644
@@ -2421,17 +2421,17 @@ build_srat(GArray *table_data, GArray *linker)
         next_base = mem_base + mem_len;
 
         /* Cut out the ACPI_PCI hole */
-        if (mem_base <= guest_info->ram_size_below_4g &&
-            next_base > guest_info->ram_size_below_4g) {
-            mem_len -= next_base - guest_info->ram_size_below_4g;
+        if (mem_base <= pcms->below_4g_mem_size &&
+            next_base > pcms->below_4g_mem_size) {
+            mem_len -= next_base - pcms->below_4g_mem_size;
             if (mem_len > 0) {
                 numamem = acpi_data_push(table_data, sizeof *numamem);
                 acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1,
                                        MEM_AFFINITY_ENABLED);
             }
             mem_base = 1ULL << 32;
-            mem_len = next_base - guest_info->ram_size_below_4g;
-            next_base += (1ULL << 32) - guest_info->ram_size_below_4g;
+            mem_len = next_base - pcms->below_4g_mem_size;
+            next_base += (1ULL << 32) - pcms->below_4g_mem_size;
         }
         numamem = acpi_data_push(table_data, sizeof *numamem);
         acpi_build_srat_memory(numamem, mem_base, mem_len, i - 1,
hw/i386/pc.c +0 -2
index 3c59500..f3fd0ed 100644
@@ -1188,8 +1188,6 @@ PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
     PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int i, j;
 
-    guest_info->ram_size_below_4g = pcms->below_4g_mem_size;
-    guest_info->ram_size = pcms->below_4g_mem_size + pcms->above_4g_mem_size;
     guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
     guest_info->apic_xrupt_override = kvm_allows_irq0_override();
     guest_info->numa_nodes = nb_numa_nodes;
Signature · 1 line
MST
#36 lore raw

[Qemu-devel] [PULL 34/49] pc: Remove PcGuestInfo.isapc_ram_fw field

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The code can use the PCMachineClass.pci_enabled field directly.

---
 include/hw/i386/pc.h | 1 -
 hw/i386/pc.c         | 2 +-
 hw/i386/pc_piix.c    | 5 +----
 hw/i386/pc_q35.c     | 4 +---
 4 files changed, 3 insertions(+), 9 deletions(-)
include/hw/i386/pc.h +0 -1
index c27e680..6a5c4da 100644
@@ -35,7 +35,6 @@
 
 /* Machine info for ACPI build: */
 struct PcGuestInfo {
-    bool isapc_ram_fw;
     unsigned apic_id_limit;
     bool apic_xrupt_override;
     uint64_t numa_nodes;
hw/i386/pc.c +1 -1
index f3fd0ed..dc0ade4 100644
@@ -1365,7 +1365,7 @@ void pc_memory_init(PCMachineState *pcms,
     }
 
     /* Initialize PC system firmware */
-    pc_system_firmware_init(rom_memory, guest_info->isapc_ram_fw);
+    pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
 
     option_rom_mr = g_malloc(sizeof(*option_rom_mr));
     memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
hw/i386/pc_piix.c +1 -4
index 584441a..6f8c2cd 100644
@@ -85,7 +85,6 @@ static void pc_init1(MachineState *machine,
     MemoryRegion *ram_memory;
     MemoryRegion *pci_memory;
     MemoryRegion *rom_memory;
-    PcGuestInfo *guest_info;
     ram_addr_t lowmem;
 
     /* Check whether RAM fits below 4G (leaving 1/2 GByte for IO memory).
@@ -141,9 +140,7 @@ static void pc_init1(MachineState *machine,
         rom_memory = system_memory;
     }
 
-    guest_info = pc_guest_info_init(pcms);
-
-    guest_info->isapc_ram_fw = !pcmc->pci_enabled;
+    pc_guest_info_init(pcms);
 
     if (pcmc->smbios_defaults) {
         MachineClass *mc = MACHINE_GET_CLASS(machine);
hw/i386/pc_q35.c +1 -3
index 45e05f4..208a224 100644
@@ -71,7 +71,6 @@ static void pc_q35_init(MachineState *machine)
     int i;
     ICH9LPCState *ich9_lpc;
     PCIDevice *ahci;
-    PcGuestInfo *guest_info;
     ram_addr_t lowmem;
     DriveInfo *hd[MAX_SATA_PORTS];
     MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -134,8 +133,7 @@ static void pc_q35_init(MachineState *machine)
         rom_memory = get_system_memory();
     }
 
-    guest_info = pc_guest_info_init(pcms);
-    guest_info->isapc_ram_fw = false;
+    pc_guest_info_init(pcms);
 
     if (pcmc->smbios_defaults) {
         /* These values are guest ABI, do not change */
Signature · 1 line
MST
#37 lore raw

[Qemu-devel] [PULL 35/49] pc: Move PcGuestInfo.fw_cfg to PCMachineState

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

---
 include/hw/i386/pc.h |  2 +-
 hw/i386/acpi-build.c |  7 +++----
 hw/i386/pc.c         | 10 ++++------
 3 files changed, 8 insertions(+), 11 deletions(-)
include/hw/i386/pc.h +1 -1
index 6a5c4da..40249b6 100644
@@ -40,7 +40,6 @@ struct PcGuestInfo {
     uint64_t numa_nodes;
     uint64_t *node_mem;
     uint64_t *node_cpu;
-    FWCfgState *fw_cfg;
 };
 
 /**
@@ -62,6 +61,7 @@ struct PCMachineState {
     HotplugHandler *acpi_dev;
     ISADevice *rtc;
     PCIBus *bus;
+    FWCfgState *fw_cfg;
 
     /* Configuration options: */
     uint64_t max_ram_below_4g;
hw/i386/acpi-build.c +3 -4
index dac7137..86baf63 100644
@@ -2806,11 +2806,10 @@ void acpi_setup(void)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     AcpiBuildTables tables;
     AcpiBuildState *build_state;
 
-    if (!guest_info->fw_cfg) {
+    if (!pcms->fw_cfg) {
         ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
         return;
     }
@@ -2841,7 +2840,7 @@ void acpi_setup(void)
     build_state->linker_mr =
         acpi_add_rom_blob(build_state, tables.linker, "etc/table-loader", 0);
 
-    fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
+    fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
     if (!pcmc->rsdp_in_ram) {
@@ -2853,7 +2852,7 @@ void acpi_setup(void)
         uint32_t rsdp_size = acpi_data_len(tables.rsdp);
 
         build_state->rsdp = g_memdup(tables.rsdp->data, rsdp_size);
-        fw_cfg_add_file_callback(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE,
+        fw_cfg_add_file_callback(pcms->fw_cfg, ACPI_BUILD_RSDP_FILE,
                                  acpi_build_update, build_state,
                                  build_state->rsdp, rsdp_size);
         build_state->rsdp_mr = NULL;
hw/i386/pc.c +4 -6
index dc0ade4..a47784a 100644
@@ -1172,10 +1172,10 @@ void pc_machine_done(Notifier *notifier, void *data)
                 extra_hosts++;
             }
         }
-        if (extra_hosts && pcms->acpi_guest_info.fw_cfg) {
+        if (extra_hosts && pcms->fw_cfg) {
             uint64_t *val = g_malloc(sizeof(*val));
             *val = cpu_to_le64(extra_hosts);
-            fw_cfg_add_file(pcms->acpi_guest_info.fw_cfg,
+            fw_cfg_add_file(pcms->fw_cfg,
                     "etc/extra-pci-roots", val, sizeof(*val));
         }
     }
@@ -1257,7 +1257,6 @@ void xen_load_linux(PCMachineState *pcms)
 {
     int i;
     FWCfgState *fw_cfg;
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
 
     assert(MACHINE(pcms)->kernel_filename != NULL);
 
@@ -1270,7 +1269,7 @@ void xen_load_linux(PCMachineState *pcms)
                !strcmp(option_rom[i].name, "multiboot.bin"));
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
-    guest_info->fw_cfg = fw_cfg;
+    pcms->fw_cfg = fw_cfg;
 }
 
 void pc_memory_init(PCMachineState *pcms,
@@ -1278,7 +1277,6 @@ void pc_memory_init(PCMachineState *pcms,
                     MemoryRegion *rom_memory,
                     MemoryRegion **ram_memory)
 {
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
@@ -1399,7 +1397,7 @@ void pc_memory_init(PCMachineState *pcms,
     for (i = 0; i < nb_option_roms; i++) {
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
-    guest_info->fw_cfg = fw_cfg;
+    pcms->fw_cfg = fw_cfg;
 }
 
 qemu_irq pc_allocate_cpu_irq(void)
Signature · 1 line
MST
#38 lore raw

[Qemu-devel] [PULL 36/49] pc: Move APIC and NUMA data from PcGuestInfo to PCMachineState

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

---
 include/hw/i386/pc.h | 14 +++++++++-----
 hw/i386/acpi-build.c | 22 +++++++++-------------
 hw/i386/pc.c         | 20 ++++++++++----------
 3 files changed, 28 insertions(+), 28 deletions(-)
include/hw/i386/pc.h +9 -5
index 40249b6..0cf67ed 100644
@@ -35,11 +35,6 @@
 
 /* Machine info for ACPI build: */
 struct PcGuestInfo {
-    unsigned apic_id_limit;
-    bool apic_xrupt_override;
-    uint64_t numa_nodes;
-    uint64_t *node_mem;
-    uint64_t *node_cpu;
 };
 
 /**
@@ -71,6 +66,15 @@ struct PCMachineState {
 
     /* RAM information (sizes, addresses, configuration): */
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
+
+    /* CPU and apic information: */
+    bool apic_xrupt_override;
+    unsigned apic_id_limit;
+
+    /* NUMA information: */
+    uint64_t numa_nodes;
+    uint64_t *node_mem;
+    uint64_t *node_cpu;
 };
 
 #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
hw/i386/acpi-build.c +9 -13
index 86baf63..35582a7 100644
@@ -364,7 +364,6 @@ static void
 build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int madt_start = table_data->len;
 
     AcpiMultipleApicTable *madt;
@@ -377,7 +376,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
     madt->local_apic_address = cpu_to_le32(APIC_DEFAULT_ADDRESS);
     madt->flags = cpu_to_le32(1);
 
-    for (i = 0; i < guest_info->apic_id_limit; i++) {
+    for (i = 0; i < pcms->apic_id_limit; i++) {
         AcpiMadtProcessorApic *apic = acpi_data_push(table_data, sizeof *apic);
         apic->type = ACPI_APIC_PROCESSOR;
         apic->length = sizeof(*apic);
@@ -397,7 +396,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
     io_apic->address = cpu_to_le32(IO_APIC_DEFAULT_ADDRESS);
     io_apic->interrupt = cpu_to_le32(0);
 
-    if (guest_info->apic_xrupt_override) {
+    if (pcms->apic_xrupt_override) {
         intsrcovr = acpi_data_push(table_data, sizeof *intsrcovr);
         intsrcovr->type   = ACPI_APIC_XRUPT_OVERRIDE;
         intsrcovr->length = sizeof(*intsrcovr);
@@ -1946,7 +1945,6 @@ build_dsdt(GArray *table_data, GArray *linker,
     GPtrArray *io_ranges = g_ptr_array_new_with_free_func(crs_range_free);
     MachineState *machine = MACHINE(qdev_get_machine());
     PCMachineState *pcms = PC_MACHINE(machine);
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     uint32_t nr_mem = machine->ram_slots;
     int root_bus_limit = 0xFF;
     PCIBus *bus = NULL;
@@ -2247,7 +2245,7 @@ build_dsdt(GArray *table_data, GArray *linker,
 
     sb_scope = aml_scope("\\_SB");
     {
-        build_processor_devices(sb_scope, guest_info->apic_id_limit, cpu, pm);
+        build_processor_devices(sb_scope, pcms->apic_id_limit, cpu, pm);
 
         build_memory_devices(sb_scope, nr_mem, pm->mem_hp_io_base,
                              pm->mem_hp_io_len);
@@ -2379,7 +2377,6 @@ build_srat(GArray *table_data, GArray *linker)
     int srat_start, numa_start, slots;
     uint64_t mem_len, mem_base, next_base;
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     ram_addr_t hotplugabble_address_space_size =
         object_property_get_int(OBJECT(pcms), PC_MACHINE_MEMHP_REGION_SIZE,
                                 NULL);
@@ -2390,12 +2387,12 @@ build_srat(GArray *table_data, GArray *linker)
     srat->reserved1 = cpu_to_le32(1);
     core = (void *)(srat + 1);
 
-    for (i = 0; i < guest_info->apic_id_limit; ++i) {
+    for (i = 0; i < pcms->apic_id_limit; ++i) {
         core = acpi_data_push(table_data, sizeof *core);
         core->type = ACPI_SRAT_PROCESSOR;
         core->length = sizeof(*core);
         core->local_apic_id = i;
-        curnode = guest_info->node_cpu[i];
+        curnode = pcms->node_cpu[i];
         core->proximity_lo = curnode;
         memset(core->proximity_hi, 0, 3);
         core->local_sapic_eid = 0;
@@ -2412,9 +2409,9 @@ build_srat(GArray *table_data, GArray *linker)
     numamem = acpi_data_push(table_data, sizeof *numamem);
     acpi_build_srat_memory(numamem, 0, 640*1024, 0, MEM_AFFINITY_ENABLED);
     next_base = 1024 * 1024;
-    for (i = 1; i < guest_info->numa_nodes + 1; ++i) {
+    for (i = 1; i < pcms->numa_nodes + 1; ++i) {
         mem_base = next_base;
-        mem_len = guest_info->node_mem[i - 1];
+        mem_len = pcms->node_mem[i - 1];
         if (i == 1) {
             mem_len -= 1024 * 1024;
         }
@@ -2438,7 +2435,7 @@ build_srat(GArray *table_data, GArray *linker)
                                MEM_AFFINITY_ENABLED);
     }
     slots = (table_data->len - numa_start) / sizeof *numamem;
-    for (; slots < guest_info->numa_nodes + 2; slots++) {
+    for (; slots < pcms->numa_nodes + 2; slots++) {
         numamem = acpi_data_push(table_data, sizeof *numamem);
         acpi_build_srat_memory(numamem, 0, 0, 0, MEM_AFFINITY_NOFLAGS);
     }
@@ -2594,7 +2591,6 @@ void acpi_build(AcpiBuildTables *tables)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     GArray *table_offsets;
     unsigned facs, dsdt, rsdt, fadt;
     AcpiCpuInfo cpu;
@@ -2658,7 +2654,7 @@ void acpi_build(AcpiBuildTables *tables)
             build_tpm2(tables_blob, tables->linker);
         }
     }
-    if (guest_info->numa_nodes) {
+    if (pcms->numa_nodes) {
         acpi_add_table(table_offsets, tables_blob);
         build_srat(tables_blob, tables->linker);
     }
hw/i386/pc.c +10 -10
index a47784a..66f7bb9 100644
@@ -1188,24 +1188,24 @@ PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
     PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int i, j;
 
-    guest_info->apic_id_limit = pc_apic_id_limit(max_cpus);
-    guest_info->apic_xrupt_override = kvm_allows_irq0_override();
-    guest_info->numa_nodes = nb_numa_nodes;
-    guest_info->node_mem = g_malloc0(guest_info->numa_nodes *
-                                    sizeof *guest_info->node_mem);
+    pcms->apic_id_limit = pc_apic_id_limit(max_cpus);
+    pcms->apic_xrupt_override = kvm_allows_irq0_override();
+    pcms->numa_nodes = nb_numa_nodes;
+    pcms->node_mem = g_malloc0(pcms->numa_nodes *
+                                    sizeof *pcms->node_mem);
     for (i = 0; i < nb_numa_nodes; i++) {
-        guest_info->node_mem[i] = numa_info[i].node_mem;
+        pcms->node_mem[i] = numa_info[i].node_mem;
     }
 
-    guest_info->node_cpu = g_malloc0(guest_info->apic_id_limit *
-                                     sizeof *guest_info->node_cpu);
+    pcms->node_cpu = g_malloc0(pcms->apic_id_limit *
+                                     sizeof *pcms->node_cpu);
 
     for (i = 0; i < max_cpus; i++) {
         unsigned int apic_id = x86_cpu_apic_id_from_index(i);
-        assert(apic_id < guest_info->apic_id_limit);
+        assert(apic_id < pcms->apic_id_limit);
         for (j = 0; j < nb_numa_nodes; j++) {
             if (test_bit(i, numa_info[j].node_cpu)) {
-                guest_info->node_cpu[apic_id] = j;
+                pcms->node_cpu[apic_id] = j;
                 break;
             }
         }
Signature · 1 line
MST
#39 lore raw

[Qemu-devel] [PULL 37/49] pc: Eliminate PcGuestInfo struct

In reply to Michael S. Tsirkin

From: Eduardo Habkost <[email protected]>

The struct is not used for anything, now.

---
 include/hw/i386/pc.h | 7 +------
 hw/i386/pc.c         | 4 +---
 2 files changed, 2 insertions(+), 9 deletions(-)
include/hw/i386/pc.h +1 -6
index 0cf67ed..8b3546e 100644
@@ -33,10 +33,6 @@
 #define kvm_ioapic_in_kernel()   0
 #endif
 
-/* Machine info for ACPI build: */
-struct PcGuestInfo {
-};
-
 /**
  * PCMachineState:
  * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
@@ -49,7 +45,6 @@ struct PCMachineState {
 
     /* State for other subsystems/APIs: */
     MemoryHotplugState hotplug_memory;
-    PcGuestInfo acpi_guest_info;
     Notifier machine_done;
 
     /* Pointers to devices and objects: */
@@ -233,7 +228,7 @@ void pc_cpus_init(PCMachineState *pcms);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);
 
-PcGuestInfo *pc_guest_info_init(PCMachineState *pcms);
+void pc_guest_info_init(PCMachineState *pcms);
 
 #define PCI_HOST_PROP_PCI_HOLE_START   "pci-hole-start"
 #define PCI_HOST_PROP_PCI_HOLE_END     "pci-hole-end"
hw/i386/pc.c +1 -3
index 66f7bb9..ce185bb 100644
@@ -1183,9 +1183,8 @@ void pc_machine_done(Notifier *notifier, void *data)
     acpi_setup();
 }
 
-PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
+void pc_guest_info_init(PCMachineState *pcms)
 {
-    PcGuestInfo *guest_info = &pcms->acpi_guest_info;
     int i, j;
 
     pcms->apic_id_limit = pc_apic_id_limit(max_cpus);
@@ -1213,7 +1212,6 @@ PcGuestInfo *pc_guest_info_init(PCMachineState *pcms)
 
     pcms->machine_done.notify = pc_machine_done;
     qemu_add_machine_init_done_notifier(&pcms->machine_done);
-    return guest_info;
 }
 
 /* setup pci memory address space mapping into system address space */
Signature · 1 line
MST
#40 lore raw

[Qemu-arm] [PULL 38/49] acpi: take oem_id in build_header(), optionally

In reply to Michael S. Tsirkin

From: Laszlo Ersek <[email protected]>

This patch is the continuation of commit 8870ca0e94f2 ("acpi: support specified oem table id for build_header"). It will allow us to control the OEM ID field too in the SDT header.

Cc: "Michael S. Tsirkin" <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Igor Mammedov <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Xiao Guangrong <[email protected]> (maintainer:NVDIMM)
Cc: Shannon Zhao <[email protected]> (maintainer:ARM ACPI Subsystem)
Cc: Paolo Bonzini <[email protected]> (maintainer:X86)
Cc: Richard W.M. Jones <[email protected]>
Cc: Aleksei Kovura <[email protected]>
Cc: Michael Tokarev <[email protected]>
Cc: Steven Newbury <[email protected]>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
LP: https://bugs.launchpad.net/qemu/+bug/1533848

---
 include/hw/acpi/aml-build.h |  2 +-
 hw/acpi/aml-build.c         | 11 ++++++++---
 hw/acpi/nvdimm.c            |  4 ++--
 hw/arm/virt-acpi-build.c    | 12 ++++++------
 hw/i386/acpi-build.c        | 18 +++++++++---------
 5 files changed, 26 insertions(+), 21 deletions(-)
include/hw/acpi/aml-build.h +1 -1
index 6d6f705..c460bdd 100644
@@ -357,7 +357,7 @@ Aml *aml_sizeof(Aml *arg);
 void
 build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
-             const char *oem_table_id);
+             const char *oem_id, const char *oem_table_id);
 void *acpi_data_push(GArray *table_data, unsigned size);
 unsigned acpi_data_len(GArray *table);
 void acpi_add_table(GArray *table_offsets, GArray *table_data);
hw/acpi/aml-build.c +8 -3
index 21d2ea0..e4b6c0c 100644
@@ -1426,12 +1426,17 @@ Aml *aml_alias(const char *source_object, const char *alias_object)
 void
 build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
-             const char *oem_table_id)
+             const char *oem_id, const char *oem_table_id)
 {
     memcpy(&h->signature, sig, 4);
     h->length = cpu_to_le32(len);
     h->revision = rev;
-    memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    if (oem_id) {
+        strncpy((char *)h->oem_id, oem_id, sizeof h->oem_id);
+    } else {
+        memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
+    }
 
     if (oem_table_id) {
         strncpy((char *)h->oem_table_id, oem_table_id, sizeof(h->oem_table_id));
@@ -1506,5 +1511,5 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
                                        sizeof(uint32_t));
     }
     build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1, NULL);
+                 (void *)rsdt, "RSDT", rsdt_len, 1, NULL, NULL);
 }
hw/acpi/nvdimm.c +2 -2
index 7ee7e16..49ee68e 100644
@@ -366,7 +366,7 @@ static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets,
 
     build_header(linker, table_data,
                  (void *)(table_data->data + header), "NFIT",
-                 sizeof(NvdimmNfitHeader) + structures->len, 1, NULL);
+                 sizeof(NvdimmNfitHeader) + structures->len, 1, NULL, NULL);
     g_array_free(structures, true);
 }
 
@@ -471,7 +471,7 @@ static void nvdimm_build_ssdt(GSList *device_list, GArray *table_offsets,
     g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - ssdt->buf->len),
-        "SSDT", ssdt->buf->len, 1, "NVDIMM");
+        "SSDT", ssdt->buf->len, 1, NULL, "NVDIMM");
     free_aml_allocator();
 }
 
hw/arm/virt-acpi-build.c +6 -6
index 87fbe7c..8017b12 100644
@@ -408,7 +408,7 @@ build_spcr(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     spcr->pci_vendor_id = 0xffff;  /* PCI Vendor ID: not a PCI device */
 
     build_header(linker, table_data, (void *)spcr, "SPCR", sizeof(*spcr), 2,
-                 NULL);
+                 NULL, NULL);
 }
 
 static void
@@ -427,7 +427,7 @@ build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     mcfg->allocation[0].end_bus_number = (memmap[VIRT_PCIE_ECAM].size
                                           / PCIE_MMCFG_SIZE_MIN) - 1;
 
-    build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL);
+    build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
 
 /* GTDT */
@@ -453,7 +453,7 @@ build_gtdt(GArray *table_data, GArray *linker)
 
     build_header(linker, table_data,
                  (void *)(table_data->data + gtdt_start), "GTDT",
-                 table_data->len - gtdt_start, 2, NULL);
+                 table_data->len - gtdt_start, 2, NULL, NULL);
 }
 
 /* MADT */
@@ -515,7 +515,7 @@ build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info,
 
     build_header(linker, table_data,
                  (void *)(table_data->data + madt_start), "APIC",
-                 table_data->len - madt_start, 3, NULL);
+                 table_data->len - madt_start, 3, NULL, NULL);
 }
 
 /* FADT */
@@ -540,7 +540,7 @@ build_fadt(GArray *table_data, GArray *linker, unsigned dsdt)
                                    sizeof fadt->dsdt);
 
     build_header(linker, table_data,
-                 (void *)fadt, "FACP", sizeof(*fadt), 5, NULL);
+                 (void *)fadt, "FACP", sizeof(*fadt), 5, NULL, NULL);
 }
 
 /* DSDT */
@@ -579,7 +579,7 @@ build_dsdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - dsdt->buf->len),
-        "DSDT", dsdt->buf->len, 2, NULL);
+        "DSDT", dsdt->buf->len, 2, NULL, NULL);
     free_aml_allocator();
 }
 
hw/i386/acpi-build.c +9 -9
index 35582a7..061a9cb 100644
@@ -357,7 +357,7 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
     fadt_setup(fadt, pm);
 
     build_header(linker, table_data,
-                 (void *)fadt, "FACP", sizeof(*fadt), 1, NULL);
+                 (void *)fadt, "FACP", sizeof(*fadt), 1, NULL, NULL);
 }
 
 static void
@@ -427,7 +427,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
 
     build_header(linker, table_data,
                  (void *)(table_data->data + madt_start), "APIC",
-                 table_data->len - madt_start, 1, NULL);
+                 table_data->len - madt_start, 1, NULL, NULL);
 }
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
@@ -2286,7 +2286,7 @@ build_dsdt(GArray *table_data, GArray *linker,
     g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - dsdt->buf->len),
-        "DSDT", dsdt->buf->len, 1, NULL);
+        "DSDT", dsdt->buf->len, 1, NULL, NULL);
     free_aml_allocator();
 }
 
@@ -2302,7 +2302,7 @@ build_hpet(GArray *table_data, GArray *linker)
     hpet->timer_block_id = cpu_to_le32(0x8086a201);
     hpet->addr.address = cpu_to_le64(HPET_BASE);
     build_header(linker, table_data,
-                 (void *)hpet, "HPET", sizeof(*hpet), 1, NULL);
+                 (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL);
 }
 
 static void
@@ -2325,7 +2325,7 @@ build_tpm_tcpa(GArray *table_data, GArray *linker, GArray *tcpalog)
                                    sizeof(tcpa->log_area_start_address));
 
     build_header(linker, table_data,
-                 (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL);
+                 (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL, NULL);
 
     acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
 }
@@ -2342,7 +2342,7 @@ build_tpm2(GArray *table_data, GArray *linker)
     tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
 
     build_header(linker, table_data,
-                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL);
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
 }
 
 typedef enum {
@@ -2456,7 +2456,7 @@ build_srat(GArray *table_data, GArray *linker)
     build_header(linker, table_data,
                  (void *)(table_data->data + srat_start),
                  "SRAT",
-                 table_data->len - srat_start, 1, NULL);
+                 table_data->len - srat_start, 1, NULL, NULL);
 }
 
 static void
@@ -2485,7 +2485,7 @@ build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
     } else {
         sig = "MCFG";
     }
-    build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL);
+    build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL, NULL);
 }
 
 static void
@@ -2509,7 +2509,7 @@ build_dmar_q35(GArray *table_data, GArray *linker)
     drhd->address = cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR);
 
     build_header(linker, table_data, (void *)(table_data->data + dmar_start),
-                 "DMAR", table_data->len - dmar_start, 1, NULL);
+                 "DMAR", table_data->len - dmar_start, 1, NULL, NULL);
 }
 
 static GArray *
Signature · 1 line
MST
#41 lore raw

Re: [Qemu-arm] [PULL 38/49] acpi: take oem_id in build_header(), optionally

Thank you for picking up my patches, and for rebasing them to the SSDT removal (Igor's "[PULL 02/49] pc: acpi: merge SSDT into DSDT").

Laszlo

Quoted 239 lines · Michael S. Tsirkin

From: Laszlo Ersek <[email protected]>

This patch is the continuation of commit 8870ca0e94f2 ("acpi: support specified oem table id for build_header"). It will allow us to control the OEM ID field too in the SDT header.

Cc: "Michael S. Tsirkin" <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Igor Mammedov <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Xiao Guangrong <[email protected]> (maintainer:NVDIMM)
Cc: Shannon Zhao <[email protected]> (maintainer:ARM ACPI Subsystem)
Cc: Paolo Bonzini <[email protected]> (maintainer:X86)
Cc: Richard W.M. Jones <[email protected]>
Cc: Aleksei Kovura <[email protected]>
Cc: Michael Tokarev <[email protected]>
Cc: Steven Newbury <[email protected]>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
LP: https://bugs.launchpad.net/qemu/+bug/1533848

---
 include/hw/acpi/aml-build.h |  2 +-
 hw/acpi/aml-build.c         | 11 ++++++++---
 hw/acpi/nvdimm.c            |  4 ++--
 hw/arm/virt-acpi-build.c    | 12 ++++++------
 hw/i386/acpi-build.c        | 18 +++++++++---------
 5 files changed, 26 insertions(+), 21 deletions(-)
include/hw/acpi/aml-build.h +1 -1
index 6d6f705..c460bdd 100644
@@ -357,7 +357,7 @@ Aml *aml_sizeof(Aml *arg);
 void
 build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
-             const char *oem_table_id);
+             const char *oem_id, const char *oem_table_id);
 void *acpi_data_push(GArray *table_data, unsigned size);
 unsigned acpi_data_len(GArray *table);
 void acpi_add_table(GArray *table_offsets, GArray *table_data);
hw/acpi/aml-build.c +8 -3
index 21d2ea0..e4b6c0c 100644
@@ -1426,12 +1426,17 @@ Aml *aml_alias(const char *source_object, const char *alias_object)
 void
 build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
-             const char *oem_table_id)
+             const char *oem_id, const char *oem_table_id)
 {
     memcpy(&h->signature, sig, 4);
     h->length = cpu_to_le32(len);
     h->revision = rev;
-    memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
+
+    if (oem_id) {
+        strncpy((char *)h->oem_id, oem_id, sizeof h->oem_id);
+    } else {
+        memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
+    }
 
     if (oem_table_id) {
         strncpy((char *)h->oem_table_id, oem_table_id, sizeof(h->oem_table_id));
@@ -1506,5 +1511,5 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
                                        sizeof(uint32_t));
     }
     build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1, NULL);
+                 (void *)rsdt, "RSDT", rsdt_len, 1, NULL, NULL);
 }
hw/acpi/nvdimm.c +2 -2
index 7ee7e16..49ee68e 100644
@@ -366,7 +366,7 @@ static void nvdimm_build_nfit(GSList *device_list, GArray *table_offsets,
 
     build_header(linker, table_data,
                  (void *)(table_data->data + header), "NFIT",
-                 sizeof(NvdimmNfitHeader) + structures->len, 1, NULL);
+                 sizeof(NvdimmNfitHeader) + structures->len, 1, NULL, NULL);
     g_array_free(structures, true);
 }
 
@@ -471,7 +471,7 @@ static void nvdimm_build_ssdt(GSList *device_list, GArray *table_offsets,
     g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - ssdt->buf->len),
-        "SSDT", ssdt->buf->len, 1, "NVDIMM");
+        "SSDT", ssdt->buf->len, 1, NULL, "NVDIMM");
     free_aml_allocator();
 }
 
hw/arm/virt-acpi-build.c +6 -6
index 87fbe7c..8017b12 100644
@@ -408,7 +408,7 @@ build_spcr(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     spcr->pci_vendor_id = 0xffff;  /* PCI Vendor ID: not a PCI device */
 
     build_header(linker, table_data, (void *)spcr, "SPCR", sizeof(*spcr), 2,
-                 NULL);
+                 NULL, NULL);
 }
 
 static void
@@ -427,7 +427,7 @@ build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     mcfg->allocation[0].end_bus_number = (memmap[VIRT_PCIE_ECAM].size
                                           / PCIE_MMCFG_SIZE_MIN) - 1;
 
-    build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL);
+    build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
 
 /* GTDT */
@@ -453,7 +453,7 @@ build_gtdt(GArray *table_data, GArray *linker)
 
     build_header(linker, table_data,
                  (void *)(table_data->data + gtdt_start), "GTDT",
-                 table_data->len - gtdt_start, 2, NULL);
+                 table_data->len - gtdt_start, 2, NULL, NULL);
 }
 
 /* MADT */
@@ -515,7 +515,7 @@ build_madt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info,
 
     build_header(linker, table_data,
                  (void *)(table_data->data + madt_start), "APIC",
-                 table_data->len - madt_start, 3, NULL);
+                 table_data->len - madt_start, 3, NULL, NULL);
 }
 
 /* FADT */
@@ -540,7 +540,7 @@ build_fadt(GArray *table_data, GArray *linker, unsigned dsdt)
                                    sizeof fadt->dsdt);
 
     build_header(linker, table_data,
-                 (void *)fadt, "FACP", sizeof(*fadt), 5, NULL);
+                 (void *)fadt, "FACP", sizeof(*fadt), 5, NULL, NULL);
 }
 
 /* DSDT */
@@ -579,7 +579,7 @@ build_dsdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
     g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - dsdt->buf->len),
-        "DSDT", dsdt->buf->len, 2, NULL);
+        "DSDT", dsdt->buf->len, 2, NULL, NULL);
     free_aml_allocator();
 }
 
hw/i386/acpi-build.c +9 -9
index 35582a7..061a9cb 100644
@@ -357,7 +357,7 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
     fadt_setup(fadt, pm);
 
     build_header(linker, table_data,
-                 (void *)fadt, "FACP", sizeof(*fadt), 1, NULL);
+                 (void *)fadt, "FACP", sizeof(*fadt), 1, NULL, NULL);
 }
 
 static void
@@ -427,7 +427,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu)
 
     build_header(linker, table_data,
                  (void *)(table_data->data + madt_start), "APIC",
-                 table_data->len - madt_start, 1, NULL);
+                 table_data->len - madt_start, 1, NULL, NULL);
 }
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
@@ -2286,7 +2286,7 @@ build_dsdt(GArray *table_data, GArray *linker,
     g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
     build_header(linker, table_data,
         (void *)(table_data->data + table_data->len - dsdt->buf->len),
-        "DSDT", dsdt->buf->len, 1, NULL);
+        "DSDT", dsdt->buf->len, 1, NULL, NULL);
     free_aml_allocator();
 }
 
@@ -2302,7 +2302,7 @@ build_hpet(GArray *table_data, GArray *linker)
     hpet->timer_block_id = cpu_to_le32(0x8086a201);
     hpet->addr.address = cpu_to_le64(HPET_BASE);
     build_header(linker, table_data,
-                 (void *)hpet, "HPET", sizeof(*hpet), 1, NULL);
+                 (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL);
 }
 
 static void
@@ -2325,7 +2325,7 @@ build_tpm_tcpa(GArray *table_data, GArray *linker, GArray *tcpalog)
                                    sizeof(tcpa->log_area_start_address));
 
     build_header(linker, table_data,
-                 (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL);
+                 (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL, NULL);
 
     acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
 }
@@ -2342,7 +2342,7 @@ build_tpm2(GArray *table_data, GArray *linker)
     tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
 
     build_header(linker, table_data,
-                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL);
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
 }
 
 typedef enum {
@@ -2456,7 +2456,7 @@ build_srat(GArray *table_data, GArray *linker)
     build_header(linker, table_data,
                  (void *)(table_data->data + srat_start),
                  "SRAT",
-                 table_data->len - srat_start, 1, NULL);
+                 table_data->len - srat_start, 1, NULL, NULL);
 }
 
 static void
@@ -2485,7 +2485,7 @@ build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
     } else {
         sig = "MCFG";
     }
-    build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL);
+    build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL, NULL);
 }
 
 static void
@@ -2509,7 +2509,7 @@ build_dmar_q35(GArray *table_data, GArray *linker)
     drhd->address = cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR);
 
     build_header(linker, table_data, (void *)(table_data->data + dmar_start),
-                 "DMAR", table_data->len - dmar_start, 1, NULL);
+                 "DMAR", table_data->len - dmar_start, 1, NULL, NULL);
 }
 
 static GArray *
#42 lore raw

[Qemu-arm] [PULL 39/49] acpi: expose oem_id and oem_table_id in build_rsdt()

In reply to Michael S. Tsirkin

From: Laszlo Ersek <[email protected]>

Since build_rsdt() is implemented as common utility code (in "hw/acpi/aml-build.c"), it should expose -- and forward -- the oem_id and oem_table_id parameters between board code and the generic build_header() function.

Cc: "Michael S. Tsirkin" <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Igor Mammedov <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Shannon Zhao <[email protected]> (maintainer:ARM ACPI Subsystem)
Cc: Paolo Bonzini <[email protected]> (maintainer:X86)
Cc: Richard W.M. Jones <[email protected]>
Cc: Aleksei Kovura <[email protected]>
Cc: Michael Tokarev <[email protected]>
Cc: Steven Newbury <[email protected]>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
LP: https://bugs.launchpad.net/qemu/+bug/1533848

---
 include/hw/acpi/aml-build.h | 3 ++-
 hw/acpi/aml-build.c         | 5 +++--
 hw/arm/virt-acpi-build.c    | 2 +-
 hw/i386/acpi-build.c        | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)
include/hw/acpi/aml-build.h +2 -1
index c460bdd..aa29d30 100644
@@ -364,6 +364,7 @@ void acpi_add_table(GArray *table_offsets, GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
-build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets,
+           const char *oem_id, const char *oem_table_id);
 
 #endif
hw/acpi/aml-build.c +3 -2
index e4b6c0c..603068b 100644
@@ -1492,7 +1492,8 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
 
 /* Build rsdt table */
 void
-build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
+build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets,
+           const char *oem_id, const char *oem_table_id)
 {
     AcpiRsdtDescriptorRev1 *rsdt;
     size_t rsdt_len;
@@ -1511,5 +1512,5 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
                                        sizeof(uint32_t));
     }
     build_header(linker, table_data,
-                 (void *)rsdt, "RSDT", rsdt_len, 1, NULL, NULL);
+                 (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id);
 }
hw/arm/virt-acpi-build.c +1 -1
index 8017b12..560764f 100644
@@ -643,7 +643,7 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
 
     /* RSDT is pointed to by RSDP */
     rsdt = tables_blob->len;
-    build_rsdt(tables_blob, tables->linker, table_offsets);
+    build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
hw/i386/acpi-build.c +1 -1
index 061a9cb..705d12f 100644
@@ -2681,7 +2681,7 @@ void acpi_build(AcpiBuildTables *tables)
 
     /* RSDT is pointed to by RSDP */
     rsdt = tables_blob->len;
-    build_rsdt(tables_blob, tables->linker, table_offsets);
+    build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
Signature · 1 line
MST
#43 lore raw

[Qemu-devel] [PULL 40/49] acpi: add function to extract oem_id and oem_table_id from the user's SLIC

In reply to Michael S. Tsirkin

From: Laszlo Ersek <[email protected]>

The acpi_get_slic_oem() function stores pointers to these fields in the (first) SLIC table that the user passes in with the -acpitable switch.

Cc: "Michael S. Tsirkin" <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Igor Mammedov <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Richard W.M. Jones <[email protected]>
Cc: Aleksei Kovura <[email protected]>
Cc: Michael Tokarev <[email protected]>
Cc: Steven Newbury <[email protected]>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
LP: https://bugs.launchpad.net/qemu/+bug/1533848

---
 include/hw/acpi/acpi.h |  7 +++++++
 hw/acpi/core.c         | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)
include/hw/acpi/acpi.h +7 -0
index b20bd55..2de3021 100644
@@ -196,4 +196,11 @@ unsigned acpi_table_len(void *current);
 void acpi_table_add(const QemuOpts *opts, Error **errp);
 void acpi_table_add_builtin(const QemuOpts *opts, Error **errp);
 
+typedef struct AcpiSlicOem AcpiSlicOem;
+struct AcpiSlicOem {
+  char *id;
+  char *table_id;
+};
+int acpi_get_slic_oem(AcpiSlicOem *oem);
+
 #endif /* !QEMU_HW_ACPI_H */
hw/acpi/core.c +16 -0
index 397e6da..edf3f96 100644
@@ -350,6 +350,22 @@ uint8_t *acpi_table_next(uint8_t *current)
     }
 }
 
+int acpi_get_slic_oem(AcpiSlicOem *oem)
+{
+    uint8_t *u;
+
+    for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
+        struct acpi_table_header *hdr = (void *)(u - sizeof(hdr->_length));
+
+        if (memcmp(hdr->sig, "SLIC", 4) == 0) {
+            oem->id = hdr->oem_id;
+            oem->table_id = hdr->oem_table_id;
+            return 0;
+        }
+    }
+    return -1;
+}
+
 static void acpi_notify_wakeup(Notifier *notifier, void *data)
 {
     ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
Signature · 1 line
MST
#44 lore raw

[Qemu-devel] [PULL 41/49] pc: set the OEM fields in the RSDT and the FADT from the SLIC

In reply to Michael S. Tsirkin

From: Laszlo Ersek <[email protected]>

The Microsoft spec about the SLIC and MSDM ACPI tables at
<http://go.microsoft.com/fwlink/p/?LinkId=234834> requires the OEM ID and OEM Table ID fields to be consistent between the SLIC and the RSDT/XSDT. That further affects the FADT, because a similar match between the FADT and the RSDT/XSDT is required by the ACPI spec in general.

This patch wires up the previous three patches.

Cc: "Michael S. Tsirkin" <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Igor Mammedov <[email protected]> (supporter:ACPI/SMBIOS)
Cc: Paolo Bonzini <[email protected]> (maintainer:X86)
Cc: Richard W.M. Jones <[email protected]>
Cc: Aleksei Kovura <[email protected]>
Cc: Michael Tokarev <[email protected]>
Cc: Steven Newbury <[email protected]>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1248758
LP: https://bugs.launchpad.net/qemu/+bug/1533848

---
 hw/i386/acpi-build.c | 13 +++++++++----
 qemu-options.hx      |  4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)
hw/i386/acpi-build.c +9 -4
index 705d12f..4554eb8 100644
@@ -336,7 +336,8 @@ static void fadt_setup(AcpiFadtDescriptorRev1 *fadt, AcpiPmInfo *pm)
 /* FADT */
 static void
 build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
-           unsigned facs, unsigned dsdt)
+           unsigned facs, unsigned dsdt,
+           const char *oem_id, const char *oem_table_id)
 {
     AcpiFadtDescriptorRev1 *fadt = acpi_data_push(table_data, sizeof(*fadt));
 
@@ -357,7 +358,7 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
     fadt_setup(fadt, pm);
 
     build_header(linker, table_data,
-                 (void *)fadt, "FACP", sizeof(*fadt), 1, NULL, NULL);
+                 (void *)fadt, "FACP", sizeof(*fadt), 1, oem_id, oem_table_id);
 }
 
 static void
@@ -2601,11 +2602,13 @@ void acpi_build(AcpiBuildTables *tables)
     uint8_t *u;
     size_t aml_len = 0;
     GArray *tables_blob = tables->table_data;
+    AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
 
     acpi_get_cpu_info(&cpu);
     acpi_get_pm_info(&pm);
     acpi_get_misc_info(&misc);
     acpi_get_pci_info(&pci);
+    acpi_get_slic_oem(&slic_oem);
 
     table_offsets = g_array_new(false, true /* clear */,
                                         sizeof(uint32_t));
@@ -2635,7 +2638,8 @@ void acpi_build(AcpiBuildTables *tables)
     /* ACPI tables pointed to by RSDT */
     fadt = tables_blob->len;
     acpi_add_table(table_offsets, tables_blob);
-    build_fadt(tables_blob, tables->linker, &pm, facs, dsdt);
+    build_fadt(tables_blob, tables->linker, &pm, facs, dsdt,
+               slic_oem.id, slic_oem.table_id);
     aml_len += tables_blob->len - fadt;
 
     acpi_add_table(table_offsets, tables_blob);
@@ -2681,7 +2685,8 @@ void acpi_build(AcpiBuildTables *tables)
 
     /* RSDT is pointed to by RSDP */
     rsdt = tables_blob->len;
-    build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
+    build_rsdt(tables_blob, tables->linker, table_offsets,
+               slic_oem.id, slic_oem.table_id);
 
     /* RSDP is in FSEG memory, so allocate it separately */
     build_rsdp(tables->rsdp, tables->linker, rsdt);
qemu-options.hx +4 -0
index 733a194..2f0465e 100644
@@ -1472,6 +1472,10 @@ ACPI headers (possible overridden by other options).
 For data=, only data
 portion of the table is used, all header information is specified in the
 command line.
+If a SLIC table is supplied to QEMU, then the SLIC's oem_id and oem_table_id
+fields will override the same in the RSDT and the FADT (a.k.a. FACP), in order
+to ensure the field matches required by the Microsoft SLIC spec and the ACPI
+spec.
 ETEXI
 
 DEF("smbios", HAS_ARG, QEMU_OPTION_smbios,
Signature · 1 line
MST
#45 lore raw

[Qemu-devel] [PULL 44/49] fix MSI injection on Xen

In reply to Michael S. Tsirkin

From: Stefano Stabellini <[email protected]>

On Xen MSIs can be remapped into pirqs, which are a type of event channels. It's mostly for the benefit of PCI passthrough devices, to avoid the overhead of interacting with the emulated lapic.

However remapping interrupts and MSIs is also supported for emulated devices, such as the e1000 and virtio-net.

When an interrupt or an MSI is remapped into a pirq, masking and unmasking is done by masking and unmasking the event channel. The masking bit on the PCI config space or MSI-X table should be ignored, but it isn't at the moment.

As a consequence emulated devices which use MSI or MSI-X, such as virtio-net, don't work properly (the guest doesn't receive any notifications). The mechanism was working properly when xen_apic was introduced, but I haven't narrowed down which commit in particular is causing the regression.

Fix the issue by ignoring the masking bit for MSI and MSI-X which have been remapped into pirqs.

---
 include/hw/xen/xen.h |  1 +
 hw/pci/msi.c         |  9 ++++++++-
 hw/pci/msix.c        | 12 ++++++++++--
 hw/xen/xen_pt_msi.c  |  4 +---
 xen-hvm-stub.c       |  5 +++++
 xen-hvm.c            |  9 +++++++++
 6 files changed, 34 insertions(+), 6 deletions(-)
include/hw/xen/xen.h +1 -0
index 1b81b4b..c577354 100644
@@ -33,6 +33,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
+int xen_is_pirq_msi(uint32_t msi_data);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
hw/pci/msi.c +8 -1
index 8efa23d..85f21b8 100644
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/pci/msi.h"
+#include "hw/xen/xen.h"
 #include "qemu/range.h"
 
 /* PCI_MSI_ADDRESS_LO */
@@ -254,13 +255,19 @@ void msi_reset(PCIDevice *dev)
 static bool msi_is_masked(const PCIDevice *dev, unsigned int vector)
 {
     uint16_t flags = pci_get_word(dev->config + msi_flags_off(dev));
-    uint32_t mask;
+    uint32_t mask, data;
+    bool msi64bit = flags & PCI_MSI_FLAGS_64BIT;
     assert(vector < PCI_MSI_VECTORS_MAX);
 
     if (!(flags & PCI_MSI_FLAGS_MASKBIT)) {
         return false;
     }
 
+    data = pci_get_word(dev->config + msi_data_off(dev, msi64bit));
+    if (xen_is_pirq_msi(data)) {
+        return false;
+    }
+
     mask = pci_get_long(dev->config +
                         msi_mask_off(dev, flags & PCI_MSI_FLAGS_64BIT));
     return mask & (1U << vector);
hw/pci/msix.c +10 -2
index 4fea7ed..eb4ef11 100644
@@ -19,6 +19,7 @@
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/pci.h"
+#include "hw/xen/xen.h"
 #include "qemu/range.h"
 
 #define MSIX_CAP_LENGTH 12
@@ -78,8 +79,15 @@ static void msix_clr_pending(PCIDevice *dev, int vector)
 
 static bool msix_vector_masked(PCIDevice *dev, unsigned int vector, bool fmask)
 {
-    unsigned offset = vector * PCI_MSIX_ENTRY_SIZE + PCI_MSIX_ENTRY_VECTOR_CTRL;
-    return fmask || dev->msix_table[offset] & PCI_MSIX_ENTRY_CTRL_MASKBIT;
+    unsigned offset = vector * PCI_MSIX_ENTRY_SIZE;
+    uint32_t *data = (uint32_t *)&dev->msix_table[offset + PCI_MSIX_ENTRY_DATA];
+    /* MSIs on Xen can be remapped into pirqs. In those cases, masking
+     * and unmasking go through the PV evtchn path. */
+    if (xen_is_pirq_msi(*data)) {
+        return false;
+    }
+    return fmask || dev->msix_table[offset + PCI_MSIX_ENTRY_VECTOR_CTRL] &
+        PCI_MSIX_ENTRY_CTRL_MASKBIT;
 }
 
 bool msix_is_masked(PCIDevice *dev, unsigned int vector)
hw/xen/xen_pt_msi.c +1 -3
index 5624685..9a16f2b 100644
@@ -115,9 +115,7 @@ static int msi_msix_setup(XenPCIPassthroughState *s,
 
     assert((!is_msix && msix_entry == 0) || is_msix);
 
-    if (gvec == 0) {
-        /* if gvec is 0, the guest is asking for a particular pirq that
-         * is passed as dest_id */
+    if (xen_is_pirq_msi(data)) {
         *ppirq = msi_ext_dest_id(addr >> 32) | msi_dest_id(addr);
         if (!*ppirq) {
             /* this probably identifies an misconfiguration of the guest,
xen-hvm-stub.c +5 -0
index a6cb5d3..c500325 100644
@@ -31,6 +31,11 @@ void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
 {
 }
 
+int xen_is_pirq_msi(uint32_t msi_data)
+{
+    return 0;
+}
+
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
                    Error **errp)
 {
xen-hvm.c +9 -0
index 1c9fb12..6861c51 100644
@@ -13,6 +13,7 @@
 
 #include "hw/pci/pci.h"
 #include "hw/i386/pc.h"
+#include "hw/i386/apic-msidef.h"
 #include "hw/xen/xen_common.h"
 #include "hw/xen/xen_backend.h"
 #include "qmp-commands.h"
@@ -158,6 +159,14 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
     }
 }
 
+int xen_is_pirq_msi(uint32_t msi_data)
+{
+    /* If vector is 0, the msi is remapped into a pirq, passed as
+     * dest_id.
+     */
+    return ((msi_data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT) == 0;
+}
+
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data)
 {
     xen_xc_hvm_inject_msi(xen_xc, xen_domid, addr, data);
Signature · 1 line
MST
#46 lore raw

[Qemu-devel] [PULL 42/49] dimm: Correct type of MemoryHotplugState->base

In reply to Michael S. Tsirkin

From: David Gibson <[email protected]>

The 'base' field of MemoryHotplugState is ram_addr_t, which indicates that it exists in the abstract address space of RAM regions.

However, the actual usage of this field indicates that it is a concrete physical address (it's passed as an offset to memory_region_add_subgregion for example).

So, correct its type to 'hwaddr'.

---
 include/hw/mem/pc-dimm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/mem/pc-dimm.h +1 -1
index d83bf30..218dfb0 100644
@@ -77,7 +77,7 @@ typedef struct PCDIMMDeviceClass {
  * @mr: hotplug memory address space container
  */
 typedef struct MemoryHotplugState {
-    ram_addr_t base;
+    hwaddr base;
     MemoryRegion mr;
 } MemoryHotplugState;
 
Signature · 1 line
MST
#47 lore raw

[Qemu-devel] [PULL 43/49] intel_iommu: large page support

In reply to Michael S. Tsirkin

From: Jason Wang <[email protected]>

Current intel_iommu only supports 4K page which may not be sufficient to cover guest working set. This patch tries to enable 2M and 1G mapping for intel_iommu. This is also useful for future device IOTLB implementation to have a better hit rate.

Major work is adding a page mask field on IOTLB entry to make it support large page. And also use the slpte level as key to do IOTLB lookup. MAMV was increased to 18 to support direct invalidation for 1G mapping.

Cc Michael S. Tsirkin <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Eduardo Habkost <[email protected]>
---
 hw/i386/intel_iommu_internal.h |  6 ++--
 include/hw/i386/intel_iommu.h  |  1 +
 hw/i386/intel_iommu.c          | 76 ++++++++++++++++++++++++++++++------------
 3 files changed, 59 insertions(+), 24 deletions(-)
hw/i386/intel_iommu_internal.h +4 -2
index ba288ab..e5f514c 100644
@@ -113,6 +113,7 @@
 
 /* The shift of source_id in the key of IOTLB hash table */
 #define VTD_IOTLB_SID_SHIFT         36
+#define VTD_IOTLB_LVL_SHIFT         44
 #define VTD_IOTLB_MAX_SIZE          1024    /* Max size of the hash table */
 
 /* IOTLB_REG */
@@ -185,9 +186,10 @@
 #define VTD_CAP_ND                  (((VTD_DOMAIN_ID_SHIFT - 4) / 2) & 7ULL)
 #define VTD_MGAW                    39  /* Maximum Guest Address Width */
 #define VTD_CAP_MGAW                (((VTD_MGAW - 1) & 0x3fULL) << 16)
-#define VTD_MAMV                    9ULL
+#define VTD_MAMV                    18ULL
 #define VTD_CAP_MAMV                (VTD_MAMV << 48)
 #define VTD_CAP_PSI                 (1ULL << 39)
+#define VTD_CAP_SLLPS               ((1ULL << 34) | (1ULL << 35))
 
 /* Supported Adjusted Guest Address Widths */
 #define VTD_CAP_SAGAW_SHIFT         8
@@ -320,7 +322,7 @@ typedef struct VTDInvDesc VTDInvDesc;
 /* Information about page-selective IOTLB invalidate */
 struct VTDIOTLBPageInvInfo {
     uint16_t domain_id;
-    uint64_t gfn;
+    uint64_t addr;
     uint8_t mask;
 };
 typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;
include/hw/i386/intel_iommu.h +1 -0
index 5dbadb7..b024ffa 100644
@@ -83,6 +83,7 @@ struct VTDIOTLBEntry {
     uint64_t gfn;
     uint16_t domain_id;
     uint64_t slpte;
+    uint64_t mask;
     bool read_flags;
     bool write_flags;
 };
hw/i386/intel_iommu.c +54 -22

150 lines not on this page · raw message

Signature · 1 line
MST
#48 lore raw

[Qemu-devel] [PULL 45/49] net: set endianness on all backend devices

In reply to Michael S. Tsirkin

From: Laurent Vivier <[email protected]>

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

---
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +11 -12
index 0bd5131..3940a04 100644
@@ -298,21 +298,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -341,8 +339,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
Signature · 1 line
MST
#49 lore raw

Re: [Qemu-devel] [PULL 45/49] net: set endianness on all backend devices

Quoted 11 lines · On Thu, 4 Feb 2016 23:54:01 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

From: Laurent Vivier <[email protected]>

commit 5be7d9f1b1452613b95c6ba70b8d7ad3d0797991
vhost-net: tell tap backend about the vnet endianness

makes vhost net to set the endianness of the device, but only for the first device.

In case of multiqueue, we have multiple devices... This patch sets the endianness for all the devices of the interface.

Quoted 7 lines

---

Cool !

Cc'ing stable since 2.4 and 2.5 need this fix as well.

Thanks.

--
Greg

Quoted 49 lines
 hw/net/vhost_net.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
hw/net/vhost_net.c +11 -12
index 0bd5131..3940a04 100644
@@ -298,21 +298,19 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
     VirtioBusState *vbus = VIRTIO_BUS(qbus);
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
-    int r, e, i;
+    int r, e, i, j;
 
     if (!k->set_guest_notifiers) {
         error_report("binding does not support guest notifiers");
-        r = -ENOSYS;
-        goto err;
+        return -ENOSYS;
     }
 
-    r = vhost_net_set_vnet_endian(dev, ncs[0].peer, true);
-    if (r < 0) {
-        goto err;
-    }
-
-    for (i = 0; i < total_queues; i++) {
-        vhost_net_set_vq_index(get_vhost_net(ncs[i].peer), i * 2);
+    for (j = 0; j < total_queues; j++) {
+        r = vhost_net_set_vnet_endian(dev, ncs[j].peer, true);
+        if (r < 0) {
+            goto err_endian;
+        }
+        vhost_net_set_vq_index(get_vhost_net(ncs[j].peer), j * 2);
     }
 
     r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
@@ -341,8 +339,9 @@ err_start:
         fflush(stderr);
     }
 err_endian:
-    vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
-err:
+    while (--j >= 0) {
+        vhost_net_set_vnet_endian(dev, ncs[j].peer, false);
+    }
     return r;
 }
 
#50 lore raw

[Qemu-devel] [PULL 46/49] i386/acpi: make floppy controller object dynamic

In reply to Michael S. Tsirkin

From: Roman Kagan <[email protected]>

Instead of statically declaring the floppy controller in DSDT, with its _STA method depending on some obscure bit in the parent ISA bridge, add the object dynamically to DSDT via AML API only when the controller is present.

The _STA method is no longer necessary and is therefore dropped. So are the declarations of the fields indicating whether the contoller is enabled.

---
 hw/i386/acpi-build.c | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)
hw/i386/acpi-build.c +3 -24
index 4554eb8..842c731 100644
@@ -1231,29 +1231,10 @@ static Aml *build_fdc_device_aml(void)
 {
     Aml *dev;
     Aml *crs;
-    Aml *method;
-    Aml *if_ctx;
-    Aml *else_ctx;
-    Aml *zero = aml_int(0);
-    Aml *is_present = aml_local(0);
 
     dev = aml_device("FDC0");
     aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700")));
 
-    method = aml_method("_STA", 0, AML_NOTSERIALIZED);
-    aml_append(method, aml_store(aml_name("FDEN"), is_present));
-    if_ctx = aml_if(aml_equal(is_present, zero));
-    {
-        aml_append(if_ctx, aml_return(aml_int(0x00)));
-    }
-    aml_append(method, if_ctx);
-    else_ctx = aml_else();
-    {
-        aml_append(else_ctx, aml_return(aml_int(0x0f)));
-    }
-    aml_append(method, else_ctx);
-    aml_append(dev, method);
-
     crs = aml_resource_template();
     aml_append(crs, aml_io(AML_DECODE16, 0x03F2, 0x03F2, 0x00, 0x04));
     aml_append(crs, aml_io(AML_DECODE16, 0x03F7, 0x03F7, 0x00, 0x01));
@@ -1411,7 +1392,9 @@ static void build_isa_devices_aml(Aml *table)
     aml_append(scope, build_rtc_device_aml());
     aml_append(scope, build_kbd_device_aml());
     aml_append(scope, build_mouse_device_aml());
-    aml_append(scope, build_fdc_device_aml());
+    if (!!pc_find_fdc0()) {
+        aml_append(scope, build_fdc_device_aml());
+    }
     aml_append(scope, build_lpt_device_aml());
     aml_append(scope, build_com_device_aml(1));
     aml_append(scope, build_com_device_aml(2));
@@ -1780,8 +1763,6 @@ static void build_q35_isa_bridge(Aml *table)
     aml_append(field, aml_named_field("COMB", 3));
     aml_append(field, aml_reserved_field(1));
     aml_append(field, aml_named_field("LPTD", 2));
-    aml_append(field, aml_reserved_field(2));
-    aml_append(field, aml_named_field("FDCD", 2));
     aml_append(dev, field);
 
     aml_append(dev, aml_operation_region("LPCE", AML_PCI_CONFIG,
@@ -1791,7 +1772,6 @@ static void build_q35_isa_bridge(Aml *table)
     aml_append(field, aml_named_field("CAEN", 1));
     aml_append(field, aml_named_field("CBEN", 1));
     aml_append(field, aml_named_field("LPEN", 1));
-    aml_append(field, aml_named_field("FDEN", 1));
     aml_append(dev, field);
 
     aml_append(scope, dev);
@@ -1839,7 +1819,6 @@ static void build_piix4_isa_bridge(Aml *table)
     aml_append(field, aml_reserved_field(3));
     aml_append(field, aml_named_field("CBEN", 1));
     aml_append(dev, field);
-    aml_append(dev, aml_name_decl("FDEN", aml_int(1)));
 
     aml_append(scope, dev);
     aml_append(table, scope);
Signature · 1 line
MST
#51 lore raw

[Qemu-devel] [PULL 47/49] expose floppy drive geometry and CMOS type

In reply to Michael S. Tsirkin

From: Roman Kagan <[email protected]>

Make it possible to query the geometry and the CMOS type of a floppy drive outside of the respective source files.

It will be useful, in particular, when dynamically building ACPI tables, and will allow to properly populate the corresponding ACPI objects and thus enable BIOS-less systems to access the floppy drives.

---
 include/hw/block/fdc.h |  2 ++
 include/hw/i386/pc.h   |  1 +
 hw/block/fdc.c         | 11 +++++++++++
 hw/i386/pc.c           |  2 +-
 4 files changed, 15 insertions(+), 1 deletion(-)
include/hw/block/fdc.h +2 -0
index adce14f..d87859e 100644
@@ -15,5 +15,7 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base,
                        DriveInfo **fds, qemu_irq *fdc_tc);
 
 FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i);
+void isa_fdc_get_drive_geometry(ISADevice *fdc, int i, uint8_t *cylinders,
+                                uint8_t *heads, uint8_t *sectors);
 
 #endif
include/hw/i386/pc.h +1 -0
index 8b3546e..472754c 100644
@@ -265,6 +265,7 @@ typedef void (*cpu_set_smm_t)(int smm, void *arg);
 void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name);
 
 ISADevice *pc_find_fdc0(void);
+int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* acpi_piix.c */
 
hw/block/fdc.c +11 -0
index 818e8a4..245184b 100644
@@ -2509,6 +2509,17 @@ FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i)
     return isa->state.drives[i].drive;
 }
 
+void isa_fdc_get_drive_geometry(ISADevice *fdc, int i, uint8_t *cylinders,
+                                uint8_t *heads, uint8_t *sectors)
+{
+    FDCtrlISABus *isa = ISA_FDC(fdc);
+    FDrive *drv = &isa->state.drives[i];
+
+    *cylinders = drv->max_track;
+    *heads = (drv->flags & FDISK_DBL_SIDES) ? 2 : 1;
+    *sectors = drv->last_sect;
+}
+
 static const VMStateDescription vmstate_isa_fdc ={
     .name = "fdc",
     .version_id = 2,
hw/i386/pc.c +1 -1
index ce185bb..fd8524f 100644
@@ -200,7 +200,7 @@ static void pic_irq_request(void *opaque, int irq, int level)
 
 #define REG_EQUIPMENT_BYTE          0x14
 
-static int cmos_get_fd_drive_type(FloppyDriveType fd0)
+int cmos_get_fd_drive_type(FloppyDriveType fd0)
 {
     int val;
 
Signature · 1 line
MST
#52 lore raw

[Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to Michael S. Tsirkin

From: Roman Kagan <[email protected]>

On x86-based systems Linux determines the presence and the type of floppy drives via a query of a CMOS field. So does SeaBIOS when populating the return data for int 0x13 function 0x08.

However Windows doesn't do it. Instead, it requests this information from BIOS via int 0x13/0x08 or through ACPI objects _FDE (Floppy Drive Enumerate) and _FDI (Floppy Drive Information) of the floppy controller object. On UEFI systems only ACPI-based detection is supported.

QEMU doesn't provide those objects in its ACPI tables and as a result floppy drives aren't invisible to Windows on UEFI/OVMF.

This patch adds those objects to the floppy controller in DSDT, populating them with the information from respective QEMU objects.

---
 hw/i386/acpi-build.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +58 -3
index 842c731..caa2e87 100644
@@ -37,6 +37,7 @@
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/loader.h"
 #include "hw/isa/isa.h"
+#include "hw/block/fdc.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/mem/nvdimm.h"
 #include "sysemu/tpm.h"
@@ -1227,10 +1228,47 @@ static void build_hpet_aml(Aml *table)
     aml_append(table, scope);
 }
 
-static Aml *build_fdc_device_aml(void)
+static Aml *build_fdinfo_aml(int idx, uint8_t type, uint8_t cylinders,
+                             uint8_t heads, uint8_t sectors)
+{
+    Aml *dev, *fdi;
+
+    dev = aml_device("FLP%c", 'A' + idx);
+
+    aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
+
+    fdi = aml_package(0x10);
+    aml_append(fdi, aml_int(idx));  /* Drive Number */
+    aml_append(fdi,
+        aml_int(cmos_get_fd_drive_type(type)));  /* Device Type */
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */
+    aml_append(fdi, aml_int(sectors));  /* Maximum Sector Number */
+    aml_append(fdi, aml_int(heads - 1));  /* Maximum Head Number */
+    /* SeaBIOS returns the below values for int 0x13 func 0x08 regardless of
+     * the drive type, so shall we */
+    aml_append(fdi, aml_int(0xAF));  /* disk_specify_1 */
+    aml_append(fdi, aml_int(0x02));  /* disk_specify_2 */
+    aml_append(fdi, aml_int(0x25));  /* disk_motor_wait */
+    aml_append(fdi, aml_int(0x02));  /* disk_sector_siz */
+    aml_append(fdi, aml_int(0x12));  /* disk_eot */
+    aml_append(fdi, aml_int(0x1B));  /* disk_rw_gap */
+    aml_append(fdi, aml_int(0xFF));  /* disk_dtl */
+    aml_append(fdi, aml_int(0x6C));  /* disk_formt_gap */
+    aml_append(fdi, aml_int(0xF6));  /* disk_fill */
+    aml_append(fdi, aml_int(0x0F));  /* disk_head_sttl */
+    aml_append(fdi, aml_int(0x08));  /* disk_motor_strt */
+
+    aml_append(dev, aml_name_decl("_FDI", fdi));
+    return dev;
+}
+
+static Aml *build_fdc_device_aml(ISADevice *fdc)
 {
+    int i;
     Aml *dev;
     Aml *crs;
+    uint32_t fde_buf[5] = {0, 0, 0, 0, cpu_to_le32(0x2)};
 
     dev = aml_device("FDC0");
     aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700")));
@@ -1243,6 +1281,21 @@ static Aml *build_fdc_device_aml(void)
         aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2));
     aml_append(dev, aml_name_decl("_CRS", crs));
 
+    for (i = 0; i < MAX_FD; i++) {
+        uint8_t type = isa_fdc_get_drive_type(fdc, i);
+
+        if (type < FLOPPY_DRIVE_TYPE_NONE) {
+            uint8_t cylinders, heads, sectors;
+
+            fde_buf[i] = cpu_to_le32(0x1);
+            isa_fdc_get_drive_geometry(fdc, i, &cylinders, &heads, &sectors);
+            aml_append(dev,
+                build_fdinfo_aml(i, type, cylinders, heads, sectors));
+        }
+    }
+    aml_append(dev, aml_name_decl("_FDE",
+               aml_buffer(sizeof(fde_buf), (uint8_t *) fde_buf)));
+
     return dev;
 }
 
@@ -1387,13 +1440,15 @@ static Aml *build_com_device_aml(uint8_t uid)
 
 static void build_isa_devices_aml(Aml *table)
 {
+    ISADevice *fdc = pc_find_fdc0();
+
     Aml *scope = aml_scope("_SB.PCI0.ISA");
 
     aml_append(scope, build_rtc_device_aml());
     aml_append(scope, build_kbd_device_aml());
     aml_append(scope, build_mouse_device_aml());
-    if (!!pc_find_fdc0()) {
-        aml_append(scope, build_fdc_device_aml());
+    if (!!fdc) {
+        aml_append(scope, build_fdc_device_aml(fdc));
     }
     aml_append(scope, build_lpt_device_aml());
     aml_append(scope, build_com_device_aml(1));
Signature · 1 line
MST
#53 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 51 lines · On Thu, 4 Feb 2016 23:54:13 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

From: Roman Kagan <[email protected]>

On x86-based systems Linux determines the presence and the type of floppy drives via a query of a CMOS field. So does SeaBIOS when populating the return data for int 0x13 function 0x08.

However Windows doesn't do it. Instead, it requests this information from BIOS via int 0x13/0x08 or through ACPI objects _FDE (Floppy Drive Enumerate) and _FDI (Floppy Drive Information) of the floppy controller object. On UEFI systems only ACPI-based detection is supported.

QEMU doesn't provide those objects in its ACPI tables and as a result floppy drives aren't invisible to Windows on UEFI/OVMF.

This patch adds those objects to the floppy controller in DSDT, populating them with the information from respective QEMU objects.

---
 hw/i386/acpi-build.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +6 -1
index 842c731..caa2e87 100644
@@ -37,6 +37,7 @@
 #include "hw/acpi/bios-linker-loader.h"
 #include "hw/loader.h"
 #include "hw/isa/isa.h"
+#include "hw/block/fdc.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/mem/nvdimm.h"
 #include "sysemu/tpm.h"
@@ -1227,10 +1228,47 @@ static void build_hpet_aml(Aml *table)
     aml_append(table, scope);
 }
 
-static Aml *build_fdc_device_aml(void)
+static Aml *build_fdinfo_aml(int idx, uint8_t type, uint8_t cylinders,
+                             uint8_t heads, uint8_t sectors)
+{
+    Aml *dev, *fdi;
+

hw/i386/acpi-build.c static void build_hpet_aml(Aml *table) · line 1245

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    dev = aml_device("FLP%c", 'A' + idx);
+
+    aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
+
+    fdi = aml_package(0x10);
+    aml_append(fdi, aml_int(idx));  /* Drive Number */
+    aml_append(fdi,
+        aml_int(cmos_get_fd_drive_type(type)));  /* Device Type */
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

Quoted 69 lines
hw/i386/acpi-build.c +42 -2
+    aml_append(fdi, aml_int(sectors));  /* Maximum Sector Number */
+    aml_append(fdi, aml_int(heads - 1));  /* Maximum Head Number */
+    /* SeaBIOS returns the below values for int 0x13 func 0x08 regardless of
+     * the drive type, so shall we */
+    aml_append(fdi, aml_int(0xAF));  /* disk_specify_1 */
+    aml_append(fdi, aml_int(0x02));  /* disk_specify_2 */
+    aml_append(fdi, aml_int(0x25));  /* disk_motor_wait */
+    aml_append(fdi, aml_int(0x02));  /* disk_sector_siz */
+    aml_append(fdi, aml_int(0x12));  /* disk_eot */
+    aml_append(fdi, aml_int(0x1B));  /* disk_rw_gap */
+    aml_append(fdi, aml_int(0xFF));  /* disk_dtl */
+    aml_append(fdi, aml_int(0x6C));  /* disk_formt_gap */
+    aml_append(fdi, aml_int(0xF6));  /* disk_fill */
+    aml_append(fdi, aml_int(0x0F));  /* disk_head_sttl */
+    aml_append(fdi, aml_int(0x08));  /* disk_motor_strt */
+
+    aml_append(dev, aml_name_decl("_FDI", fdi));
+    return dev;
+}
+
+static Aml *build_fdc_device_aml(ISADevice *fdc)
 {
+    int i;
     Aml *dev;
     Aml *crs;
+    uint32_t fde_buf[5] = {0, 0, 0, 0, cpu_to_le32(0x2)};
 
     dev = aml_device("FDC0");
     aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700")));
@@ -1243,6 +1281,21 @@ static Aml *build_fdc_device_aml(void)
         aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2));
     aml_append(dev, aml_name_decl("_CRS", crs));
 
+    for (i = 0; i < MAX_FD; i++) {
+        uint8_t type = isa_fdc_get_drive_type(fdc, i);
+
+        if (type < FLOPPY_DRIVE_TYPE_NONE) {
+            uint8_t cylinders, heads, sectors;
+
+            fde_buf[i] = cpu_to_le32(0x1);
+            isa_fdc_get_drive_geometry(fdc, i, &cylinders, &heads, &sectors);
+            aml_append(dev,
+                build_fdinfo_aml(i, type, cylinders, heads, sectors));
+        }
+    }
+    aml_append(dev, aml_name_decl("_FDE",
+               aml_buffer(sizeof(fde_buf), (uint8_t *) fde_buf)));
+
     return dev;
 }
 
@@ -1387,13 +1440,15 @@ static Aml *build_com_device_aml(uint8_t uid)
 
 static void build_isa_devices_aml(Aml *table)
 {
+    ISADevice *fdc = pc_find_fdc0();
+
     Aml *scope = aml_scope("_SB.PCI0.ISA");
 
     aml_append(scope, build_rtc_device_aml());
     aml_append(scope, build_kbd_device_aml());
     aml_append(scope, build_mouse_device_aml());
-    if (!!pc_find_fdc0()) {
-        aml_append(scope, build_fdc_device_aml());
+    if (!!fdc) {
+        aml_append(scope, build_fdc_device_aml(fdc));
     }
     aml_append(scope, build_lpt_device_aml());
     aml_append(scope, build_com_device_aml(1));
Reviewed-by Eric Blake
#54 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 20 lines · Igor Mammedov
Quoted 6 lines · On Thu, 4 Feb 2016 23:54:13 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
hw/i386/acpi-build.c +5 -1
-static Aml *build_fdc_device_aml(void)
+static Aml *build_fdinfo_aml(int idx, uint8_t type, uint8_t cylinders,
+                             uint8_t heads, uint8_t sectors)
+{
+    Aml *dev, *fdi;
+

hw/i386/acpi-build.c static void build_hpet_aml(Aml *table) · line 1245

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    dev = aml_device("FLP%c", 'A' + idx);
+
+    aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
+
+    fdi = aml_package(0x10);
+    aml_append(fdi, aml_int(idx));  /* Drive Number */
+    aml_append(fdi,
+        aml_int(cmos_get_fd_drive_type(type)));  /* Device Type */
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

Quoted 1 line

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Accidentally, I removed a "feature" where empty drives had geometry values applied to them, which allows seek on empty drives to work "by accident," as QEMU actually tries to disallow that.

Seeks on empty drives should work, though, but the easiest thing is to restore the misfeature where empty drives have non-zero geometries applied.

Document the hack accordingly.

[Maintainer edit]

This fix corrects a regression introduced in d5d47efc, where pick_geometry was modified such that it would not operate on empty drives, and as a result if there is no diskette inserted, QEMU no longer populates it with geometry bounds. As a result, seek fails when QEMU denies to move the current track, but reports success anyway. This can confuse the guest, leading to kernel panics in the guest.

Message-id: [email protected]

Roman.

#55 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 54 lines · Roman Kagan
Quoted 20 lines · Igor Mammedov
Quoted 6 lines · On Thu, 4 Feb 2016 23:54:13 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
hw/i386/acpi-build.c +5 -1
-static Aml *build_fdc_device_aml(void)
+static Aml *build_fdinfo_aml(int idx, uint8_t type, uint8_t cylinders,
+                             uint8_t heads, uint8_t sectors)
+{
+    Aml *dev, *fdi;
+

hw/i386/acpi-build.c static void build_hpet_aml(Aml *table) · line 1245

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    dev = aml_device("FLP%c", 'A' + idx);
+
+    aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
+
+    fdi = aml_package(0x10);
+    aml_append(fdi, aml_int(idx));  /* Drive Number */
+    aml_append(fdi,
+        aml_int(cmos_get_fd_drive_type(type)));  /* Device Type */
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

Quoted 1 line

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Accidentally, I removed a "feature" where empty drives had geometry values applied to them, which allows seek on empty drives to work "by accident," as QEMU actually tries to disallow that.

Seeks on empty drives should work, though, but the easiest thing is to restore the misfeature where empty drives have non-zero geometries applied.

Document the hack accordingly.

[Maintainer edit]

This fix corrects a regression introduced in d5d47efc, where pick_geometry was modified such that it would not operate on empty drives, and as a result if there is no diskette inserted, QEMU no longer populates it with geometry bounds. As a result, seek fails when QEMU denies to move the current track, but reports success anyway. This can confuse the guest, leading to kernel panics in the guest.

Quoted 6 lines

Message-id: [email protected]

Roman.

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

What do the guests use these values for? Are they fixed at boot?

--js

#56 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 17 lines · John Snow
Quoted 16 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

Quoted 6 lines
Quoted 1 line

fdc: fix detection under Linux

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

Roman.

#57 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },

...

You absolutely could get different sector and track counts before my patchset.

Quoted 11 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

Roman.

Signature · 1 line
—js
#58 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 49 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

This is entirely bogus. For one, it ties the platform firmware (the UEFI binary in the flash chip on your motherboard) to your specific floppy drive / controller. Say good-bye to any independently bought & installed floppy drives.

In theory, a floppy controller that comes with a separate PCI card could offer an option ROM with a UEFI driver in it, and that UEFI driver could install a separate SSDT with the hardware-matching _FDI in it. Still an unreasonable requirement, given that the *only* way Windows can be installed unattended (with external device drivers) is to provide those drivers on a floppy. Because, end-to-end,

do you want unattended UEFI installation with 3rd party drivers?

translates to

better have a PCI-based floppy controller such that its oprom installs an _FDI with dynamic hardware access,
*or* have your platform firmware match your floppy hardware

Implementing this in QEMU would require:
- inventing virt-only registers for the FDC that provide the current disk geometry,
- and generating AML code that reads those registers

*or*

- implementing the trial and error seeking in AML

Waste of time, don't do it. Microsoft have never documented their usage of _FDI. (Their forums are full of confused users whose physical floppy drives don't work under UEFI Windows!)

I'm quite sure the _FDI addition in the ACPI spec is actually from Microsoft as well, but of course the *reasoning* / background for _FDI is also not public. Microsoft seem to push stuff into the ACPI spec that serves them, while conveniently ignoring non-optional parts of the spec that they don't feel like supporting (I'm looking at you, DataTableRegion). And their level of support is not public.

So, the last paragraph of Roman's email
<http://thread.gmane.org/gmane.comp.emulators.qemu.block/7978/focus=8081> remains relevant -- do whatever ugly static hack is necessary in QEMU's AML generator to restore the one use case to working state that matters:
unattended installation to a virtio disk.

Noone in their right mind uses floppy in the guest interactively, and even for the unattended installation, floppy is used only because Windows is too stupid to work off a CD-ROM fully automatically. (Where everything one needs would be interrogable from on hardware / ATAPI / SCSI.)

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Thanks
Laszlo

#59 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 146 lines · Laszlo Ersek
Quoted 49 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

This is entirely bogus. For one, it ties the platform firmware (the UEFI binary in the flash chip on your motherboard) to your specific floppy drive / controller. Say good-bye to any independently bought & installed floppy drives.

In theory, a floppy controller that comes with a separate PCI card could offer an option ROM with a UEFI driver in it, and that UEFI driver could install a separate SSDT with the hardware-matching _FDI in it. Still an unreasonable requirement, given that the *only* way Windows can be installed unattended (with external device drivers) is to provide those drivers on a floppy. Because, end-to-end,

do you want unattended UEFI installation with 3rd party drivers?

translates to

better have a PCI-based floppy controller such that its oprom installs an _FDI with dynamic hardware access,
*or* have your platform firmware match your floppy hardware

Implementing this in QEMU would require:
- inventing virt-only registers for the FDC that provide the current disk geometry,
- and generating AML code that reads those registers

*or*

- implementing the trial and error seeking in AML

Waste of time, don't do it. Microsoft have never documented their usage of _FDI. (Their forums are full of confused users whose physical floppy drives don't work under UEFI Windows!)

I'm quite sure the _FDI addition in the ACPI spec is actually from Microsoft as well, but of course the *reasoning* / background for _FDI is also not public. Microsoft seem to push stuff into the ACPI spec that serves them, while conveniently ignoring non-optional parts of the spec that they don't feel like supporting (I'm looking at you, DataTableRegion). And their level of support is not public.

So, the last paragraph of Roman's email
<http://thread.gmane.org/gmane.comp.emulators.qemu.block/7978/focus=8081> remains relevant -- do whatever ugly static hack is necessary in QEMU's AML generator to restore the one use case to working state that matters:
unattended installation to a virtio disk.

Noone in their right mind uses floppy in the guest interactively, and even for the unattended installation, floppy is used only because Windows is too stupid to work off a CD-ROM fully automatically. (Where everything one needs would be interrogable from on hardware / ATAPI / SCSI.)

Quoted 5 lines

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Thanks
Laszlo

I'm fine with reporting some static values that make windows work fine. What I think is wrong is reporting geometry that happens to match current windows.

Signature · 1 line
MST
#60 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 83 lines · Michael S. Tsirkin
Quoted 82 lines · Laszlo Ersek
Quoted 49 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

Quoted 7 lines
Quoted 7 lines

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

At the very least, the Intel 82078 does not appear to be capable of replying to any query with a CHS triplet. It *can* report back the total number of sectors and the size of each sector, but that still requires geometry guesswork outside of the drive.

Quoted 22 lines
Quoted 22 lines

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

This is entirely bogus. For one, it ties the platform firmware (the UEFI binary in the flash chip on your motherboard) to your specific floppy drive / controller. Say good-bye to any independently bought & installed floppy drives.

In theory, a floppy controller that comes with a separate PCI card could offer an option ROM with a UEFI driver in it, and that UEFI driver could install a separate SSDT with the hardware-matching _FDI in it. Still an unreasonable requirement, given that the *only* way Windows can be installed unattended (with external device drivers) is to provide those drivers on a floppy. Because, end-to-end,

do you want unattended UEFI installation with 3rd party drivers?

translates to

Quoted 7 lines
Quoted 7 lines

better have a PCI-based floppy controller such that its oprom installs an _FDI with dynamic hardware access,
*or* have your platform firmware match your floppy hardware

Implementing this in QEMU would require:
- inventing virt-only registers for the FDC that provide the current disk geometry,

We do secretly have these registers, but of course there's no spec to interpreting what they mean. For instance, what do they read when the drive is empty? I am not sure that information is codified in the ACPI spec.

Could be wrong, you seemed to indicate that the ACPI spec said that the info matches what you get from a certain legacy bios routine, but I don't know the specifics of that routine, either.

Quoted 31 lines
Quoted 31 lines

- and generating AML code that reads those registers

*or*

- implementing the trial and error seeking in AML

Waste of time, don't do it. Microsoft have never documented their usage of _FDI. (Their forums are full of confused users whose physical floppy drives don't work under UEFI Windows!)

I'm quite sure the _FDI addition in the ACPI spec is actually from Microsoft as well, but of course the *reasoning* / background for _FDI is also not public. Microsoft seem to push stuff into the ACPI spec that serves them, while conveniently ignoring non-optional parts of the spec that they don't feel like supporting (I'm looking at you, DataTableRegion). And their level of support is not public.

So, the last paragraph of Roman's email
<http://thread.gmane.org/gmane.comp.emulators.qemu.block/7978/focus=8081> remains relevant -- do whatever ugly static hack is necessary in QEMU's AML generator to restore the one use case to working state that matters:
unattended installation to a virtio disk.

Noone in their right mind uses floppy in the guest interactively, and even for the unattended installation, floppy is used only because Windows is too stupid to work off a CD-ROM fully automatically. (Where everything one needs would be interrogable from on hardware / ATAPI / SCSI.)

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Quoted 7 lines
Quoted 2 lines

Thanks
Laszlo

I'm fine with reporting some static values that make windows work fine. What I think is wrong is reporting geometry that happens to match current windows.

Can you rephrase that last sentence? I don't follow, I'm sorry.

Roman, does the 0xFF "empty disk geometry" hack appear to work for Windows 10?

Maybe it's fine enough as-is, as per Laszlo's good synopsis here.

--js

#61 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 179 lines · John Snow
Quoted 83 lines · Michael S. Tsirkin
Quoted 82 lines · Laszlo Ersek
Quoted 49 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

Quoted 7 lines
Quoted 7 lines

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

At the very least, the Intel 82078 does not appear to be capable of replying to any query with a CHS triplet. It *can* report back the total number of sectors and the size of each sector, but that still requires geometry guesswork outside of the drive.

Quoted 22 lines
Quoted 22 lines

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

This is entirely bogus. For one, it ties the platform firmware (the UEFI binary in the flash chip on your motherboard) to your specific floppy drive / controller. Say good-bye to any independently bought & installed floppy drives.

In theory, a floppy controller that comes with a separate PCI card could offer an option ROM with a UEFI driver in it, and that UEFI driver could install a separate SSDT with the hardware-matching _FDI in it. Still an unreasonable requirement, given that the *only* way Windows can be installed unattended (with external device drivers) is to provide those drivers on a floppy. Because, end-to-end,

do you want unattended UEFI installation with 3rd party drivers?

translates to

Quoted 7 lines
Quoted 7 lines

better have a PCI-based floppy controller such that its oprom installs an _FDI with dynamic hardware access,
*or* have your platform firmware match your floppy hardware

Implementing this in QEMU would require:
- inventing virt-only registers for the FDC that provide the current disk geometry,

We do secretly have these registers, but of course there's no spec to interpreting what they mean. For instance, what do they read when the drive is empty? I am not sure that information is codified in the ACPI spec.

Could be wrong, you seemed to indicate that the ACPI spec said that the info matches what you get from a certain legacy bios routine, but I don't know the specifics of that routine, either.

Quoted 31 lines
Quoted 31 lines

- and generating AML code that reads those registers

*or*

- implementing the trial and error seeking in AML

Waste of time, don't do it. Microsoft have never documented their usage of _FDI. (Their forums are full of confused users whose physical floppy drives don't work under UEFI Windows!)

I'm quite sure the _FDI addition in the ACPI spec is actually from Microsoft as well, but of course the *reasoning* / background for _FDI is also not public. Microsoft seem to push stuff into the ACPI spec that serves them, while conveniently ignoring non-optional parts of the spec that they don't feel like supporting (I'm looking at you, DataTableRegion). And their level of support is not public.

So, the last paragraph of Roman's email
<http://thread.gmane.org/gmane.comp.emulators.qemu.block/7978/focus=8081> remains relevant -- do whatever ugly static hack is necessary in QEMU's AML generator to restore the one use case to working state that matters:
unattended installation to a virtio disk.

Noone in their right mind uses floppy in the guest interactively, and even for the unattended installation, floppy is used only because Windows is too stupid to work off a CD-ROM fully automatically. (Where everything one needs would be interrogable from on hardware / ATAPI / SCSI.)

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Quoted 7 lines
Quoted 2 lines

Thanks
Laszlo

I'm fine with reporting some static values that make windows work fine. What I think is wrong is reporting geometry that happens to match current windows.

Can you rephrase that last sentence? I don't follow, I'm sorry.

Quoted 6 lines

Roman, does the 0xFF "empty disk geometry" hack appear to work for Windows 10?

Maybe it's fine enough as-is, as per Laszlo's good synopsis here.

--js

Right. What I would like to avoid, if possible, is reporting the current data for whatever diskette happens to be used at machine_done time. This just makes things fragile if you switch
to a different one.

Signature · 1 line
MST
#62 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to John Snow
Quoted 9 lines · John Snow
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Laszlo Ersek

Implementing this in QEMU would require:
- inventing virt-only registers for the FDC that provide the current disk geometry,

We do secretly have these registers, but of course there's no spec to interpreting what they mean. For instance, what do they read when the drive is empty? I am not sure that information is codified in the ACPI spec.

There are various possibilities, like returning False for the corresponding drive in _FDE (Floppy Disk Enumerate) object, or returning 0 aka unknown as drive type in _FDI. Anyway I'd hate needing to expose all of that in an ACPI-accessible form, this is going to become too fat.

Quoted 3 lines

Could be wrong, you seemed to indicate that the ACPI spec said that the info matches what you get from a certain legacy bios routine, but I don't know the specifics of that routine, either.

Indeed, it's supposed to do the same as
https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH.3D08h:_Read_Drive_Parameters

and, as I wrote in another mail, the SeaBIOS implementation here is rather simplistic.

Quoted 4 lines

Roman, does the 0xFF "empty disk geometry" hack appear to work for Windows 10?

Maybe it's fine enough as-is, as per Laszlo's good synopsis here.

I'll test and let you know.

Roman.

#63 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to Laszlo Ersek
Quoted 22 lines · Laszlo Ersek

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

Quoted 5 lines

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

Well, as I wrote in another mail, SeaBIOS, which is supposed to provide the same information to int 0x13/0x08, populates it with static data based only on the drive type as encoded in CMOS at initialization time, and everyone seem to have been fine with that so far. I'll need to re-test it with real Windows guests, though.

Quoted 2 lines

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Hopefully that'll suffice.

Roman.

#64 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 29 lines · Roman Kagan
Quoted 22 lines · Laszlo Ersek

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

What this seems to require is: the firmware developer should write ACPI code that
- dynamically accesses the floppy drive / controller (using MMIO or IO port registers),
- retrieves the geometry of the disk actually inserted,
- and returns the data nicely packaged.

In effect, an ACPI-level driver for the disk.

Now, John explained to me (and please keep in mind that this is my personal account of his explanation, not a factual rendering thereof), that there used to be no *standard* way to interrogate the current disk's geometry, other than trial and error with seeking.

Quoted 5 lines

Apparently in UEFI Windows, Microsoft didn't want to implement this trial and error seeking, so -- given there was also no portable *hardware spec* to retrieve the same data, directly from the disk drive or controller -- they punted the entire question to ACPI. That is, to the firmware implementor.

Quoted 6 lines

Well, as I wrote in another mail, SeaBIOS, which is supposed to provide the same information to int 0x13/0x08, populates it with static data based only on the drive type as encoded in CMOS at initialization time, and everyone seem to have been fine with that so far. I'll need to re-test it with real Windows guests, though.

OK, but what we appear to be doing currently is polling the current geometry values for a drive instead of some pre-chosen ones based on the drive type.

What values does SeaBIOS use? (Can you point me to the table it uses?)

We could just duplicate those, probably.

Quoted 7 lines
Quoted 2 lines

IMHO, do the *absolute minimum* to adapt this AML generation patch to John's FDC rework, and ignore all dynamic aspects (like media change).

Hopefully that'll suffice.

Roman.

#65 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 8 lines · John Snow
Quoted 6 lines · Roman Kagan

Well, as I wrote in another mail, SeaBIOS, which is supposed to provide the same information to int 0x13/0x08, populates it with static data based only on the drive type as encoded in CMOS at initialization time, and everyone seem to have been fine with that so far. I'll need to re-test it with real Windows guests, though.

Quoted 5 lines

OK, but what we appear to be doing currently is polling the current geometry values for a drive instead of some pre-chosen ones based on the drive type.

What values does SeaBIOS use? (Can you point me to the table it uses?)

src/hw/floppy.c:

struct floppyinfo_s FloppyInfo[] VARFSEG = {
    // Unknown
    { {0, 0, 0}, 0x00, 0x00},
    // 1 - 360KB, 5.25" - 2 heads, 40 tracks, 9 sectors
    { {2, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
    // 2 - 1.2MB, 5.25" - 2 heads, 80 tracks, 15 sectors
    { {2, 80, 15}, FLOPPY_SIZE_525, FLOPPY_RATE_500K},
    // 3 - 720KB, 3.5"  - 2 heads, 80 tracks, 9 sectors
    { {2, 80, 9}, FLOPPY_SIZE_350, FLOPPY_RATE_250K},
    // 4 - 1.44MB, 3.5" - 2 heads, 80 tracks, 18 sectors
    { {2, 80, 18}, FLOPPY_SIZE_350, FLOPPY_RATE_500K},
    // 5 - 2.88MB, 3.5" - 2 heads, 80 tracks, 36 sectors
    { {2, 80, 36}, FLOPPY_SIZE_350, FLOPPY_RATE_1M},
    // 6 - 160k, 5.25"  - 1 heads, 40 tracks, 8 sectors
    { {1, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
    // 7 - 180k, 5.25"  - 1 heads, 40 tracks, 9 sectors
    { {1, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
    // 8 - 320k, 5.25"  - 2 heads, 40 tracks, 8 sectors
    { {2, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
};

The array is indexed by the floppy drive type from CMOS

Roman.

#66 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 38 lines · Roman Kagan
Quoted 8 lines · John Snow
Quoted 6 lines · Roman Kagan

Well, as I wrote in another mail, SeaBIOS, which is supposed to provide the same information to int 0x13/0x08, populates it with static data based only on the drive type as encoded in CMOS at initialization time, and everyone seem to have been fine with that so far. I'll need to re-test it with real Windows guests, though.

Quoted 5 lines

OK, but what we appear to be doing currently is polling the current geometry values for a drive instead of some pre-chosen ones based on the drive type.

What values does SeaBIOS use? (Can you point me to the table it uses?)

src/hw/floppy.c:

struct floppyinfo_s FloppyInfo[] VARFSEG = {
    // Unknown
    { {0, 0, 0}, 0x00, 0x00},
    // 1 - 360KB, 5.25" - 2 heads, 40 tracks, 9 sectors
    { {2, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
    // 2 - 1.2MB, 5.25" - 2 heads, 80 tracks, 15 sectors
    { {2, 80, 15}, FLOPPY_SIZE_525, FLOPPY_RATE_500K},
    // 3 - 720KB, 3.5"  - 2 heads, 80 tracks, 9 sectors
    { {2, 80, 9}, FLOPPY_SIZE_350, FLOPPY_RATE_250K},
    // 4 - 1.44MB, 3.5" - 2 heads, 80 tracks, 18 sectors
    { {2, 80, 18}, FLOPPY_SIZE_350, FLOPPY_RATE_500K},
    // 5 - 2.88MB, 3.5" - 2 heads, 80 tracks, 36 sectors
    { {2, 80, 36}, FLOPPY_SIZE_350, FLOPPY_RATE_1M},
    // 6 - 160k, 5.25"  - 1 heads, 40 tracks, 8 sectors
    { {1, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
    // 7 - 180k, 5.25"  - 1 heads, 40 tracks, 9 sectors
    { {1, 40, 9}, FLOPPY_SIZE_525, FLOPPY_RATE_300K},
    // 8 - 320k, 5.25"  - 2 heads, 40 tracks, 8 sectors
    { {2, 40, 8}, FLOPPY_SIZE_525, FLOPPY_RATE_250K},
};
Quoted 4 lines

The array is indexed by the floppy drive type from CMOS

Roman.

Hm, thanks. These seem like sane geometries, but looking at the QEMU geometry table ... I'm not sure what these even mean anymore, or what it might mean when they don't align with the SeaBIOS values. We probably don't even try very often. Maybe nobody ever has.

    { FLOPPY_DRIVE_TYPE_288, 36, 80, 1, FDRIVE_RATE_1M, }, // 5760
    { FLOPPY_DRIVE_TYPE_288, 39, 80, 1, FDRIVE_RATE_1M, }, // 6240
    { FLOPPY_DRIVE_TYPE_288, 40, 80, 1, FDRIVE_RATE_1M, }, // 6400
    { FLOPPY_DRIVE_TYPE_288, 44, 80, 1, FDRIVE_RATE_1M, }, // 7040
    { FLOPPY_DRIVE_TYPE_288, 48, 80, 1, FDRIVE_RATE_1M, }, // 7680

If sectors are 512 bytes, the byte size of these diskettes range from 2.813 MiB (or 2.99 Mb; I just today discovered the only way to get an even 2.88 is to count this as ((36 * 80 * 2) * 512 / 1000 / 1024), which mixes x^2 and x^10 designations) up through a whopping 3.74MiB/"3.84MB"

QEMU seems to try to support some real funky formats. Not even really sure where Fabrice got these numbers from.

Sigh, as long as things sort of seem to work. I'm not going to invest any further effort into figuring out exactly what we should be doing. If the UEFI guests are working I'm happy if you are.

--js

#67 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to Laszlo Ersek
Quoted 65 lines · Laszlo Ersek
Quoted 47 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

Quoted 7 lines

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

FWIW, that's not how I read the ACPI specification. I read it as saying that the information should be filled with the maximum number of CHS that the drive can support. So, even if a smaller disk happens to be in the drive the maximum the drive supports would not change.

Also, FWIW, SeaBIOS uses the standard 1.44MB floppy controller timing information even if a 5.25 drive is found - as far as I know this information is only ever used on PIO to the floppy controller and the QEMU floppy controller doesn't care what timing parameters it is programmed with.

-Kevin

#68 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 70 lines · Kevin O'Connor
Quoted 69 lines · Laszlo Ersek
Quoted 47 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

Quoted 8 lines
Quoted 3 lines

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

FWIW, that's not how I read the ACPI specification. I read it as saying that the information should be filled with the maximum number of CHS that the drive can support. So, even if a smaller disk happens to be in the drive the maximum the drive supports would not change.

If that works with Windows, I think it would be optimal for QEMU.

Thanks!
Laszlo

Quoted 9 lines

Also, FWIW, SeaBIOS uses the standard 1.44MB floppy controller timing information even if a 5.25 drive is found - as far as I know this information is only ever used on PIO to the floppy controller and the QEMU floppy controller doesn't care what timing parameters it is programmed with.

-Kevin

#69 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to Kevin O'Connor
Quoted 70 lines · Kevin O'Connor
Quoted 69 lines · Laszlo Ersek
Quoted 47 lines · John Snow
Quoted 20 lines · Roman Kagan
Quoted 19 lines · John Snow
Quoted 17 lines · Roman Kagan
Quoted 5 lines · Igor Mammedov

Review

Quoted 2 lines
(quoted diff) +2 -0
+    aml_append(fdi,
+        aml_int(cylinders - 1));  /* Maximum Cylinder Number */

this puts uint64_t(-1) in AML i.e. cylinders == 0 and overflow happens here

CCing Jon

I guess this is the effect of John's fdc rework. I used to think zero geometry was impossible at the time this patch was developed.

I wonder if it hasn't been fixed already by

commit fd9bdbd3459e5b9d51534f0747049bc5b6145e07
Author: John Snow <[email protected]>
Date: Wed Feb 3 11:28:55 2016 -0500

fdc: fix detection under Linux

Quoted 9 lines
Quoted 4 lines

Yes, hopefully solved on my end. The geometry values for an empty disk are not well defined (they certainly don't have any *meaning*) so if you are populating tables based on an empty drive, I just hope you also have the mechanisms needed to update said tables when the media changes.

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 14 lines

...

You absolutely could get different sector and track counts before my patchset.

Quoted 8 lines

Now if it actually has to be fully dynamic it's gonna be more involved...

Quoted 1 line

What do the guests use these values for? Are they fixed at boot?

Only Windows guests use it so it's hard to tell. I can only claim that if I stick bogus values into that ACPI object the guest fails to read the floppy.

We discussed this with John a bit on IRC.

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

Quoted 8 lines
Quoted 3 lines

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

FWIW, that's not how I read the ACPI specification. I read it as saying that the information should be filled with the maximum number of CHS that the drive can support. So, even if a smaller disk happens to be in the drive the maximum the drive supports would not change.

I agree. It says:
This object returns information about a floppy disk drive. This information is the same as
that returned by the INT 13 Function 08H on Intel Architecture PCs.

So disk drive, not disk information.

And FWIW I have an old "the undocumented PC" book which says this about int 13h function 8 (read diskette drive parameters):

"Remember this data is *not* the limits of the media in the drive, but the maximum capability of the specified drive".

Quoted 7 lines

Also, FWIW, SeaBIOS uses the standard 1.44MB floppy controller timing information even if a 5.25 drive is found - as far as I know this information is only ever used on PIO to the floppy controller and the QEMU floppy controller doesn't care what timing parameters it is programmed with.

-Kevin

#70 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Kevin O'Connor
Quoted 4 lines · Laszlo Ersek

In my opinion, the real mess in this case is in the ACPI spec itself. If you re-read the _FDI control method's description, the Package that it returns contains *dynamic* geometry data, about the *disk* (not *drive*):

Quoted 8 lines
Quoted 3 lines

- Maximum Cylinder Number // Integer (WORD)
- Maximum Sector Number // Integer (WORD)
- Maximum Head Number // Integer (WORD)

FWIW, that's not how I read the ACPI specification. I read it as saying that the information should be filled with the maximum number of CHS that the drive can support. So, even if a smaller disk happens to be in the drive the maximum the drive supports would not change.

I agree. It says:
This object returns information about a floppy disk drive. This information is the same as
that returned by the INT 13 Function 08H on Intel Architecture PCs.

Quoted 7 lines

So disk drive, not disk information.

And FWIW I have an old "the undocumented PC" book which says this about int 13h function 8 (read diskette drive parameters):

"Remember this data is *not* the limits of the media in the drive, but the maximum capability of the specified drive".

Thanks for the info, I've re-implemented the patchset according to it and Windows guests (w2k12, w10) seem to be happy with it, including dynamically (re-)inserting the "diskette" of compatible size.

I'll submit the patches shortly.

Thanks,
Roman.

#71 lore raw

Re: [Qemu-devel] [PULL 48/49] i386: populate floppy drive information in DSDT

In reply to John Snow
Quoted 20 lines · John Snow
Quoted 3 lines

I don't. At the time the patch was developed there basically were no mechanisms to update the geometry at all (and this was what you patchset addressed, in particular, wasn't it?) so I didn't care.

That's not true.

You could swap different 1.44MB-class diskettes for other geometries, check this out:

static const FDFormat fd_formats[] = {
    /* First entry is default format */
    /* 1.44 MB 3"1/2 floppy disks */
    { FDRIVE_DRV_144, 18, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 20, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 82, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 21, 83, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 22, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 23, 80, 1, FDRIVE_RATE_500K, },
    { FDRIVE_DRV_144, 24, 80, 1, FDRIVE_RATE_500K, },
Quoted 4 lines

...

You absolutely could get different sector and track counts before my patchset.

Indeed (sorry the patch was developed a couple of months ago so I had to look at the code to refresh my memory).

However, I tried to implement the part of ACPI spec that read

Quoted 5 lines

9.9.2 _FDI (Floppy Disk Information)
====================================
This object returns information about a floppy disk drive. This information is the same as that returned by the INT 13 Function 08H on IA-PCs.

so I went ahead and looked into what SeaBIOS did for int 0x13/0x08. And what it did was read the CMOS at 0x10 and obtain the drive type, and then return a hardcoded set of parameters (including geometry) associated to that drive type. So this was what I basically did here, too. (As a matter of fact the first patch I submitted was just pure ASL which mimicked exactly the SeaBIOS behavior: read the CMOS and return the corresponding Package with parameters.)

And IIRC the drive type couldn't change at runtime so I thought I wasn't doing worse than it was.

As for what to do now, I'll try to check how tolerant the guests are of changing the floppy geometry under them without updating _FDI, and then decide.

Roman.

#72 lore raw

[Qemu-devel] [PULL 49/49] acpi: update expected DSDT

In reply to Michael S. Tsirkin

Previous patches ("i386: populate floppy drive information in DSDT" and ("i386/acpi: make floppy controller object dynamic") change the floppy description in DSDT (and remove the floppy device if it's not present). Update expected files accordingly.

---
 tests/acpi-test-data/pc/DSDT         | Bin 5478 -> 5533 bytes
 tests/acpi-test-data/pc/DSDT.bridge  | Bin 7337 -> 7392 bytes
 tests/acpi-test-data/q35/DSDT        | Bin 8321 -> 8233 bytes
 tests/acpi-test-data/q35/DSDT.bridge | Bin 8338 -> 8250 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
index ec0e642b06967d3ec4d7a7d252b82b916f37a5e0..d3466baa0c0c93d16c51879f611a8d88f21bc162 100644
GIT binary patch
tests/acpi-test-data/pc/DSDT.bridge binary +0 -0
index 7b1c14b529f9f63fc3731c02225ce37c5cfbc0db..179f5d5348fc9ce4ecf60ee6019aca58e29fad69 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT binary +0 -0
index b492f04b8866ae82eaded81aa0ea2d3a4969dc5c..93356ac51915897db1d6615a8b6cfd607c2a2ca7 100644
GIT binary patch
tests/acpi-test-data/q35/DSDT.bridge binary +0 -0
index 3b72e250fa866ec34c315450643025e03c8c8cab..4f943e675cd4adc20ea237b9e97589ea56c5024e 100644
GIT binary patch
Signature · 1 line
MST
#73 lore raw
In reply to Michael S. Tsirkin
Quoted 15 lines · Michael S. Tsirkin

The following changes since commit 382d34ff9fcc534db32d54eb82590de7c04f9b33:

Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging (2016-02-03 19:00:33 +0000)

are available in the git repository at:

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

for you to fetch changes up to 32db7f56a0df015362fabd73c2d43dab7196fa64:

acpi: update expected DSDT (2016-02-04 20:54:21 +0200)

----------------------------------------------------------------
pc and misc cleanups and fixes, virtio optimizations

Quoted 8 lines

Included here:
Refactoring and bugfix patches in PC/ACPI.
New commands for ipmi.
Virtio optimizations.

 roms/seabios                                       |   2 +-

Dropped from my pull request queue because of the accidental-looking seabios update. Let me know if it's legit and I'll reprocess.

thanks
-- PMM

#74 lore raw
Quoted 21 lines · On Fri, 5 Feb 2016 15:03:55 +0000 Peter Maydell <[email protected]>…
Quoted 20 lines · Michael S. Tsirkin

The following changes since commit 382d34ff9fcc534db32d54eb82590de7c04f9b33:

Merge remote-tracking branch 'remotes/stefanha/tags/tracing-pull-request' into staging (2016-02-03 19:00:33 +0000)

are available in the git repository at:

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

for you to fetch changes up to 32db7f56a0df015362fabd73c2d43dab7196fa64:

acpi: update expected DSDT (2016-02-04 20:54:21 +0200)

----------------------------------------------------------------
pc and misc cleanups and fixes, virtio optimizations

Included here:
Refactoring and bugfix patches in PC/ACPI.
New commands for ipmi.
Virtio optimizations.

Quoted 6 lines
Quoted 3 lines
 roms/seabios                                       |   2 +-  

Dropped from my pull request queue because of the accidental-looking seabios update. Let me know if it's legit and I'll reprocess.

Pls, don't pull this request,

following commit BSODs WinXP,
"i386: populate floppy drive information in DSDT"
looks like wrong fdc geometry so far, but I'm still investigating it.

Quoted 4 lines

thanks
-- PMM