Skip to contentSkip to conversation

tpm: add mssim backend

PATCH Superseded James Bottomley 4 participants 12 messages Jan 9, 2023 – Sep 26, 2023 Arm/Amlogic Meson SoC support

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover tpm: add mssim backend

From: James Bottomley <[email protected]>

The requested feedback was to convert the tpmdev handler to being json based, which requires rethreading all the backends. The good news is this reduced quite a bit of code (especially as I converted it to error_fatal handling as well, which removes the return status threading). The bad news is I can't test any of the conversions. swtpm still isn't building on opensuse and, apparently, passthrough doesn't like my native TPM because it doesn't allow cancellation.

v3 pulls out more unneeded code in the visitor conversion, makes migration work on external state preservation of the simulator and adds documentation

v4 puts back the wrapper options (but doesn't add any for mssim since it post dates the necessity)

v5 rebases to the latest master branch and adjusts for removed use_FOO ptrs

v5 updates help to exit zero; does some checkpatch tidying

James

---

James Bottomley (2):
tpm: convert tpmdev options processing to new visitor format
tpm: add backend for mssim

 MAINTAINERS                    |   6 +
 backends/tpm/Kconfig           |   5 +
 backends/tpm/meson.build       |   1 +
 backends/tpm/tpm_emulator.c    |  24 +--
 backends/tpm/tpm_mssim.c       | 290 +++++++++++++++++++++++++++++++++
 backends/tpm/tpm_mssim.h       |  44 +++++
 backends/tpm/tpm_passthrough.c |  22 +--
 docs/specs/tpm.rst             |  35 ++++
 include/sysemu/tpm.h           |   4 +-
 include/sysemu/tpm_backend.h   |   2 +-
 monitor/hmp-cmds.c             |   9 +
 qapi/tpm.json                  |  45 ++++-
 softmmu/tpm.c                  |  90 ++++------
 softmmu/vl.c                   |  19 +--
 14 files changed, 488 insertions(+), 108 deletions(-)
 create mode 100644 backends/tpm/tpm_mssim.c
 create mode 100644 backends/tpm/tpm_mssim.h
Signature · 1 line
2.35.3
#1 lore raw

PATCH v6 1/2 tpm: convert tpmdev options processing to new visitor format

From: James Bottomley <[email protected]>

Instead of processing the tpmdev options using the old qemu options, convert to the new visitor format which also allows the passing of json on the command line.

---
v4: add TpmConfiOptions
v5: exit(0) for help

---
 backends/tpm/tpm_emulator.c    | 24 ++++-----
 backends/tpm/tpm_passthrough.c | 22 +++------
 include/sysemu/tpm.h           |  4 +-
 include/sysemu/tpm_backend.h   |  2 +-
 qapi/tpm.json                  | 19 +++++++
 softmmu/tpm.c                  | 90 ++++++++++++++--------------------
 softmmu/vl.c                   | 19 +------
 7 files changed, 75 insertions(+), 105 deletions(-)
backends/tpm/tpm_emulator.c +9 -15
index 49cc3d749d..cb6bf9d7c2 100644
@@ -584,33 +584,28 @@ err_exit:
     return -1;
 }
 
-static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, QemuOpts *opts)
+static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, TpmCreateOptions *opts)
 {
-    const char *value;
     Error *err = NULL;
     Chardev *dev;
 
-    value = qemu_opt_get(opts, "chardev");
-    if (!value) {
-        error_report("tpm-emulator: parameter 'chardev' is missing");
-        goto err;
-    }
+    tpm_emu->options = QAPI_CLONE(TPMEmulatorOptions, &opts->u.emulator);
+    tpm_emu->data_ioc = NULL;
 
-    dev = qemu_chr_find(value);
+    dev = qemu_chr_find(opts->u.emulator.chardev);
     if (!dev) {
-        error_report("tpm-emulator: tpm chardev '%s' not found", value);
+        error_report("tpm-emulator: tpm chardev '%s' not found",
+                opts->u.emulator.chardev);
         goto err;
     }
 
     if (!qemu_chr_fe_init(&tpm_emu->ctrl_chr, dev, &err)) {
         error_prepend(&err, "tpm-emulator: No valid chardev found at '%s':",
-                      value);
+                      opts->u.emulator.chardev);
         error_report_err(err);
         goto err;
     }
 
-    tpm_emu->options->chardev = g_strdup(value);
-
     if (tpm_emulator_prepare_data_fd(tpm_emu) < 0) {
         goto err;
     }
@@ -649,7 +644,7 @@ err:
     return -1;
 }
 
-static TPMBackend *tpm_emulator_create(QemuOpts *opts)
+static TPMBackend *tpm_emulator_create(TpmCreateOptions *opts)
 {
     TPMBackend *tb = TPM_BACKEND(object_new(TYPE_TPM_EMULATOR));
 
@@ -972,7 +967,6 @@ static void tpm_emulator_inst_init(Object *obj)
 
     trace_tpm_emulator_inst_init();
 
-    tpm_emu->options = g_new0(TPMEmulatorOptions, 1);
     tpm_emu->cur_locty_number = ~0;
     qemu_mutex_init(&tpm_emu->mutex);
     tpm_emu->vmstate =
@@ -990,7 +984,7 @@ static void tpm_emulator_shutdown(TPMEmulator *tpm_emu)
 {
     ptm_res res;
 
-    if (!tpm_emu->options->chardev) {
+    if (!tpm_emu->data_ioc) {
         /* was never properly initialized */
         return;
     }
backends/tpm/tpm_passthrough.c +6 -16
index 179697a3a9..3da467ef01 100644
@@ -252,21 +252,12 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)
 }
 
 static int
-tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opts)
+tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, TpmCreateOptions *opts)
 {
-    const char *value;
+    tpm_pt->options = QAPI_CLONE(TPMPassthroughOptions, &opts->u.passthrough);
 
-    value = qemu_opt_get(opts, "cancel-path");
-    if (value) {
-        tpm_pt->options->cancel_path = g_strdup(value);
-    }
-
-    value = qemu_opt_get(opts, "path");
-    if (value) {
-        tpm_pt->options->path = g_strdup(value);
-    }
-
-    tpm_pt->tpm_dev = value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE;
+    tpm_pt->tpm_dev = opts->u.passthrough.path ? opts->u.passthrough.path :
+            TPM_PASSTHROUGH_DEFAULT_DEVICE;
     tpm_pt->tpm_fd = qemu_open_old(tpm_pt->tpm_dev, O_RDWR);
     if (tpm_pt->tpm_fd < 0) {
         error_report("Cannot access TPM device using '%s': %s",
@@ -288,11 +279,11 @@ tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opts)
     return 0;
 }
 
-static TPMBackend *tpm_passthrough_create(QemuOpts *opts)
+static TPMBackend *tpm_passthrough_create(TpmCreateOptions *tco)
 {
     Object *obj = object_new(TYPE_TPM_PASSTHROUGH);
 
-    if (tpm_passthrough_handle_device_opts(TPM_PASSTHROUGH(obj), opts)) {
+    if (tpm_passthrough_handle_device_opts(TPM_PASSTHROUGH(obj), tco)) {
         object_unref(obj);
         return NULL;
     }
@@ -344,7 +335,6 @@ static void tpm_passthrough_inst_init(Object *obj)
 {
     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
 
-    tpm_pt->options = g_new0(TPMPassthroughOptions, 1);
     tpm_pt->tpm_fd = -1;
     tpm_pt->cancel_fd = -1;
 }
include/sysemu/tpm.h +2 -2
index fb40e30ff6..d00a833a21 100644
@@ -17,8 +17,8 @@
 
 #ifdef CONFIG_TPM
 
-int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
-int tpm_init(void);
+void tpm_config_parse(const char *optarg);
+void tpm_init(void);
 void tpm_cleanup(void);
 
 typedef enum TPMVersion {
include/sysemu/tpm_backend.h +1 -1
index 8fd3269c11..846a9e39fa 100644
@@ -57,7 +57,7 @@ struct TPMBackendClass {
     /* get a descriptive text of the backend to display to the user */
     const char *desc;
 
-    TPMBackend *(*create)(QemuOpts *opts);
+    TPMBackend *(*create)(TpmCreateOptions *tco);
 
     /* start up the TPM on the backend - optional */
     int (*startup_tpm)(TPMBackend *t, size_t buffersize);
qapi/tpm.json +19 -0
index 4e2ea9756a..2b491c28b4 100644
@@ -134,6 +134,25 @@
             'emulator': 'TPMEmulatorOptionsWrapper' },
   'if': 'CONFIG_TPM' }
 
+##
+# @TpmCreateOptions:
+#
+# A union referencing different TPM backend types' configuration options
+#   without the wrapper to be usable by visitors.
+#
+# @type: - 'passthrough' The configuration options for the TPM passthrough type
+#        - 'emulator' The configuration options for TPM emulator backend type
+#
+# Since: 7.2
+##
+{ 'union': 'TpmCreateOptions',
+  'base': { 'type': 'TpmType',
+            'id' : 'str' },
+  'discriminator': 'type',
+  'data': { 'passthrough' : 'TPMPassthroughOptions',
+            'emulator': 'TPMEmulatorOptions' },
+  'if': 'CONFIG_TPM' }
+
 ##
 # @TPMInfo:
 #
softmmu/tpm.c +36 -54

146 lines not on this page · raw message

softmmu/vl.c +2 -17
index 798e1dc933..8c2655dbc2 100644
@@ -328,16 +328,6 @@ static QemuOptsList qemu_object_opts = {
     },
 };
 
-static QemuOptsList qemu_tpmdev_opts = {
-    .name = "tpmdev",
-    .implied_opt_name = "type",
-    .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
-    .desc = {
-        /* options are defined in the TPM backends */
-        { /* end of list */ }
-    },
-};
-
 static QemuOptsList qemu_overcommit_opts = {
     .name = "overcommit",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
@@ -1934,9 +1924,7 @@ static void qemu_create_late_backends(void)
 
     object_option_foreach_add(object_create_late);
 
-    if (tpm_init() < 0) {
-        exit(1);
-    }
+    tpm_init();
 
     qemu_opts_foreach(qemu_find_opts("mon"),
                       mon_init_func, NULL, &error_fatal);
@@ -2658,7 +2646,6 @@ void qemu_init(int argc, char **argv)
     qemu_add_opts(&qemu_boot_opts);
     qemu_add_opts(&qemu_add_fd_opts);
     qemu_add_opts(&qemu_object_opts);
-    qemu_add_opts(&qemu_tpmdev_opts);
     qemu_add_opts(&qemu_overcommit_opts);
     qemu_add_opts(&qemu_msg_opts);
     qemu_add_opts(&qemu_name_opts);
@@ -2906,9 +2893,7 @@ void qemu_init(int argc, char **argv)
                 break;
 #ifdef CONFIG_TPM
             case QEMU_OPTION_tpmdev:
-                if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
-                    exit(1);
-                }
+                tpm_config_parse(optarg);
                 break;
 #endif
             case QEMU_OPTION_mempath:
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH v6 1/2] tpm: convert tpmdev options processing to new visitor format

Quoted 7 lines · James Bottomley

From: James Bottomley <[email protected]>

Instead of processing the tpmdev options using the old qemu options, convert to the new visitor format which also allows the passing of json on the command line.

$ ./scripts/checkpatch.pl 0001-tpm-convert-tpmdev-options-processing-to-new-visitor.patch

WARNING: line over 80 characters
#30: FILE: backends/tpm/tpm_emulator.c:586:
+static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, TpmCreateOptions *opts)

WARNING: line over 80 characters
#101: FILE: backends/tpm/tpm_passthrough.c:255:
+tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, TpmCreateOptions *opts)

total: 0 errors, 2 warnings, 340 lines checked

Quoted 32 lines

---
v4: add TpmConfiOptions
v5: exit(0) for help

---
  backends/tpm/tpm_emulator.c    | 24 ++++-----
  backends/tpm/tpm_passthrough.c | 22 +++------
  include/sysemu/tpm.h           |  4 +-
  include/sysemu/tpm_backend.h   |  2 +-
  qapi/tpm.json                  | 19 +++++++
  softmmu/tpm.c                  | 90 ++++++++++++++--------------------
  softmmu/vl.c                   | 19 +------
  7 files changed, 75 insertions(+), 105 deletions(-)
backends/tpm/tpm_emulator.c +1 -6
index 49cc3d749d..cb6bf9d7c2 100644
@@ -584,33 +584,28 @@ err_exit:
      return -1;
  }
 
-static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, QemuOpts *opts)
+static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, TpmCreateOptions *opts)
  {
-    const char *value;
      Error *err = NULL;
      Chardev *dev;
 
-    value = qemu_opt_get(opts, "chardev");
-    if (!value) {
-        error_report("tpm-emulator: parameter 'chardev' is missing");
-        goto err;

backends/tpm/tpm_emulator.c err_exit: · line 598

Quoted 10 lines
backends/tpm/tpm_emulator.c +5 -3
-    }
+    tpm_emu->options = QAPI_CLONE(TPMEmulatorOptions, &opts->u.emulator);
+    tpm_emu->data_ioc = NULL;
 
-    dev = qemu_chr_find(value);
+    dev = qemu_chr_find(opts->u.emulator.chardev);
      if (!dev) {
-        error_report("tpm-emulator: tpm chardev '%s' not found", value);
+        error_report("tpm-emulator: tpm chardev '%s' not found",
+                opts->u.emulator.chardev);

indentation

Quoted 261 lines
backends/tpm/tpm_emulator.c +3 -6
          goto err;
      }
 
      if (!qemu_chr_fe_init(&tpm_emu->ctrl_chr, dev, &err)) {
          error_prepend(&err, "tpm-emulator: No valid chardev found at '%s':",
-                      value);
+                      opts->u.emulator.chardev);
          error_report_err(err);
          goto err;
      }
 
-    tpm_emu->options->chardev = g_strdup(value);
-
      if (tpm_emulator_prepare_data_fd(tpm_emu) < 0) {
          goto err;
      }
@@ -649,7 +644,7 @@ err:
      return -1;
  }
 
-static TPMBackend *tpm_emulator_create(QemuOpts *opts)
+static TPMBackend *tpm_emulator_create(TpmCreateOptions *opts)
  {
      TPMBackend *tb = TPM_BACKEND(object_new(TYPE_TPM_EMULATOR));
 
@@ -972,7 +967,6 @@ static void tpm_emulator_inst_init(Object *obj)
 
      trace_tpm_emulator_inst_init();
 
-    tpm_emu->options = g_new0(TPMEmulatorOptions, 1);
      tpm_emu->cur_locty_number = ~0;
      qemu_mutex_init(&tpm_emu->mutex);
      tpm_emu->vmstate =
@@ -990,7 +984,7 @@ static void tpm_emulator_shutdown(TPMEmulator *tpm_emu)
  {
      ptm_res res;
 
-    if (!tpm_emu->options->chardev) {
+    if (!tpm_emu->data_ioc) {
          /* was never properly initialized */
          return;
      }
backends/tpm/tpm_passthrough.c +6 -16
index 179697a3a9..3da467ef01 100644
@@ -252,21 +252,12 @@ static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)
  }
 
  static int
-tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opts)
+tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, TpmCreateOptions *opts)
  {
-    const char *value;
+    tpm_pt->options = QAPI_CLONE(TPMPassthroughOptions, &opts->u.passthrough);
 
-    value = qemu_opt_get(opts, "cancel-path");
-    if (value) {
-        tpm_pt->options->cancel_path = g_strdup(value);
-    }
-
-    value = qemu_opt_get(opts, "path");
-    if (value) {
-        tpm_pt->options->path = g_strdup(value);
-    }
-
-    tpm_pt->tpm_dev = value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE;
+    tpm_pt->tpm_dev = opts->u.passthrough.path ? opts->u.passthrough.path :
+            TPM_PASSTHROUGH_DEFAULT_DEVICE;
      tpm_pt->tpm_fd = qemu_open_old(tpm_pt->tpm_dev, O_RDWR);
      if (tpm_pt->tpm_fd < 0) {
          error_report("Cannot access TPM device using '%s': %s",
@@ -288,11 +279,11 @@ tpm_passthrough_handle_device_opts(TPMPassthruState *tpm_pt, QemuOpts *opts)
      return 0;
  }
 
-static TPMBackend *tpm_passthrough_create(QemuOpts *opts)
+static TPMBackend *tpm_passthrough_create(TpmCreateOptions *tco)
  {
      Object *obj = object_new(TYPE_TPM_PASSTHROUGH);
 
-    if (tpm_passthrough_handle_device_opts(TPM_PASSTHROUGH(obj), opts)) {
+    if (tpm_passthrough_handle_device_opts(TPM_PASSTHROUGH(obj), tco)) {
          object_unref(obj);
          return NULL;
      }
@@ -344,7 +335,6 @@ static void tpm_passthrough_inst_init(Object *obj)
  {
      TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
 
-    tpm_pt->options = g_new0(TPMPassthroughOptions, 1);
      tpm_pt->tpm_fd = -1;
      tpm_pt->cancel_fd = -1;
  }
include/sysemu/tpm.h +2 -2
index fb40e30ff6..d00a833a21 100644
@@ -17,8 +17,8 @@
 
  #ifdef CONFIG_TPM
 
-int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
-int tpm_init(void);
+void tpm_config_parse(const char *optarg);
+void tpm_init(void);
  void tpm_cleanup(void);
 
  typedef enum TPMVersion {
include/sysemu/tpm_backend.h +1 -1
index 8fd3269c11..846a9e39fa 100644
@@ -57,7 +57,7 @@ struct TPMBackendClass {
      /* get a descriptive text of the backend to display to the user */
      const char *desc;
 
-    TPMBackend *(*create)(QemuOpts *opts);
+    TPMBackend *(*create)(TpmCreateOptions *tco);
 
      /* start up the TPM on the backend - optional */
      int (*startup_tpm)(TPMBackend *t, size_t buffersize);
qapi/tpm.json +19 -0
index 4e2ea9756a..2b491c28b4 100644
@@ -134,6 +134,25 @@
              'emulator': 'TPMEmulatorOptionsWrapper' },
    'if': 'CONFIG_TPM' }
 
+##
+# @TpmCreateOptions:
+#
+# A union referencing different TPM backend types' configuration options
+#   without the wrapper to be usable by visitors.
+#
+# @type: - 'passthrough' The configuration options for the TPM passthrough type
+#        - 'emulator' The configuration options for TPM emulator backend type
+#
+# Since: 7.2
+##
+{ 'union': 'TpmCreateOptions',
+  'base': { 'type': 'TpmType',
+            'id' : 'str' },
+  'discriminator': 'type',
+  'data': { 'passthrough' : 'TPMPassthroughOptions',
+            'emulator': 'TPMEmulatorOptions' },
+  'if': 'CONFIG_TPM' }
+
  ##
  # @TPMInfo:
  #
softmmu/tpm.c +20 -40
index 578563f05a..fa84a53b96 100644
@@ -17,14 +17,26 @@
  #include "qapi/error.h"
  #include "qapi/qapi-commands-tpm.h"
  #include "qapi/qmp/qerror.h"
+#include "qapi/qobject-input-visitor.h"
+#include "qapi/qapi-visit-tpm.h"
  #include "sysemu/tpm_backend.h"
  #include "sysemu/tpm.h"
  #include "qemu/config-file.h"
  #include "qemu/error-report.h"
+#include "qemu/help_option.h"
 
  static QLIST_HEAD(, TPMBackend) tpm_backends =
      QLIST_HEAD_INITIALIZER(tpm_backends);
 
+typedef struct TpmCreateOptionsQueueEntry {
+        TpmCreateOptions *tco;
+        QSIMPLEQ_ENTRY(TpmCreateOptionsQueueEntry) entry;
+} TpmCreateOptionsQueueEntry;
+
+typedef QSIMPLEQ_HEAD(, TpmCreateOptionsQueueEntry) TpmCreateOptionsQueue;
+
+static TpmCreateOptionsQueue tco_queue = QSIMPLEQ_HEAD_INITIALIZER(tco_queue);
+
  static const TPMBackendClass *
  tpm_be_find_by_type(enum TpmType type)
  {
@@ -84,63 +96,31 @@ TPMBackend *qemu_find_tpm_be(const char *id)
      return NULL;
  }
 
-static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
+static void tpm_init_tpmdev(TpmCreateOptions *tco)
  {
-    /*
-     * Use of error_report() in a function with an Error ** parameter
-     * is suspicious.  It is okay here.  The parameter only exists to
-     * make the function usable with qemu_opts_foreach().  It is not
-     * actually used.
-     */
-    const char *value;
-    const char *id;
      const TPMBackendClass *be;
      TPMBackend *drv;
-    Error *local_err = NULL;
-    int i;
 
      if (!QLIST_EMPTY(&tpm_backends)) {
          error_report("Only one TPM is allowed.");
-        return 1;
+        exit(1);
      }
 
-    id = qemu_opts_id(opts);
-    if (id == NULL) {
-        error_report(QERR_MISSING_PARAMETER, "id");
-        return 1;
-    }
-
-    value = qemu_opt_get(opts, "type");
-    if (!value) {
-        error_report(QERR_MISSING_PARAMETER, "type");
-        tpm_display_backend_drivers();
-        return 1;
-    }
-
-    i = qapi_enum_parse(&TpmType_lookup, value, -1, NULL);
-    be = i >= 0 ? tpm_be_find_by_type(i) : NULL;
+    be = tco->type >= 0 ? tpm_be_find_by_type(tco->type) : NULL;
      if (be == NULL) {
          error_report(QERR_INVALID_PARAMETER_VALUE,
                       "type", "a TPM backend type");
          tpm_display_backend_drivers();
-        return 1;
-    }
-
-    /* validate backend specific opts */
-    if (!qemu_opts_validate(opts, be->opts, &local_err)) {
-        error_report_err(local_err);
-        return 1;
+        exit(1);
      }
 
-    drv = be->create(opts);
+    drv = be->create(tco);
      if (!drv) {
-        return 1;
+        exit(1);
      }
 
-    drv->id = g_strdup(id);
+    drv->id = g_strdup(tco->id);
      QLIST_INSERT_HEAD(&tpm_backends, drv, list);
-
-    return 0;
  }
 
  /*
@@ -161,33 +141,35 @@ void tpm_cleanup(void)
   * Initialize the TPM. Process the tpmdev command line options describing the
   * TPM backend.
   */
-int tpm_init(void)
+void tpm_init(void)
  {

softmmu/tpm.c void tpm_cleanup(void) · line 150

Quoted 10 lines
softmmu/tpm.c +4 -5
-    if (qemu_opts_foreach(qemu_find_opts("tpmdev"),
-                          tpm_init_tpmdev, NULL, NULL)) {
-        return -1;
-    }
+    while (!QSIMPLEQ_EMPTY(&tco_queue)) {
+        TpmCreateOptionsQueueEntry *tcoqe = QSIMPLEQ_FIRST(&tco_queue);
 
-    return 0;
+        QSIMPLEQ_REMOVE_HEAD(&tco_queue, entry);
+        tpm_init_tpmdev(tcoqe->tco);

tcoqe->tco and the possible emulator or passthrough specific allocations should probably be also free'ed here.

Quoted 85 lines
softmmu/tpm.c +12 -9
+        g_free(tcoqe);
+    }
  }
 
  /*
   * Parse the TPM configuration options.
   * To display all available TPM backends the user may use '-tpmdev help'
   */
-int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
+void tpm_config_parse(const char *optarg)
  {
-    QemuOpts *opts;
+    Visitor *v;
+    TpmCreateOptionsQueueEntry *tcqe;
 
-    if (!strcmp(optarg, "help")) {
+    if (is_help_option(optarg)) {
          tpm_display_backend_drivers();
-        return -1;
-    }
-    opts = qemu_opts_parse_noisily(opts_list, optarg, true);
-    if (!opts) {
-        return -1;
+        exit(0);
      }
-    return 0;
+    v = qobject_input_visitor_new_str(optarg, "type", &error_fatal);
+    tcqe = g_new(TpmCreateOptionsQueueEntry, 1);
+    visit_type_TpmCreateOptions(v, NULL, &tcqe->tco, &error_fatal);
+    visit_free(v);
+    QSIMPLEQ_INSERT_TAIL(&tco_queue, tcqe, entry);
  }
 
  /*
softmmu/vl.c +2 -17
index 798e1dc933..8c2655dbc2 100644
@@ -328,16 +328,6 @@ static QemuOptsList qemu_object_opts = {
      },
  };
 
-static QemuOptsList qemu_tpmdev_opts = {
-    .name = "tpmdev",
-    .implied_opt_name = "type",
-    .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
-    .desc = {
-        /* options are defined in the TPM backends */
-        { /* end of list */ }
-    },
-};
-
  static QemuOptsList qemu_overcommit_opts = {
      .name = "overcommit",
      .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
@@ -1934,9 +1924,7 @@ static void qemu_create_late_backends(void)
 
      object_option_foreach_add(object_create_late);
 
-    if (tpm_init() < 0) {
-        exit(1);
-    }
+    tpm_init();
 
      qemu_opts_foreach(qemu_find_opts("mon"),
                        mon_init_func, NULL, &error_fatal);
@@ -2658,7 +2646,6 @@ void qemu_init(int argc, char **argv)
      qemu_add_opts(&qemu_boot_opts);
      qemu_add_opts(&qemu_add_fd_opts);
      qemu_add_opts(&qemu_object_opts);
-    qemu_add_opts(&qemu_tpmdev_opts);
      qemu_add_opts(&qemu_overcommit_opts);
      qemu_add_opts(&qemu_msg_opts);
      qemu_add_opts(&qemu_name_opts);
@@ -2906,9 +2893,7 @@ void qemu_init(int argc, char **argv)
                  break;
  #ifdef CONFIG_TPM
              case QEMU_OPTION_tpmdev:
-                if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
-                    exit(1);
-                }
+                tpm_config_parse(optarg);
                  break;
  #endif
              case QEMU_OPTION_mempath:
#3 lore raw

Re: [PATCH v6 1/2] tpm: convert tpmdev options processing to new visitor format

Quoted 10 lines · Stefan Berger
Quoted 7 lines · James Bottomley

From: James Bottomley <[email protected]>

Instead of processing the tpmdev options using the old qemu options, convert to the new visitor format which also allows the passing of json on the command line.

Quoted 7 lines
Quoted 5 lines

+    while (!QSIMPLEQ_EMPTY(&tco_queue)) {
+        TpmCreateOptionsQueueEntry *tcoqe = QSIMPLEQ_FIRST(&tco_queue); -    return 0;
+        QSIMPLEQ_REMOVE_HEAD(&tco_queue, entry);
+        tpm_init_tpmdev(tcoqe->tco);

tcoqe->tco and the possible emulator or passthrough specific allocations should probably be also free'ed here.

Use: qapi_free_TpmCreateOptions(tcoqe->tco);

#4 lore raw

PATCH v6 2/2 tpm: add backend for mssim

In reply to James Bottomley

From: James Bottomley <[email protected]>

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

https://github.com/Microsoft/ms-tpm-20-ref.git

It exports a fairly simple network socket based protocol on two sockets, one for command (default 2321) and one for control (default 2322). This patch adds a simple backend that can speak the mssim protocol over the network. It also allows the two sockets to be specified on the command line. The benefits are twofold: firstly it gives us a backend that actually speaks a standard TPM emulation protocol instead of the linux specific TPM driver format of the current emulated TPM backend and secondly, using the microsoft protocol, the end point of the emulator can be anywhere on the network, facilitating the cloud use case where a central TPM service can be used over a control network.

The implementation does basic control commands like power off/on, but doesn't implement cancellation or startup. The former because cancellation is pretty much useless on a fast operating TPM emulator and the latter because this emulator is designed to be used with OVMF which itself does TPM startup and I wanted to validate that.

To run this, simply download an emulator based on the MS specification (package ibmswtpm2 on openSUSE) and run it, then add these two lines to the qemu command and it will use the emulator.

    -tpmdev mssim,id=tpm0 \
    -device tpm-crb,tpmdev=tpm0 \

to use a remote emulator replace the first line with

    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote','port':'2321'}}"

tpm-tis also works as the backend.

---

v2: convert to SocketAddr json and use qio_channel_socket_connect_sync()
v3: gate control power off by migration state keep control socket disconnected
to test outside influence and add docs.

---
 MAINTAINERS              |   6 +
 backends/tpm/Kconfig     |   5 +
 backends/tpm/meson.build |   1 +
 backends/tpm/tpm_mssim.c | 290 +++++++++++++++++++++++++++++++++++++++
 backends/tpm/tpm_mssim.h |  44 ++++++
 docs/specs/tpm.rst       |  35 +++++
 monitor/hmp-cmds.c       |   9 ++
 qapi/tpm.json            |  28 +++-
 8 files changed, 414 insertions(+), 4 deletions(-)
 create mode 100644 backends/tpm/tpm_mssim.c
 create mode 100644 backends/tpm/tpm_mssim.h
MAINTAINERS +6 -0
index 7a40d4d865..666ca1eb1c 100644
@@ -3063,10 +3063,16 @@ F: include/hw/acpi/tpm.h
 F: include/sysemu/tpm*
 F: qapi/tpm.json
 F: backends/tpm/
+X: backends/tpm/tpm_mssim.*
 F: tests/qtest/*tpm*
 F: docs/specs/tpm.rst
 T: git https://github.com/stefanberger/qemu-tpm.git tpm-next
 
+MSSIM TPM Backend
+M: James Bottomley <[email protected]>
+S: Maintained
+F: backends/tpm/tpm_mssim.*
+
 Checkpatch
 S: Odd Fixes
 F: scripts/checkpatch.pl
backends/tpm/Kconfig +5 -0
index 5d91eb89c2..d6d6fa53e9 100644
@@ -12,3 +12,8 @@ config TPM_EMULATOR
     bool
     default y
     depends on TPM_BACKEND
+
+config TPM_MSSIM
+    bool
+    default y
+    depends on TPM_BACKEND
backends/tpm/meson.build +1 -0
index 7f2503f84e..c7c3c79125 100644
@@ -3,4 +3,5 @@ if have_tpm
   softmmu_ss.add(files('tpm_util.c'))
   softmmu_ss.add(when: 'CONFIG_TPM_PASSTHROUGH', if_true: files('tpm_passthrough.c'))
   softmmu_ss.add(when: 'CONFIG_TPM_EMULATOR', if_true: files('tpm_emulator.c'))
+  softmmu_ss.add(when: 'CONFIG_TPM_MSSIM', if_true: files('tpm_mssim.c'))
 endif
backends/tpm/tpm_mssim.c new file +290 -0

290 lines not on this page · raw message

backends/tpm/tpm_mssim.h new file +44 -0

44 lines not on this page · raw message

docs/specs/tpm.rst +35 -0
index 535912a92b..1398735956 100644
@@ -270,6 +270,38 @@ available as a module (assuming a TPM 2 is passed through):
   /sys/devices/LNXSYSTEM:00/LNXSYBUS:00/MSFT0101:00/tpm/tpm0/pcr-sha256/9
   ...
 
+The QEMU TPM Microsoft Simulator Device
+---------------------------------------
+
+The TCG provides a reference implementation for TPM 2.0 written by
+Microsoft (See `ms-tpm-20-ref`_ on github).  The reference implementation
+starts a network server and listens for TPM commands on port 2321 and
+TPM Platform control commands on port 2322, although these can be
+altered.  The QEMU mssim TPM backend talks to this implementation.  By
+default it connects to the default ports on localhost:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev mssim,id=tpm0 \
+    -device tpm-crb,tpmdev=tpm0
+
+
+Although it can also communicate with a remote host, which must be
+specified as a SocketAddress via json on the command line for each of
+the command and control ports:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':'inet','host':'remote','port':'2321'},'control':{'type':'inet','host':'remote','port':'2322'}}" \
+    -device tpm-crb,tpmdev=tpm0
+
+
+The mssim backend supports snapshotting and migration, but the state
+of the Microsoft Simulator server must be preserved (or the server
+kept running) outside of QEMU for restore to be successful.
+
 The QEMU TPM emulator device
 ----------------------------
 
@@ -526,3 +558,6 @@ the following:
 
 .. _SWTPM protocol:
    https://github.com/stefanberger/swtpm/blob/master/man/man3/swtpm_ioctls.pod
+
+.. _ms-tpm-20-ref:
+   https://github.com/microsoft/ms-tpm-20-ref
monitor/hmp-cmds.c +9 -0
index ed78a87ddd..12482368d0 100644
@@ -731,6 +731,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
     unsigned int c = 0;
     TPMPassthroughOptions *tpo;
     TPMEmulatorOptions *teo;
+    TPMmssimOptions *tmo;
 
     info_list = qmp_query_tpm(&err);
     if (err) {
@@ -764,6 +765,14 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
             teo = ti->options->u.emulator.data;
             monitor_printf(mon, ",chardev=%s", teo->chardev);
             break;
+        case TPM_TYPE_MSSIM:
+            tmo = &ti->options->u.mssim;
+            monitor_printf(mon, ",command=%s:%s,control=%s:%s",
+                           tmo->command->u.inet.host,
+                           tmo->command->u.inet.port,
+                           tmo->control->u.inet.host,
+                           tmo->control->u.inet.port);
+            break;
         case TPM_TYPE__MAX:
             break;
         }
qapi/tpm.json +24 -4
index 2b491c28b4..f9dde35377 100644
@@ -5,6 +5,7 @@
 ##
 # = TPM (trusted platform module) devices
 ##
+{ 'include': 'sockets.json' }
 
 ##
 # @TpmModel:
@@ -49,7 +50,7 @@
 #
 # Since: 1.5
 ##
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim' ],
   'if': 'CONFIG_TPM' }
 
 ##
@@ -64,7 +65,7 @@
 # Example:
 #
 # -> { "execute": "query-tpm-types" }
-# <- { "return": [ "passthrough", "emulator" ] }
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }
 #
 ##
 { 'command': 'query-tpm-types', 'returns': ['TpmType'],
@@ -117,6 +118,22 @@
   'data': { 'data': 'TPMEmulatorOptions' },
   'if': 'CONFIG_TPM' }
 
+##
+# @TPMmssimOptions:
+#
+# Information for the mssim emulator connection
+#
+# @command: command socket for the TPM emulator
+# @control: control socket for the TPM emulator
+#
+# Since: 7.2.0
+##
+{ 'struct': 'TPMmssimOptions',
+  'data': {
+      '*command': 'SocketAddress',
+      '*control': 'SocketAddress' },
+  'if': 'CONFIG_TPM' }
+
 ##
 # @TpmTypeOptions:
 #
@@ -124,6 +141,7 @@
 #
 # @type: - 'passthrough' The configuration options for the TPM passthrough type
 #        - 'emulator' The configuration options for TPM emulator backend type
+#        - 'mssim' The configuration options for TPM emulator mssim type
 #
 # Since: 1.5
 ##
@@ -131,7 +149,8 @@
   'base': { 'type': 'TpmType' },
   'discriminator': 'type',
   'data': { 'passthrough' : 'TPMPassthroughOptionsWrapper',
-            'emulator': 'TPMEmulatorOptionsWrapper' },
+            'emulator': 'TPMEmulatorOptionsWrapper',
+            'mssim' : 'TPMmssimOptions' },
   'if': 'CONFIG_TPM' }
 
 ##
@@ -150,7 +169,8 @@
             'id' : 'str' },
   'discriminator': 'type',
   'data': { 'passthrough' : 'TPMPassthroughOptions',
-            'emulator': 'TPMEmulatorOptions' },
+            'emulator': 'TPMEmulatorOptions',
+            'mssim': 'TPMmssimOptions' },
   'if': 'CONFIG_TPM' }
 
 ##
Signature · 1 line
2.35.3
Acked-by on v6 2/2
#5 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the feature. Stefan, thoughts?

Quoted 39 lines · James Bottomley

From: James Bottomley <[email protected]>

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

https://github.com/Microsoft/ms-tpm-20-ref.git

It exports a fairly simple network socket based protocol on two sockets, one for command (default 2321) and one for control (default 2322). This patch adds a simple backend that can speak the mssim protocol over the network. It also allows the two sockets to be specified on the command line. The benefits are twofold: firstly it gives us a backend that actually speaks a standard TPM emulation protocol instead of the linux specific TPM driver format of the current emulated TPM backend and secondly, using the microsoft protocol, the end point of the emulator can be anywhere on the network, facilitating the cloud use case where a central TPM service can be used over a control network.

The implementation does basic control commands like power off/on, but doesn't implement cancellation or startup. The former because cancellation is pretty much useless on a fast operating TPM emulator and the latter because this emulator is designed to be used with OVMF which itself does TPM startup and I wanted to validate that.

To run this, simply download an emulator based on the MS specification (package ibmswtpm2 on openSUSE) and run it, then add these two lines to the qemu command and it will use the emulator.

    -tpmdev mssim,id=tpm0 \
    -device tpm-crb,tpmdev=tpm0 \

to use a remote emulator replace the first line with

    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote','port':'2321'}}"

tpm-tis also works as the backend.

[...]

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 276

Quoted 12 lines
docs/specs/tpm.rst +4 -0
index 535912a92b..1398735956 100644
@@ -270,6 +270,38 @@ available as a module (assuming a TPM 2 is passed through):
   /sys/devices/LNXSYSTEM:00/LNXSYBUS:00/MSFT0101:00/tpm/tpm0/pcr-sha256/9
...
 
+The QEMU TPM Microsoft Simulator Device
+---------------------------------------
+
+The TCG provides a reference implementation for TPM 2.0 written by

Suggest to copy the cover letter's nice introductory paragraph here:

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

It provides a reference implementation for TPM 2.0 written by

Quoted 5 lines
docs/specs/tpm.rst +5 -0
+Microsoft (See `ms-tpm-20-ref`_ on github).  The reference implementation
+starts a network server and listens for TPM commands on port 2321 and
+TPM Platform control commands on port 2322, although these can be
+altered.  The QEMU mssim TPM backend talks to this implementation.  By
+default it connects to the default ports on localhost:

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 291

Quoted 10 lines
docs/specs/tpm.rst +10 -0
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev mssim,id=tpm0 \
+    -device tpm-crb,tpmdev=tpm0
+
+
+Although it can also communicate with a remote host, which must be
+specified as a SocketAddress via json on the command line for each of

Is the "via JSON" part in "must be specified ... on the command line" correct? I'd expect to be able to use dotted keys as well, like

-tpmdev type=mssim,id=tpm0,command.type=inet,command.host=remote,command.port=2321',control.type=inet,control.host=remote,control.port=2322

Aside: I do recommend management applications stick to JSON.

Quoted 55 lines
docs/specs/tpm.rst +16 -0
+the command and control ports:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':'inet','host':'remote','port':'2321'},'control':{'type':'inet','host':'remote','port':'2322'}}" \
+    -device tpm-crb,tpmdev=tpm0
+
+
+The mssim backend supports snapshotting and migration, but the state
+of the Microsoft Simulator server must be preserved (or the server
+kept running) outside of QEMU for restore to be successful.
+
 The QEMU TPM emulator device
 ----------------------------
@@ -526,3 +558,6 @@ the following:
 
 .. _SWTPM protocol:
    https://github.com/stefanberger/swtpm/blob/master/man/man3/swtpm_ioctls.pod
+
+.. _ms-tpm-20-ref:
+   https://github.com/microsoft/ms-tpm-20-ref
monitor/hmp-cmds.c +9 -0
index ed78a87ddd..12482368d0 100644
@@ -731,6 +731,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
     unsigned int c = 0;
     TPMPassthroughOptions *tpo;
     TPMEmulatorOptions *teo;
+    TPMmssimOptions *tmo;
 
     info_list = qmp_query_tpm(&err);
     if (err) {
@@ -764,6 +765,14 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
             teo = ti->options->u.emulator.data;
             monitor_printf(mon, ",chardev=%s", teo->chardev);
             break;
+        case TPM_TYPE_MSSIM:
+            tmo = &ti->options->u.mssim;
+            monitor_printf(mon, ",command=%s:%s,control=%s:%s",
+                           tmo->command->u.inet.host,
+                           tmo->command->u.inet.port,
+                           tmo->control->u.inet.host,
+                           tmo->control->u.inet.port);
+            break;
         case TPM_TYPE__MAX:
             break;
         }
qapi/tpm.json +0 -0
index 2b491c28b4..f9dde35377 100644

qapi/tpm.json line 7

Quoted 3 lines
qapi/tpm.json +0 -0
@@ -5,6 +5,7 @@
 ##
 # = TPM (trusted platform module) devices
 ##

Blank line, please.

qapi/tpm.json

Quoted 5 lines
qapi/tpm.json +1 -0
+{ 'include': 'sockets.json' }
 
 ##
 # @TpmModel:
@@ -49,7 +50,7 @@

#
# @passthrough: TPM passthrough type
#
# @emulator: Software Emulator TPM type (since 2.11)

qapi/tpm.json line 50

Quoted 1 line
qapi/tpm.json +0 -0
 #

Missing member documentation:

# @mssim: <brief description here> (since 8.2)

qapi/tpm.json line 68

Quoted 13 lines
qapi/tpm.json +2 -2
 # Since: 1.5
 ##
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim' ],
   'if': 'CONFIG_TPM' }
 
 ##
@@ -64,7 +65,7 @@
 # Example:
 #
 # -> { "execute": "query-tpm-types" }
-# <- { "return": [ "passthrough", "emulator" ] }
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }

Thanks for updating the example.

qapi/tpm.json line 122

Quoted 9 lines
qapi/tpm.json +2 -0
 #
 ##
 { 'command': 'query-tpm-types', 'returns': ['TpmType'],
@@ -117,6 +118,22 @@
   'data': { 'data': 'TPMEmulatorOptions' },
   'if': 'CONFIG_TPM' }
 
+##
+# @TPMmssimOptions:

Please capitalize similar to TPMPassthroughOptions and
TPMEmulatorOptions: TPMMssimOptions.

qapi/tpm.json line 126

Quoted 4 lines
qapi/tpm.json +4 -0
+#
+# Information for the mssim emulator connection
+#
+# @command: command socket for the TPM emulator

Blank line, please.

qapi/tpm.json line 129

Quoted 3 lines
qapi/tpm.json +3 -0
+# @control: control socket for the TPM emulator
+#
+# Since: 7.2.0

Since 8.2

qapi/tpm.json line 134

Quoted 5 lines
qapi/tpm.json +5 -0
+##
+{ 'struct': 'TPMmssimOptions',
+  'data': {
+      '*command': 'SocketAddress',
+      '*control': 'SocketAddress' },

Locally consistent indentation is

     'data': { '*command': 'SocketAddress',
               '*control': 'SocketAddress' },
Quoted 24 lines
qapi/tpm.json +5 -1
+  'if': 'CONFIG_TPM' }
+
 ##
 # @TpmTypeOptions:
 #
@@ -124,6 +141,7 @@
 #
 # @type: - 'passthrough' The configuration options for the TPM passthrough type
 #        - 'emulator' The configuration options for TPM emulator backend type
+#        - 'mssim' The configuration options for TPM emulator mssim type
 #
 # Since: 1.5
 ##
@@ -131,7 +149,8 @@
   'base': { 'type': 'TpmType' },
   'discriminator': 'type',
   'data': { 'passthrough' : 'TPMPassthroughOptionsWrapper',
-            'emulator': 'TPMEmulatorOptionsWrapper' },
+            'emulator': 'TPMEmulatorOptionsWrapper',
+            'mssim' : 'TPMmssimOptions' },
   'if': 'CONFIG_TPM' }
 
 ##

qapi/tpm.json line 176

Quoted 9 lines
qapi/tpm.json +2 -1
@@ -150,7 +169,8 @@
             'id' : 'str' },
   'discriminator': 'type',
   'data': { 'passthrough' : 'TPMPassthroughOptions',
-            'emulator': 'TPMEmulatorOptions' },
+            'emulator': 'TPMEmulatorOptions',
+            'mssim': 'TPMmssimOptions' },
   'if': 'CONFIG_TPM' }
 
 ##

Address my nitpicking, and you may add

#6 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Quoted 4 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the feature. Stefan, thoughts?

I thought we discusses it back then. Does it handle snapshotting and migration correctly?

  Stefan

Quoted 245 lines
Quoted 39 lines · James Bottomley

From: James Bottomley <[email protected]>

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

https://github.com/Microsoft/ms-tpm-20-ref.git

It exports a fairly simple network socket based protocol on two sockets, one for command (default 2321) and one for control (default 2322). This patch adds a simple backend that can speak the mssim protocol over the network. It also allows the two sockets to be specified on the command line. The benefits are twofold: firstly it gives us a backend that actually speaks a standard TPM emulation protocol instead of the linux specific TPM driver format of the current emulated TPM backend and secondly, using the microsoft protocol, the end point of the emulator can be anywhere on the network, facilitating the cloud use case where a central TPM service can be used over a control network.

The implementation does basic control commands like power off/on, but doesn't implement cancellation or startup. The former because cancellation is pretty much useless on a fast operating TPM emulator and the latter because this emulator is designed to be used with OVMF which itself does TPM startup and I wanted to validate that.

To run this, simply download an emulator based on the MS specification (package ibmswtpm2 on openSUSE) and run it, then add these two lines to the qemu command and it will use the emulator.

     -tpmdev mssim,id=tpm0 \
     -device tpm-crb,tpmdev=tpm0 \

to use a remote emulator replace the first line with

     -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote','port':'2321'}}"

tpm-tis also works as the backend.

[...]

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 276

Quoted 12 lines
docs/specs/tpm.rst +4 -0
index 535912a92b..1398735956 100644
@@ -270,6 +270,38 @@ available as a module (assuming a TPM 2 is passed through):
    /sys/devices/LNXSYSTEM:00/LNXSYBUS:00/MSFT0101:00/tpm/tpm0/pcr-sha256/9
...
 
+The QEMU TPM Microsoft Simulator Device
+---------------------------------------
+
+The TCG provides a reference implementation for TPM 2.0 written by

Suggest to copy the cover letter's nice introductory paragraph here:

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

It provides a reference implementation for TPM 2.0 written by

Quoted 5 lines
docs/specs/tpm.rst +5 -0
+Microsoft (See `ms-tpm-20-ref`_ on github).  The reference implementation
+starts a network server and listens for TPM commands on port 2321 and
+TPM Platform control commands on port 2322, although these can be
+altered.  The QEMU mssim TPM backend talks to this implementation.  By
+default it connects to the default ports on localhost:

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 291

Quoted 10 lines
docs/specs/tpm.rst +10 -0
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev mssim,id=tpm0 \
+    -device tpm-crb,tpmdev=tpm0
+
+
+Although it can also communicate with a remote host, which must be
+specified as a SocketAddress via json on the command line for each of

Is the "via JSON" part in "must be specified ... on the command line" correct? I'd expect to be able to use dotted keys as well, like

-tpmdev type=mssim,id=tpm0,command.type=inet,command.host=remote,command.port=2321',control.type=inet,control.host=remote,control.port=2322

Aside: I do recommend management applications stick to JSON.

Quoted 55 lines
docs/specs/tpm.rst +16 -0
+the command and control ports:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':'inet','host':'remote','port':'2321'},'control':{'type':'inet','host':'remote','port':'2322'}}" \
+    -device tpm-crb,tpmdev=tpm0
+
+
+The mssim backend supports snapshotting and migration, but the state
+of the Microsoft Simulator server must be preserved (or the server
+kept running) outside of QEMU for restore to be successful.
+
  The QEMU TPM emulator device
  ----------------------------
@@ -526,3 +558,6 @@ the following:
 
  .. _SWTPM protocol:
     https://github.com/stefanberger/swtpm/blob/master/man/man3/swtpm_ioctls.pod
+
+.. _ms-tpm-20-ref:
+   https://github.com/microsoft/ms-tpm-20-ref
monitor/hmp-cmds.c +9 -0
index ed78a87ddd..12482368d0 100644
@@ -731,6 +731,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
      unsigned int c = 0;
      TPMPassthroughOptions *tpo;
      TPMEmulatorOptions *teo;
+    TPMmssimOptions *tmo;
 
      info_list = qmp_query_tpm(&err);
      if (err) {
@@ -764,6 +765,14 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
              teo = ti->options->u.emulator.data;
              monitor_printf(mon, ",chardev=%s", teo->chardev);
              break;
+        case TPM_TYPE_MSSIM:
+            tmo = &ti->options->u.mssim;
+            monitor_printf(mon, ",command=%s:%s,control=%s:%s",
+                           tmo->command->u.inet.host,
+                           tmo->command->u.inet.port,
+                           tmo->control->u.inet.host,
+                           tmo->control->u.inet.port);
+            break;
          case TPM_TYPE__MAX:
              break;
          }
qapi/tpm.json +0 -0
index 2b491c28b4..f9dde35377 100644

qapi/tpm.json line 7

Quoted 3 lines
qapi/tpm.json +0 -0
@@ -5,6 +5,7 @@
  ##
  # = TPM (trusted platform module) devices
  ##

Blank line, please.

qapi/tpm.json

Quoted 5 lines
qapi/tpm.json +1 -0
+{ 'include': 'sockets.json' }
 
  ##
  # @TpmModel:
@@ -49,7 +50,7 @@

#
# @passthrough: TPM passthrough type
#
# @emulator: Software Emulator TPM type (since 2.11)

qapi/tpm.json line 50

Quoted 1 line
qapi/tpm.json +0 -0
  #

Missing member documentation:

# @mssim: <brief description here> (since 8.2)

qapi/tpm.json line 68

Quoted 13 lines
qapi/tpm.json +2 -2
  # Since: 1.5
  ##
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim' ],
    'if': 'CONFIG_TPM' }
 
  ##
@@ -64,7 +65,7 @@
  # Example:
  #
  # -> { "execute": "query-tpm-types" }
-# <- { "return": [ "passthrough", "emulator" ] }
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }

Thanks for updating the example.

qapi/tpm.json line 122

Quoted 9 lines
qapi/tpm.json +2 -0
  #
  ##
  { 'command': 'query-tpm-types', 'returns': ['TpmType'],
@@ -117,6 +118,22 @@
    'data': { 'data': 'TPMEmulatorOptions' },
    'if': 'CONFIG_TPM' }
 
+##
+# @TPMmssimOptions:

Please capitalize similar to TPMPassthroughOptions and
TPMEmulatorOptions: TPMMssimOptions.

qapi/tpm.json line 126

Quoted 4 lines
qapi/tpm.json +4 -0
+#
+# Information for the mssim emulator connection
+#
+# @command: command socket for the TPM emulator

Blank line, please.

qapi/tpm.json line 129

Quoted 3 lines
qapi/tpm.json +3 -0
+# @control: control socket for the TPM emulator
+#
+# Since: 7.2.0

Since 8.2

qapi/tpm.json line 134

Quoted 5 lines
qapi/tpm.json +5 -0
+##
+{ 'struct': 'TPMmssimOptions',
+  'data': {
+      '*command': 'SocketAddress',
+      '*control': 'SocketAddress' },

Locally consistent indentation is

      'data': { '*command': 'SocketAddress',
                '*control': 'SocketAddress' },
Quoted 24 lines
qapi/tpm.json +5 -1
+  'if': 'CONFIG_TPM' }
+
  ##
  # @TpmTypeOptions:
  #
@@ -124,6 +141,7 @@
  #
  # @type: - 'passthrough' The configuration options for the TPM passthrough type
  #        - 'emulator' The configuration options for TPM emulator backend type
+#        - 'mssim' The configuration options for TPM emulator mssim type
  #
  # Since: 1.5
  ##
@@ -131,7 +149,8 @@
    'base': { 'type': 'TpmType' },
    'discriminator': 'type',
    'data': { 'passthrough' : 'TPMPassthroughOptionsWrapper',
-            'emulator': 'TPMEmulatorOptionsWrapper' },
+            'emulator': 'TPMEmulatorOptionsWrapper',
+            'mssim' : 'TPMmssimOptions' },
    'if': 'CONFIG_TPM' }
 
  ##

qapi/tpm.json line 176

Quoted 9 lines
qapi/tpm.json +2 -1
@@ -150,7 +169,8 @@
              'id' : 'str' },
    'discriminator': 'type',
    'data': { 'passthrough' : 'TPMPassthroughOptions',
-            'emulator': 'TPMEmulatorOptions' },
+            'emulator': 'TPMEmulatorOptions',
+            'mssim': 'TPMmssimOptions' },
    'if': 'CONFIG_TPM' }
 
  ##

Address my nitpicking, and you may add

#7 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Quoted 9 lines · Stefan Berger
Quoted 4 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the feature. Stefan, thoughts?

I thought we discusses it back then. Does it handle snapshotting and migration correctly?

To quote the patch itself:

+The mssim backend supports snapshotting and migration, but the state +of the Microsoft Simulator server must be preserved (or the server +kept running) outside of QEMU for restore to be successful.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Quoted 6 lines · Daniel P. Berrangé
Quoted 5 lines · Stefan Berger
Quoted 4 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the feature. Stefan, thoughts?

Quoted 7 lines
Quoted 2 lines

I thought we discusses it back then. Does it handle snapshotting and migration correctly?

To quote the patch itself:

+The mssim backend supports snapshotting and migration, but the state +of the Microsoft Simulator server must be preserved (or the server +kept running) outside of QEMU for restore to be successful.

How does 'it' support snapshotting where the state of the TPM can be completely different depending on the snapshot?  I know what it took to support this feature with swtpm/libtpms but I don't see the equivalent here in this backend driver nor in the TCG reference code that the underlying TPM 2 simulator is based upon.

I do not want to stand in the way of it being merged but please understand that I will also neither maintain nor fix bugs related to it nor its related underlying simulator -- with James being the maintainer of it, this should be clear. I have reason why I am saying this and they come from dealing with the upstream TPM 2 reference code.

Thanks,

  Stefan

Quoted 3 lines

With regards,
Daniel

#9 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Quoted 13 lines · Stefan Berger
Quoted 11 lines · Daniel P. Berrangé
Quoted 8 lines · Stefan Berger
Quoted 5 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the feature.  Stefan, thoughts?

I thought we discusses it back then. Does it handle snapshotting and migration correctly?

To quote the patch itself:

Quoted 8 lines
Quoted 5 lines

   +The mssim backend supports snapshotting and migration, but the state
   +of the Microsoft Simulator server must be preserved (or the server
   +kept running) outside of QEMU for restore to be successful.

How does 'it' support snapshotting where the state of the TPM can be completely different depending on the snapshot?

In the same way we support things like external disk devices across snapshot and migration: it's up to the owner of the device to preserve the state for the next resume. If you muck with the state (or connect the wrong device) all bets are off.

Quoted 10 lines

  I know what it took to support this feature with swtpm/libtpms but I don't see the equivalent here in this backend driver nor in the TCG reference code that the underlying TPM 2 simulator is based upon.

I do not want to stand in the way of it being merged but please understand that I will also neither maintain nor fix bugs related to it nor its related underlying simulator -- with James being the maintainer of it, this should be clear. I have reason why I am saying this and they come from dealing with the upstream TPM 2 reference code.

I already said I'll support this, and added a Maintainers entry and a specific exclusion from your TPM maintainer entry. I'm not sure what additional assurances I can give?

James

#10 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

In reply to Markus Armbruster
Quoted 78 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the
feature.  Stefan, thoughts?

Quoted 49 lines · James Bottomley

From: James Bottomley <[email protected]>

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

https://github.com/Microsoft/ms-tpm-20-ref.git

It exports a fairly simple network socket based protocol on two sockets, one for command (default 2321) and one for control (default
2322).  This patch adds a simple backend that can speak the mssim protocol over the network.  It also allows the two sockets to be specified on the command line.  The benefits are twofold: firstly it
gives us a backend that actually speaks a standard TPM emulation protocol instead of the linux specific TPM driver format of the current emulated TPM backend and secondly, using the microsoft protocol, the end point of the emulator can be anywhere on the network, facilitating the cloud use case where a central TPM service
can be used over a control network.

The implementation does basic control commands like power off/on, but
doesn't implement cancellation or startup.  The former because cancellation is pretty much useless on a fast operating TPM emulator
and the latter because this emulator is designed to be used with OVMF
which itself does TPM startup and I wanted to validate that.

To run this, simply download an emulator based on the MS specification
(package ibmswtpm2 on openSUSE) and run it, then add these two lines
to the qemu command and it will use the emulator.

    -tpmdev mssim,id=tpm0 \
    -device tpm-crb,tpmdev=tpm0 \

to use a remote emulator replace the first line with

    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote' ,'port':'2321'}}"

tpm-tis also works as the backend.

[...]

Quoted 10 lines
docs/specs/tpm.rst +0 -0
index 535912a92b..1398735956 100644
@@ -270,6 +270,38 @@ available as a module (assuming a TPM 2 is

passed through):
   /sys/devices/LNXSYSTEM:00/LNXSYBUS:00/MSFT0101:00/tpm/tpm0/pcr- sha256/9
   ...

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 276

Quoted 4 lines
docs/specs/tpm.rst +4 -0
+The QEMU TPM Microsoft Simulator Device
+---------------------------------------
+
+The TCG provides a reference implementation for TPM 2.0 written by

Suggest to copy the cover letter's nice introductory paragraph here:

Quoted 4 lines

  The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

  It provides a reference implementation for TPM 2.0 written by

Sure, that's easy.

Quoted 23 lines
Quoted 18 lines

+Microsoft (See ms-tpm-20-ref_ on github).  The reference implementation
+starts a network server and listens for TPM commands on port 2321 and

docs/specs/tpm.rst +2 -0
+TPM Platform control commands on port 2322, although these can be
+altered.  The QEMU mssim TPM backend talks to this

implementation.  By

docs/specs/tpm.rst +11 -0
+default it connects to the default ports on localhost:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev mssim,id=tpm0 \
+    -device tpm-crb,tpmdev=tpm0
+
+
+Although it can also communicate with a remote host, which must be
+specified as a SocketAddress via json on the command line for each
Quoted 1 line

of

Is the "via JSON" part in "must be specified ... on the command line" correct?  I'd expect to be able to use dotted keys as well, like

Quoted 3 lines

    -tpmdev type=mssim,id=tpm0,command.type=inet,command.host=remote,command.port =2321',control.type=inet,control.host=remote,control.port=2322

Yes, I've verified that the dot notation works as well. However, I thought QEMU was calling all stuff like this JSON notation? If not, what do you usually call it? "json or dot notation"?

Quoted 103 lines

Aside: I do recommend management applications stick to JSON.

Quoted 62 lines
docs/specs/tpm.rst +6 -0
+the command and control ports:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev

"{'type':'mssim','id':'tpm0','command':{'type':'inet','host':'remot e','port':'2321'},'control':{'type':'inet','host':'remote','port':' 2322'}}" \
+    -device tpm-crb,tpmdev=tpm0

docs/specs/tpm.rst +3 -0
+
+
+The mssim backend supports snapshotting and migration, but the

state

docs/specs/tpm.rst +3 -0
+of the Microsoft Simulator server must be preserved (or the server
+kept running) outside of QEMU for restore to be successful.
+

 The QEMU TPM emulator device
 ----------------------------

docs/specs/tpm.rst +0 -0
@@ -526,3 +558,6 @@ the following:


 .. _SWTPM protocol:

https://github.com/stefanberger/swtpm/blob/master/man/man3/swtpm_ioctls.pod

docs/specs/tpm.rst +3 -0
+
+.. _ms-tpm-20-ref:
+   https://github.com/microsoft/ms-tpm-20-ref
monitor/hmp-cmds.c +1 -0
index ed78a87ddd..12482368d0 100644
@@ -731,6 +731,7 @@ void hmp_info_tpm(Monitor *mon, const QDict
 *qdict)
      unsigned int c = 0;
      TPMPassthroughOptions *tpo;
      TPMEmulatorOptions *teo;
+    TPMmssimOptions *tmo;


     info_list = qmp_query_tpm(&err);
     if (err) {

monitor/hmp-cmds.c +8 -0
@@ -764,6 +765,14 @@ void hmp_info_tpm(Monitor *mon, const QDict
 *qdict)
              teo = ti->options->u.emulator.data;
              monitor_printf(mon, ",chardev=%s", teo->chardev);
              break;
+        case TPM_TYPE_MSSIM:
+            tmo = &ti->options->u.mssim;
+            monitor_printf(mon, ",command=%s:%s,control=%s:%s",
+                           tmo->command->u.inet.host,
+                           tmo->command->u.inet.port,
+                           tmo->control->u.inet.host,
+                           tmo->control->u.inet.port);
+            break;

         case TPM_TYPE__MAX:
             break;
         }

qapi/tpm.json +0 -0
index 2b491c28b4..f9dde35377 100644

qapi/tpm.json line 7

Quoted 3 lines
qapi/tpm.json +0 -0
@@ -5,6 +5,7 @@
  ##
  # = TPM (trusted platform module) devices
  ##

Blank line, please.

qapi/tpm.json

Quoted 5 lines
qapi/tpm.json +1 -0
+{ 'include': 'sockets.json' }


 ##
 # @TpmModel:

qapi/tpm.json +0 -0
@@ -49,7 +50,7 @@

   #
   # @passthrough: TPM passthrough type
   #
   # @emulator: Software Emulator TPM type (since 2.11)

qapi/tpm.json line 50

Quoted 1 line
qapi/tpm.json +0 -0
  #

Missing member documentation:

   # @mssim: <brief description here> (since 8.2)

Quoted 9 lines
qapi/tpm.json +1 -1
  # Since: 1.5
  ##
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim'
 ],
    'if': 'CONFIG_TPM' }


 ##

qapi/tpm.json line 68

Quoted 5 lines
qapi/tpm.json +1 -1
@@ -64,7 +65,7 @@
  # Example:
  #
  # -> { "execute": "query-tpm-types" }
-# <- { "return": [ "passthrough", "emulator" ] }
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }

Thanks for updating the example.

Quoted 12 lines

qapi/tpm.json line 122

Quoted 9 lines
qapi/tpm.json +0 -0
  #
  ##
  { 'command': 'query-tpm-types', 'returns': ['TpmType'],
@@ -117,6 +118,22 @@
    'data': { 'data': 'TPMEmulatorOptions' },
    'if': 'CONFIG_TPM' }

qapi/tpm.json +2 -0
+##
+# @TPMmssimOptions:

Please capitalize similar to TPMPassthroughOptions and
TPMEmulatorOptions: TPMMssimOptions.

OK

Quoted 7 lines

qapi/tpm.json line 126

Quoted 5 lines
qapi/tpm.json +4 -0
+#
+# Information for the mssim emulator connection
+#
+# @command: command socket for the TPM emulator

Blank line, please.

OK

Quoted 6 lines

qapi/tpm.json line 129

Quoted 4 lines
qapi/tpm.json +3 -0
+# @control: control socket for the TPM emulator
+#
+# Since: 7.2.0

Since 8.2

Heh, yes, that keeps creeping with every release ..

Quoted 51 lines

qapi/tpm.json line 134

Quoted 6 lines
qapi/tpm.json +5 -0
+##
+{ 'struct': 'TPMmssimOptions',
+  'data': {
+      '*command': 'SocketAddress',
+      '*control': 'SocketAddress' },

Locally consistent indentation is

     'data': { '*command': 'SocketAddress',
               '*control': 'SocketAddress' },

Quoted 34 lines

+  'if': 'CONFIG_TPM' }
+
 ##
 # @TpmTypeOptions:
 #

qapi/tpm.json +0 -0
@@ -124,6 +141,7 @@
  #
  # @type: - 'passthrough' The configuration options for the TPM

passthrough type
 #        - 'emulator' The configuration options for TPM emulator backend type
+#        - 'mssim' The configuration options for TPM emulator mssim type
 #
 # Since: 1.5
 ##

qapi/tpm.json +2 -1
@@ -131,7 +149,8 @@
    'base': { 'type': 'TpmType' },
    'discriminator': 'type',
    'data': { 'passthrough' : 'TPMPassthroughOptionsWrapper',
-            'emulator': 'TPMEmulatorOptionsWrapper' },
+            'emulator': 'TPMEmulatorOptionsWrapper',
+            'mssim' : 'TPMmssimOptions' },
    'if': 'CONFIG_TPM' }


 ##

qapi/tpm.json +2 -1
@@ -150,7 +169,8 @@
              'id' : 'str' },
    'discriminator': 'type',
    'data': { 'passthrough' : 'TPMPassthroughOptions',
-            'emulator': 'TPMEmulatorOptions' },
+            'emulator': 'TPMEmulatorOptions',
+            'mssim': 'TPMmssimOptions' },
    'if': 'CONFIG_TPM' }
Quoted 2 lines


 ##

Address my nitpicking, and you may add

Quoted 1 line

James

#11 lore raw

Re: [PATCH v6 2/2] tpm: add backend for mssim

Quoted 109 lines · James Bottomley
Quoted 78 lines · Markus Armbruster

Found this cleaning out old mail, sorry for missing it until now!

I think we owe James a quick decision wether we're willing to take the
feature.  Stefan, thoughts?

Quoted 49 lines · James Bottomley

From: James Bottomley <[email protected]>

The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

https://github.com/Microsoft/ms-tpm-20-ref.git

It exports a fairly simple network socket based protocol on two sockets, one for command (default 2321) and one for control (default
2322).  This patch adds a simple backend that can speak the mssim protocol over the network.  It also allows the two sockets to be specified on the command line.  The benefits are twofold: firstly it
gives us a backend that actually speaks a standard TPM emulation protocol instead of the linux specific TPM driver format of the current emulated TPM backend and secondly, using the microsoft protocol, the end point of the emulator can be anywhere on the network, facilitating the cloud use case where a central TPM service
can be used over a control network.

The implementation does basic control commands like power off/on, but
doesn't implement cancellation or startup.  The former because cancellation is pretty much useless on a fast operating TPM emulator
and the latter because this emulator is designed to be used with OVMF
which itself does TPM startup and I wanted to validate that.

To run this, simply download an emulator based on the MS specification
(package ibmswtpm2 on openSUSE) and run it, then add these two lines
to the qemu command and it will use the emulator.

    -tpmdev mssim,id=tpm0 \
    -device tpm-crb,tpmdev=tpm0 \

to use a remote emulator replace the first line with

    -tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote' ,'port':'2321'}}"

tpm-tis also works as the backend.

[...]

Quoted 10 lines
docs/specs/tpm.rst +0 -0
index 535912a92b..1398735956 100644
@@ -270,6 +270,38 @@ available as a module (assuming a TPM 2 is

passed through):
   /sys/devices/LNXSYSTEM:00/LNXSYBUS:00/MSFT0101:00/tpm/tpm0/pcr- sha256/9
   ...

docs/specs/tpm.rst available as a module (assuming a TPM 2 is passed through): · line 276

Quoted 4 lines
docs/specs/tpm.rst +4 -0
+The QEMU TPM Microsoft Simulator Device
+---------------------------------------
+
+The TCG provides a reference implementation for TPM 2.0 written by

Suggest to copy the cover letter's nice introductory paragraph here:

Quoted 4 lines

  The Microsoft Simulator (mssim) is the reference emulation platform for the TCG TPM 2.0 specification.

  It provides a reference implementation for TPM 2.0 written by

Sure, that's easy.

Quoted 23 lines
Quoted 18 lines

+Microsoft (See ms-tpm-20-ref_ on github).  The reference implementation
+starts a network server and listens for TPM commands on port 2321 and

docs/specs/tpm.rst +2 -0
+TPM Platform control commands on port 2322, although these can be
+altered.  The QEMU mssim TPM backend talks to this

implementation.  By

docs/specs/tpm.rst +11 -0
+default it connects to the default ports on localhost:
+
+.. code-block:: console
+
+  qemu-system-x86_64 <qemu-options> \
+    -tpmdev mssim,id=tpm0 \
+    -device tpm-crb,tpmdev=tpm0
+
+
+Although it can also communicate with a remote host, which must be
+specified as a SocketAddress via json on the command line for each
Quoted 1 line

of

Is the "via JSON" part in "must be specified ... on the command line" correct?  I'd expect to be able to use dotted keys as well, like

Quoted 7 lines
Quoted 3 lines

    -tpmdev type=mssim,id=tpm0,command.type=inet,command.host=remote,command.port =2321',control.type=inet,control.host=remote,control.port=2322

Yes, I've verified that the dot notation works as well. However, I thought QEMU was calling all stuff like this JSON notation? If not, what do you usually call it? "json or dot notation"?

Our terminology is a bit fuzzy there. We commonly say "dotted keys" (although that's just the part left of the = strictly speaking) or "key=value,...".

Quoted 1 line
Quoted 1 line

Aside: I do recommend management applications stick to JSON.

[...]