From patchwork Mon Jan 4 15:23:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 562430 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 8ACD51402E2 for ; Tue, 5 Jan 2016 02:24:09 +1100 (AEDT) Received: from localhost ([::1]:45364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG6zP-00046L-1d for incoming@patchwork.ozlabs.org; Mon, 04 Jan 2016 10:24:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG6yx-0003LX-IU 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-0007DO-16 for qemu-devel@nongnu.org; Mon, 04 Jan 2016 10:23:39 -0500 Received: from e36.co.us.ibm.com ([32.97.110.154]:48468) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aG6ys-0007D7-Qd for qemu-devel@nongnu.org; Mon, 04 Jan 2016 10:23:34 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jan 2016 08:23:34 -0700 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 4 Jan 2016 08:23:32 -0700 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: stefanb@us.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 721263E4003E for ; Mon, 4 Jan 2016 08:23:31 -0700 (MST) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u04FNVAH29294748 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 u04FJTuF002509 for ; Mon, 4 Jan 2016 10:19:33 -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 u04FJSYw002462; Mon, 4 Jan 2016 10:19:29 -0500 From: Stefan Berger To: qemu-devel@nongnu.org Date: Mon, 4 Jan 2016 10:23:20 -0500 Message-Id: <1451921002-8263-3-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-0021-0000-0000-000015C25D63 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.97.110.154 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 2/4] Introduce condition to notify waiters of completed command 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 Introduce a lock and a condition to notify anyone waiting for the completion of the execution of a TPM command by the backend (thread). The backend uses the condition to signal anyone waiting for command completion. We need to place the condition in two locations: one is invoked by the backend thread, the other by the bottom half thread. We will use the signalling to wait for command completion before VM suspend. Signed-off-by: Stefan Berger --- hw/tpm/tpm_int.h | 3 +++ hw/tpm/tpm_tis.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 6b2c9c9..70be1ad 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -30,6 +30,9 @@ struct TPMState { char *backend; TPMBackend *be_driver; TPMVersion be_tpm_version; + + QemuMutex state_lock; + QemuCond cmd_complete; }; #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index ff073d5..57f540e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -366,6 +366,8 @@ static void tpm_tis_receive_bh(void *opaque) TPMTISEmuState *tis = &s->s.tis; uint8_t locty = s->locty_number; + qemu_mutex_lock(&s->state_lock); + tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); tis->loc[locty].state = TPM_TIS_STATE_COMPLETION; @@ -382,6 +384,10 @@ static void tpm_tis_receive_bh(void *opaque) tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); #endif + + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); } /* @@ -401,6 +407,11 @@ static void tpm_tis_receive_cb(TPMState *s, uint8_t locty, } } + qemu_mutex_lock(&s->state_lock); + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); + qemu_bh_schedule(tis->bh); } @@ -1070,6 +1081,9 @@ static void tpm_tis_initfn(Object *obj) memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); + + qemu_mutex_init(&s->state_lock); + qemu_cond_init(&s->cmd_complete); } static void tpm_tis_class_init(ObjectClass *klass, void *data)