From nobody Sun May 5 10:43:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150482092188067.03151610673922; Thu, 7 Sep 2017 14:48:41 -0700 (PDT) Received: from localhost ([::1]:42395 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq4fA-0008SN-NL for importer@patchew.org; Thu, 07 Sep 2017 17:48:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq4e1-0007uF-3Z for qemu-devel@nongnu.org; Thu, 07 Sep 2017 17:47:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq4dv-0002KC-V7 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 17:47:29 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58951) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dq4dv-0002IX-Ml for qemu-devel@nongnu.org; Thu, 07 Sep 2017 17:47:23 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v87Lk6c3101358 for ; Thu, 7 Sep 2017 17:47:22 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cu72yyx3y-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 07 Sep 2017 17:47:21 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Sep 2017 17:47:20 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 7 Sep 2017 17:47:17 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v87LlH3S50004216; Thu, 7 Sep 2017 21:47:17 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B25FAE03B; Thu, 7 Sep 2017 17:47:44 -0400 (EDT) Received: from sbct-3.watson.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 446A4AE034; Thu, 7 Sep 2017 17:47:44 -0400 (EDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 17:47:15 -0400 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 x-cbid: 17090721-0040-0000-0000-0000039E1CC8 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007685; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000226; SDB=6.00913733; UDB=6.00458629; IPR=6.00693991; BA=6.00005576; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017057; XFM=3.00000015; UTC=2017-09-07 21:47:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17090721-0041-0000-0000-000007931D1C Message-Id: <1504820835-15482-1-git-send-email-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-07_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709070323 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PACTH v3] specs: Describe the TPM support in QEMU 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: Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds a description of the current TPM support in QEMU to the specs. Several public specs are referenced via their landing page on the trustedcomputinggroup.org website. Signed-off-by: Stefan Berger Reviewed-by: Laszlo Ersek --- docs/specs/tpm.txt | 124 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 124 insertions(+) create mode 100644 docs/specs/tpm.txt diff --git a/docs/specs/tpm.txt b/docs/specs/tpm.txt new file mode 100644 index 0000000..79344ff --- /dev/null +++ b/docs/specs/tpm.txt @@ -0,0 +1,124 @@ +; +QEMU TPM Device +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +=3D Guest-side Hardware Interface =3D + +The QEMU TPM emulation implements a TPM TIS hardware interface following t= he +Trusted Computing Group's specification "TCG PC Client Specific TPM Interf= ace +Specification (TIS)", Specification Version 1.3, 21 March 2013. This +specification, or a later version of it, can be accessed from the following +URL: + +https://trustedcomputinggroup.org/pc-client-work-group-pc-client-specific-= tpm-interface-specification-tis/ + +The TIS interface makes a memory mapped IO region in the area 0xfed40000 - +0xfed44fff available to the guest operating system. + + +QEMU files related to TPM TIS interface: + - hw/tpm/tpm_tis.c + - hw/tpm/tpm_tis.h + + +=3D ACPI Interface =3D + +The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and p= asses +it into the guest through the fw_cfg device. The device description contai= ns +the base address of the TIS interface 0xfed40000 and the size of the MMIO = area +(0x5000). In case a TPM2 is used by QEMU, a TPM2 ACPI table is also provid= ed. +The device is described to be used in polling mode rather than interrupt m= ode +primarily because no unused IRQ could be found. + +To support measurement logs to be written by the firmware, e.g. SeaBIOS, a= TCPA +table is implemented. This table provides a 64kb buffer where the firmware= can +write its log into. For TPM 2 only a more recent version of the TPM2 table +provides support for measurements logs and a TCPA table does not need to be +created. + +The TCPA and TPM2 ACPI tables follow the Trusted Computing Group specifica= tion +"TCG ACPI Specification" Family "1.2" and "2.0", Level 00 Revision 00.37. = This +specification, or a later version of it, can be accessed from the following +URL: + +https://trustedcomputinggroup.org/tcg-acpi-specification/ + + +QEMU files related to TPM ACPI tables: + - hw/i386/acpi-build.c + - include/hw/acpi/tpm.h + + +=3D TPM backend devices =3D + +The TPM implementation is split into two parts, frontend and backend. The +frontend part is the hardware interface, such as the TPM TIS interface +described earlier, and the other part is the TPM backend interface. The ba= ckend +interfaces implement the interaction with a TPM device, which may be a phy= sical +or an emulated device. The split between the front- and backend devices al= lows +a frontend to be connected with any available backend. This enables the TIS +interface to be used with the passthrough backend or the (future) swtpm ba= ckend. + + +QEMU files related to TPM backends: + - backends/tpm.c + - include/sysemu/tpm_backend.h + - include/sysemu/tpm_backend_int.h + + +=3D=3D The QEMU TPM passthrough device =3D=3D + +In case QEMU is run on Linux as the host operating system it is possible to +make the hardware TPM device available to a single QEMU guest. In this cas= e the +user must make sure that no other program is using the device, e.g., /dev/= tpm0, +before trying to start QEMU with it. + +The passthrough driver uses the host's TPM device for sending TPM commands +and receiving responses from. Besides that it accesses the TPM device's sy= sfs +entry for support of command cancellation. Since none of the state of a +hardware TPM can be migrated between hosts, virtual machine migration is +disabled when the TPM passthrough driver is used. + +Since the host's TPM device will already be initialized by the host's firm= ware, +certain commands, e.g. TPM_Startup(), sent by the virtual firmware for dev= ice +initialization, will fail. In this case the firmware should not use the TP= M. + +Sharing the device with the host is generally not a recommended usage scen= ario +for a TPM device. The primary reason for this is that two operating system= s can +then access the device's single set of resources, such as platform configu= ration +registers (PCRs). Applications or kernel security subsystems, such as the +Linux Integrity Measurement Architecture (IMA), are not expecting to share= PCRs. + + +QEMU files related to the TPM passthrough device: + - hw/tpm/tpm_passthrough.c + - hw/tpm/tpm_util.c + - hw/tpm/tpm_util.h + + +Command line to start QEMU with the TPM passthrough device using the host's +hardware TPM /dev/tpm0: + +qemu-system-x86_64 -display sdl -enable-kvm \ + -m 1024 -boot d -bios bios-256k.bin -boot menu=3Don \ + -tpmdev passthrough,id=3Dtpm0,path=3D/dev/tpm0 \ + -device tpm-tis,tpmdev=3Dtpm0 test.img + +The following command should result in similar output inside the VM with a +Linux kernel that either has the TPM TIS driver built-in or available as a +module: + +#> dmesg | grep -i tpm +[ 0.711310] tpm_tis 00:06: 1.2 TPM (device=3Did 0x1, rev-id 1) + +#> dmesg | grep TCPA +[ 0.000000] ACPI: TCP 0x0000000003FFD191C 000032 (v02 BOCHS \ + BXPCTCPA 0000001 BXPC 00000001) + +#> ls -l /dev/tpm* +crw-------. 1 root root 10, 224 Jul 11 10:11 /dev/tpm0 + +#> find /sys/devices/ | grep pcrs$ | xargs cat +PCR-00: 35 4E 3B CE 23 9F 38 59 ... +... +PCR-23: 00 00 00 00 00 00 00 00 ... --=20 2.5.5