From nobody Sun Nov 2 11:46:59 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 150914567434140.48233580036492; Fri, 27 Oct 2017 16:07:54 -0700 (PDT) Received: from localhost ([::1]:59202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8Dj5-0005sX-WC for importer@patchew.org; Fri, 27 Oct 2017 19:07:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8Def-0002g5-Kd for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8Dec-00040Q-7i for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41506) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e8Deb-0003yi-VI for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:06 -0400 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 v9RN1xrK063039 for ; Fri, 27 Oct 2017 19:03:02 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dv8s5vv0w-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 27 Oct 2017 19:03:01 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Oct 2017 19:03:00 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 27 Oct 2017 19:02:57 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9RN2v0Y3342710; Fri, 27 Oct 2017 23:02:57 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7B440AC043; Fri, 27 Oct 2017 19:03:42 -0400 (EDT) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 6DEB2AC03A; Fri, 27 Oct 2017 19:03:42 -0400 (EDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 27 Oct 2017 19:02:41 -0400 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1509145361-11218-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1509145361-11218-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17102723-0024-0000-0000-000002E98CB0 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007964; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00937412; UDB=6.00472471; IPR=6.00717674; BA=6.00005660; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017751; XFM=3.00000015; UTC=2017-10-27 23:02:58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102723-0025-0000-0000-000045DC8CFE Message-Id: <1509145361-11218-8-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_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-1707230000 definitions=main-1710270296 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 7/7] tpm: extend TPM CRB with state migration support 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: amarnath.valluri@intel.com, marcandre.lureau@gmail.com, Stefan Berger 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" We need to synchronize with the backend thread to make sure that a command being processed by the external TPM emulator has completed and its response been received. In case the bottom half did not run, we run the function it is supposed to run. Signed-off-by: Stefan Berger --- hw/tpm/tpm_crb.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c index 64039eb..a81431e 100644 --- a/hw/tpm/tpm_crb.c +++ b/hw/tpm/tpm_crb.c @@ -27,6 +27,8 @@ #include "tpm_int.h" #include "tpm_util.h" =20 +#define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - sizeof(struct crb_regs)) + typedef struct CRBState { SysBusDevice parent_obj; =20 @@ -36,6 +38,7 @@ typedef struct CRBState { TPMBackend *tpmbe; TPMBackendCmd cmd; struct crb_regs regs; + unsigned char buf[CRB_CTRL_CMD_SIZE]; } CRBState; =20 #define CRB(obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB) @@ -64,8 +67,6 @@ typedef struct CRBState { #define CRB_INTF_IF_SELECTOR_CRB 0b1 #define CRB_INTF_IF_SELECTOR_UNLOCKED 0b0 =20 -#define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - sizeof(struct crb_regs)) - enum crb_loc_ctrl { CRB_LOC_CTRL_REQUEST_ACCESS =3D BIT(0), CRB_LOC_CTRL_RELINQUISH =3D BIT(1), @@ -227,12 +228,17 @@ static void tpm_crb_reset(DeviceState *dev) tpm_backend_startup_tpm(s->tpmbe); } =20 +static void _tpm_crb_request_completed(CRBState *s) +{ + s->regs.ctrl_start &=3D ~CRB_START_INVOKE; + /* TODO, in case of error: s->regs.ctrl_sts =3D CRB_CTRL_STS_ERROR */ +} + static void tpm_crb_request_completed(TPMIf *ti) { CRBState *s =3D CRB(ti); =20 - s->regs.ctrl_start &=3D ~CRB_START_INVOKE; - /* TODO, in case of error: s->regs.ctrl_sts =3D CRB_CTRL_STS_ERROR */ + _tpm_crb_request_completed(s); } =20 static enum TPMVersion tpm_crb_get_version(TPMIf *ti) @@ -242,9 +248,66 @@ static enum TPMVersion tpm_crb_get_version(TPMIf *ti) return tpm_backend_get_tpm_version(s->tpmbe); } =20 +/* persistent state handling */ + +static int tpm_crb_pre_save(void *opaque) +{ + CRBState *s =3D opaque; + void *mem =3D memory_region_get_ram_ptr(&s->cmdmem); + + /* + * Synchronize with backend completion. + */ + tpm_backend_wait_cmd_completed(s->tpmbe); + + if (s->regs.ctrl_start & CRB_START_INVOKE) { + _tpm_crb_request_completed(s); + } + + memcpy(s->buf, mem, sizeof(s->buf)); + + return 0; +} + +static int tpm_crb_post_load(void *opaque, + int version_id __attribute__((unused))) +{ + CRBState *s =3D opaque; + void *mem =3D memory_region_get_ram_ptr(&s->cmdmem); + + memcpy(mem, s->buf, sizeof(s->buf)); + + return 0; +} + static const VMStateDescription vmstate_tpm_crb =3D { .name =3D "tpm-crb", - .unmigratable =3D 1, + .version_id =3D 1, + .minimum_version_id =3D 0, + .minimum_version_id_old =3D 0, + .pre_save =3D tpm_crb_pre_save, + .post_load =3D tpm_crb_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(regs.loc_state, CRBState), + VMSTATE_UINT32(regs.loc_ctrl, CRBState), + VMSTATE_UINT32(regs.loc_sts, CRBState), + VMSTATE_UINT64(regs.intf_id, CRBState), + VMSTATE_UINT64(regs.ctrl_ext, CRBState), + VMSTATE_UINT32(regs.ctrl_req, CRBState), + VMSTATE_UINT32(regs.ctrl_sts, CRBState), + VMSTATE_UINT32(regs.ctrl_cancel, CRBState), + VMSTATE_UINT32(regs.ctrl_start, CRBState), + VMSTATE_UINT32(regs.ctrl_int_enable, CRBState), + VMSTATE_UINT32(regs.ctrl_int_sts, CRBState), + VMSTATE_UINT32(regs.ctrl_cmd_size, CRBState), + VMSTATE_UINT32(regs.ctrl_cmd_pa_low, CRBState), + VMSTATE_UINT32(regs.ctrl_rsp_size, CRBState), + VMSTATE_UINT64(regs.ctrl_rsp_pa, CRBState), + + VMSTATE_UINT8_ARRAY(buf, CRBState, CRB_CTRL_CMD_SIZE), + + VMSTATE_END_OF_LIST(), + } }; =20 static Property tpm_crb_properties[] =3D { --=20 2.5.5