From nobody Sat May 4 21:08:19 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 1510016453002758.6165153422043; Mon, 6 Nov 2017 17:00:53 -0800 (PST) Received: from localhost ([::1]:50887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsFx-0006EH-3F for importer@patchew.org; Mon, 06 Nov 2017 20:00:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEU-0005J6-3j for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsEQ-0003mG-Te for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37214 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 1eBsEQ-0003m1-Nc for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:10 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70sC2V063508 for ; Mon, 6 Nov 2017 19:59:05 -0500 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e31k7k523-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:05 -0500 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:04 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:02 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x2L941550062; Tue, 7 Nov 2017 00:59:02 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46465AC040; Mon, 6 Nov 2017 19:59:51 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 2FBC0AC03A; Mon, 6 Nov 2017 19:59:51 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:52 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-0036-0000-0000-00000287BE9D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-0037-0000-0000-0000424E1A3C Message-Id: <1510016336-4086-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , 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-1711070011 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 1/5] tpm: Move getting TPM buffer size to backends 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" Rather than setting the size of the TPM buffer in the front-end, query the backend for the size of the buffer. In this patch we just move the hard-coded buffer size of 4096 to the backends. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- backends/tpm.c | 9 +++++++++ hw/tpm/tpm_emulator.c | 6 ++++++ hw/tpm/tpm_passthrough.c | 6 ++++++ hw/tpm/tpm_tis.c | 12 +++++++----- include/sysemu/tpm_backend.h | 11 +++++++++++ 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/backends/tpm.c b/backends/tpm.c index 7777467..e7d0f9a 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -139,6 +139,15 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s) return k->get_tpm_version(s); } =20 +uint32_t tpm_backend_get_buffer_size(TPMBackend *s) +{ + TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); + + assert(k->get_buffer_size); + + return k->get_buffer_size(s); +} + TPMInfo *tpm_backend_query_tpm(TPMBackend *s) { TPMInfo *info =3D g_new0(TPMInfo, 1); diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 24cb611..5a6107e 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -356,6 +356,11 @@ static TPMVersion tpm_emulator_get_tpm_version(TPMBack= end *tb) return tpm_emu->tpm_version; } =20 +static uint32_t tpm_emulator_get_buffer_size(TPMBackend *tb) +{ + return 4096; +} + static int tpm_emulator_block_migration(TPMEmulator *tpm_emu) { Error *err =3D NULL; @@ -556,6 +561,7 @@ static void tpm_emulator_class_init(ObjectClass *klass,= void *data) tbc->get_tpm_established_flag =3D tpm_emulator_get_tpm_established_fla= g; tbc->reset_tpm_established_flag =3D tpm_emulator_reset_tpm_established= _flag; tbc->get_tpm_version =3D tpm_emulator_get_tpm_version; + tbc->get_buffer_size =3D tpm_emulator_get_buffer_size; tbc->get_tpm_options =3D tpm_emulator_get_tpm_options; =20 tbc->handle_request =3D tpm_emulator_handle_request; diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 73554aa..7ff9249 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -199,6 +199,11 @@ static TPMVersion tpm_passthrough_get_tpm_version(TPMB= ackend *tb) return tpm_pt->tpm_version; } =20 +static uint32_t tpm_passthrough_get_buffer_size(TPMBackend *tb) +{ + return 4096; +} + /* * Unless path or file descriptor set has been provided by user, * determine the sysfs cancel file following kernel documentation @@ -354,6 +359,7 @@ static void tpm_passthrough_class_init(ObjectClass *kla= ss, void *data) tbc->reset_tpm_established_flag =3D tpm_passthrough_reset_tpm_established_flag; tbc->get_tpm_version =3D tpm_passthrough_get_tpm_version; + tbc->get_buffer_size =3D tpm_passthrough_get_buffer_size; tbc->get_tpm_options =3D tpm_passthrough_get_tpm_options; tbc->handle_request =3D tpm_passthrough_handle_request; } diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index cc32fcd..a3df40f 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -88,6 +88,8 @@ typedef struct TPMState { =20 TPMBackend *be_driver; TPMVersion be_tpm_version; + + uint32_t be_buffer_size; } TPMState; =20 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -977,10 +979,9 @@ static int tpm_tis_do_startup_tpm(TPMState *s) return tpm_backend_startup_tpm(s->be_driver); } =20 -static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb) +static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb, + uint32_t wanted_size) { - size_t wanted_size =3D 4096; /* Linux tpm.c buffer size */ - if (sb->size !=3D wanted_size) { sb->buffer =3D g_realloc(sb->buffer, wanted_size); sb->size =3D wanted_size; @@ -1007,6 +1008,7 @@ 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); =20 tpm_backend_reset(s->be_driver); =20 @@ -1033,9 +1035,9 @@ 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); + 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); + tpm_tis_realloc_buffer(&s->loc[c].r_buffer, s->be_buffer_size); } =20 tpm_tis_do_startup_tpm(s); diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 590e8b4..d23cef2 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -80,6 +80,7 @@ struct TPMBackendClass { int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty); =20 TPMVersion (*get_tpm_version)(TPMBackend *t); + uint32_t (*get_buffer_size)(TPMBackend *t); =20 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t); =20 @@ -183,6 +184,16 @@ int tpm_backend_reset_tpm_established_flag(TPMBackend = *s, uint8_t locty); TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); =20 /** + * tpm_backend_get_buffer_size: + * @s: the backend to call into + * + * Get the TPM's buffer size. + * + * Returns buffer size. + */ +uint32_t tpm_backend_get_buffer_size(TPMBackend *s); + +/** * tpm_backend_query_tpm: * @s: the backend * --=20 2.5.5 From nobody Sat May 4 21:08:19 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 151001659682464.21121510312776; Mon, 6 Nov 2017 17:03:16 -0800 (PST) Received: from localhost ([::1]:50897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsIB-000887-Rx for importer@patchew.org; Mon, 06 Nov 2017 20:03:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEU-0005JO-Kc for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsER-0003mj-FL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40986 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 1eBsER-0003mM-AH for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:11 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70sGBD065383 for ; Mon, 6 Nov 2017 19:59:07 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e31y4t6vg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:07 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:06 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:03 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x2Rw51380332; Tue, 7 Nov 2017 00:59:03 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F450AC04A; Mon, 6 Nov 2017 19:59:52 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 3CEB1AC040; Mon, 6 Nov 2017 19:59:52 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:53 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-0040-0000-0000-000003BE6036 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-0041-0000-0000-000007B37866 Message-Id: <1510016336-4086-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , 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-1711070011 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 2/5] tpm: pull tpm_util_send() out of tpm_util_test() 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_util.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index daf1faa..396e793 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -53,10 +53,11 @@ bool tpm_util_is_selftest(const uint8_t *in, uint32_t i= n_len) * A basic test of a TPM device. We expect a well formatted response header * (error response is fine) within one second. */ -static int tpm_util_test(int fd, - unsigned char *request, - size_t requestlen, - uint16_t *return_tag) +static int tpm_util_tx(int fd, + unsigned char *request, + size_t requestlen, + unsigned char *response, + size_t responselen) { struct tpm_resp_hdr *resp; fd_set readfds; @@ -65,7 +66,6 @@ static int tpm_util_test(int fd, .tv_sec =3D 1, .tv_usec =3D 0, }; - unsigned char buf[1024]; =20 n =3D write(fd, request, requestlen); if (n < 0) { @@ -84,17 +84,36 @@ static int tpm_util_test(int fd, return -errno; } =20 - n =3D read(fd, &buf, sizeof(buf)); + n =3D read(fd, response, responselen); if (n < sizeof(struct tpm_resp_hdr)) { return -EFAULT; } =20 - resp =3D (struct tpm_resp_hdr *)buf; + resp =3D (struct tpm_resp_hdr *)response; /* check the header */ if (be32_to_cpu(resp->len) !=3D n) { return -EMSGSIZE; } =20 + return 0; +} + +static int tpm_util_test(int fd, + unsigned char *request, + size_t requestlen, + uint16_t *return_tag) +{ + struct tpm_resp_hdr *resp; + unsigned char buf[1024]; + ssize_t ret; + + ret =3D tpm_util_tx(fd, request, requestlen, + buf, sizeof(buf)); + if (ret < 0) { + return ret; + } + + resp =3D (struct tpm_resp_hdr *)buf; *return_tag =3D be16_to_cpu(resp->tag); =20 return 0; --=20 2.5.5 From nobody Sat May 4 21:08:19 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 1510016510964603.537609613862; Mon, 6 Nov 2017 17:01:50 -0800 (PST) Received: from localhost ([::1]:50893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsGi-0006op-9n for importer@patchew.org; Mon, 06 Nov 2017 20:01:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEU-0005J5-2k for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsEQ-0003mB-SP for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37212 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 1eBsEQ-0003m0-NS for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:10 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70sDAk063540 for ; Mon, 6 Nov 2017 19:59:08 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e31k7k53s-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:08 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:07 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:04 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x4dj41812132; Tue, 7 Nov 2017 00:59:04 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DC05AC048; Mon, 6 Nov 2017 19:59:53 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 40AA8AC041; Mon, 6 Nov 2017 19:59:53 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:54 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-2213-0000-0000-0000023764B8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-2214-0000-0000-00005814E86D Message-Id: <1510016336-4086-4-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , 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-1711070011 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 3/5] tpm: tpm_passthrough: Read the buffer size from the host device 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" Rather than hard coding the buffer size in the tpm_passthrough backend read the TPM I/O buffer size from the host device. Signed-off-by: Stefan Berger --- hw/tpm/tpm_int.h | 9 ++++ hw/tpm/tpm_passthrough.c | 11 ++++- hw/tpm/tpm_util.c | 116 +++++++++++++++++++++++++++++++++++++++++++= ++++ hw/tpm/tpm_util.h | 3 ++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 1df5883..f838535 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -45,11 +45,20 @@ struct tpm_resp_hdr { =20 #define TPM_ORD_ContinueSelfTest 0x53 #define TPM_ORD_GetTicks 0xf1 +#define TPM_ORD_GetCapability 0x65 =20 +#define TPM_CAP_PROPERTY 0x05 + +#define TPM_CAP_PROP_INPUT_BUFFER 0x124 =20 /* TPM2 defines */ #define TPM2_ST_NO_SESSIONS 0x8001 =20 #define TPM2_CC_ReadClock 0x00000181 +#define TPM2_CC_GetCapability 0x0000017a + +#define TPM2_CAP_TPM_PROPERTIES 0x6 + +#define TPM2_PT_INPUT_BUFFER 0x10d =20 #endif /* TPM_TPM_INT_H */ diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 7ff9249..ec755fe 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -57,6 +57,7 @@ struct TPMPassthruState { int cancel_fd; =20 TPMVersion tpm_version; + uint32_t tpm_buffersize; }; =20 typedef struct TPMPassthruState TPMPassthruState; @@ -201,7 +202,15 @@ static TPMVersion tpm_passthrough_get_tpm_version(TPMB= ackend *tb) =20 static uint32_t tpm_passthrough_get_buffer_size(TPMBackend *tb) { - return 4096; + TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); + int ret; + + ret =3D tpm_util_get_buffer_size(tpm_pt->tpm_fd, tpm_pt->tpm_version, + &tpm_pt->tpm_buffersize); + if (ret < 0) { + tpm_pt->tpm_buffersize =3D 4096; + } + return tpm_pt->tpm_buffersize; } =20 /* diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index 396e793..3c861ab 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -20,10 +20,19 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "tpm_util.h" #include "tpm_int.h" #include "exec/memory.h" =20 +#define DEBUG_TPM 0 + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_TPM) { \ + fprintf(stderr, "tpm-util:"fmt"\n", ## __VA_ARGS__); \ + } \ +} while (0) + /* * Write an error message in the given output buffer. */ @@ -170,3 +179,110 @@ int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_= version) =20 return 1; } + +int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_version, + uint32_t *buffersize) +{ + unsigned char buf[1024]; + const struct tpm_req_get_buffer_size { + struct tpm_req_hdr hdr; + uint32_t capability; + uint32_t len; + uint32_t subcap; + } QEMU_PACKED tpm_get_buffer_size =3D { + .hdr =3D { + .tag =3D cpu_to_be16(TPM_TAG_RQU_COMMAND), + .len =3D cpu_to_be32(sizeof(tpm_get_buffer_size)), + .ordinal =3D cpu_to_be32(TPM_ORD_GetCapability), + }, + .capability =3D cpu_to_be32(TPM_CAP_PROPERTY), + .len =3D cpu_to_be32(sizeof(uint32_t)), + .subcap =3D cpu_to_be32(TPM_CAP_PROP_INPUT_BUFFER), + }; + const struct tpm2_req_get_buffer_size { + struct tpm_req_hdr hdr; + uint32_t capability; + uint32_t property; + uint32_t count; + } QEMU_PACKED tpm2_get_buffer_size =3D { + .hdr =3D { + .tag =3D cpu_to_be16(TPM2_ST_NO_SESSIONS), + .len =3D cpu_to_be32(sizeof(tpm2_get_buffer_size)), + .ordinal =3D cpu_to_be32(TPM2_CC_GetCapability), + }, + .capability =3D cpu_to_be32(TPM2_CAP_TPM_PROPERTIES), + .property =3D cpu_to_be32(TPM2_PT_INPUT_BUFFER), + .count =3D cpu_to_be32(1), + }; + struct tpm_resp_get_buffer_size { + struct tpm_resp_hdr hdr; + uint32_t len; + uint32_t buffersize; + } QEMU_PACKED *tpm_resp =3D (struct tpm_resp_get_buffer_size *)buf; + struct tpm2_resp_get_buffer_size { + struct tpm_resp_hdr hdr; + uint8_t more; + uint32_t capability; + uint32_t count; + uint32_t property; + uint32_t value; + } QEMU_PACKED *tpm2_resp =3D (struct tpm2_resp_get_buffer_size *)buf; + unsigned char *request =3D NULL; + size_t requestlen; + int ret; + + switch (tpm_version) { + case TPM_VERSION_1_2: + request =3D (unsigned char *)&tpm_get_buffer_size; + requestlen =3D sizeof(tpm_get_buffer_size); + break; + case TPM_VERSION_2_0: + request =3D (unsigned char *)&tpm2_get_buffer_size; + requestlen =3D sizeof(tpm2_get_buffer_size); + break; + case TPM_VERSION_UNSPEC: + return -EFAULT; + } + + ret =3D tpm_util_tx(tpm_fd, request, requestlen, buf, sizeof(buf)); + if (ret < 0) { + return ret; + } + + switch (tpm_version) { + case TPM_VERSION_1_2: + if (be32_to_cpu(tpm_resp->hdr.len) !=3D sizeof(*tpm_resp) || + be32_to_cpu(tpm_resp->len) !=3D sizeof(uint32_t)) { + DPRINTF("tpm_resp->hdr.len =3D %u, expected =3D %zu\n", + be32_to_cpu(tpm_resp->hdr.len), sizeof(*tpm_resp)); + DPRINTF("tpm_resp->len =3D %u, expected =3D %zu\n", + be32_to_cpu(tpm_resp->len), sizeof(uint32_t)); + error_report("tpm_util: Got malformed response to " + "TPM_GetCapability; errcode: 0x%x", + be32_to_cpu(tpm_resp->hdr.errcode)); + return -EFAULT; + } + *buffersize =3D be32_to_cpu(tpm_resp->buffersize); + break; + case TPM_VERSION_2_0: + if (be32_to_cpu(tpm2_resp->hdr.len) !=3D sizeof(*tpm2_resp) || + be32_to_cpu(tpm2_resp->count) !=3D 1) { + DPRINTF("tpm2_resp->hdr.len =3D %u, expected =3D %zu\n", + be32_to_cpu(tpm2_resp->hdr.len), sizeof(*tpm2_resp)); + DPRINTF("tpm2_resp->len =3D %u, expected =3D %u\n", + be32_to_cpu(tpm2_resp->count), 1); + error_report("tpm_util: Got malformed response to " + "TPM2_GetCapability; errcode: 0x%x", + be32_to_cpu(tpm2_resp->hdr.errcode)); + return -EFAULT; + } + *buffersize =3D be32_to_cpu(tpm2_resp->value); + break; + case TPM_VERSION_UNSPEC: + break; + } + + DPRINTF("buffersize of device: %u\n", *buffersize); + + return 0; +} diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index aca10c9..e4fba32 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -36,4 +36,7 @@ static inline uint32_t tpm_cmd_get_size(const void *b) return be32_to_cpu(*(const uint32_t *)(b + 2)); } =20 +int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_version, + uint32_t *buffersize); + #endif /* TPM_TPM_UTIL_H */ --=20 2.5.5 From nobody Sat May 4 21:08:19 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 1510016600394491.2343152665435; Mon, 6 Nov 2017 17:03:20 -0800 (PST) Received: from localhost ([::1]:50898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsIM-0008Ea-Iy for importer@patchew.org; Mon, 06 Nov 2017 20:03:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEd-0005QY-T9 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsEa-0003sI-KE for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:23 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37714) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBsEa-0003rf-CG for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:20 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70wWP6129436 for ; Mon, 6 Nov 2017 19:59:11 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e30v7ctwx-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:10 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:08 -0500 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:05 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x5UP34996322; Tue, 7 Nov 2017 00:59:05 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 665F5AC043; Mon, 6 Nov 2017 19:59:54 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 4E413AC041; Mon, 6 Nov 2017 19:59:54 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:55 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-0008-0000-0000-0000029C5D97 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-0009-0000-0000-0000373BA6CC Message-Id: <1510016336-4086-5-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , 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-1711070011 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 4/5] tpm: tpm_emulator: get and set buffer size of device 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" Convert the tpm_emulator backend to get the current buffer size of the external device and set it to the buffer size that the frontend (TIS) requests. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- backends/tpm.c | 4 +-- hw/tpm/tpm_emulator.c | 79 ++++++++++++++++++++++++++++++++++++++++= +--- hw/tpm/tpm_ioctl.h | 28 +++++++++++++++- hw/tpm/tpm_tis.c | 6 ++-- include/sysemu/tpm_backend.h | 6 ++-- 5 files changed, 111 insertions(+), 12 deletions(-) diff --git a/backends/tpm.c b/backends/tpm.c index e7d0f9a..f024c27 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -68,7 +68,7 @@ int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error *= *errp) return 0; } =20 -int tpm_backend_startup_tpm(TPMBackend *s) +int tpm_backend_startup_tpm(TPMBackend *s, uint32_t buffersize) { int res =3D 0; TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); @@ -79,7 +79,7 @@ int tpm_backend_startup_tpm(TPMBackend *s) s->thread_pool =3D g_thread_pool_new(tpm_backend_worker_thread, s, 1, = TRUE, NULL); =20 - res =3D k->startup_tpm ? k->startup_tpm(s) : 0; + res =3D k->startup_tpm ? k->startup_tpm(s, buffersize) : 0; =20 s->had_startup_error =3D (res !=3D 0); =20 diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 5a6107e..a16de7a 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -232,13 +232,14 @@ static int tpm_emulator_check_caps(TPMEmulator *tpm_e= mu) switch (tpm_emu->tpm_version) { case TPM_VERSION_1_2: caps =3D PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLIS= HED | - PTM_CAP_SET_LOCALITY | PTM_CAP_SET_DATAFD; + PTM_CAP_SET_LOCALITY | PTM_CAP_SET_DATAFD | PTM_CAP_STOP | + PTM_CAP_SET_BUFFERSIZE; tpm =3D "1.2"; break; case TPM_VERSION_2_0: caps =3D PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLIS= HED | PTM_CAP_SET_LOCALITY | PTM_CAP_RESET_TPMESTABLISHED | - PTM_CAP_SET_DATAFD; + PTM_CAP_SET_DATAFD | PTM_CAP_STOP | PTM_CAP_SET_BUFFERSIZE; tpm =3D "2"; break; case TPM_VERSION_UNSPEC: @@ -255,12 +256,76 @@ static int tpm_emulator_check_caps(TPMEmulator *tpm_e= mu) return 0; } =20 -static int tpm_emulator_startup_tpm(TPMBackend *tb) +static int tpm_emulator_stop_tpm(TPMBackend *tb) +{ + TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + ptm_res res; + + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_STOP, &res, 0, sizeof(res)) < 0)= { + error_report("tpm-emulator: Could not stop TPM: %s", + strerror(errno)); + return -1; + } + + res =3D be32_to_cpu(res); + if (res) { + error_report("tpm-emulator: TPM result for CMD_STOP: 0x%x", res); + return -1; + } + + return 0; +} + +static int tpm_emulator_set_buffer_size(TPMBackend *tb, + uint32_t wanted_size, + uint32_t *actual_size) +{ + TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + ptm_setbuffersize psbs; + + if (tpm_emulator_stop_tpm(tb) < 0) { + return -1; + } + + psbs.u.req.buffersize =3D cpu_to_be32(wanted_size); + + if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_BUFFERSIZE, &psbs, + sizeof(psbs.u.req), sizeof(psbs.u.resp)) < 0)= { + error_report("tpm-emulator: Could not set buffer size: %s", + strerror(errno)); + return -1; + } + + psbs.u.resp.tpm_result =3D be32_to_cpu(psbs.u.resp.tpm_result); + if (psbs.u.resp.tpm_result !=3D 0) { + error_report("tpm-emulator: TPM result for set buffer size : 0x%x", + psbs.u.resp.tpm_result); + return -1; + } + + if (actual_size) { + *actual_size =3D be32_to_cpu(psbs.u.resp.buffersize); + } + + DPRINTF("buffer size: %u, min: %u, max: %u\n", + be32_to_cpu(psbs.u.resp.buffersize), + be32_to_cpu(psbs.u.resp.minsize), + be32_to_cpu(psbs.u.resp.maxsize)); + + return 0; +} + +static int tpm_emulator_startup_tpm(TPMBackend *tb, uint32_t buffersize) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_init init; ptm_res res; =20 + if (buffersize !=3D 0 && + tpm_emulator_set_buffer_size(tb, buffersize, NULL) < 0) { + goto err_exit; + } + DPRINTF("%s", __func__); if (tpm_emulator_ctrlcmd(tpm_emu, CMD_INIT, &init, sizeof(init), sizeof(init)) < 0) { @@ -358,7 +423,13 @@ static TPMVersion tpm_emulator_get_tpm_version(TPMBack= end *tb) =20 static uint32_t tpm_emulator_get_buffer_size(TPMBackend *tb) { - return 4096; + uint32_t actual_size; + + if (tpm_emulator_set_buffer_size(tb, 0, &actual_size) < 0) { + return 4096; + } + + return actual_size; } =20 static int tpm_emulator_block_migration(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_ioctl.h b/hw/tpm/tpm_ioctl.h index 33564b1..54c8d34 100644 --- a/hw/tpm/tpm_ioctl.h +++ b/hw/tpm/tpm_ioctl.h @@ -169,6 +169,28 @@ struct ptm_getconfig { #define PTM_CONFIG_FLAG_FILE_KEY 0x1 #define PTM_CONFIG_FLAG_MIGRATION_KEY 0x2 =20 +/* + * PTM_SET_BUFFERSIZE: Set the buffer size to be used by the TPM. + * A 0 on input queries for the current buffer size. Any other + * number will try to set the buffer size. The returned number is + * the buffer size that will be used, which can be larger than the + * requested one, if it was below the minimum, or smaller than the + * requested one, if it was above the maximum. + */ +struct ptm_setbuffersize { + union { + struct { + uint32_t buffersize; /* 0 to query for current buffer size */ + } req; /* request */ + struct { + ptm_res tpm_result; + uint32_t buffersize; /* buffer size in use */ + uint32_t minsize; /* min. supported buffer size */ + uint32_t maxsize; /* max. supported buffer size */ + } resp; /* response */ + } u; +}; + =20 typedef uint64_t ptm_cap; typedef struct ptm_est ptm_est; @@ -179,6 +201,7 @@ typedef struct ptm_init ptm_init; typedef struct ptm_getstate ptm_getstate; typedef struct ptm_setstate ptm_setstate; typedef struct ptm_getconfig ptm_getconfig; +typedef struct ptm_setbuffersize ptm_setbuffersize; =20 /* capability flags returned by PTM_GET_CAPABILITY */ #define PTM_CAP_INIT (1) @@ -194,6 +217,7 @@ typedef struct ptm_getconfig ptm_getconfig; #define PTM_CAP_STOP (1 << 10) #define PTM_CAP_GET_CONFIG (1 << 11) #define PTM_CAP_SET_DATAFD (1 << 12) +#define PTM_CAP_SET_BUFFERSIZE (1 << 13) =20 enum { PTM_GET_CAPABILITY =3D _IOR('P', 0, ptm_cap), @@ -212,6 +236,7 @@ enum { PTM_STOP =3D _IOR('P', 13, ptm_res), PTM_GET_CONFIG =3D _IOR('P', 14, ptm_getconfig), PTM_SET_DATAFD =3D _IOR('P', 15, ptm_res), + PTM_SET_BUFFERSIZE =3D _IOWR('P', 16, ptm_setbuffersize), }; =20 /* @@ -240,7 +265,8 @@ enum { CMD_SET_STATEBLOB, CMD_STOP, CMD_GET_CONFIG, - CMD_SET_DATAFD + CMD_SET_DATAFD, + CMD_SET_BUFFERSIZE, }; =20 #endif /* _TPM_IOCTL_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index a3df40f..8d7310e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -974,9 +974,9 @@ static const MemoryRegionOps tpm_tis_memory_ops =3D { }, }; =20 -static int tpm_tis_do_startup_tpm(TPMState *s) +static int tpm_tis_do_startup_tpm(TPMState *s, uint32_t buffersize) { - return tpm_backend_startup_tpm(s->be_driver); + return tpm_backend_startup_tpm(s->be_driver, buffersize); } =20 static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb, @@ -1040,7 +1040,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); + tpm_tis_do_startup_tpm(s, s->be_buffer_size); } =20 static const VMStateDescription vmstate_tpm_tis =3D { diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index d23cef2..3978d98 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -66,7 +66,7 @@ struct TPMBackendClass { TPMBackend *(*create)(QemuOpts *opts); =20 /* start up the TPM on the backend - optional */ - int (*startup_tpm)(TPMBackend *t); + int (*startup_tpm)(TPMBackend *t, uint32_t buffersize); =20 /* optional */ void (*reset)(TPMBackend *t); @@ -111,10 +111,12 @@ int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Err= or **errp); /** * tpm_backend_startup_tpm: * @s: the backend whose TPM support is to be started + * @buffersize: the buffer size the TPM is supposed to use, + * 0 to leave it as-is * * Returns 0 on success. */ -int tpm_backend_startup_tpm(TPMBackend *s); +int tpm_backend_startup_tpm(TPMBackend *s, uint32_t buffersize); =20 /** * tpm_backend_had_startup_error: --=20 2.5.5 From nobody Sat May 4 21:08:19 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 1510016455954652.808072864895; Mon, 6 Nov 2017 17:00:55 -0800 (PST) Received: from localhost ([::1]:50889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsG5-0006KW-9v for importer@patchew.org; Mon, 06 Nov 2017 20:00:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBsEa-0005NY-1q for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBsEW-0003pZ-RP for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:20 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42918 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 1eBsEW-0003pD-M4 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 19:59:16 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA70sDDd019429 for ; Mon, 6 Nov 2017 19:59:10 -0500 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e306j6pch-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 06 Nov 2017 19:59:10 -0500 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 6 Nov 2017 19:59:09 -0500 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 6 Nov 2017 19:59:06 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA70x6RV44040266; Tue, 7 Nov 2017 00:59:06 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AA82AC041; Mon, 6 Nov 2017 19:59:55 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 5E4E1AC03F; Mon, 6 Nov 2017 19:59:55 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Mon, 6 Nov 2017 19:58:56 -0500 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1510016336-4086-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17110700-0008-0000-0000-0000029C5D98 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008022; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00942183; UDB=6.00475248; IPR=6.00722471; BA=6.00005674; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017888; XFM=3.00000015; UTC=2017-11-07 00:59:08 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110700-0009-0000-0000-0000373BA6CF Message-Id: <1510016336-4086-6-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-06_08:, , 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-1711070011 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 5/5] tpm: tpm_passthrough: Fail startup if FE buffer size < BE buffer size 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" If the requested buffer size of the frontend is smaller than the fixed buffer size of the host's TPM, fail the startup_tpm() interface function, which will make the device unusable. We fail it because the backend TPM could produce larger packets than what the frontend could pass to the OS. The current combination of TIS frontend and either passthrough or emulator backend will not lead to this case since the TIS can support any size of buffer. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_passthrough.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index ec755fe..66d5098 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -304,6 +304,20 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *op= ts) return TPM_BACKEND(obj); } =20 +static int tpm_passthrough_startup_tpm(TPMBackend *tb, uint32_t buffersize) +{ + TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); + + if (buffersize && buffersize < tpm_pt->tpm_buffersize) { + error_report("Requested buffer size of %u is smaller than host TPM= 's " + "fixed buffer size of %u", + buffersize, tpm_pt->tpm_buffersize); + return -1; + } + + return 0; +} + static TpmTypeOptions *tpm_passthrough_get_tpm_options(TPMBackend *tb) { TpmTypeOptions *options =3D g_new0(TpmTypeOptions, 1); @@ -362,6 +376,7 @@ static void tpm_passthrough_class_init(ObjectClass *kla= ss, void *data) tbc->opts =3D tpm_passthrough_cmdline_opts; tbc->desc =3D "Passthrough TPM backend driver"; tbc->create =3D tpm_passthrough_create; + tbc->startup_tpm =3D tpm_passthrough_startup_tpm; tbc->reset =3D tpm_passthrough_reset; tbc->cancel_cmd =3D tpm_passthrough_cancel_cmd; tbc->get_tpm_established_flag =3D tpm_passthrough_get_tpm_established_= flag; --=20 2.5.5