From nobody Tue Feb 10 20:28:21 2026 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