diff --git a/0076-smbios-support-setting-OEM-strings-.patch b/0076-smbios-support-setting-OEM-strings-.patch new file mode 100644 index 00000000..ada51cee --- /dev/null +++ b/0076-smbios-support-setting-OEM-strings-.patch @@ -0,0 +1,215 @@ +From 3eb1915349b247cd88fd050c0caf37070b5e6977 Mon Sep 17 00:00:00 2001 +From: "Daniel P. Berrange" +Date: Sat, 28 Oct 2017 21:51:36 +0100 +Subject: [PATCH] smbios: support setting OEM strings table + +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 +Reviewed-by: Michael S. Tsirkin +Signed-off-by: Michael S. Tsirkin +(cherry picked from commit 2d6dcbf93fb01b4a7f45a93d276d4d74b16392dd) +[BR: FATE#323624] +Signed-off-by: Bruce Rogers +--- + hw/smbios/smbios.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ + hw/smbios/smbios_build.h | 12 ++++++++ + include/hw/smbios/smbios.h | 6 ++++ + 3 files changed, 90 insertions(+) + +diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c +index 1a5437a07d..5d11f01874 100644 +--- a/hw/smbios/smbios.c ++++ b/hw/smbios/smbios.c +@@ -95,6 +95,11 @@ static struct { + const char *sock_pfx, *manufacturer, *version, *serial, *asset, *part; + } type4; + ++static struct { ++ size_t nvalues; ++ const char **values; ++} type11; ++ + static struct { + const char *loc_pfx, *bank, *manufacturer, *serial, *asset, *part; + uint16_t speed; +@@ -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"); +diff --git a/hw/smbios/smbios_build.h b/hw/smbios/smbios_build.h +index 68b8b72e09..93b360d520 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 31e8d5f47e..a83adb93d7 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/qemu-linux-user.changes b/qemu-linux-user.changes index 9cb08992..e61f8005 100644 --- a/qemu-linux-user.changes +++ b/qemu-linux-user.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Mar 9 20:52:00 UTC 2018 - brogers@suse.com + +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-2.11 +* Patches added: + 0076-smbios-support-setting-OEM-strings-.patch + ------------------------------------------------------------------- Sat Mar 3 14:24:13 UTC 2018 - brogers@suse.com diff --git a/qemu-linux-user.spec b/qemu-linux-user.spec index 1eb5e185..180479e7 100644 --- a/qemu-linux-user.spec +++ b/qemu-linux-user.spec @@ -101,6 +101,7 @@ Patch0072: 0072-tests-qmp-test-blacklist-query-sev-.patch Patch0073: 0073-sev-i386-add-migration-blocker.patch Patch0074: 0074-cpu-i386-populate-CPUID-0x8000_001F.patch Patch0075: 0075-migration-warn-about-inconsistent-s.patch +Patch0076: 0076-smbios-support-setting-OEM-strings-.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. Source400: update_git.sh @@ -205,6 +206,7 @@ syscall layer occurs on the native hardware and operating system. %patch0073 -p1 %patch0074 -p1 %patch0075 -p1 +%patch0076 -p1 %build ./configure \ diff --git a/qemu-testsuite.changes b/qemu-testsuite.changes index 405795a0..a59d8263 100644 --- a/qemu-testsuite.changes +++ b/qemu-testsuite.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Mar 9 20:51:57 UTC 2018 - brogers@suse.com + +- Add support for setting OEM strings table (fate#323624) + 0076-smbios-support-setting-OEM-strings-.patch +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-2.11 + ------------------------------------------------------------------- Sat Mar 3 14:24:10 UTC 2018 - brogers@suse.com diff --git a/qemu-testsuite.spec b/qemu-testsuite.spec index 1a60ab61..e657671d 100644 --- a/qemu-testsuite.spec +++ b/qemu-testsuite.spec @@ -205,6 +205,7 @@ Patch0072: 0072-tests-qmp-test-blacklist-query-sev-.patch Patch0073: 0073-sev-i386-add-migration-blocker.patch Patch0074: 0074-cpu-i386-populate-CPUID-0x8000_001F.patch Patch0075: 0075-migration-warn-about-inconsistent-s.patch +Patch0076: 0076-smbios-support-setting-OEM-strings-.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. @@ -879,6 +880,7 @@ This package provides a service file for starting and stopping KSM. %patch0073 -p1 %patch0074 -p1 %patch0075 -p1 +%patch0076 -p1 %if 0%{?suse_version} > 1320 %patch1000 -p1 diff --git a/qemu.changes b/qemu.changes index 405795a0..a59d8263 100644 --- a/qemu.changes +++ b/qemu.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Mar 9 20:51:57 UTC 2018 - brogers@suse.com + +- Add support for setting OEM strings table (fate#323624) + 0076-smbios-support-setting-OEM-strings-.patch +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-2.11 + ------------------------------------------------------------------- Sat Mar 3 14:24:10 UTC 2018 - brogers@suse.com diff --git a/qemu.spec b/qemu.spec index 6c614437..c8f517e3 100644 --- a/qemu.spec +++ b/qemu.spec @@ -205,6 +205,7 @@ Patch0072: 0072-tests-qmp-test-blacklist-query-sev-.patch Patch0073: 0073-sev-i386-add-migration-blocker.patch Patch0074: 0074-cpu-i386-populate-CPUID-0x8000_001F.patch Patch0075: 0075-migration-warn-about-inconsistent-s.patch +Patch0076: 0076-smbios-support-setting-OEM-strings-.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. @@ -879,6 +880,7 @@ This package provides a service file for starting and stopping KSM. %patch0073 -p1 %patch0074 -p1 %patch0075 -p1 +%patch0076 -p1 %if 0%{?suse_version} > 1320 %patch1000 -p1