From nobody Wed Oct 29 08:39:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513111589317392.012481857627; Tue, 12 Dec 2017 12:46:29 -0800 (PST) Received: from localhost ([::1]:60436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOrRO-00038z-Kt for importer@patchew.org; Tue, 12 Dec 2017 15:46:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOrPW-0001uk-Ra for qemu-devel@nongnu.org; Tue, 12 Dec 2017 15:44:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOrPS-0003qE-Ip for qemu-devel@nongnu.org; Tue, 12 Dec 2017 15:44:18 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eOrPS-0003pa-AV for qemu-devel@nongnu.org; Tue, 12 Dec 2017 15:44:14 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBCKfI1d129203 for ; Tue, 12 Dec 2017 15:44:10 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2etnwq131a-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 12 Dec 2017 15:44:09 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Dec 2017 15:44:08 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 12 Dec 2017 15:44:06 -0500 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBCKi5sC51183658; Tue, 12 Dec 2017 20:44:05 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 617BA28050; Tue, 12 Dec 2017 15:43:32 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 525782804A; Tue, 12 Dec 2017 15:43:32 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org Date: Tue, 12 Dec 2017 15:44:03 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513111443-22790-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1513111443-22790-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17121220-0036-0000-0000-0000029A320E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008194; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00959287; UDB=6.00485133; IPR=6.00739309; BA=6.00005738; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018507; XFM=3.00000015; UTC=2017-12-12 20:44:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121220-0037-0000-0000-000042A5F7C4 Message-Id: <1513111443-22790-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-12_10:, , 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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712120294 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 v2 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 ef5e62d..0b8a424 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 H_SUCCESS; } =20 -static void tpm_spapr_request_completed(TPMIf *ti) +static void _tpm_spapr_request_completed(SPAPRvTPMState *s) { - SPAPRvTPMState *s =3D VIO_SPAPR_VTPM(ti); TPMSpaprCRQ *crq =3D &s->crq; uint32_t len; int rc; @@ -281,6 +280,13 @@ static void tpm_spapr_request_completed(TPMIf *ti) } } =20 +static void tpm_spapr_request_completed(TPMIf *ti) +{ + SPAPRvTPMState *s =3D VIO_SPAPR_VTPM(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); @@ -313,9 +319,56 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti) return tpm_backend_get_tpm_version(s->be_driver); } =20 +/* persistent state handling */ + +static int tpm_spapr_pre_save(void *opaque) +{ + SPAPRvTPMState *s =3D 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 =3D opaque; + + if (s->state =3D=3D 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 =3D { - .name =3D "tpm_spapr", - .unmigratable =3D 1, + .name =3D "tpm-spapr", + .version_id =3D 1, + .minimum_version_id =3D 0, + .minimum_version_id_old =3D 0, + .pre_save =3D tpm_spapr_pre_save, + .post_load =3D tpm_spapr_post_load, + .fields =3D (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(), + } }; =20 static Property tpm_spapr_properties[] =3D { --=20 2.5.5