qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joelle van Dyne <j@getutm.app>
To: qemu-devel@nongnu.org
Cc: Joelle van Dyne <j@getutm.app>,
	Stefan Berger <stefanb@linux.vnet.ibm.com>
Subject: [PATCH v2 11/11] tpm_crb: support restoring older vmstate
Date: Fri, 14 Jul 2023 00:09:27 -0700	[thread overview]
Message-ID: <20230714070931.23476-12-j@getutm.app> (raw)
In-Reply-To: <20230714070931.23476-1-j@getutm.app>

When we moved to a single mapping and modified TPM CRB's VMState, it
broke restoring of VMs that were saved on an older version. This
change allows those VMs to gracefully migrate to the new memory
mapping.

Signed-off-by: Joelle van Dyne <j@getutm.app>
---
 hw/tpm/tpm_crb.h        |  1 +
 hw/tpm/tpm_crb.c        | 14 ++++++++++++++
 hw/tpm/tpm_crb_common.c |  7 +++++++
 3 files changed, 22 insertions(+)

diff --git a/hw/tpm/tpm_crb.h b/hw/tpm/tpm_crb.h
index 7cdd37335f..7d8f643e98 100644
--- a/hw/tpm/tpm_crb.h
+++ b/hw/tpm/tpm_crb.h
@@ -70,5 +70,6 @@ enum TPMVersion tpm_crb_get_version(TPMCRBState *s);
 int tpm_crb_pre_save(TPMCRBState *s);
 void tpm_crb_reset(TPMCRBState *s, uint64_t baseaddr);
 void tpm_crb_init_memory(Object *obj, TPMCRBState *s, Error **errp);
+void tpm_crb_restore_regs(TPMCRBState *s, uint32_t *saved_regs);
 
 #endif /* TPM_TPM_CRB_H */
diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
index 594696ffb8..be29ca8c28 100644
--- a/hw/tpm/tpm_crb.c
+++ b/hw/tpm/tpm_crb.c
@@ -40,6 +40,7 @@ struct CRBState {
     ISADevice parent_obj;
 
     TPMCRBState state;
+    uint32_t legacy_regs[TPM_CRB_R_MAX];
 };
 typedef struct CRBState CRBState;
 
@@ -67,10 +68,23 @@ static int tpm_crb_isa_pre_save(void *opaque)
     return tpm_crb_pre_save(&s->state);
 }
 
+static int tpm_crb_isa_post_load(void *opaque, int version_id)
+{
+    CRBState *s = opaque;
+
+    if (version_id == 0) {
+        tpm_crb_restore_regs(&s->state, s->legacy_regs);
+    }
+    return 0;
+}
+
 static const VMStateDescription vmstate_tpm_crb_isa = {
     .name = "tpm-crb",
+    .version_id = 1,
     .pre_save = tpm_crb_isa_pre_save,
+    .post_load = tpm_crb_isa_post_load,
     .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(legacy_regs, CRBState, TPM_CRB_R_MAX),
         VMSTATE_END_OF_LIST(),
     }
 };
diff --git a/hw/tpm/tpm_crb_common.c b/hw/tpm/tpm_crb_common.c
index 4ecf064c98..5714ac7fc4 100644
--- a/hw/tpm/tpm_crb_common.c
+++ b/hw/tpm/tpm_crb_common.c
@@ -224,3 +224,10 @@ void tpm_crb_init_memory(Object *obj, TPMCRBState *s, Error **errp)
         tpm_ppi_init_memory(&s->ppi, obj);
     }
 }
+
+void tpm_crb_restore_regs(TPMCRBState *s, uint32_t *saved_regs)
+{
+    uint32_t *regs = memory_region_get_ram_ptr(&s->mmio);
+
+    memcpy(regs, saved_regs, TPM_CRB_R_MAX);
+}
-- 
2.39.2 (Apple Git-143)



  parent reply	other threads:[~2023-07-14  7:11 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14  7:09 [PATCH v2 00/11] tpm: introduce TPM CRB SysBus device Joelle van Dyne
2023-07-14  7:09 ` [PATCH v2 01/11] tpm_crb: refactor common code Joelle van Dyne
2023-07-14  7:09 ` [PATCH v2 02/11] tpm_crb: CTRL_RSP_ADDR is 64-bits wide Joelle van Dyne
2023-07-14  7:09 ` [PATCH v2 03/11] tpm_ppi: refactor memory space initialization Joelle van Dyne
2023-07-14  7:09 ` [PATCH v2 04/11] tpm_crb: use a single read-as-mem/write-as-mmio mapping Joelle van Dyne
2023-07-14 12:03   ` Stefan Berger
2023-07-14  7:09 ` [PATCH v2 05/11] tpm_crb: use the ISA bus Joelle van Dyne
2023-07-17 13:46   ` Igor Mammedov
2023-07-18 14:16     ` Stefan Berger
2023-08-01  1:46       ` Joelle van Dyne
2023-10-17 14:24         ` Alexander Graf
2023-07-14  7:09 ` [PATCH v2 06/11] tpm_crb: move ACPI table building to device interface Joelle van Dyne
2023-07-14 17:21   ` Stefan Berger
2023-07-17 13:42     ` Igor Mammedov
2023-08-01  3:02       ` Joelle van Dyne
2023-08-01 19:38         ` Stefan Berger
2023-08-07 10:20           ` Igor Mammedov
2023-07-14  7:09 ` [PATCH v2 07/11] hw/arm/virt: add plug handler for TPM on SysBus Joelle van Dyne
2023-07-14 12:11   ` Stefan Berger
2023-07-14 17:09     ` Joelle van Dyne
2023-07-17 14:00   ` Igor Mammedov
2023-07-14  7:09 ` [PATCH v2 08/11] hw/loongarch/virt: " Joelle van Dyne
2023-07-20 17:57   ` Stefan Berger
2023-08-03 11:35     ` Stefan Berger
2023-07-14  7:09 ` [PATCH v2 09/11] tpm_tis_sysbus: move DSDT AML generation to device Joelle van Dyne
2023-07-14 16:19   ` Stefan Berger
2023-07-14 17:29     ` Joelle van Dyne
2023-07-14 17:37       ` Stefan Berger
2023-07-14 17:39         ` Joelle van Dyne
2023-07-14 17:43           ` Stefan Berger
2023-07-14 17:46             ` Joelle van Dyne
2023-07-14 18:01               ` Stefan Berger
2023-07-14 18:15                 ` Joelle van Dyne
2023-07-17 14:06       ` Igor Mammedov
2023-07-14  7:09 ` [PATCH v2 10/11] tpm_crb_sysbus: introduce TPM CRB SysBus device Joelle van Dyne
2023-07-14 14:27   ` Stefan Berger
2023-07-14 17:20     ` Joelle van Dyne
2023-07-14 17:52       ` Stefan Berger
2023-07-17 14:23   ` Igor Mammedov
2023-10-29  2:21     ` Joelle van Dyne
2023-07-14  7:09 ` Joelle van Dyne [this message]
2023-07-14 14:05   ` [PATCH v2 11/11] tpm_crb: support restoring older vmstate Stefan Berger
2023-07-14 14:51     ` Stefan Berger
2023-07-14 17:04       ` Joelle van Dyne
2023-07-14 18:22         ` Stefan Berger
2023-07-14 18:41           ` Stefan Berger
2023-07-14 18:49             ` Joelle van Dyne
2023-07-14 19:12               ` Stefan Berger
2023-07-14 19:44                 ` Joelle van Dyne
2023-07-14 19:56                   ` Stefan Berger
2023-07-17 14:40                 ` Peter Maydell
2023-07-17 14:33               ` Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230714070931.23476-12-j@getutm.app \
    --to=j@getutm.app \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).