From patchwork Tue Dec 5 20:35:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 10093739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5680460348 for ; Tue, 5 Dec 2017 20:40:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4273B2995C for ; Tue, 5 Dec 2017 20:40:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35FD729975; Tue, 5 Dec 2017 20:40:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA03D2997C for ; Tue, 5 Dec 2017 20:40:02 +0000 (UTC) Received: from localhost ([::1]:51999 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMK0U-0007cI-8X for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Dec 2017 15:39:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMJws-0003OC-MJ for qemu-devel@nongnu.org; Tue, 05 Dec 2017 15:36:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMJwq-0001Pw-6G for qemu-devel@nongnu.org; Tue, 05 Dec 2017 15:36:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46466) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMJwp-0001PJ-U5 for qemu-devel@nongnu.org; Tue, 05 Dec 2017 15:36:12 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB5KY89A071401 for ; Tue, 5 Dec 2017 15:36:08 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2enya31vvy-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 05 Dec 2017 15:36:08 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Dec 2017 15:36:06 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Dec 2017 15:36:02 -0500 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB5Ka2CT43122702; Tue, 5 Dec 2017 20:36:02 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2638BAE04B; Tue, 5 Dec 2017 15:37:00 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 0F112AE03B; Tue, 5 Dec 2017 15:37:00 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 5 Dec 2017 15:35:53 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1512506153-8011-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1512506153-8011-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17120520-0008-0000-0000-000002AB3D06 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008155; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000243; SDB=6.00955925; UDB=6.00483169; IPR=6.00735963; BA=6.00005729; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018367; XFM=3.00000015; UTC=2017-12-05 20:36:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120520-0009-0000-0000-000037826844 Message-Id: <1512506153-8011-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-05_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050294 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 2/2] tpm_spapr: Support suspend and resume X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger , lo1@us.ibm.com, James.Bottomley@HansenPartnership.com, qemu-ppc@nongnu.org, clg@kaod.org, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Stefan Berger --- hw/tpm/tpm_spapr.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/hw/tpm/tpm_spapr.c b/hw/tpm/tpm_spapr.c index 909aeeb..e145697 100644 --- a/hw/tpm/tpm_spapr.c +++ b/hw/tpm/tpm_spapr.c @@ -248,9 +248,8 @@ static int tpm_spapr_do_crq(struct VIOsPAPRDevice *dev, uint8_t *crq_data) return 0; } -static void tpm_spapr_request_completed(TPMIf *ti) +static void _tpm_spapr_request_completed(SPAPRvTPMState *s) { - SPAPRvTPMState *s = VIO_SPAPR_VTPM_DEVICE(ti); tpm_spapr_crq *crq = &s->crq; uint32_t len; int rc; @@ -278,6 +277,13 @@ static void tpm_spapr_request_completed(TPMIf *ti) } } +static void tpm_spapr_request_completed(TPMIf *ti) +{ + SPAPRvTPMState *s = VIO_SPAPR_VTPM_DEVICE(ti); + + _tpm_spapr_request_completed(s); +} + static int tpm_spapr_do_startup_tpm(SPAPRvTPMState *s, size_t buffersize) { return tpm_backend_startup_tpm(s->be_driver, buffersize); @@ -310,9 +316,56 @@ 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; + + /* + * Synchronize with backend completion. + */ + tpm_backend_wait_cmd_completed(s->be_driver); + + /* + * we cannot deliver the results to the VM (in state + * SPAPR_VTPM_STATE_EXECUTION) since DMA would touch VM memory + */ + + return 0; +} + +static int tpm_spapr_post_load(void *opaque, + int version_id __attribute__((unused))) +{ + SPAPRvTPMState *s = opaque; + + if (s->state == SPAPR_VTPM_STATE_EXECUTION) { + /* + * now we can deliver the results to the VM via DMA + */ + _tpm_spapr_request_completed(s); + } + + return 0; +} + static const VMStateDescription vmstate_spapr_vtpm = { - .name = "tpm_spapr", - .unmigratable = 1, + .name = "tpm-spapr", + .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_BUFFER(crq.raw, SPAPRvTPMState), + VMSTATE_UINT64(vdev.crq.qladdr, SPAPRvTPMState), + VMSTATE_UINT32(vdev.crq.qsize, SPAPRvTPMState), + VMSTATE_UINT32(vdev.crq.qnext, SPAPRvTPMState), + VMSTATE_UINT8(state, SPAPRvTPMState), + VMSTATE_BUFFER(buffer, SPAPRvTPMState), + VMSTATE_END_OF_LIST(), + } }; static Property tpm_spapr_properties[] = {