From 6ab6369f3c4985060d98d0e5233271a5354e19b3 Mon Sep 17 00:00:00 2001 From: Xuemei Liu Date: Fri, 30 May 2025 16:38:03 +0800 Subject: [PATCH] SMBIOS support for RISC-V virt machine Signed-off-by: Xuemei Liu --- 0285-smbios-add-processor-family-option.patch | 110 ++++++++++++++++++ ...tion-to-set-default-processor-family.patch | 51 ++++++++ ...BIOS-support-for-RISC-V-virt-machine.patch | 109 +++++++++++++++++ ...tions-enable-smbios-option-on-RISC-V.patch | 36 ++++++ qemu.spec | 13 ++- 5 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 0285-smbios-add-processor-family-option.patch create mode 100644 0286-smbios-function-to-set-default-processor-family.patch create mode 100644 0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch create mode 100644 0288-qemu-options-enable-smbios-option-on-RISC-V.patch diff --git a/0285-smbios-add-processor-family-option.patch b/0285-smbios-add-processor-family-option.patch new file mode 100644 index 0000000..b9ace9d --- /dev/null +++ b/0285-smbios-add-processor-family-option.patch @@ -0,0 +1,110 @@ +From d04259d84da9fc063c8598eff5e4ca431eee5681 Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Tue, 23 Jan 2024 19:42:26 +0100 +Subject: [PATCH 1/4] smbios: add processor-family option + +For RISC-V the SMBIOS standard requires specific values of the processor +family value depending on the bitness of the CPU. + +Add a processor-family option for SMBIOS table 4. + +The value of processor-family may exceed 255 and therefore must be provided +in the Processor Family 2 field. Set the Processor Family field to 0xFE +which signals that the Processor Family 2 is used. + +Signed-off-by: Heinrich Schuchardt +Reviewed-by: Alistair Francis +Reviewed-by: Andrew Jones +Message-ID: <20240123184229.10415-2-heinrich.schuchardt@canonical.com> +Signed-off-by: Alistair Francis +(cherry picked from commit b5831d79671cea3f7bd42cffab93fe6eab8c3db0) +Signed-off-by: Xuemei Liu +--- + hw/smbios/smbios.c | 13 +++++++++++-- + qemu-options.hx | 4 ++-- + 2 files changed, 13 insertions(+), 4 deletions(-) + +diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c +index 8a44d3f27..232f3bdde 100644 +--- a/hw/smbios/smbios.c ++++ b/hw/smbios/smbios.c +@@ -102,6 +102,7 @@ static struct { + #define DEFAULT_CPU_SPEED 2000 + + static struct { ++ uint16_t processor_family; + const char *sock_pfx, *manufacturer, *version, *serial, *asset, *part; + uint64_t max_speed; + uint64_t current_speed; +@@ -110,6 +111,7 @@ static struct { + .max_speed = DEFAULT_CPU_SPEED, + .current_speed = DEFAULT_CPU_SPEED, + .processor_id = 0, ++ .processor_family = 0x01, /* Other */ + }; + + struct type8_instance { +@@ -337,6 +339,10 @@ static const QemuOptDesc qemu_smbios_type4_opts[] = { + .name = "part", + .type = QEMU_OPT_STRING, + .help = "part number", ++ }, { ++ .name = "processor-family", ++ .type = QEMU_OPT_NUMBER, ++ .help = "processor family", + }, { + .name = "processor-id", + .type = QEMU_OPT_NUMBER, +@@ -738,7 +744,7 @@ static void smbios_build_type_4_table(MachineState *ms, unsigned instance) + snprintf(sock_str, sizeof(sock_str), "%s%2x", type4.sock_pfx, instance); + SMBIOS_TABLE_SET_STR(4, socket_designation_str, sock_str); + t->processor_type = 0x03; /* CPU */ +- t->processor_family = 0x01; /* Other */ ++ t->processor_family = 0xfe; /* use Processor Family 2 field */ + SMBIOS_TABLE_SET_STR(4, processor_manufacturer_str, type4.manufacturer); + if (type4.processor_id == 0) { + t->processor_id[0] = cpu_to_le32(smbios_cpuid_version); +@@ -770,7 +776,7 @@ static void smbios_build_type_4_table(MachineState *ms, unsigned instance) + t->thread_count = (threads_per_socket > 255) ? 0xFF : threads_per_socket; + + t->processor_characteristics = cpu_to_le16(0x02); /* Unknown */ +- t->processor_family2 = cpu_to_le16(0x01); /* Other */ ++ t->processor_family2 = cpu_to_le16(type4.processor_family); + + if (tbl_len == SMBIOS_TYPE_4_LEN_V30) { + t->core_count2 = t->core_enabled2 = cpu_to_le16(cores_per_socket); +@@ -1414,6 +1420,9 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) + return; + } + save_opt(&type4.sock_pfx, opts, "sock_pfx"); ++ type4.processor_family = qemu_opt_get_number(opts, ++ "processor-family", ++ 0x01 /* Other */); + save_opt(&type4.manufacturer, opts, "manufacturer"); + save_opt(&type4.version, opts, "version"); + save_opt(&type4.serial, opts, "serial"); +diff --git a/qemu-options.hx b/qemu-options.hx +index caeca1d9b..0029569f2 100644 +--- a/qemu-options.hx ++++ b/qemu-options.hx +@@ -2679,7 +2679,7 @@ DEF("smbios", HAS_ARG, QEMU_OPTION_smbios, + " specify SMBIOS type 3 fields\n" + "-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str]\n" + " [,asset=str][,part=str][,max-speed=%d][,current-speed=%d]\n" +- " [,processor-id=%d]\n" ++ " [,processor-family=%d,processor-id=%d]\n" + " specify SMBIOS type 4 fields\n" + "-smbios type=8[,external_reference=str][,internal_reference=str][,connector_type=%d][,port_type=%d]\n" + " specify SMBIOS type 8 fields\n" +@@ -2707,7 +2707,7 @@ SRST + ``-smbios type=3[,manufacturer=str][,version=str][,serial=str][,asset=str][,sku=str]`` + Specify SMBIOS type 3 fields + +-``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-id=%d]`` ++``-smbios type=4[,sock_pfx=str][,manufacturer=str][,version=str][,serial=str][,asset=str][,part=str][,processor-family=%d][,processor-id=%d]`` + Specify SMBIOS type 4 fields + + ``-smbios type=11[,value=str][,path=filename]`` +-- +2.27.0 + diff --git a/0286-smbios-function-to-set-default-processor-family.patch b/0286-smbios-function-to-set-default-processor-family.patch new file mode 100644 index 0000000..7561e6c --- /dev/null +++ b/0286-smbios-function-to-set-default-processor-family.patch @@ -0,0 +1,51 @@ +From f1f734b376b8a9e00af2415158a436c1768ab4c5 Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Tue, 23 Jan 2024 19:42:27 +0100 +Subject: [PATCH 2/4] smbios: function to set default processor family + +Provide a function to set the default processor family. + +Signed-off-by: Heinrich Schuchardt +Reviewed-by: Andrew Jones +Message-ID: <20240123184229.10415-3-heinrich.schuchardt@canonical.com> +Signed-off-by: Alistair Francis +(cherry picked from commit 6f3b727bcc867688034ef1489a58e958142973b1) +Signed-off-by: Xuemei Liu +--- + hw/smbios/smbios.c | 7 +++++++ + include/hw/firmware/smbios.h | 1 + + 2 files changed, 8 insertions(+) + +diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c +index 232f3bdde..a3c4e52ce 100644 +--- a/hw/smbios/smbios.c ++++ b/hw/smbios/smbios.c +@@ -1001,6 +1001,13 @@ void smbios_set_cpuid(uint32_t version, uint32_t features) + field = value; \ + } + ++void smbios_set_default_processor_family(uint16_t processor_family) ++{ ++ if (type4.processor_family <= 0x01) { ++ type4.processor_family = processor_family; ++ } ++} ++ + void smbios_set_defaults(const char *manufacturer, const char *product, + const char *version, bool legacy_mode, + bool uuid_encoded, SmbiosEntryPointType ep_type) +diff --git a/include/hw/firmware/smbios.h b/include/hw/firmware/smbios.h +index 7f3259a63..6e514982d 100644 +--- a/include/hw/firmware/smbios.h ++++ b/include/hw/firmware/smbios.h +@@ -295,6 +295,7 @@ void smbios_set_cpuid(uint32_t version, uint32_t features); + void smbios_set_defaults(const char *manufacturer, const char *product, + const char *version, bool legacy_mode, + bool uuid_encoded, SmbiosEntryPointType ep_type); ++void smbios_set_default_processor_family(uint16_t processor_family); + uint8_t *smbios_get_table_legacy(MachineState *ms, size_t *length); + void smbios_get_tables(MachineState *ms, + const struct smbios_phys_mem_area *mem_array, +-- +2.27.0 + diff --git a/0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch b/0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch new file mode 100644 index 0000000..e5ad6aa --- /dev/null +++ b/0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch @@ -0,0 +1,109 @@ +From 7811c915477709a31e0e75d7d796a6bce6d52212 Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Tue, 23 Jan 2024 19:42:28 +0100 +Subject: [PATCH 3/4] target/riscv: SMBIOS support for RISC-V virt machine + +Generate SMBIOS tables for the RISC-V mach-virt. +Add CONFIG_SMBIOS=y to the RISC-V default config. +Set the default processor family in the type 4 table. + +The implementation is based on the corresponding ARM and Loongson code. + +With the patch the following firmware tables are provided: + + etc/smbios/smbios-anchor + etc/smbios/smbios-tables + +Signed-off-by: Heinrich Schuchardt +Reviewed-by: Andrew Jones +Message-ID: <20240123184229.10415-4-heinrich.schuchardt@canonical.com> +Signed-off-by: Alistair Francis +(cherry picked from commit ecf286478475d11ae4cdef7e52d9c8e1672f2868) +Signed-off-by: Xuemei Liu +--- + hw/riscv/Kconfig | 1 + + hw/riscv/virt.c | 42 ++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 43 insertions(+) + +diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig +index b6a5eb445..1e11ac943 100644 +--- a/hw/riscv/Kconfig ++++ b/hw/riscv/Kconfig +@@ -41,6 +41,7 @@ config RISCV_VIRT + select RISCV_IMSIC + select SIFIVE_PLIC + select SIFIVE_TEST ++ select SMBIOS + select VIRTIO_MMIO + select FW_CFG_DMA + select PLATFORM_BUS +diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c +index d2eac2415..9b29ed110 100644 +--- a/hw/riscv/virt.c ++++ b/hw/riscv/virt.c +@@ -36,6 +36,7 @@ + #include "hw/riscv/boot.h" + #include "hw/riscv/numa.h" + #include "kvm/kvm_riscv.h" ++#include "hw/firmware/smbios.h" + #include "hw/intc/riscv_aclint.h" + #include "hw/intc/riscv_aplic.h" + #include "hw/intc/riscv_imsic.h" +@@ -1249,6 +1250,45 @@ static void create_platform_bus(RISCVVirtState *s, DeviceState *irqchip) + sysbus_mmio_get_region(sysbus, 0)); + } + ++static void virt_build_smbios(RISCVVirtState *s) ++{ ++ MachineClass *mc = MACHINE_GET_CLASS(s); ++ MachineState *ms = MACHINE(s); ++ uint8_t *smbios_tables, *smbios_anchor; ++ size_t smbios_tables_len, smbios_anchor_len; ++ struct smbios_phys_mem_area mem_array; ++ const char *product = "QEMU Virtual Machine"; ++ ++ if (kvm_enabled()) { ++ product = "KVM Virtual Machine"; ++ } ++ ++ smbios_set_defaults("QEMU", product, mc->name, false, ++ true, SMBIOS_ENTRY_POINT_TYPE_64); ++ ++ if (riscv_is_32bit(&s->soc[0])) { ++ smbios_set_default_processor_family(0x200); ++ } else { ++ smbios_set_default_processor_family(0x201); ++ } ++ ++ /* build the array of physical mem area from base_memmap */ ++ mem_array.address = s->memmap[VIRT_DRAM].base; ++ mem_array.length = ms->ram_size; ++ ++ smbios_get_tables(ms, &mem_array, 1, ++ &smbios_tables, &smbios_tables_len, ++ &smbios_anchor, &smbios_anchor_len, ++ &error_fatal); ++ ++ if (smbios_anchor) { ++ fw_cfg_add_file(s->fw_cfg, "etc/smbios/smbios-tables", ++ smbios_tables, smbios_tables_len); ++ fw_cfg_add_file(s->fw_cfg, "etc/smbios/smbios-anchor", ++ smbios_anchor, smbios_anchor_len); ++ } ++} ++ + static void virt_machine_done(Notifier *notifier, void *data) + { + RISCVVirtState *s = container_of(notifier, RISCVVirtState, +@@ -1337,6 +1377,8 @@ static void virt_machine_done(Notifier *notifier, void *data) + riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); + } + ++ virt_build_smbios(s); ++ + if (virt_is_acpi_enabled(s)) { + virt_acpi_setup(s); + } +-- +2.27.0 + diff --git a/0288-qemu-options-enable-smbios-option-on-RISC-V.patch b/0288-qemu-options-enable-smbios-option-on-RISC-V.patch new file mode 100644 index 0000000..5955b9d --- /dev/null +++ b/0288-qemu-options-enable-smbios-option-on-RISC-V.patch @@ -0,0 +1,36 @@ +From 9d9f3bca96a8b92975047f761735dfcbbce02fdd Mon Sep 17 00:00:00 2001 +From: Heinrich Schuchardt +Date: Tue, 23 Jan 2024 19:42:29 +0100 +Subject: [PATCH 4/4] qemu-options: enable -smbios option on RISC-V + +With SMBIOS support added for RISC-V we also should enable the command line +option. + +Signed-off-by: Heinrich Schuchardt +Reviewed-by: Daniel Henrique Barboza +Acked-by: Alistair Francis +Reviewed-by: Andrew Jones +Message-ID: <20240123184229.10415-5-heinrich.schuchardt@canonical.com> +Signed-off-by: Alistair Francis +(cherry picked from commit e2ff0dec156eff4e109c678654df1225d384fd14) +Signed-off-by: Xuemei Liu +--- + qemu-options.hx | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/qemu-options.hx b/qemu-options.hx +index 0029569f2..07e0c445e 100644 +--- a/qemu-options.hx ++++ b/qemu-options.hx +@@ -2690,7 +2690,7 @@ DEF("smbios", HAS_ARG, QEMU_OPTION_smbios, + " specify SMBIOS type 17 fields\n" + "-smbios type=41[,designation=str][,kind=str][,instance=%d][,pcidev=str]\n" + " specify SMBIOS type 41 fields\n", +- QEMU_ARCH_I386 | QEMU_ARCH_ARM | QEMU_ARCH_LOONGARCH) ++ QEMU_ARCH_I386 | QEMU_ARCH_ARM | QEMU_ARCH_LOONGARCH | QEMU_ARCH_RISCV) + SRST + ``-smbios file=binary`` + Load SMBIOS entry from binary file. +-- +2.27.0 + diff --git a/qemu.spec b/qemu.spec index 13f07bf..094695e 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,4 +1,4 @@ -%define anolis_release 25 +%define anolis_release 26 %bcond_with check %global all_system_emu_support 0 @@ -567,6 +567,10 @@ Patch0281: 0281-hw-i386-pc-add-mem2-option-for-qemu.patch Patch0282: 0282-hw-misc-psp-support-tkm-use-mem2-memory.patch Patch0283: 0283-hw-misc-psp-Pin-the-hugepage-memory-specified-by-mem.patch Patch0284: 0284-fix-potential-use-after-free-with-dbus-shared-memory.patch +Patch0285: 0285-smbios-add-processor-family-option.patch +Patch0286: 0286-smbios-function-to-set-default-processor-family.patch +Patch0287: 0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch +Patch0288: 0288-qemu-options-enable-smbios-option-on-RISC-V.patch ExclusiveArch: x86_64 aarch64 loongarch64 @@ -2111,6 +2115,13 @@ useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin \ %endif %changelog +* Fri May 30 2025 Xuemei Liu - 2:8.2.0-26 +- Patch0285-smbios-add-processor-family-option.patch +- Patch0286-smbios-function-to-set-default-processor-family.patch +- Patch0287-target-riscv-SMBIOS-support-for-RISC-V-virt-machine.patch +- Patch0288-qemu-options-enable-smbios-option-on-RISC-V.patch + (SMBIOS support for RISC-V virt machine) + * Sat Nov 30 2024 Xianglai Li - 2:8.2.0-25 - Remove loongarch qemu's dependency on the seavgabios package. -- Gitee