From patchwork Fri Feb 15 13:35:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10814979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AC1313B4 for ; Fri, 15 Feb 2019 13:43:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A6262F59A for ; Fri, 15 Feb 2019 13:43:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5841B2F5A8; Fri, 15 Feb 2019 13:43:46 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D8BFA2F5B7 for ; Fri, 15 Feb 2019 13:43:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:40119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudmK-0005o3-P4 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Feb 2019 08:43:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudeR-0000PJ-Gu for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gudeQ-0008Fz-PA for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:35 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:40644) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gudeQ-00087x-Cm for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:34 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1FDYOSd094006; Fri, 15 Feb 2019 13:35:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=vfLbLcjNr/dDP9mC8UFpyDo6sg4OPCkcTCb40tdYsiw=; b=O+9PBPff/Fn2mIefI32u6q/KXIjJZRq05CrzzP9tj3zhjWqNFtAsUqHV8ArcyYE0eZRh vA/VzHKQ44iBa5jieK/IO4BzmkJabmYKHCNxIf2CU4RDJWuRtxic+hgjkclyrpyfnSUg +GaR4Ehd/M4Oz57ylbS/Dqk0SulcncGZwYb6yFQRJQL9YW2ttTZiRvjRyy+CcrVDc0z1 Y1TYpSBhlpKOO0jMaJW9mj2g3r4t4vQR3hm+P81PIzeST4XErVcQ+uNaEKf5DyOKM0Ig 53WjvujOWNqpG9pORpBT1VhYCbcChVnULCTyYyFhLeAbOAdDbBfqzncNLi/uoMTaIcOO 3w== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2qhreedwck-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:23 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1FDZMBd001156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:22 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1FDZM4I012964; Fri, 15 Feb 2019 13:35:22 GMT Received: from ol7.uk.oracle.com (/10.175.220.50) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Feb 2019 13:35:21 +0000 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Fri, 15 Feb 2019 13:35:17 +0000 Message-Id: <1550237719-28355-1-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9167 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=627 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902150097 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v5 1/3] tpm_tis: fix loop that cancels any seizure by a lower locality 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: philmd@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In tpm_tis_mmio_write() if the requesting locality is seizing access, any seizure by a lower locality is cancelled. However the loop doing the seizure had an off-by-one error and the locality immediately preceding the requesting locality was not being cleared. This is fixed by adjusting the test in the for loop to check the localities up to the requesting locality. Signed-off-by: Liam Merwick Reviewed-by: Stefan Berger --- v4 -> v5 First char in patch got deleted, corrupting email subject. hw/tpm/tpm_tis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index fd6bb9b59a96..61a130beef35 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -624,7 +624,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr, } /* cancel any seize by a lower locality */ - for (l = 0; l < locty - 1; l++) { + for (l = 0; l < locty; l++) { s->loc[l].access &= ~TPM_TIS_ACCESS_SEIZE; } From patchwork Fri Feb 15 13:35:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10814975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 06A926C2 for ; Fri, 15 Feb 2019 13:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E91592F51C for ; Fri, 15 Feb 2019 13:41:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E712E2F528; Fri, 15 Feb 2019 13:41:08 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87F4D2F52C for ; Fri, 15 Feb 2019 13:41:08 +0000 (UTC) Received: from localhost ([127.0.0.1]:40061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudjn-0003eF-Oe for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Feb 2019 08:41:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudeR-0000P3-9f for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gudeQ-0008FJ-CJ for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:35 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:43632) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gudeN-00087y-Rp for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:32 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1FDYbpL087317; Fri, 15 Feb 2019 13:35:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=drpJKbR7ITW7GhrWV3fIu0TcaupMVHuAZeOg/jWY90c=; b=ifwQ1teUD8U2SZKXUkIBoeYk4VXjxpRmLDDZikjgefzUoMGSG9nc4sex4WSdz+27XeiU ch9xcBpfKXXHyIhgjwxFpps5sd7iACqzR6IWThrXOTk2ExVHp6FtvMyXtYsdGXHjqWzB 77keeBHU6chdYYGikwX04+yBxJTv9Sd36adRmE5rQ9/cvDp9jMF3+E0T5xgcpHeDYx0r UjPs/4GboWvbfFQnOCrTxftvwOLHZTUemaIj8XZ8gIxxy22Z2X6D1ZBcfjHRKShMdUno ao3G8DCbuGTO+xOV3sytBpE9AUQvImmQCANvIEI/nfW7ClpavAQr0b+eIlzx61o/zMk9 Zg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qhrekwv5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:24 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1FDZNVM001198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:23 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1FDZNMt019137; Fri, 15 Feb 2019 13:35:23 GMT Received: from ol7.uk.oracle.com (/10.175.220.50) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Feb 2019 13:35:23 +0000 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Fri, 15 Feb 2019 13:35:18 +0000 Message-Id: <1550237719-28355-2-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550237719-28355-1-git-send-email-liam.merwick@oracle.com> References: <1550237719-28355-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9167 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=702 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902150097 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v5 2/3] tpm_tis: assert valid addr passed to tpm_tis_locality_from_addr() 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: philmd@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Assert that the address passed in results in a valid locality value. Current callers pass a valid address so this is just a defensive check to prevent future caller passing an incorrect address or catch if the MMIO address parameters were not all modified correctly. This is to help static code analysis tools that report that no explicit checking is being done. Signed-off-by: Liam Merwick --- hw/tpm/tpm_tis.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 61a130beef35..772431f20874 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -100,7 +100,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr, static uint8_t tpm_tis_locality_from_addr(hwaddr addr) { - return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7); + uint8_t locty = (uint8_t)(addr >> TPM_TIS_LOCALITY_SHIFT); + assert(TPM_TIS_IS_VALID_LOCTY(locty)); + return locty; } static void tpm_tis_show_buffer(const unsigned char *buffer, From patchwork Fri Feb 15 13:35:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10814981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 366AC6C2 for ; Fri, 15 Feb 2019 13:46:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 254E3287AD for ; Fri, 15 Feb 2019 13:46:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16B6E290C5; Fri, 15 Feb 2019 13:46:33 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7F492287AD for ; Fri, 15 Feb 2019 13:46:32 +0000 (UTC) Received: from localhost ([127.0.0.1]:40198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudp1-0000jS-IM for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Feb 2019 08:46:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gudeR-0000PK-HB for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gudeQ-0008FT-E0 for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:35 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:55888) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gudeO-0008Bc-2R for qemu-devel@nongnu.org; Fri, 15 Feb 2019 08:35:34 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1FDYZZM093475; Fri, 15 Feb 2019 13:35:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=co+RAyLKUXxsD0kcJ6HxNfb7VJRcWQnEczMoDhHG3ro=; b=joetgdxoRkjKmiIUOo36RoXFCiFMZnYcf7O0KRkQQCddwSiMAbcsINaYuVeJp71H/gbm mLQFkH09HfIrF3c5JWIm4z4sX3egb9o7x3xO/l6wum7P1e/37GoYrOZli75Sn9D18KPW DwaACBvdgGJXcaZe9VEIc/oCmuO3T9kItzZy9HGHpFs8Ss51TS3REqwHj528jJykMQSG a3geMhSDMb5cUCX+DUitqy7u8CByTKjL6lqlK8RYU4yzm2T8YDuS3Kii8kzUZ0+oXB+w QzXFqgHCd/wSy56jPVyi+Cs4+hapdTvzD0xJbLCxzmR6bGovJW4buSLTRYjLi8f8Rtpb 3g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2qhre5wu52-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:26 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1FDZOGj031356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Feb 2019 13:35:25 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1FDZOWC012978; Fri, 15 Feb 2019 13:35:24 GMT Received: from ol7.uk.oracle.com (/10.175.220.50) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Feb 2019 13:35:24 +0000 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Fri, 15 Feb 2019 13:35:19 +0000 Message-Id: <1550237719-28355-3-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550237719-28355-1-git-send-email-liam.merwick@oracle.com> References: <1550237719-28355-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9167 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902150097 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v5 3/3] tpm_tis: convert tpm_tis_show_buffer() to use trace event 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: philmd@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP cppcheck reports: [hw/tpm/tpm_tis.c:113]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int' Rather than just converting the format specifier to use '%u", the tpm_tis_show_buffer() function is converted to use trace points and the two debug callers use the trace event infrastructure so that it's available in production cases also and not just when DEBUG_TIS is enabled. Signed-off-by: Liam Merwick Reviewed-by: Stefan Berger --- v3 -> v4 - Allow for null terminator in buffer length calc. - dropped "tpm_tis: " from direction string since function name is now printed - Minor tweak to trace event format string and function parameter names Sample trace output --enable-trace-backends=simple % echo tpm_tis_show_buffer > /tmp/events % export QTEST_QEMU_BINARY="/home/Development/qemu-upstream/x86_64-softmmu/qemu-system-x86_64 --trace events=/tmp/events" % tests/tpm-tis-test /D=/home/Development/qemu-upstream/hw/tpm/tpm-tis/test_check_localities: OK /D=/home/Development/qemu-upstream/hw/tpm/tpm-tis/test_check_access_reg: OK /D=/home/Development/qemu-upstream/hw/tpm/tpm-tis/test_check_access_reg_seize: OK /D=/home/Development/qemu-upstream/hw/tpm/tpm-tis/test_check_access_reg_release: OK /D=/home/Development/qemu-upstream/hw/tpm/tpm-tis/test_check_transmit: OK % ./scripts/simpletrace.py trace-events-all `ls -1rt trace-[0-9]* | tail -1` tpm_tis_show_buffer 0.000 pid=8416 direction=To TPM len=0xc line=80 01 00 00 00 0C 00 00 01 44 00 00 tpm_tis_show_buffer 303.909 pid=8416 direction=From TPM len=0xa line=80 01 00 00 00 0A 00 00 01 01 --enable-trace-backends=log 1255@1550051983.333949:tpm_tis_show_buffer direction: To TPM len: 12 buf: 80 01 00 00 00 0C 00 00 01 44 00 00 1255@1550051983.334213:tpm_tis_show_buffer direction: From TPM len: 10 buf: 80 01 00 00 00 0A 00 00 01 01 hw/tpm/tpm_tis.c | 31 +++++++++++++++++++------------ hw/tpm/trace-events | 1 + 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 772431f20874..d7b9bee85741 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -108,17 +108,26 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr) static void tpm_tis_show_buffer(const unsigned char *buffer, size_t buffer_size, const char *string) { - uint32_t len, i; + size_t len, i; + char *line_buffer, *p; len = MIN(tpm_cmd_get_size(buffer), buffer_size); - printf("tpm_tis: %s length = %d\n", string, len); - for (i = 0; i < len; i++) { + + /* + * allocate enough room for 3 chars per buffer entry plus a + * newline after every 16 chars and a final null terminator. + */ + line_buffer = g_malloc(len * 3 + (len / 16) + 1); + + for (i = 0, p = line_buffer; i < len; i++) { if (i && !(i % 16)) { - printf("\n"); + p += sprintf(p, "\n"); } - printf("%.2X ", buffer[i]); + p += sprintf(p, "%.2X ", buffer[i]); } - printf("\n"); + trace_tpm_tis_show_buffer(string, len, line_buffer); + + g_free(line_buffer); } /* @@ -145,9 +154,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags) */ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) { - if (DEBUG_TIS) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, - "tpm_tis: To TPM"); + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "To TPM"); } /* @@ -315,9 +323,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) s->loc[locty].state = TPM_TIS_STATE_COMPLETION; s->rw_offset = 0; - if (DEBUG_TIS) { - tpm_tis_show_buffer(s->buffer, s->be_buffer_size, - "tpm_tis: From TPM"); + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { + tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "From TPM"); } if (TPM_TIS_IS_VALID_LOCTY(s->next_locty)) { diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events index 920d32ad5514..f45dcd220993 100644 --- a/hw/tpm/trace-events +++ b/hw/tpm/trace-events @@ -36,6 +36,7 @@ tpm_emulator_pre_save(void) "" tpm_emulator_inst_init(void) "" # hw/tpm/tpm_tis.c +tpm_tis_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\nbuf: %s" tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d" tpm_tis_abort(uint8_t locty) "New active locality is %d"