[libvirt] [PATCH v3 0/9] RISC-V Guest Support

Hi. Third iteration of RISC-V guest support. I believe I addressed all points of Andrea's review. Tested with: images from [1]: virt-install \ --import --name riscv64 \ --arch riscv64 --machine virt \ --memory 2048 \ --rng /dev/urandom \ --disk /var/lib/libvirt/images/stage4-disk.img,bus=virtio \ --boot kernel=/var/lib/libvirt/images/bbl,kernel_args="console=ttyS0 ro root=/dev/vda" [1] https://fedorapeople.org/groups/risc-v/disk-images/ Note that the large test suite changes that touch the '*.replies' files seem to upset the mail server, thus you're unlikely to receive them from the list. You can get them straight from my repository instead: git pull https://github.com/lkundrak/libvirt.git lr/riscv-v3 Changes since v2: * Regenerated cap test data with QEMU 3.0.0 * Squashed the tests together * Folded "docs/schemas: add RISC-V architectures" into "util: add RISC-V architectures" * Streamlined the Virtio MMIO address assignment * Added qemuDomainIsRISCVVirt() and qemuDomainMachineIsRISCVVirt() * Cosmetic changes to "util: add RISC-V architectures" * New commits: qemu: add qemuDomainAssignVirtioMMIOAddresses() qemu: add qemuDomainIsRISCVVirt() and qemuDomainMachineIsRISCVVirt() qemu: RISC-V machines have no PCI news: Add a mention of RISC-V guest support * Dropped: qemu: no USB by default on RISC-V machines (not sure why I thought this was needed) Lubomir Rintel (9): qemu: rename qemuDomainMachineIsVirt() qemu: rename qemuDomainArmVirt() util: add RISC-V architectures qemu: RISC-V machines have no PCI qemu: add qemuDomainIsRISCVVirt() and qemuDomainMachineIsRISCVVirt() qemu: add qemuDomainAssignVirtioMMIOAddresses() qemu: assign addresses to virtio devices on RISC-V tests: Add RISC-V architectures news: Add a mention of RISC-V guest support docs/news.xml | 8 + docs/schemas/basictypes.rng | 2 + src/qemu/qemu_capabilities.c | 6 +- src/qemu/qemu_command.c | 4 +- src/qemu/qemu_domain.c | 46 +- src/qemu/qemu_domain.h | 9 +- src/qemu/qemu_domain_address.c | 34 +- src/util/virarch.c | 5 +- src/util/virarch.h | 8 +- tests/capabilityschemadata/caps-qemu-kvm.xml | 36 + .../caps_3.0.0.riscv32.replies | 14819 ++++++++++++++++ .../caps_3.0.0.riscv32.xml | 118 + .../caps_3.0.0.riscv64.replies | 14819 ++++++++++++++++ .../caps_3.0.0.riscv64.xml | 118 + tests/qemucapabilitiestest.c | 2 + tests/qemuxml2argvdata/riscv64-virt.args | 30 + tests/qemuxml2argvdata/riscv64-virt.xml | 32 + tests/qemuxml2argvtest.c | 3 + .../riscv64-virt.xml | 42 + tests/qemuxml2xmloutdata/riscv64-virt.xml | 36 + tests/qemuxml2xmltest.c | 2 + tests/testutilsqemu.c | 72 + tests/vircapstest.c | 6 + 23 files changed, 30232 insertions(+), 25 deletions(-) create mode 100644 tests/qemucapabilitiesdata/caps_3.0.0.riscv32.replies create mode 100644 tests/qemucapabilitiesdata/caps_3.0.0.riscv32.xml create mode 100644 tests/qemucapabilitiesdata/caps_3.0.0.riscv64.replies create mode 100644 tests/qemucapabilitiesdata/caps_3.0.0.riscv64.xml create mode 100644 tests/qemuxml2argvdata/riscv64-virt.args create mode 100644 tests/qemuxml2argvdata/riscv64-virt.xml create mode 100644 tests/qemuxml2startupxmloutdata/riscv64-virt.xml create mode 100644 tests/qemuxml2xmloutdata/riscv64-virt.xml -- 2.17.1

It's ARM specific. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_domain.c | 6 +++--- src/qemu/qemu_domain.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 9edb4ca4d4..d9b1089c59 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5335,7 +5335,7 @@ virQEMUCapsFillDomainFeatureGICCaps(virQEMUCapsPtr qemuCaps, virDomainCapsFeatureGICPtr gic = &domCaps->gic; virGICVersion version; - if (!qemuDomainMachineIsVirt(domCaps->machine, domCaps->arch)) + if (!qemuDomainMachineIsARMVirt(domCaps->machine, domCaps->arch)) return 0; for (version = VIR_GIC_VERSION_LAST - 1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f570081e3a..ad7f4091f6 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9455,13 +9455,13 @@ qemuDomainMachineIsS390CCW(const char *machine) bool qemuDomainIsVirt(const virDomainDef *def) { - return qemuDomainMachineIsVirt(def->os.machine, def->os.arch); + return qemuDomainMachineIsARMVirt(def->os.machine, def->os.arch); } bool -qemuDomainMachineIsVirt(const char *machine, - const virArch arch) +qemuDomainMachineIsARMVirt(const char *machine, + const virArch arch) { if (arch != VIR_ARCH_ARMV7L && arch != VIR_ARCH_AARCH64) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index bff293fc0a..f883780215 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -817,8 +817,8 @@ bool qemuDomainMachineIsQ35(const char *machine); bool qemuDomainMachineIsI440FX(const char *machine); bool qemuDomainMachineNeedsFDC(const char *machine); bool qemuDomainMachineIsS390CCW(const char *machine); -bool qemuDomainMachineIsVirt(const char *machine, - const virArch arch); +bool qemuDomainMachineIsARMVirt(const char *machine, + const virArch arch); bool qemuDomainMachineIsPSeries(const char *machine, const virArch arch); bool qemuDomainMachineHasBuiltinIDE(const char *machine); -- 2.17.1

It's ARM specific. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain.c | 16 ++++++++-------- src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_domain_address.c | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d9b1089c59..d2f7e9efa6 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1787,10 +1787,10 @@ bool virQEMUCapsHasPCIMultiBus(virQEMUCapsPtr qemuCaps, return false; } - /* If 'virt' supports PCI, it supports multibus. + /* If ARM 'virt' supports PCI, it supports multibus. * No extra conditions here for simplicity. */ - if (qemuDomainIsVirt(def)) + if (qemuDomainIsARMVirt(def)) return true; return false; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ec46db5c36..334f14913a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2948,7 +2948,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_DEFAULT && !qemuDomainIsQ35(def) && - !qemuDomainIsVirt(def)) { + !qemuDomainIsARMVirt(def)) { /* An appropriate default USB controller model should already * have been selected in qemuDomainDeviceDefPostParse(); if @@ -2986,7 +2986,7 @@ qemuBuildControllerDevCommandLine(virCommandPtr cmd, if (usbcontroller == 0 && !qemuDomainIsQ35(def) && - !qemuDomainIsVirt(def) && + !qemuDomainIsARMVirt(def) && !ARCH_IS_S390(def->os.arch)) { /* We haven't added any USB controller yet, but we haven't been asked * not to add one either. Add a legacy USB controller, unless we're diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ad7f4091f6..fcb37d45e6 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3199,7 +3199,7 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, case VIR_ARCH_AARCH64: addDefaultUSB = false; addDefaultMemballoon = false; - if (qemuDomainIsVirt(def)) + if (qemuDomainIsARMVirt(def)) addPCIeRoot = virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_GPEX); break; @@ -3380,7 +3380,7 @@ qemuDomainDefEnableDefaultFeatures(virDomainDefPtr def, * was not included in the domain XML, we need to choose a suitable * GIC version ourselves */ if ((def->features[VIR_DOMAIN_FEATURE_GIC] == VIR_TRISTATE_SWITCH_ABSENT && - qemuDomainIsVirt(def)) || + qemuDomainIsARMVirt(def)) || (def->features[VIR_DOMAIN_FEATURE_GIC] == VIR_TRISTATE_SWITCH_ON && def->gic_version == VIR_GIC_VERSION_NONE)) { virGICVersion version; @@ -3832,7 +3832,7 @@ qemuDomainDefValidateFeatures(const virDomainDef *def, case VIR_DOMAIN_FEATURE_GIC: if (def->features[i] == VIR_TRISTATE_SWITCH_ON && - !qemuDomainIsVirt(def)) { + !qemuDomainIsARMVirt(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("The '%s' feature is not supported for " "architecture '%s' or machine type '%s'"), @@ -4245,7 +4245,7 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev, isCompatible = false; } - if (!qemuDomainIsVirt(def) && + if (!qemuDomainIsARMVirt(def) && (dev->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM || dev->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011)) { isCompatible = false; @@ -5770,7 +5770,7 @@ qemuDomainDefaultNetModel(const virDomainDef *def, if (STREQ(def->os.machine, "versatilepb")) return "smc91c111"; - if (qemuDomainIsVirt(def)) + if (qemuDomainIsARMVirt(def)) return "virtio"; /* Incomplete. vexpress (and a few others) use this, but not all @@ -6070,7 +6070,7 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr 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 (qemuDomainIsVirt(def)) { + } else if (qemuDomainIsARMVirt(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; @@ -6264,7 +6264,7 @@ qemuDomainDeviceVideoDefPostParse(virDomainVideoDefPtr video, if (video->type == VIR_DOMAIN_VIDEO_TYPE_DEFAULT) { if (ARCH_IS_PPC64(def->os.arch)) video->type = VIR_DOMAIN_VIDEO_TYPE_VGA; - else if (qemuDomainIsVirt(def) || ARCH_IS_S390(def->os.arch)) + else if (qemuDomainIsARMVirt(def) || ARCH_IS_S390(def->os.arch)) video->type = VIR_DOMAIN_VIDEO_TYPE_VIRTIO; else video->type = VIR_DOMAIN_VIDEO_TYPE_CIRRUS; @@ -9453,7 +9453,7 @@ qemuDomainMachineIsS390CCW(const char *machine) bool -qemuDomainIsVirt(const virDomainDef *def) +qemuDomainIsARMVirt(const virDomainDef *def) { return qemuDomainMachineIsARMVirt(def->os.machine, def->os.arch); } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f883780215..898b5b4479 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -809,7 +809,7 @@ bool qemuDomainHasPCIRoot(const virDomainDef *def); bool qemuDomainHasPCIeRoot(const virDomainDef *def); bool qemuDomainNeedsFDC(const virDomainDef *def); bool qemuDomainIsS390CCW(const virDomainDef *def); -bool qemuDomainIsVirt(const virDomainDef *def); +bool qemuDomainIsARMVirt(const virDomainDef *def); bool qemuDomainIsPSeries(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 6671eccf6f..6c540a8094 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -468,7 +468,7 @@ qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def, return; if (!(STRPREFIX(def->os.machine, "vexpress-") || - qemuDomainIsVirt(def))) + qemuDomainIsARMVirt(def))) return; /* We use virtio-mmio by default on mach-virt guests only if they already @@ -2163,7 +2163,7 @@ qemuDomainSupportsPCI(virDomainDefPtr def, if (STREQ(def->os.machine, "versatilepb")) return true; - if (qemuDomainIsVirt(def) && + if (qemuDomainIsARMVirt(def) && virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_GPEX)) return true; -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
It's ARM specific.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain.c | 16 ++++++++-------- src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_domain_address.c | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-)
https://www.redhat.com/archives/libvir-list/2018-June/msg01678.html ;) Not worth reposting just for this though, I'll just fix it myself before pushing - unless there are other issues that make a respin necessary further on. -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Reviewed-by: Andrea Bolognani <abologna@redhat.com> --- docs/schemas/basictypes.rng | 2 ++ src/qemu/qemu_domain.c | 2 ++ src/util/virarch.c | 5 ++++- src/util/virarch.h | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng index 1a18cd31b1..14a3670e5c 100644 --- a/docs/schemas/basictypes.rng +++ b/docs/schemas/basictypes.rng @@ -398,6 +398,8 @@ <value>ppc64</value> <value>ppc64le</value> <value>ppcemb</value> + <value>riscv32</value> + <value>riscv64</value> <value>s390</value> <value>s390x</value> <value>sh4</value> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fcb37d45e6..60b4a9b412 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3249,6 +3249,8 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def, case VIR_ARCH_OR32: case VIR_ARCH_PARISC: case VIR_ARCH_PARISC64: + case VIR_ARCH_RISCV32: + case VIR_ARCH_RISCV64: case VIR_ARCH_PPCLE: case VIR_ARCH_UNICORE32: case VIR_ARCH_XTENSA: diff --git a/src/util/virarch.c b/src/util/virarch.c index be48bcfb89..3f5efde8e2 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -65,15 +65,18 @@ static const struct virArchData { { "ppc64le", 64, VIR_ARCH_LITTLE_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 }, + { "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 }, + { "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 af5ff83528..a52de7f52c 100644 --- a/src/util/virarch.h +++ b/src/util/virarch.h @@ -55,15 +55,18 @@ typedef enum { VIR_ARCH_PPC64LE, /* PowerPC 64 LE http://en.wikipedia.org/wiki/PowerPC */ VIR_ARCH_PPCEMB, /* PowerPC 32 BE http://en.wikipedia.org/wiki/PowerPC */ + VIR_ARCH_RISCV32, /* RISC-V 64 LE http://en.wikipedia.org/wiki/RISC-V */ + VIR_ARCH_RISCV64, /* RISC-V 32 BE http://en.wikipedia.org/wiki/RISC-V */ VIR_ARCH_S390, /* S390 32 BE http://en.wikipedia.org/wiki/S390 */ VIR_ARCH_S390X, /* S390 64 BE http://en.wikipedia.org/wiki/S390x */ VIR_ARCH_SH4, /* SuperH4 32 LE http://en.wikipedia.org/wiki/SuperH */ + VIR_ARCH_SH4EB, /* SuperH4 32 BE http://en.wikipedia.org/wiki/SuperH */ VIR_ARCH_SPARC, /* Sparc 32 BE http://en.wikipedia.org/wiki/Sparc */ - VIR_ARCH_SPARC64, /* Sparc 64 BE http://en.wikipedia.org/wiki/Sparc */ VIR_ARCH_UNICORE32, /* UniCore 32 LE http://en.wikipedia.org/wiki/Unicore*/ VIR_ARCH_X86_64, /* x86 64 LE http://en.wikipedia.org/wiki/X86 */ + VIR_ARCH_XTENSA, /* XTensa 32 LE http://en.wikipedia.org/wiki/Xtensa#Processor_Cores */ VIR_ARCH_XTENSAEB, /* XTensa 32 BE http://en.wikipedia.org/wiki/Xtensa#Processor_Cores */ @@ -87,6 +90,9 @@ typedef enum { (arch) == VIR_ARCH_ARMV7B ||\ (arch) == VIR_ARCH_AARCH64) +# define ARCH_IS_RISCV(arch) ((arch) == VIR_ARCH_RISCV32 ||\ + (arch) == VIR_ARCH_RISCV64) + # define ARCH_IS_S390(arch) ((arch) == VIR_ARCH_S390 ||\ (arch) == VIR_ARCH_S390X) -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
+ VIR_ARCH_RISCV32, /* RISC-V 64 LE http://en.wikipedia.org/wiki/RISC-V */
This should be 32 LE ...
+ VIR_ARCH_RISCV64, /* RISC-V 32 BE http://en.wikipedia.org/wiki/RISC-V */
... and this should be 64 LE according to the corresponding implementation. I'll take care of it before pushing. Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

On Thu, 2018-08-23 at 17:30 +0200, Andrea Bolognani wrote:
On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
+ VIR_ARCH_RISCV32, /* RISC-V 64 LE http://en.wikipedia.org/wiki/RISC-V */
This should be 32 LE ...
+ VIR_ARCH_RISCV64, /* RISC-V 32 BE http://en.wikipedia.org/wiki/RISC-V */
... and this should be 64 LE
according to the corresponding implementation.
I'll take care of it before pushing.
I also had to squash in the diff below, which is necessary for the build to succeed after commit d1a6d73ddff2 (pushed minutes ago, so your series couldn't possibly account for that :). diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6a3914bde2..9fae713c63 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2298,15 +2298,18 @@ static const char *preferredMachines[] = "pseries", /* VIR_ARCH_PPC64LE */ "bamboo", /* VIR_ARCH_PPCEMB */ + "spike_v1.10", /* VIR_ARCH_RISCV32 */ + "spike_v1.10", /* VIR_ARCH_RISCV64 */ NULL, /* VIR_ARCH_S390 (no QEMU impl) */ "s390-ccw-virtio", /* VIR_ARCH_S390X */ "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 */ + "sim", /* VIR_ARCH_XTENSA */ "sim", /* VIR_ARCH_XTENSAEB */ }; -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain_address.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 6c540a8094..551883e989 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2157,7 +2157,9 @@ static bool qemuDomainSupportsPCI(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { - if ((def->os.arch != VIR_ARCH_ARMV7L) && (def->os.arch != VIR_ARCH_AARCH64)) + if ((def->os.arch != VIR_ARCH_ARMV7L) && + (def->os.arch != VIR_ARCH_AARCH64) && + !ARCH_IS_RISCV(def->os.arch)) return true; if (STREQ(def->os.machine, "versatilepb")) -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain_address.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 6c540a8094..551883e989 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2157,7 +2157,9 @@ static bool qemuDomainSupportsPCI(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { - if ((def->os.arch != VIR_ARCH_ARMV7L) && (def->os.arch != VIR_ARCH_AARCH64)) + if ((def->os.arch != VIR_ARCH_ARMV7L) && + (def->os.arch != VIR_ARCH_AARCH64) && + !ARCH_IS_RISCV(def->os.arch)) return true;
if (STREQ(def->os.machine, "versatilepb"))
Someday we should really rewrite this function. But today is not that day. Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain.c | 22 ++++++++++++++++++++++ src/qemu/qemu_domain.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 60b4a9b412..b43e9b76d4 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9477,6 +9477,28 @@ qemuDomainMachineIsARMVirt(const char *machine, } +bool +qemuDomainIsRISCVVirt(const virDomainDef *def) +{ + return qemuDomainMachineIsRISCVVirt(def->os.machine, def->os.arch); +} + + +bool +qemuDomainMachineIsRISCVVirt(const char *machine, + const virArch arch) +{ + if (!ARCH_IS_RISCV(arch)) + return false; + + if (STRNEQ(machine, "virt") && + !STRPREFIX(machine, "virt-")) + return false; + + return true; +} + + bool qemuDomainIsPSeries(const virDomainDef *def) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 898b5b4479..be9c4b7d61 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -810,6 +810,7 @@ bool qemuDomainHasPCIeRoot(const virDomainDef *def); bool qemuDomainNeedsFDC(const virDomainDef *def); bool qemuDomainIsS390CCW(const virDomainDef *def); bool qemuDomainIsARMVirt(const virDomainDef *def); +bool qemuDomainIsRISCVVirt(const virDomainDef *def); bool qemuDomainIsPSeries(const virDomainDef *def); bool qemuDomainHasBuiltinIDE(const virDomainDef *def); @@ -819,6 +820,8 @@ bool qemuDomainMachineNeedsFDC(const char *machine); bool qemuDomainMachineIsS390CCW(const char *machine); bool qemuDomainMachineIsARMVirt(const char *machine, const virArch arch); +bool qemuDomainMachineIsRISCVVirt(const char *machine, + const virArch arch); bool qemuDomainMachineIsPSeries(const char *machine, const virArch arch); bool qemuDomainMachineHasBuiltinIDE(const char *machine); -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain.c | 22 ++++++++++++++++++++++ src/qemu/qemu_domain.h | 3 +++ 2 files changed, 25 insertions(+)
Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain_address.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 551883e989..317f280f92 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -485,6 +485,14 @@ qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def, } +static void +qemuDomainAssignVirtioMMIOAddresses(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) +{ + qemuDomainAssignARMVirtioMMIOAddresses(def, qemuCaps); +} + + /** * qemuDomainDeviceCalculatePCIConnectFlags: * @@ -2923,7 +2931,7 @@ qemuDomainAssignAddresses(virDomainDefPtr def, if (qemuDomainAssignS390Addresses(def, qemuCaps) < 0) return -1; - qemuDomainAssignARMVirtioMMIOAddresses(def, qemuCaps); + qemuDomainAssignVirtioMMIOAddresses(def, qemuCaps); if (qemuDomainAssignPCIAddresses(def, qemuCaps, driver, obj) < 0) return -1; -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote: A short not explaining why you need to do this, along the lines of We're going to need to assign virtio-mmio addresses to non-ARM guests soon, so let's create a generic wrapper that calls to the architecture-specific implementation. sure would be nice... Are you okay with me adding it to the commit message before pushing? Either way the code is fine, so Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

On Thu, 2018-08-23 at 17:43 +0200, Andrea Bolognani wrote:
On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
A short not explaining why you need to do this, along the lines of
We're going to need to assign virtio-mmio addresses to non-ARM guests soon, so let's create a generic wrapper that calls to the architecture-specific implementation.
sure would be nice... Are you okay with me adding it to the commit message before pushing?
Yes, that would be fine.
Either way the code is fine, so
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Thanks, Lubo

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain_address.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 317f280f92..29a1def24c 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -485,11 +485,27 @@ qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def, } +static void +qemuDomainAssignRISCVVirtioMMIOAddresses(virDomainDefPtr def, + virQEMUCapsPtr qemuCaps) +{ + if (!qemuDomainIsRISCVVirt(def)) + return; + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MMIO)) { + qemuDomainPrimeVirtioDeviceAddresses(def, + VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO); + } +} + + static void qemuDomainAssignVirtioMMIOAddresses(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) { qemuDomainAssignARMVirtioMMIOAddresses(def, qemuCaps); + + qemuDomainAssignRISCVVirtioMMIOAddresses(def, qemuCaps); } -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote:
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/qemu/qemu_domain_address.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- docs/news.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index c6d03f5556..2b6d08dc02 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -53,6 +53,14 @@ bandwidth by using the <code>memorytune</code> element in <code>cputune</code>. </description> </change> + <change> + <summary> + qemu: Add support for RISC-V guests + </summary> + <description> + riscv32 and riscv64 guest architectures are now supported. + </description> + </change> </section> <section title="Improvements"> <change> -- 2.17.1

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote: [...]
+ <change> + <summary> + qemu: Add support for RISC-V guests + </summary> + <description> + riscv32 and riscv64 guest architectures are now supported. + </description> + </change>
Bit terse, but okay :) Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization

On Wed, 2018-08-22 at 11:15 +0200, Lubomir Rintel wrote: [...]
* Dropped: qemu: no USB by default on RISC-V machines (not sure why I thought this was needed)
I won't hold up the series because of it - in fact I intend to push it as soon as you have given me feedback for the few trivial questions I've raised during review - but I think this decision should be reverted. I've noticed that the generated command line contains -usb, which is the legacy syntax for USB support: these days guests are supposed to use -device instead, hopefully with a virt-friendly USB controller such as qemu-xhci. All those controllers are PCI, though, so they won't be usable on RISC-V until the architecture grows PCI support in QEMU... Still, we have spent a long time moving away from -usb and I don't think we should be introducing any more uses of it, so we should write a follow-up patch that gets rid of that in addition to getting patch 5/11 from v2 in. It's not like RISC-V guests would have much use for a USB controller anyway... $ qemu-system-riscv64 -device help 2>&1 | grep -i usb name "usb-redir", bus usb-bus $ -- Andrea Bolognani / Red Hat / Virtualization
participants (2)
-
Andrea Bolognani
-
Lubomir Rintel