From 1d0e5db0895d4214a1a2b9cc8374a190f1e3aeb2 Mon Sep 17 00:00:00 2001 From: Renbo Date: Fri, 20 Dec 2024 16:24:13 +0800 Subject: [PATCH 1/7] [BA] update to libvirt-8.0.0-23.3.src.rpm to #IBCOVC update to libvirt-8.0.0-23.3.src.rpm Signed-off-by: Renbo --- libvirt-Add-loongarch-support.patch | 1233 ----------------- ...w64-architecture-support-for-libvirt.patch | 687 --------- libvirt-add-loongarch-edit-xml-validate.patch | 20 - libvirt-cpu-Add-new-Dharma-CPU-model.patch | 131 -- libvirt-cpu-map-add-S5000C-cpu-model.patch | 54 - ...y-mark-empty-logical-pools-as-active.patch | 51 + libvirt.spec | 39 +- ...e-correct-tpm-device-for-all-non-x86.patch | 32 - ...alidate-Drop-tpm-tis-arch-validation.patch | 35 - 9 files changed, 62 insertions(+), 2220 deletions(-) delete mode 100644 libvirt-Add-loongarch-support.patch delete mode 100644 libvirt-Add-sw64-architecture-support-for-libvirt.patch delete mode 100644 libvirt-add-loongarch-edit-xml-validate.patch delete mode 100644 libvirt-cpu-Add-new-Dharma-CPU-model.patch delete mode 100644 libvirt-cpu-map-add-S5000C-cpu-model.patch create mode 100644 libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch delete mode 100644 qemu-command-Use-correct-tpm-device-for-all-non-x86.patch delete mode 100644 qemu-validate-Drop-tpm-tis-arch-validation.patch diff --git a/libvirt-Add-loongarch-support.patch b/libvirt-Add-loongarch-support.patch deleted file mode 100644 index ac0da71..0000000 --- a/libvirt-Add-loongarch-support.patch +++ /dev/null @@ -1,1233 +0,0 @@ -From da7befb4ce165d692f34156f740f4ea3ce2b7fec Mon Sep 17 00:00:00 2001 -From: zhaotianrui -Date: Sat, 3 Sep 2022 14:23:43 -0400 -Subject: [PATCH] Add loongarch support - -Signed-off-by: zhaotianrui -Change-Id: I8d245bc2fb914b08af4ade8e334d59ba3a5c2f01 ---- - po/POTFILES.in | 1 + - src/cpu/cpu.c | 3 +- - src/cpu/cpu.h | 3 +- - src/cpu/cpu_loongarch.c | 727 ++++++++++++++++++++++++++++++ - src/cpu/cpu_loongarch.h | 28 ++ - src/cpu/cpu_loongarch_data.h | 40 ++ - src/cpu/meson.build | 1 + - src/cpu_map/index.xml | 5 + - src/cpu_map/loongarch_vendors.xml | 3 + - src/cpu_map/ls_3a5000.xml | 6 + - src/cpu_map/meson.build | 2 + - src/qemu/qemu_capabilities.c | 5 + - src/qemu/qemu_conf.c | 4 +- - src/qemu/qemu_domain.c | 20 +- - src/qemu/qemu_domain.h | 1 + - src/qemu/qemu_domain_address.c | 58 +++ - src/qemu/qemu_validate.c | 3 +- - src/util/virarch.c | 3 + - src/util/virarch.h | 3 + - src/util/virhostcpu.c | 2 +- - src/util/virsysinfo.c | 2 +- - 21 files changed, 913 insertions(+), 7 deletions(-) - create mode 100644 src/cpu/cpu_loongarch.c - create mode 100644 src/cpu/cpu_loongarch.h - create mode 100644 src/cpu/cpu_loongarch_data.h - create mode 100644 src/cpu_map/loongarch_vendors.xml - create mode 100644 src/cpu_map/ls_3a5000.xml - -diff --git a/po/POTFILES.in b/po/POTFILES.in -index bf0a3b3529..1153e78265 100644 ---- a/po/POTFILES.in -+++ b/po/POTFILES.in -@@ -68,6 +68,7 @@ - @SRCDIR@src/cpu/cpu_arm.c - @SRCDIR@src/cpu/cpu_map.c - @SRCDIR@src/cpu/cpu_ppc64.c -+@SRCDIR@src/cpu/cpu_loongarch.c - @SRCDIR@src/cpu/cpu_s390.c - @SRCDIR@src/cpu/cpu_x86.c - @SRCDIR@src/datatypes.c -diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c -index 285c7eee44..49527c3688 100644 ---- a/src/cpu/cpu.c -+++ b/src/cpu/cpu.c -@@ -31,7 +31,7 @@ - #include "cpu_arm.h" - #include "capabilities.h" - #include "virstring.h" -- -+#include "cpu_loongarch.h" - - #define VIR_FROM_THIS VIR_FROM_CPU - -@@ -42,6 +42,7 @@ static struct cpuArchDriver *drivers[] = { - &cpuDriverPPC64, - &cpuDriverS390, - &cpuDriverArm, -+ &cpuDriverLoongArch, - }; - - -diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h -index 071b33fe76..ce7aee4757 100644 ---- a/src/cpu/cpu.h -+++ b/src/cpu/cpu.h -@@ -28,7 +28,7 @@ - #include "cpu_x86_data.h" - #include "cpu_ppc64_data.h" - #include "cpu_arm_data.h" -- -+#include "cpu_loongarch_data.h" - - typedef struct _virCPUData virCPUData; - struct _virCPUData { -@@ -37,6 +37,7 @@ struct _virCPUData { - virCPUx86Data x86; - virCPUppc64Data ppc64; - virCPUarmData arm; -+ virCPULoongArchData loongarch; - /* generic driver needs no data */ - } data; - }; -diff --git a/src/cpu/cpu_loongarch.c b/src/cpu/cpu_loongarch.c -new file mode 100644 -index 0000000000..f7b4b85a44 ---- /dev/null -+++ b/src/cpu/cpu_loongarch.c -@@ -0,0 +1,727 @@ -+/* -+ * cpu_loongarch.c: CPU driver for 64-bit LOONGARCH CPUs -+ * -+ * Copyright (C) 2013 Red Hat, Inc. -+ * Copyright (C) IBM Corporation, 2010 -+ * -+ * 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 -+#include -+#include -+#include -+ -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#include "virlog.h" -+#include "viralloc.h" -+#include "cpu.h" -+#include "virstring.h" -+#include "cpu_map.h" -+#include "virbuffer.h" -+#include "cpu_loongarch.h" -+#include "cpu_loongarch_data.h" -+ -+#define VIR_FROM_THIS VIR_FROM_CPU -+ -+VIR_LOG_INIT("cpu.cpu_loongarch"); -+ -+static const virArch archs[] = { VIR_ARCH_LOONGARCH64 }; -+ -+typedef struct _LoongArch_vendor LoongArch_vendor; -+struct _LoongArch_vendor { -+ char *name; -+}; -+ -+typedef struct _LoongArch_model LoongArch_model; -+struct _LoongArch_model { -+ char *name; -+ LoongArch_vendor *vendor; -+ virCPULoongArchData data; -+}; -+ -+typedef struct _LoongArch_map LoongArch_map; -+struct _LoongArch_map { -+ size_t nvendors; -+ LoongArch_vendor **vendors; -+ size_t nmodels; -+ LoongArch_model **models; -+}; -+ -+static void -+LoongArchDataClear(virCPULoongArchData *data) -+{ -+ if (!data) -+ return; -+ -+ g_free(data->prid); -+} -+ -+static int -+LoongArchDataCopy(virCPULoongArchData *dst, const virCPULoongArchData *src) -+{ -+ size_t i; -+ -+ dst->prid = g_new0(virCPULoongArchPrid, src->len); -+ dst->len = src->len; -+ -+ for (i = 0; i < src->len; i++) { -+ dst->prid[i].value = src->prid[i].value; -+ dst->prid[i].mask = src->prid[i].mask; -+ } -+ -+ return 0; -+} -+ -+static void -+LoongArchVendorFree(LoongArch_vendor *vendor) -+{ -+ if (!vendor) -+ return; -+ -+ g_free(vendor); -+} -+ -+static LoongArch_vendor * -+LoongArchVendorFind(LoongArch_map *map, -+ const char *name) -+{ -+ size_t i; -+ -+ for (i = 0; i < map->nvendors; i++) { -+ if (STREQ(map->vendors[i]->name, name)) -+ return map->vendors[i]; -+ } -+ -+ return NULL; -+} -+ -+static void -+LoongArchModelFree(LoongArch_model *model) -+{ -+ if (!model) -+ return; -+ -+ LoongArchDataClear(&model->data); -+ g_free(model->name); -+ g_free(model); -+} -+ -+static LoongArch_model * -+LoongArchModelCopy(LoongArch_model *model) -+{ -+ LoongArch_model *copy; -+ -+ copy = g_new0(LoongArch_model, 1); -+ copy->name = g_strdup(model->name); -+ -+ if (LoongArchDataCopy(©->data, &model->data) < 0) -+ goto error; -+ -+ copy->vendor = model->vendor; -+ -+ return copy; -+ -+ error: -+ LoongArchModelFree(copy); -+ return NULL; -+} -+ -+static LoongArch_model * -+LoongArchModelFind(LoongArch_map *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 LoongArch_model * -+LoongArchModelFindPrid(LoongArch_map *map, -+ uint32_t prid) -+{ -+ size_t i; -+ size_t j; -+ -+ for (i = 0; i < map->nmodels; i++) { -+ LoongArch_model *model = map->models[i]; -+ for (j = 0; j < model->data.len; j++) { -+ if ((prid & model->data.prid[j].mask) == model->data.prid[j].value) -+ return model; -+ } -+ } -+ -+ return NULL; -+} -+ -+static LoongArch_model * -+LoongArchModelFromCPU(const virCPUDef *cpu, -+ LoongArch_map *map) -+{ -+ LoongArch_model *model; -+ -+ if (!cpu->model) { -+ virReportError(VIR_ERR_INVALID_ARG, "%s", -+ _("no CPU model specified")); -+ return NULL; -+ } -+ -+ if (!(model = LoongArchModelFind(map, cpu->model))) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Unknown CPU model %s"), cpu->model); -+ return NULL; -+ } -+ -+ return LoongArchModelCopy(model); -+} -+ -+static void -+LoongArchMapFree(LoongArch_map *map) -+{ -+ size_t i; -+ -+ if (!map) -+ return; -+ -+ for (i = 0; i < map->nmodels; i++) -+ LoongArchModelFree(map->models[i]); -+ g_free(map->models); -+ -+ for (i = 0; i < map->nvendors; i++) -+ LoongArchVendorFree(map->vendors[i]); -+ g_free(map->vendors); -+ -+ g_free(map); -+} -+ -+static int -+LoongArchVendorParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, -+ const char *name, -+ void *data) -+{ -+ LoongArch_map *map = data; -+ LoongArch_vendor *vendor; -+ int ret = -1; -+ -+ vendor = g_new0(LoongArch_vendor, 1); -+ vendor->name = g_strdup(name); -+ -+ if (LoongArchVendorFind(map, vendor->name)) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("CPU vendor %s already defined"), vendor->name); -+ goto cleanup; -+ } -+ -+ VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor); -+ ret = 0; -+ -+ cleanup: -+ LoongArchVendorFree(vendor); -+ return ret; -+} -+ -+static int -+LoongArchModelParse(xmlXPathContextPtr ctxt, -+ const char *name, -+ void *data) -+{ -+ LoongArch_map *map = data; -+ LoongArch_model *model; -+ xmlNodePtr *nodes = NULL; -+ char *vendor = NULL; -+ unsigned long prid; -+ size_t i; -+ int n; -+ int ret = -1; -+ -+ model = g_new0(LoongArch_model, 1); -+ model->name = g_strdup(name); -+ -+ if (LoongArchModelFind(map, model->name)) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("CPU model %s already defined"), model->name); -+ goto cleanup; -+ } -+ -+ if (virXPathBoolean("boolean(./vendor)", ctxt)) { -+ vendor = virXPathString("string(./vendor/@name)", ctxt); -+ if (!vendor) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Invalid vendor element in CPU model %s"), -+ model->name); -+ goto cleanup; -+ } -+ -+ if (!(model->vendor = LoongArchVendorFind(map, vendor))) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Unknown vendor %s referenced by CPU model %s"), -+ vendor, model->name); -+ goto cleanup; -+ } -+ } -+ -+ if ((n = virXPathNodeSet("./prid", ctxt, &nodes)) <= 0) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Missing Prid information for CPU model %s"), -+ model->name); -+ goto cleanup; -+ } -+ -+ model->data.prid = g_new0(virCPULoongArchPrid, n); -+ model->data.len = n; -+ -+ for (i = 0; i < n; i++) { -+ ctxt->node = nodes[i]; -+ -+ if (virXPathULongHex("string(./@value)", ctxt, &prid) < 0) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Missing or invalid Prid value in CPU model %s"), -+ model->name); -+ goto cleanup; -+ } -+ model->data.prid[i].value = prid; -+ -+ if (virXPathULongHex("string(./@mask)", ctxt, &prid) < 0) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Missing or invalid PVR mask in CPU model %s"), -+ model->name); -+ goto cleanup; -+ } -+ model->data.prid[i].mask = prid; -+ } -+ -+ VIR_APPEND_ELEMENT(map->models, map->nmodels, model); -+ ret = 0; -+ -+ cleanup: -+ LoongArchModelFree(model); -+ g_free(vendor); -+ g_free(nodes); -+ return ret; -+} -+ -+static LoongArch_map * -+LoongArchLoadMap(void) -+{ -+ LoongArch_map *map; -+ -+ map = g_new0(LoongArch_map, 1); -+ if (cpuMapLoad("loongarch64", LoongArchVendorParse, NULL, LoongArchModelParse, map) < 0) -+ goto error; -+ -+ return map; -+ -+ error: -+ LoongArchMapFree(map); -+ return NULL; -+} -+ -+static virCPUData * -+LoongArchMakeCPUData(virArch arch, -+ virCPULoongArchData *data) -+{ -+ virCPUData *cpuData; -+ -+ cpuData = g_new0(virCPUData, 1); -+ cpuData->arch = arch; -+ -+ if (LoongArchDataCopy(&cpuData->data.loongarch, data) < 0) -+ g_free(cpuData); -+ -+ return cpuData; -+} -+ -+static virCPUCompareResult -+LoongArchCompute(virCPUDef *host, -+ const virCPUDef *other, -+ virCPUData *guestData, -+ char **message) -+{ -+ LoongArch_map *map = NULL; -+ LoongArch_model *host_model = NULL; -+ LoongArch_model *guest_model = NULL; -+ virCPUDef *cpu = NULL; -+ virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; -+ virArch arch; -+ size_t i; -+ -+ /* Ensure existing configurations are handled correctly */ -+ if (!(cpu = virCPUDefCopy(other))) -+ goto cleanup; -+ -+ if (cpu->arch != VIR_ARCH_NONE) { -+ bool found = false; -+ -+ for (i = 0; i < G_N_ELEMENTS(archs); i++) { -+ if (archs[i] == cpu->arch) { -+ found = true; -+ break; -+ } -+ } -+ -+ if (!found) { -+ VIR_DEBUG("CPU arch %s does not match host arch", -+ virArchToString(cpu->arch)); -+ if (message) { -+ *message = g_strdup_printf(_("CPU arch %s does not match host arch"), -+ virArchToString(cpu->arch)); -+ } -+ ret = VIR_CPU_COMPARE_INCOMPATIBLE; -+ goto cleanup; -+ } -+ arch = cpu->arch; -+ } else { -+ arch = host->arch; -+ } -+ -+ if (cpu->vendor && -+ (!host->vendor || STRNEQ(cpu->vendor, host->vendor))) { -+ VIR_DEBUG("host CPU vendor does not match required CPU vendor %s", -+ cpu->vendor); -+ if (message) { -+ *message = g_strdup_printf(_("host CPU vendor does not match required " -+ "CPU vendor %s"), cpu->vendor); -+ } -+ ret = VIR_CPU_COMPARE_INCOMPATIBLE; -+ goto cleanup; -+ } -+ -+ if (!(map = LoongArchLoadMap())) -+ goto cleanup; -+ -+ /* Host CPU information */ -+ if (!(host_model = LoongArchModelFromCPU(host, map))) -+ goto cleanup; -+ -+ if (cpu->type == VIR_CPU_TYPE_GUEST) { -+ /* Guest CPU information */ -+ switch (cpu->mode) { -+ case VIR_CPU_MODE_HOST_MODEL: -+ case VIR_CPU_MODE_HOST_PASSTHROUGH: -+ /* host-model and host-passthrough: -+ * the guest CPU is the same as the host */ -+ guest_model = LoongArchModelCopy(host_model); -+ break; -+ -+ case VIR_CPU_MODE_CUSTOM: -+ /* custom: -+ * look up guest CPU information */ -+ guest_model = LoongArchModelFromCPU(cpu, map); -+ break; -+ } -+ } else { -+ /* Other host CPU information */ -+ guest_model = LoongArchModelFromCPU(cpu, map); -+ } -+ -+ if (!guest_model) -+ goto cleanup; -+ -+ if (STRNEQ(guest_model->name, host_model->name)) { -+ VIR_DEBUG("host CPU model does not match required CPU model %s", -+ guest_model->name); -+ if (message) { -+ *message = g_strdup_printf(_("host CPU model does not match required " -+ "CPU model %s"),guest_model->name); -+ } -+ ret = VIR_CPU_COMPARE_INCOMPATIBLE; -+ goto cleanup; -+ } -+ -+ if (guestData) -+ if (!(guestData = LoongArchMakeCPUData(arch, &guest_model->data))) -+ goto cleanup; -+ -+ ret = VIR_CPU_COMPARE_IDENTICAL; -+ -+ cleanup: -+ virCPUDefFree(cpu); -+ LoongArchMapFree(map); -+ LoongArchModelFree(host_model); -+ LoongArchModelFree(guest_model); -+ return ret; -+} -+ -+static virCPUCompareResult -+virCPULoongArchCompare(virCPUDef *host, -+ virCPUDef *cpu, -+ bool failIncompatible) -+{ -+ virCPUCompareResult ret; -+ char *message = NULL; -+ -+ if (!host || !host->model) { -+ if (failIncompatible) { -+ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", -+ _("unknown host CPU")); -+ } else { -+ VIR_WARN("unknown host CPU"); -+ ret = VIR_CPU_COMPARE_INCOMPATIBLE; -+ } -+ return -1; -+ } -+ -+ ret = LoongArchCompute(host, cpu, NULL, &message); -+ -+ if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) { -+ ret = VIR_CPU_COMPARE_ERROR; -+ if (message) { -+ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message); -+ } else { -+ virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); -+ } -+ } -+ g_free(message); -+ -+ return ret; -+} -+ -+static int -+LoongArchDriverDecode(virCPUDef *cpu, -+ const virCPUData *data, -+ virDomainCapsCPUModels *models) -+{ -+ int ret = -1; -+ LoongArch_map *map; -+ LoongArch_model *model; -+ -+ if (!data || !(map = LoongArchLoadMap())) -+ return -1; -+ -+ if (!(model = LoongArchModelFindPrid(map, data->data.loongarch.prid[0].value))) { -+ virReportError(VIR_ERR_OPERATION_FAILED, -+ _("Cannot find CPU model with Prid 0x%08x"), -+ data->data.loongarch.prid[0].value); -+ goto cleanup; -+ } -+ -+ if (!virCPUModelIsAllowed(model->name, models)) { -+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, -+ _("CPU model %s is not supported by hypervisor"), -+ model->name); -+ goto cleanup; -+ } -+ -+ cpu->model = g_strdup(model->name); -+ if (model->vendor) { -+ cpu->vendor = g_strdup(model->vendor->name); -+ } -+ ret = 0; -+ -+ cleanup: -+ LoongArchMapFree(map); -+ -+ return ret; -+} -+ -+static void -+virCPULoongArchDataFree(virCPUData *data) -+{ -+ if (!data) -+ return; -+ -+ LoongArchDataClear(&data->data.loongarch); -+ g_free(data); -+} -+ -+static int virCPULoongArchGetHostPRID(void) -+{ -+ return 0x14c010; -+} -+ -+static int -+virCPULoongArchGetHost(virCPUDef *cpu, -+ virDomainCapsCPUModels *models) -+{ -+ virCPUData *cpuData = NULL; -+ virCPULoongArchData *data; -+ int ret = -1; -+ -+ if (!(cpuData = virCPUDataNew(archs[0]))) -+ goto cleanup; -+ -+ data = &cpuData->data.loongarch; -+ -+ data->prid = g_new0(virCPULoongArchPrid, 1); -+ data->len = 1; -+ -+ data->prid[0].value = virCPULoongArchGetHostPRID(); -+ data->prid[0].mask = 0xffff00ul; -+ -+ ret = LoongArchDriverDecode(cpu, cpuData, models); -+ -+ cleanup: -+ virCPULoongArchDataFree(cpuData); -+ return ret; -+} -+ -+ -+static int -+virCPULoongArchUpdate(virCPUDef *guest, -+ const virCPUDef *host, -+ bool relative) -+{ -+ /* -+ * - host-passthrough doesn't even get here -+ * - host-model is used for host CPU running in a compatibility mode and -+ * it needs to remain unchanged -+ * - custom doesn't support any optional features, there's nothing to -+ * update -+ */ -+ VIR_DEBUG("host model %s, if relatived %d",host->model, relative); -+ if (guest->mode == VIR_CPU_MODE_CUSTOM) -+ guest->match = VIR_CPU_MATCH_EXACT; -+ -+ return 0; -+} -+ -+static virCPUDef * -+LoongArchDriverBaseline(virCPUDef **cpus, -+ unsigned int ncpus, -+ virDomainCapsCPUModels *models, -+ const char **features, -+ bool migratable) -+{ -+ LoongArch_map *map; -+ LoongArch_model *model; -+ LoongArch_vendor *vendor = NULL; -+ virCPUDef *cpu = NULL; -+ size_t i; -+ if (models && *features) { -+ VIR_DEBUG("migratable %d features %s",migratable, *features); -+ } -+ if (!(map = LoongArchLoadMap())) -+ goto error; -+ -+ if (!(model = LoongArchModelFind(map, cpus[0]->model))) { -+ virReportError(VIR_ERR_INTERNAL_ERROR, -+ _("Unknown CPU model %s"), cpus[0]->model); -+ goto error; -+ } -+ -+ for (i = 0; i < ncpus; i++) { -+ LoongArch_vendor *vnd; -+ -+ if (STRNEQ(cpus[i]->model, model->name)) { -+ virReportError(VIR_ERR_OPERATION_FAILED, "%s", -+ _("CPUs are incompatible")); -+ goto error; -+ } -+ -+ if (!cpus[i]->vendor) -+ continue; -+ -+ if (!(vnd = LoongArchVendorFind(map, cpus[i]->vendor))) { -+ virReportError(VIR_ERR_OPERATION_FAILED, -+ _("Unknown CPU vendor %s"), cpus[i]->vendor); -+ goto error; -+ } -+ -+ if (model->vendor) { -+ if (model->vendor != vnd) { -+ virReportError(VIR_ERR_OPERATION_FAILED, -+ _("CPU vendor %s of model %s differs from " -+ "vendor %s"), -+ model->vendor->name, model->name, -+ vnd->name); -+ goto error; -+ } -+ } else if (vendor) { -+ if (vendor != vnd) { -+ virReportError(VIR_ERR_OPERATION_FAILED, "%s", -+ _("CPU vendors do not match")); -+ goto error; -+ } -+ } else { -+ vendor = vnd; -+ } -+ } -+ -+ cpu = g_new0(virCPUDef ,1); -+ cpu->model = g_strdup(model->name); -+ if (vendor) { -+ cpu->vendor = g_strdup(vendor->name); -+ } -+ cpu->type = VIR_CPU_TYPE_GUEST; -+ cpu->match = VIR_CPU_MATCH_EXACT; -+ cpu->fallback = VIR_CPU_FALLBACK_FORBID; -+ -+ cleanup: -+ LoongArchMapFree(map); -+ -+ return cpu; -+ -+ error: -+ virCPUDefFree(cpu); -+ cpu = NULL; -+ goto cleanup; -+} -+ -+static int -+virCPULoongArchDriverGetModels(char ***models) -+{ -+ LoongArch_map *map; -+ size_t i; -+ int ret = -1; -+ -+ if (!(map = LoongArchLoadMap())) -+ 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: -+ LoongArchMapFree(map); -+ return ret; -+ -+ error: -+ if (models) { -+ g_strfreev(*models); -+ *models = NULL; -+ } -+ goto cleanup; -+} -+ -+struct cpuArchDriver cpuDriverLoongArch = { -+ .name = "LoongArch", -+ .arch = archs, -+ .narch = G_N_ELEMENTS(archs), -+ .compare = virCPULoongArchCompare, -+ .decode = LoongArchDriverDecode, -+ .encode = NULL, -+ .dataFree = virCPULoongArchDataFree, -+ .getHost = virCPULoongArchGetHost, -+ .baseline = LoongArchDriverBaseline, -+ .update = virCPULoongArchUpdate, -+ .getModels = virCPULoongArchDriverGetModels, -+}; -diff --git a/src/cpu/cpu_loongarch.h b/src/cpu/cpu_loongarch.h -new file mode 100644 -index 0000000000..1fde3b5162 ---- /dev/null -+++ b/src/cpu/cpu_loongarch.h -@@ -0,0 +1,28 @@ -+/* -+ * cpu_loongarch.h: CPU driver for 64-bit LOONGARCH CPUs -+ * -+ * Copyright (C) Copyright (C) IBM Corporation, 2010 -+ * -+ * 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 -+ * . -+ */ -+ -+#ifndef __VIR_CPU_LOONGARCH_H__ -+# define __VIR_CPU_LOONGARCH_H__ -+ -+# include "cpu.h" -+ -+extern struct cpuArchDriver cpuDriverLoongArch; -+ -+#endif /* __VIR_CPU_LOONGARCH_H__ */ -diff --git a/src/cpu/cpu_loongarch_data.h b/src/cpu/cpu_loongarch_data.h -new file mode 100644 -index 0000000000..1a759e7d16 ---- /dev/null -+++ b/src/cpu/cpu_loongarch_data.h -@@ -0,0 +1,40 @@ -+/* -+ * cpu_loongarch_data.h: 64-bit LOONGARCH CPU specific data -+ * -+ * Copyright (C) 2012 IBM Corporation. -+ * -+ * 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 -+ * . -+ */ -+ -+#ifndef __VIR_CPU_LOONGARCH_DATA_H__ -+# define __VIR_CPU_LOONGARCH_DATA_H__ -+ -+# include -+ -+typedef struct _virCPULoongArchPrid virCPULoongArchPrid; -+struct _virCPULoongArchPrid { -+ uint32_t value; -+ uint32_t mask; -+}; -+ -+# define VIR_CPU_LOONGARCH_DATA_INIT { 0 } -+ -+typedef struct _virCPULoongArchData virCPULoongArchData; -+struct _virCPULoongArchData { -+ size_t len; -+ virCPULoongArchPrid *prid; -+}; -+ -+#endif /* __VIR_CPU_MIPS64_DATA_H__ */ -diff --git a/src/cpu/meson.build b/src/cpu/meson.build -index b4ad95e46d..ad2f859fd8 100644 ---- a/src/cpu/meson.build -+++ b/src/cpu/meson.build -@@ -5,6 +5,7 @@ cpu_sources = [ - 'cpu_ppc64.c', - 'cpu_s390.c', - 'cpu_x86.c', -+ 'cpu_loongarch.c', - ] - - cpu_lib = static_library( -diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml -index ffe1fa91e5..d302de396a 100644 ---- a/src/cpu_map/index.xml -+++ b/src/cpu_map/index.xml -@@ -110,4 +110,9 @@ - - - -+ -+ -+ -+ -+ - -diff --git a/src/cpu_map/loongarch_vendors.xml b/src/cpu_map/loongarch_vendors.xml -new file mode 100644 -index 0000000000..c744654617 ---- /dev/null -+++ b/src/cpu_map/loongarch_vendors.xml -@@ -0,0 +1,3 @@ -+ -+ -+ -diff --git a/src/cpu_map/ls_3a5000.xml b/src/cpu_map/ls_3a5000.xml -new file mode 100644 -index 0000000000..f6fe3386f7 ---- /dev/null -+++ b/src/cpu_map/ls_3a5000.xml -@@ -0,0 +1,6 @@ -+ -+ -+ -+ -+ -+ -diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build -index 013fc62a02..9657c5164e 100644 ---- a/src/cpu_map/meson.build -+++ b/src/cpu_map/meson.build -@@ -77,6 +77,8 @@ cpumap_data = [ - 'x86_vendors.xml', - 'x86_Westmere-IBRS.xml', - 'x86_Westmere.xml', -+ 'loongarch_vendors.xml', -+ 'ls_3a5000.xml', - ] - - install_data(cpumap_data, install_dir: pkgdatadir / 'cpu_map') -diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c -index c4f7db55c8..75668c6451 100644 ---- a/src/qemu/qemu_capabilities.c -+++ b/src/qemu/qemu_capabilities.c -@@ -2073,6 +2073,9 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) - if (ARCH_IS_X86(def->os.arch)) - return true; - -+ if (STRPREFIX(def->os.machine,"loongson7a")) -+ 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)) { -@@ -2690,6 +2693,7 @@ static const char *preferredMachines[] = - - "malta", /* VIR_ARCH_MIPS64 */ - "malta", /* VIR_ARCH_MIPS64EL */ -+ "loongson7a", /* VIR_ARCH_LOONGARCH64 */ - "or1k-sim", /* VIR_ARCH_OR32 */ - NULL, /* VIR_ARCH_PARISC (no QEMU impl) */ - NULL, /* VIR_ARCH_PARISC64 (no QEMU impl) */ -@@ -5115,6 +5119,7 @@ virQEMUCapsInitQMPBasicArch(virQEMUCaps *qemuCaps) - case VIR_ARCH_MIPSEL: - case VIR_ARCH_MIPS64: - case VIR_ARCH_MIPS64EL: -+ case VIR_ARCH_LOONGARCH64: - case VIR_ARCH_OR32: - case VIR_ARCH_PARISC: - case VIR_ARCH_PARISC64: -diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c -index a0b8076d6b..8cd03261ac 100644 ---- a/src/qemu/qemu_conf.c -+++ b/src/qemu/qemu_conf.c -@@ -101,7 +101,9 @@ qemuDriverUnlock(virQEMUDriver *driver) - "/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd:" \ - "/usr/share/OVMF/OVMF_CODE.secboot.fd:/usr/share/OVMF/OVMF_VARS.fd:" \ - "/usr/share/AAVMF/AAVMF_CODE.fd:/usr/share/AAVMF/AAVMF_VARS.fd:" \ -- "/usr/share/AAVMF/AAVMF32_CODE.fd:/usr/share/AAVMF/AAVMF32_VARS.fd" -+ "/usr/share/AAVMF/AAVMF32_CODE.fd:/usr/share/AAVMF/AAVMF32_VARS.fd:" \ -+ "/usr/share/qemu-kvm/loongarch_bios.bin:/usr/share/qemu-kvm/loongarch_bios.bin" -+ - #endif - - -diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c -index 40fe9985e6..814d8cb67d 100644 ---- a/src/qemu/qemu_domain.c -+++ b/src/qemu/qemu_domain.c -@@ -3668,6 +3668,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, - addPCIeRoot = virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_GPEX); - break; - -+ case VIR_ARCH_LOONGARCH64: -+ addPCIeRoot = true; -+ break; -+ - case VIR_ARCH_PPC64: - case VIR_ARCH_PPC64LE: - addPCIRoot = true; -@@ -5065,6 +5069,11 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, - cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) - cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; -+ } 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 (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) -+ cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; - } - } - /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr */ -@@ -8324,6 +8333,13 @@ qemuDomainDefCheckABIStability(virQEMUDriver *driver, - } - - -+bool -+qemuDomainIsLoongson(const virDomainDef *def) -+{ -+ return (STRPREFIX(def->os.machine,"loongson3a") || STRPREFIX(def->os.machine,"loongson7a")); -+} -+ -+ - bool - qemuDomainCheckABIStability(virQEMUDriver *driver, - virDomainObj *vm, -@@ -8664,7 +8680,9 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, - return qemuDomainMachineIsI440FX(machine, arch) || - STREQ(machine, "malta") || - STREQ(machine, "sun4u") || -- STREQ(machine, "g3beige"); -+ STREQ(machine, "g3beige") || -+ STREQ(machine, "loongson3a") || -+ STREQ(machine, "loongson7a"); - } - - -diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h -index e5046367e3..57f1f97348 100644 ---- a/src/qemu/qemu_domain.h -+++ b/src/qemu/qemu_domain.h -@@ -770,6 +770,7 @@ bool qemuDomainIsS390CCW(const virDomainDef *def); - bool qemuDomainIsARMVirt(const virDomainDef *def); - bool qemuDomainIsRISCVVirt(const virDomainDef *def); - bool qemuDomainIsPSeries(const virDomainDef *def); -+bool qemuDomainIsLoongson(const virDomainDef *def); - bool qemuDomainHasPCIRoot(const virDomainDef *def); - bool qemuDomainHasPCIeRoot(const virDomainDef *def); - bool qemuDomainHasBuiltinIDE(const virDomainDef *def); -diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c -index 18fc34d049..c3fac1c33b 100644 ---- a/src/qemu/qemu_domain_address.c -+++ b/src/qemu/qemu_domain_address.c -@@ -2026,6 +2026,59 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDef *def, - } - - -+static int -+qemuDomainValidateDevicePCISlotsLoongson(virDomainDef *def, -+ virDomainPCIAddressSet *addrs) -+{ -+ int ret = -1; -+ virPCIDeviceAddress tmp_addr; -+ char *addrStr = NULL; -+ virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_AUTOASSIGN -+ | VIR_PCI_CONNECT_TYPE_PCI_DEVICE); -+ -+ if (addrs->nbuses) { -+ memset(&tmp_addr, 0, sizeof(tmp_addr)); -+ tmp_addr.slot = 1; -+ /* pci-ohci at 00:01.0 */ -+ if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) -+ goto cleanup; -+ } -+ -+ if (def->nvideos > 0 && -+ def->videos[0]->type != VIR_DOMAIN_VIDEO_TYPE_NONE && -+ def->videos[0]->type != VIR_DOMAIN_VIDEO_TYPE_RAMFB) { -+ /*reserve slot 2 for vga device */ -+ virDomainVideoDef *primaryVideo = def->videos[0]; -+ -+ if (virDeviceInfoPCIAddressIsWanted(&primaryVideo->info)) { -+ memset(&tmp_addr, 0, sizeof(tmp_addr)); -+ tmp_addr.slot = 2; -+ -+ if (!(addrStr = virPCIDeviceAddressAsString(&tmp_addr))) -+ goto cleanup; -+ if (!virDomainPCIAddressValidate(addrs, &tmp_addr, -+ addrStr, flags, true)) -+ goto cleanup; -+ -+ if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { -+ if (qemuDomainPCIAddressReserveNextAddr(addrs, -+ &primaryVideo->info) < 0) -+ goto cleanup; -+ } else { -+ if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) -+ goto cleanup; -+ primaryVideo->info.addr.pci = tmp_addr; -+ primaryVideo->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; -+ } -+ } -+ } -+ ret = 0; -+ cleanup: -+ VIR_FREE(addrStr); -+ return ret; -+} -+ -+ - static int - qemuDomainValidateDevicePCISlotsChipsets(virDomainDef *def, - virDomainPCIAddressSet *addrs) -@@ -2040,6 +2093,11 @@ qemuDomainValidateDevicePCISlotsChipsets(virDomainDef *def, - return -1; - } - -+ if (qemuDomainIsLoongson(def) && -+ qemuDomainValidateDevicePCISlotsLoongson(def, addrs) < 0) { -+ return -1; -+ } -+ - return 0; - } - -diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c -index 7bc14293d6..7d01d31aaf 100644 ---- a/src/qemu/qemu_validate.c -+++ b/src/qemu/qemu_validate.c -@@ -186,7 +186,8 @@ qemuValidateDomainDefFeatures(const virDomainDef *def, - switch ((virDomainFeature) i) { - case VIR_DOMAIN_FEATURE_IOAPIC: - if (def->features[i] != VIR_DOMAIN_IOAPIC_NONE) { -- if (!ARCH_IS_X86(def->os.arch)) { -+ if (!(ARCH_IS_X86(def->os.arch) -+ || ARCH_IS_LOONGARCH(def->os.arch))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("The '%s' feature is not supported for " - "architecture '%s' or machine type '%s'"), -diff --git a/src/util/virarch.c b/src/util/virarch.c -index 2134dd6a9d..9f40a7110c 100644 ---- a/src/util/virarch.c -+++ b/src/util/virarch.c -@@ -59,6 +59,7 @@ static const struct virArchData { - - { "mips64", 64, VIR_ARCH_BIG_ENDIAN }, - { "mips64el", 64, VIR_ARCH_LITTLE_ENDIAN }, -+ { "loongarch64", 64, VIR_ARCH_LITTLE_ENDIAN }, - { "openrisc", 32, VIR_ARCH_BIG_ENDIAN }, - { "parisc", 32, VIR_ARCH_BIG_ENDIAN }, - { "parisc64", 64, VIR_ARCH_BIG_ENDIAN }, -@@ -222,6 +223,8 @@ virArch virArchFromHost(void) - arch = VIR_ARCH_X86_64; - } else if (STREQ(ut.machine, "arm64")) { - arch = VIR_ARCH_AARCH64; -+ } else if (STREQ(ut.machine, "loongarch64")) { -+ arch = VIR_ARCH_LOONGARCH64; - } else { - /* Otherwise assume the canonical name */ - if ((arch = virArchFromString(ut.machine)) == VIR_ARCH_NONE) { -diff --git a/src/util/virarch.h b/src/util/virarch.h -index 528f84f8a5..7d396f2fff 100644 ---- a/src/util/virarch.h -+++ b/src/util/virarch.h -@@ -44,6 +44,7 @@ typedef enum { - - VIR_ARCH_MIPS64, /* MIPS 64 BE https://en.wikipedia.org/wiki/MIPS_architecture */ - VIR_ARCH_MIPS64EL, /* MIPS 64 LE https://en.wikipedia.org/wiki/MIPS_architecture */ -+ VIR_ARCH_LOONGARCH64, - VIR_ARCH_OR32, /* OpenRisc 32 BE https://en.wikipedia.org/wiki/OpenRISC#QEMU_support */ - VIR_ARCH_PARISC, /* PA-Risc 32 BE https://en.wikipedia.org/wiki/PA-RISC */ - VIR_ARCH_PARISC64, /* PA-Risc 64 BE https://en.wikipedia.org/wiki/PA-RISC */ -@@ -98,6 +99,8 @@ typedef enum { - #define ARCH_IS_MIPS64(arch) ((arch) == VIR_ARCH_MIPS64 ||\ - (arch) == VIR_ARCH_MIPS64EL) - -+#define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) -+ - typedef enum { - VIR_ARCH_LITTLE_ENDIAN, - VIR_ARCH_BIG_ENDIAN, -diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c -index 35f41daef2..137796ea07 100644 ---- a/src/util/virhostcpu.c -+++ b/src/util/virhostcpu.c -@@ -546,7 +546,7 @@ virHostCPUParseFrequency(FILE *cpuinfo, - char line[1024]; - - /* No sensible way to retrieve CPU frequency */ -- if (ARCH_IS_ARM(arch)) -+ if (ARCH_IS_ARM(arch) || ARCH_IS_LOONGARCH(arch)) - return 0; - - if (ARCH_IS_X86(arch)) -diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c -index af9e03c5ac..9577cf1910 100644 ---- a/src/util/virsysinfo.c -+++ b/src/util/virsysinfo.c -@@ -1247,7 +1247,7 @@ virSysinfoRead(void) - { - #if defined(__powerpc__) - return virSysinfoReadPPC(); --#elif defined(__arm__) || defined(__aarch64__) -+#elif defined(__arm__) || defined(__aarch64__) || defined(__loongarch__) - return virSysinfoReadARM(); - #elif defined(__s390__) || defined(__s390x__) - return virSysinfoReadS390(); --- -2.27.0 - diff --git a/libvirt-Add-sw64-architecture-support-for-libvirt.patch b/libvirt-Add-sw64-architecture-support-for-libvirt.patch deleted file mode 100644 index 7654027..0000000 --- a/libvirt-Add-sw64-architecture-support-for-libvirt.patch +++ /dev/null @@ -1,687 +0,0 @@ -From 6053366caf3573323e1436fc7c3e4e13d26fd3c2 Mon Sep 17 00:00:00 2001 -From: Chen Wang -Date: Wed, 25 May 2022 09:42:04 +0800 -Subject: [PATCH] sw_64: Add sw64 architecture support for libvirt-8.0.0 - -Signed-off-by: Chen Wang ---- - docs/schemas/basictypes.rng | 1 + - docs/schemas/domaincommon.rng | 1 + - meson.build | 2 +- - src/cpu/cpu.c | 2 + - src/cpu/cpu_sw64.c | 302 ++++++++++++++++++++++++++++++++++ - src/cpu/cpu_sw64.h | 31 ++++ - src/cpu/meson.build | 1 + - src/cpu_map/index.xml | 5 + - 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 | 12 ++ - src/qemu/qemu_domain.c | 15 +- - src/util/virarch.c | 6 + - src/util/virarch.h | 3 + - src/util/virhostcpu.c | 2 + - src/util/virprocess.c | 2 + - src/util/virsysinfo.c | 3 +- - 18 files changed, 393 insertions(+), 5 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/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng -index ab18b18..e0724fe 100644 ---- a/docs/schemas/basictypes.rng -+++ b/docs/schemas/basictypes.rng -@@ -460,6 +460,7 @@ - sh4eb - sparc - sparc64 -+ sw_64 - unicore32 - x86_64 - xtensa -diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng -index 79c8979..c2bd970 100644 ---- a/docs/schemas/domaincommon.rng -+++ b/docs/schemas/domaincommon.rng -@@ -2613,6 +2613,7 @@ - pcie-pci-bridge - - ioh3420 -+ pcie-root - pcie-root-port - - x3130-upstream -diff --git a/meson.build b/meson.build -index 214a3f0..e76cf4e 100644 ---- a/meson.build -+++ b/meson.build -@@ -1596,7 +1596,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/src/cpu/cpu.c b/src/cpu/cpu.c -index 49527c3..d11bcc9 100644 ---- a/src/cpu/cpu.c -+++ b/src/cpu/cpu.c -@@ -29,6 +29,7 @@ - #include "cpu_ppc64.h" - #include "cpu_s390.h" - #include "cpu_arm.h" -+#include "cpu_sw64.h" - #include "capabilities.h" - #include "virstring.h" - #include "cpu_loongarch.h" -@@ -43,6 +44,7 @@ static struct cpuArchDriver *drivers[] = { - &cpuDriverS390, - &cpuDriverArm, - &cpuDriverLoongArch, -+ &cpuDriverSW64, - }; - - -diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c -new file mode 100644 -index 0000000..199ed60 ---- /dev/null -+++ b/src/cpu/cpu_sw64.c -@@ -0,0 +1,302 @@ -+/* -+ * 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 -+ * . -+ * -+ * Authors: -+ * Lu Feifei -+ */ -+ -+#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; -+ if (virCPUDefCopyModel(updated, host, true) < 0) -+ return -1; -+ -+ 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 %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..211a7cf ---- /dev/null -+++ b/src/cpu/cpu_sw64.h -@@ -0,0 +1,31 @@ -+/* -+ * 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 -+ * . -+ * -+ * Authors: -+ * Lu Feifei -+ */ -+ -+#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 ad2f859..5e99dbd 100644 ---- a/src/cpu/meson.build -+++ b/src/cpu/meson.build -@@ -1,6 +1,7 @@ - cpu_sources = [ - 'cpu.c', - 'cpu_arm.c', -+ 'cpu_sw64.c', - 'cpu_map.c', - 'cpu_ppc64.c', - 'cpu_s390.c', -diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml -index 3ae9348..5d1a999 100644 ---- a/src/cpu_map/index.xml -+++ b/src/cpu_map/index.xml -@@ -113,6 +113,11 @@ - - - -+ -+ -+ -+ -+ - - - -diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build -index baeffa3..3871f09 100644 ---- a/src/cpu_map/meson.build -+++ b/src/cpu_map/meson.build -@@ -79,6 +79,8 @@ cpumap_data = [ - 'x86_vendors.xml', - 'x86_Westmere-IBRS.xml', - 'x86_Westmere.xml', -+ 'sw64_core3.xml', -+ 'sw64_core4.xml', - 'loongarch_vendors.xml', - 'ls_3a5000.xml', - ] -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 75668c6..ca47a7a 100644 ---- a/src/qemu/qemu_capabilities.c -+++ b/src/qemu/qemu_capabilities.c -@@ -771,6 +771,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); - } -@@ -784,6 +786,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); - } -@@ -2072,6 +2076,10 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) - * since forever */ - 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; - - if (STRPREFIX(def->os.machine,"loongson7a")) - return true; -@@ -2718,6 +2726,8 @@ static const char *preferredMachines[] = - - "sim", /* VIR_ARCH_XTENSA */ - "sim", /* VIR_ARCH_XTENSAEB */ -+ -+ "core3", /* VIR_ARCH_SW_64 */ - }; - G_STATIC_ASSERT(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); - -@@ -5129,6 +5139,8 @@ virQEMUCapsInitQMPBasicArch(virQEMUCaps *qemuCaps) - case VIR_ARCH_XTENSAEB: - case VIR_ARCH_NONE: - case VIR_ARCH_LAST: -+ case VIR_ARCH_SW_64: -+ - default: - break; - } -diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c -index 7a53b93..f32fdcb 100644 ---- a/src/qemu/qemu_domain.c -+++ b/src/qemu/qemu_domain.c -@@ -3740,6 +3740,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, - addPCIRoot = true; - break; - -+ case VIR_ARCH_SW_64: -+ addPCIeRoot = true; -+ break; -+ - case VIR_ARCH_ARMV7B: - case VIR_ARCH_CRIS: - case VIR_ARCH_ITANIUM: -@@ -5099,7 +5103,10 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, - cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; - else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) - cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_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 */ - if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1 || -@@ -5396,7 +5403,8 @@ qemuDomainDefaultVideoDevice(const virDomainDef *def, - return VIR_DOMAIN_VIDEO_TYPE_VGA; - if (qemuDomainIsARMVirt(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)) -@@ -8705,7 +8713,8 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, - return qemuDomainMachineIsI440FX(machine, arch) || - STREQ(machine, "malta") || - STREQ(machine, "sun4u") || -- STREQ(machine, "g3beige") || -+ STRPREFIX(machine, "core") || -+ STREQ(machine, "g3beige") || - STREQ(machine, "loongson3a") || - STREQ(machine, "loongson7a"); - } -diff --git a/src/util/virarch.c b/src/util/virarch.c -index 9f40a71..ce149a4 100644 ---- a/src/util/virarch.c -+++ b/src/util/virarch.c -@@ -84,6 +84,8 @@ static const struct virArchData { - - { "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 libvir-list@redhat.com", - 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 7d396f2..2e4f7c9 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; - -@@ -98,6 +100,7 @@ typedef enum { - - #define ARCH_IS_MIPS64(arch) ((arch) == VIR_ARCH_MIPS64 ||\ - (arch) == VIR_ARCH_MIPS64EL) -+#define ARCH_IS_SW64(arch) ((arch) == VIR_ARCH_SW_64) - - #define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) - -diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c -index 137796e..2572229 100644 ---- a/src/util/virhostcpu.c -+++ b/src/util/virhostcpu.c -@@ -555,6 +555,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]"; - - if (!prefix) { - VIR_WARN("%s is not supported by the %s parser", -diff --git a/src/util/virprocess.c b/src/util/virprocess.c -index f3933a2..04095e0 100644 ---- a/src/util/virprocess.c -+++ b/src/util/virprocess.c -@@ -89,6 +89,8 @@ VIR_LOG_INIT("util.process"); - # define __NR_setns 350 - # elif defined(__s390__) - # define __NR_setns 339 -+# elif defined(__sw_64__) -+# define __NR_setns 501 - # endif - # endif - -diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c -index 9577cf1..4cdbf32 100644 ---- a/src/util/virsysinfo.c -+++ b/src/util/virsysinfo.c -@@ -1254,7 +1254,8 @@ virSysinfoRead(void) - #elif !defined(WIN32) && \ - (defined(__x86_64__) || \ - defined(__i386__) || \ -- defined(__amd64__)) -+ defined(__amd64__) || \ -+ defined(__sw_64__)) - return virSysinfoReadDMI(); - #else /* WIN32 || not supported arch */ - /* --- -2.17.1 - diff --git a/libvirt-add-loongarch-edit-xml-validate.patch b/libvirt-add-loongarch-edit-xml-validate.patch deleted file mode 100644 index 7dba7ec..0000000 --- a/libvirt-add-loongarch-edit-xml-validate.patch +++ /dev/null @@ -1,20 +0,0 @@ -From 6391d1634db6319d852c65c4e384030dcf568103 Mon Sep 17 00:00:00 2001 -From: zhaotianrui -Date: Wed, 13 Oct 2021 15:51:40 +0800 -Subject: [PATCH] Fix loongarch xml validate - -Signed-off-by: zhaotianrui ---- - -diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng -index 8146527..b58a61a 100644 ---- a/docs/schemas/basictypes.rng -+++ b/docs/schemas/basictypes.rng -@@ -425,6 +425,7 @@ - mipsel - mips64 - mips64el -+ loongarch64 - openrisc - parisc - parisc64 diff --git a/libvirt-cpu-Add-new-Dharma-CPU-model.patch b/libvirt-cpu-Add-new-Dharma-CPU-model.patch deleted file mode 100644 index 39c6176..0000000 --- a/libvirt-cpu-Add-new-Dharma-CPU-model.patch +++ /dev/null @@ -1,131 +0,0 @@ -From 654e5425700bcc5ece7a414061a504283ae24727 Mon Sep 17 00:00:00 2001 -From: Yanjing Zhou -Date: Tue, 11 Jun 2024 16:00:14 +0800 -Subject: [PATCH] cpu: Add new Dharma CPU model - -Add Hygon Dharma CPU model to the processor model. - -Signed-off-by: Yanjing Zhou ---- - src/cpu_map/index.xml | 1 + - src/cpu_map/meson.build | 1 + - src/cpu_map/x86_Dharma.xml | 83 ++++++++++++++++++++++++++++++++++++++ - 3 files changed, 85 insertions(+) - create mode 100644 src/cpu_map/x86_Dharma.xml - -diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml -index ffe1fa9..9419674 100644 ---- a/src/cpu_map/index.xml -+++ b/src/cpu_map/index.xml -@@ -72,6 +72,7 @@ - - - -+ - - - -diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build -index 013fc62..c2a7052 100644 ---- a/src/cpu_map/meson.build -+++ b/src/cpu_map/meson.build -@@ -31,6 +31,7 @@ cpumap_data = [ - 'x86_coreduo.xml', - 'x86_cpu64-rhel5.xml', - 'x86_cpu64-rhel6.xml', -+ 'x86_Dharma.xml', - 'x86_Dhyana.xml', - 'x86_EPYC-IBPB.xml', - 'x86_EPYC.xml', -diff --git a/src/cpu_map/x86_Dharma.xml b/src/cpu_map/x86_Dharma.xml -new file mode 100644 -index 0000000..bf20116 ---- /dev/null -+++ b/src/cpu_map/x86_Dharma.xml -@@ -0,0 +1,83 @@ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ --- -2.39.3 - diff --git a/libvirt-cpu-map-add-S5000C-cpu-model.patch b/libvirt-cpu-map-add-S5000C-cpu-model.patch deleted file mode 100644 index 73c051a..0000000 --- a/libvirt-cpu-map-add-S5000C-cpu-model.patch +++ /dev/null @@ -1,54 +0,0 @@ -From 0b896a38e152b7350d9f685ec898ff9ff0f86ebe Mon Sep 17 00:00:00 2001 -From: Peng Mengguang -Date: Thu, 12 Sep 2024 10:57:23 -0400 -Subject: [PATCH] cpu_map: add S5000C cpu model - - add Phytium S5000C cpu model. - -Signed-off-by: Peng Mengguang ---- - src/cpu_map/arm_Tengyun-S5000C.xml | 6 ++++++ - src/cpu_map/index.xml | 1 + - src/cpu_map/meson.build | 1 + - 3 files changed, 8 insertions(+) - create mode 100644 src/cpu_map/arm_Tengyun-S5000C.xml - -diff --git a/src/cpu_map/arm_Tengyun-S5000C.xml b/src/cpu_map/arm_Tengyun-S5000C.xml -new file mode 100644 -index 0000000000..f8fa593c19 ---- /dev/null -+++ b/src/cpu_map/arm_Tengyun-S5000C.xml -@@ -0,0 +1,6 @@ -+ -+ -+ -+ -+ -+ -diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml -index 150535fac4..3ae9348bc5 100644 ---- a/src/cpu_map/index.xml -+++ b/src/cpu_map/index.xml -@@ -110,6 +110,7 @@ - - - -+ - - - -diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build -index 42d2105f2a..baeffa3b70 100644 ---- a/src/cpu_map/meson.build -+++ b/src/cpu_map/meson.build -@@ -7,6 +7,7 @@ cpumap_data = [ - 'arm_features.xml', - 'arm_Kunpeng-920.xml', - 'arm_Tengyun-S2500.xml', -+ 'arm_Tengyun-S5000C.xml', - 'arm_ThunderX299xx.xml', - 'arm_vendors.xml', - 'index.xml', --- -2.39.3 - diff --git a/libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch b/libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch new file mode 100644 index 0000000..dbfcfe2 --- /dev/null +++ b/libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch @@ -0,0 +1,51 @@ +From afbf59c823a04b417b4ae66edb99e15e6e8ba877 Mon Sep 17 00:00:00 2001 +Message-ID: +From: Peter Krempa +Date: Tue, 8 Aug 2023 15:53:53 +0200 +Subject: [PATCH] virStorageBackendLogicalCheckPool: Properly mark empty + logical pools as active +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The '/dev' filesystem convenience directory for a LVM volume group is +not created when the volume group is empty. + +The logic in 'virStorageBackendLogicalCheckPool' which is used to see +whether a pool is active was first checking presence of the directory, +which failed for an empty VG. + +Since the second step is virStorageBackendLogicalMatchPoolSource which +is checking mapping between configured PVs and the VG, we can simply +rely on the function to also check presence of the pool. + +Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2228223 +Signed-off-by: Peter Krempa +Reviewed-by: Ján Tomko +(cherry picked from commit fa1a54baa59d244289ce666f9dc52d9eabca47f1) +https://issues.redhat.com/browse/RHEL-65771 +--- + src/storage/storage_backend_logical.c | 8 +------- + 1 file changed, 1 insertion(+), 7 deletions(-) + +diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c +index 3f27e63aeb..b7e3ba2498 100644 +--- a/src/storage/storage_backend_logical.c ++++ b/src/storage/storage_backend_logical.c +@@ -628,13 +628,7 @@ static int + virStorageBackendLogicalCheckPool(virStoragePoolObj *pool, + bool *isActive) + { +- virStoragePoolDef *def = virStoragePoolObjGetDef(pool); +- +- /* If we can find the target.path as well as ensure that the +- * pool's def source +- */ +- *isActive = virFileExists(def->target.path) && +- virStorageBackendLogicalMatchPoolSource(pool); ++ *isActive = virStorageBackendLogicalMatchPoolSource(pool); + return 0; + } + +-- +2.47.0 diff --git a/libvirt.spec b/libvirt.spec index a3f4176..3d29a96 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -3,20 +3,19 @@ # This spec file assumes you are building on a Fedora or RHEL version # that's still supported by the vendor. It may work on other distros # or versions, but no effort will be made to ensure that going forward. -%define anolis_release .0.3 %define min_rhel 8 %define min_fedora 33 -%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x loongarch64 sw_64 +%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x %if 0%{?rhel} %if 0%{?rhel} > 8 - %define arches_qemu_kvm x86_64 aarch64 s390x loongarch64 + %define arches_qemu_kvm x86_64 aarch64 s390x %else - %define arches_qemu_kvm x86_64 %{power64} aarch64 s390x loongarch64 + %define arches_qemu_kvm x86_64 %{power64} aarch64 s390x %endif %endif -%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 loongarch64 sw_64 +%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 %define arches_x86 %{ix86} x86_64 %define arches_systemtap_64bit %{arches_64bit} @@ -24,9 +23,9 @@ %define arches_xen %{arches_x86} aarch64 %define arches_vbox %{arches_x86} %define arches_ceph %{arches_64bit} -%define arches_zfs %{arches_x86} %{power64} %{arm} loongarch64 sw_64 -%define arches_numactl %{arches_x86} %{power64} aarch64 s390x loongarch64 -%define arches_numad %{arches_x86} %{power64} aarch64 loongarch64 +%define arches_zfs %{arches_x86} %{power64} %{arm} +%define arches_numactl %{arches_x86} %{power64} aarch64 s390x +%define arches_numad %{arches_x86} %{power64} aarch64 # The hypervisor drivers that run in libvirtd %define with_qemu 0%{!?_without_qemu:1} @@ -211,7 +210,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 8.0.0 -Release: 23.2%{anolis_release}%{?dist}%{?extra_release} +Release: 23.3%{?dist}%{?extra_release} License: LGPLv2+ URL: https://libvirt.org/ @@ -322,13 +321,7 @@ Patch98: libvirt-virnuma-Avoid-integer-overflow-in-virNumaGetPages.patch Patch99: libvirt-remote-check-for-negative-array-lengths-before-allocation.patch Patch100: libvirt-util-Fix-error-return-for-virProcessKillPainfullyDelay.patch Patch101: libvirt-rpc-ensure-temporary-GSource-is-removed-from-client-event-loop.patch -Patch1000: libvirt-Add-loongarch-support.patch -Patch1001: libvirt-add-loongarch-edit-xml-validate.patch -Patch1004: qemu-validate-Drop-tpm-tis-arch-validation.patch -Patch1005: qemu-command-Use-correct-tpm-device-for-all-non-x86.patch -Patch1006: libvirt-cpu-Add-new-Dharma-CPU-model.patch -Patch1007: libvirt-cpu-map-add-S5000C-cpu-model.patch -Patch1008: libvirt-Add-sw64-architecture-support-for-libvirt.patch +Patch102: libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2208,18 +2201,8 @@ exit 0 %changelog -* Mon Sep 30 2024 lufeifei - 8.0.0-23.2.0.3 -- Add sw64arch support - -* Fri Sep 20 2024 Jiakun Shuai - 8.0.0-23.2.0.2 -- Add Phytium S5000C CPU model - -* Mon Jul 15 2024 zhaotianrui - 8.0.0-23.2.0.1 -- Add loongarch support -- Fix loongarch xml validate -- Synchronize upstream patches "Use correct tpm device for all non-x86" (lixianglai@loongson.cn) -- Synchronize upstream patches "validate: Drop tpm-tis arch validation" (lixianglai@loongson.cn) -- Add new Dharma CPU model (zhouyanjing@hygon.cn) +* Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 +- virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) * Thu Jun 6 2024 Jiri Denemark - 8.0.0-23.2.el8 - util: Fix error return for virProcessKillPainfullyDelay() (RHEL-36064) diff --git a/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch b/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch deleted file mode 100644 index 8189141..0000000 --- a/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 7c9af5730bc83bde24d6788720f92fceba533124 Mon Sep 17 00:00:00 2001 -From: Cole Robinson -Date: Sat, 18 Jun 2022 12:46:03 -0400 -Subject: [PATCH 2/2] qemu: command: Use correct tpm device for all non-x86 - -The qemu `tpm-tis` device is an ISA device, so only really applicable -to x86 archs. For all non-x86 archs we should use `tpm-tis-device` - -This fixes tpm-tis usage on armv7l and riscv - -Reviewed-by: Michal Privoznik -Signed-off-by: Cole Robinson ---- - src/qemu/qemu_command.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c -index a7855d3..978ce89 100644 ---- a/src/qemu/qemu_command.c -+++ b/src/qemu/qemu_command.c -@@ -9733,7 +9733,7 @@ qemuBuildTPMDevCmd(virCommand *cmd, - const char *model = virDomainTPMModelTypeToString(tpm->model); - g_autofree char *tpmdev = g_strdup_printf("tpm-%s", tpm->info.alias); - -- if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && def->os.arch == VIR_ARCH_AARCH64) -+ if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && !ARCH_IS_X86(def->os.arch)) - model = "tpm-tis-device"; - - if (virJSONValueObjectAdd(&props, --- -2.31.1 - diff --git a/qemu-validate-Drop-tpm-tis-arch-validation.patch b/qemu-validate-Drop-tpm-tis-arch-validation.patch deleted file mode 100644 index 178a943..0000000 --- a/qemu-validate-Drop-tpm-tis-arch-validation.patch +++ /dev/null @@ -1,35 +0,0 @@ -From d45d539a4aab6702710b877816d93d70f81c0165 Mon Sep 17 00:00:00 2001 -From: Cole Robinson -Date: Sat, 18 Jun 2022 12:52:29 -0400 -Subject: [PATCH 1/2] qemu: validate: Drop tpm-tis arch validation - -Checking against qemu capabilities should be enough here - -Resolves: https://gitlab.com/libvirt/libvirt/-/issues/329 - -Reviewed-by: Michal Privoznik -Signed-off-by: Cole Robinson ---- - src/qemu/qemu_validate.c | 6 ------ - 1 file changed, 6 deletions(-) - -diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c -index 7d01d31..6b65ce4 100644 ---- a/src/qemu/qemu_validate.c -+++ b/src/qemu/qemu_validate.c -@@ -4618,12 +4618,6 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm, - - switch (tpm->model) { - case VIR_DOMAIN_TPM_MODEL_TIS: -- if (!ARCH_IS_X86(def->os.arch) && (def->os.arch != VIR_ARCH_AARCH64)) { -- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, -- _("TPM model '%s' is only available for x86 and aarch64 guests"), -- virDomainTPMModelTypeToString(tpm->model)); -- return -1; -- } - flag = QEMU_CAPS_DEVICE_TPM_TIS; - break; - case VIR_DOMAIN_TPM_MODEL_CRB: --- -2.31.1 - -- Gitee From b0d9fa0cd9bd16574204fbc3438af07703da7283 Mon Sep 17 00:00:00 2001 From: zhaotianrui Date: Thu, 8 Sep 2022 09:28:25 -0400 Subject: [PATCH 2/7] Add loongarch support Signed-off-by: zhaotianrui --- libvirt-Add-loongarch-support.patch | 1233 +++++++++++++++++++++++++++ libvirt.spec | 21 +- 2 files changed, 1246 insertions(+), 8 deletions(-) create mode 100644 libvirt-Add-loongarch-support.patch diff --git a/libvirt-Add-loongarch-support.patch b/libvirt-Add-loongarch-support.patch new file mode 100644 index 0000000..ac0da71 --- /dev/null +++ b/libvirt-Add-loongarch-support.patch @@ -0,0 +1,1233 @@ +From da7befb4ce165d692f34156f740f4ea3ce2b7fec Mon Sep 17 00:00:00 2001 +From: zhaotianrui +Date: Sat, 3 Sep 2022 14:23:43 -0400 +Subject: [PATCH] Add loongarch support + +Signed-off-by: zhaotianrui +Change-Id: I8d245bc2fb914b08af4ade8e334d59ba3a5c2f01 +--- + po/POTFILES.in | 1 + + src/cpu/cpu.c | 3 +- + src/cpu/cpu.h | 3 +- + src/cpu/cpu_loongarch.c | 727 ++++++++++++++++++++++++++++++ + src/cpu/cpu_loongarch.h | 28 ++ + src/cpu/cpu_loongarch_data.h | 40 ++ + src/cpu/meson.build | 1 + + src/cpu_map/index.xml | 5 + + src/cpu_map/loongarch_vendors.xml | 3 + + src/cpu_map/ls_3a5000.xml | 6 + + src/cpu_map/meson.build | 2 + + src/qemu/qemu_capabilities.c | 5 + + src/qemu/qemu_conf.c | 4 +- + src/qemu/qemu_domain.c | 20 +- + src/qemu/qemu_domain.h | 1 + + src/qemu/qemu_domain_address.c | 58 +++ + src/qemu/qemu_validate.c | 3 +- + src/util/virarch.c | 3 + + src/util/virarch.h | 3 + + src/util/virhostcpu.c | 2 +- + src/util/virsysinfo.c | 2 +- + 21 files changed, 913 insertions(+), 7 deletions(-) + create mode 100644 src/cpu/cpu_loongarch.c + create mode 100644 src/cpu/cpu_loongarch.h + create mode 100644 src/cpu/cpu_loongarch_data.h + create mode 100644 src/cpu_map/loongarch_vendors.xml + create mode 100644 src/cpu_map/ls_3a5000.xml + +diff --git a/po/POTFILES.in b/po/POTFILES.in +index bf0a3b3529..1153e78265 100644 +--- a/po/POTFILES.in ++++ b/po/POTFILES.in +@@ -68,6 +68,7 @@ + @SRCDIR@src/cpu/cpu_arm.c + @SRCDIR@src/cpu/cpu_map.c + @SRCDIR@src/cpu/cpu_ppc64.c ++@SRCDIR@src/cpu/cpu_loongarch.c + @SRCDIR@src/cpu/cpu_s390.c + @SRCDIR@src/cpu/cpu_x86.c + @SRCDIR@src/datatypes.c +diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c +index 285c7eee44..49527c3688 100644 +--- a/src/cpu/cpu.c ++++ b/src/cpu/cpu.c +@@ -31,7 +31,7 @@ + #include "cpu_arm.h" + #include "capabilities.h" + #include "virstring.h" +- ++#include "cpu_loongarch.h" + + #define VIR_FROM_THIS VIR_FROM_CPU + +@@ -42,6 +42,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverPPC64, + &cpuDriverS390, + &cpuDriverArm, ++ &cpuDriverLoongArch, + }; + + +diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h +index 071b33fe76..ce7aee4757 100644 +--- a/src/cpu/cpu.h ++++ b/src/cpu/cpu.h +@@ -28,7 +28,7 @@ + #include "cpu_x86_data.h" + #include "cpu_ppc64_data.h" + #include "cpu_arm_data.h" +- ++#include "cpu_loongarch_data.h" + + typedef struct _virCPUData virCPUData; + struct _virCPUData { +@@ -37,6 +37,7 @@ struct _virCPUData { + virCPUx86Data x86; + virCPUppc64Data ppc64; + virCPUarmData arm; ++ virCPULoongArchData loongarch; + /* generic driver needs no data */ + } data; + }; +diff --git a/src/cpu/cpu_loongarch.c b/src/cpu/cpu_loongarch.c +new file mode 100644 +index 0000000000..f7b4b85a44 +--- /dev/null ++++ b/src/cpu/cpu_loongarch.c +@@ -0,0 +1,727 @@ ++/* ++ * cpu_loongarch.c: CPU driver for 64-bit LOONGARCH CPUs ++ * ++ * Copyright (C) 2013 Red Hat, Inc. ++ * Copyright (C) IBM Corporation, 2010 ++ * ++ * 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 ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "virlog.h" ++#include "viralloc.h" ++#include "cpu.h" ++#include "virstring.h" ++#include "cpu_map.h" ++#include "virbuffer.h" ++#include "cpu_loongarch.h" ++#include "cpu_loongarch_data.h" ++ ++#define VIR_FROM_THIS VIR_FROM_CPU ++ ++VIR_LOG_INIT("cpu.cpu_loongarch"); ++ ++static const virArch archs[] = { VIR_ARCH_LOONGARCH64 }; ++ ++typedef struct _LoongArch_vendor LoongArch_vendor; ++struct _LoongArch_vendor { ++ char *name; ++}; ++ ++typedef struct _LoongArch_model LoongArch_model; ++struct _LoongArch_model { ++ char *name; ++ LoongArch_vendor *vendor; ++ virCPULoongArchData data; ++}; ++ ++typedef struct _LoongArch_map LoongArch_map; ++struct _LoongArch_map { ++ size_t nvendors; ++ LoongArch_vendor **vendors; ++ size_t nmodels; ++ LoongArch_model **models; ++}; ++ ++static void ++LoongArchDataClear(virCPULoongArchData *data) ++{ ++ if (!data) ++ return; ++ ++ g_free(data->prid); ++} ++ ++static int ++LoongArchDataCopy(virCPULoongArchData *dst, const virCPULoongArchData *src) ++{ ++ size_t i; ++ ++ dst->prid = g_new0(virCPULoongArchPrid, src->len); ++ dst->len = src->len; ++ ++ for (i = 0; i < src->len; i++) { ++ dst->prid[i].value = src->prid[i].value; ++ dst->prid[i].mask = src->prid[i].mask; ++ } ++ ++ return 0; ++} ++ ++static void ++LoongArchVendorFree(LoongArch_vendor *vendor) ++{ ++ if (!vendor) ++ return; ++ ++ g_free(vendor); ++} ++ ++static LoongArch_vendor * ++LoongArchVendorFind(LoongArch_map *map, ++ const char *name) ++{ ++ size_t i; ++ ++ for (i = 0; i < map->nvendors; i++) { ++ if (STREQ(map->vendors[i]->name, name)) ++ return map->vendors[i]; ++ } ++ ++ return NULL; ++} ++ ++static void ++LoongArchModelFree(LoongArch_model *model) ++{ ++ if (!model) ++ return; ++ ++ LoongArchDataClear(&model->data); ++ g_free(model->name); ++ g_free(model); ++} ++ ++static LoongArch_model * ++LoongArchModelCopy(LoongArch_model *model) ++{ ++ LoongArch_model *copy; ++ ++ copy = g_new0(LoongArch_model, 1); ++ copy->name = g_strdup(model->name); ++ ++ if (LoongArchDataCopy(©->data, &model->data) < 0) ++ goto error; ++ ++ copy->vendor = model->vendor; ++ ++ return copy; ++ ++ error: ++ LoongArchModelFree(copy); ++ return NULL; ++} ++ ++static LoongArch_model * ++LoongArchModelFind(LoongArch_map *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 LoongArch_model * ++LoongArchModelFindPrid(LoongArch_map *map, ++ uint32_t prid) ++{ ++ size_t i; ++ size_t j; ++ ++ for (i = 0; i < map->nmodels; i++) { ++ LoongArch_model *model = map->models[i]; ++ for (j = 0; j < model->data.len; j++) { ++ if ((prid & model->data.prid[j].mask) == model->data.prid[j].value) ++ return model; ++ } ++ } ++ ++ return NULL; ++} ++ ++static LoongArch_model * ++LoongArchModelFromCPU(const virCPUDef *cpu, ++ LoongArch_map *map) ++{ ++ LoongArch_model *model; ++ ++ if (!cpu->model) { ++ virReportError(VIR_ERR_INVALID_ARG, "%s", ++ _("no CPU model specified")); ++ return NULL; ++ } ++ ++ if (!(model = LoongArchModelFind(map, cpu->model))) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Unknown CPU model %s"), cpu->model); ++ return NULL; ++ } ++ ++ return LoongArchModelCopy(model); ++} ++ ++static void ++LoongArchMapFree(LoongArch_map *map) ++{ ++ size_t i; ++ ++ if (!map) ++ return; ++ ++ for (i = 0; i < map->nmodels; i++) ++ LoongArchModelFree(map->models[i]); ++ g_free(map->models); ++ ++ for (i = 0; i < map->nvendors; i++) ++ LoongArchVendorFree(map->vendors[i]); ++ g_free(map->vendors); ++ ++ g_free(map); ++} ++ ++static int ++LoongArchVendorParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, ++ const char *name, ++ void *data) ++{ ++ LoongArch_map *map = data; ++ LoongArch_vendor *vendor; ++ int ret = -1; ++ ++ vendor = g_new0(LoongArch_vendor, 1); ++ vendor->name = g_strdup(name); ++ ++ if (LoongArchVendorFind(map, vendor->name)) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("CPU vendor %s already defined"), vendor->name); ++ goto cleanup; ++ } ++ ++ VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor); ++ ret = 0; ++ ++ cleanup: ++ LoongArchVendorFree(vendor); ++ return ret; ++} ++ ++static int ++LoongArchModelParse(xmlXPathContextPtr ctxt, ++ const char *name, ++ void *data) ++{ ++ LoongArch_map *map = data; ++ LoongArch_model *model; ++ xmlNodePtr *nodes = NULL; ++ char *vendor = NULL; ++ unsigned long prid; ++ size_t i; ++ int n; ++ int ret = -1; ++ ++ model = g_new0(LoongArch_model, 1); ++ model->name = g_strdup(name); ++ ++ if (LoongArchModelFind(map, model->name)) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("CPU model %s already defined"), model->name); ++ goto cleanup; ++ } ++ ++ if (virXPathBoolean("boolean(./vendor)", ctxt)) { ++ vendor = virXPathString("string(./vendor/@name)", ctxt); ++ if (!vendor) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Invalid vendor element in CPU model %s"), ++ model->name); ++ goto cleanup; ++ } ++ ++ if (!(model->vendor = LoongArchVendorFind(map, vendor))) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Unknown vendor %s referenced by CPU model %s"), ++ vendor, model->name); ++ goto cleanup; ++ } ++ } ++ ++ if ((n = virXPathNodeSet("./prid", ctxt, &nodes)) <= 0) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Missing Prid information for CPU model %s"), ++ model->name); ++ goto cleanup; ++ } ++ ++ model->data.prid = g_new0(virCPULoongArchPrid, n); ++ model->data.len = n; ++ ++ for (i = 0; i < n; i++) { ++ ctxt->node = nodes[i]; ++ ++ if (virXPathULongHex("string(./@value)", ctxt, &prid) < 0) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Missing or invalid Prid value in CPU model %s"), ++ model->name); ++ goto cleanup; ++ } ++ model->data.prid[i].value = prid; ++ ++ if (virXPathULongHex("string(./@mask)", ctxt, &prid) < 0) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Missing or invalid PVR mask in CPU model %s"), ++ model->name); ++ goto cleanup; ++ } ++ model->data.prid[i].mask = prid; ++ } ++ ++ VIR_APPEND_ELEMENT(map->models, map->nmodels, model); ++ ret = 0; ++ ++ cleanup: ++ LoongArchModelFree(model); ++ g_free(vendor); ++ g_free(nodes); ++ return ret; ++} ++ ++static LoongArch_map * ++LoongArchLoadMap(void) ++{ ++ LoongArch_map *map; ++ ++ map = g_new0(LoongArch_map, 1); ++ if (cpuMapLoad("loongarch64", LoongArchVendorParse, NULL, LoongArchModelParse, map) < 0) ++ goto error; ++ ++ return map; ++ ++ error: ++ LoongArchMapFree(map); ++ return NULL; ++} ++ ++static virCPUData * ++LoongArchMakeCPUData(virArch arch, ++ virCPULoongArchData *data) ++{ ++ virCPUData *cpuData; ++ ++ cpuData = g_new0(virCPUData, 1); ++ cpuData->arch = arch; ++ ++ if (LoongArchDataCopy(&cpuData->data.loongarch, data) < 0) ++ g_free(cpuData); ++ ++ return cpuData; ++} ++ ++static virCPUCompareResult ++LoongArchCompute(virCPUDef *host, ++ const virCPUDef *other, ++ virCPUData *guestData, ++ char **message) ++{ ++ LoongArch_map *map = NULL; ++ LoongArch_model *host_model = NULL; ++ LoongArch_model *guest_model = NULL; ++ virCPUDef *cpu = NULL; ++ virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR; ++ virArch arch; ++ size_t i; ++ ++ /* Ensure existing configurations are handled correctly */ ++ if (!(cpu = virCPUDefCopy(other))) ++ goto cleanup; ++ ++ if (cpu->arch != VIR_ARCH_NONE) { ++ bool found = false; ++ ++ for (i = 0; i < G_N_ELEMENTS(archs); i++) { ++ if (archs[i] == cpu->arch) { ++ found = true; ++ break; ++ } ++ } ++ ++ if (!found) { ++ VIR_DEBUG("CPU arch %s does not match host arch", ++ virArchToString(cpu->arch)); ++ if (message) { ++ *message = g_strdup_printf(_("CPU arch %s does not match host arch"), ++ virArchToString(cpu->arch)); ++ } ++ ret = VIR_CPU_COMPARE_INCOMPATIBLE; ++ goto cleanup; ++ } ++ arch = cpu->arch; ++ } else { ++ arch = host->arch; ++ } ++ ++ if (cpu->vendor && ++ (!host->vendor || STRNEQ(cpu->vendor, host->vendor))) { ++ VIR_DEBUG("host CPU vendor does not match required CPU vendor %s", ++ cpu->vendor); ++ if (message) { ++ *message = g_strdup_printf(_("host CPU vendor does not match required " ++ "CPU vendor %s"), cpu->vendor); ++ } ++ ret = VIR_CPU_COMPARE_INCOMPATIBLE; ++ goto cleanup; ++ } ++ ++ if (!(map = LoongArchLoadMap())) ++ goto cleanup; ++ ++ /* Host CPU information */ ++ if (!(host_model = LoongArchModelFromCPU(host, map))) ++ goto cleanup; ++ ++ if (cpu->type == VIR_CPU_TYPE_GUEST) { ++ /* Guest CPU information */ ++ switch (cpu->mode) { ++ case VIR_CPU_MODE_HOST_MODEL: ++ case VIR_CPU_MODE_HOST_PASSTHROUGH: ++ /* host-model and host-passthrough: ++ * the guest CPU is the same as the host */ ++ guest_model = LoongArchModelCopy(host_model); ++ break; ++ ++ case VIR_CPU_MODE_CUSTOM: ++ /* custom: ++ * look up guest CPU information */ ++ guest_model = LoongArchModelFromCPU(cpu, map); ++ break; ++ } ++ } else { ++ /* Other host CPU information */ ++ guest_model = LoongArchModelFromCPU(cpu, map); ++ } ++ ++ if (!guest_model) ++ goto cleanup; ++ ++ if (STRNEQ(guest_model->name, host_model->name)) { ++ VIR_DEBUG("host CPU model does not match required CPU model %s", ++ guest_model->name); ++ if (message) { ++ *message = g_strdup_printf(_("host CPU model does not match required " ++ "CPU model %s"),guest_model->name); ++ } ++ ret = VIR_CPU_COMPARE_INCOMPATIBLE; ++ goto cleanup; ++ } ++ ++ if (guestData) ++ if (!(guestData = LoongArchMakeCPUData(arch, &guest_model->data))) ++ goto cleanup; ++ ++ ret = VIR_CPU_COMPARE_IDENTICAL; ++ ++ cleanup: ++ virCPUDefFree(cpu); ++ LoongArchMapFree(map); ++ LoongArchModelFree(host_model); ++ LoongArchModelFree(guest_model); ++ return ret; ++} ++ ++static virCPUCompareResult ++virCPULoongArchCompare(virCPUDef *host, ++ virCPUDef *cpu, ++ bool failIncompatible) ++{ ++ virCPUCompareResult ret; ++ char *message = NULL; ++ ++ if (!host || !host->model) { ++ if (failIncompatible) { ++ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", ++ _("unknown host CPU")); ++ } else { ++ VIR_WARN("unknown host CPU"); ++ ret = VIR_CPU_COMPARE_INCOMPATIBLE; ++ } ++ return -1; ++ } ++ ++ ret = LoongArchCompute(host, cpu, NULL, &message); ++ ++ if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) { ++ ret = VIR_CPU_COMPARE_ERROR; ++ if (message) { ++ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message); ++ } else { ++ virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); ++ } ++ } ++ g_free(message); ++ ++ return ret; ++} ++ ++static int ++LoongArchDriverDecode(virCPUDef *cpu, ++ const virCPUData *data, ++ virDomainCapsCPUModels *models) ++{ ++ int ret = -1; ++ LoongArch_map *map; ++ LoongArch_model *model; ++ ++ if (!data || !(map = LoongArchLoadMap())) ++ return -1; ++ ++ if (!(model = LoongArchModelFindPrid(map, data->data.loongarch.prid[0].value))) { ++ virReportError(VIR_ERR_OPERATION_FAILED, ++ _("Cannot find CPU model with Prid 0x%08x"), ++ data->data.loongarch.prid[0].value); ++ goto cleanup; ++ } ++ ++ if (!virCPUModelIsAllowed(model->name, models)) { ++ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, ++ _("CPU model %s is not supported by hypervisor"), ++ model->name); ++ goto cleanup; ++ } ++ ++ cpu->model = g_strdup(model->name); ++ if (model->vendor) { ++ cpu->vendor = g_strdup(model->vendor->name); ++ } ++ ret = 0; ++ ++ cleanup: ++ LoongArchMapFree(map); ++ ++ return ret; ++} ++ ++static void ++virCPULoongArchDataFree(virCPUData *data) ++{ ++ if (!data) ++ return; ++ ++ LoongArchDataClear(&data->data.loongarch); ++ g_free(data); ++} ++ ++static int virCPULoongArchGetHostPRID(void) ++{ ++ return 0x14c010; ++} ++ ++static int ++virCPULoongArchGetHost(virCPUDef *cpu, ++ virDomainCapsCPUModels *models) ++{ ++ virCPUData *cpuData = NULL; ++ virCPULoongArchData *data; ++ int ret = -1; ++ ++ if (!(cpuData = virCPUDataNew(archs[0]))) ++ goto cleanup; ++ ++ data = &cpuData->data.loongarch; ++ ++ data->prid = g_new0(virCPULoongArchPrid, 1); ++ data->len = 1; ++ ++ data->prid[0].value = virCPULoongArchGetHostPRID(); ++ data->prid[0].mask = 0xffff00ul; ++ ++ ret = LoongArchDriverDecode(cpu, cpuData, models); ++ ++ cleanup: ++ virCPULoongArchDataFree(cpuData); ++ return ret; ++} ++ ++ ++static int ++virCPULoongArchUpdate(virCPUDef *guest, ++ const virCPUDef *host, ++ bool relative) ++{ ++ /* ++ * - host-passthrough doesn't even get here ++ * - host-model is used for host CPU running in a compatibility mode and ++ * it needs to remain unchanged ++ * - custom doesn't support any optional features, there's nothing to ++ * update ++ */ ++ VIR_DEBUG("host model %s, if relatived %d",host->model, relative); ++ if (guest->mode == VIR_CPU_MODE_CUSTOM) ++ guest->match = VIR_CPU_MATCH_EXACT; ++ ++ return 0; ++} ++ ++static virCPUDef * ++LoongArchDriverBaseline(virCPUDef **cpus, ++ unsigned int ncpus, ++ virDomainCapsCPUModels *models, ++ const char **features, ++ bool migratable) ++{ ++ LoongArch_map *map; ++ LoongArch_model *model; ++ LoongArch_vendor *vendor = NULL; ++ virCPUDef *cpu = NULL; ++ size_t i; ++ if (models && *features) { ++ VIR_DEBUG("migratable %d features %s",migratable, *features); ++ } ++ if (!(map = LoongArchLoadMap())) ++ goto error; ++ ++ if (!(model = LoongArchModelFind(map, cpus[0]->model))) { ++ virReportError(VIR_ERR_INTERNAL_ERROR, ++ _("Unknown CPU model %s"), cpus[0]->model); ++ goto error; ++ } ++ ++ for (i = 0; i < ncpus; i++) { ++ LoongArch_vendor *vnd; ++ ++ if (STRNEQ(cpus[i]->model, model->name)) { ++ virReportError(VIR_ERR_OPERATION_FAILED, "%s", ++ _("CPUs are incompatible")); ++ goto error; ++ } ++ ++ if (!cpus[i]->vendor) ++ continue; ++ ++ if (!(vnd = LoongArchVendorFind(map, cpus[i]->vendor))) { ++ virReportError(VIR_ERR_OPERATION_FAILED, ++ _("Unknown CPU vendor %s"), cpus[i]->vendor); ++ goto error; ++ } ++ ++ if (model->vendor) { ++ if (model->vendor != vnd) { ++ virReportError(VIR_ERR_OPERATION_FAILED, ++ _("CPU vendor %s of model %s differs from " ++ "vendor %s"), ++ model->vendor->name, model->name, ++ vnd->name); ++ goto error; ++ } ++ } else if (vendor) { ++ if (vendor != vnd) { ++ virReportError(VIR_ERR_OPERATION_FAILED, "%s", ++ _("CPU vendors do not match")); ++ goto error; ++ } ++ } else { ++ vendor = vnd; ++ } ++ } ++ ++ cpu = g_new0(virCPUDef ,1); ++ cpu->model = g_strdup(model->name); ++ if (vendor) { ++ cpu->vendor = g_strdup(vendor->name); ++ } ++ cpu->type = VIR_CPU_TYPE_GUEST; ++ cpu->match = VIR_CPU_MATCH_EXACT; ++ cpu->fallback = VIR_CPU_FALLBACK_FORBID; ++ ++ cleanup: ++ LoongArchMapFree(map); ++ ++ return cpu; ++ ++ error: ++ virCPUDefFree(cpu); ++ cpu = NULL; ++ goto cleanup; ++} ++ ++static int ++virCPULoongArchDriverGetModels(char ***models) ++{ ++ LoongArch_map *map; ++ size_t i; ++ int ret = -1; ++ ++ if (!(map = LoongArchLoadMap())) ++ 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: ++ LoongArchMapFree(map); ++ return ret; ++ ++ error: ++ if (models) { ++ g_strfreev(*models); ++ *models = NULL; ++ } ++ goto cleanup; ++} ++ ++struct cpuArchDriver cpuDriverLoongArch = { ++ .name = "LoongArch", ++ .arch = archs, ++ .narch = G_N_ELEMENTS(archs), ++ .compare = virCPULoongArchCompare, ++ .decode = LoongArchDriverDecode, ++ .encode = NULL, ++ .dataFree = virCPULoongArchDataFree, ++ .getHost = virCPULoongArchGetHost, ++ .baseline = LoongArchDriverBaseline, ++ .update = virCPULoongArchUpdate, ++ .getModels = virCPULoongArchDriverGetModels, ++}; +diff --git a/src/cpu/cpu_loongarch.h b/src/cpu/cpu_loongarch.h +new file mode 100644 +index 0000000000..1fde3b5162 +--- /dev/null ++++ b/src/cpu/cpu_loongarch.h +@@ -0,0 +1,28 @@ ++/* ++ * cpu_loongarch.h: CPU driver for 64-bit LOONGARCH CPUs ++ * ++ * Copyright (C) Copyright (C) IBM Corporation, 2010 ++ * ++ * 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 ++ * . ++ */ ++ ++#ifndef __VIR_CPU_LOONGARCH_H__ ++# define __VIR_CPU_LOONGARCH_H__ ++ ++# include "cpu.h" ++ ++extern struct cpuArchDriver cpuDriverLoongArch; ++ ++#endif /* __VIR_CPU_LOONGARCH_H__ */ +diff --git a/src/cpu/cpu_loongarch_data.h b/src/cpu/cpu_loongarch_data.h +new file mode 100644 +index 0000000000..1a759e7d16 +--- /dev/null ++++ b/src/cpu/cpu_loongarch_data.h +@@ -0,0 +1,40 @@ ++/* ++ * cpu_loongarch_data.h: 64-bit LOONGARCH CPU specific data ++ * ++ * Copyright (C) 2012 IBM Corporation. ++ * ++ * 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 ++ * . ++ */ ++ ++#ifndef __VIR_CPU_LOONGARCH_DATA_H__ ++# define __VIR_CPU_LOONGARCH_DATA_H__ ++ ++# include ++ ++typedef struct _virCPULoongArchPrid virCPULoongArchPrid; ++struct _virCPULoongArchPrid { ++ uint32_t value; ++ uint32_t mask; ++}; ++ ++# define VIR_CPU_LOONGARCH_DATA_INIT { 0 } ++ ++typedef struct _virCPULoongArchData virCPULoongArchData; ++struct _virCPULoongArchData { ++ size_t len; ++ virCPULoongArchPrid *prid; ++}; ++ ++#endif /* __VIR_CPU_MIPS64_DATA_H__ */ +diff --git a/src/cpu/meson.build b/src/cpu/meson.build +index b4ad95e46d..ad2f859fd8 100644 +--- a/src/cpu/meson.build ++++ b/src/cpu/meson.build +@@ -5,6 +5,7 @@ cpu_sources = [ + 'cpu_ppc64.c', + 'cpu_s390.c', + 'cpu_x86.c', ++ 'cpu_loongarch.c', + ] + + cpu_lib = static_library( +diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml +index ffe1fa91e5..d302de396a 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -110,4 +110,9 @@ + + + ++ ++ ++ ++ ++ + +diff --git a/src/cpu_map/loongarch_vendors.xml b/src/cpu_map/loongarch_vendors.xml +new file mode 100644 +index 0000000000..c744654617 +--- /dev/null ++++ b/src/cpu_map/loongarch_vendors.xml +@@ -0,0 +1,3 @@ ++ ++ ++ +diff --git a/src/cpu_map/ls_3a5000.xml b/src/cpu_map/ls_3a5000.xml +new file mode 100644 +index 0000000000..f6fe3386f7 +--- /dev/null ++++ b/src/cpu_map/ls_3a5000.xml +@@ -0,0 +1,6 @@ ++ ++ ++ ++ ++ ++ +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index 013fc62a02..9657c5164e 100644 +--- a/src/cpu_map/meson.build ++++ b/src/cpu_map/meson.build +@@ -77,6 +77,8 @@ cpumap_data = [ + 'x86_vendors.xml', + 'x86_Westmere-IBRS.xml', + 'x86_Westmere.xml', ++ 'loongarch_vendors.xml', ++ 'ls_3a5000.xml', + ] + + install_data(cpumap_data, install_dir: pkgdatadir / 'cpu_map') +diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index c4f7db55c8..75668c6451 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -2073,6 +2073,9 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) + if (ARCH_IS_X86(def->os.arch)) + return true; + ++ if (STRPREFIX(def->os.machine,"loongson7a")) ++ 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)) { +@@ -2690,6 +2693,7 @@ static const char *preferredMachines[] = + + "malta", /* VIR_ARCH_MIPS64 */ + "malta", /* VIR_ARCH_MIPS64EL */ ++ "loongson7a", /* VIR_ARCH_LOONGARCH64 */ + "or1k-sim", /* VIR_ARCH_OR32 */ + NULL, /* VIR_ARCH_PARISC (no QEMU impl) */ + NULL, /* VIR_ARCH_PARISC64 (no QEMU impl) */ +@@ -5115,6 +5119,7 @@ virQEMUCapsInitQMPBasicArch(virQEMUCaps *qemuCaps) + case VIR_ARCH_MIPSEL: + case VIR_ARCH_MIPS64: + case VIR_ARCH_MIPS64EL: ++ case VIR_ARCH_LOONGARCH64: + case VIR_ARCH_OR32: + case VIR_ARCH_PARISC: + case VIR_ARCH_PARISC64: +diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c +index a0b8076d6b..8cd03261ac 100644 +--- a/src/qemu/qemu_conf.c ++++ b/src/qemu/qemu_conf.c +@@ -101,7 +101,9 @@ qemuDriverUnlock(virQEMUDriver *driver) + "/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd:" \ + "/usr/share/OVMF/OVMF_CODE.secboot.fd:/usr/share/OVMF/OVMF_VARS.fd:" \ + "/usr/share/AAVMF/AAVMF_CODE.fd:/usr/share/AAVMF/AAVMF_VARS.fd:" \ +- "/usr/share/AAVMF/AAVMF32_CODE.fd:/usr/share/AAVMF/AAVMF32_VARS.fd" ++ "/usr/share/AAVMF/AAVMF32_CODE.fd:/usr/share/AAVMF/AAVMF32_VARS.fd:" \ ++ "/usr/share/qemu-kvm/loongarch_bios.bin:/usr/share/qemu-kvm/loongarch_bios.bin" ++ + #endif + + +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index 40fe9985e6..814d8cb67d 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -3668,6 +3668,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, + addPCIeRoot = virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_GPEX); + break; + ++ case VIR_ARCH_LOONGARCH64: ++ addPCIeRoot = true; ++ break; ++ + case VIR_ARCH_PPC64: + case VIR_ARCH_PPC64LE: + addPCIRoot = true; +@@ -5065,6 +5069,11 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, + cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) + cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; ++ } 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 (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) ++ cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI; + } + } + /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr */ +@@ -8324,6 +8333,13 @@ qemuDomainDefCheckABIStability(virQEMUDriver *driver, + } + + ++bool ++qemuDomainIsLoongson(const virDomainDef *def) ++{ ++ return (STRPREFIX(def->os.machine,"loongson3a") || STRPREFIX(def->os.machine,"loongson7a")); ++} ++ ++ + bool + qemuDomainCheckABIStability(virQEMUDriver *driver, + virDomainObj *vm, +@@ -8664,7 +8680,9 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, + return qemuDomainMachineIsI440FX(machine, arch) || + STREQ(machine, "malta") || + STREQ(machine, "sun4u") || +- STREQ(machine, "g3beige"); ++ STREQ(machine, "g3beige") || ++ STREQ(machine, "loongson3a") || ++ STREQ(machine, "loongson7a"); + } + + +diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h +index e5046367e3..57f1f97348 100644 +--- a/src/qemu/qemu_domain.h ++++ b/src/qemu/qemu_domain.h +@@ -770,6 +770,7 @@ bool qemuDomainIsS390CCW(const virDomainDef *def); + bool qemuDomainIsARMVirt(const virDomainDef *def); + bool qemuDomainIsRISCVVirt(const virDomainDef *def); + bool qemuDomainIsPSeries(const virDomainDef *def); ++bool qemuDomainIsLoongson(const virDomainDef *def); + bool qemuDomainHasPCIRoot(const virDomainDef *def); + bool qemuDomainHasPCIeRoot(const virDomainDef *def); + bool qemuDomainHasBuiltinIDE(const virDomainDef *def); +diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c +index 18fc34d049..c3fac1c33b 100644 +--- a/src/qemu/qemu_domain_address.c ++++ b/src/qemu/qemu_domain_address.c +@@ -2026,6 +2026,59 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDef *def, + } + + ++static int ++qemuDomainValidateDevicePCISlotsLoongson(virDomainDef *def, ++ virDomainPCIAddressSet *addrs) ++{ ++ int ret = -1; ++ virPCIDeviceAddress tmp_addr; ++ char *addrStr = NULL; ++ virDomainPCIConnectFlags flags = (VIR_PCI_CONNECT_AUTOASSIGN ++ | VIR_PCI_CONNECT_TYPE_PCI_DEVICE); ++ ++ if (addrs->nbuses) { ++ memset(&tmp_addr, 0, sizeof(tmp_addr)); ++ tmp_addr.slot = 1; ++ /* pci-ohci at 00:01.0 */ ++ if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) ++ goto cleanup; ++ } ++ ++ if (def->nvideos > 0 && ++ def->videos[0]->type != VIR_DOMAIN_VIDEO_TYPE_NONE && ++ def->videos[0]->type != VIR_DOMAIN_VIDEO_TYPE_RAMFB) { ++ /*reserve slot 2 for vga device */ ++ virDomainVideoDef *primaryVideo = def->videos[0]; ++ ++ if (virDeviceInfoPCIAddressIsWanted(&primaryVideo->info)) { ++ memset(&tmp_addr, 0, sizeof(tmp_addr)); ++ tmp_addr.slot = 2; ++ ++ if (!(addrStr = virPCIDeviceAddressAsString(&tmp_addr))) ++ goto cleanup; ++ if (!virDomainPCIAddressValidate(addrs, &tmp_addr, ++ addrStr, flags, true)) ++ goto cleanup; ++ ++ if (virDomainPCIAddressSlotInUse(addrs, &tmp_addr)) { ++ if (qemuDomainPCIAddressReserveNextAddr(addrs, ++ &primaryVideo->info) < 0) ++ goto cleanup; ++ } else { ++ if (virDomainPCIAddressReserveAddr(addrs, &tmp_addr, flags, 0) < 0) ++ goto cleanup; ++ primaryVideo->info.addr.pci = tmp_addr; ++ primaryVideo->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; ++ } ++ } ++ } ++ ret = 0; ++ cleanup: ++ VIR_FREE(addrStr); ++ return ret; ++} ++ ++ + static int + qemuDomainValidateDevicePCISlotsChipsets(virDomainDef *def, + virDomainPCIAddressSet *addrs) +@@ -2040,6 +2093,11 @@ qemuDomainValidateDevicePCISlotsChipsets(virDomainDef *def, + return -1; + } + ++ if (qemuDomainIsLoongson(def) && ++ qemuDomainValidateDevicePCISlotsLoongson(def, addrs) < 0) { ++ return -1; ++ } ++ + return 0; + } + +diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c +index 7bc14293d6..7d01d31aaf 100644 +--- a/src/qemu/qemu_validate.c ++++ b/src/qemu/qemu_validate.c +@@ -186,7 +186,8 @@ qemuValidateDomainDefFeatures(const virDomainDef *def, + switch ((virDomainFeature) i) { + case VIR_DOMAIN_FEATURE_IOAPIC: + if (def->features[i] != VIR_DOMAIN_IOAPIC_NONE) { +- if (!ARCH_IS_X86(def->os.arch)) { ++ if (!(ARCH_IS_X86(def->os.arch) ++ || ARCH_IS_LOONGARCH(def->os.arch))) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("The '%s' feature is not supported for " + "architecture '%s' or machine type '%s'"), +diff --git a/src/util/virarch.c b/src/util/virarch.c +index 2134dd6a9d..9f40a7110c 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -59,6 +59,7 @@ static const struct virArchData { + + { "mips64", 64, VIR_ARCH_BIG_ENDIAN }, + { "mips64el", 64, VIR_ARCH_LITTLE_ENDIAN }, ++ { "loongarch64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "openrisc", 32, VIR_ARCH_BIG_ENDIAN }, + { "parisc", 32, VIR_ARCH_BIG_ENDIAN }, + { "parisc64", 64, VIR_ARCH_BIG_ENDIAN }, +@@ -222,6 +223,8 @@ virArch virArchFromHost(void) + arch = VIR_ARCH_X86_64; + } else if (STREQ(ut.machine, "arm64")) { + arch = VIR_ARCH_AARCH64; ++ } else if (STREQ(ut.machine, "loongarch64")) { ++ arch = VIR_ARCH_LOONGARCH64; + } else { + /* Otherwise assume the canonical name */ + if ((arch = virArchFromString(ut.machine)) == VIR_ARCH_NONE) { +diff --git a/src/util/virarch.h b/src/util/virarch.h +index 528f84f8a5..7d396f2fff 100644 +--- a/src/util/virarch.h ++++ b/src/util/virarch.h +@@ -44,6 +44,7 @@ typedef enum { + + VIR_ARCH_MIPS64, /* MIPS 64 BE https://en.wikipedia.org/wiki/MIPS_architecture */ + VIR_ARCH_MIPS64EL, /* MIPS 64 LE https://en.wikipedia.org/wiki/MIPS_architecture */ ++ VIR_ARCH_LOONGARCH64, + VIR_ARCH_OR32, /* OpenRisc 32 BE https://en.wikipedia.org/wiki/OpenRISC#QEMU_support */ + VIR_ARCH_PARISC, /* PA-Risc 32 BE https://en.wikipedia.org/wiki/PA-RISC */ + VIR_ARCH_PARISC64, /* PA-Risc 64 BE https://en.wikipedia.org/wiki/PA-RISC */ +@@ -98,6 +99,8 @@ typedef enum { + #define ARCH_IS_MIPS64(arch) ((arch) == VIR_ARCH_MIPS64 ||\ + (arch) == VIR_ARCH_MIPS64EL) + ++#define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) ++ + typedef enum { + VIR_ARCH_LITTLE_ENDIAN, + VIR_ARCH_BIG_ENDIAN, +diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c +index 35f41daef2..137796ea07 100644 +--- a/src/util/virhostcpu.c ++++ b/src/util/virhostcpu.c +@@ -546,7 +546,7 @@ virHostCPUParseFrequency(FILE *cpuinfo, + char line[1024]; + + /* No sensible way to retrieve CPU frequency */ +- if (ARCH_IS_ARM(arch)) ++ if (ARCH_IS_ARM(arch) || ARCH_IS_LOONGARCH(arch)) + return 0; + + if (ARCH_IS_X86(arch)) +diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c +index af9e03c5ac..9577cf1910 100644 +--- a/src/util/virsysinfo.c ++++ b/src/util/virsysinfo.c +@@ -1247,7 +1247,7 @@ virSysinfoRead(void) + { + #if defined(__powerpc__) + return virSysinfoReadPPC(); +-#elif defined(__arm__) || defined(__aarch64__) ++#elif defined(__arm__) || defined(__aarch64__) || defined(__loongarch__) + return virSysinfoReadARM(); + #elif defined(__s390__) || defined(__s390x__) + return virSysinfoReadS390(); +-- +2.27.0 + diff --git a/libvirt.spec b/libvirt.spec index 3d29a96..f5f8d2f 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -3,19 +3,20 @@ # This spec file assumes you are building on a Fedora or RHEL version # that's still supported by the vendor. It may work on other distros # or versions, but no effort will be made to ensure that going forward. +%define anolis_release .0.1 %define min_rhel 8 %define min_fedora 33 -%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x +%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x loongarch64 %if 0%{?rhel} %if 0%{?rhel} > 8 - %define arches_qemu_kvm x86_64 aarch64 s390x + %define arches_qemu_kvm x86_64 aarch64 s390x loongarch64 %else - %define arches_qemu_kvm x86_64 %{power64} aarch64 s390x + %define arches_qemu_kvm x86_64 %{power64} aarch64 s390x loongarch64 %endif %endif -%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 +%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 loongarch64 %define arches_x86 %{ix86} x86_64 %define arches_systemtap_64bit %{arches_64bit} @@ -23,9 +24,9 @@ %define arches_xen %{arches_x86} aarch64 %define arches_vbox %{arches_x86} %define arches_ceph %{arches_64bit} -%define arches_zfs %{arches_x86} %{power64} %{arm} -%define arches_numactl %{arches_x86} %{power64} aarch64 s390x -%define arches_numad %{arches_x86} %{power64} aarch64 +%define arches_zfs %{arches_x86} %{power64} %{arm} loongarch64 +%define arches_numactl %{arches_x86} %{power64} aarch64 s390x loongarch64 +%define arches_numad %{arches_x86} %{power64} aarch64 loongarch64 # The hypervisor drivers that run in libvirtd %define with_qemu 0%{!?_without_qemu:1} @@ -210,7 +211,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 8.0.0 -Release: 23.3%{?dist}%{?extra_release} +Release: 23.3%{anolis_release}%{?dist}%{?extra_release} License: LGPLv2+ URL: https://libvirt.org/ @@ -322,6 +323,7 @@ Patch99: libvirt-remote-check-for-negative-array-lengths-before-allocation.patch Patch100: libvirt-util-Fix-error-return-for-virProcessKillPainfullyDelay.patch Patch101: libvirt-rpc-ensure-temporary-GSource-is-removed-from-client-event-loop.patch Patch102: libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch +Patch1000: libvirt-Add-loongarch-support.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2201,6 +2203,9 @@ exit 0 %changelog +* Fri Dec 20 2024 zhaotianrui - 8.0.0-23.3.0.1 +- Add loongarch support + * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) -- Gitee From a620411335957dcedbc20139c2251baad02bc1fd Mon Sep 17 00:00:00 2001 From: lixianglai Date: Wed, 31 May 2023 02:27:43 -0400 Subject: [PATCH 3/7] Fix loongarch xml validate Signed-off-by: lixianglai --- libvirt-add-loongarch-edit-xml-validate.patch | 20 +++++++++++++++++++ libvirt.spec | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 libvirt-add-loongarch-edit-xml-validate.patch diff --git a/libvirt-add-loongarch-edit-xml-validate.patch b/libvirt-add-loongarch-edit-xml-validate.patch new file mode 100644 index 0000000..7dba7ec --- /dev/null +++ b/libvirt-add-loongarch-edit-xml-validate.patch @@ -0,0 +1,20 @@ +From 6391d1634db6319d852c65c4e384030dcf568103 Mon Sep 17 00:00:00 2001 +From: zhaotianrui +Date: Wed, 13 Oct 2021 15:51:40 +0800 +Subject: [PATCH] Fix loongarch xml validate + +Signed-off-by: zhaotianrui +--- + +diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng +index 8146527..b58a61a 100644 +--- a/docs/schemas/basictypes.rng ++++ b/docs/schemas/basictypes.rng +@@ -425,6 +425,7 @@ + mipsel + mips64 + mips64el ++ loongarch64 + openrisc + parisc + parisc64 diff --git a/libvirt.spec b/libvirt.spec index f5f8d2f..eaeaeaf 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -324,6 +324,7 @@ Patch100: libvirt-util-Fix-error-return-for-virProcessKillPainfullyDelay.patch Patch101: libvirt-rpc-ensure-temporary-GSource-is-removed-from-client-event-loop.patch Patch102: libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch Patch1000: libvirt-Add-loongarch-support.patch +Patch1001: libvirt-add-loongarch-edit-xml-validate.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2205,6 +2206,7 @@ exit 0 %changelog * Fri Dec 20 2024 zhaotianrui - 8.0.0-23.3.0.1 - Add loongarch support +- Fix loongarch xml validate * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) -- Gitee From dbf646fcc59375fcf54293987bbf419d3ddf0323 Mon Sep 17 00:00:00 2001 From: xianglai li Date: Fri, 4 Aug 2023 11:18:20 +0800 Subject: [PATCH 4/7] Synchronize upstream patches to fix TPM issues. Fix the exception of adding TPM devices via virt-manager by synchronizing upstream patches. Synchronize upstream patches "Use correct tpm device for all non-x86" Synchronize upstream patches "validate: Drop tpm-tis arch validation" Signed-off-by: xianglai li --- libvirt.spec | 4 +++ ...e-correct-tpm-device-for-all-non-x86.patch | 32 +++++++++++++++++ ...alidate-Drop-tpm-tis-arch-validation.patch | 35 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 qemu-command-Use-correct-tpm-device-for-all-non-x86.patch create mode 100644 qemu-validate-Drop-tpm-tis-arch-validation.patch diff --git a/libvirt.spec b/libvirt.spec index eaeaeaf..6ccf1d5 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -325,6 +325,8 @@ Patch101: libvirt-rpc-ensure-temporary-GSource-is-removed-from-client-event-loop Patch102: libvirt-virStorageBackendLogicalCheckPool-Properly-mark-empty-logical-pools-as-active.patch Patch1000: libvirt-Add-loongarch-support.patch Patch1001: libvirt-add-loongarch-edit-xml-validate.patch +Patch1004: qemu-validate-Drop-tpm-tis-arch-validation.patch +Patch1005: qemu-command-Use-correct-tpm-device-for-all-non-x86.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2207,6 +2209,8 @@ exit 0 * Fri Dec 20 2024 zhaotianrui - 8.0.0-23.3.0.1 - Add loongarch support - Fix loongarch xml validate +- Synchronize upstream patches "Use correct tpm device for all non-x86" (lixianglai@loongson.cn) +- Synchronize upstream patches "validate: Drop tpm-tis arch validation" (lixianglai@loongson.cn) * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) diff --git a/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch b/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch new file mode 100644 index 0000000..8189141 --- /dev/null +++ b/qemu-command-Use-correct-tpm-device-for-all-non-x86.patch @@ -0,0 +1,32 @@ +From 7c9af5730bc83bde24d6788720f92fceba533124 Mon Sep 17 00:00:00 2001 +From: Cole Robinson +Date: Sat, 18 Jun 2022 12:46:03 -0400 +Subject: [PATCH 2/2] qemu: command: Use correct tpm device for all non-x86 + +The qemu `tpm-tis` device is an ISA device, so only really applicable +to x86 archs. For all non-x86 archs we should use `tpm-tis-device` + +This fixes tpm-tis usage on armv7l and riscv + +Reviewed-by: Michal Privoznik +Signed-off-by: Cole Robinson +--- + src/qemu/qemu_command.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c +index a7855d3..978ce89 100644 +--- a/src/qemu/qemu_command.c ++++ b/src/qemu/qemu_command.c +@@ -9733,7 +9733,7 @@ qemuBuildTPMDevCmd(virCommand *cmd, + const char *model = virDomainTPMModelTypeToString(tpm->model); + g_autofree char *tpmdev = g_strdup_printf("tpm-%s", tpm->info.alias); + +- if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && def->os.arch == VIR_ARCH_AARCH64) ++ if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && !ARCH_IS_X86(def->os.arch)) + model = "tpm-tis-device"; + + if (virJSONValueObjectAdd(&props, +-- +2.31.1 + diff --git a/qemu-validate-Drop-tpm-tis-arch-validation.patch b/qemu-validate-Drop-tpm-tis-arch-validation.patch new file mode 100644 index 0000000..178a943 --- /dev/null +++ b/qemu-validate-Drop-tpm-tis-arch-validation.patch @@ -0,0 +1,35 @@ +From d45d539a4aab6702710b877816d93d70f81c0165 Mon Sep 17 00:00:00 2001 +From: Cole Robinson +Date: Sat, 18 Jun 2022 12:52:29 -0400 +Subject: [PATCH 1/2] qemu: validate: Drop tpm-tis arch validation + +Checking against qemu capabilities should be enough here + +Resolves: https://gitlab.com/libvirt/libvirt/-/issues/329 + +Reviewed-by: Michal Privoznik +Signed-off-by: Cole Robinson +--- + src/qemu/qemu_validate.c | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c +index 7d01d31..6b65ce4 100644 +--- a/src/qemu/qemu_validate.c ++++ b/src/qemu/qemu_validate.c +@@ -4618,12 +4618,6 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm, + + switch (tpm->model) { + case VIR_DOMAIN_TPM_MODEL_TIS: +- if (!ARCH_IS_X86(def->os.arch) && (def->os.arch != VIR_ARCH_AARCH64)) { +- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, +- _("TPM model '%s' is only available for x86 and aarch64 guests"), +- virDomainTPMModelTypeToString(tpm->model)); +- return -1; +- } + flag = QEMU_CAPS_DEVICE_TPM_TIS; + break; + case VIR_DOMAIN_TPM_MODEL_CRB: +-- +2.31.1 + -- Gitee From c22c70dedac5b419928a08349a3024b9007384bc Mon Sep 17 00:00:00 2001 From: Yanjing Zhou Date: Tue, 18 Jun 2024 16:07:33 +0800 Subject: [PATCH 5/7] Add new Dharma CPU model Add Hygon Dharma CPU model to the processor model. Signed-off-by: Yanjing Zhou --- libvirt-cpu-Add-new-Dharma-CPU-model.patch | 131 +++++++++++++++++++++ libvirt.spec | 2 + 2 files changed, 133 insertions(+) create mode 100644 libvirt-cpu-Add-new-Dharma-CPU-model.patch diff --git a/libvirt-cpu-Add-new-Dharma-CPU-model.patch b/libvirt-cpu-Add-new-Dharma-CPU-model.patch new file mode 100644 index 0000000..39c6176 --- /dev/null +++ b/libvirt-cpu-Add-new-Dharma-CPU-model.patch @@ -0,0 +1,131 @@ +From 654e5425700bcc5ece7a414061a504283ae24727 Mon Sep 17 00:00:00 2001 +From: Yanjing Zhou +Date: Tue, 11 Jun 2024 16:00:14 +0800 +Subject: [PATCH] cpu: Add new Dharma CPU model + +Add Hygon Dharma CPU model to the processor model. + +Signed-off-by: Yanjing Zhou +--- + src/cpu_map/index.xml | 1 + + src/cpu_map/meson.build | 1 + + src/cpu_map/x86_Dharma.xml | 83 ++++++++++++++++++++++++++++++++++++++ + 3 files changed, 85 insertions(+) + create mode 100644 src/cpu_map/x86_Dharma.xml + +diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml +index ffe1fa9..9419674 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -72,6 +72,7 @@ + + + ++ + + + +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index 013fc62..c2a7052 100644 +--- a/src/cpu_map/meson.build ++++ b/src/cpu_map/meson.build +@@ -31,6 +31,7 @@ cpumap_data = [ + 'x86_coreduo.xml', + 'x86_cpu64-rhel5.xml', + 'x86_cpu64-rhel6.xml', ++ 'x86_Dharma.xml', + 'x86_Dhyana.xml', + 'x86_EPYC-IBPB.xml', + 'x86_EPYC.xml', +diff --git a/src/cpu_map/x86_Dharma.xml b/src/cpu_map/x86_Dharma.xml +new file mode 100644 +index 0000000..bf20116 +--- /dev/null ++++ b/src/cpu_map/x86_Dharma.xml +@@ -0,0 +1,83 @@ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +-- +2.39.3 + diff --git a/libvirt.spec b/libvirt.spec index 6ccf1d5..7cdb470 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -327,6 +327,7 @@ Patch1000: libvirt-Add-loongarch-support.patch Patch1001: libvirt-add-loongarch-edit-xml-validate.patch Patch1004: qemu-validate-Drop-tpm-tis-arch-validation.patch Patch1005: qemu-command-Use-correct-tpm-device-for-all-non-x86.patch +Patch1006: libvirt-cpu-Add-new-Dharma-CPU-model.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2211,6 +2212,7 @@ exit 0 - Fix loongarch xml validate - Synchronize upstream patches "Use correct tpm device for all non-x86" (lixianglai@loongson.cn) - Synchronize upstream patches "validate: Drop tpm-tis arch validation" (lixianglai@loongson.cn) +- Add new Dharma CPU model (zhouyanjing@hygon.cn) * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) -- Gitee From 925cb80d87bdcd397544aafe98e2501a0ab5637b Mon Sep 17 00:00:00 2001 From: Jiakun Shuai Date: Fri, 20 Sep 2024 16:10:31 +0800 Subject: [PATCH 6/7] libvirt: phytium: add Phytium S5000C cpu model add Phytium S5000C cpu model. Signed-off-by: Peng Mengguang Signed-off-by: Jiakun Shuai --- libvirt-cpu-map-add-S5000C-cpu-model.patch | 54 ++++++++++++++++++++++ libvirt.spec | 2 + 2 files changed, 56 insertions(+) create mode 100644 libvirt-cpu-map-add-S5000C-cpu-model.patch diff --git a/libvirt-cpu-map-add-S5000C-cpu-model.patch b/libvirt-cpu-map-add-S5000C-cpu-model.patch new file mode 100644 index 0000000..73c051a --- /dev/null +++ b/libvirt-cpu-map-add-S5000C-cpu-model.patch @@ -0,0 +1,54 @@ +From 0b896a38e152b7350d9f685ec898ff9ff0f86ebe Mon Sep 17 00:00:00 2001 +From: Peng Mengguang +Date: Thu, 12 Sep 2024 10:57:23 -0400 +Subject: [PATCH] cpu_map: add S5000C cpu model + + add Phytium S5000C cpu model. + +Signed-off-by: Peng Mengguang +--- + src/cpu_map/arm_Tengyun-S5000C.xml | 6 ++++++ + src/cpu_map/index.xml | 1 + + src/cpu_map/meson.build | 1 + + 3 files changed, 8 insertions(+) + create mode 100644 src/cpu_map/arm_Tengyun-S5000C.xml + +diff --git a/src/cpu_map/arm_Tengyun-S5000C.xml b/src/cpu_map/arm_Tengyun-S5000C.xml +new file mode 100644 +index 0000000000..f8fa593c19 +--- /dev/null ++++ b/src/cpu_map/arm_Tengyun-S5000C.xml +@@ -0,0 +1,6 @@ ++ ++ ++ ++ ++ ++ +diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml +index 150535fac4..3ae9348bc5 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -110,6 +110,7 @@ + + + ++ + + + +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index 42d2105f2a..baeffa3b70 100644 +--- a/src/cpu_map/meson.build ++++ b/src/cpu_map/meson.build +@@ -7,6 +7,7 @@ cpumap_data = [ + 'arm_features.xml', + 'arm_Kunpeng-920.xml', + 'arm_Tengyun-S2500.xml', ++ 'arm_Tengyun-S5000C.xml', + 'arm_ThunderX299xx.xml', + 'arm_vendors.xml', + 'index.xml', +-- +2.39.3 + diff --git a/libvirt.spec b/libvirt.spec index 7cdb470..af7c878 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -328,6 +328,7 @@ Patch1001: libvirt-add-loongarch-edit-xml-validate.patch Patch1004: qemu-validate-Drop-tpm-tis-arch-validation.patch Patch1005: qemu-command-Use-correct-tpm-device-for-all-non-x86.patch Patch1006: libvirt-cpu-Add-new-Dharma-CPU-model.patch +Patch1007: libvirt-cpu-map-add-S5000C-cpu-model.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2213,6 +2214,7 @@ exit 0 - Synchronize upstream patches "Use correct tpm device for all non-x86" (lixianglai@loongson.cn) - Synchronize upstream patches "validate: Drop tpm-tis arch validation" (lixianglai@loongson.cn) - Add new Dharma CPU model (zhouyanjing@hygon.cn) +- Add Phytium S5000C CPU model (shuaijiakun1288@phytium.com.cn) * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) -- Gitee From 0887f3ac9ca486cd1d077127637699f50b2ee426 Mon Sep 17 00:00:00 2001 From: yujiayi <3076710949@qq.com> Date: Sun, 29 Sep 2024 14:46:29 +0800 Subject: [PATCH 7/7] Add sw64arch support for libvirt-8.0.0 Signed-off-by: lufeifei --- ...w64-architecture-support-for-libvirt.patch | 687 ++++++++++++++++++ libvirt.spec | 8 +- 2 files changed, 692 insertions(+), 3 deletions(-) create mode 100644 libvirt-Add-sw64-architecture-support-for-libvirt.patch diff --git a/libvirt-Add-sw64-architecture-support-for-libvirt.patch b/libvirt-Add-sw64-architecture-support-for-libvirt.patch new file mode 100644 index 0000000..7654027 --- /dev/null +++ b/libvirt-Add-sw64-architecture-support-for-libvirt.patch @@ -0,0 +1,687 @@ +From 6053366caf3573323e1436fc7c3e4e13d26fd3c2 Mon Sep 17 00:00:00 2001 +From: Chen Wang +Date: Wed, 25 May 2022 09:42:04 +0800 +Subject: [PATCH] sw_64: Add sw64 architecture support for libvirt-8.0.0 + +Signed-off-by: Chen Wang +--- + docs/schemas/basictypes.rng | 1 + + docs/schemas/domaincommon.rng | 1 + + meson.build | 2 +- + src/cpu/cpu.c | 2 + + src/cpu/cpu_sw64.c | 302 ++++++++++++++++++++++++++++++++++ + src/cpu/cpu_sw64.h | 31 ++++ + src/cpu/meson.build | 1 + + src/cpu_map/index.xml | 5 + + 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 | 12 ++ + src/qemu/qemu_domain.c | 15 +- + src/util/virarch.c | 6 + + src/util/virarch.h | 3 + + src/util/virhostcpu.c | 2 + + src/util/virprocess.c | 2 + + src/util/virsysinfo.c | 3 +- + 18 files changed, 393 insertions(+), 5 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/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng +index ab18b18..e0724fe 100644 +--- a/docs/schemas/basictypes.rng ++++ b/docs/schemas/basictypes.rng +@@ -460,6 +460,7 @@ + sh4eb + sparc + sparc64 ++ sw_64 + unicore32 + x86_64 + xtensa +diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng +index 79c8979..c2bd970 100644 +--- a/docs/schemas/domaincommon.rng ++++ b/docs/schemas/domaincommon.rng +@@ -2613,6 +2613,7 @@ + pcie-pci-bridge + + ioh3420 ++ pcie-root + pcie-root-port + + x3130-upstream +diff --git a/meson.build b/meson.build +index 214a3f0..e76cf4e 100644 +--- a/meson.build ++++ b/meson.build +@@ -1596,7 +1596,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/src/cpu/cpu.c b/src/cpu/cpu.c +index 49527c3..d11bcc9 100644 +--- a/src/cpu/cpu.c ++++ b/src/cpu/cpu.c +@@ -29,6 +29,7 @@ + #include "cpu_ppc64.h" + #include "cpu_s390.h" + #include "cpu_arm.h" ++#include "cpu_sw64.h" + #include "capabilities.h" + #include "virstring.h" + #include "cpu_loongarch.h" +@@ -43,6 +44,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverS390, + &cpuDriverArm, + &cpuDriverLoongArch, ++ &cpuDriverSW64, + }; + + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +new file mode 100644 +index 0000000..199ed60 +--- /dev/null ++++ b/src/cpu/cpu_sw64.c +@@ -0,0 +1,302 @@ ++/* ++ * 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 ++ * . ++ * ++ * Authors: ++ * Lu Feifei ++ */ ++ ++#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; ++ if (virCPUDefCopyModel(updated, host, true) < 0) ++ return -1; ++ ++ 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 %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..211a7cf +--- /dev/null ++++ b/src/cpu/cpu_sw64.h +@@ -0,0 +1,31 @@ ++/* ++ * 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 ++ * . ++ * ++ * Authors: ++ * Lu Feifei ++ */ ++ ++#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 ad2f859..5e99dbd 100644 +--- a/src/cpu/meson.build ++++ b/src/cpu/meson.build +@@ -1,6 +1,7 @@ + cpu_sources = [ + 'cpu.c', + 'cpu_arm.c', ++ 'cpu_sw64.c', + 'cpu_map.c', + 'cpu_ppc64.c', + 'cpu_s390.c', +diff --git a/src/cpu_map/index.xml b/src/cpu_map/index.xml +index 3ae9348..5d1a999 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -113,6 +113,11 @@ + + + ++ ++ ++ ++ ++ + + + +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index baeffa3..3871f09 100644 +--- a/src/cpu_map/meson.build ++++ b/src/cpu_map/meson.build +@@ -79,6 +79,8 @@ cpumap_data = [ + 'x86_vendors.xml', + 'x86_Westmere-IBRS.xml', + 'x86_Westmere.xml', ++ 'sw64_core3.xml', ++ 'sw64_core4.xml', + 'loongarch_vendors.xml', + 'ls_3a5000.xml', + ] +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 75668c6..ca47a7a 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -771,6 +771,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); + } +@@ -784,6 +786,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); + } +@@ -2072,6 +2076,10 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) + * since forever */ + 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; + + if (STRPREFIX(def->os.machine,"loongson7a")) + return true; +@@ -2718,6 +2726,8 @@ static const char *preferredMachines[] = + + "sim", /* VIR_ARCH_XTENSA */ + "sim", /* VIR_ARCH_XTENSAEB */ ++ ++ "core3", /* VIR_ARCH_SW_64 */ + }; + G_STATIC_ASSERT(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); + +@@ -5129,6 +5139,8 @@ virQEMUCapsInitQMPBasicArch(virQEMUCaps *qemuCaps) + case VIR_ARCH_XTENSAEB: + case VIR_ARCH_NONE: + case VIR_ARCH_LAST: ++ case VIR_ARCH_SW_64: ++ + default: + break; + } +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index 7a53b93..f32fdcb 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -3740,6 +3740,10 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, + addPCIRoot = true; + break; + ++ case VIR_ARCH_SW_64: ++ addPCIeRoot = true; ++ break; ++ + case VIR_ARCH_ARMV7B: + case VIR_ARCH_CRIS: + case VIR_ARCH_ITANIUM: +@@ -5099,7 +5103,10 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, + cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_QEMU_XHCI; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NEC_USB_XHCI)) + cont->model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_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 */ + if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_QUSB1 || +@@ -5396,7 +5403,8 @@ qemuDomainDefaultVideoDevice(const virDomainDef *def, + return VIR_DOMAIN_VIDEO_TYPE_VGA; + if (qemuDomainIsARMVirt(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)) +@@ -8705,7 +8713,8 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, + return qemuDomainMachineIsI440FX(machine, arch) || + STREQ(machine, "malta") || + STREQ(machine, "sun4u") || +- STREQ(machine, "g3beige") || ++ STRPREFIX(machine, "core") || ++ STREQ(machine, "g3beige") || + STREQ(machine, "loongson3a") || + STREQ(machine, "loongson7a"); + } +diff --git a/src/util/virarch.c b/src/util/virarch.c +index 9f40a71..ce149a4 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -84,6 +84,8 @@ static const struct virArchData { + + { "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 libvir-list@redhat.com", + 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 7d396f2..2e4f7c9 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; + +@@ -98,6 +100,7 @@ typedef enum { + + #define ARCH_IS_MIPS64(arch) ((arch) == VIR_ARCH_MIPS64 ||\ + (arch) == VIR_ARCH_MIPS64EL) ++#define ARCH_IS_SW64(arch) ((arch) == VIR_ARCH_SW_64) + + #define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) + +diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c +index 137796e..2572229 100644 +--- a/src/util/virhostcpu.c ++++ b/src/util/virhostcpu.c +@@ -555,6 +555,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]"; + + if (!prefix) { + VIR_WARN("%s is not supported by the %s parser", +diff --git a/src/util/virprocess.c b/src/util/virprocess.c +index f3933a2..04095e0 100644 +--- a/src/util/virprocess.c ++++ b/src/util/virprocess.c +@@ -89,6 +89,8 @@ VIR_LOG_INIT("util.process"); + # define __NR_setns 350 + # elif defined(__s390__) + # define __NR_setns 339 ++# elif defined(__sw_64__) ++# define __NR_setns 501 + # endif + # endif + +diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c +index 9577cf1..4cdbf32 100644 +--- a/src/util/virsysinfo.c ++++ b/src/util/virsysinfo.c +@@ -1254,7 +1254,8 @@ virSysinfoRead(void) + #elif !defined(WIN32) && \ + (defined(__x86_64__) || \ + defined(__i386__) || \ +- defined(__amd64__)) ++ defined(__amd64__) || \ ++ defined(__sw_64__)) + return virSysinfoReadDMI(); + #else /* WIN32 || not supported arch */ + /* +-- +2.17.1 + diff --git a/libvirt.spec b/libvirt.spec index af7c878..0cbd0ae 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -7,7 +7,7 @@ %define min_rhel 8 %define min_fedora 33 -%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x loongarch64 +%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x loongarch64 sw_64 %if 0%{?rhel} %if 0%{?rhel} > 8 %define arches_qemu_kvm x86_64 aarch64 s390x loongarch64 @@ -16,7 +16,7 @@ %endif %endif -%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 loongarch64 +%define arches_64bit x86_64 %{power64} aarch64 s390x riscv64 loongarch64 sw_64 %define arches_x86 %{ix86} x86_64 %define arches_systemtap_64bit %{arches_64bit} @@ -24,7 +24,7 @@ %define arches_xen %{arches_x86} aarch64 %define arches_vbox %{arches_x86} %define arches_ceph %{arches_64bit} -%define arches_zfs %{arches_x86} %{power64} %{arm} loongarch64 +%define arches_zfs %{arches_x86} %{power64} %{arm} loongarch64 sw_64 %define arches_numactl %{arches_x86} %{power64} aarch64 s390x loongarch64 %define arches_numad %{arches_x86} %{power64} aarch64 loongarch64 @@ -329,6 +329,7 @@ Patch1004: qemu-validate-Drop-tpm-tis-arch-validation.patch Patch1005: qemu-command-Use-correct-tpm-device-for-all-non-x86.patch Patch1006: libvirt-cpu-Add-new-Dharma-CPU-model.patch Patch1007: libvirt-cpu-map-add-S5000C-cpu-model.patch +Patch1008: libvirt-Add-sw64-architecture-support-for-libvirt.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2215,6 +2216,7 @@ exit 0 - Synchronize upstream patches "validate: Drop tpm-tis arch validation" (lixianglai@loongson.cn) - Add new Dharma CPU model (zhouyanjing@hygon.cn) - Add Phytium S5000C CPU model (shuaijiakun1288@phytium.com.cn) +- Add sw64arch support (lufeifei@wxiat.com) * Wed Nov 6 2024 Jiri Denemark - 8.0.0-23.3.el8 - virStorageBackendLogicalCheckPool: Properly mark empty logical pools as active (RHEL-65771) -- Gitee