qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	"Daniel P. Berrange" <berrange@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PULL 01/25] smbios: support setting OEM strings table
Date: Thu, 21 Dec 2017 16:27:58 +0200	[thread overview]
Message-ID: <1513866427-27125-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1513866427-27125-1-git-send-email-mst@redhat.com>

From: "Daniel P. Berrange" <berrange@redhat.com>

The cloud-init program currently allows fetching of its data by repurposing of
the 'system' type 'serial' field. This is a clear abuse of the serial field that
would clash with other valid usage a virt management app might have for that
field.

Fortunately the SMBIOS defines an "OEM Strings" table whose puporse is to allow
exposing of arbitrary vendor specific strings to the operating system. This is
perfect for use with cloud-init, or as a way to pass arguments to OS installers
such as anaconda.

This patch makes it easier to support this with QEMU. e.g.

  $QEMU -smbios type=11,value=Hello,value=World,value=Tricky,,value=test

Which results in the guest seeing dmidecode data

  Handle 0x0E00, DMI type 11, 5 bytes
  OEM Strings
          String 1: Hello
          String 2: World
          String 3: Tricky,value=test

It is suggested that any app wanting to make use of this OEM strings capability
for accepting data from the host mgmt layer should use its name as a string
prefix. e.g. to expose OEM strings targetting both cloud init and anaconda in
parallel the mgmt app could set

  $QEMU -smbios type=11,value=cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/,\
        value=anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os

which would appear as

  Handle 0x0E00, DMI type 11, 5 bytes
  OEM Strings
          String 1: cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/
          String 2: anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os

Use of such string prefixes means the app won't have to care which string slot
its data appears in.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/smbios/smbios_build.h   | 12 ++++++++
 include/hw/smbios/smbios.h |  6 ++++
 hw/smbios/smbios.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)

diff --git a/hw/smbios/smbios_build.h b/hw/smbios/smbios_build.h
index 68b8b72..93b360d 100644
--- a/hw/smbios/smbios_build.h
+++ b/hw/smbios/smbios_build.h
@@ -63,6 +63,18 @@ extern unsigned smbios_table_cnt;
         }                                                                 \
     } while (0)
 
+#define SMBIOS_TABLE_SET_STR_LIST(tbl_type, value)                        \
+    do {                                                                  \
+        int len = (value != NULL) ? strlen(value) + 1 : 0;                \
+        if (len > 1) {                                                    \
+            smbios_tables = g_realloc(smbios_tables,                      \
+                                      smbios_tables_len + len);           \
+            memcpy(smbios_tables + smbios_tables_len, value, len);        \
+            smbios_tables_len += len;                                     \
+            ++str_index;                                                  \
+        }                                                                 \
+    } while (0)
+
 #define SMBIOS_BUILD_TABLE_POST                                           \
     do {                                                                  \
         size_t term_cnt, t_size;                                          \
diff --git a/include/hw/smbios/smbios.h b/include/hw/smbios/smbios.h
index 31e8d5f..a83adb9 100644
--- a/include/hw/smbios/smbios.h
+++ b/include/hw/smbios/smbios.h
@@ -195,6 +195,12 @@ struct smbios_type_4 {
     uint16_t processor_family2;
 } QEMU_PACKED;
 
+/* SMBIOS type 11 - OEM strings */
+struct smbios_type_11 {
+    struct smbios_structure_header header;
+    uint8_t count;
+} QEMU_PACKED;
+
 /* SMBIOS type 16 - Physical Memory Array (v2.7) */
 struct smbios_type_16 {
     struct smbios_structure_header header;
diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 1a5437a..5d11f01 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -96,6 +96,11 @@ static struct {
 } type4;
 
 static struct {
+    size_t nvalues;
+    const char **values;
+} type11;
+
+static struct {
     const char *loc_pfx, *bank, *manufacturer, *serial, *asset, *part;
     uint16_t speed;
 } type17;
@@ -282,6 +287,14 @@ static const QemuOptDesc qemu_smbios_type4_opts[] = {
     { /* end of list */ }
 };
 
+static const QemuOptDesc qemu_smbios_type11_opts[] = {
+    {
+        .name = "value",
+        .type = QEMU_OPT_STRING,
+        .help = "OEM string data",
+    },
+};
+
 static const QemuOptDesc qemu_smbios_type17_opts[] = {
     {
         .name = "type",
@@ -590,6 +603,27 @@ static void smbios_build_type_4_table(unsigned instance)
     smbios_type4_count++;
 }
 
+static void smbios_build_type_11_table(void)
+{
+    char count_str[128];
+    size_t i;
+
+    if (type11.nvalues == 0) {
+        return;
+    }
+
+    SMBIOS_BUILD_TABLE_PRE(11, 0xe00, true); /* required */
+
+    snprintf(count_str, sizeof(count_str), "%zu", type11.nvalues);
+    t->count = type11.nvalues;
+
+    for (i = 0; i < type11.nvalues; i++) {
+        SMBIOS_TABLE_SET_STR_LIST(11, type11.values[i]);
+    }
+
+    SMBIOS_BUILD_TABLE_POST;
+}
+
 #define ONE_KB ((ram_addr_t)1 << 10)
 #define ONE_MB ((ram_addr_t)1 << 20)
 #define ONE_GB ((ram_addr_t)1 << 30)
@@ -832,6 +866,8 @@ void smbios_get_tables(const struct smbios_phys_mem_area *mem_array,
             smbios_build_type_4_table(i);
         }
 
+        smbios_build_type_11_table();
+
 #define MAX_DIMM_SZ (16ll * ONE_GB)
 #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \
                                         : ((ram_size - 1) % MAX_DIMM_SZ) + 1)
@@ -882,6 +918,38 @@ static void save_opt(const char **dest, QemuOpts *opts, const char *name)
     }
 }
 
+
+struct opt_list {
+    const char *name;
+    size_t *ndest;
+    const char ***dest;
+};
+
+static int save_opt_one(void *opaque,
+                        const char *name, const char *value,
+                        Error **errp)
+{
+    struct opt_list *opt = opaque;
+
+    if (!g_str_equal(name, opt->name)) {
+        return 0;
+    }
+
+    *opt->dest = g_renew(const char *, *opt->dest, (*opt->ndest) + 1);
+    (*opt->dest)[*opt->ndest] = value;
+    (*opt->ndest)++;
+    return 0;
+}
+
+static void save_opt_list(size_t *ndest, const char ***dest,
+                          QemuOpts *opts, const char *name)
+{
+    struct opt_list opt = {
+        name, ndest, dest,
+    };
+    qemu_opt_foreach(opts, save_opt_one, &opt, NULL);
+}
+
 void smbios_entry_add(QemuOpts *opts, Error **errp)
 {
     const char *val;
@@ -1035,6 +1103,10 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
             save_opt(&type4.asset, opts, "asset");
             save_opt(&type4.part, opts, "part");
             return;
+        case 11:
+            qemu_opts_validate(opts, qemu_smbios_type11_opts, &error_fatal);
+            save_opt_list(&type11.nvalues, &type11.values, opts, "value");
+            return;
         case 17:
             qemu_opts_validate(opts, qemu_smbios_type17_opts, &error_fatal);
             save_opt(&type17.loc_pfx, opts, "loc_pfx");
-- 
MST

  reply	other threads:[~2017-12-21 14:28 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 14:27 [Qemu-devel] [PULL 00/25] pc, pci, virtio: features, fixes, cleanups Michael S. Tsirkin
2017-12-21 14:27 ` Michael S. Tsirkin [this message]
2017-12-21 14:28 ` [Qemu-devel] [PULL 02/25] qdev-properties: add UUID property type Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 03/25] vmgenid: use " Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 04/25] tests: add test to check VirtQueue object Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 05/25] pci: Rename root bus initialization functions for clarity Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 06/25] pci: Move bridge data structures from pci_bus.h to pci_bridge.h Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 07/25] pci: Add pci_dev_bus_num() helper Michael S. Tsirkin
2017-12-21 14:28 ` [Qemu-devel] [PULL 08/25] pci: Eliminate redundant PCIDevice::bus pointer Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 09/25] pci: Eliminate pci_find_primary_bus() Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 10/25] virtio_error: don't invoke status callbacks Michael S. Tsirkin
2018-02-13 20:53   ` [Qemu-devel] [Qemu-stable] " Peter Lieven
2018-02-13 22:23     ` Michael S. Tsirkin
2018-02-14 21:12       ` Peter Lieven
2017-12-21 14:29 ` [Qemu-devel] [PULL 11/25] tests/pxe-test: Remove unnecessary special case test functions Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 12/25] tests/pxe-test: Use table of testcases rather than open-coding Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 13/25] tests/pxe-test: Test net booting over IPv6 in some cases Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 14/25] tests/pxe-test: Add some extra tests Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 15/25] hw/block/nvme: QOM'ify PCI NVME Michael S. Tsirkin
2017-12-21 20:38   ` Michael S. Tsirkin
2017-12-21 23:02     ` Philippe Mathieu-Daudé
2017-12-21 14:29 ` [Qemu-devel] [PULL 16/25] hw/pci-host/piix: QOM'ify the IGD Passthrough host bridge Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 17/25] hw/pci-host/xilinx: QOM'ify the AXI-PCIe " Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 18/25] hw/pci: remove obsolete PCIDevice->init() Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 19/25] vhost-user: fix indentation in protocol specification Michael S. Tsirkin
2017-12-21 14:29 ` [Qemu-devel] [PULL 20/25] vhost-user: document memory accesses Michael S. Tsirkin
2017-12-21 14:30 ` [Qemu-devel] [PULL 23/25] virtio-pci: Don't force Subsystem Vendor ID = Vendor ID Michael S. Tsirkin
2017-12-21 14:31 ` [Qemu-devel] [PULL 24/25] dump-guest-memory.py: fix "You can't do that without a process to debug" Michael S. Tsirkin
2017-12-21 14:31 ` [Qemu-devel] [PULL 25/25] smbus: do not immediately complete commands Michael S. Tsirkin
2017-12-21 14:33 ` [Qemu-devel] [PULL 21/25] intel_iommu: remove X86_IOMMU_PCI_DEVFN_MAX Michael S. Tsirkin
2017-12-21 14:34 ` [Qemu-devel] [PULL 22/25] intel_iommu: fix error param in string Michael S. Tsirkin
2017-12-21 20:26 ` [Qemu-devel] [PULL 00/25] pc, pci, virtio: features, fixes, cleanups Peter Maydell
2017-12-21 20:37   ` Michael S. Tsirkin
2017-12-21 23:05     ` Peter Maydell
2017-12-21 23:42       ` Michael S. Tsirkin
2017-12-22  0:44         ` Philippe Mathieu-Daudé
2017-12-21 23:05     ` Philippe Mathieu-Daudé
2017-12-21 23:43       ` Michael S. Tsirkin
2018-01-08  9:14         ` Peter Maydell
2018-01-08 17:04           ` Michael S. Tsirkin
2018-01-08 18:10           ` Michael S. Tsirkin
2018-01-09  1:10             ` David Gibson
2018-01-09  4:09               ` Michael S. Tsirkin
2018-01-16  2:48               ` Michael S. Tsirkin
2018-01-16  6:28                 ` Jason Wang
2018-01-16  6:33                   ` Jason Wang
2018-01-16  8:03                   ` Dmitry Fleytman
2018-01-17  3:14                     ` Jason Wang
2018-01-09  4:11           ` Michael S. Tsirkin
2018-01-11 15:31             ` Peter Maydell
2018-01-11 19:59               ` Michael S. Tsirkin
2018-01-11 20:06               ` Michael S. Tsirkin
2018-01-11 21:05               ` Michael S. Tsirkin
2018-01-12 10:44                 ` Peter Maydell
2018-01-12 16:02                   ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513866427-27125-2-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=berrange@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).