All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: peter.maydell@linaro.org
Cc: lvivier@redhat.com, "Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, groug@kaod.org, qemu-ppc@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PULL 16/34] tpm_spapr: Support suspend and resume
Date: Fri, 31 Jan 2020 17:09:06 +1100	[thread overview]
Message-ID: <20200131060924.147449-17-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20200131060924.147449-1-david@gibson.dropbear.id.au>

From: Stefan Berger <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>
Message-Id: <20200121152935.649898-5-stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/tpm/tpm_spapr.c  | 52 ++++++++++++++++++++++++++++++++++++++++++++-
 hw/tpm/trace-events |  2 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_spapr.c b/hw/tpm/tpm_spapr.c
index 2ac4cb061c..ce65eb2e45 100644
--- a/hw/tpm/tpm_spapr.c
+++ b/hw/tpm/tpm_spapr.c
@@ -76,6 +76,8 @@ typedef struct {
 
     unsigned char *buffer;
 
+    uint32_t numbytes; /* number of bytes to deliver on resume */
+
     TPMBackendCmd cmd;
 
     TPMBackend *be_driver;
@@ -240,6 +242,14 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)
 
     /* a max. of be_buffer_size bytes can be transported */
     len = MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size);
+
+    if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
+        trace_tpm_spapr_caught_response(len);
+        /* defer delivery of response until .post_load */
+        s->numbytes = len;
+        return;
+    }
+
     rc = spapr_vio_dma_write(&s->vdev, be32_to_cpu(crq->data),
                              s->buffer, len);
 
@@ -288,6 +298,7 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)
     SpaprTpmState *s = VIO_SPAPR_VTPM(dev);
 
     s->state = SPAPR_VTPM_STATE_NONE;
+    s->numbytes = 0;
 
     s->be_tpm_version = tpm_backend_get_tpm_version(s->be_driver);
 
@@ -309,9 +320,48 @@ 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)
+{
+    SpaprTpmState *s = opaque;
+
+    tpm_backend_finish_sync(s->be_driver);
+    /*
+     * 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)
+{
+    SpaprTpmState *s = opaque;
+
+    if (s->numbytes) {
+        trace_tpm_spapr_post_load();
+        /* deliver the results to the VM via DMA */
+        tpm_spapr_request_completed(TPM_IF(s), 0);
+        s->numbytes = 0;
+    }
+
+    return 0;
+}
+
 static const VMStateDescription vmstate_spapr_vtpm = {
     .name = "tpm-spapr",
-    .unmigratable = 1,
+    .pre_save = tpm_spapr_pre_save,
+    .post_load = tpm_spapr_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_SPAPR_VIO(vdev, SpaprTpmState),
+
+        VMSTATE_UINT8(state, SpaprTpmState),
+        VMSTATE_UINT32(numbytes, SpaprTpmState),
+        VMSTATE_VBUFFER_UINT32(buffer, SpaprTpmState, 0, NULL, numbytes),
+        /* remember DMA address */
+        VMSTATE_UINT32(crq.data, SpaprTpmState),
+        VMSTATE_END_OF_LIST(),
+    }
 };
 
 static Property tpm_spapr_properties[] = {
diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events
index 9143a8eaa3..439e514787 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_post_load(void) "Delivering TPM response after resume"
+tpm_spapr_caught_response(uint32_t v) "Caught response to deliver after resume: %u bytes"
-- 
2.24.1



  parent reply	other threads:[~2020-01-31  6:14 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31  6:08 [PULL 00/34] ppc-for-5.0 queue 20200131 David Gibson
2020-01-31  6:08 ` [PULL 01/34] ppc/pnv: use QEMU unit definition MiB David Gibson
2020-01-31  6:08 ` [PULL 02/34] ppc/pnv: improve error logging when a PNOR update fails David Gibson
2020-01-31  6:08 ` [PULL 03/34] ppc:virtex_ml507: remove unused arguments David Gibson
2020-01-31  6:08 ` [PULL 04/34] hw/ppc/prep: Remove the deprecated "prep" machine and the OpenHackware BIOS David Gibson
2020-01-31  6:08 ` [PULL 05/34] target/ppc: Clarify the meaning of return values in kvm_handle_debug David Gibson
2020-01-31  6:08 ` [PULL 06/34] spapr: Fail CAS if option vector table cannot be parsed David Gibson
2020-01-31  6:08 ` [PULL 07/34] target/ppc: Add privileged message send facilities David Gibson
2020-01-31  6:08 ` [PULL 08/34] target/ppc: add support for Hypervisor Facility Unavailable Exception David Gibson
2020-01-31  6:08 ` [PULL 09/34] spapr: Don't allow multiple active vCPUs at CAS David Gibson
2020-01-31  6:09 ` [PULL 10/34] ppc/pnv: Add support for HRMOR on Radix host David Gibson
2020-01-31  6:09 ` [PULL 11/34] ppc/pnv: remove useless "core-pir" property alias David Gibson
2020-01-31  6:09 ` [PULL 12/34] ppc/pnv: Add support for "hostboot" mode David Gibson
2020-01-31  6:09 ` [PULL 13/34] tpm: Move tpm_tis_show_buffer to tpm_util.c David Gibson
2020-01-31  6:09 ` [PULL 14/34] spapr: Implement get_dt_compatible() callback David Gibson
2020-01-31  6:09 ` [PULL 15/34] tpm_spapr: Support TPM for ppc64 using CRQ based interface David Gibson
2020-01-31  6:09 ` David Gibson [this message]
2020-01-31  6:09 ` [PULL 17/34] hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config David Gibson
2020-01-31  6:09 ` [PULL 18/34] docs/specs/tpm: reST-ify TPM documentation David Gibson
2020-01-31  6:09 ` [PULL 19/34] ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge David Gibson
2020-01-31  6:09 ` [PULL 20/34] ppc/pnv: Add models for POWER8 PHB3 " David Gibson
2020-01-31  6:09 ` [PULL 21/34] ppc/pnv: change the PowerNV machine devices to be non user creatable David Gibson
2020-01-31  6:09 ` [PULL 22/34] spapr: Enable DD2.3 accelerated count cache flush in pseries-5.0 machine David Gibson
2020-01-31  6:09 ` [PULL 23/34] target/ppc/cpu.h: Put macro parameter in parentheses David Gibson
2020-01-31  6:09 ` [PULL 24/34] Wrapper function to wait on condition for the main loop mutex David Gibson
2020-01-31  6:09 ` [PULL 25/34] ppc: spapr: Introduce FWNMI capability David Gibson
2020-01-31  6:09 ` [PULL 26/34] target/ppc: Handle NMI guest exit David Gibson
2020-01-31  6:09 ` [PULL 27/34] target/ppc: Build rtas error log upon an MCE David Gibson
2020-01-31  6:09 ` [PULL 28/34] ppc: spapr: Handle "ibm, nmi-register" and "ibm, nmi-interlock" RTAS calls David Gibson
2020-01-31  6:09 ` [PULL 29/34] migration: Include migration support for machine check handling David Gibson
2020-01-31  6:09 ` [PULL 30/34] ppc: spapr: Activate the FWNMI functionality David Gibson
2020-01-31  6:09 ` [PULL 31/34] target/ppc: Use probe_access for LSW, STSW David Gibson
2020-01-31  6:09 ` [PULL 32/34] target/ppc: Use probe_access for LMW, STMW David Gibson
2020-01-31  6:09 ` [PULL 33/34] target/ppc: Remove redundant mask in DCBZ David Gibson
2020-01-31  6:09 ` [PULL 34/34] target/ppc: Use probe_write for DCBZ David Gibson
2020-01-31 16:42 ` [PULL 00/34] ppc-for-5.0 queue 20200131 Peter Maydell
2020-02-02  8:43   ` David Gibson
2020-02-02 10:33     ` Greg Kurz

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=20200131060924.147449-17-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=lvivier@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.