[PULL 07/14] coverity: fix coverity issues related to confidential guest reset

Paolo Bonzini posted 14 patches 3 weeks, 5 days ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Gerd Hoffmann <kraxel@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, Ani Sinha <anisinha@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>
[PULL 07/14] coverity: fix coverity issues related to confidential guest reset
Posted by Paolo Bonzini 3 weeks, 5 days ago
From: Ani Sinha <anisinha@redhat.com>

Fix issues reported by Peter.

Fixes: ec9bafd2ea9d12c ("i386/sev: add support for confidential guest reset")
Fixes: e76c30bb13ecb9d ("hw/machine: introduce machine specific option 'x-change-vmfd-on-reset'")
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Ani Sinha <anisinha@redhat.com>
Link: https://lore.kernel.org/r/20260311074048.61367-1-anisinha@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 system/runstate.c | 10 +++++-----
 target/i386/sev.c |  4 ----
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/system/runstate.c b/system/runstate.c
index eca722b43c6..77cb14ae028 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -508,13 +508,13 @@ static int qemu_debug_requested(void)
  */
 void qemu_system_reset(ShutdownCause reason)
 {
-    MachineClass *mc;
-    ResetType type;
+    MachineClass *mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
     AccelClass *ac = ACCEL_GET_CLASS(current_accel());
+    bool force_vmfd_change =
+        current_machine ? current_machine->new_accel_vmfd_on_reset : false;
     bool guest_state_rebuilt = false;
     int ret;
-
-    mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
+    ResetType type;
 
     cpu_synchronize_all_states();
 
@@ -528,7 +528,7 @@ void qemu_system_reset(ShutdownCause reason)
 
     if ((reason == SHUTDOWN_CAUSE_GUEST_RESET ||
          reason == SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET) &&
-        (current_machine->new_accel_vmfd_on_reset || !cpus_are_resettable())) {
+        (force_vmfd_change || !cpus_are_resettable())) {
         if (ac->rebuild_guest) {
             ret = ac->rebuild_guest(current_machine);
             if (ret < 0) {
diff --git a/target/i386/sev.c b/target/i386/sev.c
index cddffe0da8d..9dde972c118 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -2011,10 +2011,6 @@ static void sev_handle_reset(Object *obj, ResetType type)
     SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs);
     SevCommonStateClass *klass = SEV_COMMON_GET_CLASS(sev_common);
 
-    if (!sev_common) {
-        return;
-    }
-
     if (!runstate_is_running()) {
         return;
     }
-- 
2.53.0