diff --git a/0001-sw_64-Add-sw64-architecture-support-for-libvirt-8.0..patch b/0001-sw_64-Add-sw64-architecture-support-for-libvirt-8.0..patch new file mode 100644 index 0000000000000000000000000000000000000000..5e1ab6bc67613b833a2e2ea07d18ee1e947f9981 --- /dev/null +++ b/0001-sw_64-Add-sw64-architecture-support-for-libvirt-8.0..patch @@ -0,0 +1,383 @@ +From 25323fd782137a270603596dff17d31e844d1b95 Mon Sep 17 00:00:00 2001 +From: Chen Wang +Date: Wed, 25 May 2022 09:42:04 +0800 +Subject: [PATCH 1/9] sw_64: Add sw64 architecture support for libvirt-8.0.0 + +Modify the build file.Create sw_64 environment. + +Signed-off-by: Chen Wang +--- + meson.build | 2 +- + src/conf/domain_conf.c | 2 +- + src/cpu/cpu.c | 2 + + src/cpu/cpu_sw64.c | 78 ++++++++++++++++++++++++++++++++++++ + src/cpu/cpu_sw64.h | 32 +++++++++++++++ + src/cpu/meson.build | 1 + + src/qemu/qemu_capabilities.c | 12 ++++++ + src/qemu/qemu_domain.c | 5 +++ + src/util/virarch.c | 6 +++ + src/util/virarch.h | 4 ++ + src/util/virhostcpu.c | 2 + + src/util/virprocess.c | 2 + + src/util/virsysinfo.c | 3 +- + 13 files changed, 148 insertions(+), 3 deletions(-) + create mode 100644 src/cpu/cpu_sw64.c + create mode 100644 src/cpu/cpu_sw64.h + +diff --git a/meson.build b/meson.build +index 214a3f05eb..e76cf4e5b0 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/conf/domain_conf.c b/src/conf/domain_conf.c +index 5691b8d2d5..a55b321285 100644 +--- a/src/conf/domain_conf.c ++++ b/src/conf/domain_conf.c +@@ -14123,6 +14123,7 @@ virDomainVideoDefaultRAM(const virDomainDef *def, + /* Original Xen PVFB hardcoded to 4 MB */ + return 4 * 1024; + ++ case VIR_DOMAIN_VIDEO_TYPE_VIRTIO: + case VIR_DOMAIN_VIDEO_TYPE_QXL: + /* QEMU use 64M as the minimal video memory for qxl device */ + return 64 * 1024; +@@ -14130,7 +14131,6 @@ virDomainVideoDefaultRAM(const virDomainDef *def, + case VIR_DOMAIN_VIDEO_TYPE_DEFAULT: + case VIR_DOMAIN_VIDEO_TYPE_VBOX: + case VIR_DOMAIN_VIDEO_TYPE_PARALLELS: +- case VIR_DOMAIN_VIDEO_TYPE_VIRTIO: + case VIR_DOMAIN_VIDEO_TYPE_GOP: + case VIR_DOMAIN_VIDEO_TYPE_NONE: + case VIR_DOMAIN_VIDEO_TYPE_RAMFB: +diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c +index 285c7eee44..4e1c433586 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" + +@@ -42,6 +43,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverPPC64, + &cpuDriverS390, + &cpuDriverArm, ++ &cpuDriverSW64 + }; + + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +new file mode 100644 +index 0000000000..ebf0171450 +--- /dev/null ++++ b/src/cpu/cpu_sw64.c +@@ -0,0 +1,78 @@ ++/* ++ * cpu_sw64.c: CPU driver for arm CPUs ++ * ++ * Copyright (C) 2013 Red Hat, Inc. ++ * Copyright (C) Canonical Ltd. 2012 ++ * ++ * 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: ++ * Chuck Short ++ */ ++ ++#include ++ ++#include "viralloc.h" ++#include "cpu.h" ++#include "cpu_sw64.h" ++#include "virstring.h" ++ ++#define VIR_FROM_THIS VIR_FROM_CPU ++#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array))) ++ ++static const virArch archs[] = { ++ VIR_ARCH_SW_64 ++}; ++ ++static int ++virCPUsw64GetHost(virCPUDef *cpu ATTRIBUTE_UNUSED, ++ virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) ++{ ++ return 0; ++} ++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 ATTRIBUTE_UNUSED, ++ bool relative ATTRIBUTE_UNUSED) ++{ ++ /* ++ * update copy from ppc64 ++ */ ++ ++ guest->mode = VIR_CPU_MODE_CUSTOM; ++ guest->match = VIR_CPU_MATCH_EXACT; ++ ++ return 0; ++} ++ ++struct cpuArchDriver cpuDriverSW64 = { ++ .name = "sw_64", ++ .arch = archs, ++ .narch = ARRAY_CARDINALITY(archs), ++ .getHost = virCPUsw64GetHost, ++ .compare = virCPUsw64Compare, ++ .decode = NULL, ++ .encode = NULL, ++ .baseline = NULL, ++ .update = virCPUsw64Update, ++}; +diff --git a/src/cpu/cpu_sw64.h b/src/cpu/cpu_sw64.h +new file mode 100644 +index 0000000000..25bde30004 +--- /dev/null ++++ b/src/cpu/cpu_sw64.h +@@ -0,0 +1,32 @@ ++/* ++ * cpu_sw64.h: CPU driver for arm CPUs ++ * ++ * Copyright (C) Canonical Ltd. 2012 ++ * ++ * 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: ++ * Chuck Short ++ */ ++ ++#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 b4ad95e46d..cedf87ebe4 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/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index 5f1eb5014c..abd9629693 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -767,6 +767,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); + } +@@ -780,6 +782,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); + } +@@ -2067,6 +2071,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def) + if (ARCH_IS_X86(def->os.arch)) + return true; + ++ /* sw_64 support PCI-multibus on all machine types ++ * since forever */ ++ if (ARCH_IS_SW64(def->os.arch)) ++ return true; ++ + /* PPC supports multibus on all machine types which have pci since qemu-2.0.0 */ + if (def->os.arch == VIR_ARCH_PPC || + ARCH_IS_PPC64(def->os.arch)) { +@@ -2706,6 +2715,7 @@ static const char *preferredMachines[] = + "puv3", /* VIR_ARCH_UNICORE32 */ + "pc", /* VIR_ARCH_X86_64 */ + ++ "core3", /* VIR_ARCH_SW_64 */ + "sim", /* VIR_ARCH_XTENSA */ + "sim", /* VIR_ARCH_XTENSAEB */ + }; +@@ -5118,6 +5128,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 a8401bac30..bb9853b65c 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -3711,6 +3711,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: +@@ -8664,6 +8668,7 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, + return qemuDomainMachineIsI440FX(machine, arch) || + STREQ(machine, "malta") || + STREQ(machine, "sun4u") || ++ STREQ(machine, "core3") || + STREQ(machine, "g3beige"); + } + +diff --git a/src/util/virarch.c b/src/util/virarch.c +index 2134dd6a9d..c0be0ac905 100644 +--- a/src/util/virarch.c ++++ b/src/util/virarch.c +@@ -83,6 +83,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); +@@ -196,6 +198,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); +@@ -220,6 +224,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 { +diff --git a/src/util/virarch.h b/src/util/virarch.h +index 528f84f8a5..7668fb6a89 100644 +--- a/src/util/virarch.h ++++ b/src/util/virarch.h +@@ -68,6 +68,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, /* SW64 64 LE XHB */ + + VIR_ARCH_LAST, + } virArch; +@@ -98,6 +100,8 @@ 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) ++ + typedef enum { + VIR_ARCH_LITTLE_ENDIAN, + VIR_ARCH_BIG_ENDIAN, +diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c +index a07c00a0e9..93aba91417 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 85d8c8e747..30581c6b9c 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 af9e03c5ac..593dcfe158 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/0002-sw_64-fix-coding-style-problems.patch b/0002-sw_64-fix-coding-style-problems.patch new file mode 100644 index 0000000000000000000000000000000000000000..cbd715bab595303e9090f6f6650c042e66401495 --- /dev/null +++ b/0002-sw_64-fix-coding-style-problems.patch @@ -0,0 +1,85 @@ +From 0e60f45ba8ece4426817dcfe51752cf7be42b191 Mon Sep 17 00:00:00 2001 +From: Chen Wang +Date: Wed, 25 May 2022 10:14:41 +0800 +Subject: [PATCH 2/9] sw_64: fix coding style problems + +Signed-off-by: Chen Wang +--- + src/cpu/cpu.c | 2 +- + src/cpu/cpu_sw64.c | 18 ++++++------------ + src/util/virarch.h | 2 +- + 3 files changed, 8 insertions(+), 14 deletions(-) + +diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c +index 4e1c433586..85cab20939 100644 +--- a/src/cpu/cpu.c ++++ b/src/cpu/cpu.c +@@ -43,7 +43,7 @@ static struct cpuArchDriver *drivers[] = { + &cpuDriverPPC64, + &cpuDriverS390, + &cpuDriverArm, +- &cpuDriverSW64 ++ &cpuDriverSW64, + }; + + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +index ebf0171450..37ce79a92f 100644 +--- a/src/cpu/cpu_sw64.c ++++ b/src/cpu/cpu_sw64.c +@@ -32,33 +32,27 @@ + #define VIR_FROM_THIS VIR_FROM_CPU + #define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array))) + +-static const virArch archs[] = { +- VIR_ARCH_SW_64 +-}; ++static const virArch archs[] = { VIR_ARCH_SW_64 }; + + static int + virCPUsw64GetHost(virCPUDef *cpu ATTRIBUTE_UNUSED, +- virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) ++ virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) + { + return 0; + } + static virCPUCompareResult + virCPUsw64Compare(virCPUDef *host ATTRIBUTE_UNUSED, +- virCPUDef *cpu ATTRIBUTE_UNUSED, +- bool failMessages ATTRIBUTE_UNUSED) ++ virCPUDef *cpu ATTRIBUTE_UNUSED, ++ bool failMessages ATTRIBUTE_UNUSED) + { + return VIR_CPU_COMPARE_IDENTICAL; + } + + static int + virCPUsw64Update(virCPUDef *guest, +- const virCPUDef *host ATTRIBUTE_UNUSED, +- bool relative ATTRIBUTE_UNUSED) ++ const virCPUDef *host ATTRIBUTE_UNUSED, ++ bool relative ATTRIBUTE_UNUSED) + { +- /* +- * update copy from ppc64 +- */ +- + guest->mode = VIR_CPU_MODE_CUSTOM; + guest->match = VIR_CPU_MATCH_EXACT; + +diff --git a/src/util/virarch.h b/src/util/virarch.h +index 7668fb6a89..252622034b 100644 +--- a/src/util/virarch.h ++++ b/src/util/virarch.h +@@ -69,7 +69,7 @@ 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, /* SW64 64 LE XHB */ ++ VIR_ARCH_SW_64, /* SW_64 64 LE XHB */ + + VIR_ARCH_LAST, + } virArch; +-- +2.17.1 + diff --git a/0003-sw_64-fix-coding-style-problems.patch b/0003-sw_64-fix-coding-style-problems.patch new file mode 100644 index 0000000000000000000000000000000000000000..7b53115e35097050567aca53fb85d80fe58cafeb --- /dev/null +++ b/0003-sw_64-fix-coding-style-problems.patch @@ -0,0 +1,100 @@ +From e031886176f1de539273ad60e1c43c677033966f Mon Sep 17 00:00:00 2001 +From: Chen Wang +Date: Wed, 1 Jun 2022 15:51:32 +0800 +Subject: [PATCH 3/9] sw_64: fix coding style problems + +Signed-off-by: Chen Wang +--- + src/cpu/cpu_sw64.c | 8 ++++---- + src/cpu/cpu_sw64.h | 6 +++--- + src/qemu/qemu_capabilities.c | 3 ++- + src/util/virhostcpu.c | 2 +- + 4 files changed, 10 insertions(+), 9 deletions(-) + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +index 37ce79a92f..bc0a383252 100644 +--- a/src/cpu/cpu_sw64.c ++++ b/src/cpu/cpu_sw64.c +@@ -1,8 +1,7 @@ + /* +- * cpu_sw64.c: CPU driver for arm CPUs ++ * cpu_sw64.c: CPU driver for sw64 CPUs + * +- * Copyright (C) 2013 Red Hat, Inc. +- * Copyright (C) Canonical Ltd. 2012 ++ * 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 +@@ -19,7 +18,7 @@ + * . + * + * Authors: +- * Chuck Short ++ * Lu Feifei + */ + + #include +@@ -40,6 +39,7 @@ virCPUsw64GetHost(virCPUDef *cpu ATTRIBUTE_UNUSED, + { + return 0; + } ++ + static virCPUCompareResult + virCPUsw64Compare(virCPUDef *host ATTRIBUTE_UNUSED, + virCPUDef *cpu ATTRIBUTE_UNUSED, +diff --git a/src/cpu/cpu_sw64.h b/src/cpu/cpu_sw64.h +index 25bde30004..4a03f0affa 100644 +--- a/src/cpu/cpu_sw64.h ++++ b/src/cpu/cpu_sw64.h +@@ -1,7 +1,7 @@ + /* +- * cpu_sw64.h: CPU driver for arm CPUs ++ * cpu_sw64.h: CPU driver for sw64 CPUs + * +- * Copyright (C) Canonical Ltd. 2012 ++ * 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 +@@ -18,7 +18,7 @@ + * . + * + * Authors: +- * Chuck Short ++ * Lu Feifei + */ + + #ifndef __VIR_CPU_SW64_H__ +diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c +index abd9629693..9a6fda7f42 100644 +--- a/src/qemu/qemu_capabilities.c ++++ b/src/qemu/qemu_capabilities.c +@@ -2715,9 +2715,10 @@ static const char *preferredMachines[] = + "puv3", /* VIR_ARCH_UNICORE32 */ + "pc", /* VIR_ARCH_X86_64 */ + +- "core3", /* VIR_ARCH_SW_64 */ + "sim", /* VIR_ARCH_XTENSA */ + "sim", /* VIR_ARCH_XTENSAEB */ ++ ++ "core3", /* VIR_ARCH_SW_64 */ + }; + G_STATIC_ASSERT(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST); + +diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c +index 93aba91417..c838cb9086 100644 +--- a/src/util/virhostcpu.c ++++ b/src/util/virhostcpu.c +@@ -556,7 +556,7 @@ virHostCPUParseFrequency(FILE *cpuinfo, + else if (ARCH_IS_S390(arch)) + prefix = "cpu MHz dynamic"; + else if (ARCH_IS_SW64(arch)) +- prefix = "cpu frequency [MHZ]"; ++ prefix = "cpu frequency [MHz]"; + + if (!prefix) { + VIR_WARN("%s is not supported by the %s parser", +-- +2.17.1 + diff --git a/0004-sw_64-fix-virsh-edit-error-caused-by-schema.patch b/0004-sw_64-fix-virsh-edit-error-caused-by-schema.patch new file mode 100644 index 0000000000000000000000000000000000000000..20b52f4fe9f2aaf490c0aec7d85d40ff2cf3ff04 --- /dev/null +++ b/0004-sw_64-fix-virsh-edit-error-caused-by-schema.patch @@ -0,0 +1,38 @@ +From b2ec733e6af23f08987f7beb1c8a66beb3b7eb9d Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Mon, 19 Jun 2023 14:50:38 +0800 +Subject: [PATCH 4/9] sw_64: fix virsh edit error caused by schema + +Signed-off-by: Zhang Wenxiang +--- + docs/schemas/basictypes.rng | 1 + + docs/schemas/domaincommon.rng | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng +index a221ff6295..256b761210 100644 +--- a/docs/schemas/basictypes.rng ++++ b/docs/schemas/basictypes.rng +@@ -459,6 +459,7 @@ + sh4eb + sparc + sparc64 ++ sw_64 + unicore32 + x86_64 + xtensa +diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng +index 7fa5c2b8b5..2c6577a257 100644 +--- a/docs/schemas/domaincommon.rng ++++ b/docs/schemas/domaincommon.rng +@@ -2606,6 +2606,7 @@ + pcie-pci-bridge + + ioh3420 ++ pcie-root + pcie-root-port + + x3130-upstream +-- +2.17.1 + diff --git a/0005-sw_64-add-support-for-custom-mode.patch b/0005-sw_64-add-support-for-custom-mode.patch new file mode 100644 index 0000000000000000000000000000000000000000..721eea5a0f653734850d6ffd851cadf3441907fa --- /dev/null +++ b/0005-sw_64-add-support-for-custom-mode.patch @@ -0,0 +1,273 @@ +From 596c1f17a40c36f81cec9b9c79d8c1c6a834654c Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Fri, 13 Oct 2023 10:52:12 +0800 +Subject: [PATCH 5/9] sw_64: add support for custom mode + +Signed-off-by: Zhang Wenxiang +--- + src/cpu/cpu_sw64.c | 168 +++++++++++++++++++++++++++++++++++-- + 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 + + 5 files changed, 174 insertions(+), 9 deletions(-) + create mode 100644 src/cpu_map/sw64_core3.xml + create mode 100644 src/cpu_map/sw64_core4.xml + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +index bc0a383252..4191088007 100644 +--- a/src/cpu/cpu_sw64.c ++++ b/src/cpu/cpu_sw64.c +@@ -26,19 +26,25 @@ + #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 ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array))) + + static const virArch archs[] = { VIR_ARCH_SW_64 }; + +-static int +-virCPUsw64GetHost(virCPUDef *cpu ATTRIBUTE_UNUSED, +- virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) +-{ +- return 0; +-} ++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, +@@ -50,23 +56,167 @@ virCPUsw64Compare(virCPUDef *host ATTRIBUTE_UNUSED, + + static int + virCPUsw64Update(virCPUDef *guest, +- const virCPUDef *host ATTRIBUTE_UNUSED, +- bool relative ATTRIBUTE_UNUSED) ++ 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 ++virCPUsw64GetHost(virCPUDef *cpu, ++ virDomainCapsCPUModels *models ATTRIBUTE_UNUSED) ++{ ++ cpu->model = g_strdup("core3"); ++ ++ return 0; ++} ++ ++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 = ARRAY_CARDINALITY(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_map/index.xml b/src/cpu_map/index.xml +index ffe1fa91e5..810c8c20ec 100644 +--- a/src/cpu_map/index.xml ++++ b/src/cpu_map/index.xml +@@ -110,4 +110,9 @@ + + + ++ ++ ++ ++ ++ + +diff --git a/src/cpu_map/meson.build b/src/cpu_map/meson.build +index 013fc62a02..7ff5d25d22 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', ++ 'sw64_core3.xml', ++ 'sw64_core4.xml', + ] + + install_data(cpumap_data, install_dir: pkgdatadir / 'cpu_map') +diff --git a/src/cpu_map/sw64_core3.xml b/src/cpu_map/sw64_core3.xml +new file mode 100644 +index 0000000000..ec3fa0ef34 +--- /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 0000000000..11e763b528 +--- /dev/null ++++ b/src/cpu_map/sw64_core4.xml +@@ -0,0 +1,4 @@ ++ ++ ++ ++ +-- +2.17.1 + diff --git a/0006-sw_64-update-getting-host-cpu-model-logical-in-sw_64.patch b/0006-sw_64-update-getting-host-cpu-model-logical-in-sw_64.patch new file mode 100644 index 0000000000000000000000000000000000000000..f05eae371f392e2146468413f38fe7a3904e582a --- /dev/null +++ b/0006-sw_64-update-getting-host-cpu-model-logical-in-sw_64.patch @@ -0,0 +1,132 @@ +From 0de8d35718e5ac958573a7f7f63004c9ea5ce8e1 Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Tue, 30 Apr 2024 09:27:16 +0800 +Subject: [PATCH 6/9] sw_64: update getting host cpu model logical in sw_64 + +In the past, we usually set sw_64 host cpu model as 'core3'. +However, after sw_64 cpu types increase, this setting becomes +unreliable. So fix it. + +Signed-off-by: Zhang Wenxiang +--- + src/cpu/cpu_sw64.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 83 insertions(+), 2 deletions(-) + +diff --git a/src/cpu/cpu_sw64.c b/src/cpu/cpu_sw64.c +index 4191088007..25c2460cf1 100644 +--- a/src/cpu/cpu_sw64.c ++++ b/src/cpu/cpu_sw64.c +@@ -23,6 +23,7 @@ + + #include + ++#include "virfile.h" + #include "viralloc.h" + #include "cpu.h" + #include "cpu_sw64.h" +@@ -32,6 +33,7 @@ + + #define VIR_FROM_THIS VIR_FROM_CPU + #define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array))) ++#define CPUINFO_PATH "/proc/cpuinfo" + + static const virArch archs[] = { VIR_ARCH_SW_64 }; + +@@ -167,13 +169,92 @@ sw64LoadMap(void) + 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) + { +- cpu->model = g_strdup("core3"); ++ int ret = -1; ++ unsigned int mode; ++ FILE *cpuinfo = fopen(CPUINFO_PATH, "r"); ++ if (!cpuinfo) { ++ virReportSystemError(errno, ++ _("cannot open %s"), CPUINFO_PATH); ++ return -1; ++ } + +- return 0; ++ 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 +-- +2.17.1 + diff --git a/0007-sw_64-set-default-video-device-to-VIR_DOMAIN_VIDEO_T.patch b/0007-sw_64-set-default-video-device-to-VIR_DOMAIN_VIDEO_T.patch new file mode 100644 index 0000000000000000000000000000000000000000..71d1cee6c1e9041348644b4effbe8caf78b7e785 --- /dev/null +++ b/0007-sw_64-set-default-video-device-to-VIR_DOMAIN_VIDEO_T.patch @@ -0,0 +1,28 @@ +From 75b520ad30f315a3274e3a5382a980b48ab533e2 Mon Sep 17 00:00:00 2001 +From: Chen Wang +Date: Mon, 6 May 2024 15:33:16 +0800 +Subject: [PATCH 7/9] sw_64: set default video device to + VIR_DOMAIN_VIDEO_TYPE_VIRTIO + +Signed-off-by: Chen Wang +--- + src/qemu/qemu_domain.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index bb9853b65c..318d8e1da6 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -5366,7 +5366,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)) +-- +2.17.1 + diff --git a/0008-sw_64-add-IDE-support-for-machine-type-core4.patch b/0008-sw_64-add-IDE-support-for-machine-type-core4.patch new file mode 100644 index 0000000000000000000000000000000000000000..ae1fbd8d50dcb9dcb3e227f403fa279bac2dea2f --- /dev/null +++ b/0008-sw_64-add-IDE-support-for-machine-type-core4.patch @@ -0,0 +1,26 @@ +From a132351ef2a8fedd8e5a8ced5a57e91d5d8466e4 Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Mon, 20 May 2024 09:10:56 +0800 +Subject: [PATCH 8/9] sw_64: add IDE support for machine type core4 + +Signed-off-by: Zhang Wenxiang +--- + src/qemu/qemu_domain.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index 318d8e1da6..c477f636c4 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -8669,7 +8669,7 @@ qemuDomainMachineHasBuiltinIDE(const char *machine, + return qemuDomainMachineIsI440FX(machine, arch) || + STREQ(machine, "malta") || + STREQ(machine, "sun4u") || +- STREQ(machine, "core3") || ++ STRPREFIX(machine, "core") || + STREQ(machine, "g3beige"); + } + +-- +2.17.1 + diff --git a/0009-sw_64-set-default-usb-device-controller-model-to-qem.patch b/0009-sw_64-set-default-usb-device-controller-model-to-qem.patch new file mode 100644 index 0000000000000000000000000000000000000000..98fdc1ebdf6f0f5f99b17fcd46ff4a4fafd23524 --- /dev/null +++ b/0009-sw_64-set-default-usb-device-controller-model-to-qem.patch @@ -0,0 +1,33 @@ +From 58dd77654345024428f892f8d0721d244529e700 Mon Sep 17 00:00:00 2001 +From: Zhang Wenxiang +Date: Tue, 21 May 2024 23:33:32 +0800 +Subject: [PATCH 9/9] sw_64: set default usb device controller model to + qemu-xhci + +Usually, libvirt set default usb controller model as piix3-uhci. +However, this model is unsupported by sw kernel, so fix it. + +Signed-off-by: Zhang Wenxiang +--- + src/qemu/qemu_domain.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index c477f636c4..4bd0449164 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -5069,7 +5069,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 || +-- +2.17.1 +