From patchwork Tue Feb 12 20:48: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: 10808683 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 F2DC8922 for ; Tue, 12 Feb 2019 21:00:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1ACA2C693 for ; Tue, 12 Feb 2019 21:00:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5B332C69E; Tue, 12 Feb 2019 21:00:21 +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 7CB2C2C68F for ; Tue, 12 Feb 2019 21:00:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:46007 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtfAC-0000mk-LY for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Feb 2019 16:00:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtf4p-0005bq-11 for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:54:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtez5-0007W6-Fu for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:55 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtez2-0007KQ-Rz for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:50 -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 x1CKmdRD169464; Tue, 12 Feb 2019 20:48:39 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=xh1d7aR2csnY40wgoLdRlsSICwSfacYY8Z1fH4Nj3mY=; b=sGC/yr/jCyjoEtwzTI+WxgOJo2BqgNawdXOeL1Agb/UIiEt4m6w5VLb8FaIeDSEP+UA2 0HZl4o6f3G0O3YNOtqsdtW7oTbWNtGnfVRAb47rYcHmuuNHtuXjWzmipX5NUNnpSiKdt ATYJeuyxTg3kBHJw+0btph2ikGTnTCMvjFg65NUwkTvY98Uc1zQKUFrUMELT7OZuUxhD 2Y2t1p5Ry4T2P1R1yMlTBU3Eol9TwhDsDihpnvbR48d4YkFGI8BemErhLg8Q/cYl9Sdu URl52+QZZDGza6lc+yJilYAJXlzLq3wzZ2VLDySIZYIEW6C1K0ihGkbcqYOunLl0NhFI 9g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qhredxcba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:39 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1CKmZaW017605 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:35 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1CKmZGY013229; Tue, 12 Feb 2019 20:48:35 GMT Received: from ol7.uk.oracle.com (/10.175.218.157) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Feb 2019 12:48:34 -0800 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Tue, 12 Feb 2019 20:48:18 +0000 Message-Id: <1550004500-24485-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=9165 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=714 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902120145 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v3 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 --- 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 Tue Feb 12 20:48: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: 10808673 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 7FE8E13B4 for ; Tue, 12 Feb 2019 20:58:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FA2B2C1A7 for ; Tue, 12 Feb 2019 20:58:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63E9F2C690; Tue, 12 Feb 2019 20:58:29 +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 18C402C1A7 for ; Tue, 12 Feb 2019 20:58:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:45991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtf8N-0007Zt-Ea for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Feb 2019 15:58:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtf4o-0005Y9-Bz for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:54:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtez5-0007Ui-14 for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:55 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:56446) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gteyz-0007Km-Oi for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:48 -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 x1CKmeuD170876; Tue, 12 Feb 2019 20:48:40 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=FLWKovuzG6r6fg+nuVlkdeFl2kLCTHDfhEwScWAVyUU=; b=yDIhvZh41thInKrcvhh+uCW0vmRXQnGM67iJ1Lxi0IN1n1pV1rqy+jZjJwNAFtVhnMCg b3ihQpmgnzeFWa3WmhHG8XRQ2e1nlqZElZz4Y0VcsGPiCbT3DbmmOpxHw/QXmjZE1QQ8 8x7GSz8Ba1CDBElfBubAlYtsRIROBeakSXlpaviyYysE0ELUnTMtrrl7WW25GClbtOOk XVyo7wCO/1Dn/+joLcI2gQeoMEQQ+xyZpG5rktxte4sXry0bLIVN45N13JpSRJfgsgA6 YBjmvkzgXTyTn3JSGguaW8TIJ54Z7rXL9q2RoCcPjnTHr6qOyNxlhZhbGTWiLrw20Yb0 UQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2qhre5eatu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:39 +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 x1CKmaWC017623 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:36 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1CKma0T026056; Tue, 12 Feb 2019 20:48:36 GMT Received: from ol7.uk.oracle.com (/10.175.218.157) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Feb 2019 12:48:35 -0800 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Tue, 12 Feb 2019 20:48:19 +0000 Message-Id: <1550004500-24485-2-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550004500-24485-1-git-send-email-liam.merwick@oracle.com> References: <1550004500-24485-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9165 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=692 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902120145 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v3 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 a 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 Tue Feb 12 20:48:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10808667 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 BFABB13A4 for ; Tue, 12 Feb 2019 20:56:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6B82C30D for ; Tue, 12 Feb 2019 20:56:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 973572C63A; Tue, 12 Feb 2019 20:56:09 +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 194302BAEA for ; Tue, 12 Feb 2019 20:56:08 +0000 (UTC) Received: from localhost ([127.0.0.1]:45926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtf65-0005fc-Os for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Feb 2019 15:56:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtf4o-0005cr-6B for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:54:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtez9-0007dJ-Oz for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:56 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:56490) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtez5-0007N4-Fu for qemu-devel@nongnu.org; Tue, 12 Feb 2019 15:48:55 -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 x1CKmh7K171179; Tue, 12 Feb 2019 20:48:43 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=6mm2kZ8Q09nqxdOQnFPibkmDuCwfBfFoPpZ0CBsA/ro=; b=eMldSQ/9mdtz3c7Ye9gfJypP0KtZ+VYi9C8LNec9HnyZPkS7iG8gb43hEnI/kri+OvTn WEOVSdZgdjJe+vjNdl+j8x+bugMuR3Y0Vx2ZksurkHPQkl+LSGkovybgpISVnujG9jpE yBbn8rtjbZYtj0axUKOv9jVgC3GbH+UUTfLEFLUArWAw720e+xAPtd2pvP6Cm+T5zpTy WuPP4feYIYuPIO2T5j2C0Z/eXbZj6gg3y4S6d8reoAk9b9l5gFaAxubDgGAZUBVd8NjP 9+QPycT8eF3JTm6W64kCwgx5b536Vr+qi7qLGdzsXg/6i2jEPh+Vd6Qleej2KIRK2osH 9w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2qhre5eaue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:42 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1CKmbqO012130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Feb 2019 20:48:37 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1CKmbRv013241; Tue, 12 Feb 2019 20:48:37 GMT Received: from ol7.uk.oracle.com (/10.175.218.157) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Feb 2019 12:48:37 -0800 From: Liam Merwick To: stefanb@linux.ibm.com, qemu-devel@nongnu.org Date: Tue, 12 Feb 2019 20:48:20 +0000 Message-Id: <1550004500-24485-3-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1550004500-24485-1-git-send-email-liam.merwick@oracle.com> References: <1550004500-24485-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9165 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-1902120145 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v3 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 --- Sample trace output % 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 trace-30665 tpm_tis_show_buffer 0.000 pid=30665 string=tpm_tis: To TPM len=0xc line=80 01 00 00 00 0C 00 00 01 44 00 00 tpm_tis_show_buffer 256.581 pid=30665 string=tpm_tis: From TPM len=0xa line=80 01 00 00 00 0A 00 00 01 01 hw/tpm/tpm_tis.c | 25 +++++++++++++++++-------- hw/tpm/trace-events | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 772431f20874..18e19d5f900d 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. + */ + line_buffer = g_malloc(len * 3 + (len / 16)); + + 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,7 +154,7 @@ 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) { + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: To TPM"); } @@ -315,7 +324,7 @@ 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) { + if (trace_event_get_state_backends(TRACE_TPM_TIS_SHOW_BUFFER)) { tpm_tis_show_buffer(s->buffer, s->be_buffer_size, "tpm_tis: From TPM"); } diff --git a/hw/tpm/trace-events b/hw/tpm/trace-events index 920d32ad5514..c0267d075027 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 *string, size_t len, const char *line) "tpm_tis: %s length = %zu\n%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"