[libvirt PATCH V2 2/4] Config some capabilities for loongarch virt machine

Xianglai Li posted 4 patches 9 months, 1 week ago
There is a newer version of this series
[libvirt PATCH V2 2/4] Config some capabilities for loongarch virt machine
Posted by Xianglai Li 9 months, 1 week ago
From: xianglai li <lixianglai@loongson.cn>

Config some capabilities for loongarch virt machine such as
PCI multi bus.

Signed-off-by: "Xianglai Li" <lixianglai@loongson.cn>
---
 src/qemu/qemu_capabilities.c | 10 ++++++++--
 src/qemu/qemu_domain.c       | 29 ++++++++++++++++++++++++++++-
 src/qemu/qemu_domain.h       |  1 +
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f2339d6013..357183cdb5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1138,7 +1138,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);
 
@@ -2080,6 +2081,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def)
         return true;
     }
 
+    /* loongarch64 support PCI-multibus on all machine types
+     * since forever */
+    if (ARCH_IS_LOONGARCH(def->os.arch))
+        return true;
+
     return false;
 }
 
@@ -3742,7 +3748,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_domain.c b/src/qemu/qemu_domain.c
index 0cea0b323a..e07fc32630 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5635,6 +5635,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 */
@@ -5933,7 +5936,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) ||
+        qemuDomainIsLoongArchVirt(def)) {
         return VIR_DOMAIN_VIDEO_TYPE_VIRTIO;
     }
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA))
@@ -8924,6 +8928,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)
@@ -9017,6 +9037,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 fa566dded6..cbcf3f0996 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -826,6 +826,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);
-- 
2.39.1
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [libvirt PATCH V2 2/4] Config some capabilities for loongarch virt machine
Posted by Andrea Bolognani 9 months ago
On Wed, Jan 10, 2024 at 11:07:47AM +0800, Xianglai Li wrote:
> Config some capabilities for loongarch virt machine
>
> Config some capabilities for loongarch virt machine such as
> PCI multi bus.

I would just say that you're implementing support for loongarch64 in
the QEMU driver, because that's what's happening :)

> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index f2339d6013..357183cdb5 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -1138,7 +1138,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);

You can drop the unnecessary ()s around the condition. Doing so will
also fix the alignment, which is slightly off right now.

> @@ -2080,6 +2081,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def)
>          return true;
>      }
>
> +    /* loongarch64 support PCI-multibus on all machine types
> +     * since forever */
> +    if (ARCH_IS_LOONGARCH(def->os.arch))
> +        return true;

You can fold this into one of the existing architecture checks.

Actually, I'll look into posting a patch that unifies a bunch of
them, because the way the function is written today makes it way more
complicated than it really needs to be :)

> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 0cea0b323a..e07fc32630 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -5933,7 +5936,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) ||
> +        qemuDomainIsLoongArchVirt(def)) {
>          return VIR_DOMAIN_VIDEO_TYPE_VIRTIO;
>      }

You can add the condition between the RISC-V and s390 ones, thus
making the diff smaller and the resulting code a tiny bit tidier.


You have missed a number of spots where the QEMU driver needs to be
taught about the new architecture. Specifically, we need to ensure
that virtio-net is used by default, that 16550a is recognized as a
valid serial console model and used by default, and that we avoid
using the legacy -usb command line option.

You can squash in the diff below to take care of all of the above,
but note that, just like virQEMUCapsHasPCIMultiBus(),
qemuDomainDefaultNetModel() will likely see some cleaning up soon.


diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 712feb7b81..2f73399e5d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2906,6 +2906,7 @@ qemuBuildDomainForbidLegacyUSBController(const
virDomainDef *def)
 {
     if (qemuDomainIsQ35(def) ||
         qemuDomainIsARMVirt(def) ||
+        qemuDomainIsLoongArchVirt(def) ||
         qemuDomainIsRISCVVirt(def))
         return true;

@@ -9218,9 +9219,11 @@ 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 */
+        /* 16550a (used by the virt machine type on some architectures)
+         * is a platform device */
         if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
             chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM &&
             chr->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A) {
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2f1b816628..48a16299eb 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5410,8 +5415,9 @@ qemuDomainDefaultNetModel(const virDomainDef *def,
         return VIR_DOMAIN_NET_MODEL_LAN9118;
     }

-    /* virtio is a sensible default for RISC-V virt guests */
-    if (qemuDomainIsRISCVVirt(def))
+    /* virtio is a sensible default for the virt machine type */
+    if (qemuDomainIsRISCVVirt(def) ||
+        qemuDomainIsLoongArchVirt(def))
         return VIR_DOMAIN_NET_MODEL_VIRTIO;

     /* In all other cases the model depends on the capabilities. If they were
@@ -5734,7 +5740,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) ||
+                   qemuDomainIsRISCVVirt(def) ||
+                   qemuDomainIsLoongArchVirt(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;
@@ -5760,7 +5768,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 (qemuDomainIsRISCVVirt(def) ||
+                       qemuDomainIsLoongArchVirt(def)) {
                 chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A;
             }
             break;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index b22d3618fe..2984bc5bb5 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;
             }
-- 
Andrea Bolognani / Red Hat / Virtualization
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [libvirt PATCH V2 2/4] Config some capabilities for loongarch virt machine
Posted by lixianglai 8 months, 2 weeks ago
Hi  Andrea :

> On Wed, Jan 10, 2024 at 11:07:47AM +0800, Xianglai Li wrote:
>> Config some capabilities for loongarch virt machine
>>
>> Config some capabilities for loongarch virt machine such as
>> PCI multi bus.
> I would just say that you're implementing support for loongarch64 in
> the QEMU driver, because that's what's happening :)

OK, I'll correct this commit message in the next patch release.


>> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
>> index f2339d6013..357183cdb5 100644
>> --- a/src/qemu/qemu_capabilities.c
>> +++ b/src/qemu/qemu_capabilities.c
>> @@ -1138,7 +1138,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);
> You can drop the unnecessary ()s around the condition. Doing so will
> also fix the alignment, which is slightly off right now.


OK!


>> @@ -2080,6 +2081,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def)
>>           return true;
>>       }
>>
>> +    /* loongarch64 support PCI-multibus on all machine types
>> +     * since forever */
>> +    if (ARCH_IS_LOONGARCH(def->os.arch))
>> +        return true;
> You can fold this into one of the existing architecture checks.
>
> Actually, I'll look into posting a patch that unifies a bunch of
> them, because the way the function is written today makes it way more
> complicated than it really needs to be :)


OK!


>> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>> index 0cea0b323a..e07fc32630 100644
>> --- a/src/qemu/qemu_domain.c
>> +++ b/src/qemu/qemu_domain.c
>> @@ -5933,7 +5936,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) ||
>> +        qemuDomainIsLoongArchVirt(def)) {
>>           return VIR_DOMAIN_VIDEO_TYPE_VIRTIO;
>>       }
> You can add the condition between the RISC-V and s390 ones, thus
> making the diff smaller and the resulting code a tiny bit tidier.
OK!
> You have missed a number of spots where the QEMU driver needs to be
> taught about the new architecture. Specifically, we need to ensure
> that virtio-net is used by default, that 16550a is recognized as a
> valid serial console model and used by default, and that we avoid
> using the legacy -usb command line option.
>
> You can squash in the diff below to take care of all of the above,
> but note that, just like virQEMUCapsHasPCIMultiBus(),
> qemuDomainDefaultNetModel() will likely see some cleaning up soon.

OK! Thank you very much!

Xianglai.


> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 712feb7b81..2f73399e5d 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -2906,6 +2906,7 @@ qemuBuildDomainForbidLegacyUSBController(const
> virDomainDef *def)
>   {
>       if (qemuDomainIsQ35(def) ||
>           qemuDomainIsARMVirt(def) ||
> +        qemuDomainIsLoongArchVirt(def) ||
>           qemuDomainIsRISCVVirt(def))
>           return true;
>
> @@ -9218,9 +9219,11 @@ 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 */
> +        /* 16550a (used by the virt machine type on some architectures)
> +         * is a platform device */
>           if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
>               chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM &&
>               chr->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A) {
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 2f1b816628..48a16299eb 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -5410,8 +5415,9 @@ qemuDomainDefaultNetModel(const virDomainDef *def,
>           return VIR_DOMAIN_NET_MODEL_LAN9118;
>       }
>
> -    /* virtio is a sensible default for RISC-V virt guests */
> -    if (qemuDomainIsRISCVVirt(def))
> +    /* virtio is a sensible default for the virt machine type */
> +    if (qemuDomainIsRISCVVirt(def) ||
> +        qemuDomainIsLoongArchVirt(def))
>           return VIR_DOMAIN_NET_MODEL_VIRTIO;
>
>       /* In all other cases the model depends on the capabilities. If they were
> @@ -5734,7 +5740,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) ||
> +                   qemuDomainIsRISCVVirt(def) ||
> +                   qemuDomainIsLoongArchVirt(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;
> @@ -5760,7 +5768,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 (qemuDomainIsRISCVVirt(def) ||
> +                       qemuDomainIsLoongArchVirt(def)) {
>                   chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_16550A;
>               }
>               break;
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index b22d3618fe..2984bc5bb5 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;
>               }
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: Re: [libvirt PATCH V2 2/4] Config some capabilities for loongarch virt machine
Posted by Andrea Bolognani 9 months ago
On Tue, Jan 16, 2024 at 05:39:05AM -0500, Andrea Bolognani wrote:
> On Wed, Jan 10, 2024 at 11:07:47AM +0800, Xianglai Li wrote:
> > @@ -2080,6 +2081,11 @@ bool virQEMUCapsHasPCIMultiBus(const virDomainDef *def)
> >          return true;
> >      }
> >
> > +    /* loongarch64 support PCI-multibus on all machine types
> > +     * since forever */
> > +    if (ARCH_IS_LOONGARCH(def->os.arch))
> > +        return true;
>
> You can fold this into one of the existing architecture checks.
>
> Actually, I'll look into posting a patch that unifies a bunch of
> them, because the way the function is written today makes it way more
> complicated than it really needs to be :)

[...]

> You can squash in the diff below to take care of all of the above,
> but note that, just like virQEMUCapsHasPCIMultiBus(),
> qemuDomainDefaultNetModel() will likely see some cleaning up soon.

Patches here:

  https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/MREXSFFSTO3X35NOOUD4TH224JZYMZ2I/

-- 
Andrea Bolognani / Red Hat / Virtualization
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org