[PATCH 3/4] qemu: Validate MTE feature

Michal Privoznik posted 4 patches 1 year, 8 months ago
[PATCH 3/4] qemu: Validate MTE feature
Posted by Michal Privoznik 1 year, 8 months ago
The MTE feature is not supported by all QEMUs, only those with
QEMU_CAPS_MACHINE_VIRT_MTE capability.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_validate.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 99c7775e9b..aec1801672 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -124,14 +124,23 @@ qemuValidateDomainDefFeatures(const virDomainDef *def,
 
         case VIR_DOMAIN_FEATURE_GIC:
         case VIR_DOMAIN_FEATURE_MTE:
-            if (def->features[i] == VIR_TRISTATE_SWITCH_ON &&
-                !qemuDomainIsARMVirt(def)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("The '%1$s' feature is not supported for architecture '%2$s' or machine type '%3$s'"),
-                               featureName,
-                               virArchToString(def->os.arch),
-                               def->os.machine);
-                return -1;
+            if (def->features[i] == VIR_TRISTATE_SWITCH_ON) {
+                if (!qemuDomainIsARMVirt(def)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("The '%1$s' feature is not supported for architecture '%2$s' or machine type '%3$s'"),
+                                   featureName,
+                                   virArchToString(def->os.arch),
+                                   def->os.machine);
+                    return -1;
+                }
+
+                if (i == VIR_DOMAIN_FEATURE_MTE &&
+                    !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_VIRT_MTE)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("The '%1$s' feature is not supported with this QEMU binary"),
+                                   featureName);
+                    return -1;
+                }
             }
             break;
 
-- 
2.39.3
Re: [PATCH 3/4] qemu: Validate MTE feature
Posted by Martin Kletzander 1 year, 8 months ago
On Tue, May 16, 2023 at 12:54:15PM +0200, Michal Privoznik wrote:
>The MTE feature is not supported by all QEMUs, only those with
>QEMU_CAPS_MACHINE_VIRT_MTE capability.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_validate.c | 25 +++++++++++++++++--------
> 1 file changed, 17 insertions(+), 8 deletions(-)
>
>diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
>index 99c7775e9b..aec1801672 100644
>--- a/src/qemu/qemu_validate.c
>+++ b/src/qemu/qemu_validate.c
>@@ -124,14 +124,23 @@ qemuValidateDomainDefFeatures(const virDomainDef *def,
>
>         case VIR_DOMAIN_FEATURE_GIC:
>         case VIR_DOMAIN_FEATURE_MTE:
>-            if (def->features[i] == VIR_TRISTATE_SWITCH_ON &&
>-                !qemuDomainIsARMVirt(def)) {
>-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>-                               _("The '%1$s' feature is not supported for architecture '%2$s' or machine type '%3$s'"),
>-                               featureName,
>-                               virArchToString(def->os.arch),
>-                               def->os.machine);
>-                return -1;
>+            if (def->features[i] == VIR_TRISTATE_SWITCH_ON) {

This is not a big deal, but this should be '!= absent'.  Not because
there could be a "default on" in qemu, but because formatting mte='off'
for a qemu (or machine type) that does not support it would not work.

This is also pre-existing for the GIC feature.  I think it'd be nicer to
have that checked properly.

>+                if (!qemuDomainIsARMVirt(def)) {
>+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>+                                   _("The '%1$s' feature is not supported for architecture '%2$s' or machine type '%3$s'"),
>+                                   featureName,
>+                                   virArchToString(def->os.arch),
>+                                   def->os.machine);
>+                    return -1;
>+                }
>+
>+                if (i == VIR_DOMAIN_FEATURE_MTE &&
>+                    !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_VIRT_MTE)) {
>+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>+                                   _("The '%1$s' feature is not supported with this QEMU binary"),
>+                                   featureName);
>+                    return -1;
>+                }
>             }
>             break;
>
>-- 
>2.39.3
>