Skip to contentSkip to conversation

Add TPM support to ppc64

PATCH New Stefan Berger 1 participant 4 messages Jan 4, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover Add TPM support to ppc64

The following series of patches adds TPM support for ppc64. The CUSE TPM backend, which is part of the TPM passthrough backend, should be considered for providing a private vTPM to a VM. The series implementing support for this has been posted here:

http://lists.gnu.org/archive/html/qemu-devel/2016-01/msg00086.html

Stefan Berger (3):
Enable PPC64 with TPM support
tpm: remove TPMState usage from backend
tpm: Support TPM for ppc64 using CRQ based interface

 backends/tpm.c               |   5 +-
 configure                    |   3 +-
 hw/tpm/Makefile.objs         |   2 +
 hw/tpm/spapr_vtpm.c          | 541 +++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/spapr_vtpm.h          |  65 ++++++
 hw/tpm/tpm_passthrough.c     |  18 +-
 hw/tpm/tpm_tis.c             |   7 +-
 include/hw/ppc/spapr_vio.h   |   1 +
 include/sysemu/tpm.h         |   1 +
 include/sysemu/tpm_backend.h |  15 +-
 qapi-schema.json             |   6 +-
 11 files changed, 648 insertions(+), 16 deletions(-)
 create mode 100644 hw/tpm/spapr_vtpm.c
 create mode 100644 hw/tpm/spapr_vtpm.h
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/3 Enable PPC64 with TPM support

From: Stefan Berger <[email protected]>

Compile the TPM passthrough device emulation on ppc64.

---
 configure | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
configure +2 -1
index 83b40fc..82ca1b5 100755
@@ -3229,7 +3229,8 @@ fi
 ##########################################
 # TPM passthrough is only on x86 Linux
 
-if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64; then
+if test "$targetos" = Linux && test "$cpu" = i386 -o "$cpu" = x86_64 \
+    -o "$cpu" = ppc64; then
   tpm_passthrough=$tpm
 else
   tpm_passthrough=no
Signature · 1 line
2.4.3
#2 lore raw

PATCH v2 2/3 tpm: remove TPMState usage from backend

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Remove the direct TPMState usage from the TPM backend. This allows different frontends to use the backend. A few more parameters now need to be passed to the backend.

Other frontends may need different TPMState structures if for example the device types they are using are not always visible during compilation. An example is the usage of the PPC64 specific VIOsPAPRDevice whose include files are not all visible to x86 target for example. Therefore, we now pass void * where previously TPMState * was passed.

---
 backends/tpm.c               |  5 +++--
 hw/tpm/tpm_passthrough.c     | 18 ++++++++++++------
 hw/tpm/tpm_tis.c             |  7 +++++--
 include/sysemu/tpm_backend.h | 15 +++++++++++----
 4 files changed, 31 insertions(+), 14 deletions(-)
backends/tpm.c +3 -2
index a512693..33af8a1 100644
@@ -39,12 +39,13 @@ void tpm_backend_destroy(TPMBackend *s)
     k->ops->destroy(s);
 }
 
-int tpm_backend_init(TPMBackend *s, TPMState *state,
+int tpm_backend_init(TPMBackend *s, void *state,
+                     uint8_t *locty_number, TPMLocality **locty_data,
                      TPMRecvDataCB *datacb)
 {
     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
 
-    return k->ops->init(s, state, datacb);
+    return k->ops->init(s, state, locty_number, locty_data, datacb);
 }
 
 int tpm_backend_startup_tpm(TPMBackend *s)
hw/tpm/tpm_passthrough.c +12 -6
index cef3696..50ef15c 100644
@@ -54,7 +54,10 @@ static const VMStateDescription vmstate_tpm_cuse;
 
 /* data structures */
 typedef struct TPMPassthruThreadParams {
-    TPMState *tpm_state;
+    void *tpm_state;
+
+    uint8_t *locty_number;
+    TPMLocality **locty_data;
 
     TPMRecvDataCB *recv_data_callback;
     TPMBackend *tb;
@@ -252,12 +255,12 @@ static void tpm_passthrough_worker_thread(gpointer data,
     switch (cmd) {
     case TPM_BACKEND_CMD_PROCESS_CMD:
         tpm_passthrough_unix_transfer(tpm_pt,
-                                      thr_parms->tpm_state->locty_number,
-                                      thr_parms->tpm_state->locty_data,
+                                      *thr_parms->locty_number,
+                                      *thr_parms->locty_data,
                                       &selftest_done);
 
         thr_parms->recv_data_callback(thr_parms->tpm_state,
-                                      thr_parms->tpm_state->locty_number,
+                                      *thr_parms->locty_number,
                                       selftest_done);
         /* result delivered */
         qemu_mutex_lock(&tpm_pt->state_lock);
@@ -400,12 +403,15 @@ static void tpm_passthrough_reset(TPMBackend *tb)
     tpm_pt->tpm_busy = false;
 }
 
-static int tpm_passthrough_init(TPMBackend *tb, TPMState *s,
+static int tpm_passthrough_init(TPMBackend *tb, void *tpm_state,
+                                uint8_t *locty_number, TPMLocality **locty_data,
                                 TPMRecvDataCB *recv_data_cb)
 {
     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
 
-    tpm_pt->tpm_thread_params.tpm_state = s;
+    tpm_pt->tpm_thread_params.tpm_state = tpm_state;
+    tpm_pt->tpm_thread_params.locty_number = locty_number;
+    tpm_pt->tpm_thread_params.locty_data = locty_data;
     tpm_pt->tpm_thread_params.recv_data_callback = recv_data_cb;
     tpm_pt->tpm_thread_params.tb = tb;
 
hw/tpm/tpm_tis.c +5 -2
index 61b26d1..3b69af4 100644
@@ -395,9 +395,10 @@ static void tpm_tis_receive_bh(void *opaque)
 /*
  * Callback from the TPM to indicate that the response was received.
  */
-static void tpm_tis_receive_cb(TPMState *s, uint8_t locty,
+static void tpm_tis_receive_cb(void *opaque, uint8_t locty,
                                bool is_selftest_done)
 {
+    TPMState *s = opaque;
     TPMTISEmuState *tis = &s->s.tis;
     uint8_t l;
 
@@ -1189,7 +1190,9 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)
 
     s->be_driver->fe_model = TPM_MODEL_TPM_TIS;
 
-    if (tpm_backend_init(s->be_driver, s, tpm_tis_receive_cb)) {
+    if (tpm_backend_init(s->be_driver, s,
+                         &s->locty_number, &s->locty_data,
+                         tpm_tis_receive_cb)) {
         error_setg(errp, "tpm_tis: backend driver with id %s could not be "
                    "initialized", s->backend);
         return;
include/sysemu/tpm_backend.h +11 -4
index 92bc3e4..927254a 100644
@@ -33,6 +33,8 @@ typedef struct TPMBackend TPMBackend;
 
 typedef struct TPMDriverOps TPMDriverOps;
 
+typedef struct TPMLocality TPMLocality;
+
 struct TPMBackendClass {
     ObjectClass parent_class;
 
@@ -56,7 +58,7 @@ struct TPMBackend {
     QLIST_ENTRY(TPMBackend) list;
 };
 
-typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done);
+typedef void (TPMRecvDataCB)(void *, uint8_t locty, bool selftest_done);
 
 typedef struct TPMSizedBuffer {
     uint32_t size;
@@ -85,7 +87,9 @@ struct TPMDriverOps {
     void (*destroy)(TPMBackend *t);
 
     /* initialize the backend */
-    int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
+    int (*init)(TPMBackend *t, void *tpm_state,
+                uint8_t *locty_number, TPMLocality **locty_data,
+                TPMRecvDataCB *datacb);
     /* start up the TPM on the backend */
     int (*startup_tpm)(TPMBackend *t);
     /* returns true if nothing will ever answer TPM requests */
@@ -132,14 +136,17 @@ void tpm_backend_destroy(TPMBackend *s);
 /**
  * tpm_backend_init:
  * @s: the backend to initialized
- * @state: TPMState
+ * @state: opaque pointer to TPM state
+ * @locty_number: pointer to locality_number
+ * @locty_data: pointer to locality_data pointer
  * @datacb: callback for sending data to frontend
  *
  * Initialize the backend with the given variables.
  *
  * Returns 0 on success.
  */
-int tpm_backend_init(TPMBackend *s, TPMState *state,
+int tpm_backend_init(TPMBackend *s, void *state,
+                     uint8_t *locty_number, TPMLocality **locty_data,
                      TPMRecvDataCB *datacb);
 
 /**
Signature · 1 line
2.4.3
#3 lore raw

PATCH v2 3/3 tpm: Support TPM for ppc64 using CRQ based interface

In reply to Stefan Berger

From: Stefan Berger <[email protected]>

Implement support for TPM on ppc64 by implementing the vTPM CRQ interface (following PAPR) as a frontend.

Have the frontend call the existing passthrough TPM device backend using data structures from the TPM TIS hardware interface emulation (tpm_tis.c). The TIS implements a superset of functionality and the vTPM CRQ interface uses part of it, such as only 1 of the 5 localities.

The Linux vTPM driver for ppc64 works with this emulation.

---
 hw/tpm/Makefile.objs       |   2 +
 hw/tpm/spapr_vtpm.c        | 541 +++++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/spapr_vtpm.h        |  65 ++++++
 include/hw/ppc/spapr_vio.h |   1 +
 include/sysemu/tpm.h       |   1 +
 qapi-schema.json           |   6 +-
 6 files changed, 615 insertions(+), 1 deletion(-)
 create mode 100644 hw/tpm/spapr_vtpm.c
 create mode 100644 hw/tpm/spapr_vtpm.h
hw/tpm/Makefile.objs +2 -0
index 64cecc3..f40f31d 100644
@@ -1,2 +1,4 @@
 common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o
 common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o
+
+obj-$(CONFIG_PSERIES) += spapr_vtpm.o
hw/tpm/spapr_vtpm.c new file +541 -0

541 lines not on this page · raw message

hw/tpm/spapr_vtpm.h new file +65 -0

65 lines not on this page · raw message

include/hw/ppc/spapr_vio.h +1 -0
index 2299a54..5efdf4f 100644
@@ -133,6 +133,7 @@ void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len);
 void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev);
 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd);
 void spapr_vscsi_create(VIOsPAPRBus *bus);
+void spapr_vtpm_create(VIOsPAPRBus *bus);
 
 VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus);
 
include/sysemu/tpm.h +1 -0
index c8afa17..45feee3 100644
@@ -27,6 +27,7 @@ typedef enum  TPMVersion {
 } TPMVersion;
 
 TPMVersion tpm_tis_get_tpm_version(Object *obj);
+TPMVersion spapr_vtpm_get_tpm_version(Object *obj);
 
 #define TYPE_TPM_TIS                "tpm-tis"
 
qapi-schema.json +5 -1
index e0ef212..2ab4dad 100644
@@ -3315,8 +3315,12 @@
 # @tpm-tis: TPM TIS model
 #
 # Since: 1.5
+#
+# @spapr-vtpm: PPC64 vTPM device model
+#
+# Since: 2.6
 ##
-{ 'enum': 'TpmModel', 'data': [ 'tpm-tis' ] }
+{ 'enum': 'TpmModel', 'data': [ 'tpm-tis', 'spapr-vtpm' ] }
 
 ##
 # @query-tpm-models:
Signature · 1 line
2.4.3