diff --git a/Add-loongarch-cpu-support.patch b/Add-loongarch-cpu-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..f7a570c78c8766fdaba921a4b1e9f441df8e0f3f --- /dev/null +++ b/Add-loongarch-cpu-support.patch @@ -0,0 +1,328 @@ +From f4f93d489679307ca40e8cb0bd381f39ad0eff4b Mon Sep 17 00:00:00 2001 +From: xianglai li +Date: Fri, 28 Jul 2023 02:45:55 -0400 +Subject: [PATCH 1/3] Add loongarch cpu support + +Add loongarch cpu support, Define new cpu type 'loongarch64' +and implement it's driver functions. + +Signed-off-by: "Xianglai Li" +Signed-off-by: Xianglai Li +--- + src/conf/schemas/basictypes.rng | 1 + + src/cpu/cpu.c | 2 ++ + src/cpu/cpu_loongarch.c | 58 +++++++++++++++++++++++++++++++++ + src/cpu/cpu_loongarch.h | 25 ++++++++++++++ + src/cpu/meson.build | 1 + + src/qemu/qemu_capabilities.c | 11 ++++--- + src/qemu/qemu_domain.c | 1 + + src/util/virarch.c | 11 ++++--- + src/util/virarch.h | 13 +++++--- + 9 files changed, 108 insertions(+), 15 deletions(-) + create mode 100644 src/cpu/cpu_loongarch.c + create mode 100644 src/cpu/cpu_loongarch.h + +diff --git a/src/conf/schemas/basictypes.rng b/src/conf/schemas/basictypes.rng +index 26eb538077..f117f19d33 100644 +--- a/src/conf/schemas/basictypes.rng ++++ b/src/conf/schemas/basictypes.rng +@@ -444,6 +444,7 @@ + i686 + ia64 + lm32 ++ loongarch64 + m68k + microblaze + microblazeel +diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c +index 4f048d0dad..33701811fb 100644 +--- a/src/cpu/cpu.c ++++ b/src/cpu/cpu.c +@@ -27,6 +27,7 @@ + #include "cpu_ppc64.h" + #include "cpu_s390.h" + #include "cpu_arm.h" ++#include "cpu_loongarch.h" + #include "cpu_riscv64.h" + #include "capabilities.h" + +@@ -41,6 +42,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverS390, + &cpuDriverArm, + &cpuDriverRiscv64, ++ &cpuDriverLoongArch, + }; + + +diff --git a/src/cpu/cpu_loongarch.c b/src/cpu/cpu_loongarch.c +new file mode 100644 +index 0000000000..78d9941320 +--- /dev/null ++++ b/src/cpu/cpu_loongarch.c +@@ -0,0 +1,58 @@ ++/* ++ * cpu_loongarch.c: CPU driver for 64-bit LOONGARCH CPUs ++ * ++ * Copyright (C) 2024 Loongson Technology. ++ * ++ * 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 "virlog.h" ++#include "cpu.h" ++ ++#define VIR_FROM_THIS VIR_FROM_CPU ++ ++VIR_LOG_INIT("cpu.cpu_loongarch"); ++ ++static const virArch archs[] = { VIR_ARCH_LOONGARCH64 }; ++ ++static virCPUCompareResult ++virCPULoongArchCompare(virCPUDef *host G_GNUC_UNUSED, ++ virCPUDef *cpu G_GNUC_UNUSED, ++ bool failIncompatible G_GNUC_UNUSED) ++{ ++ return VIR_CPU_COMPARE_IDENTICAL; ++} ++ ++static int ++virCPULoongArchUpdate(virCPUDef *guest G_GNUC_UNUSED, ++ const virCPUDef *host G_GNUC_UNUSED, ++ bool relative G_GNUC_UNUSED) ++{ ++ return 0; ++} ++ ++struct cpuArchDriver cpuDriverLoongArch = { ++ .name = "LoongArch", ++ .arch = archs, ++ .narch = G_N_ELEMENTS(archs), ++ .compare = virCPULoongArchCompare, ++ .decode = NULL, ++ .encode = NULL, ++ .dataFree = NULL, ++ .baseline = NULL, ++ .update = virCPULoongArchUpdate, ++ .getModels = NULL, ++}; +diff --git a/src/cpu/cpu_loongarch.h b/src/cpu/cpu_loongarch.h +new file mode 100644 +index 0000000000..4bc1c0cd8f +--- /dev/null ++++ b/src/cpu/cpu_loongarch.h +@@ -0,0 +1,25 @@ ++/* ++ * cpu_loongarch.h: CPU driver for 64-bit LOONGARCH CPUs ++ * ++ * Copyright (C) 2024 Loongson Technology. ++ * ++ * This library is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * This library is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with this library. If not, see ++ * . ++ */ ++ ++#pragma once ++ ++#include "cpu.h" ++ ++extern struct cpuArchDriver cpuDriverLoongArch; +diff --git a/src/cpu/meson.build b/src/cpu/meson.build +index 55396903b9..141230e380 100644 +--- a/src/cpu/meson.build ++++ b/src/cpu/meson.build +@@ -1,6 +1,7 @@ + cpu_sources = [ + 'cpu.c', + 'cpu_arm.c', ++ 'cpu_loongarch.c', + 'cpu_map.c', + 'cpu_ppc64.c', + 'cpu_riscv64.c', +diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index d25062b225..509e751274 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -2667,36 +2667,37 @@ static const char *preferredMachines[] = + NULL, /* VIR_ARCH_ITANIUM (doesn't exist in QEMU any more) */ + "lm32-evr", /* VIR_ARCH_LM32 */ + ++ NULL, /* VIR_ARCH_LOONGARCH64 */ + "mcf5208evb", /* VIR_ARCH_M68K */ + "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZE */ + "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZEEL */ + "malta", /* VIR_ARCH_MIPS */ +- "malta", /* VIR_ARCH_MIPSEL */ + ++ "malta", /* VIR_ARCH_MIPSEL */ + "malta", /* VIR_ARCH_MIPS64 */ + "malta", /* VIR_ARCH_MIPS64EL */ + "or1k-sim", /* VIR_ARCH_OR32 */ + NULL, /* VIR_ARCH_PARISC (no QEMU impl) */ +- NULL, /* VIR_ARCH_PARISC64 (no QEMU impl) */ + ++ NULL, /* VIR_ARCH_PARISC64 (no QEMU impl) */ + "g3beige", /* VIR_ARCH_PPC */ + "g3beige", /* VIR_ARCH_PPCLE */ + "pseries", /* VIR_ARCH_PPC64 */ + "pseries", /* VIR_ARCH_PPC64LE */ +- "bamboo", /* VIR_ARCH_PPCEMB */ + ++ "bamboo", /* VIR_ARCH_PPCEMB */ + "virt", /* VIR_ARCH_RISCV32 */ + "virt", /* VIR_ARCH_RISCV64 */ + NULL, /* VIR_ARCH_S390 (no QEMU impl) */ + "s390-ccw-virtio", /* VIR_ARCH_S390X */ +- "shix", /* VIR_ARCH_SH4 */ + ++ "shix", /* VIR_ARCH_SH4 */ + "shix", /* VIR_ARCH_SH4EB */ + "SS-5", /* VIR_ARCH_SPARC */ + "sun4u", /* VIR_ARCH_SPARC64 */ + "puv3", /* VIR_ARCH_UNICORE32 */ +- "pc", /* VIR_ARCH_X86_64 */ + ++ "pc", /* VIR_ARCH_X86_64 */ + "sim", /* VIR_ARCH_XTENSA */ + "sim", /* VIR_ARCH_XTENSAEB */ + }; +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index d54846e734..8374780507 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -4233,6 +4233,7 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, + case VIR_ARCH_CRIS: + case VIR_ARCH_ITANIUM: + case VIR_ARCH_LM32: ++ case VIR_ARCH_LOONGARCH64: + case VIR_ARCH_M68K: + case VIR_ARCH_MICROBLAZE: + case VIR_ARCH_MICROBLAZEEL: +diff --git a/src/util/virarch.c b/src/util/virarch.c +index 01e520de73..8545f993ea 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -51,36 +51,37 @@ static const struct virArchData { + { "ia64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "lm32", 32, VIR_ARCH_BIG_ENDIAN }, + ++ { "loongarch64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "m68k", 32, VIR_ARCH_BIG_ENDIAN }, + { "microblaze", 32, VIR_ARCH_BIG_ENDIAN }, + { "microblazeel", 32, VIR_ARCH_LITTLE_ENDIAN}, + { "mips", 32, VIR_ARCH_BIG_ENDIAN }, +- { "mipsel", 32, VIR_ARCH_LITTLE_ENDIAN }, + ++ { "mipsel", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "mips64", 64, VIR_ARCH_BIG_ENDIAN }, + { "mips64el", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "openrisc", 32, VIR_ARCH_BIG_ENDIAN }, + { "parisc", 32, VIR_ARCH_BIG_ENDIAN }, +- { "parisc64", 64, VIR_ARCH_BIG_ENDIAN }, + ++ { "parisc64", 64, VIR_ARCH_BIG_ENDIAN }, + { "ppc", 32, VIR_ARCH_BIG_ENDIAN }, + { "ppcle", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "ppc64", 64, VIR_ARCH_BIG_ENDIAN }, + { "ppc64le", 64, VIR_ARCH_LITTLE_ENDIAN }, +- { "ppcemb", 32, VIR_ARCH_BIG_ENDIAN }, + ++ { "ppcemb", 32, VIR_ARCH_BIG_ENDIAN }, + { "riscv32", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "riscv64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "s390", 32, VIR_ARCH_BIG_ENDIAN }, + { "s390x", 64, VIR_ARCH_BIG_ENDIAN }, +- { "sh4", 32, VIR_ARCH_LITTLE_ENDIAN }, + ++ { "sh4", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "sh4eb", 64, VIR_ARCH_BIG_ENDIAN }, + { "sparc", 32, VIR_ARCH_BIG_ENDIAN }, + { "sparc64", 64, VIR_ARCH_BIG_ENDIAN }, + { "unicore32", 32, VIR_ARCH_LITTLE_ENDIAN }, +- { "x86_64", 64, VIR_ARCH_LITTLE_ENDIAN }, + ++ { "x86_64", 64, VIR_ARCH_LITTLE_ENDIAN }, + { "xtensa", 32, VIR_ARCH_LITTLE_ENDIAN }, + { "xtensaeb", 32, VIR_ARCH_BIG_ENDIAN }, + }; +diff --git a/src/util/virarch.h b/src/util/virarch.h +index 747f77c48e..2c01a13b8e 100644 +--- a/src/util/virarch.h ++++ b/src/util/virarch.h +@@ -36,36 +36,37 @@ typedef enum { + VIR_ARCH_ITANIUM, /* Itanium 64 LE https://en.wikipedia.org/wiki/Itanium */ + VIR_ARCH_LM32, /* MilkyMist 32 BE https://en.wikipedia.org/wiki/Milkymist */ + ++ VIR_ARCH_LOONGARCH64, /* LoongArch 64 LE https://en.wikipedia.org/wiki/Loongson#LoongArch */ + VIR_ARCH_M68K, /* m68k 32 BE https://en.wikipedia.org/wiki/Motorola_68000_family */ + VIR_ARCH_MICROBLAZE, /* Microblaze 32 BE https://en.wikipedia.org/wiki/MicroBlaze */ + VIR_ARCH_MICROBLAZEEL, /* Microblaze 32 LE https://en.wikipedia.org/wiki/MicroBlaze */ + VIR_ARCH_MIPS, /* MIPS 32 BE https://en.wikipedia.org/wiki/MIPS_architecture */ +- VIR_ARCH_MIPSEL, /* MIPS 32 LE https://en.wikipedia.org/wiki/MIPS_architecture */ + ++ VIR_ARCH_MIPSEL, /* MIPS 32 LE https://en.wikipedia.org/wiki/MIPS_architecture */ + 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_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 */ + ++ VIR_ARCH_PARISC64, /* PA-Risc 64 BE https://en.wikipedia.org/wiki/PA-RISC */ + VIR_ARCH_PPC, /* PowerPC 32 BE https://en.wikipedia.org/wiki/PowerPC */ + VIR_ARCH_PPCLE, /* PowerPC 32 LE https://en.wikipedia.org/wiki/PowerPC */ + VIR_ARCH_PPC64, /* PowerPC 64 BE https://en.wikipedia.org/wiki/PowerPC */ + VIR_ARCH_PPC64LE, /* PowerPC 64 LE https://en.wikipedia.org/wiki/PowerPC */ +- VIR_ARCH_PPCEMB, /* PowerPC 32 BE https://en.wikipedia.org/wiki/PowerPC */ + ++ VIR_ARCH_PPCEMB, /* PowerPC 32 BE https://en.wikipedia.org/wiki/PowerPC */ + VIR_ARCH_RISCV32, /* RISC-V 32 LE https://en.wikipedia.org/wiki/RISC-V */ + VIR_ARCH_RISCV64, /* RISC-V 64 LE https://en.wikipedia.org/wiki/RISC-V */ + VIR_ARCH_S390, /* S390 32 BE https://en.wikipedia.org/wiki/S390 */ + VIR_ARCH_S390X, /* S390 64 BE https://en.wikipedia.org/wiki/S390x */ +- VIR_ARCH_SH4, /* SuperH4 32 LE https://en.wikipedia.org/wiki/SuperH */ + ++ VIR_ARCH_SH4, /* SuperH4 32 LE https://en.wikipedia.org/wiki/SuperH */ + VIR_ARCH_SH4EB, /* SuperH4 32 BE https://en.wikipedia.org/wiki/SuperH */ + VIR_ARCH_SPARC, /* Sparc 32 BE https://en.wikipedia.org/wiki/Sparc */ + VIR_ARCH_SPARC64, /* Sparc 64 BE https://en.wikipedia.org/wiki/Sparc */ + VIR_ARCH_UNICORE32, /* UniCore 32 LE https://en.wikipedia.org/wiki/Unicore */ +- VIR_ARCH_X86_64, /* x86 64 LE https://en.wikipedia.org/wiki/X86 */ + ++ VIR_ARCH_X86_64, /* x86 64 LE https://en.wikipedia.org/wiki/X86 */ + 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 */ + +@@ -106,6 +107,8 @@ typedef enum { + #define ARCH_IS_SH4(arch) ((arch) == VIR_ARCH_SH4 ||\ + (arch) == VIR_ARCH_SH4EB) + ++#define ARCH_IS_LOONGARCH(arch) ((arch) == VIR_ARCH_LOONGARCH64) ++ + typedef enum { + VIR_ARCH_LITTLE_ENDIAN, + VIR_ARCH_BIG_ENDIAN, +-- +2.39.1 + diff --git a/Implement-the-method-of-getting-host-info-for-loonga.patch b/Implement-the-method-of-getting-host-info-for-loonga.patch new file mode 100644 index 0000000000000000000000000000000000000000..cfb726a2e96d5953fc2f13c1b0b1867df000c553 --- /dev/null +++ b/Implement-the-method-of-getting-host-info-for-loonga.patch @@ -0,0 +1,77 @@ +From 918a7e7601cf7fc5d8619ff7214e7d43cdee2e08 Mon Sep 17 00:00:00 2001 +From: Xianglai Li +Date: Fri, 28 Jul 2023 03:27:41 -0400 +Subject: [PATCH 3/3] Implement the method of getting host info for loongarch + +Implement method for loongarch to get host info, such as +cpu frequency, system info, etc. + +Signed-off-by: Xianglai Li +--- + src/util/virarch.c | 2 ++ + src/util/virhostcpu.c | 7 +++++-- + src/util/virsysinfo.c | 3 ++- + 3 files changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/util/virarch.c b/src/util/virarch.c +index 8545f993ea..a94318da0d 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -223,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/virhostcpu.c b/src/util/virhostcpu.c +index a3781ca870..01de69c0d1 100644 +--- a/src/util/virhostcpu.c ++++ b/src/util/virhostcpu.c +@@ -575,6 +575,8 @@ virHostCPUParseFrequency(FILE *cpuinfo, + prefix = "clock"; + else if (ARCH_IS_S390(arch)) + prefix = "cpu MHz dynamic"; ++ else if (ARCH_IS_LOONGARCH(arch)) ++ prefix = "CPU MHz"; + + if (!prefix) { + VIR_WARN("%s is not supported by the %s parser", +@@ -601,7 +603,7 @@ virHostCPUParsePhysAddrSize(FILE *cpuinfo, unsigned int *addrsz) + char *str; + char *endptr; + +- if (!(str = STRSKIP(line, "address sizes"))) ++ if (!(str = STRCASESKIP(line, "address sizes"))) + continue; + + /* Skip the colon. */ +@@ -1672,7 +1674,8 @@ virHostCPUGetPhysAddrSize(const virArch hostArch, + { + g_autoptr(FILE) cpuinfo = NULL; + +- if (!(ARCH_IS_X86(hostArch) || ARCH_IS_SH4(hostArch))) { ++ if (!(ARCH_IS_X86(hostArch) || ARCH_IS_SH4(hostArch) || ++ ARCH_IS_LOONGARCH(hostArch))) { + /* Ensure size is set to 0 as physical address size is unknown */ + *size = 0; + return 0; +diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c +index 36a861c53f..4a03fc3246 100644 +--- a/src/util/virsysinfo.c ++++ b/src/util/virsysinfo.c +@@ -1248,7 +1248,8 @@ virSysinfoRead(void) + #elif !defined(WIN32) && \ + (defined(__x86_64__) || \ + defined(__i386__) || \ +- defined(__amd64__)) ++ defined(__amd64__) || \ ++ defined(__loongarch__)) + return virSysinfoReadDMI(); + #else /* WIN32 || not supported arch */ + /* +-- +2.39.1 + diff --git a/Support-for-loongarch64-in-the-QEMU-driver.patch b/Support-for-loongarch64-in-the-QEMU-driver.patch new file mode 100644 index 0000000000000000000000000000000000000000..949807e9cd44cde07432e9b454fa26cff204f920 --- /dev/null +++ b/Support-for-loongarch64-in-the-QEMU-driver.patch @@ -0,0 +1,208 @@ +From aeaef8019c4c1f16af1ebcb60c73c06f4f691261 Mon Sep 17 00:00:00 2001 +From: xianglai li +Date: Fri, 28 Jul 2023 03:18:44 -0400 +Subject: [PATCH 2/3] Support for loongarch64 in the QEMU driver + +Implement support for loongarch64 in the QEMU driver. + +Signed-off-by: "Xianglai Li" +Signed-off-by: Xianglai Li +--- + src/qemu/qemu_capabilities.c | 10 +++++---- + src/qemu/qemu_command.c | 3 ++- + src/qemu/qemu_domain.c | 42 ++++++++++++++++++++++++++++++++---- + src/qemu/qemu_domain.h | 1 + + src/qemu/qemu_validate.c | 1 + + 5 files changed, 48 insertions(+), 9 deletions(-) + +diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index 509e751274..79414becfd 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -1139,7 +1139,8 @@ virQEMUCapsInitGuestFromBinary(virCaps *caps, + NULL, NULL, 0, NULL); + } + +- if ((ARCH_IS_X86(guestarch) || guestarch == VIR_ARCH_AARCH64)) ++ if (ARCH_IS_X86(guestarch) || guestarch == VIR_ARCH_AARCH64 || ++ ARCH_IS_LOONGARCH(guestarch)) + virCapabilitiesAddGuestFeatureWithToggle(guest, VIR_CAPS_GUEST_FEATURE_TYPE_ACPI, + true, true); + +@@ -2075,9 +2076,10 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) + if (ARCH_IS_S390(def->os.arch)) + return true; + +- /* If the virt machine, both on ARM and RISC-V, supports PCI, ++ /* If the virt machine, both on ARM and RISC-V and LOONGARCH64, supports PCI, + * then it also supports multibus */ + if (qemuDomainIsARMVirt(def) || ++ qemuDomainIsLoongArchVirt(def) || + qemuDomainIsRISCVVirt(def)) { + return true; + } +@@ -2667,7 +2669,7 @@ static const char *preferredMachines[] = + NULL, /* VIR_ARCH_ITANIUM (doesn't exist in QEMU any more) */ + "lm32-evr", /* VIR_ARCH_LM32 */ + +- NULL, /* VIR_ARCH_LOONGARCH64 */ ++ "virt", /* VIR_ARCH_LOONGARCH64 */ + "mcf5208evb", /* VIR_ARCH_M68K */ + "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZE */ + "petalogix-s3adsp1800", /* VIR_ARCH_MICROBLAZEEL */ +@@ -3743,7 +3745,7 @@ virQEMUCapsInitCPUModel(virQEMUCaps *qemuCaps, + } else if (ARCH_IS_X86(qemuCaps->arch)) { + ret = virQEMUCapsInitCPUModelX86(qemuCaps, type, modelInfo, + cpu, migratable); +- } else if (ARCH_IS_ARM(qemuCaps->arch)) { ++ } else if (ARCH_IS_ARM(qemuCaps->arch) || ARCH_IS_LOONGARCH(qemuCaps->arch)) { + ret = 2; + } + +diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c +index 6403d5692e..609eb6772e 100644 +--- a/src/qemu/qemu_command.c ++++ b/src/qemu/qemu_command.c +@@ -9209,7 +9209,8 @@ qemuChrIsPlatformDevice(const virDomainDef *def, + } + } + +- if (ARCH_IS_RISCV(def->os.arch)) { ++ if (ARCH_IS_RISCV(def->os.arch) || ++ ARCH_IS_LOONGARCH(def->os.arch)) { + + /* 16550a (used by riscv/virt guests) is a platform device */ + if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index 8374780507..020cfc8bff 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -4229,11 +4229,14 @@ qemuDomainDefAddDefaultDevices(virQEMUDriver *driver, + addPCIRoot = true; + break; + ++ case VIR_ARCH_LOONGARCH64: ++ addPCIeRoot = true; ++ break; ++ + case VIR_ARCH_ARMV7B: + case VIR_ARCH_CRIS: + case VIR_ARCH_ITANIUM: + case VIR_ARCH_LM32: +- case VIR_ARCH_LOONGARCH64: + case VIR_ARCH_M68K: + case VIR_ARCH_MICROBLAZE: + case VIR_ARCH_MICROBLAZEEL: +@@ -5400,7 +5403,8 @@ static int + qemuDomainDefaultNetModel(const virDomainDef *def, + virQEMUCaps *qemuCaps) + { +- if (ARCH_IS_S390(def->os.arch)) ++ if (ARCH_IS_S390(def->os.arch) || ++ qemuDomainIsLoongArchVirt(def)) + return VIR_DOMAIN_NET_MODEL_VIRTIO; + + if (def->os.arch == VIR_ARCH_ARMV6L || +@@ -5639,6 +5643,9 @@ 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; + } + } + /* forbid usb model 'qusb1' and 'qusb2' in this kind of hyperviosr */ +@@ -5738,7 +5745,9 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, + chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA; + } else if (qemuDomainIsPSeries(def)) { + chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO; +- } else if (qemuDomainIsARMVirt(def) || qemuDomainIsRISCVVirt(def)) { ++ } else if (qemuDomainIsARMVirt(def) || ++ qemuDomainIsLoongArchVirt(def) || ++ qemuDomainIsRISCVVirt(def)) { + chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM; + } else if (ARCH_IS_S390(def->os.arch)) { + chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP; +@@ -5764,7 +5773,8 @@ qemuDomainChrDefPostParse(virDomainChrDef *chr, + case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM: + if (qemuDomainIsARMVirt(def)) { + chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011; +- } else if (qemuDomainIsRISCVVirt(def)) { ++ } else if (qemuDomainIsLoongArchVirt(def) || ++ qemuDomainIsRISCVVirt(def)) { + chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A; + } + break; +@@ -5936,6 +5946,7 @@ qemuDomainDefaultVideoDevice(const virDomainDef *def, + if (ARCH_IS_PPC64(def->os.arch)) + return VIR_DOMAIN_VIDEO_TYPE_VGA; + if (qemuDomainIsARMVirt(def) || ++ qemuDomainIsLoongArchVirt(def) || + qemuDomainIsRISCVVirt(def) || + ARCH_IS_S390(def->os.arch)) { + return VIR_DOMAIN_VIDEO_TYPE_VIRTIO; +@@ -8930,6 +8941,22 @@ qemuDomainMachineIsPSeries(const char *machine, + } + + ++static bool ++qemuDomainMachineIsLoongArchVirt(const char *machine, ++ const virArch arch) ++{ ++ if (!ARCH_IS_LOONGARCH(arch)) ++ return false; ++ ++ if (STREQ(machine, "virt") || ++ STRPREFIX(machine, "virt-")) { ++ return true; ++ } ++ ++ return false; ++} ++ ++ + static bool + qemuDomainMachineIsMipsMalta(const char *machine, + const virArch arch) +@@ -9023,6 +9050,13 @@ qemuDomainIsMipsMalta(const virDomainDef *def) + } + + ++bool ++qemuDomainIsLoongArchVirt(const virDomainDef *def) ++{ ++ return qemuDomainMachineIsLoongArchVirt(def->os.machine, def->os.arch); ++} ++ ++ + bool + qemuDomainHasPCIRoot(const virDomainDef *def) + { +diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h +index 7074023229..c90a361e8a 100644 +--- a/src/qemu/qemu_domain.h ++++ b/src/qemu/qemu_domain.h +@@ -829,6 +829,7 @@ bool qemuDomainIsQ35(const virDomainDef *def); + bool qemuDomainIsI440FX(const virDomainDef *def); + bool qemuDomainIsS390CCW(const virDomainDef *def); + bool qemuDomainIsARMVirt(const virDomainDef *def); ++bool qemuDomainIsLoongArchVirt(const virDomainDef *def); + bool qemuDomainIsRISCVVirt(const virDomainDef *def); + bool qemuDomainIsPSeries(const virDomainDef *def); + bool qemuDomainIsMipsMalta(const virDomainDef *def); +diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c +index 18c5b60a35..a51cb6017d 100644 +--- a/src/qemu/qemu_validate.c ++++ b/src/qemu/qemu_validate.c +@@ -2064,6 +2064,7 @@ qemuValidateDomainChrDef(const virDomainChrDef *dev, + isCompatible = false; + } + if (dev->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A && ++ !qemuDomainIsLoongArchVirt(def) && + !qemuDomainIsRISCVVirt(def)) { + isCompatible = false; + } +-- +2.39.1 + diff --git a/libvirt.spec b/libvirt.spec index fef065b936457907899cc00fb48601dfdf3bf0af..069e85c69eff08b386ae1c319a2e21cfba8c6a24 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -6,20 +6,20 @@ %define min_rhel 8 %define min_fedora 37 -%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x riscv64 +%define arches_qemu_kvm %{ix86} x86_64 %{power64} %{arm} aarch64 s390x riscv64 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} -%define arches_dmidecode %{arches_x86} +%define arches_dmidecode %{arches_x86 loongarch64} %define arches_xen %{arches_x86} aarch64 %if 0%{?fedora} %define arches_xen x86_64 aarch64 @@ -27,8 +27,8 @@ %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_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} @@ -262,7 +262,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 9.10.0 -Release: 9 +Release: 12 License: LGPLv2+ URL: https://libvirt.org/ @@ -314,7 +314,11 @@ Patch0040: Fix-off-by-one-error-in-udevListInterfacesByStatus.patch Patch0041: remote-check-for-negative-array-lengths-before-alloc.patch Patch0042: hotpatch-if-hotpatch_path-not-in-qemu.conf-the-hotpa.patch Patch0043: remote_driver-Restore-special-behavior-of-remoteDoma.patch -Patch0044: rpc-ensure-temporary-GSource-is-removed-from-client-.patch +Patch0044: remote_driver-fix-the-UAF-causing-UnicodeDecodeError.patch +Patch0045: Add-loongarch-cpu-support.patch +Patch0046: Support-for-loongarch64-in-the-QEMU-driver.patch +Patch0047: Implement-the-method-of-getting-host-info-for-loonga.patch +Patch0048: rpc-ensure-temporary-GSource-is-removed-from-client-.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -2606,9 +2610,18 @@ exit 0 %endif %changelog -* Fri May 24 2024 jiangjiacheng - 9.10.0-9 +* Fri May 31 2024 LiXiangLai 9.10.0-12 +- spec: add numa support for loongarch64 + +* Fri May 24 2024 jiangjiacheng - 9.10.0-11 - rpc: ensure temporary GSource is removed from client event loop +* Mon May 20 2024 LiXiangLai 9.10.0-10 +- spec: Add loongarch support for libvirt + +* SAT May 18 2024 QingXiu 9.10.0-9 +- spec: remote_driver: fix the UAF causing UnicodeDecodeError + * Mon May 06 2024 laokz - 9.10.0-8 - spec: enable libvirt-daemon-kvm sub-package for riscv64 diff --git a/remote_driver-fix-the-UAF-causing-UnicodeDecodeError.patch b/remote_driver-fix-the-UAF-causing-UnicodeDecodeError.patch new file mode 100644 index 0000000000000000000000000000000000000000..af8043a12125684df6b1298d9510e7e05ddce4f8 --- /dev/null +++ b/remote_driver-fix-the-UAF-causing-UnicodeDecodeError.patch @@ -0,0 +1,27 @@ +From 10ec4fa6e9f1e6c72f2d7a1025d1e200ce94f8b0 Mon Sep 17 00:00:00 2001 +From: caozhongwang +Date: Sat, 18 May 2024 17:05:07 +0800 +Subject: [PATCH] remote_driver: fix the UAF causing "UnicodeDecodeError: + 'utf-8' codec can't decode byte XXX". + +Signed-off-by:xiuqing1 +--- + src/remote/remote_driver.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c +index a1a0edd7a2..9350e811d6 100644 +--- a/src/remote/remote_driver.c ++++ b/src/remote/remote_driver.c +@@ -1408,7 +1408,7 @@ remoteConnectGetType(virConnectPtr conn) + return NULL; + + /* Stash. */ +- return priv->type = ret.type; ++ return priv->type = g_steal_pointer(&ret.type); + } + + static int remoteConnectIsSecure(virConnectPtr conn) +-- +2.27.0 +