[PATCH v5 4/6] igvm: Refactor qigvm_parameter_insert

Oliver Steffen posted 6 patches 1 week, 6 days ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, Ani Sinha <anisinha@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Marcelo Tosatti <mtosatti@redhat.com>, Zhao Liu <zhao1.liu@intel.com>
There is a newer version of this series
[PATCH v5 4/6] igvm: Refactor qigvm_parameter_insert
Posted by Oliver Steffen 1 week, 6 days ago
Use qigvm_find_param_entry() also in qigvm_parameter_insert().
This changes behavior: Processing now stops after the first parameter
entry found. That is OK, because we expect only one matching entry
anyway.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
 backends/igvm.c | 50 ++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/backends/igvm.c b/backends/igvm.c
index 213c9d337e..0a0092fb55 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -513,31 +513,31 @@ static int qigvm_directive_parameter_insert(QIgvm *ctx,
         return 0;
     }
 
-    QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next)
-    {
-        if (param_entry->index == param->parameter_area_index) {
-            region = qigvm_prepare_memory(ctx, param->gpa, param_entry->size,
-                                          ctx->current_header_index, errp);
-            if (!region) {
-                return -1;
-            }
-            memcpy(region, param_entry->data, param_entry->size);
-            g_free(param_entry->data);
-            param_entry->data = NULL;
-
-            /*
-             * If a confidential guest support object is provided then use it to
-             * set the guest state.
-             */
-            if (ctx->cgs) {
-                result = ctx->cgsc->set_guest_state(param->gpa, region,
-                                                    param_entry->size,
-                                                    CGS_PAGE_TYPE_UNMEASURED, 0,
-                                                    errp);
-                if (result < 0) {
-                    return -1;
-                }
-            }
+    param_entry = qigvm_find_param_entry(ctx, param->parameter_area_index);
+    if (param_entry == NULL) {
+        return 0;
+    }
+
+    region = qigvm_prepare_memory(ctx, param->gpa, param_entry->size,
+                                    ctx->current_header_index, errp);
+    if (!region) {
+        return -1;
+    }
+    memcpy(region, param_entry->data, param_entry->size);
+    g_free(param_entry->data);
+    param_entry->data = NULL;
+
+    /*
+     * If a confidential guest support object is provided then use it to
+     * set the guest state.
+     */
+    if (ctx->cgs) {
+        result = ctx->cgsc->set_guest_state(param->gpa, region,
+                                            param_entry->size,
+                                            CGS_PAGE_TYPE_UNMEASURED, 0,
+                                            errp);
+        if (result < 0) {
+            return -1;
         }
     }
     return 0;
-- 
2.52.0
Re: [PATCH v5 4/6] igvm: Refactor qigvm_parameter_insert
Posted by Luigi Leonardi 1 week, 4 days ago
On Tue, Jan 27, 2026 at 11:02:55AM +0100, Oliver Steffen wrote:
>Use qigvm_find_param_entry() also in qigvm_parameter_insert().
>This changes behavior: Processing now stops after the first parameter
>entry found. That is OK, because we expect only one matching entry
>anyway.
>
>Signed-off-by: Oliver Steffen <osteffen@redhat.com>
>---
> backends/igvm.c | 50 ++++++++++++++++++++++++-------------------------
> 1 file changed, 25 insertions(+), 25 deletions(-)
>
>diff --git a/backends/igvm.c b/backends/igvm.c
>index 213c9d337e..0a0092fb55 100644
>--- a/backends/igvm.c
>+++ b/backends/igvm.c
>@@ -513,31 +513,31 @@ static int qigvm_directive_parameter_insert(QIgvm *ctx,
>         return 0;
>     }
>
>-    QTAILQ_FOREACH(param_entry, &ctx->parameter_data, next)
>-    {
>-        if (param_entry->index == param->parameter_area_index) {
>-            region = qigvm_prepare_memory(ctx, param->gpa, param_entry->size,
>-                                          ctx->current_header_index, errp);
>-            if (!region) {
>-                return -1;
>-            }
>-            memcpy(region, param_entry->data, param_entry->size);
>-            g_free(param_entry->data);
>-            param_entry->data = NULL;
>-
>-            /*
>-             * If a confidential guest support object is provided then use it to
>-             * set the guest state.
>-             */
>-            if (ctx->cgs) {
>-                result = ctx->cgsc->set_guest_state(param->gpa, region,
>-                                                    param_entry->size,
>-                                                    CGS_PAGE_TYPE_UNMEASURED, 0,
>-                                                    errp);
>-                if (result < 0) {
>-                    return -1;
>-                }
>-            }
>+    param_entry = qigvm_find_param_entry(ctx, param->parameter_area_index);
>+    if (param_entry == NULL) {
>+        return 0;
>+    }
>+
>+    region = qigvm_prepare_memory(ctx, param->gpa, param_entry->size,
>+                                    ctx->current_header_index, errp);
>+    if (!region) {
>+        return -1;
>+    }
>+    memcpy(region, param_entry->data, param_entry->size);
>+    g_free(param_entry->data);
>+    param_entry->data = NULL;
>+
>+    /*
>+     * If a confidential guest support object is provided then use it to
>+     * set the guest state.
>+     */
>+    if (ctx->cgs) {
>+        result = ctx->cgsc->set_guest_state(param->gpa, region,
>+                                            param_entry->size,
>+                                            CGS_PAGE_TYPE_UNMEASURED, 0,
>+                                            errp);
>+        if (result < 0) {
>+            return -1;
>         }
>     }
>     return 0;
>-- 
>2.52.0
>

LGTM

Reviewed-by: Luigi Leonardi <leonardi@redhat.com>