From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org
Cc: andreas.niederl@iaik.tugraz.at
Subject: [Qemu-devel] [PATCH V2 1/9] Support for TPM command line options
Date: Wed, 30 Mar 2011 15:42:12 -0400 [thread overview]
Message-ID: <20110330194235.935788784@linux.vnet.ibm.com> (raw)
In-Reply-To: 20110330194211.732385449@linux.vnet.ibm.com
[-- Attachment #1: qemu_tpm.diff --]
[-- Type: text/plain, Size: 6554 bytes --]
This patch adds support for TPM command line options.
The command line supported here (considering the libtpms based
backend) are
./qemu-... -tpm type=<type>,path=<path to blockstorage file>,
and
./qemu-... -tpm ?
where the latter works similar to -soundhw ? and shows a list of
available TPM backends (i.e., libtpms-based, Xen).
Only the 'type' is interpreted in arch_init.c. Using this parameter,
the backend is chosen, i.e., 'builtin' for the libtpms-based
builtin TPM. 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
'handle_options' and return true if the VM can be started or 'false'
if not enough or bad parameters were provided.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
arch_init.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
arch_init.h | 2 +
hw/pc.h | 7 +++++
qemu-config.c | 20 ++++++++++++++
qemu-options.hx | 11 ++++++++
vl.c | 11 ++++++++
6 files changed, 128 insertions(+)
Index: qemu-git/hw/pc.h
===================================================================
--- qemu-git.orig/hw/pc.h
+++ qemu-git/hw/pc.h
@@ -6,6 +6,7 @@
#include "isa.h"
#include "fdc.h"
#include "net.h"
+#include "tpm_tis.h"
/* PC-style peripherals (also used by other machines). */
@@ -128,6 +129,12 @@ void pc_register_ferr_irq(qemu_irq irq);
void pc_cmos_set_s3_resume(void *opaque, int irq, int level);
void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
+/* tpm_tis.c */
+extern bool has_tpm;
+const BackendTPMDriver *tis_set_backend_driver(const char *tpm_type);
+void tis_display_backend_drivers(FILE *);
+
+
void pc_cpus_init(const char *cpu_model);
void pc_memory_init(ram_addr_t ram_size,
const char *kernel_filename,
Index: qemu-git/qemu-options.hx
===================================================================
--- qemu-git.orig/qemu-options.hx
+++ qemu-git/qemu-options.hx
@@ -1041,6 +1041,17 @@ Specify SMBIOS type 0 fields
Specify SMBIOS type 1 fields
ETEXI
+#ifndef _WIN32
+# ifdef CONFIG_TPM
+DEF("tpm", HAS_ARG, QEMU_OPTION_tpm, \
+ ""
+ "-tpm type=<type>,path=<path>\n" \
+ " enable a TPM with state from file in given path\n"
+ " use -tpm ? to get a list of supported TPM types\n",
+ QEMU_ARCH_I386)
+# endif
+#endif
+
DEFHEADING()
STEXI
@end table
Index: qemu-git/vl.c
===================================================================
--- qemu-git.orig/vl.c
+++ qemu-git/vl.c
@@ -244,6 +244,8 @@ int nb_numa_nodes;
uint64_t node_mem[MAX_NODES];
uint64_t node_cpumask[MAX_NODES];
+bool has_tpm = false;
+
static QEMUTimer *nographic_timer;
uint8_t qemu_uuid[16];
@@ -2420,6 +2422,15 @@ int main(int argc, char **argv, char **e
ram_size = value;
break;
}
+#ifdef CONFIG_TPM
+ case QEMU_OPTION_tpm:
+ if (!(tpm_available())) {
+ printf("Option %s not supported for this target\n", popt->name);
+ exit(1);
+ }
+ select_tpm(optarg);
+ break;
+#endif
case QEMU_OPTION_mempath:
mem_path = optarg;
break;
Index: qemu-git/qemu-config.c
===================================================================
--- qemu-git.orig/qemu-config.c
+++ qemu-git/qemu-config.c
@@ -451,6 +451,25 @@ QemuOptsList qemu_option_rom_opts = {
},
};
+static QemuOptsList qemu_tpm_opts = {
+ .name = "tpm",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_tpm_opts.head),
+ .desc = {
+ {
+ .name = "type",
+ .type = QEMU_OPT_STRING,
+ .help = "Type of TPM backend",
+ },
+ {
+ .name = "path",
+ .type = QEMU_OPT_STRING,
+ .help = "Persitent storage for TPM state",
+ },
+ { /* end of list */ }
+ },
+};
+
+
static QemuOptsList *vm_config_groups[32] = {
&qemu_drive_opts,
&qemu_chardev_opts,
@@ -465,6 +484,7 @@ static QemuOptsList *vm_config_groups[32
&qemu_trace_opts,
#endif
&qemu_option_rom_opts,
+ &qemu_tpm_opts,
NULL,
};
Index: qemu-git/arch_init.c
===================================================================
--- qemu-git.orig/arch_init.c
+++ qemu-git/arch_init.c
@@ -41,6 +41,8 @@
#include "net.h"
#include "gdbstub.h"
#include "hw/smbios.h"
+#include "blockdev.h"
+#include "hw/tpm_tis.h"
#ifdef TARGET_SPARC
int graphic_width = 1024;
@@ -726,3 +728,78 @@ int xen_available(void)
return 0;
#endif
}
+
+int tpm_available(void) {
+#ifdef CONFIG_TPM
+ return 1;
+#else
+ return 0;
+#endif
+}
+
+#ifdef CONFIG_TPM
+
+#if defined (TARGET_I386) || defined (TARGET_X86_64)
+
+
+static int configure_tpm(QemuOpts *opts)
+{
+ const char *value;
+ const BackendTPMDriver *be;
+
+ if (has_tpm) {
+ fprintf(stderr,"Only one TPM is allowed\n");
+ return 1;
+ }
+
+ value = qemu_opt_get(opts, "type");
+ if (!value) {
+ fprintf(stderr,
+ "Missing TPM backend type.");
+ tis_display_backend_drivers(stderr);
+ return 1;
+ }
+
+ be = tis_set_backend_driver(value);
+ if (be == NULL) {
+ fprintf(stderr,
+ "A TPM backend driver of type %s is not supported.\n",
+ value);
+ tis_display_backend_drivers(stderr);
+ return 1;
+ }
+
+ has_tpm = be->handle_options(opts);
+ if (!has_tpm)
+ return 1;
+
+ return 0;
+}
+
+
+void select_tpm(const char *optarg)
+{
+ QemuOpts *opts;
+
+ if (strcmp("none", optarg) != 0) {
+ if (*optarg == '?') {
+ tis_display_backend_drivers(stdout);
+ exit(0);
+ }
+ opts = qemu_opts_parse(qemu_find_opts("tpm"), optarg, 0);
+ if (!opts)
+ exit(1);
+ if (configure_tpm(opts))
+ exit(1);
+ }
+}
+
+# else /* CONFIG_TPM */
+
+void select_tpm(const char *optarg)
+{
+ (void)optarg;
+}
+
+# endif
+#endif /* CONFIG_TPM */
Index: qemu-git/arch_init.h
===================================================================
--- qemu-git.orig/arch_init.h
+++ qemu-git/arch_init.h
@@ -31,5 +31,7 @@ int audio_available(void);
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus);
int kvm_available(void);
int xen_available(void);
+int tpm_available(void);
+void select_tpm(const char *optarg);
#endif
next prev parent reply other threads:[~2011-03-30 19:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-30 19:42 [Qemu-devel] [PATCH V2 0/9] Qemu Trusted Platform Module (TPM) integration Stefan Berger
2011-03-30 19:42 ` Stefan Berger [this message]
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 2/9] Add TPM (frontend) hardware interface (TPM TIS) to Qemu Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 3/9] Add persistent state handling to TPM TIS frontend driver Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 4/9] Add tpm_tis driver to build process Stefan Berger
2011-04-01 18:14 ` Blue Swirl
2011-04-01 19:57 ` Stefan Berger
2011-04-03 9:20 ` Blue Swirl
2011-04-05 2:08 ` Stefan Berger
2011-04-05 17:45 ` Blue Swirl
2011-04-05 18:33 ` Stefan Berger
2011-04-05 18:55 ` Blue Swirl
2011-04-06 0:12 ` Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 5/9] Add a debug register Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 6/9] Implement qemu_thread_join function Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 7/9] Add a TPM backend skeleton implementation Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 8/9] Implementation of the libtpms-based backend Stefan Berger
2011-03-30 19:42 ` [Qemu-devel] [PATCH V2 9/9] Add block storage support for libtpms based TPM backend Stefan Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110330194235.935788784@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=andreas.niederl@iaik.tugraz.at \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).