QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU patch)
PATCH v5 1/6 Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
In reply to Quan Xu--Changes in v5:
-qapi schema enhancement.
--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)
configure +14 -0
@@ -3010,6 +3010,16 @@ else fi ########################################## +# TPM xenstubdoms is only on x86 Linux + +if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64 && \ + test "$xen" = "yes"; then + tpm_xenstubdoms=$tpm +else + tpm_xenstubdoms=no +fi + +########################################## # attr probe if test "$attr" != "no" ; then
@@ -4432,6 +4442,7 @@ echo "gcov $gcov_tool" echo "gcov enabled $gcov" echo "TPM support $tpm" echo "libssh2 support $libssh2" +echo "TPM xenstubdoms $tpm_xenstubdoms" echo "TPM passthrough $tpm_passthrough" echo "QOM debugging $qom_cast_debug" echo "vhdx $vhdx"
@@ -4919,6 +4930,9 @@ if test "$tpm" = "yes"; then if test "$tpm_passthrough" = "yes"; then echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak fi + if test "$tpm_xenstubdoms" = "yes"; then + echo "CONFIG_TPM_XENSTUBDOMS=y" >> $config_host_mak + fi fi echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
hmp.c +2 -0
@@ -813,6 +813,8 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) tpo->has_cancel_path ?",cancel-path=" :"" , tpo->has_cancel_path ? tpo->cancel_path : "");break ; +case TPM_TYPE_OPTIONS_KIND_XENSTUBDOMS : +break ;case TPM_TYPE_OPTIONS_KIND_MAX :break ; }
qapi-schema.json +15 -2
@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) +# # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:
@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type +# +# Since: 2.4 +## +{ 'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configuration options
@@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union': 'TpmTypeOptions', - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } } +## ## # @TpmInfo:
qemu-options.hx +11 -2
@@ -2539,7 +2539,8 @@ DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \ "-tpmdev passthrough,id=id[,path=path][,cancel-path=path]\n" " use path to provide path to a character device; default is /dev/tpm0\n" " use cancel-path to provide path to TPM's cancel sysfs entry; if\n" - " not provided it will be searched for in /sys/class/misc/tpm?/device\n", + " not provided it will be searched for in /sys/class/misc/tpm?/device\n" + "-tpmdev xenstubdoms,id=id\n", QEMU_ARCH_ALL) STEXI
@@ -2549,7 +2550,8 @@ The general form of a TPM device option is: @item -tpmdev @var{backend} ,id=@var{id} [,@var{options}] @findex -tpmdev Backend type must be: -@option{passthrough}. +@option{passthrough}, or +@option{xenstubdoms}. The specific backend type will determine the applicable options. The @code{-tpmdev} option creates the TPM backend and requires a
@@ -2599,6 +2601,13 @@ To create a passthrough TPM use the following two options: Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by @code{tpmdev=tpm0} in the device option. +To create a xenstubdoms TPM use the following two options: +@example +-tpmdev xenstubdoms,id=tpm0 -device tpm-tis,tpmdev=tpm0 +@end example +Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by +@code{tpmdev=tpm0} in the device option. + @end table ETEXI
tpm.c +6 -1
@@ -25,7 +25,7 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =#define TPM_MAX_MODELS 1 -#define TPM_MAX_DRIVERS 1 +#define TPM_MAX_DRIVERS 2static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS ] = {NULL ,
@@ -254,6 +254,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) {TPMInfo *res =g_new0 (TPMInfo,1 );TPMPassthroughOptions *tpo; +TPMXenstubdomsOptions *txo; res->id =g_strdup (drv->id); res->model = drv->fe_model;
@@ -273,6 +274,10 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) tpo->has_cancel_path = true; }break ; +case TPM_TYPE_XENSTUBDOMS : + res->options->kind =TPM_TYPE_OPTIONS_KIND_XENSTUBDOMS ; + txo =g_new0 (TPMXenstubdomsOptions,1 ); + res->options->xenstubdoms = txo;case TPM_TYPE_MAX :break ; }
Signature · 1 line
1.8.3.2
PATCH v5 2/6 Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Quan XuThis patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
Call xen_fe_register() function to register XenDevOps, and make sure, XenDevOps's flags is DEVOPS_FLAG_FE, which is flag bit to point out the XenDevOps is Xen frontend.
Create a new file xen_pvdev.c for some common part of xen frontend and backend, such as xendevs queue and xenstore update functions.
--- hw/display/xenfb.c | 4 +- hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 353 ------------------------------- hw/xen/xen_frontend.c | 345 +++++++++++++++++++++++++++++++ hw/xen/xen_pvdev.c | 481 +++++++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 22 +- 6 files changed, 850 insertions(+), 357 deletions(-) create mode 100644 hw/xen/xen_frontend.c create mode 100644 hw/xen/xen_pvdev.c
hw/display/xenfb.c +2 -2
@@ -988,8 +988,8 @@ void xen_init_display(int domid) wait_more: i++;main_loop_wait (true); - xfb =xen_be_find_xendev ("vfb" , domid,0 ); - xin =xen_be_find_xendev ("vkbd" , domid,0 ); + xfb =xen_find_xendev ("vfb" , domid,0 ); + xin =xen_find_xendev ("vkbd" , domid,0 );if (!xfb || !xin) {if (i <256 ) {usleep (10000 );
hw/xen/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ # xen backend driver support -common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o +common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o xen_frontend.o xen_pvdev.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
hw/xen/xen_backend.c +0 -353
382 lines not on this page · raw message
hw/xen/xen_frontend.c new file +345 -0
345 lines not on this page · raw message
hw/xen/xen_pvdev.c new file +481 -0
481 lines not on this page · raw message
include/hw/xen/xen_backend.h +21 -1
@@ -15,6 +15,8 @@ struct XenDevice;#define DEVOPS_FLAG_NEED_GNTDEV 1/* don't expect frontend doing correct state transitions (aka console quirk) */ #define DEVOPS_FLAG_IGNORE_STATE 2 +/*dev is frontend device*/ +#define DEVOPS_FLAG_FE 4struct XenDevOps {size_t size;
@@ -59,6 +61,7 @@ struct XenDevice {extern XenXC xen_xc;extern struct xs_handle *xenstore;extern const char *xen_protocol; +extern int xenstore_dev;/* xenstore helper functions */ int xenstore_write_str (const char *base,const char *node,const char *val);
@@ -77,9 +80,18 @@ int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival);int xenstore_read_uint64 (const char *base,const char *node,uint64_t *uval);int xenstore_read_fe_uint64 (struct XenDevice *xendev,const char *node,uint64_t *uval); +char *xenstore_get_domain_name (uint32_t domid); +const char *xenbus_strstate (enum xenbus_state state); -struct XenDevice *xen_be_find_xendev (const char *type,int dom,int dev); +struct XenDevice *xen_find_xendev (const char *type,int dom,int dev); +struct XenDevice *xen_del_xendev (int dom,int dev); +struct XenDevice *xen_be_get_xendev (const char *type,int dom,int dev, +struct XenDevOps *ops); +struct XenDevice *xen_fe_get_xendev (const char *type,int dom,int dev, +char *backend,struct XenDevOps *ops);void xen_be_check_state (struct XenDevice *xendev); +void xen_be_backend_changed (struct XenDevice *xendev,const char *node); +void xen_be_frontend_changed (struct XenDevice *xendev,const char *node);/* xen backend driver bits */ int xen_be_init (void );
@@ -90,6 +102,13 @@ void xen_be_unbind_evtchn(struct XenDevice *xendev);int xen_be_send_notify (struct XenDevice *xendev); void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...) GCC_FMT_ATTR(3, 4); +void xen_fe_printf(struct XenDevice *xendev, int msg_level, + const char *fmt, ...) + GCC_FMT_ATTR(3, 4); +/* Xen frontend driver */ +int xen_fe_register (const char *type,struct XenDevOps *ops); +int xen_fe_alloc_unbound (struct XenDevice *xendev,int dom,int remote_dom); +int xenbus_switch_state (struct XenDevice *xendev,enum xenbus_state xbus);/* actual backend drivers */ extern struct XenDevOps xen_console_ops;/* xen_console.c */
@@ -97,6 +116,7 @@ extern struct XenDevOps xen_kbdmouse_ops; /* xen_framebuffer.c */extern struct XenDevOps xen_framebuffer_ops;/* xen_framebuffer.c */ extern struct XenDevOps xen_blkdev_ops;/* xen_disk.c */ extern struct XenDevOps xen_netdev_ops;/* xen_nic.c */ +extern struct XenDevOps xen_vtpmdev_ops;/* xen_vtpm_frontend.c*/ void xen_init_display (int domid);
Signature · 1 line
1.8.3.2
PATCH v5 3/6 Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Quan XuThis patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
Call xen_fe_register() function to register XenDevOps, and make sure,
[...]
3 = ""
[...]
device = "" (frontend device, the backend is running in QEMU/.etc)
vkbd = ""
[...]
vif = ""
[...]..
(QEMU) xen_vtpmdev_ops is initialized with the following process:
xen_hvm_init()
[...]
-->xen_fe_register("vtpm", ...)
-->xenstore_fe_scan()
-->xen_fe_try_init(ops)
--> XenDevOps.init()
-->xen_fe_get_xendev()
--> XenDevOps.alloc()
-->xen_fe_check()
-->xen_fe_try_initialise()
--> XenDevOps.initialise()
-->xen_fe_try_connected()
--> XenDevOps.connected()
-->xs_watch()
[...]--Changes in v5:
-Comments enhancement.
-Pass the size of the buff for vtpm_recv()|vtpm_send().
--- hw/tpm/Makefile.objs | 1 + hw/tpm/xen_vtpm_frontend.c | 321 +++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_frontend.c | 20 +++ include/hw/xen/xen_backend.h | 7 + include/hw/xen/xen_common.h | 6 + xen-hvm.c | 5 + 6 files changed, 360 insertions(+) create mode 100644 hw/tpm/xen_vtpm_frontend.c
hw/tpm/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o
hw/tpm/xen_vtpm_frontend.c new file +321 -0
321 lines not on this page · raw message
hw/xen/xen_frontend.c +20 -0
@@ -60,6 +60,26 @@ static void xen_fe_evtchn_event(void *opaque)/* ------------------------------------------------------------- */ +void vtpm_backend_changed (struct XenDevice *xendev,const char *node) +{ +int be_state; + +if (strcmp (node,"state" ) ==0 ) { +xenstore_read_be_int (xendev, node, &be_state); +switch (be_state) { +case XenbusStateConnected: +/* TODO */ +break ; +case XenbusStateClosing: +case XenbusStateClosed: +xenbus_switch_state (xendev, XenbusStateClosing); +break ; +default : +break ; + } + } +} +int xen_fe_alloc_unbound (struct XenDevice *xendev,int dom,int remote_dom) { xendev->local_port = xc_evtchn_bind_unbound_port(xendev->evtchndev,
include/hw/xen/xen_backend.h +7 -0
@@ -110,6 +110,13 @@ int xen_fe_register(const char *type, struct XenDevOps *ops);int xen_fe_alloc_unbound (struct XenDevice *xendev,int dom,int remote_dom);int xenbus_switch_state (struct XenDevice *xendev,enum xenbus_state xbus); +/* Xen vtpm */ +int vtpm_send (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t count); +int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count); +void vtpm_backend_changed (struct XenDevice *xendev,const char *node); +/* actual backend drivers */ extern struct XenDevOps xen_console_ops;/* xen_console.c */ extern struct XenDevOps xen_kbdmouse_ops;/* xen_framebuffer.c */
include/hw/xen/xen_common.h +6 -0
@@ -132,6 +132,12 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,return xc_interface_open (logger, dombuild_logger, open_flags); } +static inline xc_gntshr *xen_xc_gntshr_open (void *logger, +unsigned int open_flags) +{ +return xc_gntshr_open (logger, open_flags); +} +/* FIXME There is now way to have the xen fd */ static inline int xc_fd (xc_interface *xen_xc) {
xen-hvm.c +5 -0
@@ -1308,6 +1308,11 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__);return -1 ; } + +#ifdef CONFIG_TPM_XENSTUBDOMS +xen_fe_register ("vtpm" , &xen_vtpmdev_ops); +#endif +xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);xen_be_register ("qdisk" , &xen_blkdev_ops);
Signature · 1 line
1.8.3.2
PATCH v5 4/6 Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Quan XuThis Patch provides the glue for the TPM_TIS(Qemu frontend) to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends with xen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.
Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by the xen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.
The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line options,
"-tpmdev xenstubdoms,id=xenvtpm0 -device tpm-tis,tpmdev=xenvtpm0"
--Changes in v5:
-comments enhancement.
--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_xenstubdoms.c
hw/tpm/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.o
hw/tpm/tpm_xenstubdoms.c new file +256 -0
256 lines not on this page · raw message
Signature · 1 line
1.8.3.2
PATCH v5 5/6 Qemu-Xen-vTPM: QEMU machine class is initialized before tpm_init()
In reply to Quan Xumake sure QEMU machine class is initialized and QEMU has registered Xen stubdom vTPM driver when call tpm_init()
--- vl.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
vl.c +11 -6
@@ -4131,12 +4131,6 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -#ifdef CONFIG_TPM -if (tpm_init () <0 ) { -exit (1 ); - } -#endif -/* init the bluetooth world */ if (foreach_device_config (DEV_BT , bt_parse))exit (1 );
@@ -4239,6 +4233,17 @@ int main(int argc, char **argv, char **envp)exit (1 ); } +/* +* For compatible with Xen stubdom vTPM driver, make +* sure QEMU machine class is initialized and QEMU has +* registered Xen stubdom vTPM driver. +*/ +#ifdef CONFIG_TPM +if (tpm_init () <0 ) { +exit (1 ); + } +#endif +/* init generic devices */ if (qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func,NULL ,1 ) !=0 )exit (1 );
Signature · 1 line
1.8.3.2
PATCH v5 6/6 Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Quan Xuand whether it completed successfully. Move tpm_passthrough_is_selftest() into tpm_util.c and rename it to tpm_util_is_selftest().
--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_xenstubdoms.c | 36 +++++++++++++++++++++++------ include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 hw/tpm/tpm_util.c
hw/tpm/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.o
hw/tpm/tpm_passthrough.c +1 -12
@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) } } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len,
@@ -136,7 +125,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, tpm_pt->tpm_executing = true; *selftest_done = false; - is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {
hw/tpm/tpm_util.c new file +50 -0
50 lines not on this page · raw message
hw/tpm/tpm_xenstubdoms.c +29 -7
@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsState TPMXenstubdomsState;/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev ==NULL ) {
@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data) locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } -vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, - &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; } static void tpm_xenstubdoms_worker_thread(gpointer data,
@@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, {TPMXenstubdomsThreadParams *thr_parms = user_data;TPMBackendCmd cmd = (TPMBackendCmd )data; +bool selftest_done = false;switch (cmd) {case TPM_BACKEND_CMD_PROCESS_CMD : -tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data, + &selftest_done); thr_parms->recv_data_callback (thr_parms->tpm_state, thr_parms->tpm_state->locty_number, - false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case TPM_BACKEND_CMD_END :
include/sysemu/tpm_backend_int.h +1 -0
@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt,void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len); typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,
Signature · 1 line
1.8.3.2
v5 cover QEMU:Xen stubdom vTPM for HVM virtual machine(QEMU patch)
*INTRODUCTION*
The goal of virtual Trusted Platform Module (vTPM) is to provide a TPM functionality to virtual machines (Fedora, Ubuntu, Redhat, Windows .etc). This allows programs to interact with a TPM in a virtual machine the same way they interact with a TPM on the physical system. Each virtual machine gets its own unique, emulated, software TPM. Each major component of vTPM is implemented as a stubdom, providing secure separation guaranteed by the hypervisor.
The vTPM stubdom is a Xen mini-OS domain that emulates a TPM for the virtual machine to use. It is a small wrapper around the Berlios TPM emulator. TPM commands are passed from mini-os TPM backend driver.
*ARCHITECTURE*
The architecture of stubdom vTPM for HVM virtual machine:
+--------------------+
| Windows/Linux DomU | ...
| | ^ |
| v | |
| Qemu tpm1.2 Tis |
| | ^ |
| v | |
| XenStubdoms backend|
+--------------------+
| ^
v |
+--------------------+
| XenDevOps |
+--------------------+
| ^
v |
+--------------------+
| mini-os/tpmback |
| | ^ |
| v | |
| vtpm-stubdom | ...
| | ^ |
| v | |
| mini-os/tpmfront |
+--------------------+
| ^
v |
+--------------------+
| mini-os/tpmback |
| | ^ |
| v | |
| vtpmmgr-stubdom |
| | ^ |
| v | |
| mini-os/tpm_tis |
+--------------------+
| ^
v |
+--------------------+
| Hardware TPM |
+--------------------+ * Windows/Linux DomU:
The HVM based guest that wants to use a vTPM. There may be more than one of these.
* Qemu tpm1.2 Tis:
Implementation of the tpm1.2 Tis interface for HVM virtual machines. It is Qemu emulation device.
* vTPM xenstubdoms driver:
Qemu vTPM driver. This driver provides vtpm initialization and sending data and commends to a para-virtualized vtpm stubdom.
* XenDevOps:
Register Xen stubdom vTPM frontend driver, and transfer any request/repond between TPM xenstubdoms driver and Xen vTPM stubdom. Facilitate communications between Xen vTPM stubdom and vTPM xenstubdoms driver.
* mini-os/tpmback:
Mini-os TPM backend driver. The Linux frontend driver connects to this backend driver to facilitate communications between the Linux DomU and its vTPM. This driver is also used by vtpmmgr stubdom to communicate with vtpm-stubdom.
* vtpm-stubdom:
A mini-os stub domain that implements a vTPM. There is a one to one mapping between running vtpm-stubdom instances and logical vtpms on the system. The vTPM Platform Configuration Registers (PCRs) are all initialized to zero.
* mini-os/tpmfront:
Mini-os TPM frontend driver. The vTPM mini-os domain vtpm stubdom uses this driver to communicate with vtpmmgr-stubdom. This driver could also be used separately to implement a mini-os domain that wishes to use a vTPM of its own.
* vtpmmgr-stubdom:
A mini-os domain that implements the vTPM manager. There is only one vTPM manager and it should be running during the entire lifetime of the machine. vtpmmgr domain securely stores encryption keys for each of the vtpms and accesses to the hardware TPM to get the root of trust for the entire system.
* mini-os/tpm_tis:
Mini-os TPM version 1.2 TPM Interface Specification (TIS) driver. This driver used by vtpmmgr-stubdom to talk directly to the hardware TPM. Communication is facilitated by mapping hardware memory pages into vtpmmgr stubdom.
* Hardware TPM: The physical TPM 1.2 that is soldered onto the motherboard.
--Changes in v5:
-Add a parameter indicating whether the command that was a selftest
and whether it completed successfully.
-comments enhancement.
-Pass the size of the buff for vtpm_recv()|vtpm_send(). -qapi schema enhancement.
Quan Xu (6):
Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
Qemu-Xen-vTPM: Xen frontend driver infrastructure
Qemu-Xen-vTPM: Xen frontend driver infrastructure
Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
Qemu-Xen-vTPM: QEMU machine class is initialized before tpm_init()
Qemu-Xen-vTPM: Add a parameter indicating whether the command that was
a selftest
configure | 14 ++ hmp.c | 2 + hw/display/xenfb.c | 4 +- hw/tpm/Makefile.objs | 3 +- hw/tpm/tpm_passthrough.c | 13 +- hw/tpm/tpm_util.c | 50 ++++ hw/tpm/tpm_xenstubdoms.c | 278 ++++++++++++++++++++++ hw/tpm/xen_vtpm_frontend.c | 321 ++++++++++++++++++++++++++ hw/xen/Makefile.objs | 2 +- hw/xen/xen_backend.c | 353 ---------------------------- hw/xen/xen_frontend.c | 365 +++++++++++++++++++++++++++++ hw/xen/xen_pvdev.c | 481 +++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 29 ++- include/hw/xen/xen_common.h | 6 + include/sysemu/tpm_backend_int.h | 1 + qapi-schema.json | 17 +- qemu-options.hx | 13 +- tpm.c | 7 +- vl.c | 17 +- xen-hvm.c | 5 + 20 files changed, 1600 insertions(+), 381 deletions(-) create mode 100644 hw/tpm/tpm_util.c create mode 100644 hw/tpm/tpm_xenstubdoms.c create mode 100644 hw/tpm/xen_vtpm_frontend.c create mode 100644 hw/xen/xen_frontend.c create mode 100644 hw/xen/xen_pvdev.c
Signature · 1 line
1.8.3.2
PATCH v5 1/6 Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
--Changes in v5:
-qapi schema enhancement.
--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)
configure +14 -0
@@ -3010,6 +3010,16 @@ else fi ########################################## +# TPM xenstubdoms is only on x86 Linux + +if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64 && \ + test "$xen" = "yes"; then + tpm_xenstubdoms=$tpm +else + tpm_xenstubdoms=no +fi + +########################################## # attr probe if test "$attr" != "no" ; then
@@ -4432,6 +4442,7 @@ echo "gcov $gcov_tool" echo "gcov enabled $gcov" echo "TPM support $tpm" echo "libssh2 support $libssh2" +echo "TPM xenstubdoms $tpm_xenstubdoms" echo "TPM passthrough $tpm_passthrough" echo "QOM debugging $qom_cast_debug" echo "vhdx $vhdx"
@@ -4919,6 +4930,9 @@ if test "$tpm" = "yes"; then if test "$tpm_passthrough" = "yes"; then echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak fi + if test "$tpm_xenstubdoms" = "yes"; then + echo "CONFIG_TPM_XENSTUBDOMS=y" >> $config_host_mak + fi fi echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak
hmp.c +2 -0
@@ -813,6 +813,8 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) tpo->has_cancel_path ?",cancel-path=" :"" , tpo->has_cancel_path ? tpo->cancel_path : "");break ; +case TPM_TYPE_OPTIONS_KIND_XENSTUBDOMS : +break ;case TPM_TYPE_OPTIONS_KIND_MAX :break ; }
qapi-schema.json +15 -2
@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) +# # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:
@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type +# +# Since: 2.4 +## +{ 'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configuration options
@@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union': 'TpmTypeOptions', - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } } +## ## # @TpmInfo:
qemu-options.hx +11 -2
@@ -2539,7 +2539,8 @@ DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \ "-tpmdev passthrough,id=id[,path=path][,cancel-path=path]\n" " use path to provide path to a character device; default is /dev/tpm0\n" " use cancel-path to provide path to TPM's cancel sysfs entry; if\n" - " not provided it will be searched for in /sys/class/misc/tpm?/device\n", + " not provided it will be searched for in /sys/class/misc/tpm?/device\n" + "-tpmdev xenstubdoms,id=id\n", QEMU_ARCH_ALL) STEXI
@@ -2549,7 +2550,8 @@ The general form of a TPM device option is: @item -tpmdev @var{backend} ,id=@var{id} [,@var{options}] @findex -tpmdev Backend type must be: -@option{passthrough}. +@option{passthrough}, or +@option{xenstubdoms}. The specific backend type will determine the applicable options. The @code{-tpmdev} option creates the TPM backend and requires a
@@ -2599,6 +2601,13 @@ To create a passthrough TPM use the following two options: Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by @code{tpmdev=tpm0} in the device option. +To create a xenstubdoms TPM use the following two options: +@example +-tpmdev xenstubdoms,id=tpm0 -device tpm-tis,tpmdev=tpm0 +@end example +Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by +@code{tpmdev=tpm0} in the device option. + @end table ETEXI
tpm.c +6 -1
@@ -25,7 +25,7 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =#define TPM_MAX_MODELS 1 -#define TPM_MAX_DRIVERS 1 +#define TPM_MAX_DRIVERS 2static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS ] = {NULL ,
@@ -254,6 +254,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) {TPMInfo *res =g_new0 (TPMInfo,1 );TPMPassthroughOptions *tpo; +TPMXenstubdomsOptions *txo; res->id =g_strdup (drv->id); res->model = drv->fe_model;
@@ -273,6 +274,10 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) tpo->has_cancel_path = true; }break ; +case TPM_TYPE_XENSTUBDOMS : + res->options->kind =TPM_TYPE_OPTIONS_KIND_XENSTUBDOMS ; + txo =g_new0 (TPMXenstubdomsOptions,1 ); + res->options->xenstubdoms = txo;case TPM_TYPE_MAX :break ; }
Signature · 1 line
1.8.3.2
PATCH v5 3/6 Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Quan XuThis patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
Call xen_fe_register() function to register XenDevOps, and make sure,
[...]
3 = ""
[...]
device = "" (frontend device, the backend is running in QEMU/.etc)
vkbd = ""
[...]
vif = ""
[...]..
(QEMU) xen_vtpmdev_ops is initialized with the following process:
xen_hvm_init()
[...]
-->xen_fe_register("vtpm", ...)
-->xenstore_fe_scan()
-->xen_fe_try_init(ops)
--> XenDevOps.init()
-->xen_fe_get_xendev()
--> XenDevOps.alloc()
-->xen_fe_check()
-->xen_fe_try_initialise()
--> XenDevOps.initialise()
-->xen_fe_try_connected()
--> XenDevOps.connected()
-->xs_watch()
[...]--Changes in v5:
-Comments enhancement.
-Pass the size of the buff for vtpm_recv()|vtpm_send().
--- hw/tpm/Makefile.objs | 1 + hw/tpm/xen_vtpm_frontend.c | 321 +++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_frontend.c | 20 +++ include/hw/xen/xen_backend.h | 7 + include/hw/xen/xen_common.h | 6 + xen-hvm.c | 5 + 6 files changed, 360 insertions(+) create mode 100644 hw/tpm/xen_vtpm_frontend.c
hw/tpm/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o
hw/tpm/xen_vtpm_frontend.c new file +321 -0
321 lines not on this page · raw message
hw/xen/xen_frontend.c +20 -0
@@ -60,6 +60,26 @@ static void xen_fe_evtchn_event(void *opaque)/* ------------------------------------------------------------- */ +void vtpm_backend_changed (struct XenDevice *xendev,const char *node) +{ +int be_state; + +if (strcmp (node,"state" ) ==0 ) { +xenstore_read_be_int (xendev, node, &be_state); +switch (be_state) { +case XenbusStateConnected: +/* TODO */ +break ; +case XenbusStateClosing: +case XenbusStateClosed: +xenbus_switch_state (xendev, XenbusStateClosing); +break ; +default : +break ; + } + } +} +int xen_fe_alloc_unbound (struct XenDevice *xendev,int dom,int remote_dom) { xendev->local_port = xc_evtchn_bind_unbound_port(xendev->evtchndev,
include/hw/xen/xen_backend.h +7 -0
@@ -110,6 +110,13 @@ int xen_fe_register(const char *type, struct XenDevOps *ops);int xen_fe_alloc_unbound (struct XenDevice *xendev,int dom,int remote_dom);int xenbus_switch_state (struct XenDevice *xendev,enum xenbus_state xbus); +/* Xen vtpm */ +int vtpm_send (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t count); +int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count); +void vtpm_backend_changed (struct XenDevice *xendev,const char *node); +/* actual backend drivers */ extern struct XenDevOps xen_console_ops;/* xen_console.c */ extern struct XenDevOps xen_kbdmouse_ops;/* xen_framebuffer.c */
include/hw/xen/xen_common.h +6 -0
@@ -132,6 +132,12 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,return xc_interface_open (logger, dombuild_logger, open_flags); } +static inline xc_gntshr *xen_xc_gntshr_open (void *logger, +unsigned int open_flags) +{ +return xc_gntshr_open (logger, open_flags); +} +/* FIXME There is now way to have the xen fd */ static inline int xc_fd (xc_interface *xen_xc) {
xen-hvm.c +5 -0
@@ -1308,6 +1308,11 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__);return -1 ; } + +#ifdef CONFIG_TPM_XENSTUBDOMS +xen_fe_register ("vtpm" , &xen_vtpmdev_ops); +#endif +xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);xen_be_register ("qdisk" , &xen_blkdev_ops);
Signature · 1 line
1.8.3.2
PATCH v5 4/6 Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Quan XuThis Patch provides the glue for the TPM_TIS(Qemu frontend) to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends with xen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.
Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by the xen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.
The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line options,
"-tpmdev xenstubdoms,id=xenvtpm0 -device tpm-tis,tpmdev=xenvtpm0"
--Changes in v5:
-comments enhancement.
--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 hw/tpm/tpm_xenstubdoms.c
hw/tpm/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.o
hw/tpm/tpm_xenstubdoms.c new file +256 -0
256 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
In reply to Quan XuQuoted 44 lines · Quan Xu
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-qapi schema enhancement.--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)+++
b/qapi-schema.jsonqapi-schema.json +12
-1@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) +# # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type +# +# Since: 2.4 +## +{ 'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configuration options
qapi-schema.json line 3030
Quoted 6 lines
qapi-schema.json +2
-1@@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union': 'TpmTypeOptions', - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } }
Hmm, maybe it is time for me to follow through with my threat of allowing anonymous types in union branches.
Review line 3031
Quoted 1 line
(quoted diff) +1
-0+##
Stray insertion. Please remove it.
Quoted 5 lines
qapi-schema.json +0
-0## # @TpmInfo:qemu-options.hx +0
-0
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Qemu-devel] [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
In reply to Quan XuQuoted 44 lines · Quan Xu
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-qapi schema enhancement.--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)+++
b/qapi-schema.jsonqapi-schema.json +12
-1@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) +# # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type +# +# Since: 2.4 +## +{ 'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configuration options
qapi-schema.json line 3030
Quoted 6 lines
qapi-schema.json +2
-1@@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union': 'TpmTypeOptions', - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } }
Hmm, maybe it is time for me to follow through with my threat of allowing anonymous types in union branches.
Review line 3031
Quoted 1 line
(quoted diff) +1
-0+##
Stray insertion. Please remove it.
Quoted 5 lines
qapi-schema.json +0
-0## # @TpmInfo:qemu-options.hx +0
-0
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Quan XuQuoted 62 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it totpm_util_is_selftest().Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_xenstubdoms.c | 36 +++++++++++++++++++++++------ include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.ohw/tpm/tpm_passthrough.c +1
-12@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) } } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len,@@ -136,7 +125,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, tpm_pt->tpm_executing = true; *selftest_done = false; - is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file +3
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +*
hw/tpm/tpm_util.c line 13
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl
I don't think that for this particular function this Copyright applies.
Quoted 16 lines
hw/tpm/tpm_util.c new file +16
-0+* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <dirent.h>
hw/tpm/tpm_util.c line 39
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+ +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h"
Can you reduce the includes to its minimum?
Quoted 88 lines
hw/tpm/tpm_util.c new file +11
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) +{ +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +29
-7@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsState TPMXenstubdomsState;/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev ==NULL ) {@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data) locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } -vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, - &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; } static void tpm_xenstubdoms_worker_thread(gpointer data,@@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, {TPMXenstubdomsThreadParams *thr_parms = user_data;TPMBackendCmd cmd = (TPMBackendCmd )data; +bool selftest_done = false;switch (cmd) {case TPM_BACKEND_CMD_PROCESS_CMD : -tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data, + &selftest_done); thr_parms->recv_data_callback (thr_parms->tpm_state, thr_parms->tpm_state->locty_number, - false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case TPM_BACKEND_CMD_END :include/sysemu/tpm_backend_int.h +0
-0
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 7 lines
include/sysemu/tpm_backend_int.h +1
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt,void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len); typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing selftest_done parameter. So you should merge this patch into the 3rd patch in this series.
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Quan XuQuoted 62 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it totpm_util_is_selftest().Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_xenstubdoms.c | 36 +++++++++++++++++++++++------ include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.ohw/tpm/tpm_passthrough.c +1
-12@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) } } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len,@@ -136,7 +125,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, tpm_pt->tpm_executing = true; *selftest_done = false; - is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file +3
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +*
hw/tpm/tpm_util.c line 13
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl
I don't think that for this particular function this Copyright applies.
Quoted 16 lines
hw/tpm/tpm_util.c new file +16
-0+* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <dirent.h>
hw/tpm/tpm_util.c line 39
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+ +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h"
Can you reduce the includes to its minimum?
Quoted 88 lines
hw/tpm/tpm_util.c new file +11
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) +{ +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +29
-7@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsState TPMXenstubdomsState;/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev ==NULL ) {@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data) locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } -vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, - &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; } static void tpm_xenstubdoms_worker_thread(gpointer data,@@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, {TPMXenstubdomsThreadParams *thr_parms = user_data;TPMBackendCmd cmd = (TPMBackendCmd )data; +bool selftest_done = false;switch (cmd) {case TPM_BACKEND_CMD_PROCESS_CMD : -tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data, + &selftest_done); thr_parms->recv_data_callback (thr_parms->tpm_state, thr_parms->tpm_state->locty_number, - false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case TPM_BACKEND_CMD_END :include/sysemu/tpm_backend_int.h +0
-0
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 7 lines
include/sysemu/tpm_backend_int.h +1
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt,void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len); typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing selftest_done parameter. So you should merge this patch into the 3rd patch in this series.
Stefan
Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
Quoted 83 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 6 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t*out,
uint32_tout_len)Quoted 6 lines
hw/tpm/tpm_passthrough.c +0
-2} } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 10 lines
hw/tpm/tpm_passthrough.c +0
-8- -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} -static int tpm_passthrough_unix_tx_bufs (TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 20 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +7
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* +* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +*
Quoted 8 lines
hw/tpm/tpm_util.c line 13
Quoted 6 lines
hw/tpm/tpm_util.c new file +6
-0+* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright, if I am not correct.
Quoted 21 lines
Quoted 21 lines
hw/tpm/tpm_util.c new file +20
-0+* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +<http://www.gnu.org/licenses/> */ + +#include <dirent.h> + +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h"
Quoted 8 lines
hw/tpm/tpm_util.c line 39
Quoted 6 lines
hw/tpm/tpm_util.c new file +6
-0+#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" Can you reduce the includes to its minimum?
Agree, I will do it in next version ASAP.
Quoted 103 lines
hw/tpm/tpm_xenstubdoms.c
Quoted 12 lines
hw/tpm/tpm_util.c new file +10
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) { +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +0
-0index
hw/tpm/tpm_xenstubdoms.c typedef struct TPMXenstubdomsState
Quoted 4 lines
3d046fc..992f2ae 100644
hw/tpm/tpm_xenstubdoms.c +0
-0@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsStateTPMXenstubdomsState;
hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const
Quoted 20 lines
hw/tpm/tpm_xenstubdoms.c +7
-1/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev == NULL) {hw/tpm/tpm_xenstubdoms.c +0
-0@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(constTPMLocality
*locty_data)hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data)
Quoted 8 lines
hw/tpm/tpm_xenstubdoms.c +1
-2locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } - vtpm_recv(xendev, locty_data->r_buffer.buffer,
locty_data->r_buffer.size,Quoted 21 lines
hw/tpm/tpm_xenstubdoms.c +17
-2- &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; }hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data)
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c +2
-1static void tpm_xenstubdoms_worker_thread(gpointer data, @@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, { TPMXenstubdomsThreadParams *thr_parms = user_data; TPMBackendCmd cmd = (TPMBackendCmd)data; + bool selftest_done = false; switch (cmd) { case TPM_BACKEND_CMD_PROCESS_CMD: -
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data);Quoted 1 line
+
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data,
Quoted 3 lines
+ &selftest_done); thr_parms->recv_data_callback(thr_parms->tpm_state,
thr_parms->tpm_state->locty_number,include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread
Quoted 11 lines
hw/tpm/tpm_xenstubdoms.c +1
-1- false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case TPM_BACKEND_CMD_END :include/sysemu/tpm_backend_int.h +0
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread*tbt,
Quoted 5 lines
include/sysemu/tpm_backend_int.h +1
-0void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len);
Quoted 7 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 2 lines
include/sysemu/tpm_backend_int.h +0
-0typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.
Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.
Thanks for your review.
-Quan
Quoted 1 line
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Stefan BergerQuoted 83 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 6 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t*out,
uint32_tout_len)Quoted 6 lines
hw/tpm/tpm_passthrough.c +0
-2} } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 10 lines
hw/tpm/tpm_passthrough.c +0
-8- -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} -static int tpm_passthrough_unix_tx_bufs (TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 20 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +7
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* +* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +*
Quoted 8 lines
hw/tpm/tpm_util.c line 13
Quoted 6 lines
hw/tpm/tpm_util.c new file +6
-0+* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright, if I am not correct.
Quoted 21 lines
Quoted 21 lines
hw/tpm/tpm_util.c new file +20
-0+* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +<http://www.gnu.org/licenses/> */ + +#include <dirent.h> + +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h"
Quoted 8 lines
hw/tpm/tpm_util.c line 39
Quoted 6 lines
hw/tpm/tpm_util.c new file +6
-0+#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" Can you reduce the includes to its minimum?
Agree, I will do it in next version ASAP.
Quoted 103 lines
hw/tpm/tpm_xenstubdoms.c
Quoted 12 lines
hw/tpm/tpm_util.c new file +10
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) { +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +0
-0index
hw/tpm/tpm_xenstubdoms.c typedef struct TPMXenstubdomsState
Quoted 4 lines
3d046fc..992f2ae 100644
hw/tpm/tpm_xenstubdoms.c +0
-0@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsStateTPMXenstubdomsState;
hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const
Quoted 20 lines
hw/tpm/tpm_xenstubdoms.c +7
-1/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev == NULL) {hw/tpm/tpm_xenstubdoms.c +0
-0@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(constTPMLocality
*locty_data)hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data)
Quoted 8 lines
hw/tpm/tpm_xenstubdoms.c +1
-2locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } - vtpm_recv(xendev, locty_data->r_buffer.buffer,
locty_data->r_buffer.size,Quoted 21 lines
hw/tpm/tpm_xenstubdoms.c +17
-2- &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; }hw/tpm/tpm_xenstubdoms.c static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data)
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c +2
-1static void tpm_xenstubdoms_worker_thread(gpointer data, @@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, { TPMXenstubdomsThreadParams *thr_parms = user_data; TPMBackendCmd cmd = (TPMBackendCmd)data; + bool selftest_done = false; switch (cmd) { case TPM_BACKEND_CMD_PROCESS_CMD: -
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data);Quoted 1 line
+
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data,
Quoted 3 lines
+ &selftest_done); thr_parms->recv_data_callback(thr_parms->tpm_state,
thr_parms->tpm_state->locty_number,include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread
Quoted 11 lines
hw/tpm/tpm_xenstubdoms.c +1
-1- false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case TPM_BACKEND_CMD_END :include/sysemu/tpm_backend_int.h +0
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread*tbt,
Quoted 5 lines
include/sysemu/tpm_backend_int.h +1
-0void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len);
Quoted 7 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 2 lines
include/sysemu/tpm_backend_int.h +0
-0typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.
Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.
Thanks for your review.
-Quan
Quoted 1 line
Stefan
Re: [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
In reply to Eric BlakeQuoted 61 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: Friday, April 10, 2015 9:22 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line optionsQuoted 42 lines · Quan Xu
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-qapi schema enhancement.--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)+++
b/qapi-schema.jsonqapi-schema.json +8
-1@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) # # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type # # Since: 2.4 ## { +'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configurationoptions @@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union':
'TpmTypeOptions',qapi-schema.json line 3030
Quoted 3 lines
qapi-schema.json +2
-1- 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } }Hmm, maybe it is time for me to follow through with my threat of allowing anonymous types in union branches.
Quoted 3 lines
Quoted 1 line
+##
Stray insertion. Please remove it.
Thanks Eric..
I will send out the next version soon.
Quan
Quoted 11 lines
Quoted 6 lines
##
# @TpmInfo:qemu-options.hx index 319d971..9254902 renamed from qemu-options.hx +0
-0100644
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options
In reply to Eric BlakeQuoted 61 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: Friday, April 10, 2015 9:22 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line optionsQuoted 42 lines · Quan Xu
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-qapi schema enhancement.--- configure | 14 ++++++++++++++ hmp.c | 2 ++ qapi-schema.json | 17 +++++++++++++++-- qemu-options.hx | 13 +++++++++++-- tpm.c | 7 ++++++- 5 files changed, 48 insertions(+), 5 deletions(-)+++
b/qapi-schema.jsonqapi-schema.json +8
-1@@ -2975,9 +2975,11 @@ # # @passthrough: TPM passthrough type # +# @xenstubdoms: TPM xenstubdoms type (since 2.4) # # Since: 1.5 ## -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'xenstubdoms' ] } ## # @query-tpm-types:@@ -3006,6 +3008,15 @@ '*cancel-path' : 'str'} } ## +# @TPMXenstubdomsOptions: +# +# Information about the TPM xenstubdoms type # # Since: 2.4 ## { +'type': 'TPMXenstubdomsOptions', 'data': { } } + +## # @TpmTypeOptions: # # A union referencing different TPM backend types' configurationoptions @@ -3015,7 +3026,9 @@ # Since: 1.5 ## { 'union':
'TpmTypeOptions',qapi-schema.json line 3030
Quoted 3 lines
qapi-schema.json +2
-1- 'data': { 'passthrough' : 'TPMPassthroughOptions' } } + 'data': { 'passthrough' : 'TPMPassthroughOptions', + 'xenstubdoms' : 'TPMXenstubdomsOptions' } }Hmm, maybe it is time for me to follow through with my threat of allowing anonymous types in union branches.
Quoted 3 lines
Quoted 1 line
+##
Stray insertion. Please remove it.
Thanks Eric..
I will send out the next version soon.
Quan
Quoted 11 lines
Quoted 6 lines
##
# @TpmInfo:qemu-options.hx index 319d971..9254902 renamed from qemu-options.hx +0
-0100644
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Stefan BergerQuoted 119 lines · Stefan Berger
Quoted 16 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it totpm_util_is_selftest().Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_xenstubdoms.c | 36 +++++++++++++++++++++++------ include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/tpm_util.c new file +1
-0+#include <dirent.h> hw/tpm/tpm_util.c line 39
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+ +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" Can you reduce the includes to its minimum?
Quoted 89 lines
hw/tpm/tpm_util.c new file +11
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) +{ +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +7
-1@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsState TPMXenstubdomsState;/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev == NULL) {hw/tpm/tpm_xenstubdoms.c +18
-4@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data) locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } -vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, - &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; }static void tpm_xenstubdoms_worker_thread(gpointer data,
hw/tpm/tpm_xenstubdoms.c +4
-2@@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, {TPMXenstubdomsThreadParams *thr_parms = user_data;TPMBackendCmd cmd = (TPMBackendCmd )data; +bool selftest_done = false;switch (cmd) {case TPM_BACKEND_CMD_PROCESS_CMD : -tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data, + &selftest_done); thr_parms->recv_data_callback (thr_parms->tpm_state, thr_parms->tpm_state->locty_number, - false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case
TPM_BACKEND_CMD_END:include/sysemu/tpm_backend_int.h +0
-0
Quoted 8 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 38
Quoted 8 lines
include/sysemu/tpm_backend_int.h +1
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt,void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len);
Put this into tpm_util.h.
Quoted 4 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 2 lines
include/sysemu/tpm_backend_int.h +0
-0typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.
Actually, please put the part that splits out the tpm_util_is_selftest function into tpm_util.c,.h and the changes to the Makefile into a patch before your current patch 3.
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Stefan BergerQuoted 119 lines · Stefan Berger
Quoted 16 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it totpm_util_is_selftest().Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_xenstubdoms.c | 36 +++++++++++++++++++++++------ include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/tpm_util.c new file +1
-0+#include <dirent.h> hw/tpm/tpm_util.c line 39
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+ +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" Can you reduce the includes to its minimum?
Quoted 89 lines
hw/tpm/tpm_util.c new file +11
-0+ +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len) +{ +struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + +if (in_len >=sizeof (*hdr)) { +return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + +return false; +}hw/tpm/tpm_xenstubdoms.c +7
-1@@ -65,11 +65,17 @@ typedef struct TPMXenstubdomsState TPMXenstubdomsState;/* Functions */ static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); -static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data, +bool *selftest_done) {size_t rlen;struct XenDevice *xendev;int ret; +bool is_selftest; +const struct tpm_resp_hdr *hdr; + + is_selftest =tpm_util_is_selftest (locty_data->w_buffer.buffer, + locty_data->w_buffer.size); xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev);if (xendev == NULL) {hw/tpm/tpm_xenstubdoms.c +18
-4@@ -81,12 +87,26 @@ static int tpm_xenstubdoms_unix_transfer(const TPMLocality *locty_data) locty_data->r_buffer.size, locty_data->w_offset);if (ret <0 ) {xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); -return -1 ; + goto err_exit; } -vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, - &rlen); -return 0 ; + ret =vtpm_recv (xendev, locty_data->r_buffer.buffer, + locty_data->r_buffer.size, &rlen); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm reception command error.\n" ); + goto err_exit; + } + +if (is_selftest && (ret >=sizeof (struct tpm_resp_hdr ))) { + hdr = (struct tpm_resp_hdr *)locty_data->r_buffer.buffer; + *selftest_done = (be32_to_cpu (hdr->errcode) ==0 ); + } + +err_exit: +if (ret <0 ) { +xen_be_printf (xendev,0 ,"vtpm command error.\n" ); + } +return ret; }static void tpm_xenstubdoms_worker_thread(gpointer data,
hw/tpm/tpm_xenstubdoms.c +4
-2@@ -94,13 +114,15 @@ static void tpm_xenstubdoms_worker_thread(gpointer data, {TPMXenstubdomsThreadParams *thr_parms = user_data;TPMBackendCmd cmd = (TPMBackendCmd )data; +bool selftest_done = false;switch (cmd) {case TPM_BACKEND_CMD_PROCESS_CMD : -tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data, + &selftest_done); thr_parms->recv_data_callback (thr_parms->tpm_state, thr_parms->tpm_state->locty_number, - false); + selftest_done);break ;case TPM_BACKEND_CMD_INIT :case
TPM_BACKEND_CMD_END:include/sysemu/tpm_backend_int.h +0
-0
Quoted 8 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 38
Quoted 8 lines
include/sysemu/tpm_backend_int.h +1
-0@@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt,void tpm_backend_thread_end (TPMBackendThread *tbt);void tpm_backend_thread_tpm_reset (TPMBackendThread *tbt,GFunc func,gpointer user_data); +bool tpm_util_is_selftest (const uint8_t *in,uint32_t in_len);
Put this into tpm_util.h.
Quoted 4 lines
include/sysemu/tpm_backend_int.h void tpm_backend_thread_create(TPMBackendThread *tbt, · line 40
Quoted 2 lines
include/sysemu/tpm_backend_int.h +0
-0typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.
Actually, please put the part that splits out the tpm_util_is_selftest function into tpm_util.c,.h and the changes to the Makefile into a patch before your current patch 3.
Stefan
Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Quan XuQuoted 139 lines · Quan Xu
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
Call
xen_fe_register()function to register XenDevOps, and make sure,[...] 3 = "" [...] device = "" (frontend device, the backend is running in QEMU/.etc) vkbd = "" [...] vif = "" [...]..
(QEMU)
xen_vtpmdev_opsis initialized with the following process:xen_hvm_init() [...] -->xen_fe_register("vtpm", ...) -->xenstore_fe_scan() -->xen_fe_try_init(ops) --> XenDevOps.init() -->xen_fe_get_xendev() --> XenDevOps.alloc() -->xen_fe_check() -->xen_fe_try_initialise() --> XenDevOps.initialise() -->xen_fe_try_connected() --> XenDevOps.connected() -->xs_watch() [...]Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-Comments enhancement.
-Pass the size of the buff for vtpm_recv()|vtpm_send().--- hw/tpm/Makefile.objs | 1 + hw/tpm/xen_vtpm_frontend.c | 321 +++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_frontend.c | 20 +++ include/hw/xen/xen_backend.h | 7 + include/hw/xen/xen_common.h | 6 + xen-hvm.c | 5 + 6 files changed, 360 insertions(+)create mode 100644
hw/tpm/xen_vtpm_frontend.chw/tpm/Makefile.objs +1
-0@@ -1,2 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.ohw/tpm/xen_vtpm_frontend.c new file +75
-0@@ -0,0 +1,321 @@ +/* +* Connect to Xen vTPM stubdom domain +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <inttypes.h> +#include <time.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/uio.h> + +#include "hw/hw.h" +#include "block/aio.h" +#include "hw/xen/xen_backend.h" + +#ifndef XS_STUBDOM_VTPM_ENABLE +#define XS_STUBDOM_VTPM_ENABLE "1" +#endif + +#ifndef PAGE_SIZE +#define PAGE_SIZE 4096 +#endif + +enum tpmif_state { +/* No contents, vTPM idle, cancel complete */ +TPMIF_STATE_IDLE , +/* Request ready or vTPM working */ +TPMIF_STATE_SUBMIT , +/* Response ready or vTPM idle */ +TPMIF_STATE_FINISH , +/* Cancel requested or vTPM working */ +TPMIF_STATE_CANCEL , +}; + +static AioContext *vtpm_aio_ctx; + +enum status_bits { +VTPM_STATUS_RUNNING =0x1 , +VTPM_STATUS_IDLE =0x2 , +VTPM_STATUS_RESULT =0x4 , +VTPM_STATUS_CANCELED =0x8 , +}; + +struct tpmif_shared_page { +/* Request and response length in bytes */ +uint32_t length; +/* Enum tpmif_state */ +uint8_t state; +/* For the current request */
hw/tpm/xen_vtpm_frontend.c line 85
Quoted 10 lines
hw/tpm/xen_vtpm_frontend.c new file +10
-0+uint8_t locality; +/* Should be zero */ +uint8_t pad; +/* Extra pages for long packets; may be zero */ +uint8_t nr_extra_pages; +/* +* Grant IDs, the length is actually nr_extra_pages. +* beyond the extra_pages entries is the actual requese +* and response. +*/
requese->request
Quoted 39 lines
hw/tpm/xen_vtpm_frontend.c new file +39
-0+uint32_t extra_pages[0 ]; +}; + +struct xen_vtpm_dev { +struct XenDevice xendev;/* must be first */ +struct tpmif_shared_page *shr; +xc_gntshr *xen_xcs; +int ring_ref; +int bedomid; +QEMUBH *sr_bh; +}; + +static uint8_t vtpm_status (struct xen_vtpm_dev *vtpmdev) +{ +switch (vtpmdev->shr->state) { +case TPMIF_STATE_IDLE : +case TPMIF_STATE_FINISH : +return VTPM_STATUS_IDLE ; +case TPMIF_STATE_SUBMIT : +case TPMIF_STATE_CANCEL : +return VTPM_STATUS_RUNNING ; +default : +return 0 ; + } +} + +static bool vtpm_aio_wait (AioContext *ctx) +{ +return aio_poll (ctx, true); +} + +static void sr_bh_handler (void *opaque) +{ +} + +int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count) +{ + struct xen_vtpm_dev *vtpmdev = container_of(xendev, struct xen_vtpm_dev,
hw/tpm/xen_vtpm_frontend.c line 134
Quoted 10 lines
hw/tpm/xen_vtpm_frontend.c new file +10
-0+ xendev); +struct tpmif_shared_page *shr = vtpmdev->shr; +unsigned int offset; +size_t length = shr->length; + +if (shr->state ==TPMIF_STATE_IDLE ) { +return -ECANCELED ; + } + + offset =sizeof (*shr) +sizeof (shr->extra_pages[0 ])*shr->nr_extra_pages;
offset now points to where the TPM response starts, right?
hw/tpm/xen_vtpm_frontend.c line 135
Quoted 1 line
hw/tpm/xen_vtpm_frontend.c new file +1
-0+if (offset > buf_size) {
You are comparing offset as if it was the size of the TPM response, but that's not what it is as far as I understand this.
I would have thought that shr->length indicates the size of the TPM response that starts at offset. So then you should only have to ensure that shr->length <= buf_size and never copy more than buf_size bytes to buf.
Similar comments to vtpm_send.
hw/tpm/xen_vtpm_frontend.c line 147
Quoted 12 lines
hw/tpm/xen_vtpm_frontend.c new file +12
-0+return -EIO ; + } + +if (offset + length > buf_size) { + length = buf_size - offset; + } + +if (length > *count) { + length = *count; + } + +memcpy (buf, offset + (uint8_t *)shr, shr->length);
use length rather than shr->length otherwise length goes unused.
Rest looks good.
Stefan
Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Quan XuQuoted 139 lines · Quan Xu
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
Call
xen_fe_register()function to register XenDevOps, and make sure,[...] 3 = "" [...] device = "" (frontend device, the backend is running in QEMU/.etc) vkbd = "" [...] vif = "" [...]..
(QEMU)
xen_vtpmdev_opsis initialized with the following process:xen_hvm_init() [...] -->xen_fe_register("vtpm", ...) -->xenstore_fe_scan() -->xen_fe_try_init(ops) --> XenDevOps.init() -->xen_fe_get_xendev() --> XenDevOps.alloc() -->xen_fe_check() -->xen_fe_try_initialise() --> XenDevOps.initialise() -->xen_fe_try_connected() --> XenDevOps.connected() -->xs_watch() [...]Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-Comments enhancement.
-Pass the size of the buff for vtpm_recv()|vtpm_send().--- hw/tpm/Makefile.objs | 1 + hw/tpm/xen_vtpm_frontend.c | 321 +++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_frontend.c | 20 +++ include/hw/xen/xen_backend.h | 7 + include/hw/xen/xen_common.h | 6 + xen-hvm.c | 5 + 6 files changed, 360 insertions(+)create mode 100644
hw/tpm/xen_vtpm_frontend.chw/tpm/Makefile.objs +1
-0@@ -1,2 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.ohw/tpm/xen_vtpm_frontend.c new file +75
-0@@ -0,0 +1,321 @@ +/* +* Connect to Xen vTPM stubdom domain +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <inttypes.h> +#include <time.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/uio.h> + +#include "hw/hw.h" +#include "block/aio.h" +#include "hw/xen/xen_backend.h" + +#ifndef XS_STUBDOM_VTPM_ENABLE +#define XS_STUBDOM_VTPM_ENABLE "1" +#endif + +#ifndef PAGE_SIZE +#define PAGE_SIZE 4096 +#endif + +enum tpmif_state { +/* No contents, vTPM idle, cancel complete */ +TPMIF_STATE_IDLE , +/* Request ready or vTPM working */ +TPMIF_STATE_SUBMIT , +/* Response ready or vTPM idle */ +TPMIF_STATE_FINISH , +/* Cancel requested or vTPM working */ +TPMIF_STATE_CANCEL , +}; + +static AioContext *vtpm_aio_ctx; + +enum status_bits { +VTPM_STATUS_RUNNING =0x1 , +VTPM_STATUS_IDLE =0x2 , +VTPM_STATUS_RESULT =0x4 , +VTPM_STATUS_CANCELED =0x8 , +}; + +struct tpmif_shared_page { +/* Request and response length in bytes */ +uint32_t length; +/* Enum tpmif_state */ +uint8_t state; +/* For the current request */
hw/tpm/xen_vtpm_frontend.c line 85
Quoted 10 lines
hw/tpm/xen_vtpm_frontend.c new file +10
-0+uint8_t locality; +/* Should be zero */ +uint8_t pad; +/* Extra pages for long packets; may be zero */ +uint8_t nr_extra_pages; +/* +* Grant IDs, the length is actually nr_extra_pages. +* beyond the extra_pages entries is the actual requese +* and response. +*/
requese->request
Quoted 39 lines
hw/tpm/xen_vtpm_frontend.c new file +39
-0+uint32_t extra_pages[0 ]; +}; + +struct xen_vtpm_dev { +struct XenDevice xendev;/* must be first */ +struct tpmif_shared_page *shr; +xc_gntshr *xen_xcs; +int ring_ref; +int bedomid; +QEMUBH *sr_bh; +}; + +static uint8_t vtpm_status (struct xen_vtpm_dev *vtpmdev) +{ +switch (vtpmdev->shr->state) { +case TPMIF_STATE_IDLE : +case TPMIF_STATE_FINISH : +return VTPM_STATUS_IDLE ; +case TPMIF_STATE_SUBMIT : +case TPMIF_STATE_CANCEL : +return VTPM_STATUS_RUNNING ; +default : +return 0 ; + } +} + +static bool vtpm_aio_wait (AioContext *ctx) +{ +return aio_poll (ctx, true); +} + +static void sr_bh_handler (void *opaque) +{ +} + +int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count) +{ + struct xen_vtpm_dev *vtpmdev = container_of(xendev, struct xen_vtpm_dev,
hw/tpm/xen_vtpm_frontend.c line 134
Quoted 10 lines
hw/tpm/xen_vtpm_frontend.c new file +10
-0+ xendev); +struct tpmif_shared_page *shr = vtpmdev->shr; +unsigned int offset; +size_t length = shr->length; + +if (shr->state ==TPMIF_STATE_IDLE ) { +return -ECANCELED ; + } + + offset =sizeof (*shr) +sizeof (shr->extra_pages[0 ])*shr->nr_extra_pages;
offset now points to where the TPM response starts, right?
hw/tpm/xen_vtpm_frontend.c line 135
Quoted 1 line
hw/tpm/xen_vtpm_frontend.c new file +1
-0+if (offset > buf_size) {
You are comparing offset as if it was the size of the TPM response, but that's not what it is as far as I understand this.
I would have thought that shr->length indicates the size of the TPM response that starts at offset. So then you should only have to ensure that shr->length <= buf_size and never copy more than buf_size bytes to buf.
Similar comments to vtpm_send.
hw/tpm/xen_vtpm_frontend.c line 147
Quoted 12 lines
hw/tpm/xen_vtpm_frontend.c new file +12
-0+return -EIO ; + } + +if (offset + length > buf_size) { + length = buf_size - offset; + } + +if (length > *count) { + length = *count; + } + +memcpy (buf, offset + (uint8_t *)shr, shr->length);
use length rather than shr->length otherwise length goes unused.
Rest looks good.
Stefan
Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Quan XuQuoted 139 lines · Quan Xu
This Patch provides the glue for the
TPM_TIS(Qemu frontend)to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends withxen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by thexen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line options,
"-tpmdev xenstubdoms,id=xenvtpm0 -device tpm-tis,tpmdev=xenvtpm0"Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-comments enhancement.--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 1 deletion(-)create mode 100644
hw/tpm/tpm_xenstubdoms.chw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.ohw/tpm/tpm_xenstubdoms.c new file +93
-0@@ -0,0 +1,256 @@ +/* +* Xen Stubdom vTPM driver +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <dirent.h> +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "qemu/log.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/xen/xen_backend.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" + +#ifdef DEBUG_TPM +#define DPRINTF (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif + +#define TYPE_TPM_XENSTUBDOMS "tpm-xenstubdoms" +#define TPM_XENSTUBDOMS (obj) \ + OBJECT_CHECK(TPMXenstubdomsState, (obj), TYPE_TPM_XENSTUBDOMS) + +static const TPMDriverOps tpm_xenstubdoms_driver; + +/* Data structures */ +typedef struct TPMXenstubdomsThreadParams { +TPMState *tpm_state; +TPMRecvDataCB *recv_data_callback; +TPMBackend *tb; +}TPMXenstubdomsThreadParams ; + +struct TPMXenstubdomsState { +TPMBackend parent; +TPMBackendThread tbt; +TPMXenstubdomsThreadParams tpm_thread_params; +bool had_startup_error; +}; + +typedef struct TPMXenstubdomsState TPMXenstubdomsState ; + +/* Functions */ +static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); + +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +{ +size_t rlen; +struct XenDevice *xendev; +int ret; + + xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev); +if (xendev ==NULL ) { +xen_be_printf (xendev,0 ,"Can not find vtpm device.\n" ); +return -1 ; + } + + ret =vtpm_send (xendev, locty_data->w_buffer.buffer, + locty_data->r_buffer.size, locty_data->w_offset); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); +return -1 ; + } + +vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, + &rlen); +return 0 ; +} + +static void tpm_xenstubdoms_worker_thread (gpointer data, +gpointer user_data)
hw/tpm/tpm_xenstubdoms.c line 103
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+{ +TPMXenstubdomsThreadParams *thr_parms = user_data; +TPMBackendCmd cmd = (TPMBackendCmd )data; + +switch (cmd) { +case TPM_BACKEND_CMD_PROCESS_CMD : +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); + thr_parms->recv_data_callback (thr_parms->tpm_state, + thr_parms->tpm_state->locty_number, + false);
Didn't look at this before. I still think you should reorder the patches.
Rest looks good.
Stefan
Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Quan XuQuoted 139 lines · Quan Xu
This Patch provides the glue for the
TPM_TIS(Qemu frontend)to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends withxen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by thexen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line options,
"-tpmdev xenstubdoms,id=xenvtpm0 -device tpm-tis,tpmdev=xenvtpm0"Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-comments enhancement.--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 1 deletion(-)create mode 100644
hw/tpm/tpm_xenstubdoms.chw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o xen_vtpm_frontend.ohw/tpm/tpm_xenstubdoms.c new file +93
-0@@ -0,0 +1,256 @@ +/* +* Xen Stubdom vTPM driver +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/> +*/ + +#include <dirent.h> +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "qemu/log.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/xen/xen_backend.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" + +#ifdef DEBUG_TPM +#define DPRINTF (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif + +#define TYPE_TPM_XENSTUBDOMS "tpm-xenstubdoms" +#define TPM_XENSTUBDOMS (obj) \ + OBJECT_CHECK(TPMXenstubdomsState, (obj), TYPE_TPM_XENSTUBDOMS) + +static const TPMDriverOps tpm_xenstubdoms_driver; + +/* Data structures */ +typedef struct TPMXenstubdomsThreadParams { +TPMState *tpm_state; +TPMRecvDataCB *recv_data_callback; +TPMBackend *tb; +}TPMXenstubdomsThreadParams ; + +struct TPMXenstubdomsState { +TPMBackend parent; +TPMBackendThread tbt; +TPMXenstubdomsThreadParams tpm_thread_params; +bool had_startup_error; +}; + +typedef struct TPMXenstubdomsState TPMXenstubdomsState ; + +/* Functions */ +static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); + +static int tpm_xenstubdoms_unix_transfer (const TPMLocality *locty_data) +{ +size_t rlen; +struct XenDevice *xendev; +int ret; + + xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev); +if (xendev ==NULL ) { +xen_be_printf (xendev,0 ,"Can not find vtpm device.\n" ); +return -1 ; + } + + ret =vtpm_send (xendev, locty_data->w_buffer.buffer, + locty_data->r_buffer.size, locty_data->w_offset); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); +return -1 ; + } + +vtpm_recv (xendev, locty_data->r_buffer.buffer, locty_data->r_buffer.size, + &rlen); +return 0 ; +} + +static void tpm_xenstubdoms_worker_thread (gpointer data, +gpointer user_data)
hw/tpm/tpm_xenstubdoms.c line 103
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+{ +TPMXenstubdomsThreadParams *thr_parms = user_data; +TPMBackendCmd cmd = (TPMBackendCmd )data; + +switch (cmd) { +case TPM_BACKEND_CMD_PROCESS_CMD : +tpm_xenstubdoms_unix_transfer (thr_parms->tpm_state->locty_data); + thr_parms->recv_data_callback (thr_parms->tpm_state, + thr_parms->tpm_state->locty_number, + false);
Didn't look at this before. I still think you should reorder the patches.
Rest looks good.
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Xu, QuanQuoted 89 lines · Quan
Quoted 80 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 5 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t*out,
uint32_tout_len)Quoted 6 lines
hw/tpm/tpm_passthrough.c +0
-2} } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 10 lines
hw/tpm/tpm_passthrough.c +0
-8- -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} -static int tpm_passthrough_unix_tx_bufs (TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 19 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +6
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* +* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> Quoted 8 lines
hw/tpm/tpm_util.c line 13
Quoted 7 lines
hw/tpm/tpm_util.c new file +7
-0+* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Quoted 2 lines
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright, if I am not correct.
For this single function that's going to land in tpm_util.c for now we don't need this Copyright.
Quoted 6 lines
Quoted 4 lines
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.
Thanks.
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Xu, QuanQuoted 89 lines · Quan
Quoted 80 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 5 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t*out,
uint32_tout_len)Quoted 6 lines
hw/tpm/tpm_passthrough.c +0
-2} } -static bool tpm_passthrough_is_selftest (const uint8_t *in,uint32_t in_len) -{ -struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 10 lines
hw/tpm/tpm_passthrough.c +0
-8- -if (in_len >=sizeof (*hdr)) { -return (be32_to_cpu (hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - -return false; -} -static int tpm_passthrough_unix_tx_bufs (TPMPassthruState *tpm_pt, const uint8_t *in, uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 19 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +6
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* +* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> Quoted 8 lines
hw/tpm/tpm_util.c line 13
Quoted 7 lines
hw/tpm/tpm_util.c new file +7
-0+* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Quoted 2 lines
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright, if I am not correct.
For this single function that's going to land in tpm_util.c for now we don't need this Copyright.
Quoted 6 lines
Quoted 4 lines
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.
Thanks.
Stefan
Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Stefan BergerQuoted 7 lines · Stefan Berger
Quoted 6 lines · Quan Xu
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
[...]
Quoted 8 lines
Quoted 8 lines
hw/tpm/xen_vtpm_frontend.c new file +8
-0+int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count) +{ + struct xen_vtpm_dev *vtpmdev = container_of(xendev, struct xen_vtpm_dev, + xendev); +struct tpmif_shared_page *shr = vtpmdev->shr; +unsigned int offset; +size_t length = shr->length;
Quoted 8 lines
hw/tpm/xen_vtpm_frontend.c line 134
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+ +if (shr->state ==TPMIF_STATE_IDLE ) { +return -ECANCELED ; + } + + offset =sizeof (*shr) +sizeof (shr->extra_pages[0 ])*shr->nr_extra_pages;offset now points to where the TPM response starts, right?
Yes.
Quoted 8 lines
Quoted 1 line
+ if (offset >
buf_size) {You are comparing offset as if it was the size of the TPM response, but that's not what it is as far as I understand this.
I would have thought that
shr->lengthindicates the size of the TPM response that starts at offset. So then you should only have to ensure thatshr->length<=buf_sizeand never copy more thanbuf_sizebytes to buf.Similar comments to
vtpm_send.
No, this check needs to remain (on both send and recv), but buf_size should be replaced by PAGE_SIZE. This prevents an incorrectly large value for nr_extra_pages from causing the packet to be located outside of the shared page, resulting in TPM packets being written to some random heap address.
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c line 141
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+return -EIO ; + } + +if (offset + length > buf_size) { + length = buf_size - offset; + }
This check also needs to be against PAGE_SIZE.
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c line 145
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c new file +4
-0+ +if (length > *count) { + length = *count; + }
Is *count even valid here? I would have assumed it was a purely out parameter, with buf_size as the maximum value it can be assigned.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + memcpy(buf, offset + (uint8_t *)shr, shr->length);use length rather than
shr->lengthotherwise length goes unused.
Agreed; the values from the shared page should not be read more than once, because an uncooperative peer could end up changing them.
Signature · 2 lines
Daniel De Graaf National Security Agency
Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure
Quoted 50 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 11:07 PM
To: Stefan Berger; Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructureQuoted 7 lines · Stefan Berger
Quoted 6 lines · Quan Xu
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
[...]
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c new file +4
-0+int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count) +{ + struct xen_vtpm_dev *vtpmdev = container_of(xendev, struct
xen_vtpm_dev,Quoted 5 lines
Quoted 5 lines
hw/tpm/xen_vtpm_frontend.c new file +5
-0+ xendev); +struct tpmif_shared_page *shr = vtpmdev->shr; +unsigned int offset; +size_t length = shr->length; +Quoted 8 lines
hw/tpm/xen_vtpm_frontend.c line 160
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+if (shr->state ==TPMIF_STATE_IDLE ) { +return -ECANCELED ; + } + + offset =sizeof (*shr) + +sizeof (shr->extra_pages[0 ])*shr->nr_extra_pages;offset now points to where the TPM response starts, right?
Yes.
Quoted 3 lines
Quoted 1 line
+ if (offset >
buf_size) {You are comparing offset as if it was the size of the TPM response, but that's
not what it is as far as I understand this.
Quoted 2 lines
I would have thought that
shr->lengthindicates the size of the TPM responsethat starts at offset.
Quoted 1 line
So then you should only have to ensure that
shr->length<=buf_sizeand never
Quoted 9 lines
copy more than
buf_sizebytes to buf.Quoted 2 lines
Similar comments to
vtpm_send.No, this check needs to remain (on both send and recv), but
buf_sizeshould be replaced byPAGE_SIZE. This prevents an incorrectly large value fornr_extra_pagesfrom causing the packet to be located outside of the shared page, resulting in TPM packets being written to some random heap address.
Thanks Deniel and Stefan.
I will replace buf_size with PAGE_SIZE in next version.
Quoted 9 lines
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c line 141
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+return -EIO ; + } + +if (offset + length > buf_size) { + length = buf_size - offset; + }This check also needs to be against
PAGE_SIZE.
Quoted 7 lines
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c line 145
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c new file +4
-0+ +if (length > *count) { + length = *count; + }Is *count even valid here? I would have assumed it was a purely out parameter, with
buf_sizeas the maximum value it can be assigned.
replaced by PAGE_SIZE?
Quoted 9 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + memcpy(buf, offset + (uint8_t *)shr, shr->length);use length rather than
shr->lengthotherwise length goes unused.Agreed; the values from the shared page should not be read more than once, because an uncooperative peer could end up changing them.
Agreed.
Quan Xu
Intel
Quoted 3 lines
--
Daniel De Graaf
National Security Agency
Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructure
In reply to Daniel De GraafQuoted 50 lines
-----Original Message-----
From: Daniel De Graaf [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 11:07 PM
To: Stefan Berger; Xu, Quan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 3/6] Qemu-Xen-vTPM: Xen frontend driver infrastructureQuoted 7 lines · Stefan Berger
Quoted 6 lines · Quan Xu
This patch adds infrastructure for xen front drivers living in qemu, so drivers don't need to implement common stuff on their own. It's mostly xenbus management stuff: some functions to access XenStore, setting up XenStore watches, callbacks on device discovery and state changes, and handle event channel between the virtual machines.
[...]
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c new file +4
-0+int vtpm_recv (struct XenDevice *xendev,uint8_t * buf,uint32_t buf_size, +size_t *count) +{ + struct xen_vtpm_dev *vtpmdev = container_of(xendev, struct
xen_vtpm_dev,Quoted 5 lines
Quoted 5 lines
hw/tpm/xen_vtpm_frontend.c new file +5
-0+ xendev); +struct tpmif_shared_page *shr = vtpmdev->shr; +unsigned int offset; +size_t length = shr->length; +Quoted 8 lines
hw/tpm/xen_vtpm_frontend.c line 160
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+if (shr->state ==TPMIF_STATE_IDLE ) { +return -ECANCELED ; + } + + offset =sizeof (*shr) + +sizeof (shr->extra_pages[0 ])*shr->nr_extra_pages;offset now points to where the TPM response starts, right?
Yes.
Quoted 3 lines
Quoted 1 line
+ if (offset >
buf_size) {You are comparing offset as if it was the size of the TPM response, but that's
not what it is as far as I understand this.
Quoted 2 lines
I would have thought that
shr->lengthindicates the size of the TPM responsethat starts at offset.
Quoted 1 line
So then you should only have to ensure that
shr->length<=buf_sizeand never
Quoted 9 lines
copy more than
buf_sizebytes to buf.Quoted 2 lines
Similar comments to
vtpm_send.No, this check needs to remain (on both send and recv), but
buf_sizeshould be replaced byPAGE_SIZE. This prevents an incorrectly large value fornr_extra_pagesfrom causing the packet to be located outside of the shared page, resulting in TPM packets being written to some random heap address.
Thanks Deniel and Stefan.
I will replace buf_size with PAGE_SIZE in next version.
Quoted 9 lines
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c line 141
Quoted 6 lines
hw/tpm/xen_vtpm_frontend.c new file +6
-0+return -EIO ; + } + +if (offset + length > buf_size) { + length = buf_size - offset; + }This check also needs to be against
PAGE_SIZE.
Quoted 7 lines
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c line 145
Quoted 4 lines
hw/tpm/xen_vtpm_frontend.c new file +4
-0+ +if (length > *count) { + length = *count; + }Is *count even valid here? I would have assumed it was a purely out parameter, with
buf_sizeas the maximum value it can be assigned.
replaced by PAGE_SIZE?
Quoted 9 lines
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + memcpy(buf, offset + (uint8_t *)shr, shr->length);use length rather than
shr->lengthotherwise length goes unused.Agreed; the values from the shared page should not be read more than once, because an uncooperative peer could end up changing them.
Agreed.
Quan Xu
Intel
Quoted 3 lines
--
Daniel De Graaf
National Security Agency
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Stefan BergerQuoted 104 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 10:56 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 45 lines · Quan
Quoted 45 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 5 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static voidQuoted 1 line
tpm_write_fatal_error_response(uint8_t
*out,
uint32_tout_len)Quoted 3 lines
}}
Quoted 6 lines
Quoted 6 lines
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 6 lines
-static bool
tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len)-{hw/tpm/tpm_passthrough.c +0
-4-struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >=sizeof (*hdr)) { - return (be32_to_cpu(hdr->ordinal) ==
TPM_ORD_ContinueSelfTest);Quoted 40 lines
Quoted 39 lines
Quoted 8 lines
hw/tpm/tpm_passthrough.c +0
-5- } - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in,
uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 16 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +3
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* hw/tpm/tpm_util.c line 13
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Quoted 5 lines
Quoted 2 lines
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright,if I am not correct.
For this single function that's going to land in
tpm_util.cfor now we don't need
Agreed, I will remove it in next version.
Quan
Quoted 12 lines
this Copyright.
Quoted 6 lines
Quoted 4 lines
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.Thanks.
Stefan
Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftest
In reply to Stefan BergerQuoted 104 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 10:56 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 45 lines · Quan
Quoted 45 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Monday, April 13, 2015 4:50 AM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v5 6/6] Qemu-Xen-vTPM: Add a parameter indicating whether the command that was a selftestQuoted 2 lines · Quan Xu
and whether it completed successfully. Move
tpm_passthrough_is_selftest()intotpm_util.cand rename it to
tpm_util_is_selftest().Quoted 5 lines
Signed-off-by Quan Xu <[email protected]>--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +---------- hw/tpm/tpm_util.c | 50++++++++++++++++++++++++++++++++++++++++
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c | 36+++++++++++++++++++++++------
Quoted 18 lines
include/sysemu/tpm_backend_int.h | 1 + 5 files changed, 82 insertions(+), 20 deletions(-)create mode 100644
hw/tpm/tpm_util.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-0190e776..cba961c 100644
hw/tpm/Makefile.objs +1
-1@@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.oxen_vtpm_frontend.o diff --git
a/hw/tpm/tpm_passthrough.cb/hw/tpm/tpm_passthrough.cindex 2a45071..ff08e15 100644hw/tpm/tpm_passthrough.c +0
-0@@ -112,17 +112,6 @@ static voidQuoted 1 line
tpm_write_fatal_error_response(uint8_t
*out,
uint32_tout_len)Quoted 3 lines
}}
Quoted 6 lines
Quoted 6 lines
hw/tpm/tpm_passthrough.c static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
Quoted 6 lines
-static bool
tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len)-{hw/tpm/tpm_passthrough.c +0
-4-struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - -if (in_len >=sizeof (*hdr)) { - return (be32_to_cpu(hdr->ordinal) ==
TPM_ORD_ContinueSelfTest);Quoted 40 lines
Quoted 39 lines
Quoted 8 lines
hw/tpm/tpm_passthrough.c +0
-5- } - -return false; -} - static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, const uint8_t *in,
uint32_t
in_len,Quoted 2 lines
uint8_t *out, uint32_t
out_len, @@ -136,7 +125,7 @@ static inttpm_passthrough_unix_tx_bufs(TPMPassthruState
*tpm_pt,Quoted 16 lines
tpm_pt->tpm_executing = true; *selftest_done = false;hw/tpm/tpm_passthrough.c +1
-1- is_selftest =tpm_passthrough_is_selftest (in, in_len); + is_selftest =tpm_util_is_selftest (in, in_len); ret =tpm_passthrough_unix_write (tpm_pt->tpm_fd, in, in_len);if (ret != in_len) {hw/tpm/tpm_util.c new file mode renamed from hw/tpm/tpm_util.c +0
-0100644 index 0000000..8566781
hw/tpm/tpm_util.c new file +3
-0@@ -0,0 +1,50 @@ +/* +* TPM util functions +* hw/tpm/tpm_util.c line 13
Quoted 10 lines
hw/tpm/tpm_util.c new file +10
-0+* * Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* Copyright (c) 2010 - 2013 IBM Corporation +* Authors: +* Stefan Berger <[email protected]> +* +* Copyright (C) 2011 IAIK, Graz University of Technology +* Author: Andreas Niederl I don't think that for this particular function this Copyright applies.
Quoted 5 lines
Quoted 2 lines
Thanks Stefan.
Could I just delete "Copyright (C) 2011 IAIK.."? share me more specific copyright,if I am not correct.
For this single function that's going to land in
tpm_util.cfor now we don't need
Agreed, I will remove it in next version.
Quan
Quoted 12 lines
this Copyright.
Quoted 6 lines
Quoted 4 lines
This patch per se looks good, but some of your modifications will not compile until this patch is applied, due to the missing
selftest_doneparameter. So you should merge this patch into the 3rd patch in this series.Okay, I will do it in next version.
If the other patches are good, I can send out v6 soon.Thanks.
Stefan
Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Stefan BergerQuoted 162 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 10:50 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.Quoted 14 lines · Quan Xu
This Patch provides the glue for the
TPM_TIS(Qemu frontend)to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends withxen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by thexen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.Quoted 5 lines
The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line
options,
Quoted 1 line
"-tpmdev xenstubdoms,id=xenvtpm0 -device
tpm-tis,tpmdev=xenvtpm0"
Quoted 8 lines
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-comments enhancement.--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256+++++++++++++++++++++++++++++++++++++++++++++++
Quoted 52 lines
2 files changed, 257 insertions(+), 1 deletion(-)create mode 100644
hw/tpm/tpm_xenstubdoms.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-057919fa..190e776 100644
hw/tpm/Makefile.objs +2
-1@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o +xen_vtpm_frontend.ohw/tpm/tpm_xenstubdoms.c new renamed from hw/tpm/tpm_xenstubdoms.c +0
-0file mode 100644 index 0000000..3d046fc
hw/tpm/tpm_xenstubdoms.c new file +34
-0@@ -0,0 +1,256 @@ +/* +* Xen Stubdom vTPM driver +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +<http://www.gnu.org/licenses/> */ + +#include <dirent.h> +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "qemu/log.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/xen/xen_backend.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" +hw/tpm/tpm_xenstubdoms.c line 44
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+#ifdef DEBUG_TPM +#define DPRINTF (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) #else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif + +#define TYPE_TPM_XENSTUBDOMS "tpm-xenstubdoms" +#define TPM_XENSTUBDOMS (obj) \ + OBJECT_CHECK(TPMXenstubdomsState, (obj),
TYPE_TPM_XENSTUBDOMS)Quoted 32 lines
hw/tpm/tpm_xenstubdoms.c new file +32
-0+ +static const TPMDriverOps tpm_xenstubdoms_driver; + +/* Data structures */ +typedef struct TPMXenstubdomsThreadParams { +TPMState *tpm_state; +TPMRecvDataCB *recv_data_callback; +TPMBackend *tb; +}TPMXenstubdomsThreadParams ; + +struct TPMXenstubdomsState { +TPMBackend parent; +TPMBackendThread tbt; +TPMXenstubdomsThreadParams tpm_thread_params; +bool had_startup_error; +}; + +typedef struct TPMXenstubdomsState TPMXenstubdomsState ; + +/* Functions */ +static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); + +static int tpm_xenstubdoms_unix_transfer (const TPMLocality +*locty_data) { +size_t rlen; +struct XenDevice *xendev; +int ret; + + xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev); +if (xendev ==NULL ) { +xen_be_printf (xendev,0 ,"Can not find vtpm device.\n" ); +return -1 ;hw/tpm/tpm_xenstubdoms.c
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+ } + + ret =vtpm_send (xendev, locty_data->w_buffer.buffer, + locty_data->r_buffer.size, locty_data->w_offset); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); +return -1 ; + } + + vtpm_recv(xendev, locty_data->r_buffer.buffer,
locty_data->r_buffer.size,hw/tpm/tpm_xenstubdoms.c line 108
Quoted 12 lines
hw/tpm/tpm_xenstubdoms.c new file +12
-0+ &rlen); +return 0 ; +} + +static void tpm_xenstubdoms_worker_thread (gpointer data, +gpointer user_data) { +TPMXenstubdomsThreadParams *thr_parms = user_data; +TPMBackendCmd cmd = (TPMBackendCmd )data; + +switch (cmd) { +case TPM_BACKEND_CMD_PROCESS_CMD : +
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data);
Quoted 6 lines
hw/tpm/tpm_xenstubdoms.c line 100
Quoted 2 lines
hw/tpm/tpm_xenstubdoms.c new file +2
-0+ thr_parms->recv_data_callback(thr_parms->tpm_state, +
thr_parms->tpm_state->locty_number,hw/tpm/tpm_xenstubdoms.c line 103
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c new file +1
-0+ false);Didn't look at this before. I still think you should reorder the patches.
I have rebased these patches against QEMU upstream in v5, but I didn't mention it. I will go through these patches.
Quan
Quoted 4 lines
Rest looks good.
Stefan
Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.
In reply to Stefan BergerQuoted 162 lines
-----Original Message-----
From: Stefan Berger [mailto:[email protected]]
Sent: Wednesday, April 15, 2015 10:50 PM
To: Xu, Quan; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH v5 4/6] Qemu-Xen-vTPM: Qemu vTPM xenstubdoms backen.Quoted 14 lines · Quan Xu
This Patch provides the glue for the
TPM_TIS(Qemu frontend)to Xen stubdom vTPM domain that provides the actual TPM functionality. It sends data and TPM commends withxen_vtpm_frontend. It is similar as another two vTPM backens:
*vTPM passthrough backen Since QEMU 1.5.
*vTPM libtpms-based backen.Some details:
This part of the patch provides support for the spawning of a thread that will interact with stubdom vTPM domain by thexen_vtpm_frontend. It expects a signal from the frontend to wake and pick up the TPM command that is supposed to be processed and delivers the response packet using a callback function provided by the frontend.Quoted 5 lines
The backend connects itself to the frontend by filling out an interface structure with pointers to the function implementing support for various operations.
(QEMU) vTPM XenStubdoms backen is initialized by Qemu command line
options,
Quoted 1 line
"-tpmdev xenstubdoms,id=xenvtpm0 -device
tpm-tis,tpmdev=xenvtpm0"
Quoted 8 lines
Signed-off-by Quan Xu <[email protected]>--Changes in v5:
-comments enhancement.--- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_xenstubdoms.c | 256+++++++++++++++++++++++++++++++++++++++++++++++
Quoted 52 lines
2 files changed, 257 insertions(+), 1 deletion(-)create mode 100644
hw/tpm/tpm_xenstubdoms.chw/tpm/Makefile.objs index renamed from hw/tpm/Makefile.objs +0
-057919fa..190e776 100644
hw/tpm/Makefile.objs +2
-1@@ -1,3 +1,3 @@ common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o -common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o +common-obj-$(CONFIG_TPM_XENSTUBDOMS) += tpm_xenstubdoms.o +xen_vtpm_frontend.ohw/tpm/tpm_xenstubdoms.c new renamed from hw/tpm/tpm_xenstubdoms.c +0
-0file mode 100644 index 0000000..3d046fc
hw/tpm/tpm_xenstubdoms.c new file +34
-0@@ -0,0 +1,256 @@ +/* +* Xen Stubdom vTPM driver +* +* Copyright (c) 2015 Intel Corporation +* Authors: +* Quan Xu <[email protected]> +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see +<http://www.gnu.org/licenses/> */ + +#include <dirent.h> +#include "qemu-common.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "qemu/log.h" +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "hw/hw.h" +#include "hw/i386/pc.h" +#include "hw/xen/xen_backend.h" +#include "sysemu/tpm_backend_int.h" +#include "tpm_tis.h" +hw/tpm/tpm_xenstubdoms.c line 44
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+#ifdef DEBUG_TPM +#define DPRINTF (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) #else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif + +#define TYPE_TPM_XENSTUBDOMS "tpm-xenstubdoms" +#define TPM_XENSTUBDOMS (obj) \ + OBJECT_CHECK(TPMXenstubdomsState, (obj),
TYPE_TPM_XENSTUBDOMS)Quoted 32 lines
hw/tpm/tpm_xenstubdoms.c new file +32
-0+ +static const TPMDriverOps tpm_xenstubdoms_driver; + +/* Data structures */ +typedef struct TPMXenstubdomsThreadParams { +TPMState *tpm_state; +TPMRecvDataCB *recv_data_callback; +TPMBackend *tb; +}TPMXenstubdomsThreadParams ; + +struct TPMXenstubdomsState { +TPMBackend parent; +TPMBackendThread tbt; +TPMXenstubdomsThreadParams tpm_thread_params; +bool had_startup_error; +}; + +typedef struct TPMXenstubdomsState TPMXenstubdomsState ; + +/* Functions */ +static void tpm_xenstubdoms_cancel_cmd (TPMBackend *tb); + +static int tpm_xenstubdoms_unix_transfer (const TPMLocality +*locty_data) { +size_t rlen; +struct XenDevice *xendev; +int ret; + + xendev =xen_find_xendev ("vtpm" , xen_domid, xenstore_dev); +if (xendev ==NULL ) { +xen_be_printf (xendev,0 ,"Can not find vtpm device.\n" ); +return -1 ;hw/tpm/tpm_xenstubdoms.c
Quoted 10 lines
hw/tpm/tpm_xenstubdoms.c new file +10
-0+ } + + ret =vtpm_send (xendev, locty_data->w_buffer.buffer, + locty_data->r_buffer.size, locty_data->w_offset); +if (ret <0 ) { +xen_be_printf (xendev,0 ,"Can not send vtpm command.\n" ); +return -1 ; + } + + vtpm_recv(xendev, locty_data->r_buffer.buffer,
locty_data->r_buffer.size,hw/tpm/tpm_xenstubdoms.c line 108
Quoted 12 lines
hw/tpm/tpm_xenstubdoms.c new file +12
-0+ &rlen); +return 0 ; +} + +static void tpm_xenstubdoms_worker_thread (gpointer data, +gpointer user_data) { +TPMXenstubdomsThreadParams *thr_parms = user_data; +TPMBackendCmd cmd = (TPMBackendCmd )data; + +switch (cmd) { +case TPM_BACKEND_CMD_PROCESS_CMD : +
tpm_xenstubdoms_unix_transfer(thr_parms->tpm_state->locty_data);
Quoted 6 lines
hw/tpm/tpm_xenstubdoms.c line 100
Quoted 2 lines
hw/tpm/tpm_xenstubdoms.c new file +2
-0+ thr_parms->recv_data_callback(thr_parms->tpm_state, +
thr_parms->tpm_state->locty_number,hw/tpm/tpm_xenstubdoms.c line 103
Quoted 1 line
hw/tpm/tpm_xenstubdoms.c new file +1
-0+ false);Didn't look at this before. I still think you should reorder the patches.
I have rebased these patches against QEMU upstream in v5, but I didn't mention it. I will go through these patches.
Quan
Quoted 4 lines
Rest looks good.
Stefan