From nobody Sun Nov 2 11:47:00 2025 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 1509145518594414.956803179605; Fri, 27 Oct 2017 16:05:18 -0700 (PDT) Received: from localhost ([::1]:59186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8Dge-0003mC-8P for importer@patchew.org; Fri, 27 Oct 2017 19:05:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e8Dec-0002eW-Ck for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e8DeX-0003vL-VI for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e8DeX-0003tR-Mn for qemu-devel@nongnu.org; Fri, 27 Oct 2017 19:03:01 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9RN0l6B019360 for ; Fri, 27 Oct 2017 19:02:57 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dv9sej1tt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 27 Oct 2017 19:02:56 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Oct 2017 19:02:54 -0400 Received: from b01cxnp22035.gho.pok.ibm.com (9.57.198.25) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 27 Oct 2017 19:02:51 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9RN2oeQ47841360; Fri, 27 Oct 2017 23:02:50 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 446C7AC03F; Fri, 27 Oct 2017 19:03:36 -0400 (EDT) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 37D53AC03A; Fri, 27 Oct 2017 19:03:36 -0400 (EDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 27 Oct 2017 19:02:35 -0400 X-Mailer: git-send-email 2.5.5 In-Reply-To: <1509145361-11218-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1509145361-11218-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17102723-0024-0000-0000-000002E98CAE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007964; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00937412; UDB=6.00472471; IPR=6.00717674; BA=6.00005660; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017751; XFM=3.00000015; UTC=2017-10-27 23:02:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102723-0025-0000-0000-000045DC8CE4 Message-Id: <1509145361-11218-2-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-27_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710270296 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/7] tpm: Introduce condition to notify waiters of completed command 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, marcandre.lureau@gmail.com, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 signaling to wait for command completion before VM suspend. Signed-off-by: Stefan Berger --- hw/tpm/tpm_tis.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 9a94051..90dca4e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -90,6 +90,9 @@ typedef struct TPMState { char *backend; TPMBackend *be_driver; TPMVersion be_tpm_version; + + QemuMutex state_lock; + QemuCond cmd_complete; } TPMState; =20 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -421,6 +424,8 @@ static void tpm_tis_request_completed(TPMIf *ti) } } =20 + qemu_mutex_lock(&s->state_lock); + tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); s->loc[locty].state =3D TPM_TIS_STATE_COMPLETION; @@ -435,6 +440,10 @@ static void tpm_tis_request_completed(TPMIf *ti) =20 tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); + + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); } =20 /* @@ -1088,6 +1097,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); } =20 static void tpm_tis_class_init(ObjectClass *klass, void *data) --=20 2.5.5