1
From: James Bottomley <James.Bottomley@HansenPartnership.com>
2
3
The requested feedback was to convert the tpmdev handler to being json
1
The requested feedback was to convert the tpmdev handler to being json
4
based, which requires rethreading all the backends. The good news is
2
based, which requires rethreading all the backends. The good news is
5
this reduced quite a bit of code (especially as I converted it to
3
this reduced quite a bit of code (especially as I converted it to
6
error_fatal handling as well, which removes the return status
4
error_fatal handling as well, which removes the return status
7
threading). The bad news is I can't test any of the conversions.
5
threading).
8
swtpm still isn't building on opensuse and, apparently, passthrough
9
doesn't like my native TPM because it doesn't allow cancellation.
10
6
11
v3 pulls out more unneeded code in the visitor conversion, makes
7
v3 pulls out more unneeded code in the visitor conversion, makes
12
migration work on external state preservation of the simulator and
8
migration work on external state preservation of the simulator and
13
adds documentation
9
adds documentation
14
10
...
...
19
15
20
v5 updates help to exit zero; does some checkpatch tidying
16
v5 updates help to exit zero; does some checkpatch tidying
21
17
22
v7 merge review feedback and add acks.
18
v7 merge review feedback and add acks.
23
19
20
v8 adds better error handling, more code tidies and adds command
21
socket disconnection/reconnection (instead of trying to keep the
22
socket open the whole time). This adds overhead, but makes
23
debugging guest kernel TPM issues much easier.
24
25
v9 Fix merge conflict with optarg->optstr conversion
26
27
v10 Fix more merge conflicts and update API versions
28
29
v11 Fix another merge conflict and correct a warm reboot problem where
30
the TPM isn't getting reset (meaning the PCR values are wrong).
31
24
James
32
James
25
33
26
---
34
---
27
35
28
James Bottomley (2):
36
James Bottomley (2):
29
tpm: convert tpmdev options processing to new visitor format
37
tpm: convert tpmdev options processing to new visitor format
30
tpm: add backend for mssim
38
tpm: add backend for mssim
31
39
32
MAINTAINERS | 6 +
40
MAINTAINERS | 6 +
33
backends/tpm/Kconfig | 5 +
41
backends/tpm/Kconfig | 5 +
34
backends/tpm/meson.build | 1 +
42
backends/tpm/meson.build | 1 +
35
backends/tpm/tpm_emulator.c | 25 ++-
43
backends/tpm/tpm_emulator.c | 25 +--
36
backends/tpm/tpm_mssim.c | 290 +++++++++++++++++++++++++++++++++
44
backends/tpm/tpm_mssim.c | 335 +++++++++++++++++++++++++++++++++
37
backends/tpm/tpm_mssim.h | 44 +++++
45
backends/tpm/tpm_mssim.h | 44 +++++
38
backends/tpm/tpm_passthrough.c | 23 +--
46
backends/tpm/tpm_passthrough.c | 23 +--
39
docs/specs/tpm.rst | 39 +++++
47
docs/specs/tpm.rst | 39 ++++
40
include/sysemu/tpm.h | 4 +-
48
include/sysemu/tpm.h | 5 +-
41
include/sysemu/tpm_backend.h | 2 +-
49
include/sysemu/tpm_backend.h | 2 +-
42
qapi/tpm.json | 49 +++++-
50
qapi/tpm.json | 50 ++++-
43
softmmu/tpm-hmp-cmds.c | 9 +
51
system/tpm-hmp-cmds.c | 9 +
44
softmmu/tpm.c | 91 +++++------
52
system/tpm.c | 91 ++++-----
45
softmmu/vl.c | 19 +--
53
system/vl.c | 19 +-
46
14 files changed, 499 insertions(+), 108 deletions(-)
54
14 files changed, 546 insertions(+), 108 deletions(-)
47
create mode 100644 backends/tpm/tpm_mssim.c
55
create mode 100644 backends/tpm/tpm_mssim.c
48
create mode 100644 backends/tpm/tpm_mssim.h
56
create mode 100644 backends/tpm/tpm_mssim.h
49
57
50
--
58
--
51
2.35.3
59
2.35.3
diff view generated by jsdifflib
1
From: James Bottomley <James.Bottomley@HansenPartnership.com>
2
3
Instead of processing the tpmdev options using the old qemu options,
1
Instead of processing the tpmdev options using the old qemu options,
4
convert to the new visitor format which also allows the passing of
2
convert to the new visitor format which also allows the passing of
5
json on the command line.
3
json on the command line.
6
4
7
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
5
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
6
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
7
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
8
8
9
---
9
---
10
v4: add TpmConfiOptions
10
v4: add TpmConfiOptions
11
v5: exit(0) for help
11
v5: exit(0) for help
12
v7: adjust line lengths, free options
12
v7: adjust line lengths, free options
13
v8: minor updates; add tested/reviewed-by
14
v9: optarg->optstr
13
---
15
---
14
backends/tpm/tpm_emulator.c | 25 ++++------
16
backends/tpm/tpm_emulator.c | 25 ++++------
15
backends/tpm/tpm_passthrough.c | 23 +++------
17
backends/tpm/tpm_passthrough.c | 23 +++------
16
include/sysemu/tpm.h | 4 +-
18
include/sysemu/tpm.h | 5 +-
17
include/sysemu/tpm_backend.h | 2 +-
19
include/sysemu/tpm_backend.h | 2 +-
18
qapi/tpm.json | 19 +++++++
20
qapi/tpm.json | 21 ++++++++
19
softmmu/tpm.c | 91 ++++++++++++++--------------------
21
system/tpm.c | 91 ++++++++++++++--------------------
20
softmmu/vl.c | 19 +------
22
system/vl.c | 19 +------
21
7 files changed, 78 insertions(+), 105 deletions(-)
23
7 files changed, 81 insertions(+), 105 deletions(-)
22
24
23
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
25
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
24
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
25
--- a/backends/tpm/tpm_emulator.c
27
--- a/backends/tpm/tpm_emulator.c
26
+++ b/backends/tpm/tpm_emulator.c
28
+++ b/backends/tpm/tpm_emulator.c
...
...
47
- dev = qemu_chr_find(value);
49
- dev = qemu_chr_find(value);
48
+ dev = qemu_chr_find(opts->u.emulator.chardev);
50
+ dev = qemu_chr_find(opts->u.emulator.chardev);
49
if (!dev) {
51
if (!dev) {
50
- error_report("tpm-emulator: tpm chardev '%s' not found", value);
52
- error_report("tpm-emulator: tpm chardev '%s' not found", value);
51
+ error_report("tpm-emulator: tpm chardev '%s' not found",
53
+ error_report("tpm-emulator: tpm chardev '%s' not found",
52
+ opts->u.emulator.chardev);
54
+ opts->u.emulator.chardev);
53
goto err;
55
goto err;
54
}
56
}
55
57
56
if (!qemu_chr_fe_init(&tpm_emu->ctrl_chr, dev, &err)) {
58
if (!qemu_chr_fe_init(&tpm_emu->ctrl_chr, dev, &err)) {
57
error_prepend(&err, "tpm-emulator: No valid chardev found at '%s':",
59
error_prepend(&err, "tpm-emulator: No valid chardev found at '%s':",
...
...
151
+++ b/include/sysemu/tpm.h
153
+++ b/include/sysemu/tpm.h
152
@@ -XXX,XX +XXX,XX @@
154
@@ -XXX,XX +XXX,XX @@
153
155
154
#ifdef CONFIG_TPM
156
#ifdef CONFIG_TPM
155
157
156
-int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
158
-int tpm_config_parse(QemuOptsList *opts_list, const char *optstr);
157
-int tpm_init(void);
159
-int tpm_init(void);
158
+void tpm_config_parse(const char *optarg);
160
+void tpm_config_parse(const char *optstr);
159
+void tpm_init(void);
161
+void tpm_init(void);
162
+
160
void tpm_cleanup(void);
163
void tpm_cleanup(void);
161
164
162
typedef enum TPMVersion {
165
typedef enum TPMVersion {
163
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
166
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
164
index XXXXXXX..XXXXXXX 100644
167
index XXXXXXX..XXXXXXX 100644
...
...
188
+# without the wrapper to be usable by visitors.
191
+# without the wrapper to be usable by visitors.
189
+#
192
+#
190
+# @type: - 'passthrough' The configuration options for the TPM passthrough type
193
+# @type: - 'passthrough' The configuration options for the TPM passthrough type
191
+# - 'emulator' The configuration options for TPM emulator backend type
194
+# - 'emulator' The configuration options for TPM emulator backend type
192
+#
195
+#
193
+# Since: 7.2
196
+# @id: The Id of the TPM
197
+#
198
+# Since: 9.0
194
+##
199
+##
195
+{ 'union': 'TpmCreateOptions',
200
+{ 'union': 'TpmCreateOptions',
196
+ 'base': { 'type': 'TpmType',
201
+ 'base': { 'type': 'TpmType',
197
+ 'id' : 'str' },
202
+ 'id' : 'str' },
198
+ 'discriminator': 'type',
203
+ 'discriminator': 'type',
...
...
201
+ 'if': 'CONFIG_TPM' }
206
+ 'if': 'CONFIG_TPM' }
202
+
207
+
203
##
208
##
204
# @TPMInfo:
209
# @TPMInfo:
205
#
210
#
206
diff --git a/softmmu/tpm.c b/softmmu/tpm.c
211
diff --git a/system/tpm.c b/system/tpm.c
207
index XXXXXXX..XXXXXXX 100644
212
index XXXXXXX..XXXXXXX 100644
208
--- a/softmmu/tpm.c
213
--- a/system/tpm.c
209
+++ b/softmmu/tpm.c
214
+++ b/system/tpm.c
210
@@ -XXX,XX +XXX,XX @@
215
@@ -XXX,XX +XXX,XX @@
211
#include "qapi/error.h"
216
#include "qapi/error.h"
212
#include "qapi/qapi-commands-tpm.h"
217
#include "qapi/qapi-commands-tpm.h"
213
#include "qapi/qmp/qerror.h"
218
#include "qapi/qmp/qerror.h"
214
+#include "qapi/qobject-input-visitor.h"
219
+#include "qapi/qobject-input-visitor.h"
...
...
329
334
330
/*
335
/*
331
* Parse the TPM configuration options.
336
* Parse the TPM configuration options.
332
* To display all available TPM backends the user may use '-tpmdev help'
337
* To display all available TPM backends the user may use '-tpmdev help'
333
*/
338
*/
334
-int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
339
-int tpm_config_parse(QemuOptsList *opts_list, const char *optstr)
335
+void tpm_config_parse(const char *optarg)
340
+void tpm_config_parse(const char *optstr)
336
{
341
{
337
- QemuOpts *opts;
342
- QemuOpts *opts;
338
+ Visitor *v;
343
+ Visitor *v;
339
+ TpmCreateOptionsQueueEntry *tcqe;
344
+ TpmCreateOptionsQueueEntry *tcqe;
340
345
341
- if (!strcmp(optarg, "help")) {
346
- if (!strcmp(optstr, "help")) {
342
+ if (is_help_option(optarg)) {
347
+ if (is_help_option(optstr)) {
343
tpm_display_backend_drivers();
348
tpm_display_backend_drivers();
344
- return -1;
349
- return -1;
345
- }
350
- }
346
- opts = qemu_opts_parse_noisily(opts_list, optarg, true);
351
- opts = qemu_opts_parse_noisily(opts_list, optstr, true);
347
- if (!opts) {
352
- if (!opts) {
348
- return -1;
353
- return -1;
349
+ exit(0);
354
+ exit(0);
350
}
355
}
351
- return 0;
356
- return 0;
352
+ v = qobject_input_visitor_new_str(optarg, "type", &error_fatal);
357
+ v = qobject_input_visitor_new_str(optstr, "type", &error_fatal);
353
+ tcqe = g_new(TpmCreateOptionsQueueEntry, 1);
358
+ tcqe = g_new(TpmCreateOptionsQueueEntry, 1);
354
+ visit_type_TpmCreateOptions(v, NULL, &tcqe->tco, &error_fatal);
359
+ visit_type_TpmCreateOptions(v, NULL, &tcqe->tco, &error_fatal);
355
+ visit_free(v);
360
+ visit_free(v);
356
+ QSIMPLEQ_INSERT_TAIL(&tco_queue, tcqe, entry);
361
+ QSIMPLEQ_INSERT_TAIL(&tco_queue, tcqe, entry);
357
}
362
}
358
363
359
/*
364
/*
360
diff --git a/softmmu/vl.c b/softmmu/vl.c
365
diff --git a/system/vl.c b/system/vl.c
361
index XXXXXXX..XXXXXXX 100644
366
index XXXXXXX..XXXXXXX 100644
362
--- a/softmmu/vl.c
367
--- a/system/vl.c
363
+++ b/softmmu/vl.c
368
+++ b/system/vl.c
364
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_object_opts = {
369
@@ -XXX,XX +XXX,XX @@ static QemuOptsList qemu_object_opts = {
365
},
370
},
366
};
371
};
367
372
368
-static QemuOptsList qemu_tpmdev_opts = {
373
-static QemuOptsList qemu_tpmdev_opts = {
...
...
377
-
382
-
378
static QemuOptsList qemu_overcommit_opts = {
383
static QemuOptsList qemu_overcommit_opts = {
379
.name = "overcommit",
384
.name = "overcommit",
380
.head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
385
.head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
381
@@ -XXX,XX +XXX,XX @@ static void qemu_create_late_backends(void)
386
@@ -XXX,XX +XXX,XX @@ static void qemu_create_late_backends(void)
382
387
exit(1);
383
object_option_foreach_add(object_create_late);
388
}
384
389
385
- if (tpm_init() < 0) {
390
- if (tpm_init() < 0) {
386
- exit(1);
391
- exit(1);
387
- }
392
- }
388
+ tpm_init();
393
+ tpm_init();
...
...
diff view generated by jsdifflib
1
From: James Bottomley <James.Bottomley@HansenPartnership.com>
2
3
The Microsoft Simulator (mssim) is the reference emulation platform
1
The Microsoft Simulator (mssim) is the reference emulation platform
4
for the TCG TPM 2.0 specification.
2
for the TCG TPM 2.0 specification.
5
3
6
https://github.com/Microsoft/ms-tpm-20-ref.git
4
https://github.com/Microsoft/ms-tpm-20-ref.git
7
5
...
...
34
32
35
-tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote','port':'2321'}}"
33
-tpmdev "{'type':'mssim','id':'tpm0','command':{'type':inet,'host':'remote','port':'2321'}}"
36
34
37
tpm-tis also works as the backend.
35
tpm-tis also works as the backend.
38
36
39
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
37
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
40
Acked-by: Markus Armbruster <armbru@redhat.com>
38
Acked-by: Markus Armbruster <armbru@redhat.com>
41
39
42
---
40
---
43
41
44
v2: convert to SocketAddr json and use qio_channel_socket_connect_sync()
42
v2: convert to SocketAddr json and use qio_channel_socket_connect_sync()
45
v3: gate control power off by migration state keep control socket disconnected
43
v3: gate control power off by migration state keep control socket disconnected
46
to test outside influence and add docs.
44
to test outside influence and add docs.
47
v7: TPMmssim -> TPMMssim; doc and json fixes
45
v7: TPMmssim -> TPMMssim; doc and json fixes
46
Make command socket open each time (makes OS debugging easier)
47
v11: add startup method to make sure TPM is reset on reboot
48
---
48
---
49
MAINTAINERS | 6 +
49
MAINTAINERS | 6 +
50
backends/tpm/Kconfig | 5 +
50
backends/tpm/Kconfig | 5 +
51
backends/tpm/meson.build | 1 +
51
backends/tpm/meson.build | 1 +
52
backends/tpm/tpm_mssim.c | 290 +++++++++++++++++++++++++++++++++++++++
52
backends/tpm/tpm_mssim.c | 335 +++++++++++++++++++++++++++++++++++++++
53
backends/tpm/tpm_mssim.h | 44 ++++++
53
backends/tpm/tpm_mssim.h | 44 +++++
54
docs/specs/tpm.rst | 39 ++++++
54
docs/specs/tpm.rst | 39 +++++
55
qapi/tpm.json | 32 ++++-
55
qapi/tpm.json | 31 +++-
56
softmmu/tpm-hmp-cmds.c | 9 ++
56
system/tpm-hmp-cmds.c | 9 ++
57
8 files changed, 422 insertions(+), 4 deletions(-)
57
8 files changed, 466 insertions(+), 4 deletions(-)
58
create mode 100644 backends/tpm/tpm_mssim.c
58
create mode 100644 backends/tpm/tpm_mssim.c
59
create mode 100644 backends/tpm/tpm_mssim.h
59
create mode 100644 backends/tpm/tpm_mssim.h
60
60
61
diff --git a/MAINTAINERS b/MAINTAINERS
61
diff --git a/MAINTAINERS b/MAINTAINERS
62
index XXXXXXX..XXXXXXX 100644
62
index XXXXXXX..XXXXXXX 100644
...
...
74
+MSSIM TPM Backend
74
+MSSIM TPM Backend
75
+M: James Bottomley <jejb@linux.ibm.com>
75
+M: James Bottomley <jejb@linux.ibm.com>
76
+S: Maintained
76
+S: Maintained
77
+F: backends/tpm/tpm_mssim.*
77
+F: backends/tpm/tpm_mssim.*
78
+
78
+
79
Checkpatch
79
SPDM
80
S: Odd Fixes
80
M: Alistair Francis <alistair.francis@wdc.com>
81
F: scripts/checkpatch.pl
81
S: Maintained
82
diff --git a/backends/tpm/Kconfig b/backends/tpm/Kconfig
82
diff --git a/backends/tpm/Kconfig b/backends/tpm/Kconfig
83
index XXXXXXX..XXXXXXX 100644
83
index XXXXXXX..XXXXXXX 100644
84
--- a/backends/tpm/Kconfig
84
--- a/backends/tpm/Kconfig
85
+++ b/backends/tpm/Kconfig
85
+++ b/backends/tpm/Kconfig
86
@@ -XXX,XX +XXX,XX @@ config TPM_EMULATOR
86
@@ -XXX,XX +XXX,XX @@ config TPM_EMULATOR
...
...
147
+ QIOChannelSocket *cmd_qc, *ctrl_qc;
147
+ QIOChannelSocket *cmd_qc, *ctrl_qc;
148
+};
148
+};
149
+
149
+
150
+static int tpm_send_ctrl(TPMMssim *t, uint32_t cmd, Error **errp)
150
+static int tpm_send_ctrl(TPMMssim *t, uint32_t cmd, Error **errp)
151
+{
151
+{
152
+ int ret;
152
+ int ret, retc;
153
+
153
+ Error *local_err = NULL;
154
+ qio_channel_socket_connect_sync(t->ctrl_qc, t->opts.control, errp);
154
+
155
+ ret = qio_channel_socket_connect_sync(t->ctrl_qc, t->opts.control, errp);
156
+ if (ret != 0) {
157
+ return ret;
158
+ }
155
+ cmd = htonl(cmd);
159
+ cmd = htonl(cmd);
156
+ ret = qio_channel_write_all(QIO_CHANNEL(t->ctrl_qc),
160
+ ret = qio_channel_write_all(QIO_CHANNEL(t->ctrl_qc),
157
+ (char *)&cmd, sizeof(cmd), errp);
161
+ (char *)&cmd, sizeof(cmd), errp);
158
+ if (ret != 0) {
162
+ if (ret != 0) {
159
+ goto out;
163
+ goto out;
...
...
168
+ error_setg(errp, ERROR_PREFIX
172
+ error_setg(errp, ERROR_PREFIX
169
+ "Incorrect ACK recieved on control channel 0x%x", cmd);
173
+ "Incorrect ACK recieved on control channel 0x%x", cmd);
170
+ ret = -1;
174
+ ret = -1;
171
+ }
175
+ }
172
+ out:
176
+ out:
173
+ qio_channel_close(QIO_CHANNEL(t->ctrl_qc), errp);
177
+ /*
174
+ return ret;
178
+ * need to close the channel here, but if that fails report it
179
+ * while not letting a prior failure get overwritten
180
+ */
181
+ retc = qio_channel_close(QIO_CHANNEL(t->ctrl_qc), &local_err);
182
+ error_propagate(errp, local_err);
183
+ return retc ? retc : ret;
175
+}
184
+}
176
+
185
+
177
+static void tpm_mssim_instance_init(Object *obj)
186
+static void tpm_mssim_instance_init(Object *obj)
178
+{
187
+{
179
+}
188
+}
180
+
189
+
181
+static void tpm_mssim_instance_finalize(Object *obj)
190
+static void tpm_mssim_instance_finalize(Object *obj)
182
+{
191
+{
183
+ TPMMssim *t = TPM_MSSIM(obj);
192
+ TPMMssim *t = TPM_MSSIM(obj);
184
+
193
+
185
+ if (t->cmd_qc && !runstate_check(RUN_STATE_POSTMIGRATE)) {
194
+ if (t->cmd_qc && !runstate_check(RUN_STATE_POSTMIGRATE)) {
186
+ tpm_send_ctrl(t, TPM_SIGNAL_POWER_OFF, NULL);
195
+ Error *errp = NULL;
196
+ int ret;
197
+
198
+ ret = tpm_send_ctrl(t, TPM_SIGNAL_POWER_OFF, &errp);
199
+ if (ret != 0) {
200
+ error_report_err(errp);
201
+ }
187
+ }
202
+ }
188
+
203
+
189
+ object_unref(OBJECT(t->ctrl_qc));
204
+ object_unref(OBJECT(t->ctrl_qc));
190
+ object_unref(OBJECT(t->cmd_qc));
205
+ object_unref(OBJECT(t->cmd_qc));
191
+}
206
+}
...
...
223
+ TPMMssim *t = TPM_MSSIM(tb);
238
+ TPMMssim *t = TPM_MSSIM(tb);
224
+ uint32_t header, len;
239
+ uint32_t header, len;
225
+ uint8_t locality = cmd->locty;
240
+ uint8_t locality = cmd->locty;
226
+ struct iovec iov[4];
241
+ struct iovec iov[4];
227
+ int ret;
242
+ int ret;
243
+
244
+ ret = qio_channel_socket_connect_sync(t->cmd_qc, t->opts.command, errp);
245
+ if (ret != 0) {
246
+ goto fail_msg;
247
+ }
228
+
248
+
229
+ header = htonl(TPM_SEND_COMMAND);
249
+ header = htonl(TPM_SEND_COMMAND);
230
+ len = htonl(cmd->in_len);
250
+ len = htonl(cmd->in_len);
231
+
251
+
232
+ iov[0].iov_base = &header;
252
+ iov[0].iov_base = &header;
...
...
269
+ if (header != 0) {
289
+ if (header != 0) {
270
+ error_setg(errp, "incorrect ACK received on command channel 0x%x", len);
290
+ error_setg(errp, "incorrect ACK received on command channel 0x%x", len);
271
+ goto fail;
291
+ goto fail;
272
+ }
292
+ }
273
+
293
+
294
+ ret = qio_channel_close(QIO_CHANNEL(t->cmd_qc), errp);
295
+ if (ret != 0) {
296
+ goto fail_msg;
297
+ }
298
+
274
+ return;
299
+ return;
275
+
300
+
276
+ fail:
301
+ fail:
302
+ /* we're already failing, so don't worry if this fails too */
303
+ qio_channel_close(QIO_CHANNEL(t->cmd_qc), NULL);
304
+ fail_msg:
277
+ error_prepend(errp, ERROR_PREFIX);
305
+ error_prepend(errp, ERROR_PREFIX);
278
+ tpm_util_write_fatal_error_response(cmd->out, cmd->out_len);
306
+ tpm_util_write_fatal_error_response(cmd->out, cmd->out_len);
279
+}
307
+}
280
+
308
+
309
+static int tpm_mssim_startup(TPMBackend *tb, size_t buffersize)
310
+{
311
+ TPMMssim *t = TPM_MSSIM(tb);
312
+ Error *errp = NULL;
313
+ int ret;
314
+
315
+ if (runstate_check(RUN_STATE_INMIGRATE)) {
316
+ return 0;
317
+ }
318
+
319
+ /*
320
+ * reset the TPM using a power cycle sequence, in case someone has
321
+ * previously powered it up
322
+ */
323
+ ret = tpm_send_ctrl(t, TPM_SIGNAL_POWER_OFF, &errp);
324
+ if (ret != 0) {
325
+ goto fail;
326
+ }
327
+
328
+ ret = tpm_send_ctrl(t, TPM_SIGNAL_POWER_ON, &errp);
329
+ if (ret != 0) {
330
+ goto fail;
331
+ }
332
+
333
+ ret = tpm_send_ctrl(t, TPM_SIGNAL_NV_ON, &errp);
334
+ if (ret != 0) {
335
+ goto fail;
336
+ }
337
+
338
+ return 0;
339
+
340
+ fail:
341
+ error_report_err(errp);
342
+ return -1;
343
+}
344
+
281
+static TPMBackend *tpm_mssim_create(TpmCreateOptions *opts)
345
+static TPMBackend *tpm_mssim_create(TpmCreateOptions *opts)
282
+{
346
+{
283
+ TPMBackend *be = TPM_BACKEND(object_new(TYPE_TPM_MSSIM));
347
+ TPMBackend *be = TPM_BACKEND(object_new(TYPE_TPM_MSSIM));
284
+ TPMMssim *t = TPM_MSSIM(be);
348
+ TPMMssim *t = TPM_MSSIM(be);
285
+ int sock;
286
+ Error *errp = NULL;
349
+ Error *errp = NULL;
287
+ TPMMssimOptions *mo = &opts->u.mssim;
350
+ TPMMssimOptions *mo = &opts->u.mssim;
288
+
351
+
289
+ if (!mo->command) {
352
+ if (!mo->command) {
290
+ mo->command = g_new0(SocketAddress, 1);
353
+ mo->command = g_new0(SocketAddress, 1);
...
...
315
+ }
378
+ }
316
+
379
+
317
+ if (qio_channel_socket_connect_sync(t->ctrl_qc, mo->control, &errp) < 0) {
380
+ if (qio_channel_socket_connect_sync(t->ctrl_qc, mo->control, &errp) < 0) {
318
+ goto fail;
381
+ goto fail;
319
+ }
382
+ }
320
+ qio_channel_close(QIO_CHANNEL(t->ctrl_qc), &errp);
383
+ qio_channel_close(QIO_CHANNEL(t->ctrl_qc), NULL);
321
+
384
+ qio_channel_close(QIO_CHANNEL(t->cmd_qc), NULL);
322
+ if (!runstate_check(RUN_STATE_INMIGRATE)) {
385
+
323
+ /*
324
+ * reset the TPM using a power cycle sequence, in case someone
325
+ * has previously powered it up
326
+ */
327
+ sock = tpm_send_ctrl(t, TPM_SIGNAL_POWER_OFF, &errp);
328
+ if (sock != 0) {
329
+ goto fail;
330
+ }
331
+
332
+ sock = tpm_send_ctrl(t, TPM_SIGNAL_POWER_ON, &errp);
333
+ if (sock != 0) {
334
+ goto fail;
335
+ }
336
+
337
+ sock = tpm_send_ctrl(t, TPM_SIGNAL_NV_ON, &errp);
338
+ if (sock != 0) {
339
+ goto fail;
340
+ }
341
+ }
342
+
386
+
343
+ return be;
387
+ return be;
344
+
388
+
345
+ fail:
389
+ fail:
346
+ object_unref(OBJECT(t->ctrl_qc));
390
+ object_unref(OBJECT(t->ctrl_qc));
...
...
375
+ cl->type = TPM_TYPE_MSSIM;
419
+ cl->type = TPM_TYPE_MSSIM;
376
+ cl->opts = tpm_mssim_cmdline_opts;
420
+ cl->opts = tpm_mssim_cmdline_opts;
377
+ cl->desc = "TPM mssim emulator backend driver";
421
+ cl->desc = "TPM mssim emulator backend driver";
378
+ cl->create = tpm_mssim_create;
422
+ cl->create = tpm_mssim_create;
379
+ cl->cancel_cmd = tpm_mssim_cancel_cmd;
423
+ cl->cancel_cmd = tpm_mssim_cancel_cmd;
424
+ cl->startup_tpm = tpm_mssim_startup;
380
+ cl->get_tpm_version = tpm_mssim_get_version;
425
+ cl->get_tpm_version = tpm_mssim_get_version;
381
+ cl->get_buffer_size = tpm_mssim_get_buffer_size;
426
+ cl->get_buffer_size = tpm_mssim_get_buffer_size;
382
+ cl->get_tpm_options = tpm_mssim_get_opts;
427
+ cl->get_tpm_options = tpm_mssim_get_opts;
383
+ cl->handle_request = tpm_mssim_handle_request;
428
+ cl->handle_request = tpm_mssim_handle_request;
384
+}
429
+}
...
...
517
#
562
#
518
@@ -XXX,XX +XXX,XX @@
563
@@ -XXX,XX +XXX,XX @@
519
#
564
#
520
# @emulator: Software Emulator TPM type (since 2.11)
565
# @emulator: Software Emulator TPM type (since 2.11)
521
#
566
#
522
+# @mssim: Microsoft TPM Emulator (since 8.2)
567
+# @mssim: Microsoft TPM Emulator (since 9.0)
523
+#
568
+#
524
# Since: 1.5
569
# Since: 1.5
525
##
570
##
526
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
571
-{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ],
527
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim' ],
572
+{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator', 'mssim' ],
528
'if': 'CONFIG_TPM' }
573
'if': 'CONFIG_TPM' }
529
574
530
##
575
##
531
@@ -XXX,XX +XXX,XX @@
576
@@ -XXX,XX +XXX,XX @@
532
# Example:
577
# .. qmp-example::
533
#
578
#
534
# -> { "execute": "query-tpm-types" }
579
# -> { "execute": "query-tpm-types" }
535
-# <- { "return": [ "passthrough", "emulator" ] }
580
-# <- { "return": [ "passthrough", "emulator" ] }
536
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }
581
+# <- { "return": [ "passthrough", "emulator", "mssim" ] }
537
+#
538
##
582
##
539
{ 'command': 'query-tpm-types', 'returns': ['TpmType'],
583
{ 'command': 'query-tpm-types', 'returns': ['TpmType'],
540
'if': 'CONFIG_TPM' }
584
'if': 'CONFIG_TPM' }
541
@@ -XXX,XX +XXX,XX @@
585
@@ -XXX,XX +XXX,XX @@
542
'data': { 'data': 'TPMEmulatorOptions' },
586
'data': { 'data': 'TPMEmulatorOptions' },
...
...
549
+#
593
+#
550
+# @command: command socket for the TPM emulator
594
+# @command: command socket for the TPM emulator
551
+#
595
+#
552
+# @control: control socket for the TPM emulator
596
+# @control: control socket for the TPM emulator
553
+#
597
+#
554
+# Since: 8.2
598
+# Since: 9.0
555
+##
599
+##
556
+{ 'struct': 'TPMMssimOptions',
600
+{ 'struct': 'TPMMssimOptions',
557
+ 'data': { '*command': 'SocketAddress',
601
+ 'data': { '*command': 'SocketAddress',
558
+ '*control': 'SocketAddress' },
602
+ '*control': 'SocketAddress' },
559
+ 'if': 'CONFIG_TPM' }
603
+ 'if': 'CONFIG_TPM' }
...
...
587
+ 'emulator': 'TPMEmulatorOptions',
631
+ 'emulator': 'TPMEmulatorOptions',
588
+ 'mssim': 'TPMMssimOptions' },
632
+ 'mssim': 'TPMMssimOptions' },
589
'if': 'CONFIG_TPM' }
633
'if': 'CONFIG_TPM' }
590
634
591
##
635
##
592
diff --git a/softmmu/tpm-hmp-cmds.c b/softmmu/tpm-hmp-cmds.c
636
diff --git a/system/tpm-hmp-cmds.c b/system/tpm-hmp-cmds.c
593
index XXXXXXX..XXXXXXX 100644
637
index XXXXXXX..XXXXXXX 100644
594
--- a/softmmu/tpm-hmp-cmds.c
638
--- a/system/tpm-hmp-cmds.c
595
+++ b/softmmu/tpm-hmp-cmds.c
639
+++ b/system/tpm-hmp-cmds.c
596
@@ -XXX,XX +XXX,XX @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
640
@@ -XXX,XX +XXX,XX @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
597
unsigned int c = 0;
641
unsigned int c = 0;
598
TPMPassthroughOptions *tpo;
642
TPMPassthroughOptions *tpo;
599
TPMEmulatorOptions *teo;
643
TPMEmulatorOptions *teo;
600
+ TPMMssimOptions *tmo;
644
+ TPMMssimOptions *tmo;
...
...
diff view generated by jsdifflib