From patchwork Wed Nov 8 19:45:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 10049075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 18BEE603FA for ; Wed, 8 Nov 2017 19:47:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 091D82901A for ; Wed, 8 Nov 2017 19:47:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F216C29429; Wed, 8 Nov 2017 19:47:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7EBAB2901A for ; Wed, 8 Nov 2017 19:47:02 +0000 (UTC) Received: from localhost ([::1]:33678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCWJR-0007jq-Bp for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Nov 2017 14:47:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCWIs-0007jW-EP for qemu-devel@nongnu.org; Wed, 08 Nov 2017 14:46:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCWIj-0004Qk-FR for qemu-devel@nongnu.org; Wed, 08 Nov 2017 14:46:26 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53040) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eCWIj-0004PH-6C for qemu-devel@nongnu.org; Wed, 08 Nov 2017 14:46:17 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vA8JiGK7082524 for ; Wed, 8 Nov 2017 14:46:09 -0500 Received: from e11.ny.us.ibm.com (e11.ny.us.ibm.com [129.33.205.201]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e45b82meu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Nov 2017 14:46:08 -0500 Received: from localhost by e11.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 8 Nov 2017 14:46:07 -0500 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e11.ny.us.ibm.com (146.89.104.198) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 8 Nov 2017 14:46:04 -0500 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vA8Jk4gV37945368; Wed, 8 Nov 2017 19:46:04 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D258CAE03C; Wed, 8 Nov 2017 14:46:52 -0500 (EST) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id C5FBAAE051; Wed, 8 Nov 2017 14:46:52 -0500 (EST) From: Stefan Berger To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com Date: Wed, 8 Nov 2017 14:45:56 -0500 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 x-cbid: 17110819-2213-0000-0000-00000238549C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008033; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00943037; UDB=6.00475760; IPR=6.00723325; BA=6.00005679; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017915; XFM=3.00000015; UTC=2017-11-08 19:46:06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17110819-2214-0000-0000-000058198E62 Message-Id: <1510170356-16953-1-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-08_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1711080258 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] tpm: Add a caching layer for the TPM Established flag 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, Stefan Berger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a caching layer for the TPM established flag so that we don't need to go to the backend every time the flag is read by accessing the REG_ACCESS register. Signed-off-by: Stefan Berger --- hw/tpm/tpm_tis.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 7402528..6b81bbf 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -95,6 +95,9 @@ struct TPMState { char *backend; TPMBackend *be_driver; TPMVersion be_tpm_version; + + unsigned int established_flag:1; + unsigned int established_flag_cached:1; }; #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) @@ -529,6 +532,26 @@ static void tpm_tis_dump_state(void *opaque, hwaddr addr) } #endif +static void tpm_tis_reset_tpm_established_flag(TPMState *s, + uint8_t locty) +{ + s->established_flag_cached = 0; + + tpm_backend_reset_tpm_established_flag(s->be_driver, locty); +} + +static unsigned int tpm_tis_get_tpm_established_flag(TPMState *s) +{ + if (s->established_flag_cached) { + return s->established_flag; + } + + s->established_flag = !tpm_backend_get_tpm_established_flag(s->be_driver); + s->established_flag_cached = 1; + + return s->established_flag; +} + /* * Read a register of the TIS interface * See specs pages 33-63 for description of the registers @@ -556,7 +579,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, if (tpm_tis_check_request_use_except(s, locty)) { val |= TPM_TIS_ACCESS_PENDING_REQUEST; } - val |= !tpm_backend_get_tpm_established_flag(s->be_driver); + val |= tpm_tis_get_tpm_established_flag(s); break; case TPM_TIS_REG_INT_ENABLE: val = s->loc[locty].inte; @@ -840,7 +863,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr, if (val & TPM_TIS_STS_RESET_ESTABLISHMENT_BIT) { if (locty == 3 || locty == 4) { - tpm_backend_reset_tpm_established_flag(s->be_driver, locty); + tpm_tis_reset_tpm_established_flag(s, locty); } } }