Skip to contentSkip to conversation

TPM status

Qemu-devel Laszlo Ersek 4 participants 16 messages Jun 14, 2017 – Jul 1, 2017

lore
Share & tools
lore
#0 lore raw

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

backends/tpm.c
hw/tpm/
include/hw/acpi/tpm.h
include/sysemu/tpm*
tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Thank you,
Laszlo

#1 lore raw
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

   backends/tpm.c
   hw/tpm/
   include/hw/acpi/tpm.h
   include/sysemu/tpm*
   tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

I'll look into that. Give me some time...

Stefan

Quoted 4 lines

Thank you,
Laszlo

#3 lore raw
In reply to Stefan Berger
Quoted 58 lines · Stefan Berger
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

   backends/tpm.c
   hw/tpm/
   include/hw/acpi/tpm.h
   include/sysemu/tpm*
   tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

Quoted 7 lines

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes
it into the guest through the fw_cfg device. The device description contains
the base address of the TIS interface 0xfed40000 and the size of the

Double space before "0xfed40000".

Quoted 7 lines

MMIO area
(0x5000). In case a TPM2 is used by QEMU, a TPM2 ACPI table is also provided. The
device is described to be used in polling mode rather than interrupt mode primarily
because no unused IRQ could be found.

Quoted 5 lines

To support measurements 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.

Does the TCPA table depend on TPM1 vs. TPM2?

Quoted 11 lines

The TCPA and TPM2 ACPI tables follow the Trusted Computing Group specification
"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/

Quoted 7 lines

= TPM backend devices =

The TPM implementation is split into two parts. The one part is the hardware
interface, such as the TPM TIS interface described earlier, and the TPM backend
interface.

The last sentence here is a bit hard to understand. Can we use frontend/backend language? (Already used below, so that's great.)

Quoted 27 lines

The backend interfaces implement the interaction with a TPM device,
which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

== The QEMU TPM passthrough device ==

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 case 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 sysfs
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.

Quoted 2 lines

Since the host's TPM device will already be initialize by the host's firmware, certain

I think this line is too long (87 chars) -- I think we should wrap at 79 chars or so.

Quoted 10 lines

commands, e.g. TPM_Startup(), sent by the virtual firmware for device initialization
will fail. In this case the firmware should simply not use the TPM.

Sharing the device with the host is generally not a recommended usage scenario
for a TPM device. The primary reason for this is that two operating systems can then
access the device's single set of resources, such as platform configuration registers (PCRs), that applications are not expecting to share.

Looks great to me, thank you!

Two requests in addition to the above remarks:
- can you provide command line options / examples wherever appropriate?
- can you list the pathnames of the source files that currently implement frontend / backend / ACPI / passthrough, as appropriate?

(I think the next version should be posted as a first class PATCH, for wider review.)

Thank you!
Laszlo

#2 lore raw
In reply to Laszlo Ersek
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

   backends/tpm.c
   hw/tpm/
   include/hw/acpi/tpm.h
   include/sysemu/tpm*
   tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes it into the guest through the fw_cfg device. The device description contains 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 provided. The device is described to be used in polling mode rather than interrupt mode primarily because no unused IRQ could be found.

To support measurements 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.

The TCPA and TPM2 ACPI tables follow the Trusted Computing Group specification "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/

= TPM backend devices =

The TPM implementation is split into two parts. The one part is the hardware interface, such as the TPM TIS interface described earlier, and the TPM backend interface. The backend interfaces implement the interaction with a TPM device, which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

== The QEMU TPM passthrough device ==

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 case 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 sysfs 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 initialize by the host's firmware, certain commands, e.g. TPM_Startup(), sent by the virtual firmware for device initialization will fail. In this case the firmware should simply not use the TPM.

Sharing the device with the host is generally not a recommended usage scenario for a TPM device. The primary reason for this is that two operating systems can then access the device's single set of resources, such as platform configuration registers (PCRs), that applications are not expecting to share.

Quoted 4 lines

Thank you,
Laszlo

#6 lore raw
Quoted 67 lines · Stefan Berger
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

   backends/tpm.c
   hw/tpm/
   include/hw/acpi/tpm.h
   include/sysemu/tpm*
   tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes it into the guest through the fw_cfg device. The device description contains 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 provided. The device is described to be used in polling mode rather than interrupt mode primarily because no unused IRQ could be found.

Quoted 3 lines

To support measurements 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.

How does this work if we boot with edk2? Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
instead of this interface? As well as it? It'd be good to have some text about this here.

Signature · 1 line
  Peter
#7 lore raw
Quoted 68 lines · Peter Jones
Quoted 67 lines · Stefan Berger
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

   backends/tpm.c
   hw/tpm/
   include/hw/acpi/tpm.h
   include/sysemu/tpm*
   tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes it into the guest through the fw_cfg device. The device description contains 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 provided. The device is described to be used in polling mode rather than interrupt mode primarily because no unused IRQ could be found.

Quoted 5 lines
Quoted 3 lines

To support measurements 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.

How does this work if we boot with edk2?

My expectation is that it doesn't work at all, without doing some OVMF platform enablement first. (See
<https://bugzilla.tianocore.org/show_bug.cgi?id=594>.) My plan is to use Stefan's document as a starting point for the edk2 / OVMF investigation -- one known and one unknown are better than two unknowns (to me).

Quoted 4 lines

Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
instead of this interface? As well as it? It'd be good to have some text about this here.

I don't think that Stefan has spent any time on EFI enablement, so this part of the document will have to be written later, once there is any EFI-related functionality we can document. (I expect.)

Thanks,
Laszlo

#8 lore raw
Quoted 77 lines · Laszlo Ersek
Quoted 67 lines · Peter Jones
Quoted 66 lines · Stefan Berger
Quoted 28 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files in the tree:

    backends/tpm.c
    hw/tpm/
    include/hw/acpi/tpm.h
    include/sysemu/tpm*
    tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 7 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS. (You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes it into the guest through the fw_cfg device. The device description contains 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 provided. The device is described to be used in polling mode rather than interrupt mode primarily because no unused IRQ could be found.

Quoted 4 lines
Quoted 3 lines

To support measurements 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.

How does this work if we boot with edk2?

My expectation is that it doesn't work at all, without doing some OVMF platform enablement first. (See
<https://bugzilla.tianocore.org/show_bug.cgi?id=594>.) My plan is to use Stefan's document as a starting point for the edk2 / OVMF investigation -- one known and one unknown are better than two unknowns (to me).

Quoted 7 lines
Quoted 4 lines

Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
instead of this interface? As well as it? It'd be good to have some text about this here.

I don't think that Stefan has spent any time on EFI enablement, so this part of the document will have to be written later, once there is any EFI-related functionality we can document. (I expect.)

Right, I did not spend any time on EFI. I suppose the ACPI tables going to a BIOS are also useful for EFI.

For BIOS there is unfortunately only a spec for TPM 1.2, none anymore for TPM2, at least back then when I last looked for it. So I ended up passing that TCPA table that has the pointer for the logging area also in case of a TPM 2. So SeaBIOS writes its log to it in both cases, following the TPM 2 format form the EFI specs for the entries. The Linux driver in the meantime has modified the code so that it doesn't show the log anymore in case of TPM 2 :-( . I think the above referenced specs would explain how the logging area is to be allocated. My guess is that after detecting the presence of a TPM 2 (for which there is also a TPM2 ACPI table passed, so maybe that can be used as an indicator) one would malloc() the logging area and then proceed similar to how the BIOS does. The difference to a BIOS is that EFI has an API for getting to that log iirc.

Stefan

#9 lore raw
Quoted 98 lines · Stefan Berger
Quoted 85 lines · Laszlo Ersek
Quoted 75 lines · Peter Jones
Quoted 74 lines · Stefan Berger
Quoted 30 lines · Laszlo Ersek

Hi Stefan,

the MAINTAINERS file doesn't seem to cover any of the TPM-related files
in the tree:

    backends/tpm.c
    hw/tpm/
    include/hw/acpi/tpm.h
    include/sysemu/tpm*
    tpm.c

but I have a gut feeling that you are semi-officially maintaining TPM anyway, so I'm going to ask you. :)

Can you please write a document, to be placed under docs/specs/, that describes the TPM device from a guest perspective, also explaining how the guest-visible bits are connected to (current) TPM backend(s)?

The document wouldn't have to be very long; I think all standardized interfaces could be mentioned by reference only (by spec names and locations). The document should however describe any QEMU specifics, and
how the relevant specs are brought together in the implementation.

Some text files I'm familiar with and can recommend as examples:
- docs/specs/fw_cfg.txt
- docs/specs/pvpanic.txt
- docs/specs/vmgenid.txt

Quoted 8 lines

(There may be more and/or better examples of course.)

This document should be the starting point for developers that want to support QEMU's TPM(s) in guest firmware that is different from SeaBIOS.
(You've been maintaining the related SeaBIOS feature.)

Would you be willing to author such a design document?

Here's what I have so far with pointers to TCG specs. Does that go in the
right direction?

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following
the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation 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.

= ACPI Interface =

The TPM device is defined with ACPI ID "PNP0C31". QEMU builds a SSDT and passes it into the guest through the fw_cfg device. The device description contains 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 provided. The device is described to be used in polling mode rather than interrupt mode primarily because no unused IRQ could be found.

Quoted 4 lines
Quoted 3 lines

To support measurements 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.

How does this work if we boot with edk2?

My expectation is that it doesn't work at all, without doing some OVMF platform enablement first. (See
<https://bugzilla.tianocore.org/show_bug.cgi?id=594>.) My plan is to use Stefan's document as a starting point for the edk2 / OVMF investigation -- one known and one unknown are better than two unknowns (to me).

Quoted 8 lines
Quoted 5 lines

Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf

instead of this interface? As well as it? It'd be good to have some text about this here.

I don't think that Stefan has spent any time on EFI enablement, so this part of the document will have to be written later, once there is any EFI-related functionality we can document. (I expect.)

Right, I did not spend any time on EFI. I suppose the ACPI tables going to a BIOS are also useful for EFI.

Quoted 13 lines

For BIOS there is unfortunately only a spec for TPM 1.2, none anymore for TPM2, at least back then when I last looked for it. So I ended up passing that TCPA table that has the pointer for the logging area also in case of a TPM 2. So SeaBIOS writes its log to it in both cases, following the TPM 2 format form the EFI specs for the entries. The Linux driver in the meantime has modified the code so that it doesn't show the log anymore in case of TPM 2 :-( . I think the above referenced specs would explain how the logging area is to be allocated. My guess is that after detecting the presence of a TPM 2 (for which there is also a TPM2 ACPI table passed, so maybe that can be used as an indicator) one would malloc() the logging area and then proceed similar to how the BIOS does. The difference to a BIOS is that EFI has an API for getting to that log iirc.

I haven't checked yet, but my worry is that the TPM drivers in edk2 will want to install the ACPI tables related to the TPM device / infrastructure themselves. If that's the case, we'll either have to modify QEMU not to produce those tables in the ACPI payload, despite exposing a TPM device to the guest -- clearly this will take another command line option, or an extension to one --, or else the TPM drivers in edk2 will have to be convinced to cope with the ACPI tables pre-installed, by some other firmware module. Again, I'm not sure if either of these will be necessary, but if one is, then the former looks way more feasible to me. The TPM drivers in edk2 could reasonably argue that on a physical platform they "own" the TPM device, along with all ACPI tables related to it. We'll see.

Thanks
Laszlo

#12 lore raw
In reply to Stefan Berger

Hello Stefan,

Thanks a lot for the summary, it's very informative. I've a question below.

Quoted 12 lines · Stefan Berger

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation Version 1.3, 21 March 2013. This specification, or a later version of it, can be accessed from the following URL:

Quoted 5 lines

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.

Besides the TIS interface, the TPM2.0 spec defines a CRB (Command Response Buffer Interface) as described in the "TCG PC Client Platform TPM Profile (PTP) Specification Family 2.0, Level 00 Revision 00.43, January 26, 2015"

https://trustedcomputinggroup.org/wp-content/uploads/PC-Client-Specific-Platform-TPM-Profile-for-TPM-2-0-v43-150126.pdf

Quoted 10 lines

= TPM backend devices =

The TPM implementation is split into two parts. The one part is the hardware interface, such as the TPM TIS interface described earlier, and the TPM backend interface. The backend interfaces implement the interaction with a TPM device, which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

So we will need another TPM interface that implements the CRB interface? I have a machine with the Intel PTT TPM2.0 (firmware-based implemented in ME) that uses this CRB interface instead of TIS1.2 + cancel, so libvirt fails:

Error starting domain: internal error: No usable sysfs TPM cancel file could be found

Traceback (most recent call last):
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 88, in cb_wrapper
callback(asyncjob, *args, **kwargs)
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 124, in tmpcb
callback(*args, **kwargs)
File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 83, in newfn

    ret = fn(self, *args, **kwargs)
  File "/usr/share/virt-manager/virtManager/domain.py", line 1479, in startup
    self._backend.create()
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 1039, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)

libvirtError: internal error: No usable sysfs TPM cancel file could be found

The Linux kernel exposes either a TIS or CRB interface depending on what is filled in the TPM2 ACPI table "Start Method" field as specified in "TCG ACPI Specification Family 1.2 and 2.0 Version 1.2, Revision 8 February 27, 2017"

https://trustedcomputinggroup.org/wp-content/uploads/TCG_ACPIGeneralSpecification-Family-1.2-and-2.0-Ver1.2-Rev8_public-revie....pdf

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#10 lore raw
In reply to Stefan Berger

Hello Stefan,

Quoted 3 lines · Stefan Berger
Quoted 2 lines · Laszlo Ersek
Quoted 1 line · Peter Jones

On Tue, Jun 27, 2017 at 12:12:50PM -0400, Stefan Berger wrote:

[snip]

Quoted 18 lines
Quoted 10 lines
Quoted 5 lines
Quoted 4 lines

To support measurements 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.

How does this work if we boot with edk2?

My expectation is that it doesn't work at all, without doing some OVMF platform enablement first. (See
<https://bugzilla.tianocore.org/show_bug.cgi?id=594>.) My plan is to use Stefan's document as a starting point for the edk2 / OVMF investigation -- one known and one unknown are better than two unknowns (to me).

Quoted 7 lines
Quoted 4 lines

Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
instead of this interface? As well as it? It'd be good to have some text about this here.

I don't think that Stefan has spent any time on EFI enablement, so this part of the document will have to be written later, once there is any EFI-related functionality we can document. (I expect.)

Quoted 6 lines

Right, I did not spend any time on EFI. I suppose the ACPI tables going to a BIOS are also useful for EFI.

For BIOS there is unfortunately only a spec for TPM 1.2, none anymore for TPM2, at least back then when I last looked for it. So I ended up passing that TCPA table that has the pointer for the logging area also in case of a TPM 2. So SeaBIOS writes its log to it in both cases, following the TPM 2

But this isn't correct from a TPM2 pov, right? Because the TPM2 spec says that the ACPI table that contains the TPM2.0 event logs is the TPM2 table.

So instead the LASA field in the passed TPM2 ACPI table should point to the allocated buffer used by the firmware to store the event logs.

Quoted 3 lines

format form the EFI specs for the entries. The Linux driver in the meantime has modified the code so that it doesn't show the log anymore in case of TPM 2 :-( . I think the above referenced specs would explain how the logging

Do you mean that in the past Linux exposed the securityfs files with the event logs for TPM2 chips as well? My understanding is that Linux does the correct thing now, since as mentioned the TCPA table should only be used for TPM1.2.

There are patches posted to add Linux support to read the event logs for TPM2 chips but from the TPM2 ACPI table. I see that hose haven't landed yet though:

https://patchwork.kernel.org/project/tpmdd-devel/list/?submitter=7143

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#13 lore raw
In reply to Javier Martinez Canillas
Quoted 30 lines · Javier Martinez Canillas

Hello Stefan,

Thanks a lot for the summary, it's very informative. I've a question below.

Quoted 11 lines · Stefan Berger

QEMU TPM Device
===============

= Guest-side Hardware Interface =

The QEMU TPM emulation implements a TPM TIS hardware interface following the Trusted Computing Group's specification "TCG PC Client Specific TPM Interface Specification (TIS)", Specifcation Version 1.3, 21 March 2013. This specification, or a later version of it, can be accessed from the following URL:

Quoted 5 lines

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.

Besides the TIS interface, the TPM2.0 spec defines a CRB (Command Response Buffer Interface) as described in the "TCG PC Client Platform TPM Profile (PTP) Specification Family 2.0, Level 00 Revision 00.43, January 26, 2015"

https://trustedcomputinggroup.org/wp-content/uploads/PC-Client-Specific-Platform-TPM-Profile-for-TPM-2-0-v43-150126.pdf

Quoted 2 lines

= TPM backend devices =

Quoted 8 lines
Quoted 7 lines

The TPM implementation is split into two parts. The one part is the hardware interface, such as the TPM TIS interface described earlier, and the TPM backend interface. The backend interfaces implement the interaction with a TPM device, which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

So we will need another TPM interface that implements the CRB interface? I

No. How did you infer that ?

Quoted 18 lines

have a machine with the Intel PTT TPM2.0 (firmware-based implemented in ME) that uses this CRB interface instead of TIS1.2 + cancel, so libvirt fails:

Error starting domain: internal error: No usable sysfs TPM cancel file could be found

Traceback (most recent call last):
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 88, in cb_wrapper
callback(asyncjob, *args, **kwargs)
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 124, in tmpcb
callback(*args, **kwargs)
File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 83, in newfn

     ret = fn(self, *args, **kwargs)
   File "/usr/share/virt-manager/virtManager/domain.py", line 1479, in startup
     self._backend.create()
   File "/usr/lib64/python2.7/site-packages/libvirt.py", line 1039, in create
     if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)

libvirtError: internal error: No usable sysfs TPM cancel file could be found

Quoted 7 lines

The Linux kernel exposes either a TIS or CRB interface depending on what is filled in the TPM2 ACPI table "Start Method" field as specified in "TCG ACPI Specification Family 1.2 and 2.0 Version 1.2, Revision 8 February 27, 2017"

https://trustedcomputinggroup.org/wp-content/uploads/TCG_ACPIGeneralSpecification-Family-1.2-and-2.0-Ver1.2-Rev8_public-revie....pdf

Best regards,

This will require a patch to libvirt. In case the host has a TPM 2 the cancel sysfs entry does not exist and we need to pass /dev/null instead. I'll have a look at that.

Stefan

#11 lore raw
In reply to Javier Martinez Canillas
Quoted 24 lines · Javier Martinez Canillas

Hello Stefan,

Quoted 3 lines · Stefan Berger
Quoted 2 lines · Laszlo Ersek
Quoted 1 line · Peter Jones

On Tue, Jun 27, 2017 at 12:12:50PM -0400, Stefan Berger wrote:

[snip]

Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
Quoted 3 lines

To support measurements 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.

How does this work if we boot with edk2?

My expectation is that it doesn't work at all, without doing some OVMF platform enablement first. (See
<https://bugzilla.tianocore.org/show_bug.cgi?id=594>.) My plan is to use Stefan's document as a starting point for the edk2 / OVMF investigation -- one known and one unknown are better than two unknowns (to me).

Quoted 4 lines

Do we get what's described in
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
instead of this interface? As well as it? It'd be good to have some text about this here.

I don't think that Stefan has spent any time on EFI enablement, so this part of the document will have to be written later, once there is any EFI-related functionality we can document. (I expect.)

Quoted 8 lines
Quoted 6 lines

Right, I did not spend any time on EFI. I suppose the ACPI tables going to a BIOS are also useful for EFI.

For BIOS there is unfortunately only a spec for TPM 1.2, none anymore for TPM2, at least back then when I last looked for it. So I ended up passing that TCPA table that has the pointer for the logging area also in case of a TPM 2. So SeaBIOS writes its log to it in both cases, following the TPM 2

But this isn't correct from a TPM2 pov, right? Because the TPM2 spec says that the ACPI table that contains the TPM2.0 event logs is the TPM2 table.

The problem is the lack of specs for BIOS to support TPM. I don't see how the TPM2 could hold the log pointer. I am looking at section 7.3 in this document here:

https://www.trustedcomputinggroup.org/wp-content/uploads/TCG_ACPIGeneralSpecification_1-10_0-37-Published.pdf

Quoted 3 lines

So instead the LASA field in the passed TPM2 ACPI table should point to the allocated buffer used by the firmware to store the event logs.

I only see LAML and LASA for TCPA ACPI table (sections 7.1.2 & 7.2.2), which seems to only be valid for TPM 1.2.

Quoted 6 lines
Quoted 3 lines

format form the EFI specs for the entries. The Linux driver in the meantime has modified the code so that it doesn't show the log anymore in case of TPM 2 :-( . I think the above referenced specs would explain how the logging

Do you mean that in the past Linux exposed the securityfs files with the event logs for TPM2 chips as well? My understanding is that Linux does the correct thing now, since as mentioned the TCPA table should only be used for TPM1.2.

There may have been a version or two of the driver that did that, yes.

This version has this check:

http://elixir.free-electrons.com/linux/v4.11.8/source/drivers/char/tpm/tpm_acpi.c#L57

This version does not have this check:

http://elixir.free-electrons.com/linux/v4.10.17/source/drivers/char/tpm/tpm_acpi.c

Quoted 5 lines

There are patches posted to add Linux support to read the event logs for TPM2 chips but from the TPM2 ACPI table. I see that hose haven't landed yet though:

https://patchwork.kernel.org/project/tpmdd-devel/list/?submitter=7143

Aha, so I see this person is following some draft spec that isn't referenced via above page, yet.

"Latest draft of TPM 2 ACPI specification added TCG log start/length to the TPM2 ACPI table. So Linux kernel can now read it without having to get involved with boot loader, same way TPM1/TCPA tables work."

https://patchwork.kernel.org/patch/9651005/

Quoted 1 line

Best regards,

#4 lore raw
In reply to Laszlo Ersek
Quoted 5 lines · Laszlo Ersek

Looks great to me, thank you!

Two requests in addition to the above remarks:
- can you provide command line options / examples wherever appropriate?

I didn't add it because we describe that on this page here:

http://download.qemu.org/qemu-doc.html

"To create a passthrough TPM use the following two options:

-tpmdev passthrough,id=tpm0 -device tpm-tis,tpmdev=tpm0"

Stefan

#14 lore raw
In reply to Stefan Berger
Quoted 1 line · Stefan Berger

On 06/29/2017 08:39 AM, Javier Martinez Canillas wrote:

[snip]

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

= TPM backend devices =

The TPM implementation is split into two parts. The one part is the hardware interface, such as the TPM TIS interface described earlier, and the TPM backend interface. The backend interfaces implement the interaction with a TPM device, which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

Quoted 4 lines
Quoted 1 line

So we will need another TPM interface that implements the CRB interface? I

No. How did you infer that ?

I thought that if the host firmware set the TPM2 Start Method to CRB instead of TIS1.2+cancel, then the guest would have to use the same interface.

But now with your patch libvirt doesn't complain anymore about a missing cancel sysfs file and I could access the host TPM2.0 as a pass-through device, even when the host is using the tpm_crb driver while the guest uses the tpm_tis one.

Sorry for the confusion, I'm just been learning about the TPM and still trying to make sense of all the different specifications and documents.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat
#15 lore raw
Quoted 14 lines · Javier Martinez Canillas
Quoted 1 line · Stefan Berger

On 06/29/2017 08:39 AM, Javier Martinez Canillas wrote:

[snip]

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

= TPM backend devices =

The TPM implementation is split into two parts. The one part is the hardware interface, such as the TPM TIS interface described earlier, and the TPM backend interface. The backend interfaces implement the interaction with a TPM device, which may be a physical or an emulated device. The split between the front- and backend devices allows 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 backend.

So we will need another TPM interface that implements the CRB interface? I

Quoted 8 lines
Quoted 2 lines

No. How did you infer that ?

I thought that if the host firmware set the TPM2 Start Method to CRB instead of TIS1.2+cancel, then the guest would have to use the same interface.

But now with your patch libvirt doesn't complain anymore about a missing cancel sysfs file and I could access the host TPM2.0 as a pass-through device, even when the host is using the tpm_crb driver while the guest uses the tpm_tis one.

For passthrough really only /dev/tpm0 matters. The rest of the interface and what interface the host device has doesn't matter, at least not with the TPM device.

Regards,
Stefan

#5 lore raw
In reply to Stefan Berger
Quoted 7 lines · Stefan Berger
Quoted 5 lines · Laszlo Ersek

Looks great to me, thank you!

Two requests in addition to the above remarks:
- can you provide command line options / examples wherever appropriate?

Quoted 8 lines

I didn't add it because we describe that on this page here:

http://download.qemu.org/qemu-doc.html

"To create a passthrough TPM use the following two options:

-tpmdev passthrough,id=tpm0 -device tpm-tis,tpmdev=tpm0"

Yes, I saw that in the manual. The manual is huge, and personally I'd prefer either an embedded example or a more targeted reference.

At least in "docs/pcie.txt", Marcel added a whole bunch of command line snippets, and it is *very* useful (to me anyway). "docs/specs/fw_cfg.txt" also talks about the command line under "Externally Provided Items".

Thanks for considering it,
Laszlo