From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-ppc@nongnu.org
Cc: marcandre.lureau@redhat.com,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
qemu-devel@nongnu.org, david@gibson.dropbear.id.au
Subject: [PATCH v4 6/8] tpm_spapr: Support suspend and resume
Date: Thu, 12 Dec 2019 13:07:42 -0500 [thread overview]
Message-ID: <20191212180744.1070446-7-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <20191212180744.1070446-1-stefanb@linux.vnet.ibm.com>
Extend the tpm_spapr frontend with VM suspend and resume support.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
diff --git a/hw/tpm/tpm_spapr.c b/hw/tpm/tpm_spapr.c
index c4a67e2403..52e0405ab4 100644
--- a/hw/tpm/tpm_spapr.c
+++ b/hw/tpm/tpm_spapr.c
@@ -87,6 +87,8 @@ typedef struct {
TPMVersion be_tpm_version;
size_t be_buffer_size;
+
+ bool deliver_response; /* whether to deliver response after VM resume */
} SPAPRvTPMState;
static void tpm_spapr_show_buffer(const unsigned char *buffer,
@@ -255,6 +257,14 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)
TPMSpaprCRQ *crq = &s->crq;
uint32_t len;
int rc;
+ bool be_suspended;
+
+ be_suspended = tpm_backend_is_suspended(s->be_driver);
+ if (be_suspended) {
+ /* defer delivery of response until .post_load */
+ s->deliver_response |= true;
+ return;
+ }
s->state = SPAPR_VTPM_STATE_COMPLETION;
@@ -316,6 +326,7 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)
SPAPRvTPMState *s = VIO_SPAPR_VTPM(dev);
s->state = SPAPR_VTPM_STATE_NONE;
+ s->deliver_response = false;
s->be_tpm_version = tpm_backend_get_tpm_version(s->be_driver);
tpm_spapr_update_deviceclass(dev);
@@ -339,9 +350,53 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)
return tpm_backend_get_tpm_version(s->be_driver);
}
+/* persistent state handling */
+
+static int tpm_spapr_pre_save(void *opaque)
+{
+ SPAPRvTPMState *s = opaque;
+
+ s->deliver_response |= tpm_backend_finish_sync(s->be_driver);
+
+ trace_tpm_spapr_pre_save(s->deliver_response);
+ /*
+ * we cannot deliver the results to the VM since DMA would touch VM memory
+ */
+
+ return 0;
+}
+
+static int tpm_spapr_post_load(void *opaque, int version_id)
+{
+ SPAPRvTPMState *s = opaque;
+
+ if (s->deliver_response) {
+ trace_tpm_spapr_post_load();
+ /* deliver the results to the VM via DMA */
+ tpm_spapr_request_completed(TPM_IF(s), 0);
+ s->deliver_response = false;
+ }
+
+ return 0;
+}
+
static const VMStateDescription vmstate_spapr_vtpm = {
.name = "tpm-spapr",
- .unmigratable = 1,
+ .version_id = 1,
+ .minimum_version_id = 0,
+ .minimum_version_id_old = 0,
+ .pre_save = tpm_spapr_pre_save,
+ .post_load = tpm_spapr_post_load,
+ .fields = (VMStateField[]) {
+ VMSTATE_SPAPR_VIO(vdev, SPAPRvTPMState),
+
+ VMSTATE_UINT8(state, SPAPRvTPMState),
+ VMSTATE_BUFFER(buffer, SPAPRvTPMState),
+ /* remember DMA address */
+ VMSTATE_UINT32(crq.s.data, SPAPRvTPMState),
+ VMSTATE_BOOL(deliver_response, SPAPRvTPMState),
+ VMSTATE_END_OF_LIST(),
+ }
};
static Property tpm_spapr_properties[] = {
diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events
index 6278a39618..d109661b96 100644
--- a/hw/tpm/trace-events
+++ b/hw/tpm/trace-events
@@ -67,3 +67,5 @@ tpm_spapr_do_crq_get_version(uint32_t version) "response: version %u"
tpm_spapr_do_crq_prepare_to_suspend(void) "response: preparing to suspend"
tpm_spapr_do_crq_unknown_msg_type(uint8_t type) "Unknown message type 0x%02x"
tpm_spapr_do_crq_unknown_crq(uint8_t raw1, uint8_t raw2) "unknown CRQ 0x%02x 0x%02x ..."
+tpm_spapr_pre_save(bool v) "TPM response to deliver after resume: %d"
+tpm_spapr_post_load(void) "Delivering TPM response after resume"
--
2.21.0
next prev parent reply other threads:[~2019-12-12 18:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-12 18:07 [PATCH v4 0/8] Add vTPM emulator supportfor ppc64 platform Stefan Berger
2019-12-12 18:07 ` [PATCH v4 1/8] tpm_spapr: Support TPM for ppc64 using CRQ based interface Stefan Berger
2019-12-12 18:07 ` [PATCH v4 2/8] tpm_backend: Implement check whether tpm backend is suspended Stefan Berger
2019-12-12 18:07 ` [PATCH v4 3/8] tpm_emulator: Implement callback for whether we are suspended Stefan Berger
2019-12-12 18:33 ` Stefan Berger
2019-12-12 20:10 ` Stefan Berger
2019-12-12 18:07 ` [PATCH v4 4/8] tpm_passthrough: " Stefan Berger
2019-12-12 18:07 ` [PATCH v4 5/8] tpm: Return bool from tpm_backend_finish_sync Stefan Berger
2019-12-12 18:07 ` Stefan Berger [this message]
2019-12-12 18:07 ` [PATCH v4 7/8] hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config Stefan Berger
2019-12-12 18:07 ` [PATCH v4 8/8] docs: tpm: Add example command line for ppc64 and tpm-spapr Stefan Berger
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=20191212180744.1070446-7-stefanb@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=david@gibson.dropbear.id.au \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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).