From patchwork Mon Jan 4 15:23:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 562433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CA9331402E2 for ; Tue, 5 Jan 2016 02:25:49 +1100 (AEDT) Received: from localhost ([::1]:45381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG711-0007Ab-Pw for incoming@patchwork.ozlabs.org; Mon, 04 Jan 2016 10:25:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG6yy-0003LZ-0P for qemu-devel@nongnu.org; Mon, 04 Jan 2016 10:23:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aG6yt-0007DX-Bg for qemu-devel@nongnu.org; Mon, 04 Jan 2016 10:23:39 -0500 Received: from e18.ny.us.ibm.com ([129.33.205.208]:49435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG6yt-0007DS-7l for qemu-devel@nongnu.org; Mon, 04 Jan 2016 10:23:35 -0500 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jan 2016 10:23:35 -0500 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 4 Jan 2016 10:23:32 -0500 X-IBM-Helo: d01dlp03.pok.ibm.com X-IBM-MailFrom: stefanb@us.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 45524C9003E for ; Mon, 4 Jan 2016 10:23:31 -0500 (EST) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u04FNV0B10092778 for ; Mon, 4 Jan 2016 15:23:31 GMT Received: from d01av05.pok.ibm.com (localhost [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u04FJUr5002518 for ; Mon, 4 Jan 2016 10:19:34 -0500 Received: from sbct-3.watson.ibm.com (sbct-3.watson.ibm.com [9.2.141.158]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u04FJSYx002462; Mon, 4 Jan 2016 10:19:29 -0500 From: Stefan Berger To: qemu-devel@nongnu.org Date: Mon, 4 Jan 2016 10:23:21 -0500 Message-Id: <1451921002-8263-4-git-send-email-stefanb@us.ibm.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1451921002-8263-1-git-send-email-stefanb@us.ibm.com> References: <1451921002-8263-1-git-send-email-stefanb@us.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16010415-0045-0000-0000-000002FBD63A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 129.33.205.208 Cc: stefanb@us.ibm.com, mst@redhat.com, Stefan Berger , jb613w@att.com, quan.xu@intel.com, silviu.vlasceanu@gmail.com, hagen.lauer@huawei.com Subject: [Qemu-devel] [PATCH v5 3/4] Introduce condition in TPM backend for notification X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: 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 a4f4fe0..fda27e3 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -75,6 +75,10 @@ struct TPMPassthruState { TPMVersion tpm_version; ptm_cap cuse_cap; /* capabilities 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; @@ -249,6 +253,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: @@ -376,6 +385,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, @@ -453,6 +463,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); } @@ -721,6 +736,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)