From nobody Sun Apr 28 19:03:08 2024 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 1510323375440574.5732202197173; Fri, 10 Nov 2017 06:16:15 -0800 (PST) Received: from localhost ([::1]:41978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA68-0006pU-Cv for importer@patchew.org; Fri, 10 Nov 2017 09:15:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2Y-0003t6-9r for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2T-0004pM-Qv for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39830) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2T-0004mv-Dr for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:09 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAEBBdt119479 for ; Fri, 10 Nov 2017 09:12:03 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5b5bqj20-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:03 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:02 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:11:59 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEBxnZ61538320; Fri, 10 Nov 2017 07:11:59 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB5F5C6042; Fri, 10 Nov 2017 07:11:58 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 8CF46C603C; Fri, 10 Nov 2017 07:11:58 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:40 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0016-0000-0000-000007C93771 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:00 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0017-0000-0000-00003C32CC9F Message-Id: <1510323112-2207-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 01/13] tpm_tis: convert uint32_t to size_t 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, 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" Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index dd43630..69fe531 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -974,7 +974,7 @@ static const MemoryRegionOps tpm_tis_memory_ops =3D { }, }; =20 -static int tpm_tis_do_startup_tpm(TPMState *s, uint32_t buffersize) +static int tpm_tis_do_startup_tpm(TPMState *s, size_t buffersize) { return tpm_backend_startup_tpm(s->be_driver, buffersize); } --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 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 1510323251106130.27015041617824; Fri, 10 Nov 2017 06:14:11 -0800 (PST) Received: from localhost ([::1]:41967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA4M-00054h-7L for importer@patchew.org; Fri, 10 Nov 2017 09:14:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2Y-0003t1-37 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2T-0004oG-5R for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2S-0004lm-P1 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:09 -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 vAAEAAd5068995 for ; Fri, 10 Nov 2017 09:12:03 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5atk8tta-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:03 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:02 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:00 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC0NU262492; Fri, 10 Nov 2017 07:12:00 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A168C6042; Fri, 10 Nov 2017 07:12:00 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 0D806C603C; Fri, 10 Nov 2017 07:11:59 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:41 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0020-0000-0000-00000CFA30AC X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:02 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0021-0000-0000-00005ED9D2DE Message-Id: <1510323112-2207-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 02/13] tpm_tis: limit size of buffer from backend 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, 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" This is a preparatory patch for the subsequent ones where we get rid of the flexibility of supporting any kind of buffer size that the backend may support. We keep the size at 4096, which is also the size the external emulator supports. So, limit the size of the buffer we can support and pass it back to the backend. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 69fe531..90c6df2 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1008,7 +1008,8 @@ static void tpm_tis_reset(DeviceState *dev) int c; =20 s->be_tpm_version =3D tpm_backend_get_tpm_version(s->be_driver); - s->be_buffer_size =3D tpm_backend_get_buffer_size(s->be_driver); + s->be_buffer_size =3D MIN(tpm_backend_get_buffer_size(s->be_driver), + TPM_TIS_BUFFER_MAX); =20 tpm_backend_reset(s->be_driver); =20 @@ -1040,7 +1041,7 @@ static void tpm_tis_reset(DeviceState *dev) tpm_tis_realloc_buffer(&s->loc[c].r_buffer, s->be_buffer_size); } =20 - tpm_tis_do_startup_tpm(s, 0); + tpm_tis_do_startup_tpm(s, s->be_buffer_size); } =20 static const VMStateDescription vmstate_tpm_tis =3D { --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323707658885.3999138806353; Fri, 10 Nov 2017 06:21:47 -0800 (PST) Received: from localhost ([::1]:42008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDABa-0003LP-Oj for importer@patchew.org; Fri, 10 Nov 2017 09:21:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2f-0003xl-R6 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2V-0004sr-Ql for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:21 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2V-0004qm-FB for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:11 -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 vAAEBAeE125023 for ; Fri, 10 Nov 2017 09:12:06 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5dds8twr-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:05 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:05 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:02 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC0ip5112162; Fri, 10 Nov 2017 07:12:01 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DECE4C603E; Fri, 10 Nov 2017 07:12:01 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 80B70C603C; Fri, 10 Nov 2017 07:12:01 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:42 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0012-0000-0000-000015463025 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0013-0000-0000-00005036C1D7 Message-Id: <1510323112-2207-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 03/13] tpm_tis: remove TPMSizeBuffer usage 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Remove usage of TPMSizeBuffer. The size of the buffers is limited now by s->be_buffer_size, which is the size of the buffer the TIS has negotiated with the backend. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 68 ++++++++++++++++++++++++----------------------------= ---- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 90c6df2..ddfcfc9 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -64,8 +64,8 @@ typedef struct TPMLocality { =20 uint16_t w_offset; uint16_t r_offset; - TPMSizedBuffer w_buffer; - TPMSizedBuffer r_buffer; + unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; } TPMLocality; =20 typedef struct TPMState { @@ -215,23 +215,19 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); } =20 -static uint32_t tpm_tis_get_size_from_buffer(const TPMSizedBuffer *sb) -{ - return tpm_cmd_get_size(sb->buffer); -} - -static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *stri= ng) +static void tpm_tis_show_buffer(const unsigned char *buffer, + size_t buffer_size, const char *string) { #ifdef DEBUG_TIS uint32_t len, i; =20 - len =3D tpm_tis_get_size_from_buffer(sb); + len =3D MIN(tpm_cmd_get_size(buffer), buffer_size); DPRINTF("tpm_tis: %s length =3D %d\n", string, len); for (i =3D 0; i < len; i++) { if (i && !(i % 16)) { DPRINTF("\n"); } - DPRINTF("%.2X ", sb->buffer[i]); + DPRINTF("%.2X ", buffer[i]); } DPRINTF("\n"); #endif @@ -263,7 +259,8 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(&s->loc[locty].w_buffer, "tpm_tis: To TPM"); + tpm_tis_show_buffer(s->loc[locty].w_buffer, s->be_buffer_size, + "tpm_tis: To TPM"); =20 /* * w_offset serves as length indicator for length of data; @@ -273,10 +270,10 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t loc= ty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D locty_data->w_buffer.buffer, + .in =3D locty_data->w_buffer, .in_len =3D locty_data->w_offset, - .out =3D locty_data->r_buffer.buffer, - .out_len =3D locty_data->r_buffer.size + .out =3D locty_data->r_buffer, + .out_len =3D s->be_buffer_size, }; =20 tpm_backend_deliver_request(s->be_driver, &s->cmd); @@ -427,7 +424,8 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(&s->loc[locty].r_buffer, "tpm_tis: From TPM"); + tpm_tis_show_buffer(s->loc[locty].r_buffer, s->be_buffer_size, + "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { tpm_tis_abort(s, locty); @@ -446,9 +444,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t= locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); + len =3D MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size); =20 - ret =3D s->loc[locty].r_buffer.buffer[s->loc[locty].r_offset++]; + ret =3D s->loc[locty].r_buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -494,11 +493,12 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); + idx < MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].r_buffer.buffer[idx], + s->loc[locty].r_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -506,11 +506,12 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&s->loc[locty].w_buffer); + idx < MIN(tpm_cmd_get_size(s->loc[locty].w_buffer), + s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].w_buffer.buffer[idx], + s->loc[locty].w_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -572,11 +573,11 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwadd= r addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffe= r) + MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { - avail =3D s->loc[locty].w_buffer.size - - s->loc[locty].w_offset; + avail =3D s->be_buffer_size - s->loc[locty].w_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -924,9 +925,9 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->loc[locty].w_offset < s->loc[locty].w_buffer.size) { - s->loc[locty].w_buffer. - buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; + if (s->loc[locty].w_offset < s->be_buffer_size) { + s->loc[locty].w_buffer[s->loc[locty].w_offset++] =3D + (uint8_t)val; val >>=3D 8; size--; } else { @@ -940,7 +941,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].w_buff= er); + len =3D tpm_cmd_get_size(&s->loc[locty].w_buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); @@ -979,15 +980,6 @@ static int tpm_tis_do_startup_tpm(TPMState *s, size_t = buffersize) return tpm_backend_startup_tpm(s->be_driver, buffersize); } =20 -static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb, - size_t wanted_size) -{ - if (sb->size !=3D wanted_size) { - sb->buffer =3D g_realloc(sb->buffer, wanted_size); - sb->size =3D wanted_size; - } -} - /* * Get the TPMVersion of the backend device being used */ @@ -1036,9 +1028,7 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 s->loc[c].w_offset =3D 0; - tpm_tis_realloc_buffer(&s->loc[c].w_buffer, s->be_buffer_size); s->loc[c].r_offset =3D 0; - tpm_tis_realloc_buffer(&s->loc[c].r_buffer, s->be_buffer_size); } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 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 1510323318574915.9417021334807; Fri, 10 Nov 2017 06:15:18 -0800 (PST) Received: from localhost ([::1]:41970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA5R-00063p-KH for importer@patchew.org; Fri, 10 Nov 2017 09:15:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2a-0003uK-U3 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2V-0004sm-QW for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:16 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2V-0004qo-F7 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:11 -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 vAAEBQMr125828 for ; Fri, 10 Nov 2017 09:12:06 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5dds8tx1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:06 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:05 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:03 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC37X10420628; Fri, 10 Nov 2017 07:12:03 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A055C603C; Fri, 10 Nov 2017 07:12:03 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 0CE27C6037; Fri, 10 Nov 2017 07:12:02 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:43 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0028-0000-0000-000008A14649 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:05 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0029-0000-0000-00003847855E Message-Id: <1510323112-2207-5-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 04/13] tpm_tis: move buffers from localities into common location 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, 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" One read buffer and one write buffer is sufficient for all localities. The localities cannot all be active at the same time, and only the active locality can use the r/w buffers. Inactive localities will require the COMMAND_READY flag to be set on the STS register to move to the READY state, which then enables access to using the buffer for writing of a command, while all other localities are inactive. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ddfcfc9..f6f5f17 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -64,16 +64,14 @@ typedef struct TPMLocality { =20 uint16_t w_offset; uint16_t r_offset; - unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; - unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; } TPMLocality; =20 typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 - uint32_t offset; - uint8_t buf[TPM_TIS_BUFFER_MAX]; + unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -259,7 +257,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(s->loc[locty].w_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->w_buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 /* @@ -270,9 +268,9 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D locty_data->w_buffer, + .in =3D s->w_buffer, .in_len =3D locty_data->w_offset, - .out =3D locty_data->r_buffer, + .out =3D s->r_buffer, .out_len =3D s->be_buffer_size, }; =20 @@ -424,7 +422,7 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(s->loc[locty].r_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->r_buffer, s->be_buffer_size, "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { @@ -444,10 +442,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + len =3D MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); =20 - ret =3D s->loc[locty].r_buffer[s->loc[locty].r_offset++]; + ret =3D s->r_buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -493,12 +491,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), - s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].r_buffer[idx], + s->r_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -506,12 +503,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->loc[locty].w_buffer), - s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(s->w_buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->loc[locty].w_buffer[idx], + s->w_buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -573,7 +569,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - MIN(tpm_cmd_get_size(&s->loc[locty].r_buffer), + MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { @@ -926,7 +922,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { if (s->loc[locty].w_offset < s->be_buffer_size) { - s->loc[locty].w_buffer[s->loc[locty].w_offset++] =3D + s->w_buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -941,7 +937,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_cmd_get_size(&s->loc[locty].w_buffer); + len =3D tpm_cmd_get_size(&s->w_buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323431838813.4968387640334; Fri, 10 Nov 2017 06:17:11 -0800 (PST) Received: from localhost ([::1]:41980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA6y-0007Vn-O5 for importer@patchew.org; Fri, 10 Nov 2017 09:16:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33025) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2d-0003vp-Nf for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2V-0004sh-Pu for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:19 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2V-0004qp-F9 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:11 -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 vAAEA8JC120345 for ; Fri, 10 Nov 2017 09:12:09 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5dds8u0s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:08 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:07 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:05 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC5oH5833008; Fri, 10 Nov 2017 07:12:05 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCD93C603E; Fri, 10 Nov 2017 07:12:04 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 8047CC6047; Fri, 10 Nov 2017 07:12:04 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:44 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0024-0000-0000-0000177747A1 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0025-0000-0000-00004D72F156 Message-Id: <1510323112-2207-6-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 05/13] tpm_tis: merge read and write buffer into single buffer 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since we can only be in read or write mode, we can merge the buffers into a single buffer. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index f6f5f17..0b6dd7f 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -70,8 +70,7 @@ typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 - unsigned char w_buffer[TPM_TIS_BUFFER_MAX]; - unsigned char r_buffer[TPM_TIS_BUFFER_MAX]; + unsigned char buffer[TPM_TIS_BUFFER_MAX]; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -257,7 +256,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(s->w_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 /* @@ -268,9 +267,9 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D s->w_buffer, + .in =3D s->buffer, .in_len =3D locty_data->w_offset, - .out =3D s->r_buffer, + .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; =20 @@ -422,7 +421,7 @@ static void tpm_tis_request_completed(TPMIf *ti) s->loc[locty].r_offset =3D 0; s->loc[locty].w_offset =3D 0; =20 - tpm_tis_show_buffer(s->r_buffer, s->be_buffer_size, + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); =20 if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { @@ -442,10 +441,10 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) uint16_t len; =20 if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D MIN(tpm_cmd_get_size(&s->r_buffer), + len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->r_buffer[s->loc[locty].r_offset++]; + ret =3D s->buffer[s->loc[locty].r_offset++]; if (s->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); @@ -491,11 +490,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: result buffer : ", s->loc[locty].r_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(&s->r_buffer), s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - s->r_buffer[idx], + s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" @@ -503,11 +502,11 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) "tpm_tis: request buffer: ", s->loc[locty].w_offset); for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->w_buffer), s->be_buffer_size); + idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - s->w_buffer[idx], + s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -569,7 +568,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, if (s->active_locty =3D=3D locty) { if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { val =3D TPM_TIS_BURST_COUNT( - MIN(tpm_cmd_get_size(&s->r_buffer), + MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - s->loc[locty].r_offset) | s->loc[locty].sts; } else { @@ -922,7 +921,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { if (s->loc[locty].w_offset < s->be_buffer_size) { - s->w_buffer[s->loc[locty].w_offset++] =3D + s->buffer[s->loc[locty].w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -937,7 +936,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_cmd_get_size(&s->w_buffer); + len =3D tpm_cmd_get_size(&s->buffer); if (len > s->loc[locty].w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323604278841.5650509743314; Fri, 10 Nov 2017 06:20:04 -0800 (PST) Received: from localhost ([::1]:41989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA9s-0001pq-AS for importer@patchew.org; Fri, 10 Nov 2017 09:19:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2f-0003xj-KK for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2a-00052h-6J for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:21 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2Z-00050N-T2 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:16 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAEBwIf021692 for ; Fri, 10 Nov 2017 09:12:11 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5bafy5p5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:10 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:09 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:06 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC69P10420650; Fri, 10 Nov 2017 07:12:06 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 678CCC603C; Fri, 10 Nov 2017 07:12:06 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id F3807C6037; Fri, 10 Nov 2017 07:12:05 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:45 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-8235-0000-0000-00000C8B156E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-8236-0000-0000-00003E639705 Message-Id: <1510323112-2207-7-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 06/13] tpm_tis: move r/w_offsets to TPMState 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that we have a single buffer, we also only need a single set of read/write offsets into that buffer. This works since only one locality can be active. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 57 +++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 0b6dd7f..dfdddd3 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -61,9 +61,6 @@ typedef struct TPMLocality { uint32_t iface_id; uint32_t inte; uint32_t ints; - - uint16_t w_offset; - uint16_t r_offset; } TPMLocality; =20 typedef struct TPMState { @@ -71,6 +68,8 @@ typedef struct TPMState { MemoryRegion mmio; =20 unsigned char buffer[TPM_TIS_BUFFER_MAX]; + uint16_t w_offset; + uint16_t r_offset; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -254,8 +253,6 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t fl= ags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - TPMLocality *locty_data =3D &s->loc[locty]; - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: To TPM"); =20 @@ -268,7 +265,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) s->cmd =3D (TPMBackendCmd) { .locty =3D locty, .in =3D s->buffer, - .in_len =3D locty_data->w_offset, + .in_len =3D s->w_offset, .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; @@ -350,8 +347,8 @@ static void tpm_tis_new_active_locality(TPMState *s, ui= nt8_t new_active_locty) /* abort -- this function switches the locality */ static void tpm_tis_abort(TPMState *s, uint8_t locty) { - s->loc[locty].r_offset =3D 0; - s->loc[locty].w_offset =3D 0; + s->r_offset =3D 0; + s->w_offset =3D 0; =20 DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_loc= ty); =20 @@ -418,8 +415,8 @@ static void tpm_tis_request_completed(TPMIf *ti) tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; - s->loc[locty].r_offset =3D 0; - s->loc[locty].w_offset =3D 0; + s->r_offset =3D 0; + s->w_offset =3D 0; =20 tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); @@ -444,14 +441,14 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->buffer[s->loc[locty].r_offset++]; - if (s->loc[locty].r_offset >=3D len) { + ret =3D s->buffer[s->r_offset++]; + if (s->r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", - ret, s->loc[locty].r_offset - 1); + ret, s->r_offset - 1); } =20 return ret; @@ -488,24 +485,24 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) =20 DPRINTF("tpm_tis: read offset : %d\n" "tpm_tis: result buffer : ", - s->loc[locty].r_offset); + s->r_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', + s->r_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" "tpm_tis: write offset : %d\n" "tpm_tis: request buffer: ", - s->loc[locty].w_offset); + s->w_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', + s->w_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } @@ -570,9 +567,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, val =3D TPM_TIS_BURST_COUNT( MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - - s->loc[locty].r_offset) | s->loc[locty].sts; + - s->r_offset) | s->loc[locty].sts; } else { - avail =3D s->be_buffer_size - s->loc[locty].w_offset; + avail =3D s->be_buffer_size - s->w_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -836,8 +833,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, switch (s->loc[locty].state) { =20 case TPM_TIS_STATE_READY: - s->loc[locty].w_offset =3D 0; - s->loc[locty].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; break; =20 case TPM_TIS_STATE_IDLE: @@ -855,8 +852,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, break; =20 case TPM_TIS_STATE_COMPLETION: - s->loc[locty].w_offset =3D 0; - s->loc[locty].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; /* shortcut to ready state with C/R set */ s->loc[locty].state =3D TPM_TIS_STATE_READY; if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { @@ -882,7 +879,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } else if (val =3D=3D TPM_TIS_STS_RESPONSE_RETRY) { switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: - s->loc[locty].r_offset =3D 0; + s->r_offset =3D 0; tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID| TPM_TIS_STS_DATA_AVAILABLE); @@ -920,8 +917,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->loc[locty].w_offset < s->be_buffer_size) { - s->buffer[s->loc[locty].w_offset++] =3D + if (s->w_offset < s->be_buffer_size) { + s->buffer[s->w_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -931,13 +928,13 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, } =20 /* check for complete packet */ - if (s->loc[locty].w_offset > 5 && + if (s->w_offset > 5 && (s->loc[locty].sts & TPM_TIS_STS_EXPECT)) { /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 len =3D tpm_cmd_get_size(&s->buffer); - if (len > s->loc[locty].w_offset) { + if (len > s->w_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); } else { @@ -1022,8 +1019,8 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].ints =3D 0; s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 - s->loc[c].w_offset =3D 0; - s->loc[c].r_offset =3D 0; + s->w_offset =3D 0; + s->r_offset =3D 0; } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323431848676.8851305480352; Fri, 10 Nov 2017 06:17:11 -0800 (PST) Received: from localhost ([::1]:41981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA71-0007Xb-Dw for importer@patchew.org; Fri, 10 Nov 2017 09:16:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2f-0003xA-1x for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2Y-0004z6-RC for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:21 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53620 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2Y-0004xk-JA for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:14 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAE9rZ0076623 for ; Fri, 10 Nov 2017 09:12:11 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e59kjkmrv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:11 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:10 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:08 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC8h96160690; Fri, 10 Nov 2017 07:12:08 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7D4AC603C; Fri, 10 Nov 2017 07:12:07 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 7F97FC6037; Fri, 10 Nov 2017 07:12:07 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:46 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0028-0000-0000-000008A1464E X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0029-0000-0000-000038478567 Message-Id: <1510323112-2207-8-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 07/13] tpm_tis: merge r/w_offset into rw_offset 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can now merge the r_offset and w_offset into a single rw_offset. This is possible since when the offset is used for writing in RECEPTION state then reads are ignore. Conversly, when the offset is used for reading when in COMPLETION state, then writes are ignored. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 60 ++++++++++++++++++++--------------------------------= ---- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index dfdddd3..7d7e2cd 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -68,8 +68,7 @@ typedef struct TPMState { MemoryRegion mmio; =20 unsigned char buffer[TPM_TIS_BUFFER_MAX]; - uint16_t w_offset; - uint16_t r_offset; + uint16_t rw_offset; =20 uint8_t active_locty; uint8_t aborting_locty; @@ -257,7 +256,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) "tpm_tis: To TPM"); =20 /* - * w_offset serves as length indicator for length of data; + * rw_offset serves as length indicator for length of data; * it's reset when the response comes back */ s->loc[locty].state =3D TPM_TIS_STATE_EXECUTION; @@ -265,7 +264,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) s->cmd =3D (TPMBackendCmd) { .locty =3D locty, .in =3D s->buffer, - .in_len =3D s->w_offset, + .in_len =3D s->rw_offset, .out =3D s->buffer, .out_len =3D s->be_buffer_size, }; @@ -347,8 +346,7 @@ static void tpm_tis_new_active_locality(TPMState *s, ui= nt8_t new_active_locty) /* abort -- this function switches the locality */ static void tpm_tis_abort(TPMState *s, uint8_t locty) { - s->r_offset =3D 0; - s->w_offset =3D 0; + s->rw_offset =3D 0; =20 DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_loc= ty); =20 @@ -415,8 +413,7 @@ static void tpm_tis_request_completed(TPMIf *ti) tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; - s->r_offset =3D 0; - s->w_offset =3D 0; + s->rw_offset =3D 0; =20 tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); @@ -441,14 +438,14 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_= t locty) len =3D MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); =20 - ret =3D s->buffer[s->r_offset++]; - if (s->r_offset >=3D len) { + ret =3D s->buffer[s->rw_offset++]; + if (s->rw_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", - ret, s->r_offset - 1); + ret, s->rw_offset - 1); } =20 return ret; @@ -483,26 +480,14 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) (int)tpm_tis_mmio_read(opaque, base + regs[idx], 4)); } =20 - DPRINTF("tpm_tis: read offset : %d\n" + DPRINTF("tpm_tis: r/w offset : %d\n" "tpm_tis: result buffer : ", - s->r_offset); + s->rw_offset); for (idx =3D 0; idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size); idx++) { DPRINTF("%c%02x%s", - s->r_offset =3D=3D idx ? '>' : ' ', - s->buffer[idx], - ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); - } - DPRINTF("\n" - "tpm_tis: write offset : %d\n" - "tpm_tis: request buffer: ", - s->w_offset); - for (idx =3D 0; - idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size); - idx++) { - DPRINTF("%c%02x%s", - s->w_offset =3D=3D idx ? '>' : ' ', + s->rw_offset =3D=3D idx ? '>' : ' ', s->buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } @@ -567,9 +552,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, val =3D TPM_TIS_BURST_COUNT( MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size) - - s->r_offset) | s->loc[locty].sts; + - s->rw_offset) | s->loc[locty].sts; } else { - avail =3D s->be_buffer_size - s->w_offset; + avail =3D s->be_buffer_size - s->rw_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -833,8 +818,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, switch (s->loc[locty].state) { =20 case TPM_TIS_STATE_READY: - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; break; =20 case TPM_TIS_STATE_IDLE: @@ -852,8 +836,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, break; =20 case TPM_TIS_STATE_COMPLETION: - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; /* shortcut to ready state with C/R set */ s->loc[locty].state =3D TPM_TIS_STATE_READY; if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { @@ -879,7 +862,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } else if (val =3D=3D TPM_TIS_STS_RESPONSE_RETRY) { switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: - s->r_offset =3D 0; + s->rw_offset =3D 0; tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID| TPM_TIS_STS_DATA_AVAILABLE); @@ -917,8 +900,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, } =20 while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) { - if (s->w_offset < s->be_buffer_size) { - s->buffer[s->w_offset++] =3D + if (s->rw_offset < s->be_buffer_size) { + s->buffer[s->rw_offset++] =3D (uint8_t)val; val >>=3D 8; size--; @@ -928,13 +911,13 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, } =20 /* check for complete packet */ - if (s->w_offset > 5 && + if (s->rw_offset > 5 && (s->loc[locty].sts & TPM_TIS_STS_EXPECT)) { /* we have a packet length - see if we have all of it */ bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 len =3D tpm_cmd_get_size(&s->buffer); - if (len > s->w_offset) { + if (len > s->rw_offset) { tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); } else { @@ -1019,8 +1002,7 @@ static void tpm_tis_reset(DeviceState *dev) s->loc[c].ints =3D 0; s->loc[c].state =3D TPM_TIS_STATE_IDLE; =20 - s->w_offset =3D 0; - s->r_offset =3D 0; + s->rw_offset =3D 0; } =20 tpm_tis_do_startup_tpm(s, s->be_buffer_size); --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323503953900.7318575923953; Fri, 10 Nov 2017 06:18:23 -0800 (PST) Received: from localhost ([::1]:41983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA88-0000Un-Vj for importer@patchew.org; Fri, 10 Nov 2017 09:18:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2i-00040E-CI for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2c-00058O-CN for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39340 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2c-00056r-6U for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:18 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAE9rEP064179 for ; Fri, 10 Nov 2017 09:12:13 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e59xau84y-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:12 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:11 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:09 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAEC9q17012774; Fri, 10 Nov 2017 07:12:09 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 672F6C603E; Fri, 10 Nov 2017 07:12:09 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 0AAA9C6042; Fri, 10 Nov 2017 07:12:08 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:47 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-8235-0000-0000-00000C8B1573 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-8236-0000-0000-00003E63970E Message-Id: <1510323112-2207-9-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 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-1711100198 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 08/13] tpm: Implement tpm_sized_buffer_reset 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the definition of TPMSizedBuffer out of tpm_tis.c into tpm_util.h and implement tpm_sized_buffer_reset() for the following patches to use. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_tis.c | 5 ----- hw/tpm/tpm_util.c | 7 +++++++ hw/tpm/tpm_util.h | 7 +++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 7d7e2cd..035c6ef 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -48,11 +48,6 @@ typedef enum { TPM_TIS_STATE_RECEPTION, } TPMTISState; =20 -typedef struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -} TPMSizedBuffer; - /* locality data -- all fields are persisted */ typedef struct TPMLocality { TPMTISState state; diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index a317243..bf97811 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -288,3 +288,10 @@ int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tp= m_version, =20 return 0; } + +void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) +{ + g_free(tsb->buffer); + tsb->buffer =3D NULL; + tsb->size =3D 0; +} diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index 1c17e39..26c9613 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -39,4 +39,11 @@ static inline uint32_t tpm_cmd_get_size(const void *b) int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_version, size_t *buffersize); =20 +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +void tpm_sized_buffer_reset(TPMSizedBuffer *tsb); + #endif /* TPM_TPM_UTIL_H */ --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 1510323549479423.3767832299501; Fri, 10 Nov 2017 06:19:09 -0800 (PST) Received: from localhost ([::1]:41986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA8s-00015a-3j for importer@patchew.org; Fri, 10 Nov 2017 09:18:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2g-0003yo-SI for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2c-00058J-Bq for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:22 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39338 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2c-00056q-6D for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:18 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAE9rld064218 for ; Fri, 10 Nov 2017 09:12:14 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e59xau85x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:14 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:13 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:11 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAECAkH45285504; Fri, 10 Nov 2017 07:12:10 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9E90C604F; Fri, 10 Nov 2017 07:12:10 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 7DE75C6042; Fri, 10 Nov 2017 07:12:10 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:48 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0012-0000-0000-00001546302B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0013-0000-0000-00005036C1ED Message-Id: <1510323112-2207-10-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 09/13] tpm: Introduce condition to notify waiters of completed command 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce a lock and a condition to notify anyone waiting for the completion of the execution of a TPM command by the backend (thread). The backend uses the condition to signal anyone waiting for command completion. We need to place the condition in two locations: one is invoked by the backend thread, the other by the bottom half thread. We will use the signaling to wait for command completion before VM suspend. Signed-off-by: Stefan Berger --- hw/tpm/tpm_tis.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 035c6ef..86e9a92 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -80,6 +80,9 @@ typedef struct TPMState { TPMVersion be_tpm_version; =20 size_t be_buffer_size; + + QemuMutex state_lock; + QemuCond cmd_complete; } TPMState; =20 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -405,6 +408,8 @@ static void tpm_tis_request_completed(TPMIf *ti) } } =20 + qemu_mutex_lock(&s->state_lock); + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; @@ -419,6 +424,10 @@ static void tpm_tis_request_completed(TPMIf *ti) =20 tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); + + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); } =20 /* @@ -1046,6 +1055,9 @@ static void tpm_tis_initfn(Object *obj) memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT= ); + + qemu_mutex_init(&s->state_lock); + qemu_cond_init(&s->cmd_complete); } =20 static void tpm_tis_class_init(ObjectClass *klass, void *data) --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 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 1510323743095242.24558692093387; Fri, 10 Nov 2017 06:22:23 -0800 (PST) Received: from localhost ([::1]:42009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDACD-0003iW-1d for importer@patchew.org; Fri, 10 Nov 2017 09:22:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2i-00040J-F9 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2c-00058C-Bd for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55276) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2c-00055d-1u for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:18 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAEAq86017688 for ; Fri, 10 Nov 2017 09:12:17 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5bafy5vf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:16 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:15 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:12 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAECCnx5177698; Fri, 10 Nov 2017 07:12:12 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5AAADC6037; Fri, 10 Nov 2017 07:12:12 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id F0609C603E; Fri, 10 Nov 2017 07:12:11 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:49 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0016-0000-0000-000007C93780 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943881; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0017-0000-0000-00003C32CCC0 Message-Id: <1510323112-2207-11-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 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 v3 10/13] tpm: Introduce condition in TPM backend for notification 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, 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" TPM backends will suspend independently of the frontends. Also here we need to be able to wait for the TPM command to have been completely processed. Signed-off-by: Stefan Berger --- backends/tpm.c | 19 +++++++++++++++++++ include/sysemu/tpm_backend.h | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/backends/tpm.c b/backends/tpm.c index 91222c5..bf0e120 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -20,6 +20,14 @@ #include "qemu/thread.h" #include "qemu/main-loop.h" =20 +void tpm_backend_cmd_completed(TPMBackend *s) +{ + qemu_mutex_lock(&s->state_lock); + s->tpm_busy =3D false; + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); +} + static void tpm_backend_request_completed_bh(void *opaque) { TPMBackend *s =3D TPM_BACKEND(opaque); @@ -36,6 +44,9 @@ static void tpm_backend_worker_thread(gpointer data, gpoi= nter user_data) k->handle_request(s, (TPMBackendCmd *)data); =20 qemu_bh_schedule(s->bh); + + /* result delivered */ + tpm_backend_cmd_completed(s); } =20 static void tpm_backend_thread_end(TPMBackend *s) @@ -64,6 +75,10 @@ int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error = **errp) object_ref(OBJECT(tpmif)); =20 s->had_startup_error =3D false; + s->tpm_busy =3D false; + + qemu_mutex_init(&s->state_lock); + qemu_cond_init(&s->cmd_complete); =20 return 0; } @@ -93,6 +108,10 @@ bool tpm_backend_had_startup_error(TPMBackend *s) =20 void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd) { + qemu_mutex_lock(&s->state_lock); + s->tpm_busy =3D true; + qemu_mutex_unlock(&s->state_lock); + g_thread_pool_push(s->thread_pool, cmd, NULL); } =20 diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 0d6c994..39598e3 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -18,6 +18,7 @@ #include "qapi-types.h" #include "qemu/option.h" #include "sysemu/tpm.h" +#include "qemu/thread.h" =20 #define TYPE_TPM_BACKEND "tpm-backend" #define TPM_BACKEND(obj) \ @@ -53,6 +54,10 @@ struct TPMBackend { char *id; =20 QLIST_ENTRY(TPMBackend) list; + + QemuMutex state_lock; + QemuCond cmd_complete; /* signaled once tpm_busy is false */ + bool tpm_busy; }; =20 struct TPMBackendClass { @@ -206,6 +211,15 @@ size_t tpm_backend_get_buffer_size(TPMBackend *s); */ TPMInfo *tpm_backend_query_tpm(TPMBackend *s); =20 +/** + * tpm_backend_cmd_completed: + * @s: the backend + * + * Mark the backend as not busy and notify anyone interested + * in the state changed + */ +void tpm_backend_cmd_completed(TPMBackend *s); + TPMBackend *qemu_find_tpm_be(const char *id); =20 #endif --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 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 1510323820650996.881598679785; Fri, 10 Nov 2017 06:23:40 -0800 (PST) Received: from localhost ([::1]:42013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDADP-0004UF-NB for importer@patchew.org; Fri, 10 Nov 2017 09:23:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2m-00044w-UP for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2f-0005FM-7z for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:28 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54496 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2f-0005EC-2q for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:21 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAE9tFt076779 for ; Fri, 10 Nov 2017 09:12:20 -0500 Received: from e37.co.us.ibm.com (e37.co.us.ibm.com [32.97.110.158]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e59kjkmyw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:19 -0500 Received: from localhost by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:18 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:14 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAECDVV8585588; Fri, 10 Nov 2017 07:12:13 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD181C603C; Fri, 10 Nov 2017 07:12:13 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 70A7AC6047; Fri, 10 Nov 2017 07:12:13 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:50 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0024-0000-0000-0000177747AA X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724162; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0025-0000-0000-00004D72F16D Message-Id: <1510323112-2207-12-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 11/13] tpm: implement tpm_backend_wait_cmd_completed 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, 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" Implement tpm_backend_wait_cmd_completed to synchronize with the backend (thread) for the completion of a command. Signed-off-by: Stefan Berger --- backends/tpm.c | 10 ++++++++++ include/sysemu/tpm_backend.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/backends/tpm.c b/backends/tpm.c index bf0e120..5e4de27 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -28,6 +28,16 @@ void tpm_backend_cmd_completed(TPMBackend *s) qemu_mutex_unlock(&s->state_lock); } =20 +void tpm_backend_wait_cmd_completed(TPMBackend *s) +{ + qemu_mutex_lock(&s->state_lock); + + if (s->tpm_busy) { + qemu_cond_wait(&s->cmd_complete, &s->state_lock); + } + qemu_mutex_unlock(&s->state_lock); +} + static void tpm_backend_request_completed_bh(void *opaque) { TPMBackend *s =3D TPM_BACKEND(opaque); diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 39598e3..1170cb9 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -220,6 +220,14 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s); */ void tpm_backend_cmd_completed(TPMBackend *s); =20 +/** + * tpm_backend_wait_cmd_completed: + * @s: the backend + * + * Wait the backend to not be busy anymore + */ +void tpm_backend_wait_cmd_completed(TPMBackend *s); + TPMBackend *qemu_find_tpm_be(const char *id); =20 #endif --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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 151032386005441.76542808894578; Fri, 10 Nov 2017 06:24:20 -0800 (PST) Received: from localhost ([::1]:42014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDADz-0004t6-1S for importer@patchew.org; Fri, 10 Nov 2017 09:24:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2i-00040h-P3 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2d-0005Bv-V2 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:24 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42026) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2d-00059u-KT for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:19 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAEB800119364 for ; Fri, 10 Nov 2017 09:12:18 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e5b5bqjjm-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:18 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:17 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:15 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAECFEM5374292; Fri, 10 Nov 2017 07:12:15 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 58497C6037; Fri, 10 Nov 2017 07:12:15 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id E37B8C603C; Fri, 10 Nov 2017 07:12:14 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:51 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0008-0000-0000-000008D82BAB X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943881; UDB=6.00476265; IPR=6.00724163; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0009-0000-0000-000044B4CB71 Message-Id: <1510323112-2207-13-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 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-1711100198 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 v3 12/13] tpm: extend TPM emulator 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, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Extend the TPM emulator backend device with state migration support. The external TPM emulator 'swtpm' provides a protocol over its control channel to retrieve its state blobs. We implement functions for getting and setting the different state blobs. Since we have an external TPM emulator, we need to make sure that we do not migrate the state for as long as it is busy processing a request. We need to wait for notification that the request has completed processing. Signed-off-by: Stefan Berger --- hw/tpm/tpm_emulator.c | 303 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 293 insertions(+), 10 deletions(-) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 3ae8bf6..f05753f 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -61,6 +61,19 @@ #define TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(S, cap) (((S)->caps & (cap)) =3D= =3D (cap)) =20 /* data structures */ + +/* blobs from the TPM; part of VM state when migrating */ +typedef struct TPMBlobBuffers { + uint32_t permanent_flags; + TPMSizedBuffer permanent; + + uint32_t volatil_flags; + TPMSizedBuffer volatil; + + uint32_t savestate_flags; + TPMSizedBuffer savestate; +} TPMBlobBuffers; + typedef struct TPMEmulator { TPMBackend parent; =20 @@ -73,6 +86,8 @@ typedef struct TPMEmulator { Error *migration_blocker; =20 QemuMutex mutex; + + TPMBlobBuffers state_blobs; } TPMEmulator; =20 =20 @@ -315,18 +330,24 @@ static int tpm_emulator_set_buffer_size(TPMBackend *t= b, return 0; } =20 -static int tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize) +static int _tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize, + bool is_resume) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_init init; ptm_res res; =20 + DPRINTF("%s is_resume: %d", __func__, is_resume); + if (buffersize !=3D 0 && tpm_emulator_set_buffer_size(tb, buffersize, NULL) < 0) { goto err_exit; } =20 - DPRINTF("%s", __func__); + if (is_resume) { + init.u.req.init_flags =3D cpu_to_be32(PTM_INIT_FLAG_DELETE_VOLATIL= E); + } + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_INIT, &init, sizeof(init), sizeof(init)) < 0) { error_report("tpm-emulator: could not send INIT: %s", @@ -345,6 +366,11 @@ err_exit: return -1; } =20 +static int tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize) +{ + return _tpm_emulator_startup_tpm(tb, buffersize, false); +} + static bool tpm_emulator_get_tpm_established_flag(TPMBackend *tb) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); @@ -435,16 +461,21 @@ static size_t tpm_emulator_get_buffer_size(TPMBackend= *tb) static int tpm_emulator_block_migration(TPMEmulator *tpm_emu) { Error *err =3D NULL; + ptm_cap caps =3D PTM_CAP_GET_STATEBLOB | PTM_CAP_SET_STATEBLOB | + PTM_CAP_STOP; =20 - error_setg(&tpm_emu->migration_blocker, - "Migration disabled: TPM emulator not yet migratable"); - migrate_add_blocker(tpm_emu->migration_blocker, &err); - if (err) { - error_report_err(err); - error_free(tpm_emu->migration_blocker); - tpm_emu->migration_blocker =3D NULL; + if (!TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(tpm_emu, caps)) { + error_setg(&tpm_emu->migration_blocker, + "Migration disabled: TPM emulator does not support " + "migration"); + migrate_add_blocker(tpm_emu->migration_blocker, &err); + if (err) { + error_report_err(err); + error_free(tpm_emu->migration_blocker); + tpm_emu->migration_blocker =3D NULL; =20 - return -1; + return -1; + } } =20 return 0; @@ -573,6 +604,253 @@ static const QemuOptDesc tpm_emulator_cmdline_opts[] = =3D { { /* end of list */ }, }; =20 +/* + * Transfer a TPM state blob from the TPM into a provided buffer. + * + * @tpm_emu: TPMEmulator + * @type: the type of blob to transfer + * @tsb: the TPMSizeBuffer to fill with the blob + * @flags: the flags to return to the caller + */ +static int tpm_emulator_get_state_blob(TPMEmulator *tpm_emu, + uint8_t type, + TPMSizedBuffer *tsb, + uint32_t *flags) +{ + ptm_getstate pgs; + ptm_res res; + ssize_t n; + uint32_t totlength, length; + + tpm_sized_buffer_reset(tsb); + + pgs.u.req.state_flags =3D cpu_to_be32(PTM_STATE_FLAG_DECRYPTED); + pgs.u.req.type =3D cpu_to_be32(type); + pgs.u.req.offset =3D 0; + + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_GET_STATEBLOB, + &pgs, sizeof(pgs.u.req), + offsetof(ptm_getstate, u.resp.data)) < 0) { + error_report("tpm-emulator: could not get state blob type %d : %s", + type, strerror(errno)); + return -1; + } + + res =3D be32_to_cpu(pgs.u.resp.tpm_result); + if (res !=3D 0 && (res & 0x800) =3D=3D 0) { + error_report("tpm-emulator: Getting the stateblob (type %d) failed= " + "with a TPM error 0x%x", type, res); + return -1; + } + + totlength =3D be32_to_cpu(pgs.u.resp.totlength); + if (totlength >=3D 32 * 1024) { + error_report("tpm-emulator: TPM state blob (type %d) with %d bytes= " + "too large to read", type, totlength); + return -1; + } + + length =3D be32_to_cpu(pgs.u.resp.length); + if (totlength !=3D length) { + error_report("tpm-emulator: Expecting to read %u bytes " + "but would get %u", totlength, length); + return -1; + } + + *flags =3D be32_to_cpu(pgs.u.resp.state_flags); + + tsb->buffer =3D g_malloc(totlength); + + n =3D qemu_chr_fe_read_all(&tpm_emu->ctrl_chr, tsb->buffer, totlength); + if (n !=3D totlength) { + error_report("tpm-emulator: Could not read stateblob (type %d) : %= s", + type, strerror(errno)); + return -1; + } + tsb->size =3D totlength; + + DPRINTF("got state blob type %d, %d bytes, flags 0x%08x\n", + type, tsb->size, *flags); + + return 0; +} + +static int tpm_emulator_get_state_blobs(TPMEmulator *tpm_emu) +{ + TPMBlobBuffers *state_blobs =3D &tpm_emu->state_blobs; + + if (tpm_emulator_get_state_blob(tpm_emu, PTM_BLOB_TYPE_PERMANENT, + &state_blobs->permanent, + &state_blobs->permanent_flags) < 0 || + tpm_emulator_get_state_blob(tpm_emu, PTM_BLOB_TYPE_VOLATILE, + &state_blobs->volatil, + &state_blobs->volatil_flags) < 0 || + tpm_emulator_get_state_blob(tpm_emu, PTM_BLOB_TYPE_SAVESTATE, + &state_blobs->savestate, + &state_blobs->savestate_flags) < 0) { + goto err_exit; + } + + return 0; + + err_exit: + tpm_sized_buffer_reset(&state_blobs->volatil); + tpm_sized_buffer_reset(&state_blobs->permanent); + tpm_sized_buffer_reset(&state_blobs->savestate); + + return -1; +} + +/* + * Transfer a TPM state blob to the TPM emulator. + * + * @tpm_emu: TPMEmulator + * @type: the type of TPM state blob to transfer + * @tsb: TPMSizeBuffer containing the TPM state blob + * @flags: Flags describing the (encryption) state of the TPM state blob + */ +static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, + uint32_t type, + TPMSizedBuffer *tsb, + uint32_t flags) +{ + uint32_t offset =3D 0; + ssize_t n; + ptm_setstate pss; + ptm_res tpm_result; + + if (tsb->size =3D=3D 0) { + return 0; + } + + pss =3D (ptm_setstate) { + .u.req.state_flags =3D cpu_to_be32(flags), + .u.req.type =3D cpu_to_be32(type), + .u.req.length =3D cpu_to_be32(tsb->size), + }; + + /* write the header only */ + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_STATEBLOB, &pss, + offsetof(ptm_setstate, u.req.data), 0) < 0) { + error_report("tpm-emulator: could not set state blob type %d : %s", + type, strerror(errno)); + return -1; + } + + /* now the body */ + n =3D qemu_chr_fe_write_all(&tpm_emu->ctrl_chr, + &tsb->buffer[offset], tsb->size); + if (n !=3D tsb->size) { + error_report("tpm-emulator: Writing the stateblob (type %d) " + "failed: %s", type, strerror(errno)); + return -1; + } + + /* now get the result */ + n =3D qemu_chr_fe_read_all(&tpm_emu->ctrl_chr, + (uint8_t *)&pss, sizeof(pss.u.resp)); + if (n !=3D sizeof(pss.u.resp)) { + error_report("tpm-emulator: Reading response from writing stateblo= b " + "(type %d) failed: %s", type, strerror(errno)); + return -1; + } + + tpm_result =3D be32_to_cpu(pss.u.resp.tpm_result); + if (tpm_result !=3D 0) { + error_report("tpm-emulator: Setting the stateblob (type %d) failed= " + "with a TPM error 0x%x", type, tpm_result); + return -1; + } + + DPRINTF("set the state blob type %d, %d bytes, flags 0x%08x\n", + type, tsb->size, flags); + + return 0; +} + +static int tpm_emulator_set_state_blobs(TPMBackend *tb) +{ + TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + TPMBlobBuffers *state_blobs =3D &tpm_emu->state_blobs; + + DPRINTF("%s: %d", __func__, __LINE__); + + if (tpm_emulator_stop_tpm(tb) < 0) { + return -1; + } + + if (tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_PERMANENT, + &state_blobs->permanent, + state_blobs->permanent_flags) < 0 || + tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_VOLATILE, + &state_blobs->volatil, + state_blobs->volatil_flags) < 0 || + tpm_emulator_set_state_blob(tpm_emu, PTM_BLOB_TYPE_SAVESTATE, + &state_blobs->savestate, + state_blobs->savestate_flags) < 0) { + return -1; + } + + DPRINTF("DONE SETTING STATEBLOBS"); + + return 0; +} + +static int tpm_emulator_pre_save(void *opaque) +{ + TPMBackend *tb =3D opaque; + TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + + DPRINTF("%s", __func__); + + tpm_backend_wait_cmd_completed(tb); + + /* get the state blobs from the TPM */ + return tpm_emulator_get_state_blobs(tpm_emu); +} + +static int tpm_emulator_post_load(void *opaque, + int version_id __attribute__((unused))) +{ + TPMBackend *tb =3D opaque; + + if (tpm_emulator_set_state_blobs(tb) < 0) { + return 1; + } + + return _tpm_emulator_startup_tpm(tb, 0, true); +} + +static const VMStateDescription vmstate_tpm_emulator =3D { + .name =3D "tpm-emulator", + .version_id =3D 1, + .minimum_version_id =3D 0, + .minimum_version_id_old =3D 0, + .pre_save =3D tpm_emulator_pre_save, + .post_load =3D tpm_emulator_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(state_blobs.permanent_flags, TPMEmulator), + VMSTATE_UINT32(state_blobs.permanent.size, TPMEmulator), + VMSTATE_VBUFFER_ALLOC_UINT32(state_blobs.permanent.buffer, + TPMEmulator, 1, 0, + state_blobs.permanent.size), + + VMSTATE_UINT32(state_blobs.volatil_flags, TPMEmulator), + VMSTATE_UINT32(state_blobs.volatil.size, TPMEmulator), + VMSTATE_VBUFFER_ALLOC_UINT32(state_blobs.volatil.buffer, + TPMEmulator, 1, 0, + state_blobs.volatil.size), + + VMSTATE_UINT32(state_blobs.savestate_flags, TPMEmulator), + VMSTATE_UINT32(state_blobs.savestate.size, TPMEmulator), + VMSTATE_VBUFFER_ALLOC_UINT32(state_blobs.savestate.buffer, + TPMEmulator, 1, 0, + state_blobs.savestate.size), + + VMSTATE_END_OF_LIST() + } +}; + static void tpm_emulator_inst_init(Object *obj) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(obj); @@ -580,7 +858,10 @@ static void tpm_emulator_inst_init(Object *obj) DPRINTF("%s", __func__); tpm_emu->options =3D g_new0(TPMEmulatorOptions, 1); tpm_emu->cur_locty_number =3D ~0; + qemu_mutex_init(&tpm_emu->mutex); + + vmstate_register(NULL, -1, &vmstate_tpm_emulator, obj); } =20 /* @@ -617,6 +898,8 @@ static void tpm_emulator_inst_finalize(Object *obj) } =20 qemu_mutex_destroy(&tpm_emu->mutex); + + vmstate_unregister(NULL, &vmstate_tpm_emulator, obj); } =20 static void tpm_emulator_class_init(ObjectClass *klass, void *data) --=20 2.5.5 From nobody Sun Apr 28 19:03:08 2024 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 1510323590749489.782107191966; Fri, 10 Nov 2017 06:19:50 -0800 (PST) Received: from localhost ([::1]:41988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA9o-0001mW-QE for importer@patchew.org; Fri, 10 Nov 2017 09:19:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDA2n-00045h-Kq for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDA2j-0005PQ-62 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:29 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52780 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eDA2i-0005OT-WC for qemu-devel@nongnu.org; Fri, 10 Nov 2017 09:12:25 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAAEA17n099245 for ; Fri, 10 Nov 2017 09:12:21 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e59mu3xty-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 10 Nov 2017 09:12:20 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Nov 2017 07:12:19 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 10 Nov 2017 07:12:17 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAAECGvu2752970; Fri, 10 Nov 2017 07:12:16 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC011C603C; Fri, 10 Nov 2017 07:12:16 -0700 (MST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 6EF46C6043; Fri, 10 Nov 2017 07:12:16 -0700 (MST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Fri, 10 Nov 2017 09:11:52 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111014-0012-0000-0000-000015463032 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008044; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943880; UDB=6.00476265; IPR=6.00724163; BA=6.00005686; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017951; XFM=3.00000015; UTC=2017-11-10 14:12:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111014-0013-0000-0000-00005036C1F9 Message-Id: <1510323112-2207-14-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-10_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711100198 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v3 13/13] tpm_tis: extend TPM TIS 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, 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" Extend the TPM TIS interface with state migration support. 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. Since only 1 locality can be active at any time we only need to store the command buffer of that active locality. Signed-off-by: Stefan Berger --- hw/tpm/tpm_tis.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 86e9a92..c0a0204 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -393,12 +393,8 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t lo= cty, uint8_t newlocty) tpm_tis_abort(s, locty); } =20 -/* - * Callback from the TPM to indicate that the response was received. - */ -static void tpm_tis_request_completed(TPMIf *ti) +static void _tpm_tis_request_completed(TPMState *s) { - TPMState *s =3D TPM(ti); uint8_t locty =3D s->cmd.locty; uint8_t l; =20 @@ -431,6 +427,14 @@ static void tpm_tis_request_completed(TPMIf *ti) } =20 /* + * Callback from the TPM to indicate that the response was received. + */ +static void tpm_tis_request_completed(TPMIf *ti) +{ + _tpm_tis_request_completed(TPM(ti)); +} + +/* * Read a byte of response data */ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) @@ -1012,9 +1016,67 @@ static void tpm_tis_reset(DeviceState *dev) tpm_tis_do_startup_tpm(s, s->be_buffer_size); } =20 +/* persistent state handling */ + +static int tpm_tis_pre_save(void *opaque) +{ + TPMState *s =3D opaque; + uint8_t locty =3D s->active_locty; + + DPRINTF("tpm_tis: suspend: locty =3D %d : rw_offset =3D %u\n", + locty, s->rw_offset); +#ifdef DEBUG_TIS + tpm_tis_dump_state(opaque, 0); +#endif + + /* + * Synchronize with backend completion. + */ + tpm_backend_wait_cmd_completed(s->be_driver); + + if (TPM_TIS_IS_VALID_LOCTY(locty) && + s->loc[locty].state =3D=3D TPM_TIS_STATE_EXECUTION) { + /* bottom half did not run - run its function */ + _tpm_tis_request_completed(s); + } + + return 0; +} + +static const VMStateDescription vmstate_locty =3D { + .name =3D "loc", + .version_id =3D 1, + .minimum_version_id =3D 0, + .minimum_version_id_old =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(state, TPMLocality), + VMSTATE_UINT32(inte, TPMLocality), + VMSTATE_UINT32(ints, TPMLocality), + VMSTATE_UINT8(access, TPMLocality), + VMSTATE_UINT32(sts, TPMLocality), + VMSTATE_UINT32(iface_id, TPMLocality), + VMSTATE_END_OF_LIST(), + } +}; + static const VMStateDescription vmstate_tpm_tis =3D { .name =3D "tpm", - .unmigratable =3D 1, + .version_id =3D 1, + .minimum_version_id =3D 0, + .minimum_version_id_old =3D 0, + .pre_save =3D tpm_tis_pre_save, + .fields =3D (VMStateField[]) { + VMSTATE_BUFFER(buffer, TPMState), + VMSTATE_UINT16(rw_offset, TPMState), + VMSTATE_UINT8(active_locty, TPMState), + VMSTATE_UINT8(aborting_locty, TPMState), + VMSTATE_UINT8(next_locty, TPMState), + + VMSTATE_STRUCT_ARRAY(loc, TPMState, TPM_TIS_NUM_LOCALITIES, 1, + vmstate_locty, TPMLocality), + + VMSTATE_END_OF_LIST() + } }; =20 static Property tpm_tis_properties[] =3D { --=20 2.5.5