Add vTPM emulator support for ppc64 platform
v8 cover Add vTPM emulator support for ppc64 platform
The following series of patches adds vTPM emulator support for the ppc64 platform (pSeries).
It can be tested as follows with swtpm/libtpms:
mkdir /tmp/mytpm1
swtpm socket --tpmstate dir=/tmp/mytpm1 \
--ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock \
--log level=20
If TPM 2 is desired, add --tpm2 as parameter to the above.
In another terminal start QEMU:
sudo ./ppc64-softmmu/qemu-system-ppc64 -display sdl \ -machine pseries,accel=kvm \ -m 1024 -bios slof.bin -boot menu=on \ -nodefaults -device VGA -device pci-ohci -device usb-kbd \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-spapr,tpmdev=tpm0 \ -device spapr-vscsi,id=scsi0,reg=0x00002000 \ -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
Links:
- libtpms: https://github.com/stefanberger/libtpms/wiki
- swtpm: https://github.com/stefanberger/swtpm/wiki
Changes:
v7->v8:
- Folded documentation patch into 3rd patch
- Added Marc-André's patch to end of series
v6->v7:
- Implemented get_dt_compatible() and using it
- Moved tpm_this_show_buffer to tpm_util.c
v5->v6:
- adjusted names of structures and simplified
- only transmitting min. necessary bytes to pass to VM after resume
- addressed other issues pointed out by D. Gibson
v4->v5:
- use runstate_check(RUN_STATE_FINISH_MIGRATE) to check whether devices are suspending; ditch 3 patches in this series that tried to do similar
v3->v4:
- addressed comments to v3
- reworked suspend/resume support that requires extensions to backends
v2->v3:
- patch 1: a TPM 2 is identified by IBM,vtpm20 in the compatible node
- patch 1: convert to tracing to display Tx and Rx buffers
- added documentation patch
- added patch to enable TPM device as part of pSeries
v1->v2:
- followed Cedric Le Goater's suggestions to patch 1
- send appropriate CRQ error responses if DMA read or write fails
- renamed tpm_spapr_got_payload to tpm_spapr_process_cmd and pass endianess-adjusted data pointer from CRQ to it
Regards,
Stefan
Marc-André Lureau (1):
docs/specs/tpm: reST-ify TPM documentation
Stefan Berger (5):
tpm: Move tpm_tis_show_buffer to tpm_util.c
spapr: Implement get_dt_compatible() callback
tpm_spapr: Support TPM for ppc64 using CRQ based interface
tpm_spapr: Support suspend and resume hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config
docs/specs/index.rst | 1 + docs/specs/tpm.rst | 503 +++++++++++++++++++++++++++++++++++++ docs/specs/tpm.txt | 427 ------------------------------- hw/ppc/Kconfig | 1 + hw/ppc/spapr_vio.c | 11 +- hw/tpm/Kconfig | 6 + hw/tpm/Makefile.objs | 1 + hw/tpm/tpm_spapr.c | 443 ++++++++++++++++++++++++++++++++ hw/tpm/tpm_tis.c | 32 +-- hw/tpm/tpm_util.c | 25 ++ hw/tpm/tpm_util.h | 3 + hw/tpm/trace-events | 16 +- include/hw/ppc/spapr_vio.h | 1 + include/sysemu/tpm.h | 3 + qapi/tpm.json | 6 +- 15 files changed, 1018 insertions(+), 461 deletions(-) create mode 100644 docs/specs/tpm.rst delete mode 100644 docs/specs/tpm.txt create mode 100644 hw/tpm/tpm_spapr.c
Signature · 1 line
2.24.1
PATCH v8 1/6 tpm: Move tpm_tis_show_buffer to tpm_util.c
From: Stefan Berger <[email protected]>
--- hw/tpm/tpm_tis.c | 32 ++++---------------------------- hw/tpm/tpm_util.c | 25 +++++++++++++++++++++++++ hw/tpm/tpm_util.h | 3 +++ hw/tpm/trace-events | 2 +- 4 files changed, 33 insertions(+), 29 deletions(-)
hw/tpm/tpm_tis.c +4 -28
@@ -107,30 +107,6 @@ static uint8_t tpm_tis_locality_from_addr(hwaddr addr)return (uint8_t )((addr >>TPM_TIS_LOCALITY_SHIFT ) &0x7 ); } -static void tpm_tis_show_buffer (const unsigned char *buffer, -size_t buffer_size,const char *string) -{ -size_t len, i; -char *line_buffer, *p; - - len =MIN (tpm_cmd_get_size (buffer), buffer_size); - -/* -* allocate enough room for 3 chars per buffer entry plus a -* newline after every 16 chars and a final null terminator. -*/ - line_buffer =g_malloc (len *3 + (len /16 ) +1 ); - -for (i =0 , p = line_buffer; i < len; i++) { -if (i && !(i %16 )) { - p +=sprintf (p,"\n" ); - } - p +=sprintf (p,"%.2X " , buffer[i]); - } -trace_tpm_tis_show_buffer (string, len, line_buffer); - -g_free (line_buffer); -}/* * Set the given flags in the STS register by clearing the register but
@@ -156,8 +132,8 @@ static void tpm_tis_sts_set(TPMLocality *l, uint32_t flags)*/ static void tpm_tis_tpm_send (TPMState *s,uint8_t locty) { -if (trace_event_get_state_backends (TRACE_TPM_TIS_SHOW_BUFFER )) { -tpm_tis_show_buffer (s->buffer, s->be_buffer_size,"To TPM" ); +if (trace_event_get_state_backends (TRACE_TPM_UTIL_SHOW_BUFFER )) { +tpm_util_show_buffer (s->buffer, s->be_buffer_size,"To TPM" ); }/*
@@ -325,8 +301,8 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret) s->loc[locty].state =TPM_TIS_STATE_COMPLETION ; s->rw_offset =0 ; -if (trace_event_get_state_backends (TRACE_TPM_TIS_SHOW_BUFFER )) { -tpm_tis_show_buffer (s->buffer, s->be_buffer_size,"From TPM" ); +if (trace_event_get_state_backends (TRACE_TPM_UTIL_SHOW_BUFFER )) { +tpm_util_show_buffer (s->buffer, s->be_buffer_size,"From TPM" ); }if (TPM_TIS_IS_VALID_LOCTY (s->next_locty)) {
hw/tpm/tpm_util.c +25 -0
@@ -350,3 +350,28 @@ void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) tsb->buffer =NULL ; tsb->size =0 ; } + +void tpm_util_show_buffer (const unsigned char *buffer, +size_t buffer_size,const char *string) +{ +size_t len, i; +char *line_buffer, *p; + + len =MIN (tpm_cmd_get_size (buffer), buffer_size); + +/* +* allocate enough room for 3 chars per buffer entry plus a +* newline after every 16 chars and a final null terminator. +*/ + line_buffer =g_malloc (len *3 + (len /16 ) +1 ); + +for (i =0 , p = line_buffer; i < len; i++) { +if (i && !(i %16 )) { + p +=sprintf (p,"\n" ); + } + p +=sprintf (p,"%.2X " , buffer[i]); + } +trace_tpm_util_show_buffer (string, len, line_buffer); + +g_free (line_buffer); +}
hw/tpm/tpm_util.h +3 -0
@@ -79,4 +79,7 @@ typedef struct TPMSizedBuffer {void tpm_sized_buffer_reset (TPMSizedBuffer *tsb); +void tpm_util_show_buffer (const unsigned char *buffer, +size_t buffer_size,const char *string); +#endif /* TPM_TPM_UTIL_H */
hw/tpm/trace-events +1 -1
@@ -14,6 +14,7 @@ tpm_util_get_buffer_size_len(uint32_t len, size_t expected) "tpm_resp->len = %u, tpm_util_get_buffer_size_hdr_len2(uint32_t len, size_t expected) "tpm2_resp->hdr.len = %u, expected = %zu" tpm_util_get_buffer_size_len2(uint32_t len, size_t expected) "tpm2_resp->len = %u, expected = %zu" tpm_util_get_buffer_size(size_t len) "buffersize of device: %zu" +tpm_util_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" # tpm_emulator.c tpm_emulator_set_locality(uint8_t locty) "setting locality to %d"
@@ -36,7 +37,6 @@ tpm_emulator_pre_save(void) "" tpm_emulator_inst_init(void) "" # tpm_tis.c -tpm_tis_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\nbuf: %s" tpm_tis_raise_irq(uint32_t irqmask) "Raising IRQ for flag 0x%08x" tpm_tis_new_active_locality(uint8_t locty) "Active locality is now %d" tpm_tis_abort(uint8_t locty) "New active locality is %d"
Signature · 1 line
2.24.1
PATCH v8 2/6 spapr: Implement get_dt_compatible() callback
In reply to Stefan BergerFrom: Stefan Berger <[email protected]>
For devices that cannot be statically initialized, implement a get_dt_compatible() callback that allows us to ask the device for the 'compatible' value.
--- hw/ppc/spapr_vio.c | 11 +++++++++-- include/hw/ppc/spapr_vio.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)
hw/ppc/spapr_vio.c +9 -2
@@ -87,6 +87,7 @@ static int vio_make_devnode(SpaprVioDevice *dev,SpaprVioDeviceClass *pc =VIO_SPAPR_DEVICE_GET_CLASS (dev);int vdevice_off, node_off, ret;char *dt_name; +const char *dt_compatible; vdevice_off =fdt_path_offset (fdt,"/vdevice" );if (vdevice_off <0 ) {
@@ -113,9 +114,15 @@ static int vio_make_devnode(SpaprVioDevice *dev, } } -if (pc->dt_compatible) { +if (pc->get_dt_compatible) { + dt_compatible = pc->get_dt_compatible (dev); + }else { + dt_compatible = pc->dt_compatible; + } + +if (dt_compatible) { ret =fdt_setprop_string (fdt, node_off,"compatible" , - pc->dt_compatible); + dt_compatible);if (ret <0 ) {return ret; }
include/hw/ppc/spapr_vio.h +1 -0
@@ -58,6 +58,7 @@ typedef struct SpaprVioDeviceClass {void (*realize)(SpaprVioDevice *dev,Error **errp);void (*reset)(SpaprVioDevice *dev);int (*devnode)(SpaprVioDevice *dev,void *fdt,int node_off); +const char *(*get_dt_compatible)(SpaprVioDevice *dev); } SpaprVioDeviceClass;struct SpaprVioDevice {
Signature · 1 line
2.24.1
Re: [PATCH v8 2/6] spapr: Implement get_dt_compatible() callback
Quoted 8 lines · Stefan Berger
From: Stefan Berger <[email protected]>
For devices that cannot be statically initialized, implement a
get_dt_compatible()callback that allows us to ask the device for the 'compatible' value.Signed-off-by Stefan Berger <[email protected]>
Quoted 51 lines
--- hw/ppc/spapr_vio.c | 11 +++++++++-- include/hw/ppc/spapr_vio.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/ppc/spapr_vio.c +9
-2@@ -87,6 +87,7 @@ static int vio_make_devnode(SpaprVioDevice *dev,SpaprVioDeviceClass *pc =VIO_SPAPR_DEVICE_GET_CLASS (dev);int vdevice_off, node_off, ret;char *dt_name; +const char *dt_compatible; vdevice_off =fdt_path_offset (fdt,"/vdevice" );if (vdevice_off <0 ) {@@ -113,9 +114,15 @@ static int vio_make_devnode(SpaprVioDevice *dev, } } -if (pc->dt_compatible) { +if (pc->get_dt_compatible) { + dt_compatible = pc->get_dt_compatible (dev); + }else { + dt_compatible = pc->dt_compatible; + } + +if (dt_compatible) { ret =fdt_setprop_string (fdt, node_off,"compatible" , - pc->dt_compatible); + dt_compatible);if (ret <0 ) {return ret; }include/hw/ppc/spapr_vio.h +1
-1@@ -58,6 +58,7 @@ typedef struct SpaprVioDeviceClass {void (*realize)(SpaprVioDevice *dev,Error **errp);void (*reset)(SpaprVioDevice *dev);int (*devnode)(SpaprVioDevice *dev,void *fdt,int node_off); +const char *(*get_dt_compatible)(SpaprVioDevice *dev); } SpaprVioDeviceClass;struct SpaprVioDevice { --2.24.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH v8 2/6] spapr: Implement get_dt_compatible() callback
In reply to Stefan BergerQuoted 7 lines · Stefan Berger
From: Stefan Berger <[email protected]>
For devices that cannot be statically initialized, implement a
get_dt_compatible()callback that allows us to ask the device for the 'compatible' value.Signed-off-by Stefan Berger <[email protected]>
Quoted 47 lines
--- hw/ppc/spapr_vio.c | 11 +++++++++-- include/hw/ppc/spapr_vio.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)hw/ppc/spapr_vio.c +9
-2@@ -87,6 +87,7 @@ static int vio_make_devnode(SpaprVioDevice *dev,SpaprVioDeviceClass *pc =VIO_SPAPR_DEVICE_GET_CLASS (dev);int vdevice_off, node_off, ret;char *dt_name; +const char *dt_compatible; vdevice_off =fdt_path_offset (fdt,"/vdevice" );if (vdevice_off <0 ) {@@ -113,9 +114,15 @@ static int vio_make_devnode(SpaprVioDevice *dev, } } -if (pc->dt_compatible) { +if (pc->get_dt_compatible) { + dt_compatible = pc->get_dt_compatible (dev); + }else { + dt_compatible = pc->dt_compatible; + } + +if (dt_compatible) { ret =fdt_setprop_string (fdt, node_off,"compatible" , - pc->dt_compatible); + dt_compatible);if (ret <0 ) {return ret; }include/hw/ppc/spapr_vio.h +1
-0@@ -58,6 +58,7 @@ typedef struct SpaprVioDeviceClass {void (*realize)(SpaprVioDevice *dev,Error **errp);void (*reset)(SpaprVioDevice *dev);int (*devnode)(SpaprVioDevice *dev,void *fdt,int node_off); +const char *(*get_dt_compatible)(SpaprVioDevice *dev); } SpaprVioDeviceClass;struct SpaprVioDevice {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v8 3/6 tpm_spapr: Support TPM for ppc64 using CRQ based interface
In reply to Stefan BergerFrom: Stefan Berger <[email protected]>
Implement support for TPM on ppc64 by implementing the vTPM CRQ interface as a frontend. It can use the tpm_emulator driver backend with the external swtpm.
The Linux vTPM driver for ppc64 works with this emulation.
This TPM emulator also handles the TPM 2 case.
--- docs/specs/tpm.txt | 20 ++- hw/tpm/Kconfig | 6 + hw/tpm/Makefile.objs | 1 + hw/tpm/tpm_spapr.c | 378 +++++++++++++++++++++++++++++++++++++++++++ hw/tpm/trace-events | 12 ++ include/sysemu/tpm.h | 3 + qapi/tpm.json | 6 +- 7 files changed, 422 insertions(+), 4 deletions(-) create mode 100644 hw/tpm/tpm_spapr.c
docs/specs/tpm.txt +19 -1
@@ -34,6 +34,12 @@ The CRB interface makes a memory mapped IO region in the area 0xfed40000 - QEMU files related to TPM CRB interface: - hw/tpm/tpm_crb.c + +pSeries (ppc64) machines offer a tpm-spapr device model. + +QEMU files related to the SPAPR interface: + - hw/tpm/tpm_spapr.c + = fw_cfg interface = The bios/firmware may read the "etc/tpm/config" fw_cfg entry for
@@ -281,7 +287,7 @@ swtpm socket --tpmstate dir=/tmp/mytpm1 \ --log level=20 Command line to start QEMU with the TPM emulator device communicating with -the swtpm: +the swtpm (x86): qemu-system-x86_64 -display sdl -accel kvm \ -m 1024 -boot d -bios bios-256k.bin -boot menu=on \
@@ -289,6 +295,18 @@ qemu-system-x86_64 -display sdl -accel kvm \ -tpmdev emulator,id=tpm0,chardev=chrtpm \ -device tpm-tis,tpmdev=tpm0 test.img +In case a pSeries machine is emulated, use the following command line: + +qemu-system-ppc64 -display sdl -machine pseries,accel=kvm \ + -m 1024 -bios slof.bin -boot menu=on \ + -nodefaults -device VGA -device pci-ohci -device usb-kbd \ + -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-spapr,tpmdev=tpm0 \ + -device spapr-vscsi,id=scsi0,reg=0x00002000 \ + -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 SeaBIOS is used as firmware, it should show the TPM menu item after entering the menu with 'ESC'.
hw/tpm/Kconfig +6 -0
@@ -22,3 +22,9 @@ config TPM_EMULATOR bool default y depends on TPMDEV + +config TPM_SPAPR + bool + default n + select TPMDEV + depends on PSERIES
hw/tpm/Makefile.objs +1 -0
@@ -4,3 +4,4 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.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 +obj-$(CONFIG_TPM_SPAPR) += tpm_spapr.o
hw/tpm/tpm_spapr.c new file +378 -0
378 lines not on this page · raw message
hw/tpm/trace-events +12 -0
@@ -55,3 +55,15 @@ tpm_tis_pre_save(uint8_t locty, uint32_t rw_offset) "locty: %d, rw_offset = %u" # tpm_ppi.c tpm_ppi_memset(uint8_t *ptr, size_t size) "memset: %p %zu" + +# hw/tpm/tpm_spapr.c +tpm_spapr_show_buffer(const char *direction, size_t len, const char *buf) "direction: %s len: %zu\n%s" +tpm_spapr_do_crq(uint8_t raw1, uint8_t raw2) "1st 2 bytes in CRQ: 0x%02x 0x%02x" +tpm_spapr_do_crq_crq_result(void) "SPAPR_VTPM_INIT_CRQ_RESULT" +tpm_spapr_do_crq_crq_complete_result(void) "SPAPR_VTPM_INIT_CRQ_COMP_RESULT" +tpm_spapr_do_crq_tpm_command(void) "got TPM command payload" +tpm_spapr_do_crq_tpm_get_rtce_buffer_size(size_t buffersize) "response: buffer size is %zu" +tpm_spapr_do_crq_get_version(uint32_t version) "response: version %u" +tpm_spapr_do_crq_prepare_to_suspend(void) "response: preparing to suspend" +tpm_spapr_do_crq_unknown_msg_type(uint8_t type) "Unknown message type 0x%02x" +tpm_spapr_do_crq_unknown_crq(uint8_t raw1, uint8_t raw2) "unknown CRQ 0x%02x 0x%02x ..."
include/sysemu/tpm.h +3 -0
@@ -45,11 +45,14 @@ typedef struct TPMIfClass {#define TYPE_TPM_TIS "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_CRB (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB) +#define TPM_IS_SPAPR (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)/* returns NULL unless there is exactly one TPM device */ static inline TPMIf *tpm_find (void )
qapi/tpm.json +3 -3
@@ -12,11 +12,11 @@ # # @tpm-tis: TPM TIS model # @tpm-crb: TPM CRB model (since 2.12) +# @tpm-spapr: TPM SPAPR model (since 5.0) # # Since: 1.5 ## -{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb' ] } - +{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'tpm-crb', 'tpm-spapr' ] } ## # @query-tpm-models: #
@@ -29,7 +29,7 @@ # Example: # # -> { "execute": "query-tpm-models" } -# <- { "return": [ "tpm-tis", "tpm-crb" ] } +# <- { "return": [ "tpm-tis", "tpm-crb", "tpm-spapr" ] } # ## { 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
Signature · 1 line
2.24.1
PATCH v8 4/6 tpm_spapr: Support suspend and resume
In reply to Stefan BergerFrom: Stefan Berger <[email protected]>
Extend the tpm_spapr frontend with VM suspend and resume support.
--- hw/tpm/tpm_spapr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- hw/tpm/trace-events | 2 ++ 2 files changed, 68 insertions(+), 1 deletion(-)
hw/tpm/tpm_spapr.c +66 -1
@@ -76,6 +76,9 @@ typedef struct {unsigned char buffer[TPM_SPAPR_BUFFER_MAX ]; +uint32_t numbytes;/* number of bytes in suspend_buffer */ +unsigned char *suspend_buffer; +TPMBackendCmd cmd;TPMBackend *be_driver;
@@ -240,6 +243,13 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)/* a max. of be_buffer_size bytes can be transported */ len =MIN (tpm_cmd_get_size (s->buffer), s->be_buffer_size); + +if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { +/* defer delivery of response until .post_load */ + s->numbytes = len; +return ; + } + rc =spapr_vio_dma_write (&s->vdev,be32_to_cpu (crq->data), s->buffer, len);
@@ -288,11 +298,13 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)SpaprTpmState *s =VIO_SPAPR_VTPM (dev); s->state =SPAPR_VTPM_STATE_NONE ; + s->numbytes =0 ; s->be_tpm_version =tpm_backend_get_tpm_version (s->be_driver); s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_SPAPR_BUFFER_MAX ); + s->suspend_buffer =g_realloc (s->suspend_buffer, s->be_buffer_size);tpm_backend_reset (s->be_driver);tpm_spapr_do_startup_tpm (s, s->be_buffer_size);
@@ -309,9 +321,62 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)return tpm_backend_get_tpm_version (s->be_driver); } +/* persistent state handling */ + +static int tpm_spapr_pre_save (void *opaque) +{ +SpaprTpmState *s = opaque; + +tpm_backend_finish_sync (s->be_driver); + +if (s->numbytes) { +memcpy (s->suspend_buffer, s->buffer, s->numbytes); + } + +trace_tpm_spapr_pre_save (s->numbytes); +/* +* we cannot deliver the results to the VM since DMA would touch VM memory +*/ + +return 0 ; +} + +static int tpm_spapr_post_load (void *opaque,int version_id) +{ +SpaprTpmState *s = opaque; + +if (s->numbytes) { +trace_tpm_spapr_post_load (); + +memcpy (s->buffer, s->suspend_buffer, +MIN (s->numbytes, s->be_buffer_size)); +/* deliver the results to the VM via DMA */ +tpm_spapr_request_completed (TPM_IF (s),0 ); + s->numbytes =0 ; + } + +return 0 ; +} +static const VMStateDescription vmstate_spapr_vtpm = { .name ="tpm-spapr" , - .unmigratable =1 , + .version_id =1 , + .minimum_version_id =0 , + .minimum_version_id_old =0 , + .pre_save = tpm_spapr_pre_save, + .post_load = tpm_spapr_post_load, + .fields = (VMStateField []) { +VMSTATE_SPAPR_VIO (vdev, SpaprTpmState), + +VMSTATE_UINT8 (state, SpaprTpmState), +VMSTATE_UINT32 (numbytes, SpaprTpmState), +VMSTATE_VBUFFER_ALLOC_UINT32 (suspend_buffer, + SpaprTpmState,0 ,NULL , + numbytes), +/* remember DMA address */ +VMSTATE_UINT32 (crq.data, SpaprTpmState), +VMSTATE_END_OF_LIST (), + } };static Property tpm_spapr_properties[] = {
hw/tpm/trace-events +2 -0
@@ -67,3 +67,5 @@ tpm_spapr_do_crq_get_version(uint32_t version) "response: version %u" tpm_spapr_do_crq_prepare_to_suspend(void) "response: preparing to suspend" tpm_spapr_do_crq_unknown_msg_type(uint8_t type) "Unknown message type 0x%02x" tpm_spapr_do_crq_unknown_crq(uint8_t raw1, uint8_t raw2) "unknown CRQ 0x%02x 0x%02x ..." +tpm_spapr_pre_save(uint32_t v) "Number of TPM response bytes to deliver after resume: %u" +tpm_spapr_post_load(void) "Delivering TPM response after resume"
Signature · 1 line
2.24.1
Re: [PATCH v8 4/6] tpm_spapr: Support suspend and resume
Hi
Quoted 16 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Extend the
tpm_spaprfrontend with VM suspend and resume support.Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_spapr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- hw/tpm/trace-events | 2 ++ 2 files changed, 68 insertions(+), 1 deletion(-)hw/tpm/tpm_spapr.c +0
-0
hw/tpm/tpm_spapr.c typedef struct { · line 80
Quoted 5 lines
hw/tpm/tpm_spapr.c +2
-0@@ -76,6 +76,9 @@ typedef struct {unsigned char buffer[TPM_SPAPR_BUFFER_MAX ]; +uint32_t numbytes;/* number of bytes in suspend_buffer */ +unsigned char *suspend_buffer;
Why do you need a copy suspend_buffer? Why not use and save buffer[] directly?
Also numbytes wouldn't be necessary, you would just need a bool flag to say if the request_completed is pending.
Quoted 69 lines
hw/tpm/tpm_spapr.c +43
-0+TPMBackendCmd cmd;TPMBackend *be_driver;@@ -240,6 +243,13 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)/* a max. of be_buffer_size bytes can be transported */ len =MIN (tpm_cmd_get_size (s->buffer), s->be_buffer_size); + +if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { +/* defer delivery of response until .post_load */ + s->numbytes = len; +return ; + } + rc =spapr_vio_dma_write (&s->vdev,be32_to_cpu (crq->data), s->buffer, len);@@ -288,11 +298,13 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)SpaprTpmState *s =VIO_SPAPR_VTPM (dev); s->state =SPAPR_VTPM_STATE_NONE ; + s->numbytes =0 ; s->be_tpm_version =tpm_backend_get_tpm_version (s->be_driver); s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_SPAPR_BUFFER_MAX ); + s->suspend_buffer =g_realloc (s->suspend_buffer, s->be_buffer_size);tpm_backend_reset (s->be_driver);tpm_spapr_do_startup_tpm (s, s->be_buffer_size);@@ -309,9 +321,62 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)return tpm_backend_get_tpm_version (s->be_driver); } +/* persistent state handling */ + +static int tpm_spapr_pre_save (void *opaque) +{ +SpaprTpmState *s = opaque; + +tpm_backend_finish_sync (s->be_driver); + +if (s->numbytes) { +memcpy (s->suspend_buffer, s->buffer, s->numbytes); + } + +trace_tpm_spapr_pre_save (s->numbytes); +/* +* we cannot deliver the results to the VM since DMA would touch VM memory +*/ + +return 0 ; +} + +static int tpm_spapr_post_load (void *opaque,int version_id) +{ +SpaprTpmState *s = opaque; + +if (s->numbytes) { +trace_tpm_spapr_post_load (); + +memcpy (s->buffer, s->suspend_buffer, +MIN (s->numbytes, s->be_buffer_size)); +/* deliver the results to the VM via DMA */ +tpm_spapr_request_completed (TPM_IF (s),0 ); + s->numbytes =0 ; + }
hw/tpm/tpm_spapr.c static enum TPMVersion tpm_spapr_get_version(TPMIf *ti) · line 365
Quoted 10 lines
hw/tpm/tpm_spapr.c +7
-1+ +return 0 ; +} +static const VMStateDescription vmstate_spapr_vtpm = { .name ="tpm-spapr" , - .unmigratable =1 , + .version_id =1 , + .minimum_version_id =0 , + .minimum_version_id_old =0 ,
Yyou should leave all the fields to 0 (there is no version 0 so far). Thus no need to have them set explicitly either.
Quoted 31 lines
hw/tpm/tpm_spapr.c +14
-0+ .pre_save = tpm_spapr_pre_save, + .post_load = tpm_spapr_post_load, + .fields = (VMStateField []) { +VMSTATE_SPAPR_VIO (vdev, SpaprTpmState), + +VMSTATE_UINT8 (state, SpaprTpmState), +VMSTATE_UINT32 (numbytes, SpaprTpmState), +VMSTATE_VBUFFER_ALLOC_UINT32 (suspend_buffer, + SpaprTpmState,0 ,NULL , + numbytes), +/* remember DMA address */ +VMSTATE_UINT32 (crq.data, SpaprTpmState), +VMSTATE_END_OF_LIST (), + } };static Property tpm_spapr_properties[] = {hw/tpm/trace-events +2
-1@@ -67,3 +67,5 @@ tpm_spapr_do_crq_get_version(uint32_t version) "response: version %u" tpm_spapr_do_crq_prepare_to_suspend(void) "response: preparing to suspend" tpm_spapr_do_crq_unknown_msg_type(uint8_t type) "Unknown message type 0x%02x" tpm_spapr_do_crq_unknown_crq(uint8_t raw1, uint8_t raw2) "unknown CRQ 0x%02x 0x%02x ..." +tpm_spapr_pre_save(uint32_t v) "Number of TPM response bytes to deliver after resume: %u" +tpm_spapr_post_load(void) "Delivering TPM response after resume" --2.24.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH v8 4/6] tpm_spapr: Support suspend and resume
Quoted 19 lines · Marc-André Lureau
Hi
Quoted 16 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Extend the
tpm_spaprfrontend with VM suspend and resume support.Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_spapr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- hw/tpm/trace-events | 2 ++ 2 files changed, 68 insertions(+), 1 deletion(-)hw/tpm/tpm_spapr.c +0
-0@@ -76,6 +76,9 @@ typedef struct {
Quoted 5 lines
hw/tpm/tpm_spapr.c typedef struct { · line 80
Quoted 4 lines
hw/tpm/tpm_spapr.c +2
-0unsigned char buffer[TPM_SPAPR_BUFFER_MAX ]; +uint32_t numbytes;/* number of bytes in suspend_buffer */ +unsigned char *suspend_buffer;Why do you need a copy
suspend_buffer? Why not use and save buffer[] directly?
This addresses David's comment:
"Transferring the whole 4kiB buffer unconditionally when it mostly won't have anything useful in it doesn't seem like a great idea."
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg02601.html
Quoted 78 lines
Also numbytes wouldn't be necessary, you would just need a bool flag to say if the
request_completedis pending.Quoted 74 lines
hw/tpm/tpm_spapr.c +47
-0+TPMBackendCmd cmd;TPMBackend *be_driver;@@ -240,6 +243,13 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)/* a max. of be_buffer_size bytes can be transported */ len =MIN (tpm_cmd_get_size (s->buffer), s->be_buffer_size); + +if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { +/* defer delivery of response until .post_load */ + s->numbytes = len; +return ; + } + rc =spapr_vio_dma_write (&s->vdev,be32_to_cpu (crq->data), s->buffer, len);@@ -288,11 +298,13 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)SpaprTpmState *s =VIO_SPAPR_VTPM (dev); s->state =SPAPR_VTPM_STATE_NONE ; + s->numbytes =0 ; s->be_tpm_version =tpm_backend_get_tpm_version (s->be_driver); s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_SPAPR_BUFFER_MAX ); + s->suspend_buffer =g_realloc (s->suspend_buffer, s->be_buffer_size);tpm_backend_reset (s->be_driver);tpm_spapr_do_startup_tpm (s, s->be_buffer_size);@@ -309,9 +321,62 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)return tpm_backend_get_tpm_version (s->be_driver); } +/* persistent state handling */ + +static int tpm_spapr_pre_save (void *opaque) +{ +SpaprTpmState *s = opaque; + +tpm_backend_finish_sync (s->be_driver); + +if (s->numbytes) { +memcpy (s->suspend_buffer, s->buffer, s->numbytes); + } + +trace_tpm_spapr_pre_save (s->numbytes); +/* +* we cannot deliver the results to the VM since DMA would touch VM memory +*/ + +return 0 ; +} + +static int tpm_spapr_post_load (void *opaque,int version_id) +{ +SpaprTpmState *s = opaque; + +if (s->numbytes) { +trace_tpm_spapr_post_load (); + +memcpy (s->buffer, s->suspend_buffer, +MIN (s->numbytes, s->be_buffer_size)); +/* deliver the results to the VM via DMA */ +tpm_spapr_request_completed (TPM_IF (s),0 ); + s->numbytes =0 ; + } + +return 0 ; +} +static const VMStateDescription vmstate_spapr_vtpm = {
Quoted 8 lines
hw/tpm/tpm_spapr.c static enum TPMVersion tpm_spapr_get_version(TPMIf *ti) · line 365
Quoted 5 lines
hw/tpm/tpm_spapr.c +3
-1.name = "tpm-spapr", - .unmigratable = 1, + .version_id = 1, + .minimum_version_id = 0, + .minimum_version_id_old = 0,Yyou should leave all the fields to 0 (there is no version 0 so far). Thus no need to have them set explicitly either.
Ok, I will fix.
Thanks.
Re: [PATCH v8 4/6] tpm_spapr: Support suspend and resume
Quoted 28 lines · Stefan Berger
Quoted 19 lines · Marc-André Lureau
Hi
Quoted 16 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Extend the
tpm_spaprfrontend with VM suspend and resume support.Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_spapr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- hw/tpm/trace-events | 2 ++ 2 files changed, 68 insertions(+), 1 deletion(-)hw/tpm/tpm_spapr.c +0
-0@@ -76,6 +76,9 @@ typedef struct {Quoted 5 lines
hw/tpm/tpm_spapr.c typedef struct { · line 80
Quoted 4 lines
hw/tpm/tpm_spapr.c +2
-0unsigned char buffer[TPM_SPAPR_BUFFER_MAX ]; +uint32_t numbytes;/* number of bytes in suspend_buffer */ +unsigned char *suspend_buffer;Why do you need a copy
suspend_buffer? Why not use and save buffer[] directly?
Quoted 6 lines
This addresses David's comment:
"Transferring the whole 4kiB buffer unconditionally when it mostly won't have anything useful in it doesn't seem like a great idea."
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg02601.html
Oh ok.. (well really I don't think 4k (usually compressed) will really matter much in multi-gigabytes streams ;)
Quoted 93 lines
Quoted 80 lines
Also numbytes wouldn't be necessary, you would just need a bool flag to say if the
request_completedis pending.Quoted 74 lines
hw/tpm/tpm_spapr.c +47
-0+TPMBackendCmd cmd;TPMBackend *be_driver;@@ -240,6 +243,13 @@ static void tpm_spapr_request_completed(TPMIf *ti, int ret)/* a max. of be_buffer_size bytes can be transported */ len =MIN (tpm_cmd_get_size (s->buffer), s->be_buffer_size); + +if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { +/* defer delivery of response until .post_load */ + s->numbytes = len; +return ; + } + rc =spapr_vio_dma_write (&s->vdev,be32_to_cpu (crq->data), s->buffer, len);@@ -288,11 +298,13 @@ static void tpm_spapr_reset(SpaprVioDevice *dev)SpaprTpmState *s =VIO_SPAPR_VTPM (dev); s->state =SPAPR_VTPM_STATE_NONE ; + s->numbytes =0 ; s->be_tpm_version =tpm_backend_get_tpm_version (s->be_driver); s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_SPAPR_BUFFER_MAX ); + s->suspend_buffer =g_realloc (s->suspend_buffer, s->be_buffer_size);tpm_backend_reset (s->be_driver);tpm_spapr_do_startup_tpm (s, s->be_buffer_size);@@ -309,9 +321,62 @@ static enum TPMVersion tpm_spapr_get_version(TPMIf *ti)return tpm_backend_get_tpm_version (s->be_driver); } +/* persistent state handling */ + +static int tpm_spapr_pre_save (void *opaque) +{ +SpaprTpmState *s = opaque; + +tpm_backend_finish_sync (s->be_driver); + +if (s->numbytes) { +memcpy (s->suspend_buffer, s->buffer, s->numbytes); + } + +trace_tpm_spapr_pre_save (s->numbytes); +/* +* we cannot deliver the results to the VM since DMA would touch VM memory +*/ + +return 0 ; +} + +static int tpm_spapr_post_load (void *opaque,int version_id) +{ +SpaprTpmState *s = opaque; + +if (s->numbytes) { +trace_tpm_spapr_post_load (); + +memcpy (s->buffer, s->suspend_buffer, +MIN (s->numbytes, s->be_buffer_size)); +/* deliver the results to the VM via DMA */ +tpm_spapr_request_completed (TPM_IF (s),0 ); + s->numbytes =0 ; + } + +return 0 ; +} +static const VMStateDescription vmstate_spapr_vtpm = {Quoted 8 lines
hw/tpm/tpm_spapr.c static enum TPMVersion tpm_spapr_get_version(TPMIf *ti) · line 365
Quoted 5 lines
hw/tpm/tpm_spapr.c +3
-1.name = "tpm-spapr", - .unmigratable = 1, + .version_id = 1, + .minimum_version_id = 0, + .minimum_version_id_old = 0,Yyou should leave all the fields to 0 (there is no version 0 so far). Thus no need to have them set explicitly either.
Ok, I will fix.
Thanks.
Signature · 1 line
Marc-André Lureau
Re: [PATCH v8 4/6] tpm_spapr: Support suspend and resume
Quoted 31 lines · Marc-André Lureau
Quoted 30 lines · Stefan Berger
Quoted 19 lines · Marc-André Lureau
Hi
Quoted 16 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Extend the
tpm_spaprfrontend with VM suspend and resume support.Signed-off-by Stefan Berger <[email protected]>--- hw/tpm/tpm_spapr.c | 67 ++++++++++++++++++++++++++++++++++++++++++++- hw/tpm/trace-events | 2 ++ 2 files changed, 68 insertions(+), 1 deletion(-)hw/tpm/tpm_spapr.c +0
-0@@ -76,6 +76,9 @@ typedef struct {Quoted 5 lines
hw/tpm/tpm_spapr.c typedef struct { · line 80
Quoted 4 lines
hw/tpm/tpm_spapr.c +2
-0unsigned char buffer[TPM_SPAPR_BUFFER_MAX ]; +uint32_t numbytes;/* number of bytes in suspend_buffer */ +unsigned char *suspend_buffer;Why do you need a copy
suspend_buffer? Why not use and save buffer[] directly?This addresses David's comment:
Quoted 7 lines
Quoted 4 lines
"Transferring the whole 4kiB buffer unconditionally when it mostly won't have anything useful in it doesn't seem like a great idea."
https://lists.nongnu.org/archive/html/qemu-devel/2019-12/msg02601.html
Oh ok.. (well really I don't think 4k (usually compressed) will really matter much in multi-gigabytes streams ;)
Probably not - though it is in the downtime portion of the stream.
But more to the point you can still make the size / whether you send conditional on numbytes without having a whole separate buffer for it.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v8 5/6 hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config
In reply to Stefan BergerFrom: Stefan Berger <[email protected]>
--- hw/ppc/Kconfig | 1 + 1 file changed, 1 insertion(+)
hw/ppc/Kconfig +1 -0
@@ -10,6 +10,7 @@ config PSERIES select XICS_SPAPR select XIVE_SPAPR select MSI_NONBROKEN + select TPM_SPAPR config SPAPR_RNG bool
Signature · 1 line
2.24.1
Re: [PATCH v8 5/6] hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config
Quoted 4 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Signed-off-by Stefan Berger <[email protected]>
(trivial conflict on master)
Quoted 20 lines
--- hw/ppc/Kconfig | 1 + 1 file changed, 1 insertion(+)hw/ppc/Kconfig +1
-1@@ -10,6 +10,7 @@ config PSERIES select XICS_SPAPR select XIVE_SPAPR select MSI_NONBROKEN + select TPM_SPAPR config SPAPR_RNG bool --2.24.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH v8 5/6] hw/ppc/Kconfig: Enable TPM_SPAPR as part of PSERIES config
In reply to Stefan BergerQuoted 3 lines · Stefan Berger
From: Stefan Berger <[email protected]>
Signed-off-by Stefan Berger <[email protected]>
Quoted 16 lines
--- hw/ppc/Kconfig | 1 + 1 file changed, 1 insertion(+)hw/ppc/Kconfig +1
-0@@ -10,6 +10,7 @@ config PSERIES select XICS_SPAPR select XIVE_SPAPR select MSI_NONBROKEN + select TPM_SPAPR config SPAPR_RNG bool
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v8 6/6 docs/specs/tpm: reST-ify TPM documentation
In reply to Stefan BergerFrom: Marc-André Lureau <[email protected]>
--- docs/specs/index.rst | 1 + docs/specs/tpm.rst | 503 +++++++++++++++++++++++++++++++++++++++++++ docs/specs/tpm.txt | 445 -------------------------------------- 3 files changed, 504 insertions(+), 445 deletions(-) create mode 100644 docs/specs/tpm.rst delete mode 100644 docs/specs/tpm.txt
docs/specs/index.rst +1 -0
@@ -13,3 +13,4 @@ Contents: ppc-xive ppc-spapr-xive acpi_hw_reduced_hotplug + tpm
docs/specs/tpm.rst new file +503 -0
503 lines not on this page · raw message
docs/specs/tpm.txt deleted +0 -445
445 lines not on this page · raw message
Signature · 1 line
2.24.1