qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V22 1/7] Support for TPM command line options


From: Corey Bryant
Subject: Re: [Qemu-devel] [PATCH V22 1/7] Support for TPM command line options
Date: Fri, 15 Feb 2013 09:23:45 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2



On 02/14/2013 04:43 PM, Stefan Berger wrote:
This patch adds support for TPM command line options.
The command line options supported here are

./qemu-... -tpmdev passthrough,path=<path to TPM device>,id=<id>
            -device tpm-tis,tpmdev=<id>

and

./qemu-... -tpmdev help

where the latter works similar to -soundhw ? and shows a list of
available TPM backends (for example 'passthrough').

Using the type parameter, the backend is chosen, i.e., 'passthrough' for the
passthrough driver. The interpretation of the other parameters along
with determining whether enough parameters were provided is pushed into
the backend driver, which needs to implement the interface function
'create' and return a TPMDriver structure if the VM can be started or 'NULL'
if not enough or bad parameters were provided.

Monitor support for 'info tpm' has been added. It for example prints the
following:

(qemu) info tpm
TPM devices:
  tpm0: model=tpm-tis
   \ tpm0: type=passthrough,path=/dev/tpm0

Signed-off-by: Stefan Berger <address@hidden>
---
  Makefile.objs     |   1 +
  hmp-commands.hx   |   2 +
  hmp.c             |  44 +++++++++
  hmp.h             |   1 +
  include/tpm/tpm.h |  21 +++++
  monitor.c         |   8 ++
  qapi-schema.json  |  83 +++++++++++++++++
  qemu-options.hx   |  33 +++++++
  qmp-commands.hx   |  18 ++++
  tpm/Makefile.objs |   1 +
  tpm/tpm.c         | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  tpm/tpm_int.h     |  79 ++++++++++++++++
  tpm/tpm_tis.h     |  78 ++++++++++++++++
  vl.c              |  37 ++++++++
  14 files changed, 678 insertions(+)
  create mode 100644 include/tpm/tpm.h
  create mode 100644 tpm/Makefile.objs
  create mode 100644 tpm/tpm.c
  create mode 100644 tpm/tpm_int.h
  create mode 100644 tpm/tpm_tis.h

diff --git a/Makefile.objs b/Makefile.objs
index 21e9c91..d52ea49 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -74,6 +74,7 @@ common-obj-y += bt-host.o bt-vhci.o
  common-obj-y += dma-helpers.o
  common-obj-y += qtest.o
  common-obj-y += vl.o
+common-obj-y += tpm/

  common-obj-$(CONFIG_SLIRP) += slirp/

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 64008a9..a952fd1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1642,6 +1642,8 @@ show device tree
  show qdev device model list
  @item info roms
  show roms
address@hidden info tpm
+show the TPM device
  @end table
  ETEXI

diff --git a/hmp.c b/hmp.c
index 2f47a8a..b0a861c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -607,6 +607,50 @@ void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
      }
  }

+void hmp_info_tpm(Monitor *mon, const QDict *qdict)
+{
+    TPMInfoList *info_list, *info;
+    Error *err = NULL;
+    unsigned int c = 0;
+    TPMPassthroughOptions *tpo;
+
+    info_list = qmp_query_tpm(&err);
+    if (err) {
+        monitor_printf(mon, "TPM device not supported\n");
+        error_free(err);
+        return;
+    }
+
+    if (info_list) {
+        monitor_printf(mon, "TPM device:\n");
+    }
+
+    for (info = info_list; info; info = info->next) {
+        TPMInfo *ti = info->value;
+        monitor_printf(mon, " tpm%d: model=%s\n",
+                       c, TpmModel_lookup[ti->model]);
+
+        monitor_printf(mon, "  \\ %s: type=%s",
+                       ti->id, TpmType_lookup[ti->type]);
+
+        switch (ti->tpm_options->kind) {
+        case TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH_OPTIONS:
+            tpo = ti->tpm_options->tpm_passthrough_options;
+            monitor_printf(mon, "%s%s%s%s",
+                           tpo->has_path ? ",path=" : "",
+                           tpo->has_path ? tpo->path : "",
+                           tpo->has_cancel_path ? ",cancel-path=" : "",
+                           tpo->has_cancel_path ? tpo->cancel_path : "");
+            break;
+        case TPM_TYPE_OPTIONS_KIND_MAX:
+            break;
+        }
+        monitor_printf(mon, "\n");
+        c++;
+    }
+    qapi_free_TPMInfoList(info_list);
+}
+
  void hmp_quit(Monitor *mon, const QDict *qdict)
  {
      monitor_suspend(mon);
diff --git a/hmp.h b/hmp.h
index 30b3c20..95fe76e 100644
--- a/hmp.h
+++ b/hmp.h
@@ -36,6 +36,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict);
  void hmp_info_balloon(Monitor *mon, const QDict *qdict);
  void hmp_info_pci(Monitor *mon, const QDict *qdict);
  void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
+void hmp_info_tpm(Monitor *mon, const QDict *qdict);
  void hmp_quit(Monitor *mon, const QDict *qdict);
  void hmp_stop(Monitor *mon, const QDict *qdict);
  void hmp_system_reset(Monitor *mon, const QDict *qdict);
diff --git a/include/tpm/tpm.h b/include/tpm/tpm.h
new file mode 100644
index 0000000..cc8f20e
--- /dev/null
+++ b/include/tpm/tpm.h
@@ -0,0 +1,21 @@
+/*
+ * Public TPM functions
+ *
+ * Copyright (C) 2011-2013 IBM Corporation
+ *
+ * Authors:
+ *  Stefan Berger    <address@hidden>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_TPM_H
+#define QEMU_TPM_H
+
+#include "qemu/option.h"
+
+int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
+int tpm_init(void);
+void tpm_cleanup(void);
+
+#endif /* QEMU_TPM_H */
diff --git a/monitor.c b/monitor.c
index 20bd19b..71fbdda 100644
--- a/monitor.c
+++ b/monitor.c
@@ -47,6 +47,7 @@
  #include "migration/migration.h"
  #include "sysemu/kvm.h"
  #include "qemu/acl.h"
+#include "tpm/tpm.h"
  #include "qapi/qmp/qint.h"
  #include "qapi/qmp/qfloat.h"
  #include "qapi/qmp/qlist.h"
@@ -2722,6 +2723,13 @@ static mon_cmd_t info_cmds[] = {
          .mhandler.cmd = do_trace_print_events,
      },
      {
+        .name       = "tpm",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the TPM device",
+        .mhandler.cmd = hmp_info_tpm,
+    },
+    {
          .name       = NULL,
      },
  };
diff --git a/qapi-schema.json b/qapi-schema.json
index 7275b5d..b1ef27d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3184,3 +3184,86 @@
  # Since: 1.4
  ##
  { 'command': 'chardev-remove', 'data': {'id': 'str'} }
+
+##
+# @TpmModel
+#
+# An enumeration of TPM models.
+#
+# @tpm-tis: TPM TIS model
+#
+# Since: 1.5
+##
+{ 'enum': 'TpmModel',
+  'data': [ 'tpm-tis' ] }
+
+##
+# @query-tpm-models:
+#
+# Return a list of supported TPM models
+#
+# Returns: a list of TpmModel
+#
+# Since: 1.5
+##
+{ 'command': 'query-tpm-models', 'returns': ['TpmModel'] }
+
+##
+# @TpmType
+#
+# An enumeration of TPM types.
+#
+# @passthrough: TPM passthrough
+#
+# Since: 1.5
+##
+{ 'enum': 'TpmType',
+  'data': [ 'passthrough' ] }
+
+##
+# @query-tpm-types:
+#
+# Return a list of supported TPM types
+#
+# Returns: a list of TpmType
+#
+# Since: 1.5
+##
+{ 'command': 'query-tpm-types', 'returns': ['TpmType'] }
+
+##
+# @TpmInfo:
+#
+# Information about the TPM
+#
+# @model: The TPM frontend model, i.e., tpm-tis
+#
+# @id: The ID of the TPM
+#
+# @type: The type of TPM backend, i.e., passthrough
+#
+# @path: #optional Path to the TPM backend device
+#
+# @cancel-path: #optional Path to TPM backend device's cancel sysfs entry
+#
+# Since: 1.5
+##
+{ 'type': 'TPMPassthroughOptions', 'data': { '*path':'str', 
'*cancel-path':'str'} }
+
+{ 'union': 'TpmTypeOptions',
+   'data': { 'tpm-passthrough-options'   : 'TPMPassthroughOptions' } }
+
+{ 'type': 'TPMInfo',
+  'data': {'id': 'str', 'model': 'TpmModel', 'type': 'TpmType',
+           'tpm-options': 'TpmTypeOptions' } }

These all look good to me but I think you're going to need individual comments for each union and type.

--
Regards,
Corey Bryan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]