The various notifiers that are used needs to be installed only once not on
every initialization. This includes the vm state change notifier and others.
This change uses 'cgs->ready' flag to install the notifiers only one time,
the first time.
Signed-off-by: Ani Sinha <anisinha@redhat.com>
---
target/i386/sev.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 260d8ef88b..647f4bf63d 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -1920,8 +1920,9 @@ static int sev_common_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
return -1;
}
- qemu_add_vm_change_state_handler(sev_vm_state_change, sev_common);
-
+ if (!cgs->ready) {
+ qemu_add_vm_change_state_handler(sev_vm_state_change, sev_common);
+ }
cgs->ready = true;
return 0;
@@ -1943,22 +1944,23 @@ static int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
return -1;
}
- /*
- * SEV uses these notifiers to register/pin pages prior to guest use,
- * but SNP relies on guest_memfd for private pages, which has its
- * own internal mechanisms for registering/pinning private memory.
- */
- ram_block_notifier_add(&sev_ram_notifier);
-
- /*
- * The machine done notify event is used for SEV guests to get the
- * measurement of the encrypted images. When SEV-SNP is enabled, the
- * measurement is part of the guest attestation process where it can
- * be collected without any reliance on the VMM. So skip registering
- * the notifier for SNP in favor of using guest attestation instead.
- */
- qemu_add_machine_init_done_notifier(&sev_machine_done_notify);
+ if (!cgs->ready) {
+ /*
+ * SEV uses these notifiers to register/pin pages prior to guest use,
+ * but SNP relies on guest_memfd for private pages, which has its
+ * own internal mechanisms for registering/pinning private memory.
+ */
+ ram_block_notifier_add(&sev_ram_notifier);
+ /*
+ * The machine done notify event is used for SEV guests to get the
+ * measurement of the encrypted images. When SEV-SNP is enabled, the
+ * measurement is part of the guest attestation process where it can
+ * be collected without any reliance on the VMM. So skip registering
+ * the notifier for SNP in favor of using guest attestation instead.
+ */
+ qemu_add_machine_init_done_notifier(&sev_machine_done_notify);
+ }
return 0;
}
--
2.42.0