From 910ca2d2b08399f6f7dab811cdf9dbcd84cbf219 Mon Sep 17 00:00:00 2001 From: yujiayi <3076710949@qq.com> Date: Tue, 24 Dec 2024 17:27:40 +0800 Subject: [PATCH] Add sw64arch support Signed-off-by: lufeifei --- ...hitecture-support-for-libvirt-9.10.0.patch | 722 ++++++++++++++++++ libvirt.spec | 12 +- 2 files changed, 730 insertions(+), 4 deletions(-) create mode 100644 Add-sw64-architecture-support-for-libvirt-9.10.0.patch diff --git a/Add-sw64-architecture-support-for-libvirt-9.10.0.patch b/Add-sw64-architecture-support-for-libvirt-9.10.0.patch new file mode 100644 index 0000000..1bf2cdb --- /dev/null +++ b/Add-sw64-architecture-support-for-libvirt-9.10.0.patch @@ -0,0 +1,722 @@ +From 12d17eb21cc31bd7089646cc2062cbabfbe0b2e9 Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Thu, 22 Feb 2024 15:43:58 +0800 +Subject: [PATCH] sw_64: Add sw64 architecture support for libvirt-9.10.0 + +Signed-off-by: Zhang Wenxiang +--- + meson.build | 2 +- + po/POTFILES | 1 + + src/conf/schemas/basictypes.rng | 1 + + src/cpu/cpu.c | 2 + + src/cpu/cpu_sw64.c | 298 ++++++++++++++++++++++++++++++++ + src/cpu/cpu_sw64.h | 30 ++++ + src/cpu/meson.build | 1 + + src/cpu_map/index.xml | 6 + + src/cpu_map/meson.build | 2 + + src/cpu_map/sw64_core3.xml | 4 + + src/cpu_map/sw64_core4.xml | 4 + + src/qemu/qemu_capabilities.c | 11 ++ + src/qemu/qemu_command.c | 3 +- + src/qemu/qemu_domain.c | 30 +++- + src/qemu/qemu_domain.h | 1 + + src/remote/remote_driver.c | 2 +- + src/util/virarch.c | 6 + + src/util/virarch.h | 4 + + src/util/virhostcpu.c | 2 + + src/util/virsysinfo.c | 1 + + 20 files changed, 407 insertions(+), 4 deletions(-) + create mode 100644 src/cpu/cpu_sw64.c + create mode 100644 src/cpu/cpu_sw64.h + create mode 100644 src/cpu_map/sw64_core3.xml + create mode 100644 src/cpu_map/sw64_core4.xml + +diff --git a/meson.build b/meson.build +index 62481a0..0216b27 100644 +--- a/meson.build ++++ b/meson.build +@@ -1552,7 +1552,7 @@ elif get_option('driver_lxc').enabled() + error('linux and remote_driver are required for LXC') + endif + +-if not get_option('driver_ch').disabled() and host_machine.system() == 'linux' and (host_machine.cpu_family() == 'x86_64' or host_machine.cpu_family() == 'aarch64') ++if not get_option('driver_ch').disabled() and host_machine.system() == 'linux' and (host_machine.cpu_family() == 'x86_64' or host_machine.cpu_family() == 'aarch64' or host_machine.cpu_family() == 'sw_64') + use_ch = true + + if not conf.has('WITH_LIBVIRTD') +diff --git a/po/POTFILES b/po/POTFILES +index 3a51aea..77d75c9 100644 +--- a/po/POTFILES ++++ b/po/POTFILES +@@ -72,6 +72,7 @@ src/cpu/cpu_map.c + src/cpu/cpu_ppc64.c + src/cpu/cpu_riscv64.c + src/cpu/cpu_s390.c ++src/cpu/cpu_sw64.c + src/cpu/cpu_x86.c + src/datatypes.c + src/driver.c +diff --git a/src/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng +index f117f19..68e93fb 100644 +--- a/src/conf/schemas/basictypes.rng ++++ b/src/conf/schemas/basictypes.rng +@@ -471,6 +471,7 @@ + x86_64 + xtensa + xtensaeb ++ sw_64 + + + +diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c +index 1e7c879..04d8009 100644 +--- a/src/cpu/cpu.c ++++ b/src/cpu/cpu.c +@@ -29,6 +29,7 @@ + #include "cpu_arm.h" + #include "cpu_loongarch.h" + #include "cpu_riscv64.h" ++#include "cpu_sw64.h" + #include "capabilities.h" + + +@@ -43,6 +44,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverArm, + &cpuDriverRiscv64, + &cpuDriverLoongArch, ++ &cpuDriverSW64, + }; + + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +new file mode 100644 +index 0000000..56c8ed1 +--- /dev/null ++++ b/src/cpu/cpu_sw64.c +@@ -0,0 +1,298 @@ ++/* ++ * cpu_sw64.c: CPU driver for sw64 CPUs ++ * ++ * Copyright (C) 2021 Lu Feifei ++ * ++ * This library is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library. If not, see ++ * . ++ */ ++ ++#include ++ ++#include "virfile.h" ++#include "viralloc.h" ++#include "cpu.h" ++#include "cpu_sw64.h" ++#include "cpu_map.h" ++#include "virstring.h" ++#include "virhostcpu.h" ++ ++#define VIR_FROM_THIS VIR_FROM_CPU ++#define CPUINFO_PATH "/proc/cpuinfo" ++ ++static const virArch archs[] = { VIR_ARCH_SW_64 }; ++ ++typedef struct _sw64Model sw64Model; ++struct _sw64Model { ++ char *name; ++}; ++ ++typedef struct _sw64Map sw64Map; ++struct _sw64Map { ++ size_t nmodels; ++ sw64Model **models; ++}; ++ ++static virCPUCompareResult ++virCPUsw64Compare(virCPUDef *host ATTRIBUTE_UNUSED, ++ virCPUDef *cpu ATTRIBUTE_UNUSED, ++ bool failMessages ATTRIBUTE_UNUSED) ++{ ++ return VIR_CPU_COMPARE_IDENTICAL; ++} ++ ++static int ++virCPUsw64Update(virCPUDef *guest, ++ const virCPUDef *host, ++ bool relative) ++{ ++ g_autoptr(virCPUDef) updated = NULL; ++ ++ if (!relative || guest->mode != VIR_CPU_MODE_HOST_MODEL) ++ return 0; ++ ++ if (!host) { ++ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", ++ _("unknown host CPU model")); ++ return -1; ++ } ++ ++ if (!(updated = virCPUDefCopyWithoutModel(guest))) ++ return -1; ++ ++ updated->mode = VIR_CPU_MODE_CUSTOM; ++ virCPUDefCopyModel(updated, host, true); ++ ++ virCPUDefStealModel(guest, updated, false); ++ guest->mode = VIR_CPU_MODE_CUSTOM; ++ guest->match = VIR_CPU_MATCH_EXACT; ++ ++ return 0; ++} ++ ++static void ++sw64ModelFree(sw64Model *model) ++{ ++ if (!model) ++ return; ++ ++ VIR_FREE(model->name); ++ VIR_FREE(model); ++} ++ ++static void ++sw64MapFree(sw64Map *map) ++{ ++ size_t i; ++ ++ if (!map) ++ return; ++ ++ for (i = 0; i < map->nmodels; i++) ++ sw64ModelFree(map->models[i]); ++ VIR_FREE(map->models); ++ VIR_FREE(map); ++} ++ ++static sw64Model * ++sw64ModelFind(const sw64Map *map, ++ const char *name) ++{ ++ size_t i; ++ ++ for (i = 0; i < map->nmodels; i++) { ++ if (STREQ(map->models[i]->name, name)) ++ return map->models[i]; ++ } ++ ++ return NULL; ++} ++ ++static int ++sw64ModelParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, ++ const char *name, ++ void *data) ++{ ++ sw64Map *map = data; ++ sw64Model *model; ++ int ret = -1; ++ ++ model = g_new0(sw64Model, 1); ++ ++ model->name = g_strdup(name); ++ ++ if (sw64ModelFind(map, model->name)) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("CPU model %1$s already defined"), model->name); ++ goto cleanup; ++ } ++ ++ VIR_APPEND_ELEMENT(map->models, map->nmodels, model); ++ ++ ret = 0; ++ ++ cleanup: ++ sw64ModelFree(model); ++ return ret; ++} ++ ++static sw64Map * ++sw64LoadMap(void) ++{ ++ sw64Map *map; ++ ++ map = g_new0(sw64Map, 1); ++ ++ if (cpuMapLoad("sw64", NULL, NULL, sw64ModelParse, map) < 0) ++ goto error; ++ ++ return map; ++ ++ error: ++ sw64MapFree(map); ++ return NULL; ++} ++ ++static int ++sw64CPUParseCpuModeString(const char *str, ++ const char *prefix, ++ unsigned int *mode) ++{ ++ char *p; ++ unsigned int ui; ++ /* If the string doesn't start with the expected prefix, then ++ * we're not looking at the right string and we should move on */ ++ if (!STRPREFIX(str, prefix)) ++ return 1; ++ /* Skip the prefix */ ++ str += strlen(prefix); ++ ++ /* Skip all whitespace */ ++ while (g_ascii_isspace(*str)) ++ str++; ++ if (*str == '\0') ++ goto error; ++ ++ /* Skip the colon. If anything but a colon is found, then we're ++ * not looking at the right string and we should move on */ ++ if (*str != ':') ++ return 1; ++ str++; ++ ++ /* Skip all whitespace */ ++ while (g_ascii_isspace(*str)) ++ str++; ++ if (*str == '\0') ++ goto error; ++ ++ if (virStrToLong_ui(str, &p, 10, &ui) < 0 || ++ (*p != '.' && *p != '\0' && !g_ascii_isspace(*p))) { ++ goto error; ++ } ++ ++ *mode = ui; ++ return 0; ++ ++ error: ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Missing or invalid CPU variation in %s"), ++ CPUINFO_PATH); ++ return -1; ++} ++ ++static int ++sw64CPUParseCpuMode(FILE *cpuinfo, unsigned int *mode) ++{ ++ const char *prefix = "cpu variation"; ++ char line[1024]; ++ ++ while (fgets(line, sizeof(line), cpuinfo) != NULL) { ++ if (sw64CPUParseCpuModeString(line, prefix, mode) < 0) ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int ++virCPUsw64GetHost(virCPUDef *cpu, ++ virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) ++{ ++ int ret = -1; ++ unsigned int mode; ++ FILE *cpuinfo = fopen(CPUINFO_PATH, "r"); ++ if (!cpuinfo) { ++ virReportSystemError(errno, ++ _("cannot open %s"), CPUINFO_PATH); ++ return -1; ++ } ++ ++ ret = sw64CPUParseCpuMode(cpuinfo, &mode); ++ if (ret < 0) ++ goto cleanup; ++ ++ if (mode == 3) ++ cpu->model = g_strdup("core3"); ++ else if (mode == 4) ++ cpu->model = g_strdup("core4"); ++ ++ cleanup: ++ VIR_FORCE_FCLOSE(cpuinfo); ++ return ret; ++} ++ ++static int ++virCPUsw64DriverGetModels(char ***models) ++{ ++ sw64Map *map; ++ size_t i; ++ int ret = -1; ++ ++ if (!(map = sw64LoadMap())) ++ goto error; ++ ++ if (models) { ++ *models = g_new0(char *, map->nmodels + 1); ++ ++ for (i = 0; i < map->nmodels; i++) { ++ (*models)[i] = g_strdup(map->models[i]->name); ++ } ++ } ++ ++ ret = map->nmodels; ++ ++ cleanup: ++ sw64MapFree(map); ++ return ret; ++ ++ error: ++ if (models) { ++ g_strfreev(*models); ++ *models = NULL; ++ } ++ goto cleanup; ++} ++ ++struct cpuArchDriver cpuDriverSW64 = { ++ .name = "sw_64", ++ .arch = archs, ++ .narch = G_N_ELEMENTS(archs), ++ .getHost = virCPUsw64GetHost, ++ .compare = virCPUsw64Compare, ++ .decode = NULL, ++ .encode = NULL, ++ .baseline = NULL, ++ .update = virCPUsw64Update, ++ .getModels = virCPUsw64DriverGetModels, ++}; +diff --git a/src/cpu/cpu_sw64.h b/src/cpu/cpu_sw64.h +new file mode 100644 +index 0000000..d38cd9f +--- /dev/null ++++ b/src/cpu/cpu_sw64.h +@@ -0,0 +1,30 @@ ++/* ++ * cpu_sw64.h: CPU driver for sw64 CPUs ++ * ++ * Copyright (C) 2021 Lu Feifei ++ * ++ * This library is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library. If not, see ++ * . ++ */ ++ ++#pragma once ++ ++#ifndef __VIR_CPU_SW64_H__ ++#define __VIR_CPU_SW64_H__ ++ ++#include "cpu.h" ++ ++extern struct cpuArchDriver cpuDriverSW64; ++ ++#endif /* __VIR_CPU_SW64_H__ */ +diff --git a/src/cpu/meson.build b/src/cpu/meson.build +index 141230e..8171aa0 100644 +--- a/src/cpu/meson.build ++++ b/src/cpu/meson.build +@@ -2,6 +2,7 @@ cpu_sources = [ + 'cpu.c', + 'cpu_arm.c', + 'cpu_loongarch.c', ++ 'cpu_sw64.c', + 'cpu_map.c', + 'cpu_ppc64.c', + 'cpu_riscv64.c', +diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml +index 5d18a4a..fed5fe3 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -120,4 +120,10 @@ + + + ++ ++ ++ ++ ++ ++ + +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index ca4934d..98d74bc 100644 +--- a/src/cpu_map/meson.build ++++ b/src/cpu_map/meson.build +@@ -85,6 +85,8 @@ cpumap_data = [ + 'x86_vendors.xml', + 'x86_Westmere-IBRS.xml', + 'x86_Westmere.xml', ++ 'sw64_core3.xml', ++ 'sw64_core4.xml', + ] + + install_data(cpumap_data, install_dir: pkgdatadir / 'cpu_map') +diff --git a/src/cpu_map/sw64_core3.xml b/src/cpu_map/sw64_core3.xml +new file mode 100644 +index 0000000..ec3fa0e +--- /dev/null ++++ b/src/cpu_map/sw64_core3.xml +@@ -0,0 +1,4 @@ ++ ++ ++ ++ +diff --git a/src/cpu_map/sw64_core4.xml b/src/cpu_map/sw64_core4.xml +new file mode 100644 +index 0000000..11e763b +--- /dev/null ++++ b/src/cpu_map/sw64_core4.xml +@@ -0,0 +1,4 @@ ++ ++ ++ ++ +diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index 9552997..520af43 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -818,6 +818,8 @@ virArch virQEMUCapsArchFromString(const char *arch) + return VIR_ARCH_ARMV7L; + if (STREQ(arch, "or32")) + return VIR_ARCH_OR32; ++ if (STREQ(arch, "sw64")) ++ return VIR_ARCH_SW_64; + + return virArchFromString(arch); + } +@@ -831,6 +833,8 @@ const char *virQEMUCapsArchToString(virArch arch) + return "arm"; + if (arch == VIR_ARCH_OR32) + return "or32"; ++ if (arch == VIR_ARCH_SW_64) ++ return "sw64"; + + return virArchToString(arch); + } +@@ -2064,6 +2068,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) + if (ARCH_IS_X86(def->os.arch)) + return true; + ++ /* sw_64 support PCI-multibus on all machine types ++ * since forever */ ++ if (ARCH_IS_SW64(def->os.arch)) ++ return true; ++ + /* PPC supports multibus on all machine types which have pci since qemu-2.0.0 */ + if (def->os.arch == VIR_ARCH_PPC || + ARCH_IS_PPC64(def->os.arch)) { +@@ -2700,6 +2709,8 @@ static const char *preferredMachines[] = + "pc", /* VIR_ARCH_X86_64 */ + "sim", /* VIR_ARCH_XTENSA */ + "sim", /* VIR_ARCH_XTENSAEB */ ++ ++ "core4", /* VIR_ARCH_SW_64 */ + }; + G_STATIC_ASSERT(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); + +diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c +index 30d9f8e..a0ebe8d 100644 +--- a/src/qemu/qemu_command.c ++++ b/src/qemu/qemu_command.c +@@ -6051,7 +6051,8 @@ qemuBuildPMCommandLine(virCommand *cmd, + if (virQEMUCapsMachineSupportsACPI(qemuCaps, def->virtType, def->os.machine) == VIR_TRISTATE_BOOL_ABSENT && + (def->os.arch == VIR_ARCH_I686 || + def->os.arch == VIR_ARCH_X86_64 || +- def->os.arch == VIR_ARCH_AARCH64)) { ++ def->os.arch == VIR_ARCH_AARCH64 || ++ def->os.arch == VIR_ARCH_SW_64)) { + if (def->features[VIR_DOMAIN_FEATURE_ACPI] != VIR_TRISTATE_SWITCH_ON) + virCommandAddArg(cmd, "-no-acpi"); + } +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index 5fb3c67..dcee753 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -4226,6 +4226,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, + addPCIeRoot = true; + break; + ++ case VIR_ARCH_SW_64: ++ addPCIeRoot = true; ++ break; ++ + case VIR_ARCH_ARMV7B: + case VIR_ARCH_CRIS: + case VIR_ARCH_ITANIUM: +@@ -5639,6 +5643,9 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, + } else if (ARCH_IS_LOONGARCH(def->os.arch)) { + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) + cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; ++ } else if (def->os.arch == VIR_ARCH_SW_64) { ++ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU_XHCI)) ++ cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; + } + } + /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr */ +@@ -5941,7 +5948,8 @@ qemuDomainDefaultVideoDevice(const virDomainDef *def, + if (qemuDomainIsARMVirt(def) || + qemuDomainIsLoongArchVirt(def) || + qemuDomainIsRISCVVirt(def) || +- ARCH_IS_S390(def->os.arch)) { ++ ARCH_IS_S390(def->os.arch) || ++ ARCH_IS_SW64(def->os.arch)) { + return VIR_DOMAIN_VIDEO_TYPE_VIRTIO; + } + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA)) +@@ -8961,6 +8969,19 @@ qemuDomainMachineIsMipsMalta(const char *machine, + return false; + } + ++static bool ++qemuDomainMachineIsSW64(const char *machine, ++ const virArch arch) ++{ ++ if (!ARCH_IS_SW64(arch)) ++ return false; ++ ++ if (STRPREFIX(machine, "core")) ++ return true; ++ ++ return false; ++} ++ + + /* You should normally avoid this function and use + * qemuDomainHasBuiltinIDE() instead. */ +@@ -9048,6 +9069,13 @@ qemuDomainIsLoongArchVirt(const virDomainDef *def) + } + + ++bool ++qemuDomainIsSW64(const virDomainDef *def) ++{ ++ return qemuDomainMachineIsSW64(def->os.machine, def->os.arch); ++} ++ ++ + bool + qemuDomainHasPCIRoot(const virDomainDef *def) + { +diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h +index 0641c83..8899170 100644 +--- a/src/qemu/qemu_domain.h ++++ b/src/qemu/qemu_domain.h +@@ -829,6 +829,7 @@ bool qemuDomainIsLoongArchVirt(const virDomainDef *def); + bool qemuDomainIsRISCVVirt(const virDomainDef *def); + bool qemuDomainIsPSeries(const virDomainDef *def); + bool qemuDomainIsMipsMalta(const virDomainDef *def); ++bool qemuDomainIsSW64(const virDomainDef *def); + bool qemuDomainHasPCIRoot(const virDomainDef *def); + bool qemuDomainHasPCIeRoot(const virDomainDef *def); + bool qemuDomainHasBuiltinIDE(const virDomainDef *def); +diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c +index 4cbf7b0..5f0bc4f 100644 +--- a/src/remote/remote_driver.c ++++ b/src/remote/remote_driver.c +@@ -1408,7 +1408,7 @@ remoteConnectGetType(virConnectPtr conn) + return NULL; + + /* Stash. */ +- return priv->type = ret.type; ++ return priv->type = g_steal_pointer(&ret.type); + } + + static int remoteConnectIsSecure(virConnectPtr conn) +diff --git a/src/util/virarch.c b/src/util/virarch.c +index a94318d..5bb4ffe 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -84,6 +84,8 @@ static const struct virArchData { + { "x86_64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "xtensa", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "xtensaeb", 32, VIR_ARCH_BIG_ENDIAN }, ++ ++ { "sw_64", 64, VIR_ARCH_LITTLE_ENDIAN }, + }; + + G_STATIC_ASSERT(G_N_ELEMENTS(virArchData) == VIR_ARCH_LAST); +@@ -197,6 +199,8 @@ virArch virArchFromHost(void) + return VIR_ARCH_ARMV7L; + case PROCESSOR_ARCHITECTURE_ARM64: + return VIR_ARCH_AARCH64; ++ case PROCESSOR_ARCHITECTURE_SW64: ++ return VIR_ARCH_SW_64; + default: + VIR_WARN("Unknown host arch '%d', report to devel@lists.libvirt.org", + info.wProcessorArchitecture); +@@ -221,6 +225,8 @@ virArch virArchFromHost(void) + arch = VIR_ARCH_I686; + } else if (STREQ(ut.machine, "amd64")) { + arch = VIR_ARCH_X86_64; ++ } else if (STREQ(ut.machine, "sw_64")) { ++ arch = VIR_ARCH_SW_64; + } else if (STREQ(ut.machine, "arm64")) { + arch = VIR_ARCH_AARCH64; + } else if (STREQ(ut.machine, "loongarch64")) { +diff --git a/src/util/virarch.h b/src/util/virarch.h +index 2c01a13..5d8acff 100644 +--- a/src/util/virarch.h ++++ b/src/util/virarch.h +@@ -70,6 +70,8 @@ typedef enum { + VIR_ARCH_XTENSA, /* XTensa 32 LE https://en.wikipedia.org/wiki/Xtensa#Processor_Cores */ + VIR_ARCH_XTENSAEB, /* XTensa 32 BE https://en.wikipedia.org/wiki/Xtensa#Processor_Cores */ + ++ VIR_ARCH_SW_64, /* SW_64 64 LE XHB */ ++ + VIR_ARCH_LAST, + } virArch; + +@@ -109,6 +111,8 @@ typedef enum { + + #define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) + ++#define ARCH_IS_SW64(arch) ((arch) == VIR_ARCH_SW_64) ++ + typedef enum { + VIR_ARCH_LITTLE_ENDIAN, + VIR_ARCH_BIG_ENDIAN, +diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c +index cf3a967..9c1493e 100644 +--- a/src/util/virhostcpu.c ++++ b/src/util/virhostcpu.c +@@ -553,6 +553,8 @@ virHostCPUParseFrequency(FILE *cpuinfo, + prefix = "clock"; + else if (ARCH_IS_S390(arch)) + prefix = "cpu MHz dynamic"; ++ else if (ARCH_IS_SW64(arch)) ++ prefix = "cpu frequency [MHz]"; + else if (ARCH_IS_LOONGARCH(arch)) + prefix = "CPU MHz"; + +diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c +index 4a03fc3..116e9d7 100644 +--- a/src/util/virsysinfo.c ++++ b/src/util/virsysinfo.c +@@ -1249,6 +1249,7 @@ virSysinfoRead(void) + (defined(__x86_64__) || \ + defined(__i386__) || \ + defined(__amd64__) || \ ++ defined(__sw_64__) || \ + defined(__loongarch__)) + return virSysinfoReadDMI(); + #else /* WIN32 || not supported arch */ +-- +2.17.1 + diff --git a/libvirt.spec b/libvirt.spec index 287c2f4..c1205cc 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -1,15 +1,15 @@ -%define anolis_release 8 +%define anolis_release 9 -%define arches_qemu_kvm x86_64 aarch64 loongarch64 +%define arches_qemu_kvm x86_64 aarch64 loongarch64 sw_64 -%define arches_64bit x86_64 aarch64 riscv64 loongarch64 +%define arches_64bit x86_64 aarch64 riscv64 loongarch64 sw_64 %define arches_x86 x86_64 %define arches_systemtap_64bit %{arches_64bit} %define arches_dmidecode %{arches_x86} %define arches_xen %{arches_x86} aarch64 %define arches_vbox %{arches_x86} -%define arches_zfs %{arches_x86} +%define arches_zfs %{arches_x86} sw_64 %define arches_numactl %{arches_x86} aarch64 loongarch64 %define arches_numad %{arches_x86} aarch64 loongarch64 @@ -173,6 +173,7 @@ Patch0008: 100-fix-CVE-2024-4418.patch Patch0009: Add-cvm-parameter-into-the-type-of-LaunchSecurity.patch Patch0010: Add-get-tmm-memory-info-API-into-libvirt-host.patch Patch0011: Make-daemons-depend-on-generated-protocol.patch +Patch0012: Add-sw64-architecture-support-for-libvirt-9.10.0.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2152,6 +2153,9 @@ exit 0 %changelog +* Tue Dec 24 2024 lufeifei - 9.10.0-9 +- Add sw64arch support + * Wed Dec 18 2024 Bin Guo - 9.10.0-8 - support the virtCCA feature -- Gitee