vTPM for aarch64
v4 cover vTPM for aarch64
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
The existing TPM TIS code is reshuffled into a generic part, the ISA device and the sysbus device. The sysbus TPM-TIS device gets dynamically instantiated in machvirt on the platform bus.
ACPI boot is not yet supported on ARM. Note that the UEFI firmware is itself a consumer of the DT description, so we need the DT related changes regardless of whether the VM boots in DT or ACPI mode.
Related qtests are reshuffled to allow the reuse of existing tests for both the ISA and the sysbus devices: Adaption consists in changing the qemu command line (change in the device name and provide explicit machine options) and adapt to the relocation of the TPM-TIS device in the memory map.
The series was tested with the swtpm/libtpms emulator. Automatic guest LUKS volume unlocking (tpm2) was successful. EDK2 support is under development [3]. Thanks to Ard for supporting me when setting up the test environment.
Best Regards
Eric
Testing:
mkdir /tmp/tpm
swtpm socket \
--tpm2 \
-t -d \
--tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=/tmp/swtpm-sock
qemu command line must be augmented with the following options:
-chardev socket,id=chrtpm,path=/tmp/swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis-device,tpmdev=tpm0 \
References:
[1] libtpms: https://github.com/stefanberger/libtpms/wiki
[2] swtpm: https://github.com/stefanberger/swtpm/wiki
[3] [PATCH v3 0/9] ArmVirtPkg: implement measured boot for ArmVirtQemu
This series can be found at:
https://github.com/eauger/qemu/tree/v4.2.0-tpm-patch-v4
History:
v3 -> v4:
- collect additional R-b's
- add 'Not used but needed for linking' mention related to tpm_tis_base_addr in CRB test files
- fix comment style
RFCv2 -> PATCH v3:
- Updated the doc for ARM
- Adapted existing tests for ARM
- use qemu_fdt_setprop_string in add_tpm_tis_fdt_node
- Collected R-b's
- Comments not taken into account:
- I have kept the tpm-tis-device name for now despite Stefan's suggestion to rename it into tpm-tis-sysbus. This is not frozen though
- Common state still is not a QOM object (no double inheritence)
RFC v1 -> RFC v2:
- restructure the existing code with common, ISA and sysbus part.
- both ARM and x86 integration were tested.
Eric Auger (10):
tpm: rename TPM_TIS into TPM_TIS_ISA
tpm: Use TPMState as a common struct
tpm: Separate tpm_tis common functions from isa code
tpm: Separate TPM_TIS and TPM_TIS_ISA configs
tpm: Add the SysBus TPM TIS device
hw/arm/virt: vTPM support
docs/specs/tpm: Document TPM_TIS sysbus device for ARM
test: tpm: pass optional machine options to swtpm test functions
test: tpm-tis: Get prepared to share tests between ISA and sysbus
devices
test: tpm-tis: Add Sysbus TPM-TIS device test
default-configs/i386-softmmu.mak | 2 +-
docs/specs/tpm.rst | 25 +-
hw/arm/Kconfig | 1 +
hw/arm/sysbus-fdt.c | 33 ++
hw/arm/virt.c | 7 +
hw/i386/Kconfig | 2 +-
hw/i386/acpi-build.c | 6 +-
hw/tpm/Kconfig | 12 +-
hw/tpm/Makefile.objs | 4 +-
hw/tpm/tpm_tis.h | 91 +++++
hw/tpm/{tpm_tis.c => tpm_tis_common.c} | 181 +---------
hw/tpm/tpm_tis_isa.c | 170 +++++++++
hw/tpm/tpm_tis_sysbus.c | 159 +++++++++
include/sysemu/tpm.h | 7 +-
tests/qtest/Makefile.include | 11 +-
tests/qtest/tpm-crb-swtpm-test.c | 9 +-
tests/qtest/tpm-crb-test.c | 3 +
tests/qtest/tpm-tests.c | 10 +-
tests/qtest/tpm-tests.h | 5 +-
tests/qtest/tpm-tis-device-swtpm-test.c | 76 ++++
tests/qtest/tpm-tis-device-test.c | 87 +++++
tests/qtest/tpm-tis-swtpm-test.c | 8 +-
tests/qtest/tpm-tis-test.c | 414 +---------------------
tests/qtest/tpm-tis-util.c | 451 ++++++++++++++++++++++++
tests/qtest/tpm-tis-util.h | 23 ++
tests/qtest/tpm-util.c | 11 +-
tests/qtest/tpm-util.h | 8 +-
27 files changed, 1207 insertions(+), 609 deletions(-)
create mode 100644 hw/tpm/tpm_tis.h
rename hw/tpm/{tpm_tis.c => tpm_tis_common.c} (85%)
create mode 100644 hw/tpm/tpm_tis_isa.c
create mode 100644 hw/tpm/tpm_tis_sysbus.c
create mode 100644 tests/qtest/tpm-tis-device-swtpm-test.c
create mode 100644 tests/qtest/tpm-tis-device-test.c
create mode 100644 tests/qtest/tpm-tis-util.c
create mode 100644 tests/qtest/tpm-tis-util.hSignature · 1 line
2.20.1
PATCH v4 1/10 tpm: rename TPM_TIS into TPM_TIS_ISA
As we plan to introduce a sysbus TPM_TIS, let's rename TPM_TIS into TPM_TIS_ISA.
---
RFC v2 -> PATCH:
- added Philippe and Stefan's R-b
--- hw/i386/acpi-build.c | 6 +++--- hw/tpm/tpm_tis.c | 4 ++-- include/sysemu/tpm.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-)
hw/i386/acpi-build.c +3 -3
@@ -2026,7 +2026,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } -if (TPM_IS_TIS (tpm_find ())) { +if (TPM_IS_TIS_ISA (tpm_find ())) {aml_append (crs,aml_memory32_fixed (TPM_TIS_ADDR_BASE ,TPM_TIS_ADDR_SIZE ,AML_READ_WRITE )); }
@@ -2197,7 +2197,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); -if (TPM_IS_TIS (tpm)) { +if (TPM_IS_TIS_ISA (tpm)) {if (misc->tpm_version ==TPM_VERSION_2_0 ) { dev =aml_device ("TPM" ); aml_append(dev, aml_name_decl("_HID",
@@ -2304,7 +2304,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) (char *)&tpm2_ptr->log_area_start_address - table_data->data; tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); -if (TPM_IS_TIS (tpm_find ())) { +if (TPM_IS_TIS_ISA (tpm_find ())) { tpm2_ptr->control_area_address =cpu_to_le64 (0 ); tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); }else if (TPM_IS_CRB (tpm_find ())) {
hw/tpm/tpm_tis.c +2 -2
@@ -91,7 +91,7 @@ typedef struct TPMState {TPMPPI ppi; } TPMState; -#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) +#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS_ISA)#define DEBUG_TIS 0
@@ -1008,7 +1008,7 @@ static void tpm_tis_class_init(ObjectClass *klass, void *data) }static const TypeInfo tpm_tis_info = { - .name =TYPE_TPM_TIS , + .name =TYPE_TPM_TIS_ISA , .parent =TYPE_ISA_DEVICE , .instance_size =sizeof (TPMState), .instance_init = tpm_tis_initfn,
include/sysemu/tpm.h +3 -3
@@ -43,12 +43,12 @@ typedef struct TPMIfClass {enum TPMVersion (*get_version)(TPMIf *obj); } TPMIfClass; -#define TYPE_TPM_TIS "tpm-tis" +#define TYPE_TPM_TIS_ISA "tpm-tis"#define TYPE_TPM_CRB "tpm-crb"#define TYPE_TPM_SPAPR "tpm-spapr" -#define TPM_IS_TIS (chr) \ - object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS) +#define TPM_IS_TIS_ISA (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)#define TPM_IS_CRB (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)#define TPM_IS_SPAPR (chr) \
Signature · 1 line
2.20.1
PATCH v4 2/10 tpm: Use TPMState as a common struct
In reply to Eric AugerAs we plan to introduce a SysBus TPM TIS device, let's make the TPMState a common struct usable by both the ISADevice and the SysBusDevice. TPMStateISA embeds the struct and inherits from the ISADevice.
The prototype of functions bound to be used by both the ISA and SysBus devices is changed to take TPMState handle.
A bunch of structs also are renamed to be specialized for the ISA device. Besides those transformations, no functional change is expected.
---
v2 -> v3:
- Added Stefan's R-b
--- hw/tpm/tpm_tis.c | 146 +++++++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 55 deletions(-)
hw/tpm/tpm_tis.c +91 -55
@@ -65,7 +65,6 @@ typedef struct TPMLocality { } TPMLocality; typedef struct TPMState { - ISADevice busdev; MemoryRegion mmio; unsigned char buffer[TPM_TIS_BUFFER_MAX];
@@ -91,7 +90,15 @@ typedef struct TPMState {TPMPPI ppi; } TPMState; -#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS_ISA) +typedef struct TPMStateISA { +/*< private >*/ +ISADevice parent_obj; + +/*< public >*/ +TPMState state;/* not a QOM object */ +}TPMStateISA ; + +#define TPM_TIS_ISA (obj) OBJECT_CHECK(TPMStateISA, (obj), TYPE_TPM_TIS_ISA)#define DEBUG_TIS 0
@@ -281,9 +288,8 @@ static void tpm_tis_prep_abort(TPMState *s, uint8_t locty, uint8_t newlocty)/* * Callback from the TPM to indicate that the response was received. */ -static void tpm_tis_request_completed (TPMIf *ti,int ret) +static void tpm_tis_request_completed (TPMState *s,int ret) { -TPMState *s =TPM (ti);uint8_t locty = s->cmd.locty;uint8_t l;
@@ -338,7 +344,7 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty) } #ifdef DEBUG_TIS -static void tpm_tis_dump_state(void *opaque, hwaddr addr) +static void tpm_tis_dump_state(TPMState *s, hwaddr addr) { static const unsigned regs[] = { TPM_TIS_REG_ACCESS,
@@ -353,7 +359,6 @@ static void tpm_tis_dump_state(void *opaque, hwaddr addr)int idx;uint8_t locty =tpm_tis_locality_from_addr (addr);hwaddr base = addr & ~0xfff ; -TPMState *s = opaque;printf ("tpm_tis: active locality : %d\n" "tpm_tis: state of locality %d : %d\n"
@@ -363,7 +368,7 @@ static void tpm_tis_dump_state(void *opaque, hwaddr addr)for (idx =0 ; regs[idx] !=0xfff ; idx++) {printf ("tpm_tis: 0x%04x : 0x%08x\n" , regs[idx], - (int )tpm_tis_mmio_read (opaque, base + regs[idx],4 )); + (int )tpm_tis_mmio_read (s, base + regs[idx],4 )); } printf("tpm_tis: r/w offset : %d\n"
@@ -488,7 +493,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,break ;#ifdef DEBUG_TIS case TPM_TIS_REG_DEBUG : -tpm_tis_dump_state (opaque, addr); +tpm_tis_dump_state (s, addr);break ;#endif }
@@ -835,10 +840,8 @@ static const MemoryRegionOps tpm_tis_memory_ops = {/* * Get the TPMVersion of the backend device being used */ -static enum TPMVersion tpm_tis_get_tpm_version (TPMIf *ti) +static enum TPMVersion tpm_tis_get_tpm_version (TPMState *s) { -TPMState *s =TPM (ti); -if (tpm_backend_had_startup_error (s->be_driver)) {return TPM_VERSION_UNSPEC ; }
@@ -850,9 +853,8 @@ static enum TPMVersion tpm_tis_get_tpm_version(TPMIf *ti)* This function is called when the machine starts, resets or due to * S3 resume. */ -static void tpm_tis_reset (DeviceState *dev) +static void tpm_tis_reset (TPMState *s) { -TPMState *s =TPM (dev);int c; s->be_tpm_version =tpm_backend_get_tpm_version (s->be_driver);
@@ -896,15 +898,14 @@ static void tpm_tis_reset(DeviceState *dev)/* persistent state handling */ -static int tpm_tis_pre_save (void *opaque) +static int tpm_tis_pre_save (TPMState *s) { -TPMState *s = opaque;uint8_t locty = s->active_locty;trace_tpm_tis_pre_save (locty, s->rw_offset);if (DEBUG_TIS ) { -tpm_tis_dump_state (opaque,0 ); +tpm_tis_dump_state (s,0 ); }/*
@@ -929,34 +930,78 @@ static const VMStateDescription vmstate_locty = { } }; -static const VMStateDescription vmstate_tpm_tis = { +/* ISA */ + +static int tpm_tis_pre_save_isa (void *opaque) +{ +TPMStateISA *isadev = opaque; + +return tpm_tis_pre_save (&isadev->state); +} + +static const VMStateDescription vmstate_tpm_tis_isa = { .name ="tpm-tis" , .version_id =0 , - .pre_save = tpm_tis_pre_save, + .pre_save = tpm_tis_pre_save_isa, .fields = (VMStateField []) { -VMSTATE_BUFFER (buffer, TPMState), -VMSTATE_UINT16 (rw_offset, TPMState), -VMSTATE_UINT8 (active_locty, TPMState), -VMSTATE_UINT8 (aborting_locty, TPMState), -VMSTATE_UINT8 (next_locty, TPMState), +VMSTATE_BUFFER (state.buffer, TPMStateISA), +VMSTATE_UINT16 (state.rw_offset, TPMStateISA), +VMSTATE_UINT8 (state.active_locty, TPMStateISA), +VMSTATE_UINT8 (state.aborting_locty, TPMStateISA), +VMSTATE_UINT8 (state.next_locty, TPMStateISA), -VMSTATE_STRUCT_ARRAY (loc, TPMState,TPM_TIS_NUM_LOCALITIES ,0 , +VMSTATE_STRUCT_ARRAY (state.loc, TPMStateISA,TPM_TIS_NUM_LOCALITIES ,0 , vmstate_locty, TPMLocality),VMSTATE_END_OF_LIST () } }; -static Property tpm_tis_properties[] = { -DEFINE_PROP_UINT32 ("irq" , TPMState, irq_num,TPM_TIS_IRQ ), -DEFINE_PROP_TPMBE ("tpmdev" , TPMState, be_driver), -DEFINE_PROP_BOOL ("ppi" , TPMState, ppi_enabled, true), +static void tpm_tis_isa_request_completed (TPMIf *ti,int ret) +{ +TPMStateISA *isadev =TPM_TIS_ISA (ti); +TPMState *s = &isadev->state; + +tpm_tis_request_completed (s, ret); +} + +static enum TPMVersion tpm_tis_isa_get_tpm_version (TPMIf *ti) +{ +TPMStateISA *isadev =TPM_TIS_ISA (ti); +TPMState *s = &isadev->state; + +return tpm_tis_get_tpm_version (s); +} + +static void tpm_tis_isa_reset (DeviceState *dev) +{ +TPMStateISA *isadev =TPM_TIS_ISA (dev); +TPMState *s = &isadev->state; + +return tpm_tis_reset (s); +} + +static Property tpm_tis_isa_properties[] = { +DEFINE_PROP_UINT32 ("irq" , TPMStateISA, state.irq_num,TPM_TIS_IRQ ), +DEFINE_PROP_TPMBE ("tpmdev" , TPMStateISA, state.be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMStateISA, state.ppi_enabled, true),DEFINE_PROP_END_OF_LIST (), }; -static void tpm_tis_realizefn (DeviceState *dev,Error **errp) +static void tpm_tis_isa_initfn (Object *obj) { -TPMState *s =TPM (dev); +TPMStateISA *isadev =TPM_TIS_ISA (obj); +TPMState *s = &isadev->state; + +memory_region_init_io (&s->mmio, obj, &tpm_tis_memory_ops, + s,"tpm-tis-mmio" , +TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); +} + +static void tpm_tis_isa_realizefn (DeviceState *dev,Error **errp) +{ +TPMStateISA *isadev =TPM_TIS_ISA (dev); +TPMState *s = &isadev->state;if (!tpm_find ()) {error_setg (errp,"at most one TPM device is permitted" );
@@ -973,55 +1018,46 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)return ; } -isa_init_irq (&s->busdev, &s->irq, s->irq_num); +isa_init_irq (ISA_DEVICE (dev), &s->irq, s->irq_num);memory_region_add_subregion (isa_address_space (ISA_DEVICE (dev)),TPM_TIS_ADDR_BASE , &s->mmio);if (s->ppi_enabled) {tpm_ppi_init (&s->ppi,isa_address_space (ISA_DEVICE (dev)), -TPM_PPI_ADDR_BASE ,OBJECT (s)); +TPM_PPI_ADDR_BASE ,OBJECT (dev)); } } -static void tpm_tis_initfn (Object *obj) -{ -TPMState *s =TPM (obj); - -memory_region_init_io (&s->mmio,OBJECT (s), &tpm_tis_memory_ops, - s,"tpm-tis-mmio" , -TPM_TIS_NUM_LOCALITIES <<TPM_TIS_LOCALITY_SHIFT ); -} - -static void tpm_tis_class_init (ObjectClass *klass,void *data) +static void tpm_tis_isa_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);TPMIfClass *tc =TPM_IF_CLASS (klass); - dc->realize = tpm_tis_realizefn; -device_class_set_props (dc, tpm_tis_properties); - dc->reset = tpm_tis_reset; - dc->vmsd = &vmstate_tpm_tis; +device_class_set_props (dc, tpm_tis_isa_properties); + dc->vmsd = &vmstate_tpm_tis_isa; tc->model =TPM_MODEL_TPM_TIS ; - tc->get_version = tpm_tis_get_tpm_version; - tc->request_completed = tpm_tis_request_completed; + dc->realize = tpm_tis_isa_realizefn; + dc->reset = tpm_tis_isa_reset; + tc->request_completed = tpm_tis_isa_request_completed; + tc->get_version = tpm_tis_isa_get_tpm_version; } -static const TypeInfo tpm_tis_info = { +static const TypeInfo tpm_tis_isa_info = { .name =TYPE_TPM_TIS_ISA , .parent =TYPE_ISA_DEVICE , - .instance_size =sizeof (TPMState), - .instance_init = tpm_tis_initfn, - .class_init = tpm_tis_class_init, + .instance_size =sizeof (TPMStateISA), + .instance_init = tpm_tis_isa_initfn, + .class_init = tpm_tis_isa_class_init, .interfaces = (InterfaceInfo []) { {TYPE_TPM_IF }, { } } }; -static void tpm_tis_register (void ) +static void tpm_tis_isa_register (void ) { -type_register_static (&tpm_tis_info); +type_register_static (&tpm_tis_isa_info); } -type_init (tpm_tis_register) +type_init (tpm_tis_isa_register)
Signature · 1 line
2.20.1
PATCH v4 3/10 tpm: Separate tpm_tis common functions from isa code
In reply to Eric AugerMove the device agnostic code into tpm_tis_common.c and put the ISA device specific code into tpm_tis_isa.c
---
v2 -> v3:
- Added Stefan's R-b
---
hw/tpm/Makefile.objs | 2 +-
hw/tpm/tpm_tis.h | 91 +++++++++++
hw/tpm/{tpm_tis.c => tpm_tis_common.c} | 209 ++-----------------------
hw/tpm/tpm_tis_isa.c | 170 ++++++++++++++++++++
4 files changed, 271 insertions(+), 201 deletions(-)
create mode 100644 hw/tpm/tpm_tis.h
rename hw/tpm/{tpm_tis.c => tpm_tis_common.c} (83%)
create mode 100644 hw/tpm/tpm_tis_isa.chw/tpm/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-$(CONFIG_TPM) += tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis_isa.o tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o
hw/tpm/tpm_tis.h new file +91 -0
91 lines not on this page · raw message
hw/tpm/tpm_tis_common.c renamed from hw/tpm/tpm_tis.c +9 -200
264 lines not on this page · raw message
hw/tpm/tpm_tis_isa.c new file +170 -0
170 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 4/10 tpm: Separate TPM_TIS and TPM_TIS_ISA configs
In reply to Eric AugerLet's separate the compilation of tpm_tis_common.c from the compilation of tpm_tis_isa.c
The common part will be also compiled along with the tpm_tis_sysbus device.
---
v2 -> v3:
- added Phillipe's R-b
--- default-configs/i386-softmmu.mak | 2 +- hw/i386/Kconfig | 2 +- hw/tpm/Kconfig | 7 ++++++- hw/tpm/Makefile.objs | 3 ++- tests/qtest/Makefile.include | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-)
default-configs/i386-softmmu.mak +1 -1
@@ -20,7 +20,7 @@ #CONFIG_SGA=n #CONFIG_TEST_DEVICES=n #CONFIG_TPM_CRB=n -#CONFIG_TPM_TIS=n +#CONFIG_TPM_TIS_ISA=n #CONFIG_VTD=n # Boards:
hw/i386/Kconfig +1 -1
@@ -20,7 +20,7 @@ config PC imply SGA imply TEST_DEVICES imply TPM_CRB - imply TPM_TIS + imply TPM_TIS_ISA imply VGA_PCI imply VIRTIO_VGA select FDC
hw/tpm/Kconfig +6 -1
@@ -2,9 +2,14 @@ config TPMDEV bool depends on TPM -config TPM_TIS +config TPM_TIS_ISA bool depends on TPM && ISA_BUS + select TPM_TIS + +config TPM_TIS + bool + depends on TPM select TPMDEV config TPM_CRB
hw/tpm/Makefile.objs +2 -1
@@ -1,6 +1,7 @@ common-obj-$(CONFIG_TPM) += tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o -common-obj-$(CONFIG_TPM_TIS) += tpm_tis_isa.o tpm_tis_common.o +common-obj-$(CONFIG_TPM_TIS_ISA) += tpm_tis_isa.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o
tests/qtest/Makefile.include +2 -2
@@ -54,8 +54,8 @@ check-qtest-i386-y += q35-test check-qtest-i386-y += vmgenid-test check-qtest-i386-$(CONFIG_TPM_CRB) += tpm-crb-swtpm-test check-qtest-i386-$(CONFIG_TPM_CRB) += tpm-crb-test -check-qtest-i386-$(CONFIG_TPM_TIS) += tpm-tis-swtpm-test -check-qtest-i386-$(CONFIG_TPM_TIS) += tpm-tis-test +check-qtest-i386-$(CONFIG_TPM_TIS_ISA) += tpm-tis-swtpm-test +check-qtest-i386-$(CONFIG_TPM_TIS_ISA) += tpm-tis-test check-qtest-i386-$(CONFIG_SLIRP) += test-netfilter check-qtest-i386-$(CONFIG_POSIX) += test-filter-mirror check-qtest-i386-$(CONFIG_RTL8139_PCI) += test-filter-redirector
Signature · 1 line
2.20.1
PATCH v4 5/10 tpm: Add the SysBus TPM TIS device
In reply to Eric AugerIntroduce the tpm-tis-device which is a sysbus device and is bound to be used on ARM.
---
v2 -> v3:
- Added Stefan's R-b
--- hw/tpm/Kconfig | 5 ++ hw/tpm/Makefile.objs | 1 + hw/tpm/tpm_tis_sysbus.c | 159 ++++++++++++++++++++++++++++++++++++++++ include/sysemu/tpm.h | 1 + 4 files changed, 166 insertions(+) create mode 100644 hw/tpm/tpm_tis_sysbus.c
hw/tpm/Kconfig +5 -0
@@ -7,6 +7,11 @@ config TPM_TIS_ISA depends on TPM && ISA_BUS select TPM_TIS +config TPM_TIS_SYSBUS + bool + depends on TPM + select TPM_TIS + config TPM_TIS bool depends on TPM
hw/tpm/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ common-obj-$(CONFIG_TPM) += tpm_util.o obj-$(call lor,$(CONFIG_TPM_TIS),$(CONFIG_TPM_CRB)) += tpm_ppi.o common-obj-$(CONFIG_TPM_TIS_ISA) += tpm_tis_isa.o +common-obj-$(CONFIG_TPM_TIS_SYSBUS) += tpm_tis_sysbus.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis_common.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
hw/tpm/tpm_tis_sysbus.c new file +159 -0
159 lines not on this page · raw message
include/sysemu/tpm.h +1 -0
@@ -44,6 +44,7 @@ typedef struct TPMIfClass { } TPMIfClass;#define TYPE_TPM_TIS_ISA "tpm-tis" +#define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"#define TYPE_TPM_CRB "tpm-crb"#define TYPE_TPM_SPAPR "tpm-spapr"
Signature · 1 line
2.20.1
PATCH v4 6/10 hw/arm/virt: vTPM support
In reply to Eric AugerLet the TPM TIS SYSBUS device be dynamically instantiable in ARM virt. A device tree node is dynamically created (TPM via MMIO).
The TPM Physical Presence interface (PPI) is not supported.
To run with the swtmp TPM emulator, the qemu command line must be augmented with:
-chardev socket,id=chrtpm,path=swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis-device,tpmdev=tpm0 \swtpm/libtpms command line example:
swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=swtpm-sock
---
v2 -> v3:
- use qemu_fdt_setprop_string()
--- hw/arm/Kconfig | 1 + hw/arm/sysbus-fdt.c | 33 +++++++++++++++++++++++++++++++++ hw/arm/virt.c | 7 +++++++ 3 files changed, 41 insertions(+)
hw/arm/Kconfig +1 -0
@@ -5,6 +5,7 @@ config ARM_VIRT imply VFIO_AMD_XGBE imply VFIO_PLATFORM imply VFIO_XGMAC + imply TPM_TIS_SYSBUS select A15MPCORE select ACPI select ARM_SMMUV3
hw/arm/sysbus-fdt.c +33 -0
@@ -30,6 +30,7 @@#include "hw/arm/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" +#include "sysemu/tpm.h" #include "hw/platform-bus.h" #include "hw/vfio/vfio-platform.h" #include "hw/vfio/vfio-calxeda-xgmac.h"
@@ -434,6 +435,37 @@ static bool vfio_platform_match(SysBusDevice *sbdev,#define VFIO_PLATFORM_BINDING (compat, add_fn) \ {TYPE_VFIO_PLATFORM, (compat), (add_fn), vfio_platform_match} +/* +* add_tpm_tis_fdt_node: Create a DT node for TPM TIS +* +* See kernel documentation: +* Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt +* Optional interrupt for command completion is not exposed +*/ +static int add_tpm_tis_fdt_node (SysBusDevice *sbdev,void *opaque) +{ +PlatformBusFDTData *data = opaque; +PlatformBusDevice *pbus = data->pbus; +void *fdt = data->fdt; +const char *parent_node = data->pbus_node_name; +char *nodename; +uint32_t reg_attr[2 ]; +uint64_t mmio_base; + + mmio_base =platform_bus_get_mmio_addr (pbus, sbdev,0 ); + nodename =g_strdup_printf ("%s/tpm_tis@%" PRIx64, parent_node, mmio_base); +qemu_fdt_add_subnode (fdt, nodename); + +qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"tcg,tpm-tis-mmio" ); + + reg_attr[0 ] =cpu_to_be32 (mmio_base); + reg_attr[1 ] =cpu_to_be32 (0x5000 ); +qemu_fdt_setprop (fdt, nodename,"reg" , reg_attr,2 *sizeof (uint32_t )); + +g_free (nodename); +return 0 ; +} +#endif /* CONFIG_LINUX */ static int no_fdt_node (SysBusDevice *sbdev,void *opaque)
@@ -455,6 +487,7 @@ static const BindingEntry bindings[] = {TYPE_BINDING (TYPE_VFIO_CALXEDA_XGMAC , add_calxeda_midway_xgmac_fdt_node),TYPE_BINDING (TYPE_VFIO_AMD_XGBE , add_amd_xgbe_fdt_node),VFIO_PLATFORM_BINDING ("amd,xgbe-seattle-v1a" , add_amd_xgbe_fdt_node), +TYPE_BINDING (TYPE_TPM_TIS_SYSBUS , add_tpm_tis_fdt_node), #endifTYPE_BINDING (TYPE_RAMFB_DEVICE , no_fdt_node), TYPE_BINDING("", NULL), /* last element */
hw/arm/virt.c +7 -0
@@ -47,6 +47,7 @@#include "sysemu/numa.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" +#include "sysemu/tpm.h" #include "sysemu/kvm.h" #include "hw/loader.h" #include "exec/address-spaces.h"
@@ -2041,6 +2042,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)machine_class_allow_dynamic_sysbus_dev (mc,TYPE_VFIO_AMD_XGBE );machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE );machine_class_allow_dynamic_sysbus_dev (mc,TYPE_VFIO_PLATFORM ); +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS ); mc->block_default_type =IF_VIRTIO ; mc->no_cdrom =1 ; mc->pci_allow_0_address = true;
@@ -2153,6 +2155,11 @@ type_init(machvirt_machine_init);static void virt_machine_5_0_options (MachineClass *mc) { +static GlobalProperty compat[] = { + {TYPE_TPM_TIS_SYSBUS ,"ppi" ,"false" }, + }; + +compat_props_add (mc->compat_props, compat,G_N_ELEMENTS (compat)); }DEFINE_VIRT_MACHINE_AS_LATEST (5 ,0 )
Signature · 1 line
2.20.1
Re: [PATCH v4 06/10] hw/arm/virt: vTPM support
Hi Peter,
Quoted 15 lines · Eric Auger
Let the TPM TIS SYSBUS device be dynamically instantiable in ARM virt. A device tree node is dynamically created (TPM via MMIO).
The TPM Physical Presence interface (PPI) is not supported.
To run with the swtmp TPM emulator, the qemu command line must be augmented with:
-chardev socket,id=chrtpm,path=swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-tis-device,tpmdev=tpm0 \swtpm/libtpms command line example:
Quoted 7 lines
swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=swtpm-sockSigned-off-by Eric Auger <[email protected]>Reviewed-by Stefan Berger <[email protected]>Tested-by Ard Biesheuvel <[email protected]>Acked-by Ard Biesheuvel <[email protected]>
When you can find free cycles, please can you check you have nothing against that patch. The rest of the series looks OK from Stefan's and Ard's point of view.
Thanks
Eric
Quoted 114 lines
---
v2 -> v3:
- useqemu_fdt_setprop_string()--- hw/arm/Kconfig | 1 + hw/arm/sysbus-fdt.c | 33 +++++++++++++++++++++++++++++++++ hw/arm/virt.c | 7 +++++++ 3 files changed, 41 insertions(+)hw/arm/Kconfig +1
-0@@ -5,6 +5,7 @@ config ARM_VIRT imply VFIO_AMD_XGBE imply VFIO_PLATFORM imply VFIO_XGMAC + imply TPM_TIS_SYSBUS select A15MPCORE select ACPI select ARM_SMMUV3hw/arm/sysbus-fdt.c +33
-0@@ -30,6 +30,7 @@#include "hw/arm/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" +#include "sysemu/tpm.h" #include "hw/platform-bus.h" #include "hw/vfio/vfio-platform.h" #include "hw/vfio/vfio-calxeda-xgmac.h" @@ -434,6 +435,37 @@ static bool vfio_platform_match(SysBusDevice *sbdev,#define VFIO_PLATFORM_BINDING (compat, add_fn) \ {TYPE_VFIO_PLATFORM, (compat), (add_fn), vfio_platform_match} +/* +* add_tpm_tis_fdt_node: Create a DT node for TPM TIS +* +* See kernel documentation: +* Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt +* Optional interrupt for command completion is not exposed +*/ +static int add_tpm_tis_fdt_node (SysBusDevice *sbdev,void *opaque) +{ +PlatformBusFDTData *data = opaque; +PlatformBusDevice *pbus = data->pbus; +void *fdt = data->fdt; +const char *parent_node = data->pbus_node_name; +char *nodename; +uint32_t reg_attr[2 ]; +uint64_t mmio_base; + + mmio_base =platform_bus_get_mmio_addr (pbus, sbdev,0 ); + nodename =g_strdup_printf ("%s/tpm_tis@%" PRIx64, parent_node, mmio_base); +qemu_fdt_add_subnode (fdt, nodename); + +qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"tcg,tpm-tis-mmio" ); + + reg_attr[0 ] =cpu_to_be32 (mmio_base); + reg_attr[1 ] =cpu_to_be32 (0x5000 ); +qemu_fdt_setprop (fdt, nodename,"reg" , reg_attr,2 *sizeof (uint32_t )); + +g_free (nodename); +return 0 ; +} +#endif /* CONFIG_LINUX */ static int no_fdt_node (SysBusDevice *sbdev,void *opaque)@@ -455,6 +487,7 @@ static const BindingEntry bindings[] = {TYPE_BINDING (TYPE_VFIO_CALXEDA_XGMAC , add_calxeda_midway_xgmac_fdt_node),TYPE_BINDING (TYPE_VFIO_AMD_XGBE , add_amd_xgbe_fdt_node),VFIO_PLATFORM_BINDING ("amd,xgbe-seattle-v1a" , add_amd_xgbe_fdt_node), +TYPE_BINDING (TYPE_TPM_TIS_SYSBUS , add_tpm_tis_fdt_node), #endifTYPE_BINDING (TYPE_RAMFB_DEVICE , no_fdt_node), TYPE_BINDING("", NULL), /* last element */hw/arm/virt.c +7
-0@@ -47,6 +47,7 @@#include "sysemu/numa.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" +#include "sysemu/tpm.h" #include "sysemu/kvm.h" #include "hw/loader.h" #include "exec/address-spaces.h" @@ -2041,6 +2042,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)machine_class_allow_dynamic_sysbus_dev (mc,TYPE_VFIO_AMD_XGBE );machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE );machine_class_allow_dynamic_sysbus_dev (mc,TYPE_VFIO_PLATFORM ); +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS ); mc->block_default_type =IF_VIRTIO ; mc->no_cdrom =1 ; mc->pci_allow_0_address = true;@@ -2153,6 +2155,11 @@ type_init(machvirt_machine_init);static void virt_machine_5_0_options (MachineClass *mc) { +static GlobalProperty compat[] = { + {TYPE_TPM_TIS_SYSBUS ,"ppi" ,"false" }, + }; + +compat_props_add (mc->compat_props, compat,G_N_ELEMENTS (compat)); }DEFINE_VIRT_MACHINE_AS_LATEST (5 ,0 )
PATCH v4 7/10 docs/specs/tpm: Document TPM_TIS sysbus device for ARM
In reply to Eric AugerUpdate the documentation with recent changes related to the sysbus TPM_TIS device addition and add the command line to be used with arm VIRT.
---
v3 -> v4:
- s/later/latter
--- docs/specs/tpm.rst | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
docs/specs/tpm.rst +24 -1
@@ -18,9 +18,15 @@ 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_common.c`` + - ``hw/tpm/tpm_tis_isa.c`` + - ``hw/tpm/tpm_tis_sysbus.c`` - ``hw/tpm/tpm_tis.h`` +Both an ISA device and a sysbus device are available. The former is +used with pc/q35 machine while the latter can be instantiated in the +ARM virt machine. + CRB interface -------------
@@ -325,6 +331,23 @@ In case a pSeries machine is emulated, use the following command line: -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,id=virtio-disk0 \ -drive file=test.img,format=raw,if=none,id=drive-virtio-disk0 +In case an ARM virt machine is emulated, use the following command line: + +.. code-block:: console + + qemu-system-aarch64 -machine virt,gic-version=3,accel=kvm \ + -cpu host -m 4G \ + -nographic -no-acpi \ + -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis-device,tpmdev=tpm0 \ + -device virtio-blk-pci,drive=drv0 \ + -drive format=qcow2,file=hda.qcow2,if=none,id=drv0 \ + -drive if=pflash,format=raw,file=flash0.img,readonly \ + -drive if=pflash,format=raw,file=flash1.img + + On ARM, ACPI boot with TPM is not yet supported. + In case SeaBIOS is used as firmware, it should show the TPM menu item after entering the menu with 'ESC'.
Signature · 1 line
2.20.1
PATCH v4 8/10 test: tpm: pass optional machine options to swtpm test functions
In reply to Eric AugerWe plan to use swtpm test functions on ARM for testing the sysbus TPM-TIS device. However on ARM there is no default machine type. So we need to explictly pass some machine options on startup. Let's allow this by adding a new parameter to both swtpm test functions and update all call sites.
---
v3 -> v4:
- added Stefan's R-b
--- tests/qtest/tpm-crb-swtpm-test.c | 5 +++-- tests/qtest/tpm-tests.c | 10 ++++++---- tests/qtest/tpm-tests.h | 5 +++-- tests/qtest/tpm-tis-swtpm-test.c | 5 +++-- tests/qtest/tpm-util.c | 8 ++++++-- tests/qtest/tpm-util.h | 3 ++- 6 files changed, 23 insertions(+), 13 deletions(-)
tests/qtest/tpm-crb-swtpm-test.c +3 -2
@@ -29,7 +29,8 @@ static void tpm_crb_swtpm_test(const void *data) {const TestState *ts = data; -tpm_test_swtpm_test (ts->src_tpm_path, tpm_util_crb_transfer,"tpm-crb" ); +tpm_test_swtpm_test (ts->src_tpm_path, tpm_util_crb_transfer, +"tpm-crb" ,NULL ); }static void tpm_crb_swtpm_migration_test (const void *data)
@@ -37,7 +38,7 @@ static void tpm_crb_swtpm_migration_test(const void *data)const TestState *ts = data;tpm_test_swtpm_migration_test (ts->src_tpm_path, ts->dst_tpm_path, ts->uri, - tpm_util_crb_transfer,"tpm-crb" ); + tpm_util_crb_transfer,"tpm-crb" ,NULL ); }int main (int argc,char **argv)
tests/qtest/tpm-tests.c +6 -4
@@ -30,7 +30,7 @@ tpm_test_swtpm_skip(void) }void tpm_test_swtpm_test (const char *src_tpm_path,tx_func *tx, -const char *ifmodel) +const char *ifmodel,const char *machine_options) {char *args =NULL ;QTestState *s;
@@ -47,10 +47,11 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,g_assert_true (succ); args =g_strdup_printf ( +"%s " "-chardev socket,id=chr,path=%s " "-tpmdev emulator,id=dev,chardev=chr " "-device %s,tpmdev=dev" , - addr->u.q_unix.path, ifmodel); + machine_options ? :"" , addr->u.q_unix.path, ifmodel); s =qtest_start (args);g_free (args);
@@ -78,7 +79,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,void tpm_test_swtpm_migration_test (const char *src_tpm_path,const char *dst_tpm_path,const char *uri,tx_func *tx, -const char *ifmodel) +const char *ifmodel, +const char *machine_options) {gboolean succ;GPid src_tpm_pid, dst_tpm_pid;
@@ -100,7 +102,7 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,tpm_util_migration_start_qemu (&src_qemu, &dst_qemu, src_tpm_addr, dst_tpm_addr, uri, - ifmodel); + ifmodel, machine_options);tpm_util_startup (src_qemu, tx);tpm_util_pcrextend (src_qemu, tx);
tests/qtest/tpm-tests.h +3 -2
@@ -16,11 +16,12 @@#include "tpm-util.h" void tpm_test_swtpm_test (const char *src_tpm_path,tx_func *tx, -const char *ifmodel); +const char *ifmodel,const char *machine_options);void tpm_test_swtpm_migration_test (const char *src_tpm_path,const char *dst_tpm_path,const char *uri,tx_func *tx, -const char *ifmodel); +const char *ifmodel, +const char *machine_options);#endif /* TESTS_TPM_TESTS_H */
tests/qtest/tpm-tis-swtpm-test.c +3 -2
@@ -29,7 +29,8 @@ static void tpm_tis_swtpm_test(const void *data) {const TestState *ts = data; -tpm_test_swtpm_test (ts->src_tpm_path, tpm_util_tis_transfer,"tpm-tis" ); +tpm_test_swtpm_test (ts->src_tpm_path, tpm_util_tis_transfer, +"tpm-tis" ,NULL ); }static void tpm_tis_swtpm_migration_test (const void *data)
@@ -37,7 +38,7 @@ static void tpm_tis_swtpm_migration_test(const void *data)const TestState *ts = data;tpm_test_swtpm_migration_test (ts->src_tpm_path, ts->dst_tpm_path, ts->uri, - tpm_util_tis_transfer,"tpm-tis" ); + tpm_util_tis_transfer,"tpm-tis" ,NULL ); }int main (int argc,char **argv)
tests/qtest/tpm-util.c +6 -2
@@ -258,23 +258,27 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu, SocketAddress *src_tpm_addr, SocketAddress *dst_tpm_addr, const char *miguri, - const char *ifmodel) + const char *ifmodel, + const char *machine_options) {char *src_qemu_args, *dst_qemu_args; src_qemu_args =g_strdup_printf ( +"%s " "-chardev socket,id=chr,path=%s " "-tpmdev emulator,id=dev,chardev=chr " "-device %s,tpmdev=dev " , - src_tpm_addr->u.q_unix.path, ifmodel); + machine_options ? :"" , src_tpm_addr->u.q_unix.path, ifmodel); *src_qemu =qtest_init (src_qemu_args); dst_qemu_args =g_strdup_printf ( +"%s " "-chardev socket,id=chr,path=%s " "-tpmdev emulator,id=dev,chardev=chr " "-device %s,tpmdev=dev " "-incoming %s" , + machine_options ? :"" , dst_tpm_addr->u.q_unix.path, ifmodel, miguri);
tests/qtest/tpm-util.h +2 -1
@@ -44,7 +44,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu, SocketAddress *src_tpm_addr, SocketAddress *dst_tpm_addr, const char *miguri, - const char *ifmodel); + const char *ifmodel, + const char *machine_options);void tpm_util_wait_for_migration_complete (QTestState *who);
Signature · 1 line
2.20.1
PATCH v4 9/10 test: tpm-tis: Get prepared to share tests between ISA and sysbus devices
In reply to Eric AugerISA and sysbus TPM-TIS devices will share their tests. Only the main() will change (instantiation option is different). Also the base address of the TPM-TIS device is going to be different. on x86 it is located at 0xFED40000 while on ARM it can be located at any location, discovered through the device tree description.
So we put shared test functions in a new object module. Each test needs to set tpm_tis_base_addr global variable.
Also take benefit of this move to fix "block comments using a leading */ on a separate line" checkpatch warnings.
---
v3 -> v4:
- added 'not used but needed for linking' (TPM_TIS_ADDR_BASE) in crb files
- fix comment style warnings
--- tests/qtest/Makefile.include | 2 +- tests/qtest/tpm-crb-swtpm-test.c | 4 + tests/qtest/tpm-crb-test.c | 3 + tests/qtest/tpm-tis-swtpm-test.c | 3 + tests/qtest/tpm-tis-test.c | 414 +--------------------------- tests/qtest/tpm-tis-util.c | 451 +++++++++++++++++++++++++++++++ tests/qtest/tpm-tis-util.h | 23 ++ tests/qtest/tpm-util.c | 3 - tests/qtest/tpm-util.h | 5 + 9 files changed, 493 insertions(+), 415 deletions(-) create mode 100644 tests/qtest/tpm-tis-util.c create mode 100644 tests/qtest/tpm-tis-util.h
tests/qtest/Makefile.include +1 -1
@@ -302,7 +302,7 @@ tests/qtest/tpm-crb-swtpm-test$(EXESUF): tests/qtest/tpm-crb-swtpm-test.o tests/ tests/qtest/tpm-crb-test$(EXESUF): tests/qtest/tpm-crb-test.o tests/qtest/tpm-emu.o $(test-io-obj-y) tests/qtest/tpm-tis-swtpm-test$(EXESUF): tests/qtest/tpm-tis-swtpm-test.o tests/qtest/tpm-emu.o \ tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) -tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/tpm-emu.o $(test-io-obj-y) +tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) # QTest rules
tests/qtest/tpm-crb-swtpm-test.c +4 -0
@@ -18,6 +18,10 @@#include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" +#include "hw/acpi/tpm.h" + +/* Not used but needed for linking */ +uint64_t tpm_tis_base_addr =TPM_TIS_ADDR_BASE ; typedef struct TestState { char *src_tpm_path;
tests/qtest/tpm-crb-test.c +3 -0
@@ -19,6 +19,9 @@#include "qemu/module.h" #include "tpm-emu.h" +/* Not used but needed for linking */ +uint64_t tpm_tis_base_addr =TPM_TIS_ADDR_BASE ; +#define TPM_CMD "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00"static void tpm_crb_test (const void *data)
tests/qtest/tpm-tis-swtpm-test.c +3 -0
@@ -18,6 +18,9 @@#include "libqtest.h" #include "qemu/module.h" #include "tpm-tests.h" +#include "hw/acpi/tpm.h" + +uint64_t tpm_tis_base_addr =TPM_TIS_ADDR_BASE ; typedef struct TestState { char *src_tpm_path;
tests/qtest/tpm-tis-test.c +3 -411
425 lines not on this page · raw message
tests/qtest/tpm-tis-util.c new file +451 -0
451 lines not on this page · raw message
tests/qtest/tpm-tis-util.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* QTest TPM TIS: Common test functions used for both the +* ISA and SYSBUS devices +* +* Copyright (c) 2018 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef TESTS_TPM_TIS_UTIL_H +#define TESTS_TPM_TIS_UTIL_H + +void tpm_tis_test_check_localities (const void *data); +void tpm_tis_test_check_access_reg (const void *data); +void tpm_tis_test_check_access_reg_seize (const void *data); +void tpm_tis_test_check_access_reg_release (const void *data); +void tpm_tis_test_check_transmit (const void *data); + +#endif /* TESTS_TPM_TIS_UTIL_H */
tests/qtest/tpm-util.c +0 -3
@@ -19,9 +19,6 @@#include "tpm-util.h" #include "qapi/qmp/qdict.h" -#define TIS_REG (LOCTY ,REG ) \ - (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG) -void tpm_util_crb_transfer (QTestState *s,const unsigned char *req,size_t req_size,unsigned char *rsp,size_t rsp_size)
tests/qtest/tpm-util.h +5 -0
@@ -15,6 +15,11 @@#include "io/channel-socket.h" +extern uint64_t tpm_tis_base_addr; + +#define TIS_REG (LOCTY ,REG ) \ + (tpm_tis_base_addr + ((LOCTY) << 12) + REG) +typedef void (tx_func )(QTestState *s,const unsigned char *req,size_t req_size,unsigned char *rsp,size_t rsp_size);
Signature · 1 line
2.20.1
PATCH v4 10/10 test: tpm-tis: Add Sysbus TPM-TIS device test
In reply to Eric AugerThe tests themselves are the same as the ISA device ones. Only the main() changes as the "tpm-tis-device" device gets instantiated. Also the base address of the device is not 0xFED40000 anymore but matches the base address of the ARM virt platform bus.
--- tests/qtest/Makefile.include | 5 ++ tests/qtest/tpm-tis-device-swtpm-test.c | 76 +++++++++++++++++++++ tests/qtest/tpm-tis-device-test.c | 87 +++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 tests/qtest/tpm-tis-device-swtpm-test.c create mode 100644 tests/qtest/tpm-tis-device-test.c
tests/qtest/Makefile.include +5 -0
@@ -130,6 +130,8 @@ check-qtest-arm-y += hexloader-test check-qtest-arm-$(CONFIG_PFLASH_CFI02) += pflash-cfi02-test check-qtest-aarch64-y += arm-cpu-features +check-qtest-aarch64-$(CONFIG_TPM_TIS_SYSBUS) += tpm-tis-device-test +check-qtest-aarch64-$(CONFIG_TPM_TIS_SYSBUS) += tpm-tis-device-swtpm-test check-qtest-aarch64-y += numa-test check-qtest-aarch64-y += boot-serial-test check-qtest-aarch64-y += migration-test
@@ -302,7 +304,10 @@ tests/qtest/tpm-crb-swtpm-test$(EXESUF): tests/qtest/tpm-crb-swtpm-test.o tests/ tests/qtest/tpm-crb-test$(EXESUF): tests/qtest/tpm-crb-test.o tests/qtest/tpm-emu.o $(test-io-obj-y) tests/qtest/tpm-tis-swtpm-test$(EXESUF): tests/qtest/tpm-tis-swtpm-test.o tests/qtest/tpm-emu.o \ tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) +tests/qtest/tpm-tis-device-swtpm-test$(EXESUF): tests/qtest/tpm-tis-device-swtpm-test.o tests/qtest/tpm-emu.o \ + tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) +tests/qtest/tpm-tis-device-test$(EXESUF): tests/qtest/tpm-tis-device-test.o tests/qtest/tpm-tis-util.o tests/qtest/tpm-emu.o $(test-io-obj-y) # QTest rules
tests/qtest/tpm-tis-device-swtpm-test.c new file +76 -0
76 lines not on this page · raw message
tests/qtest/tpm-tis-device-test.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.20.1
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
I queued it now here: https://github.com/stefanberger/qemu-tpm/commits/tpm-next
I will send the PR within a few days. Thanks!
Cheers,
Stefan
Quoted 122 lines
The existing TPM TIS code is reshuffled into a generic part, the ISA device and the sysbus device. The sysbus TPM-TIS device gets dynamically instantiated in machvirt on the platform bus.
ACPI boot is not yet supported on ARM. Note that the UEFI firmware is itself a consumer of the DT description, so we need the DT related changes regardless of whether the VM boots in DT or ACPI mode.
Related qtests are reshuffled to allow the reuse of existing tests for both the ISA and the sysbus devices: Adaption consists in changing the qemu command line (change in the device name and provide explicit machine options) and adapt to the relocation of the TPM-TIS device in the memory map.
The series was tested with the swtpm/libtpms emulator. Automatic guest LUKS volume unlocking (tpm2) was successful. EDK2 support is under development [3]. Thanks to Ard for supporting me when setting up the test environment.
Best Regards
Eric
Testing:
mkdir
/tmp/tpm
swtpm socket \
--tpm2 \
-t -d \
--tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=/tmp/swtpm-sockqemu command line must be augmented with the following options:
(quoted diff) +0
-3-chardev socket,id=chrtpm,path=/tmp/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-tis-device,tpmdev=tpm0 \References:
[1] libtpms: https://github.com/stefanberger/libtpms/wiki
[2] swtpm: https://github.com/stefanberger/swtpm/wiki
[3] [PATCH v3 0/9] ArmVirtPkg: implement measured boot for ArmVirtQemuThis series can be found at:
https://github.com/eauger/qemu/tree/v4.2.0-tpm-patch-v4History:
v3 -> v4:
- collect additional R-b's
- add 'Not used but needed for linking' mention related totpm_tis_base_addrin CRB test files
- fix comment styleRFCv2 -> PATCH v3:
- Updated the doc for ARM
- Adapted existing tests for ARM
- useqemu_fdt_setprop_stringinadd_tpm_tis_fdt_node
- Collected R-b's
- Comments not taken into account:
- I have kept the tpm-tis-device name for now despite Stefan's suggestion to rename it into tpm-tis-sysbus. This is not frozen though
- Common state still is not a QOM object (no double inheritence)RFC v1 -> RFC v2:
- restructure the existing code with common, ISA and sysbus part.
- both ARM and x86 integration were tested.Eric Auger (10):
tpm: renameTPM_TISintoTPM_TIS_ISA
tpm: Use TPMState as a common struct
tpm: Separatetpm_tiscommon functions from isa code
tpm: SeparateTPM_TISandTPM_TIS_ISAconfigs
tpm: Add the SysBus TPM TIS device
hw/arm/virt: vTPM support
docs/specs/tpm: DocumentTPM_TISsysbus device for ARM
test: tpm: pass optional machine options to swtpm test functions
test: tpm-tis: Get prepared to share tests between ISA and sysbus
devices
test: tpm-tis: Add Sysbus TPM-TIS device testdefault-configs/i386-softmmu.mak | 2 +- docs/specs/tpm.rst | 25 +- hw/arm/Kconfig | 1 + hw/arm/sysbus-fdt.c | 33 ++ hw/arm/virt.c | 7 + hw/i386/Kconfig | 2 +- hw/i386/acpi-build.c | 6 +- hw/tpm/Kconfig | 12 +- hw/tpm/Makefile.objs | 4 +- hw/tpm/tpm_tis.h | 91 +++++ hw/tpm/{tpm_tis.c => tpm_tis_common.c} | 181 +--------- hw/tpm/tpm_tis_isa.c | 170 +++++++++ hw/tpm/tpm_tis_sysbus.c | 159 +++++++++ include/sysemu/tpm.h | 7 +- tests/qtest/Makefile.include | 11 +- tests/qtest/tpm-crb-swtpm-test.c | 9 +- tests/qtest/tpm-crb-test.c | 3 + tests/qtest/tpm-tests.c | 10 +- tests/qtest/tpm-tests.h | 5 +- tests/qtest/tpm-tis-device-swtpm-test.c | 76 ++++ tests/qtest/tpm-tis-device-test.c | 87 +++++ tests/qtest/tpm-tis-swtpm-test.c | 8 +- tests/qtest/tpm-tis-test.c | 414 +--------------------- tests/qtest/tpm-tis-util.c | 451 ++++++++++++++++++++++++ tests/qtest/tpm-tis-util.h | 23 ++ tests/qtest/tpm-util.c | 11 +- tests/qtest/tpm-util.h | 8 +- 27 files changed, 1207 insertions(+), 609 deletions(-)create mode 100644
hw/tpm/tpm_tis.h
renamehw/tpm/{tpm_tis.c=>tpm_tis_common.c} (85%) create mode 100644hw/tpm/tpm_tis_isa.c
create mode 100644hw/tpm/tpm_tis_sysbus.ccreate mode 100644tests/qtest/tpm-tis-device-swtpm-test.ccreate mode 100644tests/qtest/tpm-tis-device-test.ccreate mode 100644tests/qtest/tpm-tis-util.ccreate mode 100644tests/qtest/tpm-tis-util.h
Hi Stefan,
Quoted 8 lines · Stefan Berger
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
I queued it now here:
https://github.com/stefanberger/qemu-tpm/commits/tpm-nextI will send the PR within a few days. Thanks!
Thank you. I will just ping Peter to make sure he has no comments on
[PATCH v4 06/10] hw/arm/virt: vTPM support
Eric
Quoted 131 lines
Cheers,
Stefan
Quoted 122 lines
The existing TPM TIS code is reshuffled into a generic part, the ISA device and the sysbus device. The sysbus TPM-TIS device gets dynamically instantiated in machvirt on the platform bus.
ACPI boot is not yet supported on ARM. Note that the UEFI firmware is itself a consumer of the DT description, so we need the DT related changes regardless of whether the VM boots in DT or ACPI mode.
Related qtests are reshuffled to allow the reuse of existing tests for both the ISA and the sysbus devices: Adaption consists in changing the qemu command line (change in the device name and provide explicit machine options) and adapt to the relocation of the TPM-TIS device in the memory map.
The series was tested with the swtpm/libtpms emulator. Automatic guest LUKS volume unlocking (tpm2) was successful. EDK2 support is under development [3]. Thanks to Ard for supporting me when setting up the test environment.
Best Regards
Eric
Testing:
mkdir
/tmp/tpm
swtpm socket \
--tpm2 \
-t -d \
--tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=/tmp/swtpm-sockqemu command line must be augmented with the following options:
(quoted diff) +0
-3-chardev socket,id=chrtpm,path=/tmp/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-tis-device,tpmdev=tpm0 \References:
[1] libtpms: https://github.com/stefanberger/libtpms/wiki
[2] swtpm: https://github.com/stefanberger/swtpm/wiki
[3] [PATCH v3 0/9] ArmVirtPkg: implement measured boot for ArmVirtQemuThis series can be found at:
https://github.com/eauger/qemu/tree/v4.2.0-tpm-patch-v4History:
v3 -> v4:
- collect additional R-b's
- add 'Not used but needed for linking' mention related totpm_tis_base_addrin CRB test files
- fix comment styleRFCv2 -> PATCH v3:
- Updated the doc for ARM
- Adapted existing tests for ARM
- useqemu_fdt_setprop_stringinadd_tpm_tis_fdt_node
- Collected R-b's
- Comments not taken into account:
- I have kept the tpm-tis-device name for now despite Stefan's suggestion to rename it into tpm-tis-sysbus. This is not frozen though
- Common state still is not a QOM object (no double inheritence)RFC v1 -> RFC v2:
- restructure the existing code with common, ISA and sysbus part.
- both ARM and x86 integration were tested.Eric Auger (10):
tpm: renameTPM_TISintoTPM_TIS_ISA
tpm: Use TPMState as a common struct
tpm: Separatetpm_tiscommon functions from isa code
tpm: SeparateTPM_TISandTPM_TIS_ISAconfigs
tpm: Add the SysBus TPM TIS device
hw/arm/virt: vTPM support
docs/specs/tpm: DocumentTPM_TISsysbus device for ARM
test: tpm: pass optional machine options to swtpm test functions
test: tpm-tis: Get prepared to share tests between ISA and sysbus devices
test: tpm-tis: Add Sysbus TPM-TIS device testdefault-configs/i386-softmmu.mak | 2 +- docs/specs/tpm.rst | 25 +- hw/arm/Kconfig | 1 + hw/arm/sysbus-fdt.c | 33 ++ hw/arm/virt.c | 7 + hw/i386/Kconfig | 2 +- hw/i386/acpi-build.c | 6 +- hw/tpm/Kconfig | 12 +- hw/tpm/Makefile.objs | 4 +- hw/tpm/tpm_tis.h | 91 +++++
hw/tpm/{tpm_tis.c=> tpm_tis_common.c} | 181 +--------- hw/tpm/tpm_tis_isa.c | 170 +++++++++ hw/tpm/tpm_tis_sysbus.c | 159 +++++++++ include/sysemu/tpm.h | 7 +- tests/qtest/Makefile.include | 11 +- tests/qtest/tpm-crb-swtpm-test.c | 9 +- tests/qtest/tpm-crb-test.c | 3 + tests/qtest/tpm-tests.c | 10 +- tests/qtest/tpm-tests.h | 5 +-tests/qtest/tpm-tis-device-swtpm-test.c| 76 ++++ tests/qtest/tpm-tis-device-test.c | 87 +++++ tests/qtest/tpm-tis-swtpm-test.c | 8 +-tests/qtest/tpm-tis-test.c | 414 +--------------------- tests/qtest/tpm-tis-util.c | 451 ++++++++++++++++++++++++ tests/qtest/tpm-tis-util.h | 23 ++ tests/qtest/tpm-util.c | 11 +- tests/qtest/tpm-util.h | 8 +- 27 files changed, 1207 insertions(+), 609 deletions(-)create mode 100644
hw/tpm/tpm_tis.h
renamehw/tpm/{tpm_tis.c=>tpm_tis_common.c} (85%) create mode 100644hw/tpm/tpm_tis_isa.c
create mode 100644hw/tpm/tpm_tis_sysbus.ccreate mode 100644tests/qtest/tpm-tis-device-swtpm-test.ccreate mode 100644tests/qtest/tpm-tis-device-test.ccreate mode 100644tests/qtest/tpm-tis-util.ccreate mode 100644tests/qtest/tpm-tis-util.h
Quoted 5 lines · Auger Eric
Hi Stefan,
Quoted 3 lines · Stefan Berger
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
Quoted 7 lines
Quoted 4 lines
I queued it now here:
https://github.com/stefanberger/qemu-tpm/commits/tpm-nextI will send the PR within a few days. Thanks!
Thank you. I will just ping Peter to make sure he has no comments on
[PATCH v4 06/10] hw/arm/virt: vTPM support
The little dent is now an arm boot failure:
https://travis-ci.org/stefanberger/qemu-tpm/jobs/655573347?utm_medium=notification&utm_source=email
Have a look at the raw log.
Stefan
Hi Stefan,
Quoted 12 lines · Stefan Berger
Quoted 11 lines · Auger Eric
Hi Stefan,
Quoted 7 lines · Stefan Berger
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
I queued it now here:
https://github.com/stefanberger/qemu-tpm/commits/tpm-nextI will send the PR within a few days. Thanks!
Thank you. I will just ping Peter to make sure he has no comments on
Quoted 7 lines
Quoted 1 line
[PATCH v4 06/10] hw/arm/virt: vTPM support
The little dent is now an arm boot failure:
https://travis-ci.org/stefanberger/qemu-tpm/jobs/655573347?utm_medium=notification&utm_source=email
is this really related to the sysbus TPM-TIS addition? I have the impression cubieboard acceptance tests (ARM 32b) are failing. I touched ARM virt machine.
Thanks
Eric
Quoted 10 lines
Have a look at the raw log.
Stefan
Quoted 16 lines · Auger Eric
Hi Stefan,
Quoted 14 lines · Stefan Berger
Quoted 12 lines · Auger Eric
Hi Stefan,
Quoted 7 lines · Stefan Berger
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
I queued it now here:
https://github.com/stefanberger/qemu-tpm/commits/tpm-nextI will send the PR within a few days. Thanks!
Thank you. I will just ping Peter to make sure he has no comments on
[PATCH v4 06/10] hw/arm/virt: vTPM support
Quoted 7 lines
Quoted 4 lines
The little dent is now an arm boot failure:
https://travis-ci.org/stefanberger/qemu-tpm/jobs/655573347?utm_medium=notification&utm_source=email
is this really related to the sysbus TPM-TIS addition? I have the impression cubieboard acceptance tests (ARM 32b) are failing. I touched ARM virt machine.
I hadn't seen this one here before:
https://travis-ci.org/qemu/qemu/jobs/656327906
We're good.
Stefan
Quoted 13 lines
Thanks
Eric
Quoted 9 lines
Have a look at the raw log.
Stefan
Hi Stefan,
Quoted 26 lines · Stefan Berger
Quoted 16 lines · Auger Eric
Hi Stefan,
Quoted 14 lines · Stefan Berger
Quoted 12 lines · Auger Eric
Hi Stefan,
Quoted 7 lines · Stefan Berger
Quoted 2 lines · Eric Auger
This series adds the capability to instantiate an MMIO TPM TIS in ARM virt. It is candidate to qemu 5.0.
I queued it now here:
https://github.com/stefanberger/qemu-tpm/commits/tpm-nextI will send the PR within a few days. Thanks!
Thank you. I will just ping Peter to make sure he has no comments on
[PATCH v4 06/10] hw/arm/virt: vTPM support
Quoted 8 lines
Quoted 5 lines
The little dent is now an arm boot failure:
https://travis-ci.org/stefanberger/qemu-tpm/jobs/655573347?utm_medium=notification&utm_source=email
is this really related to the sysbus TPM-TIS addition? I have the impression cubieboard acceptance tests (ARM 32b) are failing. I touched ARM virt machine.
Quoted 6 lines
I hadn't seen this one here before:
https://travis-ci.org/qemu/qemu/jobs/656327906
We're good.
Thanks for the confirmation.
Best Regards
Eric
Quoted 20 lines
Stefan
Quoted 13 lines
Thanks
Eric
Quoted 9 lines
Have a look at the raw log.
Stefan