From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqkw6-0003FO-5N for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yqkw2-0002U1-6K for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:38 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:46472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqkw1-0002Te-WF for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:34 -0400 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 May 2015 10:15:33 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 8589219D804A for ; Fri, 8 May 2015 10:06:34 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t48GDRdu19333258 for ; Fri, 8 May 2015 09:13:27 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t48GFUwF010802 for ; Fri, 8 May 2015 10:15:30 -0600 From: Stefan Berger Date: Fri, 8 May 2015 12:15:19 -0400 Message-Id: <1431101720-701152-6-git-send-email-stefanb@linux.vnet.ibm.com> In-Reply-To: <1431101720-701152-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1431101720-701152-1-git-send-email-stefanb@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 5/6] Introduce condition in TPM backend for notification List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mst@redhat.com Cc: imammedo@redhat.com, kevin@koconnor.net, stefanb@us.ibm.com, quan.xu@intel.com, Stefan Berger TPM backends will suspend independently of the frontends. Also here we need to be able to wait for the TPM command to have been completely processed. Signed-off-by: Stefan Berger --- hw/tpm/tpm_passthrough.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 3926094..46b801f 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -76,6 +76,10 @@ struct TPMPassthruState { TPMVersion tpm_version; ptmcap_t cuse_cap; /* capabilties of the CUSE TPM */ uint8_t cur_locty_number; /* last set locality */ + + QemuMutex state_lock; + QemuCond cmd_complete; /* singnaled once tpm_busy is false */ + bool tpm_busy; }; typedef struct TPMPassthruState TPMPassthruState; @@ -252,6 +256,11 @@ static void tpm_passthrough_worker_thread(gpointer data, thr_parms->recv_data_callback(thr_parms->tpm_state, thr_parms->tpm_state->locty_number, selftest_done); + /* result delivered */ + qemu_mutex_lock(&tpm_pt->state_lock); + tpm_pt->tpm_busy = false; + qemu_cond_signal(&tpm_pt->cmd_complete); + qemu_mutex_unlock(&tpm_pt->state_lock); break; case TPM_BACKEND_CMD_INIT: case TPM_BACKEND_CMD_END: @@ -385,6 +394,7 @@ static void tpm_passthrough_reset(TPMBackend *tb) tpm_backend_thread_end(&tpm_pt->tbt); tpm_pt->had_startup_error = false; + tpm_pt->tpm_busy = false; } static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, @@ -465,6 +475,11 @@ static void tpm_passthrough_deliver_request(TPMBackend *tb) { TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + /* TPM considered busy once TPM Request scheduled for processing */ + qemu_mutex_lock(&tpm_pt->state_lock); + tpm_pt->tpm_busy = true; + qemu_mutex_unlock(&tpm_pt->state_lock); + tpm_backend_thread_deliver_request(&tpm_pt->tbt); } @@ -736,6 +751,11 @@ static const TPMDriverOps tpm_passthrough_driver = { static void tpm_passthrough_inst_init(Object *obj) { + TPMBackend *tb = TPM_BACKEND(obj); + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); + + qemu_mutex_init(&tpm_pt->state_lock); + qemu_cond_init(&tpm_pt->cmd_complete); } static void tpm_passthrough_inst_finalize(Object *obj) -- 1.9.3