From nobody Sun Apr 28 04:08:33 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 15075900705761018.0308200363519; Mon, 9 Oct 2017 16:01:10 -0700 (PDT) Received: from localhost ([::1]:60143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h2o-0000Ge-Pz for importer@patchew.org; Mon, 09 Oct 2017 19:01:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyP-0005Jy-9R for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyN-0004jp-5R for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyM-0004iz-V3 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4F9861478; Mon, 9 Oct 2017 22:56:29 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68D6E67CF0; Mon, 9 Oct 2017 22:56:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D4F9861478 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:42 +0200 Message-Id: <20171009225623.29232-2-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 Oct 2017 22:56:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/42] tpm-tis: remove unused hw_access argument 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This argument is always false, simplify the code. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index d5118e7f60..a9e9cbdeb2 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -615,9 +615,8 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, * Write a value to a register of the TIS interface * See specs pages 33-63 for description of the registers */ -static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr, - uint64_t val, unsigned size, - bool hw_access) +static void tpm_tis_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) { TPMState *s =3D opaque; TPMTISEmuState *tis =3D &s->s.tis; @@ -631,7 +630,7 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwa= ddr addr, =20 DPRINTF("tpm_tis: write.%u(%08x) =3D %08x\n", size, (int)addr, (int)va= l); =20 - if (locty =3D=3D 4 && !hw_access) { + if (locty =3D=3D 4) { DPRINTF("tpm_tis: Access to locality 4 only allowed from hardware\= n"); return; } @@ -942,12 +941,6 @@ static void tpm_tis_mmio_write_intern(void *opaque, hw= addr addr, } } =20 -static void tpm_tis_mmio_write(void *opaque, hwaddr addr, - uint64_t val, unsigned size) -{ - tpm_tis_mmio_write_intern(opaque, addr, val, size, false); -} - static const MemoryRegionOps tpm_tis_memory_ops =3D { .read =3D tpm_tis_mmio_read, .write =3D tpm_tis_mmio_write, --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507589919006670.798561362149; Mon, 9 Oct 2017 15:58:39 -0700 (PDT) Received: from localhost ([::1]:60131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0I-0006X5-Ey for importer@patchew.org; Mon, 09 Oct 2017 18:58:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyT-0005LF-4i for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyS-0004m1-Ep for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyS-0004lf-6b for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FE7D80F97; Mon, 9 Oct 2017 22:56:35 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70ED162460; Mon, 9 Oct 2017 22:56:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2FE7D80F97 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:43 +0200 Message-Id: <20171009225623.29232-3-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:56:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/42] tpm-tis: remove RAISE_STS_IRQ 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This look like temporary hacking code. It shouldn't be necessary in release code, or there should be a runtime option for it. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index a9e9cbdeb2..c54dac32de 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -43,9 +43,6 @@ } \ } while (0); =20 -/* whether the STS interrupt is supported */ -#define RAISE_STS_IRQ - /* tis registers */ #define TPM_TIS_REG_ACCESS 0x00 #define TPM_TIS_REG_INT_ENABLE 0x08 @@ -98,21 +95,11 @@ #define TPM_TIS_INT_POLARITY_MASK (3 << 3) #define TPM_TIS_INT_POLARITY_LOW_LEVEL (1 << 3) =20 -#ifndef RAISE_STS_IRQ - -#define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ - TPM_TIS_INT_DATA_AVAILABLE | \ - TPM_TIS_INT_COMMAND_READY) - -#else - #define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \ TPM_TIS_INT_DATA_AVAILABLE | \ TPM_TIS_INT_STS_VALID | \ TPM_TIS_INT_COMMAND_READY) =20 -#endif - #define TPM_TIS_CAP_INTERFACE_VERSION1_3 (2 << 28) #define TPM_TIS_CAP_INTERFACE_VERSION1_3_FOR_TPM2_0 (3 << 28) #define TPM_TIS_CAP_DATA_TRANSFER_64B (3 << 9) @@ -377,12 +364,8 @@ static void tpm_tis_receive_bh(void *opaque) tpm_tis_abort(s, locty); } =20 -#ifndef RAISE_STS_IRQ - tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE); -#else tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); -#endif } =20 /* @@ -421,9 +404,7 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t = locty) if (tis->loc[locty].r_offset >=3D len) { /* got last byte */ tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID); -#ifdef RAISE_STS_IRQ tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); -#endif } DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x [%d]\n", ret, tis->loc[locty].r_offset-1); @@ -912,9 +893,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, if (tis->loc[locty].w_offset > 5 && (tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { /* we have a packet length - see if we have all of it */ -#ifdef RAISE_STS_IRQ bool need_irq =3D !(tis->loc[locty].sts & TPM_TIS_STS_VALI= D); -#endif + len =3D tpm_tis_get_size_from_buffer(&tis->loc[locty].w_bu= ffer); if (len > tis->loc[locty].w_offset) { tpm_tis_sts_set(&tis->loc[locty], @@ -923,11 +903,9 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr ad= dr, /* packet complete */ tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID); } -#ifdef RAISE_STS_IRQ if (need_irq) { tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); } -#endif } } break; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590080476390.2130180691139; Mon, 9 Oct 2017 16:01:20 -0700 (PDT) Received: from localhost ([::1]:60145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h2z-0000PC-NO for importer@patchew.org; Mon, 09 Oct 2017 19:01:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyZ-0005Pq-K7 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyW-0004ny-Eq for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyW-0004nd-8m for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46382C04AC6A; Mon, 9 Oct 2017 22:56:39 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id C38656BC01; Mon, 9 Oct 2017 22:56:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 46382C04AC6A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:44 +0200 Message-Id: <20171009225623.29232-4-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:56:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/42] tpm: make tpm_get_backend_driver() static 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No need to export the function. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 1 - tpm.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 2c798a1eb4..c6e5637f68 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -215,7 +215,6 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s); =20 TPMBackend *qemu_find_tpm(const char *id); =20 -const TPMDriverOps *tpm_get_backend_driver(const char *type); void tpm_register_model(enum TpmModel model); void tpm_register_driver(const TPMDriverOps *tdo); =20 diff --git a/tpm.c b/tpm.c index 3122227156..bc7d7470a8 100644 --- a/tpm.c +++ b/tpm.c @@ -31,7 +31,7 @@ void tpm_register_model(enum TpmModel model) tpm_models[model] =3D true; } =20 -const TPMDriverOps *tpm_get_backend_driver(const char *type) +static const TPMDriverOps *tpm_get_backend_driver(const char *type) { int i =3D qapi_enum_parse(&TpmType_lookup, type, -1, NULL); =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507589932774842.8157213633874; Mon, 9 Oct 2017 15:58:52 -0700 (PDT) Received: from localhost ([::1]:60132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0U-0006ix-4o for importer@patchew.org; Mon, 09 Oct 2017 18:58:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyZ-0005Pr-Km for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyY-0004ov-9o for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyY-0004oS-4N for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20677C04AC71; Mon, 9 Oct 2017 22:56:41 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id A833A17525; Mon, 9 Oct 2017 22:56:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 20677C04AC71 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:45 +0200 Message-Id: <20171009225623.29232-5-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:56:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/42] tpm: lookup tpm backend class in tpm_driver_find_by_type() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" One step towards removing TPMDriverOps and driver registration. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- tpm.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tpm.c b/tpm.c index bc7d7470a8..04de8da5fd 100644 --- a/tpm.c +++ b/tpm.c @@ -47,6 +47,24 @@ void tpm_register_driver(const TPMDriverOps *tdo) be_drivers[tdo->type] =3D tdo; } =20 +static const TPMDriverOps * +tpm_driver_find_by_type(enum TpmType type) +{ + ObjectClass *oc; + TPMBackendClass *bc; + char *typename =3D g_strdup_printf("tpm-%s", TpmType_str(type)); + + oc =3D object_class_by_name(typename); + g_free(typename); + + if (!object_class_dynamic_cast(oc, TYPE_TPM_BACKEND)) { + return NULL; + } + + bc =3D TPM_BACKEND_CLASS(oc); + return bc->ops; +} + /* * Walk the list of available TPM backend drivers and display them on the * screen. @@ -58,11 +76,11 @@ static void tpm_display_backend_drivers(void) fprintf(stderr, "Supported TPM types (choose only one):\n"); =20 for (i =3D 0; i < TPM_TYPE__MAX; i++) { - if (be_drivers[i] =3D=3D NULL) { + const TPMDriverOps *ops =3D tpm_driver_find_by_type(i); + if (!ops) { continue; } - fprintf(stderr, "%12s %s\n", - TpmType_str(i), be_drivers[i]->desc); + fprintf(stderr, "%12s %s\n", TpmType_str(i), ops->desc); } fprintf(stderr, "\n"); } @@ -196,11 +214,6 @@ int tpm_config_parse(QemuOptsList *opts_list, const ch= ar *optarg) =20 #endif /* CONFIG_TPM */ =20 -static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) -{ - return be_drivers[type]; -} - /* * Walk the list of active TPM backends and collect information about them * following the schema description in qapi-schema.json. --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590090829292.602869704888; Mon, 9 Oct 2017 16:01:30 -0700 (PDT) Received: from localhost ([::1]:60147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h3B-0000ZR-KW for importer@patchew.org; Mon, 09 Oct 2017 19:01:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyd-0005T6-U6 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyd-0004qe-43 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyc-0004qN-Tk for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD267C04AC6B; Mon, 9 Oct 2017 22:56:45 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 824ED17D43; Mon, 9 Oct 2017 22:56:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD267C04AC6B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:46 +0200 Message-Id: <20171009225623.29232-6-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:56:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/42] tpm: replace tpm_get_backend_driver() to drop be_drivers 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use tpm_driver_find_by_type() instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- tpm.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tpm.c b/tpm.c index 04de8da5fd..ad2ed6a0da 100644 --- a/tpm.c +++ b/tpm.c @@ -31,13 +31,6 @@ void tpm_register_model(enum TpmModel model) tpm_models[model] =3D true; } =20 -static const TPMDriverOps *tpm_get_backend_driver(const char *type) -{ - int i =3D qapi_enum_parse(&TpmType_lookup, type, -1, NULL); - - return i >=3D 0 ? be_drivers[i] : NULL; -} - #ifdef CONFIG_TPM =20 void tpm_register_driver(const TPMDriverOps *tdo) @@ -110,6 +103,7 @@ static int configure_tpm(QemuOpts *opts) const TPMDriverOps *be; TPMBackend *drv; Error *local_err =3D NULL; + int i; =20 if (!QLIST_EMPTY(&tpm_backends)) { error_report("Only one TPM is allowed."); @@ -129,7 +123,8 @@ static int configure_tpm(QemuOpts *opts) return 1; } =20 - be =3D tpm_get_backend_driver(value); + i =3D qapi_enum_parse(&TpmType_lookup, value, -1, NULL); + be =3D i >=3D 0 ? tpm_driver_find_by_type(i) : NULL; if (be =3D=3D NULL) { error_report(QERR_INVALID_PARAMETER_VALUE, "type", "a TPM backend type"); --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590393776920.8157944295693; Mon, 9 Oct 2017 16:06:33 -0700 (PDT) Received: from localhost ([::1]:60168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h81-0004nE-Rx for importer@patchew.org; Mon, 09 Oct 2017 19:06:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyk-0005XP-47 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyh-0004s9-03 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8557) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyg-0004rp-Ps for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B8FC2356DA; Mon, 9 Oct 2017 22:56:49 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BAAB4D757; Mon, 9 Oct 2017 22:56:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8FC2356DA Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:47 +0200 Message-Id: <20171009225623.29232-7-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 09 Oct 2017 22:56:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/42] tpm: remove tpm_register_driver() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No more users of be_drivers[], drop that too. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 1 - hw/tpm/tpm_emulator.c | 1 - hw/tpm/tpm_passthrough.c | 1 - tpm.c | 8 -------- 4 files changed, 11 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index c6e5637f68..adb6a68076 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -216,6 +216,5 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s); TPMBackend *qemu_find_tpm(const char *id); =20 void tpm_register_model(enum TpmModel model); -void tpm_register_driver(const TPMDriverOps *tdo); =20 #endif diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 5ddd7238d2..9e24a5f30e 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -581,7 +581,6 @@ static const TypeInfo tpm_emulator_info =3D { static void tpm_emulator_register(void) { type_register_static(&tpm_emulator_info); - tpm_register_driver(&tpm_emulator_driver); } =20 type_init(tpm_emulator_register) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index e6ace28b04..f04eab3e63 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -418,7 +418,6 @@ static const TypeInfo tpm_passthrough_info =3D { static void tpm_passthrough_register(void) { type_register_static(&tpm_passthrough_info); - tpm_register_driver(&tpm_passthrough_driver); } =20 type_init(tpm_passthrough_register) diff --git a/tpm.c b/tpm.c index ad2ed6a0da..75a589b837 100644 --- a/tpm.c +++ b/tpm.c @@ -23,7 +23,6 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =3D QLIST_HEAD_INITIALIZER(tpm_backends); =20 -static TPMDriverOps const *be_drivers[TPM_TYPE__MAX]; static bool tpm_models[TPM_MODEL__MAX]; =20 void tpm_register_model(enum TpmModel model) @@ -33,13 +32,6 @@ void tpm_register_model(enum TpmModel model) =20 #ifdef CONFIG_TPM =20 -void tpm_register_driver(const TPMDriverOps *tdo) -{ - assert(!be_drivers[tdo->type]); - - be_drivers[tdo->type] =3D tdo; -} - static const TPMDriverOps * tpm_driver_find_by_type(enum TpmType type) { --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590234844674.7534086410825; Mon, 9 Oct 2017 16:03:54 -0700 (PDT) Received: from localhost ([::1]:60154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h5T-0002a9-Ee for importer@patchew.org; Mon, 09 Oct 2017 19:03:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyk-0005XR-5n for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyi-0004t4-VQ for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48426) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyi-0004sb-PI for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF1F87EA8E; Mon, 9 Oct 2017 22:56:51 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209B260464; Mon, 9 Oct 2017 22:56:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BF1F87EA8E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:48 +0200 Message-Id: <20171009225623.29232-8-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 09 Oct 2017 22:56:51 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/42] tpm: move TPMSizedBuffer to tpm_tis.h 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Close to where it's being used. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.h | 5 +++++ include/sysemu/tpm_backend.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h index a1df41fa21..31e612a7f4 100644 --- a/hw/tpm/tpm_tis.h +++ b/hw/tpm/tpm_tis.h @@ -37,6 +37,11 @@ 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/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index adb6a68076..63093551a1 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -66,11 +66,6 @@ struct TPMBackendClass { void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd); }; =20 -typedef struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -} TPMSizedBuffer; - struct TPMDriverOps { enum TpmType type; const QemuOptDesc *opts; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590416904704.035809268198; Mon, 9 Oct 2017 16:06:56 -0700 (PDT) Received: from localhost ([::1]:60169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h8G-0004xa-2g for importer@patchew.org; Mon, 09 Oct 2017 19:06:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyn-0005a1-0z for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyl-0004u9-Ch for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyl-0004tx-3s for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15EEB7EA8C; Mon, 9 Oct 2017 22:56:54 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E81617525; Mon, 9 Oct 2017 22:56:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 15EEB7EA8C Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:49 +0200 Message-Id: <20171009225623.29232-9-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 09 Oct 2017 22:56:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/42] tpm: remove TPMDriverOps 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use TPMBackendClass to hold class methods/fields. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 15 +++++---------- backends/tpm.c | 31 ++++++++++++++++--------------- hw/tpm/tpm_emulator.c | 29 ++++++++++++----------------- hw/tpm/tpm_passthrough.c | 25 +++++++++++-------------- tpm.c | 20 +++++++++----------- scripts/checkpatch.pl | 1 - 6 files changed, 53 insertions(+), 68 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 63093551a1..a4288df038 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -29,7 +29,7 @@ =20 typedef struct TPMBackendClass TPMBackendClass; typedef struct TPMBackend TPMBackend; -typedef struct TPMDriverOps TPMDriverOps; + typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done= ); =20 typedef enum TPMBackendCmd { @@ -59,14 +59,6 @@ struct TPMBackend { struct TPMBackendClass { ObjectClass parent_class; =20 - const TPMDriverOps *ops; - - void (*opened)(TPMBackend *s, Error **errp); - - void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd); -}; - -struct TPMDriverOps { enum TpmType type; const QemuOptDesc *opts; /* get a descriptive text of the backend to display to the user */ @@ -90,8 +82,11 @@ struct TPMDriverOps { TPMVersion (*get_tpm_version)(TPMBackend *t); =20 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t); -}; =20 + void (*opened)(TPMBackend *s, Error **errp); + + void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd); +}; =20 /** * tpm_backend_get_type: diff --git a/backends/tpm.c b/backends/tpm.c index 37c84b7c66..ca3a78eea8 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -41,7 +41,7 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - return k->ops->type; + return k->type; } =20 int tpm_backend_init(TPMBackend *s, TPMState *state, @@ -53,7 +53,7 @@ int tpm_backend_init(TPMBackend *s, TPMState *state, s->recv_data_callback =3D datacb; s->had_startup_error =3D false; =20 - return k->ops->init ? k->ops->init(s) : 0; + return k->init ? k->init(s) : 0; } =20 int tpm_backend_startup_tpm(TPMBackend *s) @@ -68,7 +68,7 @@ int tpm_backend_startup_tpm(TPMBackend *s) NULL); g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NUL= L); =20 - res =3D k->ops->startup_tpm ? k->ops->startup_tpm(s) : 0; + res =3D k->startup_tpm ? k->startup_tpm(s) : 0; =20 s->had_startup_error =3D (res !=3D 0); =20 @@ -90,8 +90,8 @@ void tpm_backend_reset(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - if (k->ops->reset) { - k->ops->reset(s); + if (k->reset) { + k->reset(s); } =20 tpm_backend_thread_end(s); @@ -103,34 +103,34 @@ void tpm_backend_cancel_cmd(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - assert(k->ops->cancel_cmd); + assert(k->cancel_cmd); =20 - k->ops->cancel_cmd(s); + k->cancel_cmd(s); } =20 bool tpm_backend_get_tpm_established_flag(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - return k->ops->get_tpm_established_flag ? - k->ops->get_tpm_established_flag(s) : false; + return k->get_tpm_established_flag ? + k->get_tpm_established_flag(s) : false; } =20 int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - return k->ops->reset_tpm_established_flag ? - k->ops->reset_tpm_established_flag(s, locty) : 0; + return k->reset_tpm_established_flag ? + k->reset_tpm_established_flag(s, locty) : 0; } =20 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - assert(k->ops->get_tpm_version); + assert(k->get_tpm_version); =20 - return k->ops->get_tpm_version(s); + return k->get_tpm_version(s); } =20 TPMInfo *tpm_backend_query_tpm(TPMBackend *s) @@ -140,8 +140,9 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s) =20 info->id =3D g_strdup(s->id); info->model =3D s->fe_model; - info->options =3D k->ops->get_tpm_options ? - k->ops->get_tpm_options(s) : NULL; + if (k->get_tpm_options) { + info->options =3D k->get_tpm_options(s); + } =20 return info; } diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 9e24a5f30e..bb5a65b492 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -60,8 +60,6 @@ =20 #define TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(S, cap) (((S)->caps & (cap)) =3D= =3D (cap)) =20 -static const TPMDriverOps tpm_emulator_driver; - /* data structures */ typedef struct TPMEmulator { TPMBackend parent; @@ -504,20 +502,6 @@ static const QemuOptDesc tpm_emulator_cmdline_opts[] = =3D { { /* end of list */ }, }; =20 -static const TPMDriverOps tpm_emulator_driver =3D { - .type =3D TPM_TYPE_EMULATOR, - .opts =3D tpm_emulator_cmdline_opts, - .desc =3D "TPM emulator backend driver", - - .create =3D tpm_emulator_create, - .startup_tpm =3D tpm_emulator_startup_tpm, - .cancel_cmd =3D tpm_emulator_cancel_cmd, - .get_tpm_established_flag =3D tpm_emulator_get_tpm_established_flag, - .reset_tpm_established_flag =3D tpm_emulator_reset_tpm_established_fla= g, - .get_tpm_version =3D tpm_emulator_get_tpm_version, - .get_tpm_options =3D tpm_emulator_get_tpm_options, -}; - static void tpm_emulator_inst_init(Object *obj) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(obj); @@ -565,7 +549,18 @@ static void tpm_emulator_inst_finalize(Object *obj) static void tpm_emulator_class_init(ObjectClass *klass, void *data) { TPMBackendClass *tbc =3D TPM_BACKEND_CLASS(klass); - tbc->ops =3D &tpm_emulator_driver; + + tbc->type =3D TPM_TYPE_EMULATOR; + tbc->opts =3D tpm_emulator_cmdline_opts; + tbc->desc =3D "TPM emulator backend driver"; + tbc->create =3D tpm_emulator_create; + tbc->startup_tpm =3D tpm_emulator_startup_tpm; + tbc->cancel_cmd =3D tpm_emulator_cancel_cmd; + 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_tpm_options =3D tpm_emulator_get_tpm_options; + tbc->handle_request =3D tpm_emulator_handle_request; } =20 diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index f04eab3e63..d9da99bc8e 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -365,19 +365,6 @@ static const QemuOptDesc tpm_passthrough_cmdline_opts[= ] =3D { { /* end of list */ }, }; =20 -static const TPMDriverOps tpm_passthrough_driver =3D { - .type =3D TPM_TYPE_PASSTHROUGH, - .opts =3D tpm_passthrough_cmdline_opts, - .desc =3D "Passthrough TPM backend driver", - .create =3D tpm_passthrough_create, - .reset =3D tpm_passthrough_reset, - .cancel_cmd =3D tpm_passthrough_cancel_cmd, - .get_tpm_established_flag =3D tpm_passthrough_get_tpm_established_flag, - .reset_tpm_established_flag =3D tpm_passthrough_reset_tpm_established_= flag, - .get_tpm_version =3D tpm_passthrough_get_tpm_version, - .get_tpm_options =3D tpm_passthrough_get_tpm_options, -}; - static void tpm_passthrough_inst_init(Object *obj) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(obj); @@ -402,7 +389,17 @@ static void tpm_passthrough_class_init(ObjectClass *kl= ass, void *data) { TPMBackendClass *tbc =3D TPM_BACKEND_CLASS(klass); =20 - tbc->ops =3D &tpm_passthrough_driver; + tbc->type =3D TPM_TYPE_PASSTHROUGH; + tbc->opts =3D tpm_passthrough_cmdline_opts; + tbc->desc =3D "Passthrough TPM backend driver"; + tbc->create =3D tpm_passthrough_create; + 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; + tbc->reset_tpm_established_flag =3D + tpm_passthrough_reset_tpm_established_flag; + tbc->get_tpm_version =3D tpm_passthrough_get_tpm_version; + tbc->get_tpm_options =3D tpm_passthrough_get_tpm_options; tbc->handle_request =3D tpm_passthrough_handle_request; } =20 diff --git a/tpm.c b/tpm.c index 75a589b837..4882501bd7 100644 --- a/tpm.c +++ b/tpm.c @@ -32,11 +32,10 @@ void tpm_register_model(enum TpmModel model) =20 #ifdef CONFIG_TPM =20 -static const TPMDriverOps * -tpm_driver_find_by_type(enum TpmType type) +static const TPMBackendClass * +tpm_be_find_by_type(enum TpmType type) { ObjectClass *oc; - TPMBackendClass *bc; char *typename =3D g_strdup_printf("tpm-%s", TpmType_str(type)); =20 oc =3D object_class_by_name(typename); @@ -46,8 +45,7 @@ tpm_driver_find_by_type(enum TpmType type) return NULL; } =20 - bc =3D TPM_BACKEND_CLASS(oc); - return bc->ops; + return TPM_BACKEND_CLASS(oc); } =20 /* @@ -61,11 +59,11 @@ static void tpm_display_backend_drivers(void) fprintf(stderr, "Supported TPM types (choose only one):\n"); =20 for (i =3D 0; i < TPM_TYPE__MAX; i++) { - const TPMDriverOps *ops =3D tpm_driver_find_by_type(i); - if (!ops) { + const TPMBackendClass *bc =3D tpm_be_find_by_type(i); + if (!bc) { continue; } - fprintf(stderr, "%12s %s\n", TpmType_str(i), ops->desc); + fprintf(stderr, "%12s %s\n", TpmType_str(i), bc->desc); } fprintf(stderr, "\n"); } @@ -92,7 +90,7 @@ static int configure_tpm(QemuOpts *opts) { const char *value; const char *id; - const TPMDriverOps *be; + const TPMBackendClass *be; TPMBackend *drv; Error *local_err =3D NULL; int i; @@ -116,7 +114,7 @@ static int configure_tpm(QemuOpts *opts) } =20 i =3D qapi_enum_parse(&TpmType_lookup, value, -1, NULL); - be =3D i >=3D 0 ? tpm_driver_find_by_type(i) : NULL; + be =3D i >=3D 0 ? tpm_be_find_by_type(i) : NULL; if (be =3D=3D NULL) { error_report(QERR_INVALID_PARAMETER_VALUE, "type", "a TPM backend type"); @@ -234,7 +232,7 @@ TpmTypeList *qmp_query_tpm_types(Error **errp) TpmTypeList *head =3D NULL, *prev =3D NULL, *cur_item; =20 for (i =3D 0; i < TPM_TYPE__MAX; i++) { - if (!tpm_driver_find_by_type(i)) { + if (!tpm_be_find_by_type(i)) { continue; } cur_item =3D g_new0(TpmTypeList, 1); diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0c41f1212f..c9529df67f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2602,7 +2602,6 @@ sub process { SCSIBusInfo| SCSIReqOps| Spice[A-Z][a-zA-Z0-9]*Interface| - TPMDriverOps| USBDesc[A-Z][a-zA-Z0-9]*| VhostOps| VMStateDescription| --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590260547669.4619230545132; Mon, 9 Oct 2017 16:04:20 -0700 (PDT) Received: from localhost ([::1]:60156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h5r-0002tF-Oy for importer@patchew.org; Mon, 09 Oct 2017 19:04:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyt-0005hX-04 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyp-0004wI-Vg for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyp-0004vz-Ph for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:56:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B962BC058EA9; Mon, 9 Oct 2017 22:56:58 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C8FB5C6BF; Mon, 9 Oct 2017 22:56:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B962BC058EA9 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:50 +0200 Message-Id: <20171009225623.29232-10-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 09 Oct 2017 22:56:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/42] tpm: remove init() class method 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No backend use it. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 2 -- backends/tpm.c | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index a4288df038..b08f985500 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -66,8 +66,6 @@ struct TPMBackendClass { =20 TPMBackend *(*create)(QemuOpts *opts, const char *id); =20 - /* initialize the backend */ - int (*init)(TPMBackend *t); /* start up the TPM on the backend */ int (*startup_tpm)(TPMBackend *t); =20 diff --git a/backends/tpm.c b/backends/tpm.c index ca3a78eea8..dc750d48c9 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -47,13 +47,11 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) int tpm_backend_init(TPMBackend *s, TPMState *state, TPMRecvDataCB *datacb) { - TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); - s->tpm_state =3D state; s->recv_data_callback =3D datacb; s->had_startup_error =3D false; =20 - return k->init ? k->init(s) : 0; + return 0; } =20 int tpm_backend_startup_tpm(TPMBackend *s) --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590539325909.4097747190059; Mon, 9 Oct 2017 16:08:59 -0700 (PDT) Received: from localhost ([::1]:60178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hAQ-0006sN-Dj for importer@patchew.org; Mon, 09 Oct 2017 19:08:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gys-0005hW-Vw for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gys-0004xL-04 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyr-0004wv-Qj for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4444356EC; Mon, 9 Oct 2017 22:57:00 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 591D24D757; Mon, 9 Oct 2017 22:56:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C4444356EC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:51 +0200 Message-Id: <20171009225623.29232-11-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 09 Oct 2017 22:57:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/42] tpm: remove configure_tpm() hop 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- tpm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tpm.c b/tpm.c index 4882501bd7..45520f555d 100644 --- a/tpm.c +++ b/tpm.c @@ -86,7 +86,7 @@ TPMBackend *qemu_find_tpm(const char *id) return NULL; } =20 -static int configure_tpm(QemuOpts *opts) +static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) { const char *value; const char *id; @@ -145,11 +145,6 @@ static int configure_tpm(QemuOpts *opts) return 0; } =20 -static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) -{ - return configure_tpm(opts); -} - /* * Walk the list of TPM backend drivers that are in use and call their * destroy function to have them cleaned up. --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590419578578.305400219803; Mon, 9 Oct 2017 16:06:59 -0700 (PDT) Received: from localhost ([::1]:60171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h8P-00056j-HH for importer@patchew.org; Mon, 09 Oct 2017 19:06:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gyx-0005jj-Rj for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyw-0004zp-RB for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47224) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyw-0004zJ-Im for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B095C04AC6B; Mon, 9 Oct 2017 22:57:05 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E8525ED4D; Mon, 9 Oct 2017 22:57:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B095C04AC6B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:52 +0200 Message-Id: <20171009225623.29232-12-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:57:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/42] tpm: remove unused TPMBackendCmd 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is only handling of request so far in both backends. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/sysemu/tpm_backend.h | 9 +-------- backends/tpm.c | 7 ++----- hw/tpm/tpm_emulator.c | 42 ++++++++++++++++------------------------= -- hw/tpm/tpm_passthrough.c | 29 ++++++++++------------------- 4 files changed, 29 insertions(+), 58 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index b08f985500..7d7ebfc21d 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -32,13 +32,6 @@ typedef struct TPMBackend TPMBackend; =20 typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done= ); =20 -typedef enum TPMBackendCmd { - TPM_BACKEND_CMD_INIT =3D 1, - TPM_BACKEND_CMD_PROCESS_CMD, - TPM_BACKEND_CMD_END, - TPM_BACKEND_CMD_TPM_RESET, -} TPMBackendCmd; - struct TPMBackend { Object parent; =20 @@ -83,7 +76,7 @@ struct TPMBackendClass { =20 void (*opened)(TPMBackend *s, Error **errp); =20 - void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd); + void (*handle_request)(TPMBackend *s); }; =20 /** diff --git a/backends/tpm.c b/backends/tpm.c index dc750d48c9..34e82085ec 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -25,13 +25,12 @@ static void tpm_backend_worker_thread(gpointer data, gp= ointer user_data) TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 assert(k->handle_request !=3D NULL); - k->handle_request(s, (TPMBackendCmd)data); + k->handle_request(s); } =20 static void tpm_backend_thread_end(TPMBackend *s) { if (s->thread_pool) { - g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_END, = NULL); g_thread_pool_free(s->thread_pool, FALSE, TRUE); s->thread_pool =3D NULL; } @@ -64,7 +63,6 @@ int tpm_backend_startup_tpm(TPMBackend *s) =20 s->thread_pool =3D g_thread_pool_new(tpm_backend_worker_thread, s, 1, = TRUE, NULL); - g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NUL= L); =20 res =3D k->startup_tpm ? k->startup_tpm(s) : 0; =20 @@ -80,8 +78,7 @@ bool tpm_backend_had_startup_error(TPMBackend *s) =20 void tpm_backend_deliver_request(TPMBackend *s) { - g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_PROCESS_C= MD, - NULL); + g_thread_pool_push(s->thread_pool, NULL, NULL); } =20 void tpm_backend_reset(TPMBackend *s) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index bb5a65b492..dadc264182 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -172,39 +172,29 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm= _emu, uint8_t locty_number) return 0; } =20 -static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd cmd) +static void tpm_emulator_handle_request(TPMBackend *tb) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); TPMLocality *locty =3D NULL; bool selftest_done =3D false; Error *err =3D NULL; =20 - DPRINTF("processing command type %d", cmd); - - switch (cmd) { - case TPM_BACKEND_CMD_PROCESS_CMD: - locty =3D tb->tpm_state->locty_data; - if (tpm_emulator_set_locality(tpm_emu, - tb->tpm_state->locty_number) < 0 || - tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, - locty->w_offset, locty->r_buffer.buf= fer, - locty->r_buffer.size, &selftest_done, - &err) < 0) { - tpm_util_write_fatal_error_response(locty->r_buffer.buffer, - locty->r_buffer.size); - error_report_err(err); - } - - tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number, - selftest_done); - - break; - case TPM_BACKEND_CMD_INIT: - case TPM_BACKEND_CMD_END: - case TPM_BACKEND_CMD_TPM_RESET: - /* nothing to do */ - break; + DPRINTF("processing TPM command"); + + locty =3D tb->tpm_state->locty_data; + if (tpm_emulator_set_locality(tpm_emu, + tb->tpm_state->locty_number) < 0 || + tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, + locty->w_offset, locty->r_buffer.buffer, + locty->r_buffer.size, &selftest_done, + &err) < 0) { + tpm_util_write_fatal_error_response(locty->r_buffer.buffer, + locty->r_buffer.size); + error_report_err(err); } + + tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number, + selftest_done); } =20 static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index d9da99bc8e..5cd988e8a4 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -149,29 +149,20 @@ static int tpm_passthrough_unix_transfer(TPMPassthruS= tate *tpm_pt, selftest_done); } =20 -static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd c= md) +static void tpm_passthrough_handle_request(TPMBackend *tb) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); bool selftest_done =3D false; =20 - DPRINTF("tpm_passthrough: processing command type %d\n", cmd); - - switch (cmd) { - case TPM_BACKEND_CMD_PROCESS_CMD: - tpm_passthrough_unix_transfer(tpm_pt, - tb->tpm_state->locty_data, - &selftest_done); - - tb->recv_data_callback(tb->tpm_state, - tb->tpm_state->locty_number, - selftest_done); - break; - case TPM_BACKEND_CMD_INIT: - case TPM_BACKEND_CMD_END: - case TPM_BACKEND_CMD_TPM_RESET: - /* nothing to do */ - break; - } + DPRINTF("tpm_passthrough: processing command\n"); + + tpm_passthrough_unix_transfer(tpm_pt, + tb->tpm_state->locty_data, + &selftest_done); + + tb->recv_data_callback(tb->tpm_state, + tb->tpm_state->locty_number, + selftest_done); } =20 static void tpm_passthrough_reset(TPMBackend *tb) --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590568497264.3648867746617; Mon, 9 Oct 2017 16:09:28 -0700 (PDT) Received: from localhost ([::1]:60179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hAg-00076O-Kn for importer@patchew.org; Mon, 09 Oct 2017 19:09:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gz2-0005qA-4f for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gyz-00052F-4S for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gyy-00050v-Ur for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9C3761478; Mon, 9 Oct 2017 22:57:07 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E8E818796; Mon, 9 Oct 2017 22:57:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E9C3761478 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:53 +0200 Message-Id: <20171009225623.29232-13-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 Oct 2017 22:57:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/42] tpm: remove needless cast 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 5cd988e8a4..fed3d69799 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -96,7 +96,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState = *tpm_pt, =20 is_selftest =3D tpm_util_is_selftest(in, in_len); =20 - ret =3D qemu_write_full(tpm_pt->tpm_fd, (const void *)in, (size_t)in_l= en); + ret =3D qemu_write_full(tpm_pt->tpm_fd, in, in_len); if (ret !=3D in_len) { if (!tpm_pt->tpm_op_canceled || errno !=3D ECANCELED) { error_report("tpm_passthrough: error while transmitting data " --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590695466455.6190242911873; Mon, 9 Oct 2017 16:11:35 -0700 (PDT) Received: from localhost ([::1]:60192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hCo-0000k0-JE for importer@patchew.org; Mon, 09 Oct 2017 19:11:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gz2-0005qB-5N for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gz1-00053C-Bc for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47542) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gz1-00052q-31 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06F8CC04AC71; Mon, 9 Oct 2017 22:57:10 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5845477714; Mon, 9 Oct 2017 22:57:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06F8CC04AC71 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:54 +0200 Message-Id: <20171009225623.29232-14-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:57:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/42] tpm: remove locty argument from receive_cb 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The tpm_state is passed as argument, the assert() is pointless since we give it the value of tpm_state->locty_number already. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 2 +- hw/tpm/tpm_emulator.c | 3 +-- hw/tpm/tpm_passthrough.c | 4 +--- hw/tpm/tpm_tis.c | 5 ++--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 7d7ebfc21d..9c83a512e1 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -30,7 +30,7 @@ typedef struct TPMBackendClass TPMBackendClass; typedef struct TPMBackend TPMBackend; =20 -typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done= ); +typedef void (TPMRecvDataCB)(TPMState *, bool selftest_done); =20 struct TPMBackend { Object parent; diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index dadc264182..4fe405353a 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -193,8 +193,7 @@ static void tpm_emulator_handle_request(TPMBackend *tb) error_report_err(err); } =20 - tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number, - selftest_done); + tb->recv_data_callback(tb->tpm_state, selftest_done); } =20 static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index fed3d69799..0ae4596932 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -160,9 +160,7 @@ static void tpm_passthrough_handle_request(TPMBackend *= tb) tb->tpm_state->locty_data, &selftest_done); =20 - tb->recv_data_callback(tb->tpm_state, - tb->tpm_state->locty_number, - selftest_done); + tb->recv_data_callback(tb->tpm_state, selftest_done); } =20 static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index c54dac32de..345a4fbee5 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -371,14 +371,13 @@ static void tpm_tis_receive_bh(void *opaque) /* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_receive_cb(TPMState *s, uint8_t locty, +static void tpm_tis_receive_cb(TPMState *s, bool is_selftest_done) { TPMTISEmuState *tis =3D &s->s.tis; + uint8_t locty =3D s->locty_number; uint8_t l; =20 - assert(s->locty_number =3D=3D locty); - if (is_selftest_done) { for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES; l++) { tis->loc[locty].sts |=3D TPM_TIS_STS_SELFTEST_DONE; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507589978751539.32966871506; Mon, 9 Oct 2017 15:59:38 -0700 (PDT) Received: from localhost ([::1]:60133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h18-0007Cb-Ci for importer@patchew.org; Mon, 09 Oct 2017 18:59:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gz7-0005xR-34 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gz5-000559-R4 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gz5-00054p-IV for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 854534ACBA; Mon, 9 Oct 2017 22:57:14 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 966B169FBC; Mon, 9 Oct 2017 22:57:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 854534ACBA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:55 +0200 Message-Id: <20171009225623.29232-15-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 09 Oct 2017 22:57:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/42] tpm: add TPMBackendCmd to hold the request state 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This simplifies a bit locality handling, and argument passing, and could pave the way to queuing requests (if that makes sense). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 1 + include/sysemu/tpm_backend.h | 16 +++++++++++++--- backends/tpm.c | 6 +++--- hw/tpm/tpm_emulator.c | 29 +++++++++++++++-------------- hw/tpm/tpm_passthrough.c | 24 +++++------------------- hw/tpm/tpm_tis.c | 18 +++++++++++++----- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index f2f285b3cc..6d7b3dc850 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -26,6 +26,7 @@ struct TPMState { =20 uint8_t locty_number; TPMLocality *locty_data; + TPMBackendCmd cmd; =20 char *backend; TPMBackend *be_driver; diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 9c83a512e1..3bb90be3de 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -30,7 +30,16 @@ typedef struct TPMBackendClass TPMBackendClass; typedef struct TPMBackend TPMBackend; =20 -typedef void (TPMRecvDataCB)(TPMState *, bool selftest_done); +typedef void (TPMRecvDataCB)(TPMState *); + +typedef struct TPMBackendCmd { + uint8_t locty; + const uint8_t *in; + uint32_t in_len; + uint8_t *out; + uint32_t out_len; + bool selftest_done; +} TPMBackendCmd; =20 struct TPMBackend { Object parent; @@ -76,7 +85,7 @@ struct TPMBackendClass { =20 void (*opened)(TPMBackend *s, Error **errp); =20 - void (*handle_request)(TPMBackend *s); + void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd); }; =20 /** @@ -121,11 +130,12 @@ bool tpm_backend_had_startup_error(TPMBackend *s); /** * tpm_backend_deliver_request: * @s: the backend to send the request to + * @cmd: the command to deliver * * Send a request to the backend. The backend will then send the request * to the TPM implementation. */ -void tpm_backend_deliver_request(TPMBackend *s); +void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd); =20 /** * tpm_backend_reset: diff --git a/backends/tpm.c b/backends/tpm.c index 34e82085ec..dc7c831ff8 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -25,7 +25,7 @@ static void tpm_backend_worker_thread(gpointer data, gpoi= nter user_data) TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 assert(k->handle_request !=3D NULL); - k->handle_request(s); + k->handle_request(s, (TPMBackendCmd *)data); } =20 static void tpm_backend_thread_end(TPMBackend *s) @@ -76,9 +76,9 @@ bool tpm_backend_had_startup_error(TPMBackend *s) return s->had_startup_error; } =20 -void tpm_backend_deliver_request(TPMBackend *s) +void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd) { - g_thread_pool_push(s->thread_pool, NULL, NULL); + g_thread_pool_push(s->thread_pool, cmd, NULL); } =20 void tpm_backend_reset(TPMBackend *s) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 4fe405353a..788ab9876d 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -172,28 +172,29 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm= _emu, uint8_t locty_number) return 0; } =20 -static void tpm_emulator_handle_request(TPMBackend *tb) +static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); - TPMLocality *locty =3D NULL; - bool selftest_done =3D false; Error *err =3D NULL; =20 DPRINTF("processing TPM command"); =20 - locty =3D tb->tpm_state->locty_data; - if (tpm_emulator_set_locality(tpm_emu, - tb->tpm_state->locty_number) < 0 || - tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, - locty->w_offset, locty->r_buffer.buffer, - locty->r_buffer.size, &selftest_done, - &err) < 0) { - tpm_util_write_fatal_error_response(locty->r_buffer.buffer, - locty->r_buffer.size); - error_report_err(err); + if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < = 0) { + goto error; + } + + if (tpm_emulator_unix_tx_bufs(tpm_emu, cmd->in, cmd->in_len, + cmd->out, cmd->out_len, + &cmd->selftest_done, &err) < 0) { + goto error; } =20 - tb->recv_data_callback(tb->tpm_state, selftest_done); + tb->recv_data_callback(tb->tpm_state); + return; + +error: + tpm_util_write_fatal_error_response(cmd->out, cmd->out_len); + error_report_err(err); } =20 static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 0ae4596932..93d72b8e9e 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -137,30 +137,16 @@ err_exit: return ret; } =20 -static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, - const TPMLocality *locty_data, - bool *selftest_done) -{ - return tpm_passthrough_unix_tx_bufs(tpm_pt, - locty_data->w_buffer.buffer, - locty_data->w_offset, - locty_data->r_buffer.buffer, - locty_data->r_buffer.size, - selftest_done); -} - -static void tpm_passthrough_handle_request(TPMBackend *tb) +static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *= cmd) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); - bool selftest_done =3D false; =20 - DPRINTF("tpm_passthrough: processing command\n"); + DPRINTF("tpm_passthrough: processing command %p\n", cmd); =20 - tpm_passthrough_unix_transfer(tpm_pt, - tb->tpm_state->locty_data, - &selftest_done); + tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len, + cmd->out, cmd->out_len, &cmd->selftest_do= ne); =20 - tb->recv_data_callback(tb->tpm_state, selftest_done); + tb->recv_data_callback(tb->tpm_state); } =20 static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 345a4fbee5..ffed7bfaf9 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -215,7 +215,15 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t loct= y) */ tis->loc[locty].state =3D TPM_TIS_STATE_EXECUTION; =20 - tpm_backend_deliver_request(s->be_driver); + s->cmd =3D (TPMBackendCmd) { + .locty =3D locty, + .in =3D s->locty_data->w_buffer.buffer, + .in_len =3D s->locty_data->w_offset, + .out =3D s->locty_data->r_buffer.buffer, + .out_len =3D s->locty_data->r_buffer.size + }; + + tpm_backend_deliver_request(s->be_driver, &s->cmd); } =20 /* raise an interrupt if allowed */ @@ -352,7 +360,7 @@ static void tpm_tis_receive_bh(void *opaque) { TPMState *s =3D opaque; TPMTISEmuState *tis =3D &s->s.tis; - uint8_t locty =3D s->locty_number; + uint8_t locty =3D s->cmd.locty; =20 tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); @@ -371,11 +379,11 @@ static void tpm_tis_receive_bh(void *opaque) /* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_receive_cb(TPMState *s, - bool is_selftest_done) +static void tpm_tis_receive_cb(TPMState *s) { TPMTISEmuState *tis =3D &s->s.tis; - uint8_t locty =3D s->locty_number; + bool is_selftest_done =3D s->cmd.selftest_done; + uint8_t locty =3D s->cmd.locty; uint8_t l; =20 if (is_selftest_done) { --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590572384938.3254261954669; Mon, 9 Oct 2017 16:09:32 -0700 (PDT) Received: from localhost ([::1]:60180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hAr-0007JP-W9 for importer@patchew.org; Mon, 09 Oct 2017 19:09:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzB-0005zh-Qi for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gz8-00056x-Ow for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47812) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gz8-00056W-JI for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:18 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DB77C04AC46; Mon, 9 Oct 2017 22:57:17 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F7E8179D1; Mon, 9 Oct 2017 22:57:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8DB77C04AC46 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:56 +0200 Message-Id: <20171009225623.29232-16-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:57:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 15/42] tpm-emulator: fix error handling 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The previous patch cleaned up a bit error handling, and exposed an existing bug: error_report_err() could be called with a NULL error. Instead, make tpm_emulator_set_locality() set the error. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_emulator.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 788ab9876d..25a6258c10 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -141,7 +141,8 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_e= mu, return 0; } =20 -static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_n= umber) +static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_n= umber, + Error **errp) { ptm_loc loc; =20 @@ -155,15 +156,15 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm= _emu, uint8_t locty_number) loc.u.req.loc =3D locty_number; if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SET_LOCALITY, &loc, sizeof(loc), sizeof(loc)) < 0) { - error_report("tpm-emulator: could not set locality : %s", - strerror(errno)); + error_setg(errp, "tpm-emulator: could not set locality : %s", + strerror(errno)); return -1; } =20 loc.u.resp.tpm_result =3D be32_to_cpu(loc.u.resp.tpm_result); if (loc.u.resp.tpm_result !=3D 0) { - error_report("tpm-emulator: TPM result for set locality : 0x%x", - loc.u.resp.tpm_result); + error_setg(errp, "tpm-emulator: TPM result for set locality : 0x%x= ", + loc.u.resp.tpm_result); return -1; } =20 @@ -179,7 +180,8 @@ static void tpm_emulator_handle_request(TPMBackend *tb,= TPMBackendCmd *cmd) =20 DPRINTF("processing TPM command"); =20 - if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < = 0) { + if (tpm_emulator_set_locality(tpm_emu, + tb->tpm_state->locty_number, &err) < 0) { goto error; } =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 150759012617276.17156109650159; Mon, 9 Oct 2017 16:02:06 -0700 (PDT) Received: from localhost ([::1]:60149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h3l-00014c-7L for importer@patchew.org; Mon, 09 Oct 2017 19:02:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzB-0005zg-QY for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzA-000594-VQ for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzA-00057X-JU for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AB5D13A98; Mon, 9 Oct 2017 22:57:19 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F19917C59; Mon, 9 Oct 2017 22:57:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AB5D13A98 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:57 +0200 Message-Id: <20171009225623.29232-17-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:57:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 16/42] tpm: remove locty_data from 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Keep it internal to tpm-tis instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 2 -- hw/tpm/tpm_emulator.c | 3 +-- hw/tpm/tpm_tis.c | 12 +++++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 6d7b3dc850..252c4082ef 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -24,8 +24,6 @@ struct TPMState { TPMTISEmuState tis; } s; =20 - uint8_t locty_number; - TPMLocality *locty_data; TPMBackendCmd cmd; =20 char *backend; diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 25a6258c10..407ac97651 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -180,8 +180,7 @@ static void tpm_emulator_handle_request(TPMBackend *tb,= TPMBackendCmd *cmd) =20 DPRINTF("processing TPM command"); =20 - if (tpm_emulator_set_locality(tpm_emu, - tb->tpm_state->locty_number, &err) < 0) { + if (tpm_emulator_set_locality(tpm_emu, cmd->locty, &err) < 0) { goto error; } =20 diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ffed7bfaf9..ad2845622e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -203,12 +203,10 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t = flags) static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { TPMTISEmuState *tis =3D &s->s.tis; + TPMLocality *locty_data =3D &tis->loc[locty]; =20 tpm_tis_show_buffer(&tis->loc[locty].w_buffer, "tpm_tis: To TPM"); =20 - s->locty_number =3D locty; - s->locty_data =3D &tis->loc[locty]; - /* * w_offset serves as length indicator for length of data; * it's reset when the response comes back @@ -217,10 +215,10 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t loc= ty) =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, - .in =3D s->locty_data->w_buffer.buffer, - .in_len =3D s->locty_data->w_offset, - .out =3D s->locty_data->r_buffer.buffer, - .out_len =3D s->locty_data->r_buffer.size + .in =3D locty_data->w_buffer.buffer, + .in_len =3D locty_data->w_offset, + .out =3D locty_data->r_buffer.buffer, + .out_len =3D locty_data->r_buffer.size }; =20 tpm_backend_deliver_request(s->be_driver, &s->cmd); --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 150759029992521.506724177535716; Mon, 9 Oct 2017 16:04:59 -0700 (PDT) Received: from localhost ([::1]:60157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h6N-0003KU-5d for importer@patchew.org; Mon, 09 Oct 2017 19:04:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzG-00062F-9r for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzF-0005Ar-HG for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzF-0005Ac-Ac for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52B7A13AA3; Mon, 9 Oct 2017 22:57:24 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08A5A5ED4D; Mon, 9 Oct 2017 22:57:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 52B7A13AA3 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:58 +0200 Message-Id: <20171009225623.29232-18-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:57:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 17/42] tpm-tis: move TPMState to TIS header 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_int.h | 23 ++--------------------- hw/tpm/tpm_tis.h | 19 +++++++++++++++++++ hw/tpm/tpm_util.c | 1 + 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 252c4082ef..e231d0eb4f 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -12,28 +12,9 @@ #ifndef TPM_TPM_INT_H #define TPM_TPM_INT_H =20 -#include "exec/memory.h" -#include "tpm_tis.h" +#include "qemu/osdep.h" =20 -/* overall state of the TPM interface */ -struct TPMState { - ISADevice busdev; - MemoryRegion mmio; - - union { - TPMTISEmuState tis; - } s; - - TPMBackendCmd cmd; - - char *backend; - TPMBackend *be_driver; - TPMVersion be_tpm_version; -}; - -#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) - -#define TPM_STANDARD_CMDLINE_OPTS \ +#define TPM_STANDARD_CMDLINE_OPTS \ { \ .name =3D "type", \ .type =3D QEMU_OPT_STRING, \ diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h index 31e612a7f4..30e35eef64 100644 --- a/hw/tpm/tpm_tis.h +++ b/hw/tpm/tpm_tis.h @@ -72,4 +72,23 @@ typedef struct TPMTISEmuState { uint32_t irq_num; } TPMTISEmuState; =20 +/* overall state of the TPM interface */ +struct TPMState { + ISADevice busdev; + MemoryRegion mmio; + + union { + TPMTISEmuState tis; + } s; + + uint8_t locty_number; + TPMBackendCmd cmd; + + char *backend; + TPMBackend *be_driver; + TPMVersion be_tpm_version; +}; + +#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) + #endif /* TPM_TPM_TIS_H */ diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c index fb929f6e92..7dc5b08824 100644 --- a/hw/tpm/tpm_util.c +++ b/hw/tpm/tpm_util.c @@ -22,6 +22,7 @@ #include "qemu/osdep.h" #include "tpm_util.h" #include "tpm_int.h" +#include "exec/memory.h" =20 /* * Write an error message in the given output buffer. --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590445598329.47661673851667; Mon, 9 Oct 2017 16:07:25 -0700 (PDT) Received: from localhost ([::1]:60172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h8u-0005Wp-KM for importer@patchew.org; Mon, 09 Oct 2017 19:07:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzK-00065p-Se for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzH-0005Bn-R3 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42412) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzH-0005BL-IP for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 805C47E43F; Mon, 9 Oct 2017 22:57:26 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id E80AC5ED4D; Mon, 9 Oct 2017 22:57:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 805C47E43F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:55:59 +0200 Message-Id: <20171009225623.29232-19-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:57:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 18/42] tpm-tis: remove tpm_tis.h header 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The definitions are now private to TIS implementation. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.h | 94 --------------------------------------------= ---- hw/tpm/tpm_passthrough.c | 1 - hw/tpm/tpm_tis.c | 72 ++++++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 96 deletions(-) delete mode 100644 hw/tpm/tpm_tis.h diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h deleted file mode 100644 index 30e35eef64..0000000000 --- a/hw/tpm/tpm_tis.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * tpm_tis.h - QEMU's TPM TIS interface emulator - * - * Copyright (C) 2006, 2010-2013 IBM Corporation - * - * Authors: - * Stefan Berger - * David Safford - * - * This work is licensed under the terms of the GNU GPL, version 2 or late= r. - * See the COPYING file in the top-level directory. - * - * Implementation of the TIS interface according to specs found at - * http://www.trustedcomputinggroup.org - * - */ -#ifndef TPM_TPM_TIS_H -#define TPM_TPM_TIS_H - -#include "hw/isa/isa.h" -#include "hw/acpi/tpm.h" -#include "qemu-common.h" - -#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ -#define TPM_TIS_LOCALITY_SHIFT 12 -#define TPM_TIS_NO_LOCALITY 0xff - -#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) - -#define TPM_TIS_BUFFER_MAX 4096 - -typedef enum { - TPM_TIS_STATE_IDLE =3D 0, - TPM_TIS_STATE_READY, - TPM_TIS_STATE_COMPLETION, - TPM_TIS_STATE_EXECUTION, - TPM_TIS_STATE_RECEPTION, -} TPMTISState; - -typedef struct TPMSizedBuffer { - uint32_t size; - uint8_t *buffer; -} TPMSizedBuffer; - -/* locality data -- all fields are persisted */ -typedef struct TPMLocality { - TPMTISState state; - uint8_t access; - uint32_t sts; - uint32_t iface_id; - uint32_t inte; - uint32_t ints; - - uint16_t w_offset; - uint16_t r_offset; - TPMSizedBuffer w_buffer; - TPMSizedBuffer r_buffer; -} TPMLocality; - -typedef struct TPMTISEmuState { - QEMUBH *bh; - uint32_t offset; - uint8_t buf[TPM_TIS_BUFFER_MAX]; - - uint8_t active_locty; - uint8_t aborting_locty; - uint8_t next_locty; - - TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; - - qemu_irq irq; - uint32_t irq_num; -} TPMTISEmuState; - -/* overall state of the TPM interface */ -struct TPMState { - ISADevice busdev; - MemoryRegion mmio; - - union { - TPMTISEmuState tis; - } s; - - uint8_t locty_number; - TPMBackendCmd cmd; - - char *backend; - TPMBackend *be_driver; - TPMVersion be_tpm_version; -}; - -#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) - -#endif /* TPM_TPM_TIS_H */ diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 93d72b8e9e..4274164a61 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -31,7 +31,6 @@ #include "hw/hw.h" #include "hw/i386/pc.h" #include "qapi/clone-visitor.h" -#include "tpm_tis.h" #include "tpm_util.h" =20 #define DEBUG_TPM 0 diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ad2845622e..73cda41dc6 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "hw/isa/isa.h" #include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "sysemu/block-backend.h" @@ -30,10 +31,79 @@ #include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/pci/pci_ids.h" -#include "tpm_tis.h" #include "qapi/error.h" #include "qemu-common.h" #include "qemu/main-loop.h" +#include "hw/acpi/tpm.h" + +#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ +#define TPM_TIS_LOCALITY_SHIFT 12 +#define TPM_TIS_NO_LOCALITY 0xff + +#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES) + +#define TPM_TIS_BUFFER_MAX 4096 + +typedef enum { + TPM_TIS_STATE_IDLE =3D 0, + TPM_TIS_STATE_READY, + TPM_TIS_STATE_COMPLETION, + TPM_TIS_STATE_EXECUTION, + TPM_TIS_STATE_RECEPTION, +} TPMTISState; + +typedef struct TPMSizedBuffer { + uint32_t size; + uint8_t *buffer; +} TPMSizedBuffer; + +/* locality data -- all fields are persisted */ +typedef struct TPMLocality { + TPMTISState state; + uint8_t access; + uint32_t sts; + uint32_t iface_id; + uint32_t inte; + uint32_t ints; + + uint16_t w_offset; + uint16_t r_offset; + TPMSizedBuffer w_buffer; + TPMSizedBuffer r_buffer; +} TPMLocality; + +typedef struct TPMTISEmuState { + QEMUBH *bh; + uint32_t offset; + uint8_t buf[TPM_TIS_BUFFER_MAX]; + + uint8_t active_locty; + uint8_t aborting_locty; + uint8_t next_locty; + + TPMLocality loc[TPM_TIS_NUM_LOCALITIES]; + + qemu_irq irq; + uint32_t irq_num; +} TPMTISEmuState; + +struct TPMState { + ISADevice busdev; + MemoryRegion mmio; + + union { + TPMTISEmuState tis; + } s; + + uint8_t locty_number; + TPMBackendCmd cmd; + + char *backend; + TPMBackend *be_driver; + TPMVersion be_tpm_version; +}; + +#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) =20 #define DEBUG_TIS 0 =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590605397725.8843368585681; Mon, 9 Oct 2017 16:10:05 -0700 (PDT) Received: from localhost ([::1]:60181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hBR-0007oS-DY for importer@patchew.org; Mon, 09 Oct 2017 19:10:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzN-00068Q-Mz for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzK-0005Ch-NA for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzK-0005CL-Ay for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:30 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 430D313AA3; Mon, 9 Oct 2017 22:57:29 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3246317C59; Mon, 9 Oct 2017 22:57:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 430D313AA3 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:00 +0200 Message-Id: <20171009225623.29232-20-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:57:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 19/42] tpm-tis: fold TPMTISEmuState in 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.c | 336 ++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 157 insertions(+), 179 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 73cda41dc6..d84eec48b4 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -72,7 +72,10 @@ typedef struct TPMLocality { TPMSizedBuffer r_buffer; } TPMLocality; =20 -typedef struct TPMTISEmuState { +struct TPMState { + ISADevice busdev; + MemoryRegion mmio; + QEMUBH *bh; uint32_t offset; uint8_t buf[TPM_TIS_BUFFER_MAX]; @@ -85,15 +88,6 @@ typedef struct TPMTISEmuState { =20 qemu_irq irq; uint32_t irq_num; -} TPMTISEmuState; - -struct TPMState { - ISADevice busdev; - MemoryRegion mmio; - - union { - TPMTISEmuState tis; - } s; =20 uint8_t locty_number; TPMBackendCmd cmd; @@ -272,16 +266,15 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t = flags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - TPMTISEmuState *tis =3D &s->s.tis; - TPMLocality *locty_data =3D &tis->loc[locty]; + TPMLocality *locty_data =3D &s->loc[locty]; =20 - tpm_tis_show_buffer(&tis->loc[locty].w_buffer, "tpm_tis: To TPM"); + tpm_tis_show_buffer(&s->loc[locty].w_buffer, "tpm_tis: To TPM"); =20 /* * w_offset serves as length indicator for length of data; * it's reset when the response comes back */ - tis->loc[locty].state =3D TPM_TIS_STATE_EXECUTION; + s->loc[locty].state =3D TPM_TIS_STATE_EXECUTION; =20 s->cmd =3D (TPMBackendCmd) { .locty =3D locty, @@ -297,17 +290,15 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t loc= ty) /* raise an interrupt if allowed */ static void tpm_tis_raise_irq(TPMState *s, uint8_t locty, uint32_t irqmask) { - TPMTISEmuState *tis =3D &s->s.tis; - if (!TPM_TIS_IS_VALID_LOCTY(locty)) { return; } =20 - if ((tis->loc[locty].inte & TPM_TIS_INT_ENABLED) && - (tis->loc[locty].inte & irqmask)) { + if ((s->loc[locty].inte & TPM_TIS_INT_ENABLED) && + (s->loc[locty].inte & irqmask)) { DPRINTF("tpm_tis: Raising IRQ for flag %08x\n", irqmask); - qemu_irq_raise(s->s.tis.irq); - tis->loc[locty].ints |=3D irqmask; + qemu_irq_raise(s->irq); + s->loc[locty].ints |=3D irqmask; } } =20 @@ -319,7 +310,7 @@ static uint32_t tpm_tis_check_request_use_except(TPMSta= te *s, uint8_t locty) if (l =3D=3D locty) { continue; } - if ((s->s.tis.loc[l].access & TPM_TIS_ACCESS_REQUEST_USE)) { + if ((s->loc[l].access & TPM_TIS_ACCESS_REQUEST_USE)) { return 1; } } @@ -329,14 +320,13 @@ static uint32_t tpm_tis_check_request_use_except(TPMS= tate *s, uint8_t locty) =20 static void tpm_tis_new_active_locality(TPMState *s, uint8_t new_active_lo= cty) { - TPMTISEmuState *tis =3D &s->s.tis; - bool change =3D (s->s.tis.active_locty !=3D new_active_locty); + bool change =3D (s->active_locty !=3D new_active_locty); bool is_seize; uint8_t mask; =20 - if (change && TPM_TIS_IS_VALID_LOCTY(s->s.tis.active_locty)) { + if (change && TPM_TIS_IS_VALID_LOCTY(s->active_locty)) { is_seize =3D TPM_TIS_IS_VALID_LOCTY(new_active_locty) && - tis->loc[new_active_locty].access & TPM_TIS_ACCESS_SEIZ= E; + s->loc[new_active_locty].access & TPM_TIS_ACCESS_SEIZE; =20 if (is_seize) { mask =3D ~(TPM_TIS_ACCESS_ACTIVE_LOCALITY); @@ -345,73 +335,70 @@ static void tpm_tis_new_active_locality(TPMState *s, = uint8_t new_active_locty) TPM_TIS_ACCESS_REQUEST_USE); } /* reset flags on the old active locality */ - tis->loc[s->s.tis.active_locty].access &=3D mask; + s->loc[s->active_locty].access &=3D mask; =20 if (is_seize) { - tis->loc[tis->active_locty].access |=3D TPM_TIS_ACCESS_BEEN_SE= IZED; + s->loc[s->active_locty].access |=3D TPM_TIS_ACCESS_BEEN_SEIZED; } } =20 - tis->active_locty =3D new_active_locty; + s->active_locty =3D new_active_locty; =20 - DPRINTF("tpm_tis: Active locality is now %d\n", s->s.tis.active_locty); + DPRINTF("tpm_tis: Active locality is now %d\n", s->active_locty); =20 if (TPM_TIS_IS_VALID_LOCTY(new_active_locty)) { /* set flags on the new active locality */ - tis->loc[new_active_locty].access |=3D TPM_TIS_ACCESS_ACTIVE_LOCAL= ITY; - tis->loc[new_active_locty].access &=3D ~(TPM_TIS_ACCESS_REQUEST_US= E | + s->loc[new_active_locty].access |=3D TPM_TIS_ACCESS_ACTIVE_LOCALIT= Y; + s->loc[new_active_locty].access &=3D ~(TPM_TIS_ACCESS_REQUEST_USE | TPM_TIS_ACCESS_SEIZE); } =20 if (change) { - tpm_tis_raise_irq(s, tis->active_locty, TPM_TIS_INT_LOCALITY_CHANG= ED); + tpm_tis_raise_irq(s, s->active_locty, TPM_TIS_INT_LOCALITY_CHANGED= ); } } =20 /* abort -- this function switches the locality */ static void tpm_tis_abort(TPMState *s, uint8_t locty) { - TPMTISEmuState *tis =3D &s->s.tis; - - tis->loc[locty].r_offset =3D 0; - tis->loc[locty].w_offset =3D 0; + s->loc[locty].r_offset =3D 0; + s->loc[locty].w_offset =3D 0; =20 - DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", tis->next_l= octy); + DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_loc= ty); =20 /* * Need to react differently depending on who's aborting now and * which locality will become active afterwards. */ - if (tis->aborting_locty =3D=3D tis->next_locty) { - tis->loc[tis->aborting_locty].state =3D TPM_TIS_STATE_READY; - tpm_tis_sts_set(&tis->loc[tis->aborting_locty], + if (s->aborting_locty =3D=3D s->next_locty) { + s->loc[s->aborting_locty].state =3D TPM_TIS_STATE_READY; + tpm_tis_sts_set(&s->loc[s->aborting_locty], TPM_TIS_STS_COMMAND_READY); - tpm_tis_raise_irq(s, tis->aborting_locty, TPM_TIS_INT_COMMAND_READ= Y); + tpm_tis_raise_irq(s, s->aborting_locty, TPM_TIS_INT_COMMAND_READY); } =20 /* locality after abort is another one than the current one */ - tpm_tis_new_active_locality(s, tis->next_locty); + tpm_tis_new_active_locality(s, s->next_locty); =20 - tis->next_locty =3D TPM_TIS_NO_LOCALITY; + s->next_locty =3D TPM_TIS_NO_LOCALITY; /* nobody's aborting a command anymore */ - tis->aborting_locty =3D TPM_TIS_NO_LOCALITY; + s->aborting_locty =3D TPM_TIS_NO_LOCALITY; } =20 /* prepare aborting current command */ static void tpm_tis_prep_abort(TPMState *s, uint8_t locty, uint8_t newloct= y) { - TPMTISEmuState *tis =3D &s->s.tis; uint8_t busy_locty; =20 - tis->aborting_locty =3D locty; - tis->next_locty =3D newlocty; /* locality after successful abort */ + s->aborting_locty =3D locty; + s->next_locty =3D newlocty; /* locality after successful abort */ =20 /* * only abort a command using an interrupt if currently executing * a command AND if there's a valid connection to the vTPM. */ for (busy_locty =3D 0; busy_locty < TPM_TIS_NUM_LOCALITIES; busy_locty= ++) { - if (tis->loc[busy_locty].state =3D=3D TPM_TIS_STATE_EXECUTION) { + if (s->loc[busy_locty].state =3D=3D TPM_TIS_STATE_EXECUTION) { /* * request the backend to cancel. Some backends may not * support it @@ -427,16 +414,15 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t l= octy, uint8_t newlocty) static void tpm_tis_receive_bh(void *opaque) { TPMState *s =3D opaque; - TPMTISEmuState *tis =3D &s->s.tis; uint8_t locty =3D s->cmd.locty; =20 - tpm_tis_sts_set(&tis->loc[locty], + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); - tis->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; - tis->loc[locty].r_offset =3D 0; - tis->loc[locty].w_offset =3D 0; + s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; + s->loc[locty].r_offset =3D 0; + s->loc[locty].w_offset =3D 0; =20 - if (TPM_TIS_IS_VALID_LOCTY(tis->next_locty)) { + if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { tpm_tis_abort(s, locty); } =20 @@ -449,18 +435,17 @@ static void tpm_tis_receive_bh(void *opaque) */ static void tpm_tis_receive_cb(TPMState *s) { - TPMTISEmuState *tis =3D &s->s.tis; bool is_selftest_done =3D s->cmd.selftest_done; uint8_t locty =3D s->cmd.locty; uint8_t l; =20 if (is_selftest_done) { for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES; l++) { - tis->loc[locty].sts |=3D TPM_TIS_STS_SELFTEST_DONE; + s->loc[locty].sts |=3D TPM_TIS_STS_SELFTEST_DONE; } } =20 - qemu_bh_schedule(tis->bh); + qemu_bh_schedule(s->bh); } =20 /* @@ -468,21 +453,20 @@ static void tpm_tis_receive_cb(TPMState *s) */ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) { - TPMTISEmuState *tis =3D &s->s.tis; uint32_t ret =3D TPM_TIS_NO_DATA_BYTE; uint16_t len; =20 - if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { - len =3D tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); + if ((s->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { + len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); =20 - ret =3D tis->loc[locty].r_buffer.buffer[tis->loc[locty].r_offset++= ]; - if (tis->loc[locty].r_offset >=3D len) { + ret =3D s->loc[locty].r_buffer.buffer[s->loc[locty].r_offset++]; + if (s->loc[locty].r_offset >=3D len) { /* got last byte */ - tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID); + 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, tis->loc[locty].r_offset-1); + ret, s->loc[locty].r_offset - 1); } =20 return ret; @@ -505,13 +489,12 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) uint8_t locty =3D tpm_tis_locality_from_addr(addr); hwaddr base =3D addr & ~0xfff; TPMState *s =3D opaque; - TPMTISEmuState *tis =3D &s->s.tis; =20 DPRINTF("tpm_tis: active locality : %d\n" "tpm_tis: state of locality %d : %d\n" "tpm_tis: register dump:\n", - tis->active_locty, - locty, tis->loc[locty].state); + s->active_locty, + locty, s->loc[locty].state); =20 for (idx =3D 0; regs[idx] !=3D 0xfff; idx++) { DPRINTF("tpm_tis: 0x%04x : 0x%08x\n", regs[idx], @@ -520,25 +503,25 @@ static void tpm_tis_dump_state(void *opaque, hwaddr a= ddr) =20 DPRINTF("tpm_tis: read offset : %d\n" "tpm_tis: result buffer : ", - tis->loc[locty].r_offset); + s->loc[locty].r_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].r_buffer); + idx < tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffer); idx++) { DPRINTF("%c%02x%s", - tis->loc[locty].r_offset =3D=3D idx ? '>' : ' ', - tis->loc[locty].r_buffer.buffer[idx], + s->loc[locty].r_offset =3D=3D idx ? '>' : ' ', + s->loc[locty].r_buffer.buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n" "tpm_tis: write offset : %d\n" "tpm_tis: request buffer: ", - tis->loc[locty].w_offset); + s->loc[locty].w_offset); for (idx =3D 0; - idx < tpm_tis_get_size_from_buffer(&tis->loc[locty].w_buffer); + idx < tpm_tis_get_size_from_buffer(&s->loc[locty].w_buffer); idx++) { DPRINTF("%c%02x%s", - tis->loc[locty].w_offset =3D=3D idx ? '>' : ' ', - tis->loc[locty].w_buffer.buffer[idx], + s->loc[locty].w_offset =3D=3D idx ? '>' : ' ', + s->loc[locty].w_buffer.buffer[idx], ((idx & 0xf) =3D=3D 0xf) ? "\ntpm_tis: " := ""); } DPRINTF("\n"); @@ -553,7 +536,6 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, unsigned size) { TPMState *s =3D opaque; - TPMTISEmuState *tis =3D &s->s.tis; uint16_t offset =3D addr & 0xffc; uint8_t shift =3D (addr & 0x3) * 8; uint32_t val =3D 0xffffffff; @@ -568,7 +550,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, switch (offset) { case TPM_TIS_REG_ACCESS: /* never show the SEIZE flag even though we use it internally */ - val =3D tis->loc[locty].access & ~TPM_TIS_ACCESS_SEIZE; + val =3D s->loc[locty].access & ~TPM_TIS_ACCESS_SEIZE; /* the pending flag is always calculated */ if (tpm_tis_check_request_use_except(s, locty)) { val |=3D TPM_TIS_ACCESS_PENDING_REQUEST; @@ -576,13 +558,13 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwadd= r addr, val |=3D !tpm_backend_get_tpm_established_flag(s->be_driver); break; case TPM_TIS_REG_INT_ENABLE: - val =3D tis->loc[locty].inte; + val =3D s->loc[locty].inte; break; case TPM_TIS_REG_INT_VECTOR: - val =3D tis->irq_num; + val =3D s->irq_num; break; case TPM_TIS_REG_INT_STATUS: - val =3D tis->loc[locty].ints; + val =3D s->loc[locty].ints; break; case TPM_TIS_REG_INTF_CAPABILITY: switch (s->be_tpm_version) { @@ -598,14 +580,14 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwadd= r addr, } break; case TPM_TIS_REG_STS: - if (tis->active_locty =3D=3D locty) { - if ((tis->loc[locty].sts & TPM_TIS_STS_DATA_AVAILABLE)) { + 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(&tis->loc[locty].r_buf= fer) - - tis->loc[locty].r_offset) | tis->loc[locty].sts; + tpm_tis_get_size_from_buffer(&s->loc[locty].r_buffe= r) + - s->loc[locty].r_offset) | s->loc[locty].sts; } else { - avail =3D tis->loc[locty].w_buffer.size - - tis->loc[locty].w_offset; + avail =3D s->loc[locty].w_buffer.size + - s->loc[locty].w_offset; /* * byte-sized reads should not return 0x00 for 0x100 * available bytes. @@ -613,13 +595,13 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwadd= r addr, if (size =3D=3D 1 && avail > 0xff) { avail =3D 0xff; } - val =3D TPM_TIS_BURST_COUNT(avail) | tis->loc[locty].sts; + val =3D TPM_TIS_BURST_COUNT(avail) | s->loc[locty].sts; } } break; case TPM_TIS_REG_DATA_FIFO: case TPM_TIS_REG_DATA_XFIFO ... TPM_TIS_REG_DATA_XFIFO_END: - if (tis->active_locty =3D=3D locty) { + if (s->active_locty =3D=3D locty) { if (size > 4 - (addr & 0x3)) { /* prevent access beyond FIFO */ size =3D 4 - (addr & 0x3); @@ -627,7 +609,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, val =3D 0; shift =3D 0; while (size > 0) { - switch (tis->loc[locty].state) { + switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: v =3D tpm_tis_data_read(s, locty); break; @@ -643,7 +625,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr = addr, } break; case TPM_TIS_REG_INTERFACE_ID: - val =3D tis->loc[locty].iface_id; + val =3D s->loc[locty].iface_id; break; case TPM_TIS_REG_DID_VID: val =3D (TPM_TIS_TPM_DID << 16) | TPM_TIS_TPM_VID; @@ -675,7 +657,6 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, uint64_t val, unsigned size) { TPMState *s =3D opaque; - TPMTISEmuState *tis =3D &s->s.tis; uint16_t off =3D addr & 0xffc; uint8_t shift =3D (addr & 0x3) * 8; uint8_t locty =3D tpm_tis_locality_from_addr(addr); @@ -712,17 +693,17 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, TPM_TIS_ACCESS_ACTIVE_LOCALITY); } =20 - active_locty =3D tis->active_locty; + active_locty =3D s->active_locty; =20 if ((val & TPM_TIS_ACCESS_ACTIVE_LOCALITY)) { /* give up locality if currently owned */ - if (tis->active_locty =3D=3D locty) { + if (s->active_locty =3D=3D locty) { DPRINTF("tpm_tis: Releasing locality %d\n", locty); =20 uint8_t newlocty =3D TPM_TIS_NO_LOCALITY; /* anybody wants the locality ? */ for (c =3D TPM_TIS_NUM_LOCALITIES - 1; c >=3D 0; c--) { - if ((tis->loc[c].access & TPM_TIS_ACCESS_REQUEST_USE))= { + if ((s->loc[c].access & TPM_TIS_ACCESS_REQUEST_USE)) { DPRINTF("tpm_tis: Locality %d requests use.\n", c); newlocty =3D c; break; @@ -740,12 +721,12 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, } } else { /* not currently the owner; clear a pending request */ - tis->loc[locty].access &=3D ~TPM_TIS_ACCESS_REQUEST_USE; + s->loc[locty].access &=3D ~TPM_TIS_ACCESS_REQUEST_USE; } } =20 if ((val & TPM_TIS_ACCESS_BEEN_SEIZED)) { - tis->loc[locty].access &=3D ~TPM_TIS_ACCESS_BEEN_SEIZED; + s->loc[locty].access &=3D ~TPM_TIS_ACCESS_BEEN_SEIZED; } =20 if ((val & TPM_TIS_ACCESS_SEIZE)) { @@ -756,19 +737,19 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, * allow seize for requesting locality if no locality is * active */ - while ((TPM_TIS_IS_VALID_LOCTY(tis->active_locty) && - locty > tis->active_locty) || - !TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { + while ((TPM_TIS_IS_VALID_LOCTY(s->active_locty) && + locty > s->active_locty) || + !TPM_TIS_IS_VALID_LOCTY(s->active_locty)) { bool higher_seize =3D FALSE; =20 /* already a pending SEIZE ? */ - if ((tis->loc[locty].access & TPM_TIS_ACCESS_SEIZE)) { + if ((s->loc[locty].access & TPM_TIS_ACCESS_SEIZE)) { break; } =20 /* check for ongoing seize by a higher locality */ for (l =3D locty + 1; l < TPM_TIS_NUM_LOCALITIES; l++) { - if ((tis->loc[l].access & TPM_TIS_ACCESS_SEIZE)) { + if ((s->loc[l].access & TPM_TIS_ACCESS_SEIZE)) { higher_seize =3D TRUE; break; } @@ -780,24 +761,24 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, =20 /* cancel any seize by a lower locality */ for (l =3D 0; l < locty - 1; l++) { - tis->loc[l].access &=3D ~TPM_TIS_ACCESS_SEIZE; + s->loc[l].access &=3D ~TPM_TIS_ACCESS_SEIZE; } =20 - tis->loc[locty].access |=3D TPM_TIS_ACCESS_SEIZE; + s->loc[locty].access |=3D TPM_TIS_ACCESS_SEIZE; DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: " "Locality %d seized from locality %d\n", - locty, tis->active_locty); + locty, s->active_locty); DPRINTF("tpm_tis: TPM_TIS_ACCESS_SEIZE: Initiating abort.\= n"); set_new_locty =3D 0; - tpm_tis_prep_abort(s, tis->active_locty, locty); + tpm_tis_prep_abort(s, s->active_locty, locty); break; } } =20 if ((val & TPM_TIS_ACCESS_REQUEST_USE)) { - if (tis->active_locty !=3D locty) { - if (TPM_TIS_IS_VALID_LOCTY(tis->active_locty)) { - tis->loc[locty].access |=3D TPM_TIS_ACCESS_REQUEST_USE; + if (s->active_locty !=3D locty) { + if (TPM_TIS_IS_VALID_LOCTY(s->active_locty)) { + s->loc[locty].access |=3D TPM_TIS_ACCESS_REQUEST_USE; } else { /* no locality active -> make this one active now */ active_locty =3D locty; @@ -811,12 +792,12 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, =20 break; case TPM_TIS_REG_INT_ENABLE: - if (tis->active_locty !=3D locty) { + if (s->active_locty !=3D locty) { break; } =20 - tis->loc[locty].inte &=3D mask; - tis->loc[locty].inte |=3D (val & (TPM_TIS_INT_ENABLED | + s->loc[locty].inte &=3D mask; + s->loc[locty].inte |=3D (val & (TPM_TIS_INT_ENABLED | TPM_TIS_INT_POLARITY_MASK | TPM_TIS_INTERRUPTS_SUPPORTED)); break; @@ -824,30 +805,30 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, /* hard wired -- ignore */ break; case TPM_TIS_REG_INT_STATUS: - if (tis->active_locty !=3D locty) { + if (s->active_locty !=3D locty) { break; } =20 /* clearing of interrupt flags */ if (((val & TPM_TIS_INTERRUPTS_SUPPORTED)) && - (tis->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) { - tis->loc[locty].ints &=3D ~val; - if (tis->loc[locty].ints =3D=3D 0) { - qemu_irq_lower(tis->irq); + (s->loc[locty].ints & TPM_TIS_INTERRUPTS_SUPPORTED)) { + s->loc[locty].ints &=3D ~val; + if (s->loc[locty].ints =3D=3D 0) { + qemu_irq_lower(s->irq); DPRINTF("tpm_tis: Lowering IRQ\n"); } } - tis->loc[locty].ints &=3D ~(val & TPM_TIS_INTERRUPTS_SUPPORTED); + s->loc[locty].ints &=3D ~(val & TPM_TIS_INTERRUPTS_SUPPORTED); break; case TPM_TIS_REG_STS: - if (tis->active_locty !=3D locty) { + if (s->active_locty !=3D locty) { break; } =20 if (s->be_tpm_version =3D=3D TPM_VERSION_2_0) { /* some flags that are only supported for TPM 2 */ if (val & TPM_TIS_STS_COMMAND_CANCEL) { - if (tis->loc[locty].state =3D=3D TPM_TIS_STATE_EXECUTION) { + if (s->loc[locty].state =3D=3D TPM_TIS_STATE_EXECUTION) { /* * request the backend to cancel. Some backends may not * support it @@ -867,16 +848,16 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, TPM_TIS_STS_RESPONSE_RETRY); =20 if (val =3D=3D TPM_TIS_STS_COMMAND_READY) { - switch (tis->loc[locty].state) { + switch (s->loc[locty].state) { =20 case TPM_TIS_STATE_READY: - tis->loc[locty].w_offset =3D 0; - tis->loc[locty].r_offset =3D 0; + s->loc[locty].w_offset =3D 0; + s->loc[locty].r_offset =3D 0; break; =20 case TPM_TIS_STATE_IDLE: - tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_COMMAND_READ= Y); - tis->loc[locty].state =3D TPM_TIS_STATE_READY; + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_COMMAND_READY); + s->loc[locty].state =3D TPM_TIS_STATE_READY; tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); break; =20 @@ -889,23 +870,23 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, break; =20 case TPM_TIS_STATE_COMPLETION: - tis->loc[locty].w_offset =3D 0; - tis->loc[locty].r_offset =3D 0; + s->loc[locty].w_offset =3D 0; + s->loc[locty].r_offset =3D 0; /* shortcut to ready state with C/R set */ - tis->loc[locty].state =3D TPM_TIS_STATE_READY; - if (!(tis->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { - tpm_tis_sts_set(&tis->loc[locty], + s->loc[locty].state =3D TPM_TIS_STATE_READY; + if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) { + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_COMMAND_READY); tpm_tis_raise_irq(s, locty, TPM_TIS_INT_COMMAND_READY); } - tis->loc[locty].sts &=3D ~(TPM_TIS_STS_DATA_AVAILABLE); + s->loc[locty].sts &=3D ~(TPM_TIS_STS_DATA_AVAILABLE); break; =20 } } else if (val =3D=3D TPM_TIS_STS_TPM_GO) { - switch (tis->loc[locty].state) { + switch (s->loc[locty].state) { case TPM_TIS_STATE_RECEPTION: - if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) =3D=3D 0) { + if ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) =3D=3D 0) { tpm_tis_tpm_send(s, locty); } break; @@ -914,10 +895,10 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, break; } } else if (val =3D=3D TPM_TIS_STS_RESPONSE_RETRY) { - switch (tis->loc[locty].state) { + switch (s->loc[locty].state) { case TPM_TIS_STATE_COMPLETION: - tis->loc[locty].r_offset =3D 0; - tpm_tis_sts_set(&tis->loc[locty], + s->loc[locty].r_offset =3D 0; + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID| TPM_TIS_STS_DATA_AVAILABLE); break; @@ -930,20 +911,20 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, case TPM_TIS_REG_DATA_FIFO: case TPM_TIS_REG_DATA_XFIFO ... TPM_TIS_REG_DATA_XFIFO_END: /* data fifo */ - if (tis->active_locty !=3D locty) { + if (s->active_locty !=3D locty) { break; } =20 - if (tis->loc[locty].state =3D=3D TPM_TIS_STATE_IDLE || - tis->loc[locty].state =3D=3D TPM_TIS_STATE_EXECUTION || - tis->loc[locty].state =3D=3D TPM_TIS_STATE_COMPLETION) { + if (s->loc[locty].state =3D=3D TPM_TIS_STATE_IDLE || + s->loc[locty].state =3D=3D TPM_TIS_STATE_EXECUTION || + s->loc[locty].state =3D=3D TPM_TIS_STATE_COMPLETION) { /* drop the byte */ } else { DPRINTF("tpm_tis: Data to send to TPM: %08x (size=3D%d)\n", (int)val, size); - if (tis->loc[locty].state =3D=3D TPM_TIS_STATE_READY) { - tis->loc[locty].state =3D TPM_TIS_STATE_RECEPTION; - tpm_tis_sts_set(&tis->loc[locty], + if (s->loc[locty].state =3D=3D TPM_TIS_STATE_READY) { + s->loc[locty].state =3D TPM_TIS_STATE_RECEPTION; + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID); } =20 @@ -953,30 +934,30 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr a= ddr, size =3D 4 - (addr & 0x3); } =20 - while ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0)= { - if (tis->loc[locty].w_offset < tis->loc[locty].w_buffer.si= ze) { - tis->loc[locty].w_buffer. - buffer[tis->loc[locty].w_offset++] =3D (uint8_t)va= l; + 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; val >>=3D 8; size--; } else { - tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID); + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); } } =20 /* check for complete packet */ - if (tis->loc[locty].w_offset > 5 && - (tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) { + if (s->loc[locty].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 !(tis->loc[locty].sts & TPM_TIS_STS_VALI= D); + bool need_irq =3D !(s->loc[locty].sts & TPM_TIS_STS_VALID); =20 - len =3D tpm_tis_get_size_from_buffer(&tis->loc[locty].w_bu= ffer); - if (len > tis->loc[locty].w_offset) { - tpm_tis_sts_set(&tis->loc[locty], + len =3D tpm_tis_get_size_from_buffer(&s->loc[locty].w_buff= er); + if (len > s->loc[locty].w_offset) { + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID= ); } else { /* packet complete */ - tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID); + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID); } if (need_irq) { tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID); @@ -987,7 +968,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr add= r, case TPM_TIS_REG_INTERFACE_ID: if (val & TPM_TIS_IFACE_ID_INT_SEL_LOCK) { for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES; l++) { - tis->loc[l].iface_id |=3D TPM_TIS_IFACE_ID_INT_SEL_LOCK; + s->loc[l].iface_id |=3D TPM_TIS_IFACE_ID_INT_SEL_LOCK; } } break; @@ -1036,39 +1017,38 @@ TPMVersion tpm_tis_get_tpm_version(Object *obj) static void tpm_tis_reset(DeviceState *dev) { TPMState *s =3D TPM(dev); - TPMTISEmuState *tis =3D &s->s.tis; int c; =20 s->be_tpm_version =3D tpm_backend_get_tpm_version(s->be_driver); =20 tpm_backend_reset(s->be_driver); =20 - tis->active_locty =3D TPM_TIS_NO_LOCALITY; - tis->next_locty =3D TPM_TIS_NO_LOCALITY; - tis->aborting_locty =3D TPM_TIS_NO_LOCALITY; + s->active_locty =3D TPM_TIS_NO_LOCALITY; + s->next_locty =3D TPM_TIS_NO_LOCALITY; + s->aborting_locty =3D TPM_TIS_NO_LOCALITY; =20 for (c =3D 0; c < TPM_TIS_NUM_LOCALITIES; c++) { - tis->loc[c].access =3D TPM_TIS_ACCESS_TPM_REG_VALID_STS; + s->loc[c].access =3D TPM_TIS_ACCESS_TPM_REG_VALID_STS; switch (s->be_tpm_version) { case TPM_VERSION_UNSPEC: break; case TPM_VERSION_1_2: - tis->loc[c].sts =3D TPM_TIS_STS_TPM_FAMILY1_2; - tis->loc[c].iface_id =3D TPM_TIS_IFACE_ID_SUPPORTED_FLAGS1_3; + s->loc[c].sts =3D TPM_TIS_STS_TPM_FAMILY1_2; + s->loc[c].iface_id =3D TPM_TIS_IFACE_ID_SUPPORTED_FLAGS1_3; break; case TPM_VERSION_2_0: - tis->loc[c].sts =3D TPM_TIS_STS_TPM_FAMILY2_0; - tis->loc[c].iface_id =3D TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0; + s->loc[c].sts =3D TPM_TIS_STS_TPM_FAMILY2_0; + s->loc[c].iface_id =3D TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0; break; } - tis->loc[c].inte =3D TPM_TIS_INT_POLARITY_LOW_LEVEL; - tis->loc[c].ints =3D 0; - tis->loc[c].state =3D TPM_TIS_STATE_IDLE; - - tis->loc[c].w_offset =3D 0; - tpm_tis_realloc_buffer(&tis->loc[c].w_buffer); - tis->loc[c].r_offset =3D 0; - tpm_tis_realloc_buffer(&tis->loc[c].r_buffer); + s->loc[c].inte =3D TPM_TIS_INT_POLARITY_LOW_LEVEL; + s->loc[c].ints =3D 0; + s->loc[c].state =3D TPM_TIS_STATE_IDLE; + + s->loc[c].w_offset =3D 0; + tpm_tis_realloc_buffer(&s->loc[c].w_buffer); + s->loc[c].r_offset =3D 0; + tpm_tis_realloc_buffer(&s->loc[c].r_buffer); } =20 tpm_tis_do_startup_tpm(s); @@ -1080,8 +1060,7 @@ static const VMStateDescription vmstate_tpm_tis =3D { }; =20 static Property tpm_tis_properties[] =3D { - DEFINE_PROP_UINT32("irq", TPMState, - s.tis.irq_num, TPM_TIS_IRQ), + DEFINE_PROP_UINT32("irq", TPMState, irq_num, TPM_TIS_IRQ), DEFINE_PROP_STRING("tpmdev", TPMState, backend), DEFINE_PROP_END_OF_LIST(), }; @@ -1089,7 +1068,6 @@ static Property tpm_tis_properties[] =3D { static void tpm_tis_realizefn(DeviceState *dev, Error **errp) { TPMState *s =3D TPM(dev); - TPMTISEmuState *tis =3D &s->s.tis; =20 s->be_driver =3D qemu_find_tpm(s->backend); if (!s->be_driver) { @@ -1106,15 +1084,15 @@ static void tpm_tis_realizefn(DeviceState *dev, Err= or **errp) return; } =20 - if (tis->irq_num > 15) { + if (s->irq_num > 15) { error_setg(errp, "tpm_tis: IRQ %d for TPM TIS is outside valid ran= ge " - "of 0 to 15", tis->irq_num); + "of 0 to 15", s->irq_num); return; } =20 - tis->bh =3D qemu_bh_new(tpm_tis_receive_bh, s); + s->bh =3D qemu_bh_new(tpm_tis_receive_bh, s); =20 - isa_init_irq(&s->busdev, &tis->irq, tis->irq_num); + isa_init_irq(&s->busdev, &s->irq, s->irq_num); =20 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), TPM_TIS_ADDR_BASE, &s->mmio); --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590722458704.5245477261894; Mon, 9 Oct 2017 16:12:02 -0700 (PDT) Received: from localhost ([::1]:60193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hDI-0001Ap-Hc for importer@patchew.org; Mon, 09 Oct 2017 19:11:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzP-0006BO-KF for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzO-0005E7-PQ for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzO-0005Do-Jd for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 888C2552EA; Mon, 9 Oct 2017 22:57:33 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id D543F17C59; Mon, 9 Oct 2017 22:57:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 888C2552EA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:01 +0200 Message-Id: <20171009225623.29232-21-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:57:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 20/42] tpm: add a QOM TPM interface 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will simplify backend / interface objects relationship, so the frontend interface will simply have to implement the TPM QOM interface. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 17 +++++++++++++++++ backends/tpm.c | 8 ++++++++ hw/tpm/tpm_tis.c | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index e231d0eb4f..eb02e7760c 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -13,6 +13,23 @@ #define TPM_TPM_INT_H =20 #include "qemu/osdep.h" +#include "qom/object.h" + +#define TYPE_TPM_IF "tpm-if" +#define TPM_IF_CLASS(klass) \ + OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF) +#define TPM_IF_GET_CLASS(obj) \ + OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF) +#define TPM_IF(obj) \ + INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF) + +typedef struct TPMIf { + Object parent_obj; +} TPMIf; + +typedef struct TPMIfClass { + InterfaceClass parent_class; +} TPMIfClass; =20 #define TPM_STANDARD_CMDLINE_OPTS \ { \ diff --git a/backends/tpm.c b/backends/tpm.c index dc7c831ff8..87c5c09179 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "sysemu/tpm.h" +#include "hw/tpm/tpm_int.h" #include "qemu/thread.h" =20 static void tpm_backend_worker_thread(gpointer data, gpointer user_data) @@ -209,9 +210,16 @@ static const TypeInfo tpm_backend_info =3D { .abstract =3D true, }; =20 +static const TypeInfo tpm_if_info =3D { + .name =3D TYPE_TPM_IF, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(TPMIfClass), +}; + static void register_types(void) { type_register_static(&tpm_backend_info); + type_register_static(&tpm_if_info); } =20 type_init(register_types); diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index d84eec48b4..dbb50043ac 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1123,6 +1123,10 @@ static const TypeInfo tpm_tis_info =3D { .instance_size =3D sizeof(TPMState), .instance_init =3D tpm_tis_initfn, .class_init =3D tpm_tis_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_TPM_IF }, + { } + } }; =20 static void tpm_tis_register(void) --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590888479936.7033544150544; Mon, 9 Oct 2017 16:14:48 -0700 (PDT) Received: from localhost ([::1]:60204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hFo-0003SC-GZ for importer@patchew.org; Mon, 09 Oct 2017 19:14:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzT-0006G6-TG for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzQ-0005Eu-OM for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzQ-0005Ef-G4 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6AB4C5D68D; Mon, 9 Oct 2017 22:57:35 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAAED5ED4D; Mon, 9 Oct 2017 22:57:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6AB4C5D68D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:02 +0200 Message-Id: <20171009225623.29232-22-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 Oct 2017 22:57:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 21/42] tpm: move recv_data_callback to TPM interface 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Simplify the TPM backend setup, move callback to TPM interface. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 3 +++ include/sysemu/tpm_backend.h | 6 +----- backends/tpm.c | 4 +--- hw/tpm/tpm_emulator.c | 3 ++- hw/tpm/tpm_passthrough.c | 3 ++- hw/tpm/tpm_tis.c | 11 ++++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index eb02e7760c..9c045b6691 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -29,6 +29,9 @@ typedef struct TPMIf { =20 typedef struct TPMIfClass { InterfaceClass parent_class; + + /* run in thread pool by backend */ + void (*request_completed)(TPMIf *obj); } TPMIfClass; =20 #define TPM_STANDARD_CMDLINE_OPTS \ diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 3bb90be3de..03ea5a3400 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -30,8 +30,6 @@ typedef struct TPMBackendClass TPMBackendClass; typedef struct TPMBackend TPMBackend; =20 -typedef void (TPMRecvDataCB)(TPMState *); - typedef struct TPMBackendCmd { uint8_t locty; const uint8_t *in; @@ -48,7 +46,6 @@ struct TPMBackend { bool opened; TPMState *tpm_state; GThreadPool *thread_pool; - TPMRecvDataCB *recv_data_callback; bool had_startup_error; =20 /* */ @@ -106,8 +103,7 @@ enum TpmType tpm_backend_get_type(TPMBackend *s); * * Returns 0 on success. */ -int tpm_backend_init(TPMBackend *s, TPMState *state, - TPMRecvDataCB *datacb); +int tpm_backend_init(TPMBackend *s, TPMState *state); =20 /** * tpm_backend_startup_tpm: diff --git a/backends/tpm.c b/backends/tpm.c index 87c5c09179..5763f6f369 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -44,11 +44,9 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) return k->type; } =20 -int tpm_backend_init(TPMBackend *s, TPMState *state, - TPMRecvDataCB *datacb) +int tpm_backend_init(TPMBackend *s, TPMState *state) { s->tpm_state =3D state; - s->recv_data_callback =3D datacb; s->had_startup_error =3D false; =20 return 0; diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 407ac97651..f04f4e0830 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -176,6 +176,7 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_e= mu, uint8_t locty_number, static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpm_state); Error *err =3D NULL; =20 DPRINTF("processing TPM command"); @@ -190,7 +191,7 @@ static void tpm_emulator_handle_request(TPMBackend *tb,= TPMBackendCmd *cmd) goto error; } =20 - tb->recv_data_callback(tb->tpm_state); + tic->request_completed(TPM_IF(tb->tpm_state)); return; =20 error: diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 4274164a61..c440aff4b2 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -139,13 +139,14 @@ err_exit: static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *= cmd) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpm_state); =20 DPRINTF("tpm_passthrough: processing command %p\n", cmd); =20 tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len, cmd->out, cmd->out_len, &cmd->selftest_do= ne); =20 - tb->recv_data_callback(tb->tpm_state); + tic->request_completed(TPM_IF(tb->tpm_state)); } =20 static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index dbb50043ac..8c5cac5fa5 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -430,11 +430,10 @@ static void tpm_tis_receive_bh(void *opaque) TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); } =20 -/* - * Callback from the TPM to indicate that the response was received. - */ -static void tpm_tis_receive_cb(TPMState *s) +static void tpm_tis_request_completed(TPMIf *ti) { + TPMState *s =3D TPM(ti); + bool is_selftest_done =3D s->cmd.selftest_done; uint8_t locty =3D s->cmd.locty; uint8_t l; @@ -1078,7 +1077,7 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) =20 s->be_driver->fe_model =3D TPM_MODEL_TPM_TIS; =20 - if (tpm_backend_init(s->be_driver, s, tpm_tis_receive_cb)) { + if (tpm_backend_init(s->be_driver, s)) { error_setg(errp, "tpm_tis: backend driver with id %s could not be " "initialized", s->backend); return; @@ -1110,11 +1109,13 @@ static void tpm_tis_initfn(Object *obj) static void tpm_tis_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); + TPMIfClass *tc =3D TPM_IF_CLASS(klass); =20 dc->realize =3D tpm_tis_realizefn; dc->props =3D tpm_tis_properties; dc->reset =3D tpm_tis_reset; dc->vmsd =3D &vmstate_tpm_tis; + tc->request_completed =3D tpm_tis_request_completed; } =20 static const TypeInfo tpm_tis_info =3D { --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590767743438.8625905576131; Mon, 9 Oct 2017 16:12:47 -0700 (PDT) Received: from localhost ([::1]:60194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hDx-0001r8-O3 for importer@patchew.org; Mon, 09 Oct 2017 19:12:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzW-0006IK-ED for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzV-0005Gr-Dl for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42592) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzV-0005GR-5y for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23F097E43F; Mon, 9 Oct 2017 22:57:40 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6770518796; Mon, 9 Oct 2017 22:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 23F097E43F Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:03 +0200 Message-Id: <20171009225623.29232-23-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:57:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 22/42] tpm-backend: store TPMIf interface, improve backend_init() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Store the TPM interface, the actual object may be different from TPMState. Keep a reference on the interface, and check the backend wasn't already initialized. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/sysemu/tpm_backend.h | 7 ++++--- backends/tpm.c | 12 +++++++++--- hw/tpm/tpm_emulator.c | 4 ++-- hw/tpm/tpm_passthrough.c | 4 ++-- hw/tpm/tpm_tis.c | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 03ea5a3400..8d08765b3c 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 "hw/tpm/tpm_int.h" =20 #define TYPE_TPM_BACKEND "tpm-backend" #define TPM_BACKEND(obj) \ @@ -43,8 +44,8 @@ struct TPMBackend { Object parent; =20 /*< protected >*/ + TPMIf *tpmif; bool opened; - TPMState *tpm_state; GThreadPool *thread_pool; bool had_startup_error; =20 @@ -96,14 +97,14 @@ enum TpmType tpm_backend_get_type(TPMBackend *s); /** * tpm_backend_init: * @s: the backend to initialized - * @state: TPMState + * @tpmif: TPM interface * @datacb: callback for sending data to frontend * * Initialize the backend with the given variables. * * Returns 0 on success. */ -int tpm_backend_init(TPMBackend *s, TPMState *state); +int tpm_backend_init(TPMBackend *s, TPMIf *tpmif); =20 /** * tpm_backend_startup_tpm: diff --git a/backends/tpm.c b/backends/tpm.c index 5763f6f369..86f0e7e915 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -17,7 +17,6 @@ #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "sysemu/tpm.h" -#include "hw/tpm/tpm_int.h" #include "qemu/thread.h" =20 static void tpm_backend_worker_thread(gpointer data, gpointer user_data) @@ -44,9 +43,15 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) return k->type; } =20 -int tpm_backend_init(TPMBackend *s, TPMState *state) +int tpm_backend_init(TPMBackend *s, TPMIf *tpmif) { - s->tpm_state =3D state; + if (s->tpmif) { + return -1; + } + + s->tpmif =3D tpmif; + object_ref(OBJECT(tpmif)); + s->had_startup_error =3D false; =20 return 0; @@ -194,6 +199,7 @@ static void tpm_backend_instance_finalize(Object *obj) { TPMBackend *s =3D TPM_BACKEND(obj); =20 + object_unref(OBJECT(s->tpmif)); g_free(s->id); tpm_backend_thread_end(s); } diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index f04f4e0830..07e7aa4abc 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -176,7 +176,7 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_e= mu, uint8_t locty_number, static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); - TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpm_state); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpmif); Error *err =3D NULL; =20 DPRINTF("processing TPM command"); @@ -191,7 +191,7 @@ static void tpm_emulator_handle_request(TPMBackend *tb,= TPMBackendCmd *cmd) goto error; } =20 - tic->request_completed(TPM_IF(tb->tpm_state)); + tic->request_completed(tb->tpmif); return; =20 error: diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index c440aff4b2..2ad74badca 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -139,14 +139,14 @@ err_exit: static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *= cmd) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); - TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpm_state); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpmif); =20 DPRINTF("tpm_passthrough: processing command %p\n", cmd); =20 tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len, cmd->out, cmd->out_len, &cmd->selftest_do= ne); =20 - tic->request_completed(TPM_IF(tb->tpm_state)); + tic->request_completed(tb->tpmif); } =20 static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 8c5cac5fa5..c24be57136 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1077,7 +1077,7 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) =20 s->be_driver->fe_model =3D TPM_MODEL_TPM_TIS; =20 - if (tpm_backend_init(s->be_driver, s)) { + if (tpm_backend_init(s->be_driver, TPM_IF(s))) { error_setg(errp, "tpm_tis: backend driver with id %s could not be " "initialized", s->backend); return; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590772331618.271309001661; Mon, 9 Oct 2017 16:12:52 -0700 (PDT) Received: from localhost ([::1]:60196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hE3-0001wx-GH for importer@patchew.org; Mon, 09 Oct 2017 19:12:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55055) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzd-0006Mc-3f for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gza-0005IP-1w for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzZ-0005I1-S1 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA838C04AC46; Mon, 9 Oct 2017 22:57:44 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id B05DA60E3F; Mon, 9 Oct 2017 22:57:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA838C04AC46 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:04 +0200 Message-Id: <20171009225623.29232-24-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:57:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 23/42] tpm-tis: no longer expose 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that there is an interface instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm.h | 2 -- hw/tpm/tpm_tis.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index c8afa179e5..62b073beeb 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -14,8 +14,6 @@ =20 #include "qemu/option.h" =20 -typedef struct TPMState TPMState; - int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); int tpm_init(void); void tpm_cleanup(void); diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index c24be57136..b3757bfbda 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -72,7 +72,7 @@ typedef struct TPMLocality { TPMSizedBuffer r_buffer; } TPMLocality; =20 -struct TPMState { +typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 @@ -95,7 +95,7 @@ struct TPMState { char *backend; TPMBackend *be_driver; TPMVersion be_tpm_version; -}; +} TPMState; =20 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 150759103755485.57916445252579; Mon, 9 Oct 2017 16:17:17 -0700 (PDT) Received: from localhost ([::1]:60219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hIF-0005gB-KN for importer@patchew.org; Mon, 09 Oct 2017 19:17:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzf-0006PE-V7 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gze-0005KL-QO for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gze-0005Jw-Hx for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BCAE85363; Mon, 9 Oct 2017 22:57:49 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B346179D1; Mon, 9 Oct 2017 22:57:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8BCAE85363 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:05 +0200 Message-Id: <20171009225623.29232-25-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Oct 2017 22:57:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 24/42] tpm-be: call request_completed() out of thread 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Lift from the backend implementation the responsability to call the request_completed() callback outside of thread context. This also simplify frontend/interface work, as they no longer need to care whether the callback is called from a different thread. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 1 - include/sysemu/tpm_backend.h | 1 + backends/tpm.c | 15 ++++++++++++++- hw/tpm/tpm_emulator.c | 2 -- hw/tpm/tpm_passthrough.c | 3 --- hw/tpm/tpm_tis.c | 36 +++++++++++++----------------------- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 9c045b6691..9c49325f03 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -30,7 +30,6 @@ typedef struct TPMIf { typedef struct TPMIfClass { InterfaceClass parent_class; =20 - /* run in thread pool by backend */ void (*request_completed)(TPMIf *obj); } TPMIfClass; =20 diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 8d08765b3c..dd4fb288ea 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -48,6 +48,7 @@ struct TPMBackend { bool opened; GThreadPool *thread_pool; bool had_startup_error; + QEMUBH *bh; =20 /* */ char *id; diff --git a/backends/tpm.c b/backends/tpm.c index 86f0e7e915..58f823d54c 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -18,14 +18,25 @@ #include "qapi/qmp/qerror.h" #include "sysemu/tpm.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" + +static void tpm_backend_request_completed_bh(void *opaque) +{ + TPMBackend *s =3D TPM_BACKEND(opaque); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(s->tpmif); + + tic->request_completed(s->tpmif); +} =20 static void tpm_backend_worker_thread(gpointer data, gpointer user_data) { TPMBackend *s =3D TPM_BACKEND(user_data); - TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); + TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 assert(k->handle_request !=3D NULL); k->handle_request(s, (TPMBackendCmd *)data); + + qemu_bh_schedule(s->bh); } =20 static void tpm_backend_thread_end(TPMBackend *s) @@ -193,6 +204,7 @@ static void tpm_backend_instance_init(Object *obj) tpm_backend_prop_set_opened, NULL); s->fe_model =3D -1; + s->bh =3D qemu_bh_new(tpm_backend_request_completed_bh, s); } =20 static void tpm_backend_instance_finalize(Object *obj) @@ -202,6 +214,7 @@ static void tpm_backend_instance_finalize(Object *obj) object_unref(OBJECT(s->tpmif)); g_free(s->id); tpm_backend_thread_end(s); + qemu_bh_delete(s->bh); } =20 static const TypeInfo tpm_backend_info =3D { diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 07e7aa4abc..36454837b3 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -176,7 +176,6 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_e= mu, uint8_t locty_number, static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); - TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpmif); Error *err =3D NULL; =20 DPRINTF("processing TPM command"); @@ -191,7 +190,6 @@ static void tpm_emulator_handle_request(TPMBackend *tb,= TPMBackendCmd *cmd) goto error; } =20 - tic->request_completed(tb->tpmif); return; =20 error: diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 2ad74badca..8c002e4da6 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -139,14 +139,11 @@ err_exit: static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *= cmd) { TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); - TPMIfClass *tic =3D TPM_IF_GET_CLASS(tb->tpmif); =20 DPRINTF("tpm_passthrough: processing command %p\n", cmd); =20 tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len, cmd->out, cmd->out_len, &cmd->selftest_do= ne); - - tic->request_completed(tb->tpmif); } =20 static void tpm_passthrough_reset(TPMBackend *tb) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index b3757bfbda..355427ab29 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -76,7 +76,6 @@ typedef struct TPMState { ISADevice busdev; MemoryRegion mmio; =20 - QEMUBH *bh; uint32_t offset; uint8_t buf[TPM_TIS_BUFFER_MAX]; =20 @@ -411,10 +410,20 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t l= octy, uint8_t newlocty) tpm_tis_abort(s, locty); } =20 -static void tpm_tis_receive_bh(void *opaque) +/* + * Callback from the TPM to indicate that the response was received. + */ +static void tpm_tis_request_completed(TPMIf *ti) { - TPMState *s =3D opaque; - uint8_t locty =3D s->cmd.locty; + TPMState *s =3D TPM(ti); + uint8_t locty =3D s->locty_number; + uint8_t l; + + if (s->cmd.selftest_done) { + for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES; l++) { + s->loc[locty].sts |=3D TPM_TIS_STS_SELFTEST_DONE; + } + } =20 tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); @@ -430,23 +439,6 @@ static void tpm_tis_receive_bh(void *opaque) TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); } =20 -static void tpm_tis_request_completed(TPMIf *ti) -{ - TPMState *s =3D TPM(ti); - - bool is_selftest_done =3D s->cmd.selftest_done; - uint8_t locty =3D s->cmd.locty; - uint8_t l; - - if (is_selftest_done) { - for (l =3D 0; l < TPM_TIS_NUM_LOCALITIES; l++) { - s->loc[locty].sts |=3D TPM_TIS_STS_SELFTEST_DONE; - } - } - - qemu_bh_schedule(s->bh); -} - /* * Read a byte of response data */ @@ -1089,8 +1081,6 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) return; } =20 - s->bh =3D qemu_bh_new(tpm_tis_receive_bh, s); - isa_init_irq(&s->busdev, &s->irq, s->irq_num); =20 memory_region_add_subregion(isa_address_space(ISA_DEVICE(dev)), --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591186434608.5601445591886; Mon, 9 Oct 2017 16:19:46 -0700 (PDT) Received: from localhost ([::1]:60228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hKj-0007ti-9w for importer@patchew.org; Mon, 09 Oct 2017 19:19:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzm-0006VC-Eq for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzj-0005Lu-D5 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzj-0005LX-6k for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 052C55D68D; Mon, 9 Oct 2017 22:57:54 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2562418990; Mon, 9 Oct 2017 22:57:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 052C55D68D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:06 +0200 Message-Id: <20171009225623.29232-26-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 09 Oct 2017 22:57:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 25/42] tpm-be: report error instead of front-end 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Backend can give more accurate error description, and lift out the job from the frontend. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 3 ++- backends/tpm.c | 3 ++- hw/tpm/tpm_tis.c | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index dd4fb288ea..51dfc0de9c 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -100,12 +100,13 @@ enum TpmType tpm_backend_get_type(TPMBackend *s); * @s: the backend to initialized * @tpmif: TPM interface * @datacb: callback for sending data to frontend + * @errp: a pointer to return the #Error object if an error occurs. * * Initialize the backend with the given variables. * * Returns 0 on success. */ -int tpm_backend_init(TPMBackend *s, TPMIf *tpmif); +int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp); =20 /** * tpm_backend_startup_tpm: diff --git a/backends/tpm.c b/backends/tpm.c index 58f823d54c..7b108bd5d8 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -54,9 +54,10 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) return k->type; } =20 -int tpm_backend_init(TPMBackend *s, TPMIf *tpmif) +int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp) { if (s->tpmif) { + error_setg(errp, "TPM backend '%s' is already initialized", s->id); return -1; } =20 diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 355427ab29..2fbc760730 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1069,9 +1069,7 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) =20 s->be_driver->fe_model =3D TPM_MODEL_TPM_TIS; =20 - if (tpm_backend_init(s->be_driver, TPM_IF(s))) { - error_setg(errp, "tpm_tis: backend driver with id %s could not be " - "initialized", s->backend); + if (tpm_backend_init(s->be_driver, TPM_IF(s), errp)) { return; } =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590846662622.5445570879532; Mon, 9 Oct 2017 16:14:06 -0700 (PDT) Received: from localhost ([::1]:60201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hFH-00031A-NI for importer@patchew.org; Mon, 09 Oct 2017 19:13:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzo-0006Ws-AP for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzn-0005NV-Bt for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzn-0005Mx-2z for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:57:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E855381DEE; Mon, 9 Oct 2017 22:57:57 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5395618796; Mon, 9 Oct 2017 22:57:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E855381DEE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:07 +0200 Message-Id: <20171009225623.29232-27-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Oct 2017 22:57:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 26/42] tpm-be: ask model to the TPM interface 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No need to store the mode in the backend, or to let the frontend set it itself. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 1 + include/sysemu/tpm_backend.h | 1 - backends/tpm.c | 4 ++-- hw/tpm/tpm_tis.c | 3 +-- tpm.c | 3 ++- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 9c49325f03..90e97b9170 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -30,6 +30,7 @@ typedef struct TPMIf { typedef struct TPMIfClass { InterfaceClass parent_class; =20 + enum TpmModel model; void (*request_completed)(TPMIf *obj); } TPMIfClass; =20 diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 51dfc0de9c..b12ae5b625 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -52,7 +52,6 @@ struct TPMBackend { =20 /* */ char *id; - enum TpmModel fe_model; =20 QLIST_ENTRY(TPMBackend) list; }; diff --git a/backends/tpm.c b/backends/tpm.c index 7b108bd5d8..0c48d18775 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -148,9 +148,10 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s) { TPMInfo *info =3D g_new0(TPMInfo, 1); TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); + TPMIfClass *tic =3D TPM_IF_GET_CLASS(s->tpmif); =20 info->id =3D g_strdup(s->id); - info->model =3D s->fe_model; + info->model =3D tic->model; if (k->get_tpm_options) { info->options =3D k->get_tpm_options(s); } @@ -204,7 +205,6 @@ static void tpm_backend_instance_init(Object *obj) tpm_backend_prop_get_opened, tpm_backend_prop_set_opened, NULL); - s->fe_model =3D -1; s->bh =3D qemu_bh_new(tpm_backend_request_completed_bh, s); } =20 diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 2fbc760730..3c8d246ac8 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1067,8 +1067,6 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) return; } =20 - s->be_driver->fe_model =3D TPM_MODEL_TPM_TIS; - if (tpm_backend_init(s->be_driver, TPM_IF(s), errp)) { return; } @@ -1103,6 +1101,7 @@ static void tpm_tis_class_init(ObjectClass *klass, vo= id *data) dc->props =3D tpm_tis_properties; dc->reset =3D tpm_tis_reset; dc->vmsd =3D &vmstate_tpm_tis; + tc->model =3D TPM_MODEL_TPM_TIS; tc->request_completed =3D tpm_tis_request_completed; } =20 diff --git a/tpm.c b/tpm.c index 45520f555d..ce1543fcb4 100644 --- a/tpm.c +++ b/tpm.c @@ -204,9 +204,10 @@ TPMInfoList *qmp_query_tpm(Error **errp) TPMInfoList *info, *head =3D NULL, *cur_item =3D NULL; =20 QLIST_FOREACH(drv, &tpm_backends, list) { - if (!tpm_models[drv->fe_model]) { + if (!drv->tpmif) { continue; } + info =3D g_new0(TPMInfoList, 1); info->value =3D tpm_backend_query_tpm(drv); =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 150759092803667.73700112858148; Mon, 9 Oct 2017 16:15:28 -0700 (PDT) Received: from localhost ([::1]:60206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hGS-00040k-1n for importer@patchew.org; Mon, 09 Oct 2017 19:15:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzq-0006ZH-HW for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzp-0005ON-As for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzp-0005No-2f for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F23223B9; Mon, 9 Oct 2017 22:57:59 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 844BC77710; Mon, 9 Oct 2017 22:57:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F23223B9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:08 +0200 Message-Id: <20171009225623.29232-28-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:58:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 27/42] tpm: remove unused opened code 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 12 ------------ backends/tpm.c | 42 ----------------------------------------= -- tpm.c | 6 ------ 3 files changed, 60 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index b12ae5b625..a893e586ae 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -81,8 +81,6 @@ struct TPMBackendClass { =20 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t); =20 - void (*opened)(TPMBackend *s, Error **errp); - void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd); }; =20 @@ -172,16 +170,6 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *= s); */ int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty); =20 -/** - * tpm_backend_open: - * @s: the backend to open - * @errp: a pointer to return the #Error object if an error occurs. - * - * This function will open the backend if it is not already open. Calling= this - * function on an already opened backend will not result in an error. - */ -void tpm_backend_open(TPMBackend *s, Error **errp); - /** * tpm_backend_get_tpm_version: * @s: the backend to call into diff --git a/backends/tpm.c b/backends/tpm.c index 0c48d18775..7e636fbc7a 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -159,52 +159,10 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s) return info; } =20 -static bool tpm_backend_prop_get_opened(Object *obj, Error **errp) -{ - TPMBackend *s =3D TPM_BACKEND(obj); - - return s->opened; -} - -void tpm_backend_open(TPMBackend *s, Error **errp) -{ - object_property_set_bool(OBJECT(s), true, "opened", errp); -} - -static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **e= rrp) -{ - TPMBackend *s =3D TPM_BACKEND(obj); - TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); - Error *local_err =3D NULL; - - if (value =3D=3D s->opened) { - return; - } - - if (!value && s->opened) { - error_setg(errp, QERR_PERMISSION_DENIED); - return; - } - - if (k->opened) { - k->opened(s, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - } - - s->opened =3D true; -} - static void tpm_backend_instance_init(Object *obj) { TPMBackend *s =3D TPM_BACKEND(obj); =20 - object_property_add_bool(obj, "opened", - tpm_backend_prop_get_opened, - tpm_backend_prop_set_opened, - NULL); s->bh =3D qemu_bh_new(tpm_backend_request_completed_bh, s); } =20 diff --git a/tpm.c b/tpm.c index ce1543fcb4..a46ee5f144 100644 --- a/tpm.c +++ b/tpm.c @@ -134,12 +134,6 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts= , Error **errp) return 1; } =20 - tpm_backend_open(drv, &local_err); - if (local_err) { - error_report_err(local_err); - return 1; - } - QLIST_INSERT_HEAD(&tpm_backends, drv, list); =20 return 0; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590999514660.6571153715564; Mon, 9 Oct 2017 16:16:39 -0700 (PDT) Received: from localhost ([::1]:60217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hHj-0005F4-LL for importer@patchew.org; Mon, 09 Oct 2017 19:16:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzs-0006ap-1E for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzr-0005Ox-9p for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzr-0005Od-3T for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02882C04AC46; Mon, 9 Oct 2017 22:58:02 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FA2F5C6BF; Mon, 9 Oct 2017 22:58:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 02882C04AC46 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:09 +0200 Message-Id: <20171009225623.29232-29-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:58:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 28/42] tpm-passthrough: don't save guessed cancel_path in options 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The value is later unneeded, and may leak if the free visitor doesn't consider it since has_cancel_path is false. And for consistency with "path" it shouldn't be returned in get_tpm_options(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 8c002e4da6..048edb1a1a 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -226,9 +226,7 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPassthr= uState *tpm_pt) if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel= ", dev) < sizeof(path)) { fd =3D qemu_open(path, O_WRONLY); - if (fd >=3D 0) { - tpm_pt->options->cancel_path =3D g_strdup(path); - } else { + if (fd < 0) { error_report("tpm_passthrough: Could not open TPM cancel " "path %s : %s", path, strerror(errno)); } --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591147913633.5116136596691; Mon, 9 Oct 2017 16:19:07 -0700 (PDT) Received: from localhost ([::1]:60226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hKB-0007P2-J6 for importer@patchew.org; Mon, 09 Oct 2017 19:19:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzv-0006e3-An for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzu-0005Q6-HY for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42964) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzu-0005Pg-B9 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:06 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C4607E43E; Mon, 9 Oct 2017 22:58:05 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BDB769FBC; Mon, 9 Oct 2017 22:58:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4C4607E43E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:10 +0200 Message-Id: <20171009225623.29232-30-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:58:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 29/42] tpm-be: update optional function pointers 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QEMU code doesn't generally have assert() for mandatory callbacks/function pointers, probably because the crash is pretty obvious. Document the methods instead of going into the code. Make get_tpm_options() mandatory to implement (since all backend implementation have it). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 5 ++++- backends/tpm.c | 9 +-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index a893e586ae..594bb50782 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -66,15 +66,18 @@ struct TPMBackendClass { =20 TPMBackend *(*create)(QemuOpts *opts, const char *id); =20 - /* start up the TPM on the backend */ + /* start up the TPM on the backend - optional */ int (*startup_tpm)(TPMBackend *t); =20 + /* optional */ void (*reset)(TPMBackend *t); =20 void (*cancel_cmd)(TPMBackend *t); =20 + /* optional */ bool (*get_tpm_established_flag)(TPMBackend *t); =20 + /* optional */ int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty); =20 TPMVersion (*get_tpm_version)(TPMBackend *t); diff --git a/backends/tpm.c b/backends/tpm.c index 7e636fbc7a..7777467c44 100644 --- a/backends/tpm.c +++ b/backends/tpm.c @@ -33,7 +33,6 @@ static void tpm_backend_worker_thread(gpointer data, gpoi= nter user_data) TPMBackend *s =3D TPM_BACKEND(user_data); TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - assert(k->handle_request !=3D NULL); k->handle_request(s, (TPMBackendCmd *)data); =20 qemu_bh_schedule(s->bh); @@ -114,8 +113,6 @@ void tpm_backend_cancel_cmd(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - assert(k->cancel_cmd); - k->cancel_cmd(s); } =20 @@ -139,8 +136,6 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s) { TPMBackendClass *k =3D TPM_BACKEND_GET_CLASS(s); =20 - assert(k->get_tpm_version); - return k->get_tpm_version(s); } =20 @@ -152,9 +147,7 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s) =20 info->id =3D g_strdup(s->id); info->model =3D tic->model; - if (k->get_tpm_options) { - info->options =3D k->get_tpm_options(s); - } + info->options =3D k->get_tpm_options(s); =20 return info; } --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591301426113.61110064085153; Mon, 9 Oct 2017 16:21:41 -0700 (PDT) Received: from localhost ([::1]:60239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hMW-0001E9-L5 for importer@patchew.org; Mon, 09 Oct 2017 19:21:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzx-0006fw-6r for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzw-0005Qv-IR for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzw-0005QO-D3 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5712B883C2; Mon, 9 Oct 2017 22:58:07 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD3245C6BF; Mon, 9 Oct 2017 22:58:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5712B883C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:11 +0200 Message-Id: <20171009225623.29232-31-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Oct 2017 22:58:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 30/42] tpm-passthrough: pass TPMPassthruState to handle_device_opts 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It doesn't need TPMBackend. Also reorder arguments for consistency. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 048edb1a1a..9326cbfdc9 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -239,9 +239,9 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPassthr= uState *tpm_pt) return fd; } =20 -static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *= tb) +static int +tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opt= s) { - TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); const char *value; =20 value =3D qemu_opt_get(opts, "cancel-path"); @@ -292,7 +292,7 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opt= s, const char *id) =20 tb->id =3D g_strdup(id); =20 - if (tpm_passthrough_handle_device_opts(opts, tb)) { + if (tpm_passthrough_handle_device_opts(tpm_pt, opts)) { goto err_exit; } =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591336295833.6226898323278; Mon, 9 Oct 2017 16:22:16 -0700 (PDT) Received: from localhost ([::1]:60241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hN2-0001ac-6s for importer@patchew.org; Mon, 09 Oct 2017 19:22:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1gzz-0006iK-Kl for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1gzy-0005T6-ND for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1gzy-0005SL-E5 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60E7813A5D; Mon, 9 Oct 2017 22:58:09 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAB325C6BF; Mon, 9 Oct 2017 22:58:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 60E7813A5D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:12 +0200 Message-Id: <20171009225623.29232-32-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:58:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 31/42] tpm-backend: move set 'id' to common code 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 2 +- hw/tpm/tpm_emulator.c | 12 +++--------- hw/tpm/tpm_passthrough.c | 9 +++------ tpm.c | 3 ++- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 594bb50782..881be97ee3 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -64,7 +64,7 @@ struct TPMBackendClass { /* get a descriptive text of the backend to display to the user */ const char *desc; =20 - TPMBackend *(*create)(QemuOpts *opts, const char *id); + TPMBackend *(*create)(QemuOpts *opts); =20 /* start up the TPM on the backend - optional */ int (*startup_tpm)(TPMBackend *t); diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 36454837b3..315819329b 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -453,22 +453,16 @@ err: return -1; } =20 -static TPMBackend *tpm_emulator_create(QemuOpts *opts, const char *id) +static TPMBackend *tpm_emulator_create(QemuOpts *opts) { TPMBackend *tb =3D TPM_BACKEND(object_new(TYPE_TPM_EMULATOR)); =20 - tb->id =3D g_strdup(id); - if (tpm_emulator_handle_device_opts(TPM_EMULATOR(tb), opts)) { - goto err_exit; + object_unref(OBJECT(tb)); + return NULL; } =20 return tb; - -err_exit: - object_unref(OBJECT(tb)); - - return NULL; } =20 static TpmTypeOptions *tpm_emulator_get_tpm_options(TPMBackend *tb) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 9326cbfdc9..7371d50739 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -284,13 +284,10 @@ tpm_passthrough_handle_device_opts(TPMPassthruState *= tpm_pt, QemuOpts *opts) return 1; } =20 -static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) +static TPMBackend *tpm_passthrough_create(QemuOpts *opts) { Object *obj =3D object_new(TYPE_TPM_PASSTHROUGH); - TPMBackend *tb =3D TPM_BACKEND(obj); - TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(tb); - - tb->id =3D g_strdup(id); + TPMPassthruState *tpm_pt =3D TPM_PASSTHROUGH(obj); =20 if (tpm_passthrough_handle_device_opts(tpm_pt, opts)) { goto err_exit; @@ -301,7 +298,7 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opt= s, const char *id) goto err_exit; } =20 - return tb; + return TPM_BACKEND(obj); =20 err_exit: object_unref(obj); diff --git a/tpm.c b/tpm.c index a46ee5f144..37298f3f03 100644 --- a/tpm.c +++ b/tpm.c @@ -129,11 +129,12 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opt= s, Error **errp) return 1; } =20 - drv =3D be->create(opts, id); + drv =3D be->create(opts); if (!drv) { return 1; } =20 + drv->id =3D g_strdup(id); QLIST_INSERT_HEAD(&tpm_backends, drv, list); =20 return 0; --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591504710242.11428527692317; Mon, 9 Oct 2017 16:25:04 -0700 (PDT) Received: from localhost ([::1]:60253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hPu-0003yS-RR for importer@patchew.org; Mon, 09 Oct 2017 19:24:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h06-0006pC-Qs for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h03-0005Uv-PG for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h03-0005Uj-J3 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7FF067E43E; Mon, 9 Oct 2017 22:58:14 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01F246155F; Mon, 9 Oct 2017 22:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7FF067E43E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:13 +0200 Message-Id: <20171009225623.29232-33-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:58:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 32/42] tpm-passthrough: make it safer to destroy after creation 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Check fds values before closing, to avoid close(-1). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 7371d50739..aa9167e3c6 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -347,8 +347,12 @@ static void tpm_passthrough_inst_finalize(Object *obj) =20 tpm_passthrough_cancel_cmd(TPM_BACKEND(obj)); =20 - qemu_close(tpm_pt->tpm_fd); - qemu_close(tpm_pt->cancel_fd); + if (tpm_pt->tpm_fd >=3D 0) { + qemu_close(tpm_pt->tpm_fd); + } + if (tpm_pt->cancel_fd >=3D 0) { + qemu_close(tpm_pt->cancel_fd); + } qapi_free_TPMPassthroughOptions(tpm_pt->options); } =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591072139415.2715090238912; Mon, 9 Oct 2017 16:17:52 -0700 (PDT) Received: from localhost ([::1]:60220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hIr-0006FW-9w for importer@patchew.org; Mon, 09 Oct 2017 19:17:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h08-0006qi-HD for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h07-0005WL-DX for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h07-0005Vr-7J for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E5A1C04AC6A; Mon, 9 Oct 2017 22:58:18 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1EA1600CD; Mon, 9 Oct 2017 22:58:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E5A1C04AC6A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:14 +0200 Message-Id: <20171009225623.29232-34-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 09 Oct 2017 22:58:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 33/42] tpm-passthrough: remove error cleanup from handle_device_opts 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Clean-up is handled by the create() function. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/tpm/tpm_passthrough.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index aa9167e3c6..0806cf86af 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -261,27 +261,16 @@ tpm_passthrough_handle_device_opts(TPMPassthruState *= tpm_pt, QemuOpts *opts) if (tpm_pt->tpm_fd < 0) { error_report("Cannot access TPM device using '%s': %s", tpm_pt->tpm_dev, strerror(errno)); - goto err_free_parameters; + return -1; } =20 if (tpm_util_test_tpmdev(tpm_pt->tpm_fd, &tpm_pt->tpm_version)) { error_report("'%s' is not a TPM device.", tpm_pt->tpm_dev); - goto err_close_tpmdev; + return -1; } =20 return 0; - - err_close_tpmdev: - qemu_close(tpm_pt->tpm_fd); - tpm_pt->tpm_fd =3D -1; - - err_free_parameters: - qapi_free_TPMPassthroughOptions(tpm_pt->options); - tpm_pt->options =3D NULL; - tpm_pt->tpm_dev =3D NULL; - - return 1; } =20 static TPMBackend *tpm_passthrough_create(QemuOpts *opts) --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591075196372.1167490793222; Mon, 9 Oct 2017 16:17:55 -0700 (PDT) Received: from localhost ([::1]:60222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hJ0-0006Mx-Ca for importer@patchew.org; Mon, 09 Oct 2017 19:17:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0G-0006w5-Sw for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0D-0005aJ-Qa for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0D-0005a5-K9 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A2C685363; Mon, 9 Oct 2017 22:58:24 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6E205ED4D; Mon, 9 Oct 2017 22:58:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8A2C685363 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:15 +0200 Message-Id: <20171009225623.29232-35-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 09 Oct 2017 22:58:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 34/42] tpm-passthrough: workaround a possible race 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The TPM backend processing thread has common shared variable race issues. (they should not be so easy to reach since guest interaction with the device is slow compared to host emulation) An obvious one is setting op_cancelled from device thread after calling write(cancel_fd). The backend thread may return before the device thread has set the variable. Instead set it before cancellation. Even if the write() failed, the end result is command get possibly cancelled (even if cancellation came from external sources it doesn't matter much). It's worth to consider removing the backend processing thread for now. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 0806cf86af..d71d64e8aa 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -89,6 +89,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState = *tpm_pt, bool is_selftest; const struct tpm_resp_hdr *hdr; =20 + /* FIXME: protect shared variables or use other sync mechanism */ tpm_pt->tpm_op_canceled =3D false; tpm_pt->tpm_executing =3D true; *selftest_done =3D false; @@ -178,12 +179,11 @@ static void tpm_passthrough_cancel_cmd(TPMBackend *tb) */ if (tpm_pt->tpm_executing) { if (tpm_pt->cancel_fd >=3D 0) { + tpm_pt->tpm_op_canceled =3D true; n =3D write(tpm_pt->cancel_fd, "-", 1); if (n !=3D 1) { error_report("Canceling TPM command failed: %s", strerror(errno)); - } else { - tpm_pt->tpm_op_canceled =3D true; } } else { error_report("Cannot cancel TPM command due to missing " --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507590927180936.8162007661036; Mon, 9 Oct 2017 16:15:27 -0700 (PDT) Received: from localhost ([::1]:60209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hGZ-00047e-0x for importer@patchew.org; Mon, 09 Oct 2017 19:15:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0G-0006w4-SX for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0F-0005al-Qd for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43230) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0F-0005aX-L5 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98E1F7E43E; Mon, 9 Oct 2017 22:58:26 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E36600CD; Mon, 9 Oct 2017 22:58:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 98E1F7E43E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:16 +0200 Message-Id: <20171009225623.29232-36-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:58:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 35/42] tpm-tis: simplify header inclusion 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_tis.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 3c8d246ac8..e7e8b112e8 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -24,17 +24,12 @@ =20 #include "qemu/osdep.h" #include "hw/isa/isa.h" -#include "sysemu/tpm_backend.h" -#include "tpm_int.h" -#include "sysemu/block-backend.h" -#include "exec/address-spaces.h" -#include "hw/hw.h" -#include "hw/i386/pc.h" -#include "hw/pci/pci_ids.h" #include "qapi/error.h" -#include "qemu-common.h" -#include "qemu/main-loop.h" + #include "hw/acpi/tpm.h" +#include "hw/pci/pci_ids.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" =20 #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ #define TPM_TIS_LOCALITY_SHIFT 12 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591425570661.2923980629748; Mon, 9 Oct 2017 16:23:45 -0700 (PDT) Received: from localhost ([::1]:60246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hOc-0002zM-QH for importer@patchew.org; Mon, 09 Oct 2017 19:23:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0I-0006xp-Lk for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0H-0005c1-Vp for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55266) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0H-0005bi-R7 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2633883C9; Mon, 9 Oct 2017 22:58:28 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65D8D61550; Mon, 9 Oct 2017 22:58:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2633883C9 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:17 +0200 Message-Id: <20171009225623.29232-37-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Oct 2017 22:58:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 36/42] tpm: rename qemu_find_tpm() -> qemu_find_tpm_be() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" find_tpm() will be introduced to lookup the TPM device. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm_backend.h | 2 +- hw/tpm/tpm_tis.c | 2 +- tpm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index 881be97ee3..d02067e631 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -193,7 +193,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); */ TPMInfo *tpm_backend_query_tpm(TPMBackend *s); =20 -TPMBackend *qemu_find_tpm(const char *id); +TPMBackend *qemu_find_tpm_be(const char *id); =20 void tpm_register_model(enum TpmModel model); =20 diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index e7e8b112e8..954b7b0e5d 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -1055,7 +1055,7 @@ static void tpm_tis_realizefn(DeviceState *dev, Error= **errp) { TPMState *s =3D TPM(dev); =20 - s->be_driver =3D qemu_find_tpm(s->backend); + s->be_driver =3D qemu_find_tpm_be(s->backend); if (!s->be_driver) { error_setg(errp, "tpm_tis: backend driver with id %s could not be " "found", s->backend); diff --git a/tpm.c b/tpm.c index 37298f3f03..4d6c45a4f2 100644 --- a/tpm.c +++ b/tpm.c @@ -71,7 +71,7 @@ static void tpm_display_backend_drivers(void) /* * Find the TPM with the given Id */ -TPMBackend *qemu_find_tpm(const char *id) +TPMBackend *qemu_find_tpm_be(const char *id) { TPMBackend *drv; =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 150759123325644.39717871710752; Mon, 9 Oct 2017 16:20:33 -0700 (PDT) Received: from localhost ([::1]:60231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hLS-000058-NJ for importer@patchew.org; Mon, 09 Oct 2017 19:20:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0R-000761-KU for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0Q-0005e3-Jz for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0Q-0005dp-Bw for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EA7E883C2; Mon, 9 Oct 2017 22:58:37 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71DDA18990; Mon, 9 Oct 2017 22:58:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3EA7E883C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:18 +0200 Message-Id: <20171009225623.29232-38-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Oct 2017 22:58:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 37/42] tpm: lookup the the TPM interface instead of TIS 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, Eduardo Habkost , "Michael S. Tsirkin" , stefanb@linux.vnet.ibm.com, Paolo Bonzini , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This will allow to introduce new devices implementing TPM. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_int.h | 19 ------------------- include/sysemu/tpm.h | 52 ++++++++++++++++++++++++++++++++++++++----------= ---- hw/i386/acpi-build.c | 2 +- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 90e97b9170..86fadc16d3 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -15,25 +15,6 @@ #include "qemu/osdep.h" #include "qom/object.h" =20 -#define TYPE_TPM_IF "tpm-if" -#define TPM_IF_CLASS(klass) \ - OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF) -#define TPM_IF_GET_CLASS(obj) \ - OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF) -#define TPM_IF(obj) \ - INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF) - -typedef struct TPMIf { - Object parent_obj; -} TPMIf; - -typedef struct TPMIfClass { - InterfaceClass parent_class; - - enum TpmModel model; - void (*request_completed)(TPMIf *obj); -} TPMIfClass; - #define TPM_STANDARD_CMDLINE_OPTS \ { \ .name =3D "type", \ diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 62b073beeb..dbd2b0cc7a 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -12,32 +12,56 @@ #ifndef QEMU_TPM_H #define QEMU_TPM_H =20 -#include "qemu/option.h" +#include "qom/object.h" +#include "qapi-types.h" =20 -int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); -int tpm_init(void); -void tpm_cleanup(void); - -typedef enum TPMVersion { +typedef enum TPMVersion { TPM_VERSION_UNSPEC =3D 0, TPM_VERSION_1_2 =3D 1, TPM_VERSION_2_0 =3D 2, } TPMVersion; =20 -TPMVersion tpm_tis_get_tpm_version(Object *obj); +#define TYPE_TPM_IF "tpm-if" +#define TPM_IF_CLASS(klass) \ + OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF) +#define TPM_IF_GET_CLASS(obj) \ + OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF) +#define TPM_IF(obj) \ + INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF) + +typedef struct TPMIf { + Object parent_obj; +} TPMIf; + +typedef struct TPMIfClass { + InterfaceClass parent_class; + + enum TpmModel model; + void (*request_completed)(TPMIf *obj); +} TPMIfClass; + +int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); +int tpm_init(void); +void tpm_cleanup(void); =20 #define TYPE_TPM_TIS "tpm-tis" =20 -static inline TPMVersion tpm_get_version(void) +static inline TPMIf *tpm_find(void) { -#ifdef CONFIG_TPM - Object *obj =3D object_resolve_path_type("", TYPE_TPM_TIS, NULL); + Object *obj =3D object_resolve_path_type("", TYPE_TPM_IF, NULL); + + return TPM_IF(obj); +} =20 - if (obj) { - return tpm_tis_get_tpm_version(obj); +TPMVersion tpm_tis_get_tpm_version(Object *obj); + +static inline TPMVersion tpm_get_version(TPMIf *ti) +{ + if (!ti) { + return TPM_VERSION_UNSPEC; } -#endif - return TPM_VERSION_UNSPEC; + + return tpm_tis_get_tpm_version(OBJECT(ti)); } =20 #endif /* QEMU_TPM_H */ diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 2af37a9129..40371b6f75 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -208,7 +208,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) } =20 info->has_hpet =3D hpet_find(); - info->tpm_version =3D tpm_get_version(); + info->tpm_version =3D tpm_get_version(tpm_find()); info->pvpanic_port =3D pvpanic_port(); info->applesmc_io_base =3D applesmc_port(); } --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591369904885.9172442363123; Mon, 9 Oct 2017 16:22:49 -0700 (PDT) Received: from localhost ([::1]:60243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hNg-0002Ff-7o for importer@patchew.org; Mon, 09 Oct 2017 19:22:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0V-000791-Le for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0U-0005fd-Pm for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55616) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0U-0005fI-JK for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8ACEA883C5; Mon, 9 Oct 2017 22:58:41 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id A399877713; Mon, 9 Oct 2017 22:58:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8ACEA883C5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:19 +0200 Message-Id: <20171009225623.29232-39-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Oct 2017 22:58:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 38/42] tpm: add TPM interface to lookup TPM version 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Do not hardcode TPM device model to lookup version, use an interface instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm.h | 5 ++--- hw/tpm/tpm_tis.c | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index dbd2b0cc7a..9439330cf1 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -38,6 +38,7 @@ typedef struct TPMIfClass { =20 enum TpmModel model; void (*request_completed)(TPMIf *obj); + enum TPMVersion (*get_version)(TPMIf *obj); } TPMIfClass; =20 int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); @@ -53,15 +54,13 @@ static inline TPMIf *tpm_find(void) return TPM_IF(obj); } =20 -TPMVersion tpm_tis_get_tpm_version(Object *obj); - static inline TPMVersion tpm_get_version(TPMIf *ti) { if (!ti) { return TPM_VERSION_UNSPEC; } =20 - return tpm_tis_get_tpm_version(OBJECT(ti)); + return TPM_IF_GET_CLASS(ti)->get_version(ti); } =20 #endif /* QEMU_TPM_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 954b7b0e5d..6aac9bfe6b 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -989,9 +989,9 @@ static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb) /* * Get the TPMVersion of the backend device being used */ -TPMVersion tpm_tis_get_tpm_version(Object *obj) +static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti) { - TPMState *s =3D TPM(obj); + TPMState *s =3D TPM(ti); =20 return tpm_backend_get_tpm_version(s->be_driver); } @@ -1097,6 +1097,7 @@ static void tpm_tis_class_init(ObjectClass *klass, vo= id *data) dc->reset =3D tpm_tis_reset; dc->vmsd =3D &vmstate_tpm_tis; tc->model =3D TPM_MODEL_TPM_TIS; + tc->get_version =3D tpm_tis_get_tpm_version; tc->request_completed =3D tpm_tis_request_completed; } =20 --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591618733475.1795434324032; Mon, 9 Oct 2017 16:26:58 -0700 (PDT) Received: from localhost ([::1]:60267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hRb-0005Ix-4m for importer@patchew.org; Mon, 09 Oct 2017 19:26:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0c-0007Ef-7L for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0Y-0005hA-SO for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0Y-0005h4-Me for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A22CA13A5D; Mon, 9 Oct 2017 22:58:45 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAF38600CD; Mon, 9 Oct 2017 22:58:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A22CA13A5D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:20 +0200 Message-Id: <20171009225623.29232-40-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 Oct 2017 22:58:45 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 39/42] tpm: add tpm_cmd_get_size() to tpm_util 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function is generally useful and used in the following patches. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_util.h | 8 +++++++- hw/tpm/tpm_tis.c | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h index 2f7c96146d..aca10c97bf 100644 --- a/hw/tpm/tpm_util.h +++ b/hw/tpm/tpm_util.h @@ -22,7 +22,8 @@ #ifndef TPM_TPM_UTIL_H #define TPM_TPM_UTIL_H =20 -#include "sysemu/tpm_backend.h" +#include "sysemu/tpm.h" +#include "qemu/bswap.h" =20 void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len); =20 @@ -30,4 +31,9 @@ bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_= len); =20 int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version); =20 +static inline uint32_t tpm_cmd_get_size(const void *b) +{ + return be32_to_cpu(*(const uint32_t *)(b + 2)); +} + #endif /* TPM_TPM_UTIL_H */ diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 6aac9bfe6b..d0e1aac247 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -30,6 +30,7 @@ #include "hw/pci/pci_ids.h" #include "sysemu/tpm_backend.h" #include "tpm_int.h" +#include "tpm_util.h" =20 #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */ #define TPM_TIS_LOCALITY_SHIFT 12 @@ -216,7 +217,7 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) =20 static uint32_t tpm_tis_get_size_from_buffer(const TPMSizedBuffer *sb) { - return be32_to_cpu(*(uint32_t *)&sb->buffer[2]); + return tpm_cmd_get_size(sb->buffer); } =20 static void tpm_tis_show_buffer(const TPMSizedBuffer *sb, const char *stri= ng) --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591547388266.5926631738881; Mon, 9 Oct 2017 16:25:47 -0700 (PDT) Received: from localhost ([::1]:60263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hQa-0004cU-NQ for importer@patchew.org; Mon, 09 Oct 2017 19:25:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0h-0007Ig-2r for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0g-0005jA-3p for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43838) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0f-0005io-S1 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA2993680A; Mon, 9 Oct 2017 22:58:52 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CCC85ED4D; Mon, 9 Oct 2017 22:58:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA2993680A Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:21 +0200 Message-Id: <20171009225623.29232-41-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 09 Oct 2017 22:58:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 40/42] acpi: change TPM TIS data conditions 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, Eduardo Habkost , "Michael S. Tsirkin" , stefanb@linux.vnet.ibm.com, Paolo Bonzini , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The device should be exposed if present. It shouldn't have an undefined version (or else backend init failed, and device should fail too). Finally, make the fields specific to TIS device model. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- include/sysemu/tpm.h | 3 +++ hw/i386/acpi-build.c | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 9439330cf1..8223ec621c 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -47,6 +47,9 @@ void tpm_cleanup(void); =20 #define TYPE_TPM_TIS "tpm-tis" =20 +#define TPM_IS_TIS(chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS) + static inline TPMIf *tpm_find(void) { Object *obj =3D object_resolve_path_type("", TYPE_TPM_IF, NULL); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 40371b6f75..ee38b00e31 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2038,7 +2038,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } =20 - if (misc->tpm_version !=3D TPM_VERSION_UNSPEC) { + if (TPM_IS_TIS(tpm_find())) { aml_append(crs, aml_memory32_fixed(TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE, AML_READ_WRITE)); } @@ -2204,7 +2204,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, /* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en); =20 - if (misc->tpm_version !=3D TPM_VERSION_UNSPEC) { + if (TPM_IS_TIS(tpm_find())) { dev =3D aml_device("ISA.TPM"); aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31"= ))); aml_append(dev, aml_name_decl("_STA", aml_int(0xF))); @@ -2281,8 +2281,12 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) tpm2_ptr =3D acpi_data_push(table_data, sizeof *tpm2_ptr); =20 tpm2_ptr->platform_class =3D cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); - tpm2_ptr->control_area_address =3D cpu_to_le64(0); - tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_MMIO); + if (TPM_IS_TIS(tpm_find())) { + tpm2_ptr->control_area_address =3D cpu_to_le64(0); + tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_MMIO); + } else { + g_warn_if_reached(); + } =20 build_header(linker, table_data, (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NUL= L); --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591238223211.3744248575074; Mon, 9 Oct 2017 16:20:38 -0700 (PDT) Received: from localhost ([::1]:60229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hLI-0008NU-D2 for importer@patchew.org; Mon, 09 Oct 2017 19:20:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0k-0007LP-57 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0h-0005kB-Rx for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0h-0005jm-Mj for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:58:55 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7CE8883C3; Mon, 9 Oct 2017 22:58:54 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20B1B18990; Mon, 9 Oct 2017 22:58:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A7CE8883C3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:22 +0200 Message-Id: <20171009225623.29232-42-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 09 Oct 2017 22:58:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 41/42] tpm-emulator: add a FIXME comment about blocking cancel 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Berger --- hw/tpm/tpm_emulator.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 315819329b..091d7ea147 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -328,6 +328,7 @@ static void tpm_emulator_cancel_cmd(TPMBackend *tb) return; } =20 + /* FIXME: make the function non-blocking, or it may block a VCPU */ if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_CANCEL_TPM_CMD, &res,= 0, sizeof(res)) < 0) { error_report("tpm-emulator: Could not cancel command: %s", --=20 2.14.1.146.gd35faa819 From nobody Sun Apr 28 04:08:33 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 1507591653661681.0921809051758; Mon, 9 Oct 2017 16:27:33 -0700 (PDT) Received: from localhost ([::1]:60268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1hS9-0005pt-Mz for importer@patchew.org; Mon, 09 Oct 2017 19:27:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1h0q-0007Rv-RA for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:59:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1h0o-0005mN-Pw for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:59:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1h0o-0005m5-Fv for qemu-devel@nongnu.org; Mon, 09 Oct 2017 18:59:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F6A67E440; Mon, 9 Oct 2017 22:59:01 +0000 (UTC) Received: from localhost (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4459017525; Mon, 9 Oct 2017 22:58:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6F6A67E440 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 00:56:23 +0200 Message-Id: <20171009225623.29232-43-marcandre.lureau@redhat.com> In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com> References: <20171009225623.29232-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 09 Oct 2017 22:59:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 42/42] WIP: add TPM CRB 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, Eduardo Habkost , "Michael S. Tsirkin" , stefanb@linux.vnet.ibm.com, Markus Armbruster , Paolo Bonzini , Igor Mammedov , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface as defined in TCG PC Client Platform TPM Profile (PTP) Specification Family =E2=80=9C2.0=E2=80=9D Level 00 Revision 01.03 v22. The PTP allows device implementation to switch between TIS and CRB model at run time, but given that CRB is a simpler device to implement, I chose to implement it as a different device. The device doesn't implement other locality than 0 for now (my laptop TPM doesn't either, so I assume this isn't so bad) The command/reply memory region is statically allocated after the CRB registers address TPM_CRB_ADDR_BASE + sizeof(struct crb_regs). I wonder if the BIOS could or should allocate it instead, or what size to use. The PTP doesn't specify a particular bus to put the device. I chose to add it on the system bus directly, so it could hopefully be used easily on a different platform. However, I am not sure this is easily done or a smart approach. It fails to init on piix, because error_on_sysbus_device() check. Removing this check, the device is still functional... We may want to put it on ISA bus instead for now. Tested with some success with Linux upstream and Windows 10. The device is recognized and correctly transmit command/response with passthrough/emu, but the swtpm emulator has some issues I need to investigate further. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi/tpm.json | 7 +- include/hw/acpi/tpm.h | 65 ++++++++ include/sysemu/tpm.h | 3 + hw/i386/acpi-build.c | 19 +++ hw/tpm/tpm_crb.c | 320 +++++++++++++++++++++++++++++++++= ++++ default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/tpm/Makefile.objs | 1 + 8 files changed, 414 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_crb.c diff --git a/qapi/tpm.json b/qapi/tpm.json index 7093f268fb..12a4509ad6 100644 --- a/qapi/tpm.json +++ b/qapi/tpm.json @@ -10,11 +10,12 @@ # # An enumeration of TPM models # -# @tpm-tis: TPM TIS model +# @tpm-tis: TPM TIS model (since 1.5) +# @tpm-crb: TPM CRB model (since 2.11) # # Since: 1.5 ## -{ 'enum': 'TpmModel', 'data': [ 'tpm-tis' ] } +{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb' ] } =20 ## # @query-tpm-models: @@ -28,7 +29,7 @@ # Example: # # -> { "execute": "query-tpm-models" } -# <- { "return": [ "tpm-tis" ] } +# <- { "return": [ "tpm-tis", "tpm-crb" ] } # ## { 'command': 'query-tpm-models', 'returns': ['TpmModel'] } diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h index 6d516c6a7f..c0b9a0ca6e 100644 --- a/include/hw/acpi/tpm.h +++ b/include/hw/acpi/tpm.h @@ -16,11 +16,75 @@ #ifndef HW_ACPI_TPM_H #define HW_ACPI_TPM_H =20 +#include "qemu/osdep.h" + #define TPM_TIS_ADDR_BASE 0xFED40000 #define TPM_TIS_ADDR_SIZE 0x5000 =20 #define TPM_TIS_IRQ 5 =20 +struct crb_regs { + union { + uint32_t loc_state; + struct { + unsigned tpm_established:1; + unsigned loc_assigned:1; + unsigned active_locality:3; + unsigned reserved:2; + unsigned tpm_reg_valid_sts:1; + } loc_state_bits; + }; + uint32_t reserved1; + uint32_t loc_ctrl; + uint32_t loc_sts; + uint8_t reserved2[32]; + union { + uint64_t intf_id; + struct { + unsigned type:4; + unsigned version:4; + unsigned cap_locality:1; + unsigned cap_crb_idle_bypass:1; + unsigned reserved1:1; + unsigned cap_data_xfer_size_support:2; + unsigned cap_fifo:1; + unsigned cap_crb:1; + unsigned cap_if_res:2; + unsigned if_selector:2; + unsigned if_selector_lock:1; + unsigned reserved2:4; + unsigned rid:8; + unsigned vid:16; + unsigned did:16; + } intf_id_bits; + }; + uint64_t ctrl_ext; + + uint32_t ctrl_req; + union { + uint32_t ctrl_sts; + struct { + unsigned tpm_sts:1; + unsigned tpm_idle:1; + unsigned reserved:30; + } ctrl_sts_bits; + }; + uint32_t ctrl_cancel; + uint32_t ctrl_start; + uint32_t ctrl_int_enable; + uint32_t ctrl_int_sts; + uint32_t ctrl_cmd_size; + uint32_t ctrl_cmd_pa_low; + uint32_t ctrl_cmd_pa_high; + uint32_t ctrl_rsp_size; + uint64_t ctrl_rsp_pa; +} QEMU_PACKED; + +#define TPM_CRB_ADDR_BASE 0xFED40000 +#define TPM_CRB_ADDR_SIZE 0x1000 +#define TPM_CRB_ADDR_CTRL \ + (TPM_CRB_ADDR_BASE + offsetof(struct crb_regs, ctrl_req)) + #define TPM_LOG_AREA_MINIMUM_SIZE (64 * 1024) =20 #define TPM_TCPA_ACPI_CLASS_CLIENT 0 @@ -30,5 +94,6 @@ #define TPM2_ACPI_CLASS_SERVER 1 =20 #define TPM2_START_METHOD_MMIO 6 +#define TPM2_START_METHOD_CRB 7 =20 #endif /* HW_ACPI_TPM_H */ diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 8223ec621c..bdc6bde109 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -46,9 +46,12 @@ int tpm_init(void); void tpm_cleanup(void); =20 #define TYPE_TPM_TIS "tpm-tis" +#define TYPE_TPM_CRB "tpm-crb" =20 #define TPM_IS_TIS(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS) +#define TPM_IS_CRB(chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB) =20 static inline TPMIf *tpm_find(void) { diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index ee38b00e31..f9345c75e6 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2224,6 +2224,22 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, aml_append(sb_scope, scope); } } + + if (TPM_IS_CRB(tpm_find())) { + dev =3D aml_device("TPM"); + aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101"))); + crs =3D aml_resource_template(); + aml_append(crs, aml_memory32_fixed(TPM_CRB_ADDR_BASE, + TPM_CRB_ADDR_SIZE, AML_READ_WRI= TE)); + aml_append(dev, aml_name_decl("_CRS", crs)); + + method =3D aml_method("_STA", 0, AML_NOTSERIALIZED); + aml_append(method, aml_return(aml_int(0x0f))); + aml_append(dev, method); + + aml_append(sb_scope, dev); + } + aml_append(dsdt, sb_scope); =20 /* copy AML table into ACPI tables blob and patch header there */ @@ -2284,6 +2300,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) if (TPM_IS_TIS(tpm_find())) { tpm2_ptr->control_area_address =3D cpu_to_le64(0); tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_MMIO); + } else if (TPM_IS_CRB(tpm_find())) { + tpm2_ptr->control_area_address =3D cpu_to_le32(TPM_CRB_ADDR_CTRL); + tpm2_ptr->start_method =3D cpu_to_le32(TPM2_START_METHOD_CRB); } else { g_warn_if_reached(); } diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c new file mode 100644 index 0000000000..64039ebc8e --- /dev/null +++ b/hw/tpm/tpm_crb.c @@ -0,0 +1,320 @@ +/* + * tpm_crb.c - QEMU's TPM CRB interface emulator + * + * Copyright (c) 2017 Red Hat, Inc. + * + * Authors: + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * tpm_crb is a device for TPM 2.0 Command Response Buffer (CRB) Interface + * as defined in TCG PC Client Platform TPM Profile (PTP) Specification + * Family =E2=80=9C2.0=E2=80=9D Level 00 Revision 01.03 v22 + */ + +#include "qemu/osdep.h" + +#include "qemu-common.h" +#include "qapi/error.h" +#include "hw/sysbus.h" +#include "exec/address-spaces.h" + +#include "hw/pci/pci_ids.h" +#include "hw/acpi/tpm.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "tpm_util.h" + +typedef struct CRBState { + SysBusDevice parent_obj; + + MemoryRegion mmio; + MemoryRegion cmdmem; + char *backend; + TPMBackend *tpmbe; + TPMBackendCmd cmd; + struct crb_regs regs; +} CRBState; + +#define CRB(obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB) + +#define DEBUG_CRB 0 + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_CRB) { \ + printf(fmt, ## __VA_ARGS__); \ + } \ + } while (0); + +#define CRB_ADDR_LOC_STATE offsetof(struct crb_regs, loc_state) +#define CRB_ADDR_LOC_CTRL offsetof(struct crb_regs, loc_ctrl) +#define CRB_ADDR_CTRL_REQ offsetof(struct crb_regs, ctrl_req) +#define CRB_ADDR_CTRL_CANCEL offsetof(struct crb_regs, ctrl_cancel) +#define CRB_ADDR_CTRL_START offsetof(struct crb_regs, ctrl_start) + +#define CRB_INTF_TYPE_CRB_ACTIVE 0b1 +#define CRB_INTF_VERSION_CRB 0b1 +#define CRB_INTF_CAP_LOCALITY_0_ONLY 0b0 +#define CRB_INTF_CAP_IDLE_FAST 0b0 +#define CRB_INTF_CAP_XFER_SIZE_64 0b11 +#define CRB_INTF_CAP_FIFO_NOT_SUPPORTED 0b0 +#define CRB_INTF_CAP_CRB_SUPPORTED 0b1 +#define CRB_INTF_IF_SELECTOR_CRB 0b1 +#define CRB_INTF_IF_SELECTOR_UNLOCKED 0b0 + +#define CRB_CTRL_CMD_SIZE (TPM_CRB_ADDR_SIZE - sizeof(struct crb_regs)) + +enum crb_loc_ctrl { + CRB_LOC_CTRL_REQUEST_ACCESS =3D BIT(0), + CRB_LOC_CTRL_RELINQUISH =3D BIT(1), + CRB_LOC_CTRL_SEIZE =3D BIT(2), + CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT =3D BIT(3), +}; + +enum crb_ctrl_req { + CRB_CTRL_REQ_CMD_READY =3D BIT(0), + CRB_CTRL_REQ_GO_IDLE =3D BIT(1), +}; + +enum crb_ctrl_sts { + CRB_CTRL_STS_ERROR =3D BIT(0), + CRB_CTRL_STS_TPM_IDLE =3D BIT(1), +}; + +enum crb_start { + CRB_START_INVOKE =3D BIT(0), +}; + +enum crb_cancel { + CRB_CANCEL_INVOKE =3D BIT(0), +}; + +static const char *addr_desc(unsigned off) +{ + switch (off) { +#define CASE(off) \ + case offsetof(struct crb_regs, off): \ + return G_STRINGIFY(off) + CASE(loc_state); + CASE(reserved1); + CASE(loc_ctrl); + CASE(loc_sts); + CASE(reserved2); + CASE(intf_id); + CASE(ctrl_ext); + CASE(ctrl_req); + CASE(ctrl_sts); + CASE(ctrl_cancel); + CASE(ctrl_start); + CASE(ctrl_int_enable); + CASE(ctrl_int_sts); + CASE(ctrl_cmd_size); + CASE(ctrl_cmd_pa_low); + CASE(ctrl_cmd_pa_high); + CASE(ctrl_rsp_size); + CASE(ctrl_rsp_pa); +#undef CASE + } + return NULL; +} + +static uint64_t tpm_crb_mmio_read(void *opaque, hwaddr addr, + unsigned size) +{ + CRBState *s =3D CRB(opaque); + DPRINTF("CRB read %lx:%s %u\n", addr, addr_desc(addr), size); + + /* all registers are 32-bit aligned */ + if (addr % 4) { + return G_MAXUINT64; + } + return ((uint32_t *)&s->regs)[addr / 4]; +} + +static void tpm_crb_mmio_write(void *opaque, hwaddr addr, + uint64_t val, unsigned size) +{ + CRBState *s =3D CRB(opaque); + DPRINTF("CRB write %lx:%s %lu %u\n", addr, addr_desc(addr), val, size); + + switch (addr) { + case CRB_ADDR_CTRL_REQ: + switch (val) { + case CRB_CTRL_REQ_CMD_READY: + s->regs.ctrl_sts_bits.tpm_idle =3D 0; + break; + case CRB_CTRL_REQ_GO_IDLE: + s->regs.ctrl_sts_bits.tpm_idle =3D 1; + break; + } + break; + case CRB_ADDR_CTRL_CANCEL: + if (val =3D=3D CRB_CANCEL_INVOKE && s->regs.ctrl_start & CRB_START= _INVOKE) { + tpm_backend_cancel_cmd(s->tpmbe); + } + break; + case CRB_ADDR_CTRL_START: + if (val =3D=3D CRB_START_INVOKE && + !(s->regs.ctrl_start & CRB_START_INVOKE)) { + void *mem =3D memory_region_get_ram_ptr(&s->cmdmem); + + s->regs.ctrl_start |=3D CRB_START_INVOKE; + s->cmd =3D (TPMBackendCmd) { + .in =3D mem, + .in_len =3D MIN(tpm_cmd_get_size(mem), CRB_CTRL_CMD_SIZE), + .out =3D mem, + .out_len =3D CRB_CTRL_CMD_SIZE, + }; + + tpm_backend_deliver_request(s->tpmbe, &s->cmd); + } + break; + case CRB_ADDR_LOC_CTRL: + switch (val) { + case CRB_LOC_CTRL_RESET_ESTABLISHMENT_BIT: + /* not loc 3 or 4 */ + break; + case CRB_LOC_CTRL_RELINQUISH: + break; + case CRB_LOC_CTRL_REQUEST_ACCESS: + s->regs.loc_state_bits.loc_assigned =3D 1; + s->regs.loc_state_bits.tpm_reg_valid_sts =3D 1; + break; + } + break; + } +} + +static const MemoryRegionOps tpm_crb_memory_ops =3D { + .read =3D tpm_crb_mmio_read, + .write =3D tpm_crb_mmio_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 4, + }, +}; + +static void tpm_crb_reset(DeviceState *dev) +{ + CRBState *s =3D CRB(dev); + + s->regs =3D (struct crb_regs) { + .intf_id_bits =3D { + .type =3D CRB_INTF_TYPE_CRB_ACTIVE, + .version =3D CRB_INTF_VERSION_CRB, + .cap_locality =3D CRB_INTF_CAP_LOCALITY_0_ONLY, + .cap_crb_idle_bypass =3D CRB_INTF_CAP_IDLE_FAST, + .cap_data_xfer_size_support =3D CRB_INTF_CAP_XFER_SIZE_64, + .cap_fifo =3D CRB_INTF_CAP_FIFO_NOT_SUPPORTED, + .cap_crb =3D CRB_INTF_CAP_CRB_SUPPORTED, + .cap_if_res =3D 0b0, + .if_selector =3D CRB_INTF_IF_SELECTOR_CRB, + .if_selector_lock =3D CRB_INTF_IF_SELECTOR_UNLOCKED, + .rid =3D 0b0001, + .vid =3D PCI_VENDOR_ID_IBM, + .did =3D 0b0001, + }, + .ctrl_cmd_size =3D CRB_CTRL_CMD_SIZE, + .ctrl_cmd_pa_low =3D TPM_CRB_ADDR_BASE + sizeof(struct crb_regs), + .ctrl_rsp_size =3D CRB_CTRL_CMD_SIZE, + .ctrl_rsp_pa =3D TPM_CRB_ADDR_BASE + sizeof(struct crb_regs), + }; + + tpm_backend_reset(s->tpmbe); + tpm_backend_startup_tpm(s->tpmbe); +} + +static void tpm_crb_request_completed(TPMIf *ti) +{ + CRBState *s =3D CRB(ti); + + s->regs.ctrl_start &=3D ~CRB_START_INVOKE; + /* TODO, in case of error: s->regs.ctrl_sts =3D CRB_CTRL_STS_ERROR */ +} + +static enum TPMVersion tpm_crb_get_version(TPMIf *ti) +{ + CRBState *s =3D CRB(ti); + + return tpm_backend_get_tpm_version(s->tpmbe); +} + +static const VMStateDescription vmstate_tpm_crb =3D { + .name =3D "tpm-crb", + .unmigratable =3D 1, +}; + +static Property tpm_crb_properties[] =3D { + DEFINE_PROP_STRING("tpmdev", CRBState, backend), + DEFINE_PROP_END_OF_LIST(), +}; + +static void tpm_crb_realizefn(DeviceState *dev, Error **errp) +{ + CRBState *s =3D CRB(dev); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + + if (!tpm_find()) { + error_setg(errp, "at most one TPM device is permitted"); + return; + } + + s->tpmbe =3D qemu_find_tpm_be(s->backend); + if (!s->tpmbe) { + error_setg(errp, "tpm-crb: backend driver with id '%s' could not b= e " + "found", s->backend); + return; + } + + if (tpm_backend_init(s->tpmbe, TPM_IF(s), errp)) { + return; + } + + memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s, + "tpm-crb-mmio", sizeof(struct crb_regs)); + memory_region_init_ram(&s->cmdmem, OBJECT(s), + "tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp); + + sysbus_init_mmio(sbd, &s->mmio); + sysbus_mmio_map(sbd, 0, TPM_CRB_ADDR_BASE); + /* allocate ram in bios instead? */ + memory_region_add_subregion(get_system_memory(), + TPM_CRB_ADDR_BASE + sizeof(struct crb_regs), &s->cmdmem); +} + +static void tpm_crb_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + TPMIfClass *tc =3D TPM_IF_CLASS(klass); + + dc->realize =3D tpm_crb_realizefn; + dc->props =3D tpm_crb_properties; + dc->reset =3D tpm_crb_reset; + dc->vmsd =3D &vmstate_tpm_crb; + dc->user_creatable =3D true; + tc->model =3D TPM_MODEL_TPM_CRB; + tc->get_version =3D tpm_crb_get_version; + tc->request_completed =3D tpm_crb_request_completed; +} + +static const TypeInfo tpm_crb_info =3D { + .name =3D TYPE_TPM_CRB, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(CRBState), + .class_init =3D tpm_crb_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_TPM_IF }, + { } + } +}; + +static void tpm_crb_register(void) +{ + type_register_static(&tpm_crb_info); + tpm_register_model(TPM_MODEL_TPM_CRB); +} + +type_init(tpm_crb_register) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmm= u.mak index d2ab2f6655..c10afe953a 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -36,6 +36,7 @@ CONFIG_APPLESMC=3Dy CONFIG_I8259=3Dy CONFIG_PFLASH_CFI01=3Dy CONFIG_TPM_TIS=3D$(CONFIG_TPM) +CONFIG_TPM_CRB=3D$(CONFIG_TPM) CONFIG_MC146818RTC=3Dy CONFIG_PCI_PIIX=3Dy CONFIG_WDT_IB700=3Dy diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-so= ftmmu.mak index 9bde2f1c4b..1a6004f3f8 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -36,6 +36,7 @@ CONFIG_APPLESMC=3Dy CONFIG_I8259=3Dy CONFIG_PFLASH_CFI01=3Dy CONFIG_TPM_TIS=3D$(CONFIG_TPM) +CONFIG_TPM_CRB=3D$(CONFIG_TPM) CONFIG_MC146818RTC=3Dy CONFIG_PCI_PIIX=3Dy CONFIG_WDT_IB700=3Dy diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 41f0b7a590..5c98af0de4 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,3 +1,4 @@ common-obj-$(CONFIG_TPM_TIS) +=3D tpm_tis.o +common-obj-$(CONFIG_TPM_CRB) +=3D tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) +=3D tpm_passthrough.o tpm_util.o common-obj-$(CONFIG_TPM_EMULATOR) +=3D tpm_emulator.o tpm_util.o --=20 2.14.1.146.gd35faa819