Skip to contentSkip to conversation

pc,pci,virtio fixes and cleanups

GIT PULL Michael S. Tsirkin 1 participant 15 messages Sep 29, 2013

lore
Share & tools
lore
#0 lore raw

The following changes since commit 2d1fe1873a984d1c2c89ffa3d12949cafc718551:

Merge remote-tracking branch 'pmaydell/tags/pull-target-arm-20130910' into staging (2013-09-11 14:46:52 -0500)

are available in the git repository at:

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

for you to fetch changes up to e26d3e734650640fabd7d95ace4f3a6f88725e0b:

smbios: Factor out smbios_maybe_add_str() (2013-09-28 23:49:39 +0300)

----------------------------------------------------------------
pc,pci,virtio fixes and cleanups

This includes pc and pci cleanups and enhancements, and a virtio-net bugfix related to softmac programming.

----------------------------------------------------------------
Hervé Poussineau (1):
pci: remove explicit check to 64K ioport size

Markus Armbruster (5):
smbios: Normalize smbios_entry_add()'s error handling to exit(1)
smbios: Convert to QemuOpts
smbios: Improve diagnostics for conflicting entries
smbios: Make multiple -smbios type= accumulate sanely
smbios: Factor out smbios_maybe_add_str()

Michael S. Tsirkin (8):
q35: make pci window address/size match guest cfg
range: add Range to typedefs
range: add min/max operations on ranges
pci: add helper to retrieve the 64-bit range
q35: use 64 bit window programmed by guest
piix: use 64 bit window programmed by guest
piix4: disable io on reset
virtio-net: fix up HMP NIC info string on reset

 include/hw/i386/smbios.h   |   5 +-
 include/hw/pci/pci.h       |   1 +
 include/qemu/range.h       |  20 ++-
 include/qemu/typedefs.h    |   1 +
 include/sysemu/arch_init.h |   2 +-
 include/sysemu/sysemu.h    |   1 +
 arch_init.c                |   9 +-
 hw/acpi/piix4.c            |   1 +
 hw/i386/smbios.c           | 339 ++++++++++++++++++++++++++++++++-------------
 hw/net/virtio-net.c        |   1 +
 hw/pci-host/piix.c         |  14 +-
 hw/pci-host/q35.c          |  24 +++-
 hw/pci/pci.c               |  56 +++++++-
 vl.c                       |   5 +-
 14 files changed, 359 insertions(+), 120 deletions(-)
Signature · 1 line
MST
#1 lore raw

[Qemu-devel] [PULL 01/14] q35: make pci window address/size match guest cfg

For Q35, MMCFG address and size are guest configurable. Update w32 property to make it behave accordingly.

---
 hw/pci-host/q35.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/pci-host/q35.c +10 -0
index 5473504..72f6b72 100644
@@ -214,6 +214,16 @@ static void mch_update_pciexbar(MCHPCIState *mch)
     }
     addr = pciexbar & addr_mask;
     pcie_host_mmcfg_update(pehb, enable, addr, length);
+    /* Leave enough space for the MCFG BAR */
+    /*
+     * TODO: this matches current bios behaviour, but it's not a power of two,
+     * which means an MTRR can't cover it exactly.
+     */
+    if (enable) {
+        mch->pci_info.w32.begin = addr + length;
+    } else {
+        mch->pci_info.w32.begin = MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT;
+    }
 }
 
 /* PAM */
Signature · 1 line
MST
#2 lore raw

[Qemu-devel] [PULL 02/14] range: add Range to typedefs

In reply to Michael S. Tsirkin

will help simplify header dependencies.

---
 include/qemu/range.h    | 2 +-
 include/qemu/typedefs.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/qemu/range.h +1 -1
index b76cc0d..4a0780d 100644
@@ -2,6 +2,7 @@
 #define QEMU_RANGE_H
 
 #include <inttypes.h>
+#include <qemu/typedefs.h>
 
 /*
  * Operations on 64 bit address ranges.
@@ -15,7 +16,6 @@ struct Range {
     uint64_t begin; /* First byte of the range, or 0 if empty. */
     uint64_t end;   /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */
 };
-typedef struct Range Range;
 
 /* Get last byte of a range from offset + length.
  * Undefined for ranges that wrap around 0. */
include/qemu/typedefs.h +1 -0
index 3205540..a4c1b84 100644
@@ -68,5 +68,6 @@ typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
 typedef struct FWCfgState FWCfgState;
 typedef struct PcGuestInfo PcGuestInfo;
+typedef struct Range Range;
 
 #endif /* QEMU_TYPEDEFS_H */
Signature · 1 line
MST
#3 lore raw

[Qemu-devel] [PULL 03/14] range: add min/max operations on ranges

In reply to Michael S. Tsirkin
---
 include/qemu/range.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/qemu/range.h +18 -0
index 4a0780d..aae9720 100644
@@ -17,6 +17,24 @@ struct Range {
     uint64_t end;   /* 1 + the last byte. 0 if range empty or ends at ~0x0LL. */
 };
 
+static inline void range_extend(Range *range, Range *extend_by)
+{
+    if (!extend_by->begin && !extend_by->end) {
+        return;
+    }
+    if (!range->begin && !range->end) {
+        *range = *extend_by;
+        return;
+    }
+    if (range->begin > extend_by->begin) {
+        range->begin = extend_by->begin;
+    }
+    /* Compare last byte in case region ends at ~0x0LL */
+    if (range->end - 1 < extend_by->end - 1) {
+        range->end = extend_by->end;
+    }
+}
+
 /* Get last byte of a range from offset + length.
  * Undefined for ranges that wrap around 0. */
 static inline uint64_t range_get_last(uint64_t offset, uint64_t len)
Signature · 1 line
MST
#4 lore raw

[Qemu-devel] [PULL 04/14] pci: add helper to retrieve the 64-bit range

In reply to Michael S. Tsirkin
---
 include/hw/pci/pci.h |  1 +
 hw/pci/pci.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
include/hw/pci/pci.h +1 -0
index 37979aa..4b90e5d 100644
@@ -397,6 +397,7 @@ const char *pci_root_bus_path(PCIDevice *dev);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, PCIBus *root, const char *devaddr);
+void pci_bus_get_w64_range(PCIBus *bus, Range *range);
 
 int pci_parse_devaddr(const char *addr, int *domp, int *busp,
                       unsigned int *slotp, unsigned int *funcp);
hw/pci/pci.c +50 -0

56 lines not on this page · raw message

Signature · 1 line
MST
#5 lore raw

[Qemu-devel] [PULL 05/14] q35: use 64 bit window programmed by guest

In reply to Michael S. Tsirkin

Detect the 64 bit window programmed by firmware
and configure properties accordingly.

---
 hw/pci-host/q35.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
hw/pci-host/q35.c +10 -4
index 72f6b72..23dbeea 100644
@@ -89,18 +89,24 @@ static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v,
                                           void *opaque, const char *name,
                                           Error **errp)
 {
-    Q35PCIHost *s = Q35_HOST_DEVICE(obj);
+    PCIHostState *h = PCI_HOST_BRIDGE(obj);
+    Range w64;
+
+    pci_bus_get_w64_range(h->bus, &w64);
 
-    visit_type_uint64(v, &s->mch.pci_info.w64.begin, name, errp);
+    visit_type_uint64(v, &w64.begin, name, errp);
 }
 
 static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v,
                                         void *opaque, const char *name,
                                         Error **errp)
 {
-    Q35PCIHost *s = Q35_HOST_DEVICE(obj);
+    PCIHostState *h = PCI_HOST_BRIDGE(obj);
+    Range w64;
+
+    pci_bus_get_w64_range(h->bus, &w64);
 
-    visit_type_uint64(v, &s->mch.pci_info.w64.end, name, errp);
+    visit_type_uint64(v, &w64.end, name, errp);
 }
 
 static Property mch_props[] = {
Signature · 1 line
MST
#6 lore raw

[Qemu-devel] [PULL 06/14] piix: use 64 bit window programmed by guest

In reply to Michael S. Tsirkin

Detect the 64 bit window programmed by firmware
and configure properties accordingly.

---
 hw/pci-host/piix.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
hw/pci-host/piix.c +10 -4
index 221d82b..c041149 100644
@@ -235,18 +235,24 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v,
                                                 void *opaque, const char *name,
                                                 Error **errp)
 {
-    I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj);
+    PCIHostState *h = PCI_HOST_BRIDGE(obj);
+    Range w64;
+
+    pci_bus_get_w64_range(h->bus, &w64);
 
-    visit_type_uint64(v, &s->pci_info.w64.begin, name, errp);
+    visit_type_uint64(v, &w64.begin, name, errp);
 }
 
 static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,
                                               void *opaque, const char *name,
                                               Error **errp)
 {
-    I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj);
+    PCIHostState *h = PCI_HOST_BRIDGE(obj);
+    Range w64;
+
+    pci_bus_get_w64_range(h->bus, &w64);
 
-    visit_type_uint64(v, &s->pci_info.w64.end, name, errp);
+    visit_type_uint64(v, &w64.end, name, errp);
 }
 
 static void i440fx_pcihost_initfn(Object *obj)
Signature · 1 line
MST
#7 lore raw

[Qemu-devel] [PULL 07/14] piix4: disable io on reset

In reply to Michael S. Tsirkin

io base register at 0x40 is cleared on reset,
but io is not disabled until some other event
happens to call pm_io_space_update.

Invoke pm_io_space_update directly to make this
consistent.

---
 hw/acpi/piix4.c | 1 +
 1 file changed, 1 insertion(+)
hw/acpi/piix4.c +1 -0
index 0b8d1d9..b46bd5e 100644
@@ -380,6 +380,7 @@ static void piix4_reset(void *opaque)
         /* Mark SMM as already inited (until KVM supports SMM). */
         pci_conf[0x5B] = 0x02;
     }
+    pm_io_space_update(s);
     piix4_update_hotplug(s);
 }
 
Signature · 1 line
MST
#8 lore raw

[Qemu-devel] [PULL 08/14] pci: remove explicit check to 64K ioport size

In reply to Michael S. Tsirkin

From: Hervé Poussineau <[email protected]>

This check is useless, as bigger addresses will be ignored when added to 'io' MemoryRegion, which has a size of 64K.

However, some architectures don't use the 'io' MemoryRegion, like the alpha and versatile platforms. They create a PCI I/O region bigger than 64K, so let them handle PCI I/O BARs in the higher range.

MST: reinstated work-around for BAR sizing.

---
 hw/pci/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci/pci.c +4 -2
index 52cbab7..00554a0 100644
@@ -1028,8 +1028,10 @@ static pcibus_t pci_bar_address(PCIDevice *d,
         }
         new_addr = pci_get_long(d->config + bar) & ~(size - 1);
         last_addr = new_addr + size - 1;
-        /* NOTE: we have only 64K ioports on PC */
-        if (last_addr <= new_addr || new_addr == 0 || last_addr > UINT16_MAX) {
+        /* Check if 32 bit BAR wraps around explicitly.
+         * TODO: make priorities correct and remove this work around.
+         */
+        if (last_addr <= new_addr || new_addr == 0 || last_addr >= UINT32_MAX) {
             return PCI_BAR_UNMAPPED;
         }
         return new_addr;
Signature · 1 line
MST
#9 lore raw

[Qemu-devel] [PULL 09/14] virtio-net: fix up HMP NIC info string on reset

In reply to Michael S. Tsirkin

When mac is updated on reset, info string has stale data. Fix it up.

---
 hw/net/virtio-net.c | 1 +
 1 file changed, 1 insertion(+)
hw/net/virtio-net.c +1 -0
index dd41008..22dbd05 100644
@@ -314,6 +314,7 @@ static void virtio_net_reset(VirtIODevice *vdev)
     n->mac_table.uni_overflow = 0;
     memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
     memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
+    qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
     memset(n->vlans, 0, MAX_VLAN >> 3);
 }
 
Signature · 1 line
MST
#10 lore raw

[Qemu-devel] [PULL 10/14] smbios: Normalize smbios_entry_add()'s error handling to exit(1)

In reply to Michael S. Tsirkin

From: Markus Armbruster <[email protected]>

It exits on all error conditions but one, where it returns -1. Normalize, and return void.

---
 include/hw/i386/smbios.h |  2 +-
 arch_init.c              |  4 +---
 hw/i386/smbios.c         | 10 +++++-----
 3 files changed, 7 insertions(+), 9 deletions(-)
include/hw/i386/smbios.h +1 -1
index 9babeaf..56c6108 100644
@@ -13,7 +13,7 @@
  *
  */
 
-int smbios_entry_add(const char *t);
+void smbios_entry_add(const char *t);
 void smbios_add_field(int type, int offset, const void *data, size_t len);
 uint8_t *smbios_get_table(size_t *length);
 
arch_init.c +1 -3
index e47e139..6ae8eb6 100644
@@ -1137,9 +1137,7 @@ void do_acpitable_option(const QemuOpts *opts)
 void do_smbios_option(const char *optarg)
 {
 #ifdef TARGET_I386
-    if (smbios_entry_add(optarg) < 0) {
-        exit(1);
-    }
+    smbios_entry_add(optarg);
 #endif
 }
 
hw/i386/smbios.c +5 -5
index e708cb8..0608aee 100644
@@ -183,7 +183,7 @@ static void smbios_build_type_1_fields(const char *t)
                          buf, strlen(buf) + 1);
 }
 
-int smbios_entry_add(const char *t)
+void smbios_entry_add(const char *t)
 {
     char buf[1024];
 
@@ -222,7 +222,7 @@ int smbios_entry_add(const char *t)
         smbios_entries_len += sizeof(*table) + size;
         (*(uint16_t *)smbios_entries) =
                 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
-        return 0;
+        return;
     }
 
     if (get_param_value(buf, sizeof(buf), "type", t)) {
@@ -230,10 +230,10 @@ int smbios_entry_add(const char *t)
         switch (type) {
         case 0:
             smbios_build_type_0_fields(t);
-            return 0;
+            return;
         case 1:
             smbios_build_type_1_fields(t);
-            return 0;
+            return;
         default:
             error_report("Don't know how to build fields for SMBIOS type %ld",
                          type);
@@ -242,5 +242,5 @@ int smbios_entry_add(const char *t)
     }
 
     error_report("Must specify type= or file=");
-    return -1;
+    exit(1);
 }
Signature · 1 line
MST
#11 lore raw

[Qemu-devel] [PULL 11/14] smbios: Convert to QemuOpts

In reply to Michael S. Tsirkin

From: Markus Armbruster <[email protected]>

So that it can be set in config file for -readconfig.

This tightens parsing of -smbios, and makes it more consistent with other options: unknown parameters are rejected, numbers with trailing junk are rejected, when a parameter is given multiple times, last rather than first wins, ...

MST: drop one chunk to fix build errors

---
 include/hw/i386/smbios.h   |   4 +-
 include/sysemu/arch_init.h |   2 +-
 arch_init.c                |   4 +-
 hw/i386/smbios.c           | 209 ++++++++++++++++++++++++++++++++++++---------
 vl.c                       |   3 +-
 5 files changed, 179 insertions(+), 43 deletions(-)
include/hw/i386/smbios.h +3 -1
index 56c6108..d9f43b7 100644
@@ -13,7 +13,9 @@
  *
  */
 
-void smbios_entry_add(const char *t);
+#include "qemu/option.h"
+
+void smbios_entry_add(QemuOpts *opts);
 void smbios_add_field(int type, int offset, const void *data, size_t len);
 uint8_t *smbios_get_table(size_t *length);
 
include/sysemu/arch_init.h +1 -1
index dece913..be71bca 100644
@@ -28,7 +28,7 @@ extern const uint32_t arch_type;
 
 void select_soundhw(const char *optarg);
 void do_acpitable_option(const QemuOpts *opts);
-void do_smbios_option(const char *optarg);
+void do_smbios_option(QemuOpts *opts);
 void cpudef_init(void);
 void audio_init(void);
 int tcg_available(void);
arch_init.c +2 -2
index 6ae8eb6..62f1118 100644
@@ -1134,10 +1134,10 @@ void do_acpitable_option(const QemuOpts *opts)
 #endif
 }
 
-void do_smbios_option(const char *optarg)
+void do_smbios_option(QemuOpts *opts)
 {
 #ifdef TARGET_I386
-    smbios_entry_add(optarg);
+    smbios_entry_add(opts);
 #endif
 }
 
hw/i386/smbios.c +171 -38

289 lines not on this page · raw message

vl.c +2 -1
index 4e709d5..503f903 100644
@@ -3491,7 +3491,8 @@ int main(int argc, char **argv, char **envp)
                 do_acpitable_option(opts);
                 break;
             case QEMU_OPTION_smbios:
-                do_smbios_option(optarg);
+                opts = qemu_opts_parse(qemu_find_opts("smbios"), optarg, 0);
+                do_smbios_option(opts);
                 break;
             case QEMU_OPTION_enable_kvm:
                 olist = qemu_find_opts("machine");
Signature · 1 line
MST
#12 lore raw

[Qemu-devel] [PULL 12/14] smbios: Improve diagnostics for conflicting entries

In reply to Michael S. Tsirkin

From: Markus Armbruster <[email protected]>

We allow either tables or fields for the same type. Makes sense, because SeaBIOS uses fields only when no tables are present.

We do this by searching the SMBIOS blob for a previously added table or field. Error messages look like this:

qemu-system-x86_64: -smbios type=1,serial=42: SMBIOS type 1 table already defined, cannot add field

User needs to know that "table" is defined by -smbios file=..., and "field" by -smbios type=...

Instead of searching the blob, record additions of interest, and check that. Simpler, and makes better error messages possible:

qemu-system-x86_64: -smbios file=smbios_type_1.bin: Can't mix file= and type= for same type
qemu-system-x86_64: -smbios type=1,serial=42,serial=99: This is the conflicting setting

---
 hw/i386/smbios.c | 43 +++++++++++++++++--------------------------
 1 file changed, 17 insertions(+), 26 deletions(-)
hw/i386/smbios.c +17 -26
index abfd6f7..4263551 100644
@@ -48,6 +48,12 @@ static uint8_t *smbios_entries;
 static size_t smbios_entries_len;
 static int smbios_type4_count = 0;
 
+static struct {
+    bool seen;
+    int headertype;
+    Location loc;
+} first_opt[2];
+
 static QemuOptsList qemu_smbios_opts = {
     .name = "smbios",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head),
@@ -159,35 +165,20 @@ uint8_t *smbios_get_table(size_t *length)
  */
 static void smbios_check_collision(int type, int entry)
 {
-    uint16_t *num_entries = (uint16_t *)smbios_entries;
-    struct smbios_header *header;
-    char *p;
-    int i;
-
-    if (!num_entries)
-        return;
-
-    p = (char *)(num_entries + 1);
-
-    for (i = 0; i < *num_entries; i++) {
-        header = (struct smbios_header *)p;
-        if (entry == SMBIOS_TABLE_ENTRY && header->type == SMBIOS_FIELD_ENTRY) {
-            struct smbios_field *field = (void *)header;
-            if (type == field->type) {
-                error_report("SMBIOS type %d field already defined, "
-                             "cannot add table", type);
-                exit(1);
-            }
-        } else if (entry == SMBIOS_FIELD_ENTRY &&
-                   header->type == SMBIOS_TABLE_ENTRY) {
-            struct smbios_structure_header *table = (void *)(header + 1);
-            if (type == table->type) {
-                error_report("SMBIOS type %d table already defined, "
-                             "cannot add field", type);
+    if (type < ARRAY_SIZE(first_opt)) {
+        if (first_opt[type].seen) {
+            if (first_opt[type].headertype != entry) {
+                error_report("Can't mix file= and type= for same type");
+                loc_push_restore(&first_opt[type].loc);
+                error_report("This is the conflicting setting");
+                loc_pop(&first_opt[type].loc);
                 exit(1);
             }
+        } else {
+            first_opt[type].seen = true;
+            first_opt[type].headertype = entry;
+            loc_save(&first_opt[type].loc);
         }
-        p += le16_to_cpu(header->length);
     }
 }
 
Signature · 1 line
MST
#13 lore raw

[Qemu-devel] [PULL 13/14] smbios: Make multiple -smbios type= accumulate sanely

In reply to Michael S. Tsirkin

From: Markus Armbruster <[email protected]>

Currently, -smbios type=T,NAME=VAL,... adds one field (T,NAME) with value VAL to fw_cfg for each unique NAME. If NAME occurs multiple times, the last one's VAL is used (before the QemuOpts conversion, the first one was used).

Multiple -smbios can add multiple fields with the same (T, NAME). SeaBIOS reads all of them from fw_cfg, but uses only the first field (T, NAME). The others are ignored.

"First one wins, subsequent ones get ignored silently" isn't nice. We commonly let the last option win. Useful, because it lets you -readconfig first, then selectively override with command line options.

Clean up -smbios to work the common way. Accumulate the settings, with later ones overwriting earlier ones. Put the result into fw_cfg (no more useless duplicates).

Bonus cleanup: qemu_uuid_parse() no longer sets SMBIOS system uuid by side effect.

---
 include/hw/i386/smbios.h |   1 -
 include/sysemu/sysemu.h  |   1 +
 arch_init.c              |   3 -
 hw/i386/smbios.c         | 152 ++++++++++++++++++++++++++++-------------------
 vl.c                     |   2 +
 5 files changed, 94 insertions(+), 65 deletions(-)
include/hw/i386/smbios.h +0 -1
index d9f43b7..b08ec71 100644
@@ -16,7 +16,6 @@
 #include "qemu/option.h"
 
 void smbios_entry_add(QemuOpts *opts);
-void smbios_add_field(int type, int offset, const void *data, size_t len);
 uint8_t *smbios_get_table(size_t *length);
 
 /*
include/sysemu/sysemu.h +1 -0
index b1aa059..4257736 100644
@@ -16,6 +16,7 @@ extern const char *bios_name;
 
 extern const char *qemu_name;
 extern uint8_t qemu_uuid[];
+extern bool qemu_uuid_set;
 int qemu_uuid_parse(const char *str, uint8_t *uuid);
 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
 
arch_init.c +0 -3
index 62f1118..150647b 100644
@@ -1113,9 +1113,6 @@ int qemu_uuid_parse(const char *str, uint8_t *uuid)
     if (ret != 16) {
         return -1;
     }
-#ifdef TARGET_I386
-    smbios_add_field(1, offsetof(struct smbios_type_1, uuid), uuid, 16);
-#endif
     return 0;
 }
 
hw/i386/smbios.c +91 -61

236 lines not on this page · raw message

vl.c +2 -0
index 503f903..fb8006e 100644
@@ -254,6 +254,7 @@ uint64_t node_mem[MAX_NODES];
 unsigned long *node_cpumask[MAX_NODES];
 
 uint8_t qemu_uuid[16];
+bool qemu_uuid_set;
 
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;
@@ -3588,6 +3589,7 @@ int main(int argc, char **argv, char **envp)
                             " Wrong format.\n");
                     exit(1);
                 }
+                qemu_uuid_set = true;
                 break;
 	    case QEMU_OPTION_option_rom:
 		if (nb_option_roms >= MAX_OPTION_ROMS) {
Signature · 1 line
MST
#14 lore raw

[Qemu-devel] [PULL 14/14] smbios: Factor out smbios_maybe_add_str()

In reply to Michael S. Tsirkin

From: Markus Armbruster <[email protected]>

---
 hw/i386/smbios.c | 61 +++++++++++++++++++++++---------------------------------
 1 file changed, 25 insertions(+), 36 deletions(-)
hw/i386/smbios.c +25 -36
index d2dba6c..d3f1ee6 100644
@@ -210,21 +210,22 @@ static void smbios_add_field(int type, int offset, const void *data, size_t len)
             cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
 }
 
-static void smbios_build_type_0_fields(void)
+static void smbios_maybe_add_str(int type, int offset, const char *data)
 {
-    if (type0.vendor) {
-        smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str),
-                         type0.vendor, strlen(type0.vendor) + 1);
-    }
-    if (type0.version) {
-        smbios_add_field(0, offsetof(struct smbios_type_0, bios_version_str),
-                         type0.version, strlen(type0.version) + 1);
+    if (data) {
+        smbios_add_field(type, offset, data, strlen(data) + 1);
     }
-    if (type0.date) {
-        smbios_add_field(0, offsetof(struct smbios_type_0,
+}
+
+static void smbios_build_type_0_fields(void)
+{
+    smbios_maybe_add_str(0, offsetof(struct smbios_type_0, vendor_str),
+                         type0.vendor);
+    smbios_maybe_add_str(0, offsetof(struct smbios_type_0, bios_version_str),
+                         type0.version);
+    smbios_maybe_add_str(0, offsetof(struct smbios_type_0,
                                      bios_release_date_str),
-                         type0.date, strlen(type0.date) + 1);
-    }
+                         type0.date);
     if (type0.have_major_minor) {
         smbios_add_field(0, offsetof(struct smbios_type_0,
                                      system_bios_major_release),
@@ -237,30 +238,18 @@ static void smbios_build_type_0_fields(void)
 
 static void smbios_build_type_1_fields(void)
 {
-    if (type1.manufacturer) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, manufacturer_str),
-                         type1.manufacturer, strlen(type1.manufacturer) + 1);
-    }
-    if (type1.product) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, product_name_str),
-                         type1.product, strlen(type1.product) + 1);
-    }
-    if (type1.version) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, version_str),
-                         type1.version, strlen(type1.version) + 1);
-    }
-    if (type1.serial) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, serial_number_str),
-                         type1.serial, strlen(type1.serial) + 1);
-    }
-    if (type1.sku) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, sku_number_str),
-                         type1.sku, strlen(type1.sku) + 1);
-    }
-    if (type1.family) {
-        smbios_add_field(1, offsetof(struct smbios_type_1, family_str),
-                         type1.family, strlen(type1.family) + 1);
-    }
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, manufacturer_str),
+                         type1.manufacturer);
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, product_name_str),
+                         type1.product);
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, version_str),
+                         type1.version);
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, serial_number_str),
+                         type1.serial);
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, sku_number_str),
+                         type1.sku);
+    smbios_maybe_add_str(1, offsetof(struct smbios_type_1, family_str),
+                         type1.family);
     if (qemu_uuid_set) {
         smbios_add_field(1, offsetof(struct smbios_type_1, uuid),
                          qemu_uuid, 16);
Signature · 1 line
MST