diff options
18 files changed, 3260 insertions, 1758 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0001-Provide-support-for-the-CUSE-TPM.patch b/meta/recipes-devtools/qemu/qemu/0001-Provide-support-for-the-CUSE-TPM.patch deleted file mode 100644 index 74dc6f5df8..0000000000 --- a/meta/recipes-devtools/qemu/qemu/0001-Provide-support-for-the-CUSE-TPM.patch +++ /dev/null | |||
| @@ -1,870 +0,0 @@ | |||
| 1 | From 8737eef18f39ed087fd911d0a0886e8174d0468c Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 3 | Date: Sat, 31 Dec 2016 11:23:32 -0500 | ||
| 4 | Subject: [PATCH 1/4] Provide support for the CUSE TPM | ||
| 5 | |||
| 6 | Rather than integrating TPM functionality into QEMU directly | ||
| 7 | using the TPM emulation of libtpms, we now integrate an external | ||
| 8 | emulated TPM device. This device is expected to implement a Linux | ||
| 9 | CUSE interface (CUSE = character device in userspace). | ||
| 10 | |||
| 11 | QEMU talks to the CUSE TPM using much functionality of the | ||
| 12 | passthrough driver. For example, the TPM commands and responses | ||
| 13 | are sent to the CUSE TPM using the read()/write() interface. | ||
| 14 | However, some out-of-band control needs to be done using the CUSE | ||
| 15 | TPM's ioctls. The CUSE TPM currently defines and implements 15 | ||
| 16 | different ioctls for controlling certain life-cycle aspects of | ||
| 17 | the emulated TPM. The ioctls can be regarded as a replacement for | ||
| 18 | direct function calls to a TPM emulator if the TPM were to be | ||
| 19 | directly integrated into QEMU. | ||
| 20 | |||
| 21 | One of the ioctls allows to get a bitmask of supported capabilities. | ||
| 22 | Each returned bit indicates which capabilities have been implemented. | ||
| 23 | An include file defining the various ioctls is added to QEMU. | ||
| 24 | |||
| 25 | The CUSE TPM and associated tools can be found here: | ||
| 26 | |||
| 27 | https://github.com/stefanberger/swtpm | ||
| 28 | |||
| 29 | (please use the latest version) | ||
| 30 | |||
| 31 | To use the external CUSE TPM, the CUSE TPM should be started as follows: | ||
| 32 | |||
| 33 | /usr/bin/swtpm_ioctl -s /dev/vtpm-test | ||
| 34 | |||
| 35 | /usr/bin/swtpm_cuse -n vtpm-test | ||
| 36 | |||
| 37 | QEMU can then be started using the following parameters: | ||
| 38 | |||
| 39 | qemu-system-x86_64 \ | ||
| 40 | [...] \ | ||
| 41 | -tpmdev cuse-tpm,id=tpm0,cancel-path=/dev/null,path=/dev/vtpm-test \ | ||
| 42 | -device tpm-tis,id=tpm0,tpmdev=tpm0 \ | ||
| 43 | [...] | ||
| 44 | |||
| 45 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 46 | Cc: Eric Blake <eblake@redhat.com> | ||
| 47 | |||
| 48 | Conflicts: | ||
| 49 | docs/qmp-commands.txt | ||
| 50 | |||
| 51 | Patch cherry-picked from https://github.com/stefanberger/qemu-tpm, branch v2.8.0+tpm, | ||
| 52 | commit 27d6cd856d5a14061955df7a93ee490697a7a174. Applied cleanly except for | ||
| 53 | docs/qmp-commands.txt which did not exist yet in qemu 2.7. | ||
| 54 | |||
| 55 | Upstream-Status: Pending [https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg00252.html] | ||
| 56 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> | ||
| 57 | --- | ||
| 58 | hmp.c | 6 ++ | ||
| 59 | hw/tpm/tpm_int.h | 1 + | ||
| 60 | hw/tpm/tpm_ioctl.h | 215 +++++++++++++++++++++++++++++++++++++ | ||
| 61 | hw/tpm/tpm_passthrough.c | 274 +++++++++++++++++++++++++++++++++++++++++++++-- | ||
| 62 | qapi-schema.json | 18 +++- | ||
| 63 | qemu-options.hx | 21 +++- | ||
| 64 | tpm.c | 11 +- | ||
| 65 | 7 files changed, 529 insertions(+), 17 deletions(-) | ||
| 66 | create mode 100644 hw/tpm/tpm_ioctl.h | ||
| 67 | |||
| 68 | diff --git a/hmp.c b/hmp.c | ||
| 69 | index cc2056e9e2..277b45ef5a 100644 | ||
| 70 | --- a/hmp.c | ||
| 71 | +++ b/hmp.c | ||
| 72 | @@ -883,6 +883,12 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) | ||
| 73 | tpo->has_cancel_path ? ",cancel-path=" : "", | ||
| 74 | tpo->has_cancel_path ? tpo->cancel_path : ""); | ||
| 75 | break; | ||
| 76 | + case TPM_TYPE_OPTIONS_KIND_CUSE_TPM: | ||
| 77 | + tpo = ti->options->u.passthrough.data; | ||
| 78 | + monitor_printf(mon, "%s%s", | ||
| 79 | + tpo->has_path ? ",path=" : "", | ||
| 80 | + tpo->has_path ? tpo->path : ""); | ||
| 81 | + break; | ||
| 82 | case TPM_TYPE_OPTIONS_KIND__MAX: | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h | ||
| 86 | index f2f285b3cc..6b2c9c953a 100644 | ||
| 87 | --- a/hw/tpm/tpm_int.h | ||
| 88 | +++ b/hw/tpm/tpm_int.h | ||
| 89 | @@ -61,6 +61,7 @@ struct tpm_resp_hdr { | ||
| 90 | #define TPM_TAG_RSP_AUTH1_COMMAND 0xc5 | ||
| 91 | #define TPM_TAG_RSP_AUTH2_COMMAND 0xc6 | ||
| 92 | |||
| 93 | +#define TPM_SUCCESS 0 | ||
| 94 | #define TPM_FAIL 9 | ||
| 95 | |||
| 96 | #define TPM_ORD_ContinueSelfTest 0x53 | ||
| 97 | diff --git a/hw/tpm/tpm_ioctl.h b/hw/tpm/tpm_ioctl.h | ||
| 98 | new file mode 100644 | ||
| 99 | index 0000000000..a341e15741 | ||
| 100 | --- /dev/null | ||
| 101 | +++ b/hw/tpm/tpm_ioctl.h | ||
| 102 | @@ -0,0 +1,215 @@ | ||
| 103 | +/* | ||
| 104 | + * tpm_ioctl.h | ||
| 105 | + * | ||
| 106 | + * (c) Copyright IBM Corporation 2014, 2015. | ||
| 107 | + * | ||
| 108 | + * This file is licensed under the terms of the 3-clause BSD license | ||
| 109 | + */ | ||
| 110 | +#ifndef _TPM_IOCTL_H_ | ||
| 111 | +#define _TPM_IOCTL_H_ | ||
| 112 | + | ||
| 113 | +#include <stdint.h> | ||
| 114 | +#include <sys/uio.h> | ||
| 115 | +#include <sys/types.h> | ||
| 116 | +#include <sys/ioctl.h> | ||
| 117 | + | ||
| 118 | +/* | ||
| 119 | + * Every response from a command involving a TPM command execution must hold | ||
| 120 | + * the ptm_res as the first element. | ||
| 121 | + * ptm_res corresponds to the error code of a command executed by the TPM. | ||
| 122 | + */ | ||
| 123 | + | ||
| 124 | +typedef uint32_t ptm_res; | ||
| 125 | + | ||
| 126 | +/* PTM_GET_TPMESTABLISHED: get the establishment bit */ | ||
| 127 | +struct ptm_est { | ||
| 128 | + union { | ||
| 129 | + struct { | ||
| 130 | + ptm_res tpm_result; | ||
| 131 | + unsigned char bit; /* TPM established bit */ | ||
| 132 | + } resp; /* response */ | ||
| 133 | + } u; | ||
| 134 | +}; | ||
| 135 | + | ||
| 136 | +/* PTM_RESET_TPMESTABLISHED: reset establishment bit */ | ||
| 137 | +struct ptm_reset_est { | ||
| 138 | + union { | ||
| 139 | + struct { | ||
| 140 | + uint8_t loc; /* locality to use */ | ||
| 141 | + } req; /* request */ | ||
| 142 | + struct { | ||
| 143 | + ptm_res tpm_result; | ||
| 144 | + } resp; /* response */ | ||
| 145 | + } u; | ||
| 146 | +}; | ||
| 147 | + | ||
| 148 | +/* PTM_INIT */ | ||
| 149 | +struct ptm_init { | ||
| 150 | + union { | ||
| 151 | + struct { | ||
| 152 | + uint32_t init_flags; /* see definitions below */ | ||
| 153 | + } req; /* request */ | ||
| 154 | + struct { | ||
| 155 | + ptm_res tpm_result; | ||
| 156 | + } resp; /* response */ | ||
| 157 | + } u; | ||
| 158 | +}; | ||
| 159 | + | ||
| 160 | +/* above init_flags */ | ||
| 161 | +#define PTM_INIT_FLAG_DELETE_VOLATILE (1 << 0) | ||
| 162 | + /* delete volatile state file after reading it */ | ||
| 163 | + | ||
| 164 | +/* PTM_SET_LOCALITY */ | ||
| 165 | +struct ptm_loc { | ||
| 166 | + union { | ||
| 167 | + struct { | ||
| 168 | + uint8_t loc; /* locality to set */ | ||
| 169 | + } req; /* request */ | ||
| 170 | + struct { | ||
| 171 | + ptm_res tpm_result; | ||
| 172 | + } resp; /* response */ | ||
| 173 | + } u; | ||
| 174 | +}; | ||
| 175 | + | ||
| 176 | +/* PTM_HASH_DATA: hash given data */ | ||
| 177 | +struct ptm_hdata { | ||
| 178 | + union { | ||
| 179 | + struct { | ||
| 180 | + uint32_t length; | ||
| 181 | + uint8_t data[4096]; | ||
| 182 | + } req; /* request */ | ||
| 183 | + struct { | ||
| 184 | + ptm_res tpm_result; | ||
| 185 | + } resp; /* response */ | ||
| 186 | + } u; | ||
| 187 | +}; | ||
| 188 | + | ||
| 189 | +/* | ||
| 190 | + * size of the TPM state blob to transfer; x86_64 can handle 8k, | ||
| 191 | + * ppc64le only ~7k; keep the response below a 4k page size | ||
| 192 | + */ | ||
| 193 | +#define PTM_STATE_BLOB_SIZE (3 * 1024) | ||
| 194 | + | ||
| 195 | +/* | ||
| 196 | + * The following is the data structure to get state blobs from the TPM. | ||
| 197 | + * If the size of the state blob exceeds the PTM_STATE_BLOB_SIZE, multiple reads | ||
| 198 | + * with this ioctl and with adjusted offset are necessary. All bytes | ||
| 199 | + * must be transferred and the transfer is done once the last byte has been | ||
| 200 | + * returned. | ||
| 201 | + * It is possible to use the read() interface for reading the data; however, | ||
| 202 | + * the first bytes of the state blob will be part of the response to the ioctl(); | ||
| 203 | + * a subsequent read() is only necessary if the total length (totlength) exceeds | ||
| 204 | + * the number of received bytes. seek() is not supported. | ||
| 205 | + */ | ||
| 206 | +struct ptm_getstate { | ||
| 207 | + union { | ||
| 208 | + struct { | ||
| 209 | + uint32_t state_flags; /* may be: PTM_STATE_FLAG_DECRYPTED */ | ||
| 210 | + uint32_t type; /* which blob to pull */ | ||
| 211 | + uint32_t offset; /* offset from where to read */ | ||
| 212 | + } req; /* request */ | ||
| 213 | + struct { | ||
| 214 | + ptm_res tpm_result; | ||
| 215 | + uint32_t state_flags; /* may be: PTM_STATE_FLAG_ENCRYPTED */ | ||
| 216 | + uint32_t totlength; /* total length that will be transferred */ | ||
| 217 | + uint32_t length; /* number of bytes in following buffer */ | ||
| 218 | + uint8_t data[PTM_STATE_BLOB_SIZE]; | ||
| 219 | + } resp; /* response */ | ||
| 220 | + } u; | ||
| 221 | +}; | ||
| 222 | + | ||
| 223 | +/* TPM state blob types */ | ||
| 224 | +#define PTM_BLOB_TYPE_PERMANENT 1 | ||
| 225 | +#define PTM_BLOB_TYPE_VOLATILE 2 | ||
| 226 | +#define PTM_BLOB_TYPE_SAVESTATE 3 | ||
| 227 | + | ||
| 228 | +/* state_flags above : */ | ||
| 229 | +#define PTM_STATE_FLAG_DECRYPTED 1 /* on input: get decrypted state */ | ||
| 230 | +#define PTM_STATE_FLAG_ENCRYPTED 2 /* on output: state is encrypted */ | ||
| 231 | + | ||
| 232 | +/* | ||
| 233 | + * The following is the data structure to set state blobs in the TPM. | ||
| 234 | + * If the size of the state blob exceeds the PTM_STATE_BLOB_SIZE, multiple | ||
| 235 | + * 'writes' using this ioctl are necessary. The last packet is indicated | ||
| 236 | + * by the length being smaller than the PTM_STATE_BLOB_SIZE. | ||
| 237 | + * The very first packet may have a length indicator of '0' enabling | ||
| 238 | + * a write() with all the bytes from a buffer. If the write() interface | ||
| 239 | + * is used, a final ioctl with a non-full buffer must be made to indicate | ||
| 240 | + * that all data were transferred (a write with 0 bytes would not work). | ||
| 241 | + */ | ||
| 242 | +struct ptm_setstate { | ||
| 243 | + union { | ||
| 244 | + struct { | ||
| 245 | + uint32_t state_flags; /* may be PTM_STATE_FLAG_ENCRYPTED */ | ||
| 246 | + uint32_t type; /* which blob to set */ | ||
| 247 | + uint32_t length; /* length of the data; | ||
| 248 | + use 0 on the first packet to | ||
| 249 | + transfer using write() */ | ||
| 250 | + uint8_t data[PTM_STATE_BLOB_SIZE]; | ||
| 251 | + } req; /* request */ | ||
| 252 | + struct { | ||
| 253 | + ptm_res tpm_result; | ||
| 254 | + } resp; /* response */ | ||
| 255 | + } u; | ||
| 256 | +}; | ||
| 257 | + | ||
| 258 | +/* | ||
| 259 | + * PTM_GET_CONFIG: Data structure to get runtime configuration information | ||
| 260 | + * such as which keys are applied. | ||
| 261 | + */ | ||
| 262 | +struct ptm_getconfig { | ||
| 263 | + union { | ||
| 264 | + struct { | ||
| 265 | + ptm_res tpm_result; | ||
| 266 | + uint32_t flags; | ||
| 267 | + } resp; /* response */ | ||
| 268 | + } u; | ||
| 269 | +}; | ||
| 270 | + | ||
| 271 | +#define PTM_CONFIG_FLAG_FILE_KEY 0x1 | ||
| 272 | +#define PTM_CONFIG_FLAG_MIGRATION_KEY 0x2 | ||
| 273 | + | ||
| 274 | + | ||
| 275 | +typedef uint64_t ptm_cap; | ||
| 276 | +typedef struct ptm_est ptm_est; | ||
| 277 | +typedef struct ptm_reset_est ptm_reset_est; | ||
| 278 | +typedef struct ptm_loc ptm_loc; | ||
| 279 | +typedef struct ptm_hdata ptm_hdata; | ||
| 280 | +typedef struct ptm_init ptm_init; | ||
| 281 | +typedef struct ptm_getstate ptm_getstate; | ||
| 282 | +typedef struct ptm_setstate ptm_setstate; | ||
| 283 | +typedef struct ptm_getconfig ptm_getconfig; | ||
| 284 | + | ||
| 285 | +/* capability flags returned by PTM_GET_CAPABILITY */ | ||
| 286 | +#define PTM_CAP_INIT (1) | ||
| 287 | +#define PTM_CAP_SHUTDOWN (1<<1) | ||
| 288 | +#define PTM_CAP_GET_TPMESTABLISHED (1<<2) | ||
| 289 | +#define PTM_CAP_SET_LOCALITY (1<<3) | ||
| 290 | +#define PTM_CAP_HASHING (1<<4) | ||
| 291 | +#define PTM_CAP_CANCEL_TPM_CMD (1<<5) | ||
| 292 | +#define PTM_CAP_STORE_VOLATILE (1<<6) | ||
| 293 | +#define PTM_CAP_RESET_TPMESTABLISHED (1<<7) | ||
| 294 | +#define PTM_CAP_GET_STATEBLOB (1<<8) | ||
| 295 | +#define PTM_CAP_SET_STATEBLOB (1<<9) | ||
| 296 | +#define PTM_CAP_STOP (1<<10) | ||
| 297 | +#define PTM_CAP_GET_CONFIG (1<<11) | ||
| 298 | + | ||
| 299 | +enum { | ||
| 300 | + PTM_GET_CAPABILITY = _IOR('P', 0, ptm_cap), | ||
| 301 | + PTM_INIT = _IOWR('P', 1, ptm_init), | ||
| 302 | + PTM_SHUTDOWN = _IOR('P', 2, ptm_res), | ||
| 303 | + PTM_GET_TPMESTABLISHED = _IOR('P', 3, ptm_est), | ||
| 304 | + PTM_SET_LOCALITY = _IOWR('P', 4, ptm_loc), | ||
| 305 | + PTM_HASH_START = _IOR('P', 5, ptm_res), | ||
| 306 | + PTM_HASH_DATA = _IOWR('P', 6, ptm_hdata), | ||
| 307 | + PTM_HASH_END = _IOR('P', 7, ptm_res), | ||
| 308 | + PTM_CANCEL_TPM_CMD = _IOR('P', 8, ptm_res), | ||
| 309 | + PTM_STORE_VOLATILE = _IOR('P', 9, ptm_res), | ||
| 310 | + PTM_RESET_TPMESTABLISHED = _IOWR('P', 10, ptm_reset_est), | ||
| 311 | + PTM_GET_STATEBLOB = _IOWR('P', 11, ptm_getstate), | ||
| 312 | + PTM_SET_STATEBLOB = _IOWR('P', 12, ptm_setstate), | ||
| 313 | + PTM_STOP = _IOR('P', 13, ptm_res), | ||
| 314 | + PTM_GET_CONFIG = _IOR('P', 14, ptm_getconfig), | ||
| 315 | +}; | ||
| 316 | + | ||
| 317 | +#endif /* _TPM_IOCTL_H */ | ||
| 318 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 319 | index e88c0d20bc..050f2ba850 100644 | ||
| 320 | --- a/hw/tpm/tpm_passthrough.c | ||
| 321 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 322 | @@ -33,6 +33,7 @@ | ||
| 323 | #include "sysemu/tpm_backend_int.h" | ||
| 324 | #include "tpm_tis.h" | ||
| 325 | #include "tpm_util.h" | ||
| 326 | +#include "tpm_ioctl.h" | ||
| 327 | |||
| 328 | #define DEBUG_TPM 0 | ||
| 329 | |||
| 330 | @@ -45,6 +46,7 @@ | ||
| 331 | #define TYPE_TPM_PASSTHROUGH "tpm-passthrough" | ||
| 332 | #define TPM_PASSTHROUGH(obj) \ | ||
| 333 | OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) | ||
| 334 | +#define TYPE_TPM_CUSE "tpm-cuse" | ||
| 335 | |||
| 336 | static const TPMDriverOps tpm_passthrough_driver; | ||
| 337 | |||
| 338 | @@ -71,12 +73,18 @@ struct TPMPassthruState { | ||
| 339 | bool had_startup_error; | ||
| 340 | |||
| 341 | TPMVersion tpm_version; | ||
| 342 | + ptm_cap cuse_cap; /* capabilities of the CUSE TPM */ | ||
| 343 | + uint8_t cur_locty_number; /* last set locality */ | ||
| 344 | }; | ||
| 345 | |||
| 346 | typedef struct TPMPassthruState TPMPassthruState; | ||
| 347 | |||
| 348 | #define TPM_PASSTHROUGH_DEFAULT_DEVICE "/dev/tpm0" | ||
| 349 | |||
| 350 | +#define TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt) (tpm_pt->cuse_cap != 0) | ||
| 351 | + | ||
| 352 | +#define TPM_CUSE_IMPLEMENTS_ALL(S, cap) (((S)->cuse_cap & (cap)) == (cap)) | ||
| 353 | + | ||
| 354 | /* functions */ | ||
| 355 | |||
| 356 | static void tpm_passthrough_cancel_cmd(TPMBackend *tb); | ||
| 357 | @@ -148,7 +156,28 @@ static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len) | ||
| 358 | return false; | ||
| 359 | } | ||
| 360 | |||
| 361 | +static int tpm_passthrough_set_locality(TPMPassthruState *tpm_pt, | ||
| 362 | + uint8_t locty_number) | ||
| 363 | +{ | ||
| 364 | + ptm_loc loc; | ||
| 365 | + | ||
| 366 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 367 | + if (tpm_pt->cur_locty_number != locty_number) { | ||
| 368 | + loc.u.req.loc = locty_number; | ||
| 369 | + if (ioctl(tpm_pt->tpm_fd, PTM_SET_LOCALITY, &loc) < 0) { | ||
| 370 | + error_report("tpm_cuse: could not set locality on " | ||
| 371 | + "CUSE TPM: %s", | ||
| 372 | + strerror(errno)); | ||
| 373 | + return -1; | ||
| 374 | + } | ||
| 375 | + tpm_pt->cur_locty_number = locty_number; | ||
| 376 | + } | ||
| 377 | + } | ||
| 378 | + return 0; | ||
| 379 | +} | ||
| 380 | + | ||
| 381 | static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 382 | + uint8_t locality_number, | ||
| 383 | const uint8_t *in, uint32_t in_len, | ||
| 384 | uint8_t *out, uint32_t out_len, | ||
| 385 | bool *selftest_done) | ||
| 386 | @@ -157,6 +186,11 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 387 | bool is_selftest; | ||
| 388 | const struct tpm_resp_hdr *hdr; | ||
| 389 | |||
| 390 | + ret = tpm_passthrough_set_locality(tpm_pt, locality_number); | ||
| 391 | + if (ret < 0) { | ||
| 392 | + goto err_exit; | ||
| 393 | + } | ||
| 394 | + | ||
| 395 | tpm_pt->tpm_op_canceled = false; | ||
| 396 | tpm_pt->tpm_executing = true; | ||
| 397 | *selftest_done = false; | ||
| 398 | @@ -207,10 +241,12 @@ err_exit: | ||
| 399 | } | ||
| 400 | |||
| 401 | static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, | ||
| 402 | + uint8_t locality_number, | ||
| 403 | const TPMLocality *locty_data, | ||
| 404 | bool *selftest_done) | ||
| 405 | { | ||
| 406 | return tpm_passthrough_unix_tx_bufs(tpm_pt, | ||
| 407 | + locality_number, | ||
| 408 | locty_data->w_buffer.buffer, | ||
| 409 | locty_data->w_offset, | ||
| 410 | locty_data->r_buffer.buffer, | ||
| 411 | @@ -231,6 +267,7 @@ static void tpm_passthrough_worker_thread(gpointer data, | ||
| 412 | switch (cmd) { | ||
| 413 | case TPM_BACKEND_CMD_PROCESS_CMD: | ||
| 414 | tpm_passthrough_unix_transfer(tpm_pt, | ||
| 415 | + thr_parms->tpm_state->locty_number, | ||
| 416 | thr_parms->tpm_state->locty_data, | ||
| 417 | &selftest_done); | ||
| 418 | |||
| 419 | @@ -247,6 +284,93 @@ static void tpm_passthrough_worker_thread(gpointer data, | ||
| 420 | } | ||
| 421 | |||
| 422 | /* | ||
| 423 | + * Gracefully shut down the external CUSE TPM | ||
| 424 | + */ | ||
| 425 | +static void tpm_passthrough_shutdown(TPMPassthruState *tpm_pt) | ||
| 426 | +{ | ||
| 427 | + ptm_res res; | ||
| 428 | + | ||
| 429 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 430 | + if (ioctl(tpm_pt->tpm_fd, PTM_SHUTDOWN, &res) < 0) { | ||
| 431 | + error_report("tpm_cuse: Could not cleanly shut down " | ||
| 432 | + "the CUSE TPM: %s", | ||
| 433 | + strerror(errno)); | ||
| 434 | + } | ||
| 435 | + } | ||
| 436 | +} | ||
| 437 | + | ||
| 438 | +/* | ||
| 439 | + * Probe for the CUSE TPM by sending an ioctl() requesting its | ||
| 440 | + * capability flags. | ||
| 441 | + */ | ||
| 442 | +static int tpm_passthrough_cuse_probe(TPMPassthruState *tpm_pt) | ||
| 443 | +{ | ||
| 444 | + int rc = 0; | ||
| 445 | + | ||
| 446 | + if (ioctl(tpm_pt->tpm_fd, PTM_GET_CAPABILITY, &tpm_pt->cuse_cap) < 0) { | ||
| 447 | + error_report("Error: CUSE TPM was requested, but probing failed"); | ||
| 448 | + rc = -1; | ||
| 449 | + } | ||
| 450 | + | ||
| 451 | + return rc; | ||
| 452 | +} | ||
| 453 | + | ||
| 454 | +static int tpm_passthrough_cuse_check_caps(TPMPassthruState *tpm_pt) | ||
| 455 | +{ | ||
| 456 | + int rc = 0; | ||
| 457 | + ptm_cap caps = 0; | ||
| 458 | + const char *tpm = NULL; | ||
| 459 | + | ||
| 460 | + /* check for min. required capabilities */ | ||
| 461 | + switch (tpm_pt->tpm_version) { | ||
| 462 | + case TPM_VERSION_1_2: | ||
| 463 | + caps = PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLISHED | | ||
| 464 | + PTM_CAP_SET_LOCALITY; | ||
| 465 | + tpm = "1.2"; | ||
| 466 | + break; | ||
| 467 | + case TPM_VERSION_2_0: | ||
| 468 | + caps = PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLISHED | | ||
| 469 | + PTM_CAP_SET_LOCALITY | PTM_CAP_RESET_TPMESTABLISHED; | ||
| 470 | + tpm = "2"; | ||
| 471 | + break; | ||
| 472 | + case TPM_VERSION_UNSPEC: | ||
| 473 | + error_report("tpm_cuse: %s: TPM version has not been set", | ||
| 474 | + __func__); | ||
| 475 | + return -1; | ||
| 476 | + } | ||
| 477 | + | ||
| 478 | + if (!TPM_CUSE_IMPLEMENTS_ALL(tpm_pt, caps)) { | ||
| 479 | + error_report("tpm_cuse: TPM does not implement minimum set of required " | ||
| 480 | + "capabilities for TPM %s (0x%x)", tpm, (int)caps); | ||
| 481 | + rc = -1; | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + return rc; | ||
| 485 | +} | ||
| 486 | + | ||
| 487 | +/* | ||
| 488 | + * Initialize the external CUSE TPM | ||
| 489 | + */ | ||
| 490 | +static int tpm_passthrough_cuse_init(TPMPassthruState *tpm_pt) | ||
| 491 | +{ | ||
| 492 | + int rc = 0; | ||
| 493 | + ptm_init init = { | ||
| 494 | + .u.req.init_flags = PTM_INIT_FLAG_DELETE_VOLATILE, | ||
| 495 | + }; | ||
| 496 | + | ||
| 497 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 498 | + if (ioctl(tpm_pt->tpm_fd, PTM_INIT, &init) < 0) { | ||
| 499 | + error_report("tpm_cuse: Detected CUSE TPM but could not " | ||
| 500 | + "send INIT: %s", | ||
| 501 | + strerror(errno)); | ||
| 502 | + rc = -1; | ||
| 503 | + } | ||
| 504 | + } | ||
| 505 | + | ||
| 506 | + return rc; | ||
| 507 | +} | ||
| 508 | + | ||
| 509 | +/* | ||
| 510 | * Start the TPM (thread). If it had been started before, then terminate | ||
| 511 | * and start it again. | ||
| 512 | */ | ||
| 513 | @@ -261,6 +385,8 @@ static int tpm_passthrough_startup_tpm(TPMBackend *tb) | ||
| 514 | tpm_passthrough_worker_thread, | ||
| 515 | &tpm_pt->tpm_thread_params); | ||
| 516 | |||
| 517 | + tpm_passthrough_cuse_init(tpm_pt); | ||
| 518 | + | ||
| 519 | return 0; | ||
| 520 | } | ||
| 521 | |||
| 522 | @@ -291,14 +417,43 @@ static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, | ||
| 523 | |||
| 524 | static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb) | ||
| 525 | { | ||
| 526 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 527 | + ptm_est est; | ||
| 528 | + | ||
| 529 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 530 | + if (ioctl(tpm_pt->tpm_fd, PTM_GET_TPMESTABLISHED, &est) < 0) { | ||
| 531 | + error_report("tpm_cuse: Could not get the TPM established " | ||
| 532 | + "flag from the CUSE TPM: %s", | ||
| 533 | + strerror(errno)); | ||
| 534 | + return false; | ||
| 535 | + } | ||
| 536 | + return (est.u.resp.bit != 0); | ||
| 537 | + } | ||
| 538 | return false; | ||
| 539 | } | ||
| 540 | |||
| 541 | static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb, | ||
| 542 | uint8_t locty) | ||
| 543 | { | ||
| 544 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 545 | + int rc = 0; | ||
| 546 | + ptm_reset_est ptmreset_est; | ||
| 547 | + | ||
| 548 | /* only a TPM 2.0 will support this */ | ||
| 549 | - return 0; | ||
| 550 | + if (tpm_pt->tpm_version == TPM_VERSION_2_0) { | ||
| 551 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 552 | + ptmreset_est.u.req.loc = tpm_pt->cur_locty_number; | ||
| 553 | + | ||
| 554 | + if (ioctl(tpm_pt->tpm_fd, PTM_RESET_TPMESTABLISHED, | ||
| 555 | + &ptmreset_est) < 0) { | ||
| 556 | + error_report("tpm_cuse: Could not reset the establishment bit " | ||
| 557 | + "failed: %s", | ||
| 558 | + strerror(errno)); | ||
| 559 | + rc = -1; | ||
| 560 | + } | ||
| 561 | + } | ||
| 562 | + } | ||
| 563 | + return rc; | ||
| 564 | } | ||
| 565 | |||
| 566 | static bool tpm_passthrough_get_startup_error(TPMBackend *tb) | ||
| 567 | @@ -329,7 +484,8 @@ static void tpm_passthrough_deliver_request(TPMBackend *tb) | ||
| 568 | static void tpm_passthrough_cancel_cmd(TPMBackend *tb) | ||
| 569 | { | ||
| 570 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 571 | - int n; | ||
| 572 | + ptm_res res; | ||
| 573 | + static bool error_printed; | ||
| 574 | |||
| 575 | /* | ||
| 576 | * As of Linux 3.7 the tpm_tis driver does not properly cancel | ||
| 577 | @@ -338,17 +494,34 @@ static void tpm_passthrough_cancel_cmd(TPMBackend *tb) | ||
| 578 | * command, e.g., a command executed on the host. | ||
| 579 | */ | ||
| 580 | if (tpm_pt->tpm_executing) { | ||
| 581 | - if (tpm_pt->cancel_fd >= 0) { | ||
| 582 | - n = write(tpm_pt->cancel_fd, "-", 1); | ||
| 583 | - if (n != 1) { | ||
| 584 | - error_report("Canceling TPM command failed: %s", | ||
| 585 | - strerror(errno)); | ||
| 586 | - } else { | ||
| 587 | - tpm_pt->tpm_op_canceled = true; | ||
| 588 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 589 | + if (TPM_CUSE_IMPLEMENTS_ALL(tpm_pt, PTM_CAP_CANCEL_TPM_CMD)) { | ||
| 590 | + if (ioctl(tpm_pt->tpm_fd, PTM_CANCEL_TPM_CMD, &res) < 0) { | ||
| 591 | + error_report("tpm_cuse: Could not cancel command on " | ||
| 592 | + "CUSE TPM: %s", | ||
| 593 | + strerror(errno)); | ||
| 594 | + } else if (res != TPM_SUCCESS) { | ||
| 595 | + if (!error_printed) { | ||
| 596 | + error_report("TPM error code from command " | ||
| 597 | + "cancellation of CUSE TPM: 0x%x", res); | ||
| 598 | + error_printed = true; | ||
| 599 | + } | ||
| 600 | + } else { | ||
| 601 | + tpm_pt->tpm_op_canceled = true; | ||
| 602 | + } | ||
| 603 | } | ||
| 604 | } else { | ||
| 605 | - error_report("Cannot cancel TPM command due to missing " | ||
| 606 | - "TPM sysfs cancel entry"); | ||
| 607 | + if (tpm_pt->cancel_fd >= 0) { | ||
| 608 | + if (write(tpm_pt->cancel_fd, "-", 1) != 1) { | ||
| 609 | + error_report("Canceling TPM command failed: %s", | ||
| 610 | + strerror(errno)); | ||
| 611 | + } else { | ||
| 612 | + tpm_pt->tpm_op_canceled = true; | ||
| 613 | + } | ||
| 614 | + } else { | ||
| 615 | + error_report("Cannot cancel TPM command due to missing " | ||
| 616 | + "TPM sysfs cancel entry"); | ||
| 617 | + } | ||
| 618 | } | ||
| 619 | } | ||
| 620 | } | ||
| 621 | @@ -378,6 +551,11 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) | ||
| 622 | char *dev; | ||
| 623 | char path[PATH_MAX]; | ||
| 624 | |||
| 625 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 626 | + /* not needed, but so we have a fd */ | ||
| 627 | + return qemu_open("/dev/null", O_WRONLY); | ||
| 628 | + } | ||
| 629 | + | ||
| 630 | if (tb->cancel_path) { | ||
| 631 | fd = qemu_open(tb->cancel_path, O_WRONLY); | ||
| 632 | if (fd < 0) { | ||
| 633 | @@ -412,12 +590,22 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 634 | { | ||
| 635 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 636 | const char *value; | ||
| 637 | + bool have_cuse = false; | ||
| 638 | + | ||
| 639 | + value = qemu_opt_get(opts, "type"); | ||
| 640 | + if (value != NULL && !strcmp("cuse-tpm", value)) { | ||
| 641 | + have_cuse = true; | ||
| 642 | + } | ||
| 643 | |||
| 644 | value = qemu_opt_get(opts, "cancel-path"); | ||
| 645 | tb->cancel_path = g_strdup(value); | ||
| 646 | |||
| 647 | value = qemu_opt_get(opts, "path"); | ||
| 648 | if (!value) { | ||
| 649 | + if (have_cuse) { | ||
| 650 | + error_report("Missing path to access CUSE TPM"); | ||
| 651 | + goto err_free_parameters; | ||
| 652 | + } | ||
| 653 | value = TPM_PASSTHROUGH_DEFAULT_DEVICE; | ||
| 654 | } | ||
| 655 | |||
| 656 | @@ -432,15 +620,36 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 657 | goto err_free_parameters; | ||
| 658 | } | ||
| 659 | |||
| 660 | + tpm_pt->cur_locty_number = ~0; | ||
| 661 | + | ||
| 662 | + if (have_cuse) { | ||
| 663 | + if (tpm_passthrough_cuse_probe(tpm_pt)) { | ||
| 664 | + goto err_close_tpmdev; | ||
| 665 | + } | ||
| 666 | + /* init TPM for probing */ | ||
| 667 | + if (tpm_passthrough_cuse_init(tpm_pt)) { | ||
| 668 | + goto err_close_tpmdev; | ||
| 669 | + } | ||
| 670 | + } | ||
| 671 | + | ||
| 672 | if (tpm_util_test_tpmdev(tpm_pt->tpm_fd, &tpm_pt->tpm_version)) { | ||
| 673 | error_report("'%s' is not a TPM device.", | ||
| 674 | tpm_pt->tpm_dev); | ||
| 675 | goto err_close_tpmdev; | ||
| 676 | } | ||
| 677 | |||
| 678 | + if (have_cuse) { | ||
| 679 | + if (tpm_passthrough_cuse_check_caps(tpm_pt)) { | ||
| 680 | + goto err_close_tpmdev; | ||
| 681 | + } | ||
| 682 | + } | ||
| 683 | + | ||
| 684 | + | ||
| 685 | return 0; | ||
| 686 | |||
| 687 | err_close_tpmdev: | ||
| 688 | + tpm_passthrough_shutdown(tpm_pt); | ||
| 689 | + | ||
| 690 | qemu_close(tpm_pt->tpm_fd); | ||
| 691 | tpm_pt->tpm_fd = -1; | ||
| 692 | |||
| 693 | @@ -491,6 +700,8 @@ static void tpm_passthrough_destroy(TPMBackend *tb) | ||
| 694 | |||
| 695 | tpm_backend_thread_end(&tpm_pt->tbt); | ||
| 696 | |||
| 697 | + tpm_passthrough_shutdown(tpm_pt); | ||
| 698 | + | ||
| 699 | qemu_close(tpm_pt->tpm_fd); | ||
| 700 | qemu_close(tpm_pt->cancel_fd); | ||
| 701 | |||
| 702 | @@ -564,3 +775,44 @@ static void tpm_passthrough_register(void) | ||
| 703 | } | ||
| 704 | |||
| 705 | type_init(tpm_passthrough_register) | ||
| 706 | + | ||
| 707 | +/* CUSE TPM */ | ||
| 708 | +static const char *tpm_passthrough_cuse_create_desc(void) | ||
| 709 | +{ | ||
| 710 | + return "CUSE TPM backend driver"; | ||
| 711 | +} | ||
| 712 | + | ||
| 713 | +static const TPMDriverOps tpm_cuse_driver = { | ||
| 714 | + .type = TPM_TYPE_CUSE_TPM, | ||
| 715 | + .opts = tpm_passthrough_cmdline_opts, | ||
| 716 | + .desc = tpm_passthrough_cuse_create_desc, | ||
| 717 | + .create = tpm_passthrough_create, | ||
| 718 | + .destroy = tpm_passthrough_destroy, | ||
| 719 | + .init = tpm_passthrough_init, | ||
| 720 | + .startup_tpm = tpm_passthrough_startup_tpm, | ||
| 721 | + .realloc_buffer = tpm_passthrough_realloc_buffer, | ||
| 722 | + .reset = tpm_passthrough_reset, | ||
| 723 | + .had_startup_error = tpm_passthrough_get_startup_error, | ||
| 724 | + .deliver_request = tpm_passthrough_deliver_request, | ||
| 725 | + .cancel_cmd = tpm_passthrough_cancel_cmd, | ||
| 726 | + .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, | ||
| 727 | + .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag, | ||
| 728 | + .get_tpm_version = tpm_passthrough_get_tpm_version, | ||
| 729 | +}; | ||
| 730 | + | ||
| 731 | +static const TypeInfo tpm_cuse_info = { | ||
| 732 | + .name = TYPE_TPM_CUSE, | ||
| 733 | + .parent = TYPE_TPM_BACKEND, | ||
| 734 | + .instance_size = sizeof(TPMPassthruState), | ||
| 735 | + .class_init = tpm_passthrough_class_init, | ||
| 736 | + .instance_init = tpm_passthrough_inst_init, | ||
| 737 | + .instance_finalize = tpm_passthrough_inst_finalize, | ||
| 738 | +}; | ||
| 739 | + | ||
| 740 | +static void tpm_cuse_register(void) | ||
| 741 | +{ | ||
| 742 | + type_register_static(&tpm_cuse_info); | ||
| 743 | + tpm_register_driver(&tpm_cuse_driver); | ||
| 744 | +} | ||
| 745 | + | ||
| 746 | +type_init(tpm_cuse_register) | ||
| 747 | diff --git a/qapi-schema.json b/qapi-schema.json | ||
| 748 | index 5658723b37..53120d0f63 100644 | ||
| 749 | --- a/qapi-schema.json | ||
| 750 | +++ b/qapi-schema.json | ||
| 751 | @@ -3522,10 +3522,12 @@ | ||
| 752 | # An enumeration of TPM types | ||
| 753 | # | ||
| 754 | # @passthrough: TPM passthrough type | ||
| 755 | +# @cuse-tpm: CUSE TPM type | ||
| 756 | +# Since: 2.6 | ||
| 757 | # | ||
| 758 | # Since: 1.5 | ||
| 759 | ## | ||
| 760 | -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } | ||
| 761 | +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'cuse-tpm' ] } | ||
| 762 | |||
| 763 | ## | ||
| 764 | # @query-tpm-types: | ||
| 765 | @@ -3554,6 +3556,17 @@ | ||
| 766 | '*cancel-path' : 'str'} } | ||
| 767 | |||
| 768 | ## | ||
| 769 | +# @TPMCuseOptions: | ||
| 770 | +# | ||
| 771 | +# Information about the CUSE TPM type | ||
| 772 | +# | ||
| 773 | +# @path: string describing the path used for accessing the TPM device | ||
| 774 | +# | ||
| 775 | +# Since: 2.6 | ||
| 776 | +## | ||
| 777 | +{ 'struct': 'TPMCuseOptions', 'data': { 'path' : 'str'}} | ||
| 778 | + | ||
| 779 | +## | ||
| 780 | # @TpmTypeOptions: | ||
| 781 | # | ||
| 782 | # A union referencing different TPM backend types' configuration options | ||
| 783 | @@ -3563,7 +3576,8 @@ | ||
| 784 | # Since: 1.5 | ||
| 785 | ## | ||
| 786 | { 'union': 'TpmTypeOptions', | ||
| 787 | - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } | ||
| 788 | + 'data': { 'passthrough' : 'TPMPassthroughOptions', | ||
| 789 | + 'cuse-tpm' : 'TPMCuseOptions' } } | ||
| 790 | |||
| 791 | ## | ||
| 792 | # @TpmInfo: | ||
| 793 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
| 794 | index a71aaf8ea8..e0f1d8e676 100644 | ||
| 795 | --- a/qemu-options.hx | ||
| 796 | +++ b/qemu-options.hx | ||
| 797 | @@ -2763,7 +2763,10 @@ DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \ | ||
| 798 | "-tpmdev passthrough,id=id[,path=path][,cancel-path=path]\n" | ||
| 799 | " use path to provide path to a character device; default is /dev/tpm0\n" | ||
| 800 | " use cancel-path to provide path to TPM's cancel sysfs entry; if\n" | ||
| 801 | - " not provided it will be searched for in /sys/class/misc/tpm?/device\n", | ||
| 802 | + " not provided it will be searched for in /sys/class/misc/tpm?/device\n" | ||
| 803 | + "-tpmdev cuse-tpm,id=id,path=path\n" | ||
| 804 | + " use path to provide path to a character device to talk to the\n" | ||
| 805 | + " TPM emulator providing a CUSE interface\n", | ||
| 806 | QEMU_ARCH_ALL) | ||
| 807 | STEXI | ||
| 808 | |||
| 809 | @@ -2772,8 +2775,8 @@ The general form of a TPM device option is: | ||
| 810 | |||
| 811 | @item -tpmdev @var{backend} ,id=@var{id} [,@var{options}] | ||
| 812 | @findex -tpmdev | ||
| 813 | -Backend type must be: | ||
| 814 | -@option{passthrough}. | ||
| 815 | +Backend type must be either one of the following: | ||
| 816 | +@option{passthrough}, @option{cuse-tpm}. | ||
| 817 | |||
| 818 | The specific backend type will determine the applicable options. | ||
| 819 | The @code{-tpmdev} option creates the TPM backend and requires a | ||
| 820 | @@ -2823,6 +2826,18 @@ To create a passthrough TPM use the following two options: | ||
| 821 | Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by | ||
| 822 | @code{tpmdev=tpm0} in the device option. | ||
| 823 | |||
| 824 | +@item -tpmdev cuse-tpm, id=@var{id}, path=@var{path} | ||
| 825 | + | ||
| 826 | +(Linux-host only) Enable access to a TPM emulator with a CUSE interface. | ||
| 827 | + | ||
| 828 | +@option{path} specifies the path to the CUSE TPM character device. | ||
| 829 | + | ||
| 830 | +To create a backend device accessing the CUSE TPM emulator using /dev/vtpm | ||
| 831 | +use the following two options: | ||
| 832 | +@example | ||
| 833 | +-tpmdev cuse-tpm,id=tpm0,path=/dev/vtpm -device tpm-tis,tpmdev=tpm0 | ||
| 834 | +@end example | ||
| 835 | + | ||
| 836 | @end table | ||
| 837 | |||
| 838 | ETEXI | ||
| 839 | diff --git a/tpm.c b/tpm.c | ||
| 840 | index 9a7c7114d3..5ec2373286 100644 | ||
| 841 | --- a/tpm.c | ||
| 842 | +++ b/tpm.c | ||
| 843 | @@ -25,7 +25,7 @@ static QLIST_HEAD(, TPMBackend) tpm_backends = | ||
| 844 | |||
| 845 | |||
| 846 | #define TPM_MAX_MODELS 1 | ||
| 847 | -#define TPM_MAX_DRIVERS 1 | ||
| 848 | +#define TPM_MAX_DRIVERS 2 | ||
| 849 | |||
| 850 | static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = { | ||
| 851 | NULL, | ||
| 852 | @@ -272,6 +272,15 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) | ||
| 853 | tpo->has_cancel_path = true; | ||
| 854 | } | ||
| 855 | break; | ||
| 856 | + case TPM_TYPE_CUSE_TPM: | ||
| 857 | + res->options->type = TPM_TYPE_OPTIONS_KIND_CUSE_TPM; | ||
| 858 | + tpo = g_new0(TPMPassthroughOptions, 1); | ||
| 859 | + res->options->u.passthrough.data = tpo; | ||
| 860 | + if (drv->path) { | ||
| 861 | + tpo->path = g_strdup(drv->path); | ||
| 862 | + tpo->has_path = true; | ||
| 863 | + } | ||
| 864 | + break; | ||
| 865 | case TPM_TYPE__MAX: | ||
| 866 | break; | ||
| 867 | } | ||
| 868 | -- | ||
| 869 | 2.11.0 | ||
| 870 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch b/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch new file mode 100644 index 0000000000..1a484b91c3 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch | |||
| @@ -0,0 +1,154 @@ | |||
| 1 | From a0f8d150794164f41cd7288c9ed059bbf21c95ec Mon Sep 17 00:00:00 2001 | ||
| 2 | From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com> | ||
| 3 | Date: Thu, 24 Aug 2017 10:45:58 +0200 | ||
| 4 | Subject: [PATCH 01/12] tpm: Clean up driver registration & lookup | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | We have a strict separation between enum TpmType and be_drivers[]: | ||
| 10 | |||
| 11 | * TpmType may have any number of members. It just happens to have one. | ||
| 12 | |||
| 13 | * tpm_register_driver() uses the first empty slot in be_drivers[]. | ||
| 14 | |||
| 15 | If you register more than tpm_models[] has space, | ||
| 16 | tpm_register_driver() fails. Its caller silently ignores the | ||
| 17 | failure. | ||
| 18 | |||
| 19 | If you register more than one with a given TpmType, | ||
| 20 | tpm_display_backend_drivers() will shows all of them, but | ||
| 21 | tpm_driver_find_by_type() and tpm_get_backend_driver() will find | ||
| 22 | only the one one that registered first. | ||
| 23 | |||
| 24 | Since we only ever register one driver, and be_drivers[] has space for | ||
| 25 | just that one, this contraption even works. | ||
| 26 | |||
| 27 | Turn be_drivers[] into a straight map from enum TpmType to driver. | ||
| 28 | Much simpler, and has a decent chance to actually work should we ever | ||
| 29 | acquire additional drivers. | ||
| 30 | |||
| 31 | While there, use qapi_enum_parse() in tpm_get_backend_driver(). | ||
| 32 | |||
| 33 | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 34 | Message-Id: <20170822132255.23945-8-marcandre.lureau@redhat.com> | ||
| 35 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
| 36 | [Rebased, superfluous initializer dropped, commit message rewritten] | ||
| 37 | Cc: Stefan Berger <stefanb@us.ibm.com> | ||
| 38 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
| 39 | Message-Id: <1503564371-26090-4-git-send-email-armbru@redhat.com> | ||
| 40 | |||
| 41 | Upstream-Status: Backport | ||
| 42 | --- | ||
| 43 | include/sysemu/tpm_backend.h | 2 +- | ||
| 44 | tpm.c | 45 +++++++++++++------------------------------- | ||
| 45 | 2 files changed, 14 insertions(+), 33 deletions(-) | ||
| 46 | |||
| 47 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 48 | index b58f52d39f..1d21c6b19b 100644 | ||
| 49 | --- a/include/sysemu/tpm_backend.h | ||
| 50 | +++ b/include/sysemu/tpm_backend.h | ||
| 51 | @@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id); | ||
| 52 | |||
| 53 | const TPMDriverOps *tpm_get_backend_driver(const char *type); | ||
| 54 | int tpm_register_model(enum TpmModel model); | ||
| 55 | -int tpm_register_driver(const TPMDriverOps *tdo); | ||
| 56 | +void tpm_register_driver(const TPMDriverOps *tdo); | ||
| 57 | |||
| 58 | #endif | ||
| 59 | diff --git a/tpm.c b/tpm.c | ||
| 60 | index 9a7c7114d3..bb45d0c08e 100644 | ||
| 61 | --- a/tpm.c | ||
| 62 | +++ b/tpm.c | ||
| 63 | @@ -14,6 +14,7 @@ | ||
| 64 | #include "qemu/osdep.h" | ||
| 65 | |||
| 66 | #include "qapi/qmp/qerror.h" | ||
| 67 | +#include "qapi/util.h" | ||
| 68 | #include "sysemu/tpm_backend.h" | ||
| 69 | #include "sysemu/tpm.h" | ||
| 70 | #include "qemu/config-file.h" | ||
| 71 | @@ -25,11 +26,8 @@ static QLIST_HEAD(, TPMBackend) tpm_backends = | ||
| 72 | |||
| 73 | |||
| 74 | #define TPM_MAX_MODELS 1 | ||
| 75 | -#define TPM_MAX_DRIVERS 1 | ||
| 76 | |||
| 77 | -static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = { | ||
| 78 | - NULL, | ||
| 79 | -}; | ||
| 80 | +static TPMDriverOps const *be_drivers[TPM_TYPE__MAX]; | ||
| 81 | |||
| 82 | static enum TpmModel tpm_models[TPM_MAX_MODELS] = { | ||
| 83 | TPM_MODEL__MAX, | ||
| 84 | @@ -63,31 +61,18 @@ static bool tpm_model_is_registered(enum TpmModel model) | ||
| 85 | |||
| 86 | const TPMDriverOps *tpm_get_backend_driver(const char *type) | ||
| 87 | { | ||
| 88 | - int i; | ||
| 89 | - | ||
| 90 | - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { | ||
| 91 | - if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) { | ||
| 92 | - return be_drivers[i]; | ||
| 93 | - } | ||
| 94 | - } | ||
| 95 | + int i = qapi_enum_parse(TpmType_lookup, type, TPM_TYPE__MAX, -1, NULL); | ||
| 96 | |||
| 97 | - return NULL; | ||
| 98 | + return i >= 0 ? be_drivers[i] : NULL; | ||
| 99 | } | ||
| 100 | |||
| 101 | #ifdef CONFIG_TPM | ||
| 102 | |||
| 103 | -int tpm_register_driver(const TPMDriverOps *tdo) | ||
| 104 | +void tpm_register_driver(const TPMDriverOps *tdo) | ||
| 105 | { | ||
| 106 | - int i; | ||
| 107 | + assert(!be_drivers[tdo->type]); | ||
| 108 | |||
| 109 | - for (i = 0; i < TPM_MAX_DRIVERS; i++) { | ||
| 110 | - if (!be_drivers[i]) { | ||
| 111 | - be_drivers[i] = tdo; | ||
| 112 | - return 0; | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - error_report("Could not register TPM driver"); | ||
| 116 | - return 1; | ||
| 117 | + be_drivers[tdo->type] = tdo; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* | ||
| 121 | @@ -100,9 +85,12 @@ static void tpm_display_backend_drivers(void) | ||
| 122 | |||
| 123 | fprintf(stderr, "Supported TPM types (choose only one):\n"); | ||
| 124 | |||
| 125 | - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { | ||
| 126 | + for (i = 0; i < TPM_TYPE__MAX; i++) { | ||
| 127 | + if (be_drivers[i] == NULL) { | ||
| 128 | + continue; | ||
| 129 | + } | ||
| 130 | fprintf(stderr, "%12s %s\n", | ||
| 131 | - TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc()); | ||
| 132 | + TpmType_lookup[i], be_drivers[i]->desc()); | ||
| 133 | } | ||
| 134 | fprintf(stderr, "\n"); | ||
| 135 | } | ||
| 136 | @@ -239,14 +227,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg) | ||
| 137 | |||
| 138 | static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) | ||
| 139 | { | ||
| 140 | - int i; | ||
| 141 | - | ||
| 142 | - for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) { | ||
| 143 | - if (be_drivers[i]->type == type) { | ||
| 144 | - return be_drivers[i]; | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - return NULL; | ||
| 148 | + return be_drivers[type]; | ||
| 149 | } | ||
| 150 | |||
| 151 | static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) | ||
| 152 | -- | ||
| 153 | 2.11.0 | ||
| 154 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0002-Introduce-condition-to-notify-waiters-of-completed-c.patch b/meta/recipes-devtools/qemu/qemu/0002-Introduce-condition-to-notify-waiters-of-completed-c.patch deleted file mode 100644 index c88c98e565..0000000000 --- a/meta/recipes-devtools/qemu/qemu/0002-Introduce-condition-to-notify-waiters-of-completed-c.patch +++ /dev/null | |||
| @@ -1,86 +0,0 @@ | |||
| 1 | From b5ffd3aa4e9bd4edb09cc84c46f78da72697a946 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 3 | Date: Sat, 31 Dec 2016 11:23:32 -0500 | ||
| 4 | Subject: [PATCH 2/4] Introduce condition to notify waiters of completed | ||
| 5 | command | ||
| 6 | |||
| 7 | Introduce a lock and a condition to notify anyone waiting for the completion | ||
| 8 | of the execution of a TPM command by the backend (thread). The backend | ||
| 9 | uses the condition to signal anyone waiting for command completion. | ||
| 10 | We need to place the condition in two locations: one is invoked by the | ||
| 11 | backend thread, the other by the bottom half thread. | ||
| 12 | We will use the signalling to wait for command completion before VM | ||
| 13 | suspend. | ||
| 14 | |||
| 15 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 16 | |||
| 17 | Upstream-Status: Pending [https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg00252.html] | ||
| 18 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> | ||
| 19 | --- | ||
| 20 | hw/tpm/tpm_int.h | 3 +++ | ||
| 21 | hw/tpm/tpm_tis.c | 14 ++++++++++++++ | ||
| 22 | 2 files changed, 17 insertions(+) | ||
| 23 | |||
| 24 | diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h | ||
| 25 | index 6b2c9c953a..70be1ad8d9 100644 | ||
| 26 | --- a/hw/tpm/tpm_int.h | ||
| 27 | +++ b/hw/tpm/tpm_int.h | ||
| 28 | @@ -30,6 +30,9 @@ struct TPMState { | ||
| 29 | char *backend; | ||
| 30 | TPMBackend *be_driver; | ||
| 31 | TPMVersion be_tpm_version; | ||
| 32 | + | ||
| 33 | + QemuMutex state_lock; | ||
| 34 | + QemuCond cmd_complete; | ||
| 35 | }; | ||
| 36 | |||
| 37 | #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) | ||
| 38 | diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c | ||
| 39 | index 381e7266ea..14d9e83ea2 100644 | ||
| 40 | --- a/hw/tpm/tpm_tis.c | ||
| 41 | +++ b/hw/tpm/tpm_tis.c | ||
| 42 | @@ -368,6 +368,8 @@ static void tpm_tis_receive_bh(void *opaque) | ||
| 43 | TPMTISEmuState *tis = &s->s.tis; | ||
| 44 | uint8_t locty = s->locty_number; | ||
| 45 | |||
| 46 | + qemu_mutex_lock(&s->state_lock); | ||
| 47 | + | ||
| 48 | tpm_tis_sts_set(&tis->loc[locty], | ||
| 49 | TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); | ||
| 50 | tis->loc[locty].state = TPM_TIS_STATE_COMPLETION; | ||
| 51 | @@ -384,6 +386,10 @@ static void tpm_tis_receive_bh(void *opaque) | ||
| 52 | tpm_tis_raise_irq(s, locty, | ||
| 53 | TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); | ||
| 54 | #endif | ||
| 55 | + | ||
| 56 | + /* notify of completed command */ | ||
| 57 | + qemu_cond_signal(&s->cmd_complete); | ||
| 58 | + qemu_mutex_unlock(&s->state_lock); | ||
| 59 | } | ||
| 60 | |||
| 61 | /* | ||
| 62 | @@ -403,6 +409,11 @@ static void tpm_tis_receive_cb(TPMState *s, uint8_t locty, | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | + qemu_mutex_lock(&s->state_lock); | ||
| 67 | + /* notify of completed command */ | ||
| 68 | + qemu_cond_signal(&s->cmd_complete); | ||
| 69 | + qemu_mutex_unlock(&s->state_lock); | ||
| 70 | + | ||
| 71 | qemu_bh_schedule(tis->bh); | ||
| 72 | } | ||
| 73 | |||
| 74 | @@ -1072,6 +1083,9 @@ static void tpm_tis_initfn(Object *obj) | ||
| 75 | memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, | ||
| 76 | s, "tpm-tis-mmio", | ||
| 77 | TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); | ||
| 78 | + | ||
| 79 | + qemu_mutex_init(&s->state_lock); | ||
| 80 | + qemu_cond_init(&s->cmd_complete); | ||
| 81 | } | ||
| 82 | |||
| 83 | static void tpm_tis_class_init(ObjectClass *klass, void *data) | ||
| 84 | -- | ||
| 85 | 2.11.0 | ||
| 86 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0002-tpm-Clean-up-model-registration-lookup.patch b/meta/recipes-devtools/qemu/qemu/0002-tpm-Clean-up-model-registration-lookup.patch new file mode 100644 index 0000000000..c223ba83b6 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0002-tpm-Clean-up-model-registration-lookup.patch | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | From 89430c64784484214b3c99562520cdffe79cd801 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Markus Armbruster <armbru@redhat.com> | ||
| 3 | Date: Thu, 24 Aug 2017 10:45:59 +0200 | ||
| 4 | Subject: [PATCH 02/12] tpm: Clean up model registration & lookup | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | We have a strict separation between enum TpmModel and tpm_models[]: | ||
| 10 | |||
| 11 | * TpmModel may have any number of members. It just happens to have one. | ||
| 12 | |||
| 13 | * tpm_register_model() uses the first empty slot in tpm_models[]. | ||
| 14 | |||
| 15 | If you register more than tpm_models[] has space, | ||
| 16 | tpn_register_model() fails. Its caller silently ignores the | ||
| 17 | failure. | ||
| 18 | |||
| 19 | Register the same TpmModel more than once has no effect other than | ||
| 20 | wasting tpm_models[] slots: tpm_model_is_registered() is happy with | ||
| 21 | the first one it finds. | ||
| 22 | |||
| 23 | Since we only ever register one model, and tpm_models[] has space for | ||
| 24 | just that one, this contraption even works. | ||
| 25 | |||
| 26 | Turn tpm_models[] into a straight map from enum TpmType to bool. Much | ||
| 27 | simpler. | ||
| 28 | |||
| 29 | Cc: Stefan Berger <stefanb@us.ibm.com> | ||
| 30 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
| 31 | Message-Id: <1503564371-26090-5-git-send-email-armbru@redhat.com> | ||
| 32 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 33 | [Commit message typo fixed] | ||
| 34 | |||
| 35 | Upstream-Status: Backport | ||
| 36 | --- | ||
| 37 | include/sysemu/tpm_backend.h | 2 +- | ||
| 38 | tpm.c | 37 +++++-------------------------------- | ||
| 39 | 2 files changed, 6 insertions(+), 33 deletions(-) | ||
| 40 | |||
| 41 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 42 | index 1d21c6b19b..b0a9731aee 100644 | ||
| 43 | --- a/include/sysemu/tpm_backend.h | ||
| 44 | +++ b/include/sysemu/tpm_backend.h | ||
| 45 | @@ -226,7 +226,7 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); | ||
| 46 | TPMBackend *qemu_find_tpm(const char *id); | ||
| 47 | |||
| 48 | const TPMDriverOps *tpm_get_backend_driver(const char *type); | ||
| 49 | -int tpm_register_model(enum TpmModel model); | ||
| 50 | +void tpm_register_model(enum TpmModel model); | ||
| 51 | void tpm_register_driver(const TPMDriverOps *tdo); | ||
| 52 | |||
| 53 | #endif | ||
| 54 | diff --git a/tpm.c b/tpm.c | ||
| 55 | index bb45d0c08e..2dbea70645 100644 | ||
| 56 | --- a/tpm.c | ||
| 57 | +++ b/tpm.c | ||
| 58 | @@ -24,39 +24,12 @@ | ||
| 59 | static QLIST_HEAD(, TPMBackend) tpm_backends = | ||
| 60 | QLIST_HEAD_INITIALIZER(tpm_backends); | ||
| 61 | |||
| 62 | - | ||
| 63 | -#define TPM_MAX_MODELS 1 | ||
| 64 | - | ||
| 65 | static TPMDriverOps const *be_drivers[TPM_TYPE__MAX]; | ||
| 66 | +static bool tpm_models[TPM_MODEL__MAX]; | ||
| 67 | |||
| 68 | -static enum TpmModel tpm_models[TPM_MAX_MODELS] = { | ||
| 69 | - TPM_MODEL__MAX, | ||
| 70 | -}; | ||
| 71 | - | ||
| 72 | -int tpm_register_model(enum TpmModel model) | ||
| 73 | -{ | ||
| 74 | - int i; | ||
| 75 | - | ||
| 76 | - for (i = 0; i < TPM_MAX_MODELS; i++) { | ||
| 77 | - if (tpm_models[i] == TPM_MODEL__MAX) { | ||
| 78 | - tpm_models[i] = model; | ||
| 79 | - return 0; | ||
| 80 | - } | ||
| 81 | - } | ||
| 82 | - error_report("Could not register TPM model"); | ||
| 83 | - return 1; | ||
| 84 | -} | ||
| 85 | - | ||
| 86 | -static bool tpm_model_is_registered(enum TpmModel model) | ||
| 87 | +void tpm_register_model(enum TpmModel model) | ||
| 88 | { | ||
| 89 | - int i; | ||
| 90 | - | ||
| 91 | - for (i = 0; i < TPM_MAX_MODELS; i++) { | ||
| 92 | - if (tpm_models[i] == model) { | ||
| 93 | - return true; | ||
| 94 | - } | ||
| 95 | - } | ||
| 96 | - return false; | ||
| 97 | + tpm_models[model] = true; | ||
| 98 | } | ||
| 99 | |||
| 100 | const TPMDriverOps *tpm_get_backend_driver(const char *type) | ||
| 101 | @@ -270,7 +243,7 @@ TPMInfoList *qmp_query_tpm(Error **errp) | ||
| 102 | TPMInfoList *info, *head = NULL, *cur_item = NULL; | ||
| 103 | |||
| 104 | QLIST_FOREACH(drv, &tpm_backends, list) { | ||
| 105 | - if (!tpm_model_is_registered(drv->fe_model)) { | ||
| 106 | + if (!tpm_models[drv->fe_model]) { | ||
| 107 | continue; | ||
| 108 | } | ||
| 109 | info = g_new0(TPMInfoList, 1); | ||
| 110 | @@ -317,7 +290,7 @@ TpmModelList *qmp_query_tpm_models(Error **errp) | ||
| 111 | TpmModelList *head = NULL, *prev = NULL, *cur_item; | ||
| 112 | |||
| 113 | for (i = 0; i < TPM_MODEL__MAX; i++) { | ||
| 114 | - if (!tpm_model_is_registered(i)) { | ||
| 115 | + if (!tpm_models[i]) { | ||
| 116 | continue; | ||
| 117 | } | ||
| 118 | cur_item = g_new0(TpmModelList, 1); | ||
| 119 | -- | ||
| 120 | 2.11.0 | ||
| 121 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch b/meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch deleted file mode 100644 index e58f019062..0000000000 --- a/meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch +++ /dev/null | |||
| @@ -1,79 +0,0 @@ | |||
| 1 | From 732a8e046948fd62b32cd1dd76a6798eb1caf4d6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 3 | Date: Sat, 31 Dec 2016 11:23:32 -0500 | ||
| 4 | Subject: [PATCH 3/4] Introduce condition in TPM backend for notification | ||
| 5 | |||
| 6 | TPM backends will suspend independently of the frontends. Also | ||
| 7 | here we need to be able to wait for the TPM command to have been | ||
| 8 | completely processed. | ||
| 9 | |||
| 10 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 11 | |||
| 12 | Upstream-Status: Pending [https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg00252.html] | ||
| 13 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> | ||
| 14 | --- | ||
| 15 | hw/tpm/tpm_passthrough.c | 20 ++++++++++++++++++++ | ||
| 16 | 1 file changed, 20 insertions(+) | ||
| 17 | |||
| 18 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 19 | index 050f2ba850..44739ebad2 100644 | ||
| 20 | --- a/hw/tpm/tpm_passthrough.c | ||
| 21 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 22 | @@ -75,6 +75,10 @@ struct TPMPassthruState { | ||
| 23 | TPMVersion tpm_version; | ||
| 24 | ptm_cap cuse_cap; /* capabilities of the CUSE TPM */ | ||
| 25 | uint8_t cur_locty_number; /* last set locality */ | ||
| 26 | + | ||
| 27 | + QemuMutex state_lock; | ||
| 28 | + QemuCond cmd_complete; /* singnaled once tpm_busy is false */ | ||
| 29 | + bool tpm_busy; | ||
| 30 | }; | ||
| 31 | |||
| 32 | typedef struct TPMPassthruState TPMPassthruState; | ||
| 33 | @@ -274,6 +278,11 @@ static void tpm_passthrough_worker_thread(gpointer data, | ||
| 34 | thr_parms->recv_data_callback(thr_parms->tpm_state, | ||
| 35 | thr_parms->tpm_state->locty_number, | ||
| 36 | selftest_done); | ||
| 37 | + /* result delivered */ | ||
| 38 | + qemu_mutex_lock(&tpm_pt->state_lock); | ||
| 39 | + tpm_pt->tpm_busy = false; | ||
| 40 | + qemu_cond_signal(&tpm_pt->cmd_complete); | ||
| 41 | + qemu_mutex_unlock(&tpm_pt->state_lock); | ||
| 42 | break; | ||
| 43 | case TPM_BACKEND_CMD_INIT: | ||
| 44 | case TPM_BACKEND_CMD_END: | ||
| 45 | @@ -401,6 +410,7 @@ static void tpm_passthrough_reset(TPMBackend *tb) | ||
| 46 | tpm_backend_thread_end(&tpm_pt->tbt); | ||
| 47 | |||
| 48 | tpm_pt->had_startup_error = false; | ||
| 49 | + tpm_pt->tpm_busy = false; | ||
| 50 | } | ||
| 51 | |||
| 52 | static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, | ||
| 53 | @@ -478,6 +488,11 @@ static void tpm_passthrough_deliver_request(TPMBackend *tb) | ||
| 54 | { | ||
| 55 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 56 | |||
| 57 | + /* TPM considered busy once TPM Request scheduled for processing */ | ||
| 58 | + qemu_mutex_lock(&tpm_pt->state_lock); | ||
| 59 | + tpm_pt->tpm_busy = true; | ||
| 60 | + qemu_mutex_unlock(&tpm_pt->state_lock); | ||
| 61 | + | ||
| 62 | tpm_backend_thread_deliver_request(&tpm_pt->tbt); | ||
| 63 | } | ||
| 64 | |||
| 65 | @@ -746,6 +761,11 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 66 | |||
| 67 | static void tpm_passthrough_inst_init(Object *obj) | ||
| 68 | { | ||
| 69 | + TPMBackend *tb = TPM_BACKEND(obj); | ||
| 70 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 71 | + | ||
| 72 | + qemu_mutex_init(&tpm_pt->state_lock); | ||
| 73 | + qemu_cond_init(&tpm_pt->cmd_complete); | ||
| 74 | } | ||
| 75 | |||
| 76 | static void tpm_passthrough_inst_finalize(Object *obj) | ||
| 77 | -- | ||
| 78 | 2.11.0 | ||
| 79 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0003-tpm-backend-Remove-unneeded-member-variable-from-bac.patch b/meta/recipes-devtools/qemu/qemu/0003-tpm-backend-Remove-unneeded-member-variable-from-bac.patch new file mode 100644 index 0000000000..6b94eba720 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0003-tpm-backend-Remove-unneeded-member-variable-from-bac.patch | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | From cac845f55b8f27e5c90e0f2e3dcbeea7013df67c Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Thu, 30 Mar 2017 15:55:17 +0300 | ||
| 4 | Subject: [PATCH 03/12] tpm-backend: Remove unneeded member variable from | ||
| 5 | backend class | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=UTF-8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | TPMDriverOps inside TPMBackend is not required, as it is supposed to be a class | ||
| 11 | member. The only possible reason for keeping in TPMBackend was, to get the | ||
| 12 | backend type in tpm.c where dedicated backend api, tpm_backend_get_type() is | ||
| 13 | present. | ||
| 14 | |||
| 15 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 16 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 17 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 18 | |||
| 19 | Upstream-Status: Backport [fb4b0c6765471dad2363875989e7661ca5f9a608] | ||
| 20 | --- | ||
| 21 | hw/tpm/tpm_passthrough.c | 4 ---- | ||
| 22 | include/sysemu/tpm_backend.h | 1 - | ||
| 23 | tpm.c | 2 +- | ||
| 24 | 3 files changed, 1 insertion(+), 6 deletions(-) | ||
| 25 | |||
| 26 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 27 | index 9234eb3459..a0baf5f080 100644 | ||
| 28 | --- a/hw/tpm/tpm_passthrough.c | ||
| 29 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 30 | @@ -46,8 +46,6 @@ | ||
| 31 | #define TPM_PASSTHROUGH(obj) \ | ||
| 32 | OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) | ||
| 33 | |||
| 34 | -static const TPMDriverOps tpm_passthrough_driver; | ||
| 35 | - | ||
| 36 | /* data structures */ | ||
| 37 | typedef struct TPMPassthruThreadParams { | ||
| 38 | TPMState *tpm_state; | ||
| 39 | @@ -462,8 +460,6 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) | ||
| 40 | /* let frontend set the fe_model to proper value */ | ||
| 41 | tb->fe_model = -1; | ||
| 42 | |||
| 43 | - tb->ops = &tpm_passthrough_driver; | ||
| 44 | - | ||
| 45 | if (tpm_passthrough_handle_device_opts(opts, tb)) { | ||
| 46 | goto err_exit; | ||
| 47 | } | ||
| 48 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 49 | index b0a9731aee..3708413035 100644 | ||
| 50 | --- a/include/sysemu/tpm_backend.h | ||
| 51 | +++ b/include/sysemu/tpm_backend.h | ||
| 52 | @@ -50,7 +50,6 @@ struct TPMBackend { | ||
| 53 | enum TpmModel fe_model; | ||
| 54 | char *path; | ||
| 55 | char *cancel_path; | ||
| 56 | - const TPMDriverOps *ops; | ||
| 57 | |||
| 58 | QLIST_ENTRY(TPMBackend) list; | ||
| 59 | }; | ||
| 60 | diff --git a/tpm.c b/tpm.c | ||
| 61 | index 2dbea70645..b7166ca200 100644 | ||
| 62 | --- a/tpm.c | ||
| 63 | +++ b/tpm.c | ||
| 64 | @@ -212,7 +212,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) | ||
| 65 | res->model = drv->fe_model; | ||
| 66 | res->options = g_new0(TpmTypeOptions, 1); | ||
| 67 | |||
| 68 | - switch (drv->ops->type) { | ||
| 69 | + switch (tpm_backend_get_type(drv)) { | ||
| 70 | case TPM_TYPE_PASSTHROUGH: | ||
| 71 | res->options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; | ||
| 72 | tpo = g_new0(TPMPassthroughOptions, 1); | ||
| 73 | -- | ||
| 74 | 2.11.0 | ||
| 75 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch b/meta/recipes-devtools/qemu/qemu/0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch deleted file mode 100644 index f1dbaffeac..0000000000 --- a/meta/recipes-devtools/qemu/qemu/0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch +++ /dev/null | |||
| @@ -1,719 +0,0 @@ | |||
| 1 | From 5e9dd9063f514447ea4f54046793f4f01c297ed4 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 3 | Date: Sat, 31 Dec 2016 11:23:32 -0500 | ||
| 4 | Subject: [PATCH 4/4] Add support for VM suspend/resume for TPM TIS | ||
| 5 | |||
| 6 | Extend the TPM TIS code to support suspend/resume. In case a command | ||
| 7 | is being processed by the external TPM when suspending, wait for the command | ||
| 8 | to complete to catch the result. In case the bottom half did not run, | ||
| 9 | run the one function the bottom half is supposed to run. This then | ||
| 10 | makes the resume operation work. | ||
| 11 | |||
| 12 | The passthrough backend does not support suspend/resume operation | ||
| 13 | and is therefore blocked from suspend/resume and migration. | ||
| 14 | |||
| 15 | The CUSE TPM's supported capabilities are tested and if sufficient | ||
| 16 | capabilities are implemented, suspend/resume, snapshotting and | ||
| 17 | migration are supported by the CUSE TPM. | ||
| 18 | |||
| 19 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 20 | |||
| 21 | Upstream-Status: Pending [https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg00252.html] | ||
| 22 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> | ||
| 23 | --- | ||
| 24 | hw/tpm/tpm_passthrough.c | 130 +++++++++++++++++++++++-- | ||
| 25 | hw/tpm/tpm_tis.c | 137 +++++++++++++++++++++++++- | ||
| 26 | hw/tpm/tpm_tis.h | 2 + | ||
| 27 | hw/tpm/tpm_util.c | 223 +++++++++++++++++++++++++++++++++++++++++++ | ||
| 28 | hw/tpm/tpm_util.h | 7 ++ | ||
| 29 | include/sysemu/tpm_backend.h | 12 +++ | ||
| 30 | 6 files changed, 503 insertions(+), 8 deletions(-) | ||
| 31 | |||
| 32 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 33 | index 44739ebad2..bc8072d0bc 100644 | ||
| 34 | --- a/hw/tpm/tpm_passthrough.c | ||
| 35 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 36 | @@ -34,6 +34,8 @@ | ||
| 37 | #include "tpm_tis.h" | ||
| 38 | #include "tpm_util.h" | ||
| 39 | #include "tpm_ioctl.h" | ||
| 40 | +#include "migration/migration.h" | ||
| 41 | +#include "qapi/error.h" | ||
| 42 | |||
| 43 | #define DEBUG_TPM 0 | ||
| 44 | |||
| 45 | @@ -49,6 +51,7 @@ | ||
| 46 | #define TYPE_TPM_CUSE "tpm-cuse" | ||
| 47 | |||
| 48 | static const TPMDriverOps tpm_passthrough_driver; | ||
| 49 | +static const VMStateDescription vmstate_tpm_cuse; | ||
| 50 | |||
| 51 | /* data structures */ | ||
| 52 | typedef struct TPMPassthruThreadParams { | ||
| 53 | @@ -79,6 +82,10 @@ struct TPMPassthruState { | ||
| 54 | QemuMutex state_lock; | ||
| 55 | QemuCond cmd_complete; /* singnaled once tpm_busy is false */ | ||
| 56 | bool tpm_busy; | ||
| 57 | + | ||
| 58 | + Error *migration_blocker; | ||
| 59 | + | ||
| 60 | + TPMBlobBuffers tpm_blobs; | ||
| 61 | }; | ||
| 62 | |||
| 63 | typedef struct TPMPassthruState TPMPassthruState; | ||
| 64 | @@ -306,6 +313,10 @@ static void tpm_passthrough_shutdown(TPMPassthruState *tpm_pt) | ||
| 65 | strerror(errno)); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | + if (tpm_pt->migration_blocker) { | ||
| 69 | + migrate_del_blocker(tpm_pt->migration_blocker); | ||
| 70 | + error_free(tpm_pt->migration_blocker); | ||
| 71 | + } | ||
| 72 | } | ||
| 73 | |||
| 74 | /* | ||
| 75 | @@ -360,12 +371,14 @@ static int tpm_passthrough_cuse_check_caps(TPMPassthruState *tpm_pt) | ||
| 76 | /* | ||
| 77 | * Initialize the external CUSE TPM | ||
| 78 | */ | ||
| 79 | -static int tpm_passthrough_cuse_init(TPMPassthruState *tpm_pt) | ||
| 80 | +static int tpm_passthrough_cuse_init(TPMPassthruState *tpm_pt, | ||
| 81 | + bool is_resume) | ||
| 82 | { | ||
| 83 | int rc = 0; | ||
| 84 | - ptm_init init = { | ||
| 85 | - .u.req.init_flags = PTM_INIT_FLAG_DELETE_VOLATILE, | ||
| 86 | - }; | ||
| 87 | + ptm_init init; | ||
| 88 | + if (is_resume) { | ||
| 89 | + init.u.req.init_flags = PTM_INIT_FLAG_DELETE_VOLATILE; | ||
| 90 | + } | ||
| 91 | |||
| 92 | if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 93 | if (ioctl(tpm_pt->tpm_fd, PTM_INIT, &init) < 0) { | ||
| 94 | @@ -394,7 +407,7 @@ static int tpm_passthrough_startup_tpm(TPMBackend *tb) | ||
| 95 | tpm_passthrough_worker_thread, | ||
| 96 | &tpm_pt->tpm_thread_params); | ||
| 97 | |||
| 98 | - tpm_passthrough_cuse_init(tpm_pt); | ||
| 99 | + tpm_passthrough_cuse_init(tpm_pt, false); | ||
| 100 | |||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | @@ -466,6 +479,32 @@ static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb, | ||
| 104 | return rc; | ||
| 105 | } | ||
| 106 | |||
| 107 | +static int tpm_cuse_get_state_blobs(TPMBackend *tb, | ||
| 108 | + bool decrypted_blobs, | ||
| 109 | + TPMBlobBuffers *tpm_blobs) | ||
| 110 | +{ | ||
| 111 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 112 | + | ||
| 113 | + assert(TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)); | ||
| 114 | + | ||
| 115 | + return tpm_util_cuse_get_state_blobs(tpm_pt->tpm_fd, decrypted_blobs, | ||
| 116 | + tpm_blobs); | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +static int tpm_cuse_set_state_blobs(TPMBackend *tb, | ||
| 120 | + TPMBlobBuffers *tpm_blobs) | ||
| 121 | +{ | ||
| 122 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 123 | + | ||
| 124 | + assert(TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)); | ||
| 125 | + | ||
| 126 | + if (tpm_util_cuse_set_state_blobs(tpm_pt->tpm_fd, tpm_blobs)) { | ||
| 127 | + return 1; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + return tpm_passthrough_cuse_init(tpm_pt, true); | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | static bool tpm_passthrough_get_startup_error(TPMBackend *tb) | ||
| 134 | { | ||
| 135 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 136 | @@ -488,7 +527,7 @@ static void tpm_passthrough_deliver_request(TPMBackend *tb) | ||
| 137 | { | ||
| 138 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 139 | |||
| 140 | - /* TPM considered busy once TPM Request scheduled for processing */ | ||
| 141 | + /* TPM considered busy once TPM request scheduled for processing */ | ||
| 142 | qemu_mutex_lock(&tpm_pt->state_lock); | ||
| 143 | tpm_pt->tpm_busy = true; | ||
| 144 | qemu_mutex_unlock(&tpm_pt->state_lock); | ||
| 145 | @@ -601,6 +640,25 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) | ||
| 146 | return fd; | ||
| 147 | } | ||
| 148 | |||
| 149 | +static void tpm_passthrough_block_migration(TPMPassthruState *tpm_pt) | ||
| 150 | +{ | ||
| 151 | + ptm_cap caps; | ||
| 152 | + | ||
| 153 | + if (TPM_PASSTHROUGH_USES_CUSE_TPM(tpm_pt)) { | ||
| 154 | + caps = PTM_CAP_GET_STATEBLOB | PTM_CAP_SET_STATEBLOB | | ||
| 155 | + PTM_CAP_STOP; | ||
| 156 | + if (!TPM_CUSE_IMPLEMENTS_ALL(tpm_pt, caps)) { | ||
| 157 | + error_setg(&tpm_pt->migration_blocker, | ||
| 158 | + "Migration disabled: CUSE TPM lacks necessary capabilities"); | ||
| 159 | + migrate_add_blocker(tpm_pt->migration_blocker); | ||
| 160 | + } | ||
| 161 | + } else { | ||
| 162 | + error_setg(&tpm_pt->migration_blocker, | ||
| 163 | + "Migration disabled: Passthrough TPM does not support migration"); | ||
| 164 | + migrate_add_blocker(tpm_pt->migration_blocker); | ||
| 165 | + } | ||
| 166 | +} | ||
| 167 | + | ||
| 168 | static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 169 | { | ||
| 170 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 171 | @@ -642,7 +700,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 172 | goto err_close_tpmdev; | ||
| 173 | } | ||
| 174 | /* init TPM for probing */ | ||
| 175 | - if (tpm_passthrough_cuse_init(tpm_pt)) { | ||
| 176 | + if (tpm_passthrough_cuse_init(tpm_pt, false)) { | ||
| 177 | goto err_close_tpmdev; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | @@ -659,6 +717,7 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | + tpm_passthrough_block_migration(tpm_pt); | ||
| 185 | |||
| 186 | return 0; | ||
| 187 | |||
| 188 | @@ -766,10 +825,13 @@ static void tpm_passthrough_inst_init(Object *obj) | ||
| 189 | |||
| 190 | qemu_mutex_init(&tpm_pt->state_lock); | ||
| 191 | qemu_cond_init(&tpm_pt->cmd_complete); | ||
| 192 | + | ||
| 193 | + vmstate_register(NULL, -1, &vmstate_tpm_cuse, obj); | ||
| 194 | } | ||
| 195 | |||
| 196 | static void tpm_passthrough_inst_finalize(Object *obj) | ||
| 197 | { | ||
| 198 | + vmstate_unregister(NULL, &vmstate_tpm_cuse, obj); | ||
| 199 | } | ||
| 200 | |||
| 201 | static void tpm_passthrough_class_init(ObjectClass *klass, void *data) | ||
| 202 | @@ -802,6 +864,60 @@ static const char *tpm_passthrough_cuse_create_desc(void) | ||
| 203 | return "CUSE TPM backend driver"; | ||
| 204 | } | ||
| 205 | |||
| 206 | +static void tpm_cuse_pre_save(void *opaque) | ||
| 207 | +{ | ||
| 208 | + TPMPassthruState *tpm_pt = opaque; | ||
| 209 | + TPMBackend *tb = &tpm_pt->parent; | ||
| 210 | + | ||
| 211 | + qemu_mutex_lock(&tpm_pt->state_lock); | ||
| 212 | + /* wait for TPM to finish processing */ | ||
| 213 | + if (tpm_pt->tpm_busy) { | ||
| 214 | + qemu_cond_wait(&tpm_pt->cmd_complete, &tpm_pt->state_lock); | ||
| 215 | + } | ||
| 216 | + qemu_mutex_unlock(&tpm_pt->state_lock); | ||
| 217 | + | ||
| 218 | + /* get the decrypted state blobs from the TPM */ | ||
| 219 | + tpm_cuse_get_state_blobs(tb, TRUE, &tpm_pt->tpm_blobs); | ||
| 220 | +} | ||
| 221 | + | ||
| 222 | +static int tpm_cuse_post_load(void *opaque, | ||
| 223 | + int version_id __attribute__((unused))) | ||
| 224 | +{ | ||
| 225 | + TPMPassthruState *tpm_pt = opaque; | ||
| 226 | + TPMBackend *tb = &tpm_pt->parent; | ||
| 227 | + | ||
| 228 | + return tpm_cuse_set_state_blobs(tb, &tpm_pt->tpm_blobs); | ||
| 229 | +} | ||
| 230 | + | ||
| 231 | +static const VMStateDescription vmstate_tpm_cuse = { | ||
| 232 | + .name = "cuse-tpm", | ||
| 233 | + .version_id = 1, | ||
| 234 | + .minimum_version_id = 0, | ||
| 235 | + .minimum_version_id_old = 0, | ||
| 236 | + .pre_save = tpm_cuse_pre_save, | ||
| 237 | + .post_load = tpm_cuse_post_load, | ||
| 238 | + .fields = (VMStateField[]) { | ||
| 239 | + VMSTATE_UINT32(tpm_blobs.permanent_flags, TPMPassthruState), | ||
| 240 | + VMSTATE_UINT32(tpm_blobs.permanent.size, TPMPassthruState), | ||
| 241 | + VMSTATE_VBUFFER_ALLOC_UINT32(tpm_blobs.permanent.buffer, | ||
| 242 | + TPMPassthruState, 1, NULL, | ||
| 243 | + tpm_blobs.permanent.size), | ||
| 244 | + | ||
| 245 | + VMSTATE_UINT32(tpm_blobs.volatil_flags, TPMPassthruState), | ||
| 246 | + VMSTATE_UINT32(tpm_blobs.volatil.size, TPMPassthruState), | ||
| 247 | + VMSTATE_VBUFFER_ALLOC_UINT32(tpm_blobs.volatil.buffer, | ||
| 248 | + TPMPassthruState, 1, NULL, | ||
| 249 | + tpm_blobs.volatil.size), | ||
| 250 | + | ||
| 251 | + VMSTATE_UINT32(tpm_blobs.savestate_flags, TPMPassthruState), | ||
| 252 | + VMSTATE_UINT32(tpm_blobs.savestate.size, TPMPassthruState), | ||
| 253 | + VMSTATE_VBUFFER_ALLOC_UINT32(tpm_blobs.savestate.buffer, | ||
| 254 | + TPMPassthruState, 1, NULL, | ||
| 255 | + tpm_blobs.savestate.size), | ||
| 256 | + VMSTATE_END_OF_LIST() | ||
| 257 | + } | ||
| 258 | +}; | ||
| 259 | + | ||
| 260 | static const TPMDriverOps tpm_cuse_driver = { | ||
| 261 | .type = TPM_TYPE_CUSE_TPM, | ||
| 262 | .opts = tpm_passthrough_cmdline_opts, | ||
| 263 | diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c | ||
| 264 | index 14d9e83ea2..9b660cf737 100644 | ||
| 265 | --- a/hw/tpm/tpm_tis.c | ||
| 266 | +++ b/hw/tpm/tpm_tis.c | ||
| 267 | @@ -368,6 +368,8 @@ static void tpm_tis_receive_bh(void *opaque) | ||
| 268 | TPMTISEmuState *tis = &s->s.tis; | ||
| 269 | uint8_t locty = s->locty_number; | ||
| 270 | |||
| 271 | + tis->bh_scheduled = false; | ||
| 272 | + | ||
| 273 | qemu_mutex_lock(&s->state_lock); | ||
| 274 | |||
| 275 | tpm_tis_sts_set(&tis->loc[locty], | ||
| 276 | @@ -415,6 +417,8 @@ static void tpm_tis_receive_cb(TPMState *s, uint8_t locty, | ||
| 277 | qemu_mutex_unlock(&s->state_lock); | ||
| 278 | |||
| 279 | qemu_bh_schedule(tis->bh); | ||
| 280 | + | ||
| 281 | + tis->bh_scheduled = true; | ||
| 282 | } | ||
| 283 | |||
| 284 | /* | ||
| 285 | @@ -1030,9 +1034,140 @@ static void tpm_tis_reset(DeviceState *dev) | ||
| 286 | tpm_tis_do_startup_tpm(s); | ||
| 287 | } | ||
| 288 | |||
| 289 | + | ||
| 290 | +/* persistent state handling */ | ||
| 291 | + | ||
| 292 | +static void tpm_tis_pre_save(void *opaque) | ||
| 293 | +{ | ||
| 294 | + TPMState *s = opaque; | ||
| 295 | + TPMTISEmuState *tis = &s->s.tis; | ||
| 296 | + uint8_t locty = tis->active_locty; | ||
| 297 | + | ||
| 298 | + DPRINTF("tpm_tis: suspend: locty = %d : r_offset = %d, w_offset = %d\n", | ||
| 299 | + locty, tis->loc[0].r_offset, tis->loc[0].w_offset); | ||
| 300 | +#ifdef DEBUG_TIS | ||
| 301 | + tpm_tis_dump_state(opaque, 0); | ||
| 302 | +#endif | ||
| 303 | + | ||
| 304 | + qemu_mutex_lock(&s->state_lock); | ||
| 305 | + | ||
| 306 | + /* wait for outstanding request to complete */ | ||
| 307 | + if (TPM_TIS_IS_VALID_LOCTY(locty) && | ||
| 308 | + tis->loc[locty].state == TPM_TIS_STATE_EXECUTION) { | ||
| 309 | + /* | ||
| 310 | + * If we get here when the bh is scheduled but did not run, | ||
| 311 | + * we won't get notified... | ||
| 312 | + */ | ||
| 313 | + if (!tis->bh_scheduled) { | ||
| 314 | + /* backend thread to notify us */ | ||
| 315 | + qemu_cond_wait(&s->cmd_complete, &s->state_lock); | ||
| 316 | + } | ||
| 317 | + if (tis->loc[locty].state == TPM_TIS_STATE_EXECUTION) { | ||
| 318 | + /* bottom half did not run - run its function */ | ||
| 319 | + qemu_mutex_unlock(&s->state_lock); | ||
| 320 | + tpm_tis_receive_bh(opaque); | ||
| 321 | + qemu_mutex_lock(&s->state_lock); | ||
| 322 | + } | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + qemu_mutex_unlock(&s->state_lock); | ||
| 326 | + | ||
| 327 | + /* copy current active read or write buffer into the buffer | ||
| 328 | + written to disk */ | ||
| 329 | + if (TPM_TIS_IS_VALID_LOCTY(locty)) { | ||
| 330 | + switch (tis->loc[locty].state) { | ||
| 331 | + case TPM_TIS_STATE_RECEPTION: | ||
| 332 | + memcpy(tis->buf, | ||
| 333 | + tis->loc[locty].w_buffer.buffer, | ||
| 334 | + MIN(sizeof(tis->buf), | ||
| 335 | + tis->loc[locty].w_buffer.size)); | ||
| 336 | + tis->offset = tis->loc[locty].w_offset; | ||
| 337 | + break; | ||
| 338 | + case TPM_TIS_STATE_COMPLETION: | ||
| 339 | + memcpy(tis->buf, | ||
| 340 | + tis->loc[locty].r_buffer.buffer, | ||
| 341 | + MIN(sizeof(tis->buf), | ||
| 342 | + tis->loc[locty].r_buffer.size)); | ||
| 343 | + tis->offset = tis->loc[locty].r_offset; | ||
| 344 | + break; | ||
| 345 | + default: | ||
| 346 | + /* leak nothing */ | ||
| 347 | + memset(tis->buf, 0x0, sizeof(tis->buf)); | ||
| 348 | + break; | ||
| 349 | + } | ||
| 350 | + } | ||
| 351 | +} | ||
| 352 | + | ||
| 353 | +static int tpm_tis_post_load(void *opaque, | ||
| 354 | + int version_id __attribute__((unused))) | ||
| 355 | +{ | ||
| 356 | + TPMState *s = opaque; | ||
| 357 | + TPMTISEmuState *tis = &s->s.tis; | ||
| 358 | + | ||
| 359 | + uint8_t locty = tis->active_locty; | ||
| 360 | + | ||
| 361 | + if (TPM_TIS_IS_VALID_LOCTY(locty)) { | ||
| 362 | + switch (tis->loc[locty].state) { | ||
| 363 | + case TPM_TIS_STATE_RECEPTION: | ||
| 364 | + memcpy(tis->loc[locty].w_buffer.buffer, | ||
| 365 | + tis->buf, | ||
| 366 | + MIN(sizeof(tis->buf), | ||
| 367 | + tis->loc[locty].w_buffer.size)); | ||
| 368 | + tis->loc[locty].w_offset = tis->offset; | ||
| 369 | + break; | ||
| 370 | + case TPM_TIS_STATE_COMPLETION: | ||
| 371 | + memcpy(tis->loc[locty].r_buffer.buffer, | ||
| 372 | + tis->buf, | ||
| 373 | + MIN(sizeof(tis->buf), | ||
| 374 | + tis->loc[locty].r_buffer.size)); | ||
| 375 | + tis->loc[locty].r_offset = tis->offset; | ||
| 376 | + break; | ||
| 377 | + default: | ||
| 378 | + break; | ||
| 379 | + } | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + DPRINTF("tpm_tis: resume : locty = %d : r_offset = %d, w_offset = %d\n", | ||
| 383 | + locty, tis->loc[0].r_offset, tis->loc[0].w_offset); | ||
| 384 | + | ||
| 385 | + return 0; | ||
| 386 | +} | ||
| 387 | + | ||
| 388 | +static const VMStateDescription vmstate_locty = { | ||
| 389 | + .name = "loc", | ||
| 390 | + .version_id = 1, | ||
| 391 | + .minimum_version_id = 0, | ||
| 392 | + .minimum_version_id_old = 0, | ||
| 393 | + .fields = (VMStateField[]) { | ||
| 394 | + VMSTATE_UINT32(state, TPMLocality), | ||
| 395 | + VMSTATE_UINT32(inte, TPMLocality), | ||
| 396 | + VMSTATE_UINT32(ints, TPMLocality), | ||
| 397 | + VMSTATE_UINT8(access, TPMLocality), | ||
| 398 | + VMSTATE_UINT32(sts, TPMLocality), | ||
| 399 | + VMSTATE_UINT32(iface_id, TPMLocality), | ||
| 400 | + VMSTATE_END_OF_LIST(), | ||
| 401 | + } | ||
| 402 | +}; | ||
| 403 | + | ||
| 404 | static const VMStateDescription vmstate_tpm_tis = { | ||
| 405 | .name = "tpm", | ||
| 406 | - .unmigratable = 1, | ||
| 407 | + .version_id = 1, | ||
| 408 | + .minimum_version_id = 0, | ||
| 409 | + .minimum_version_id_old = 0, | ||
| 410 | + .pre_save = tpm_tis_pre_save, | ||
| 411 | + .post_load = tpm_tis_post_load, | ||
| 412 | + .fields = (VMStateField[]) { | ||
| 413 | + VMSTATE_UINT32(s.tis.offset, TPMState), | ||
| 414 | + VMSTATE_BUFFER(s.tis.buf, TPMState), | ||
| 415 | + VMSTATE_UINT8(s.tis.active_locty, TPMState), | ||
| 416 | + VMSTATE_UINT8(s.tis.aborting_locty, TPMState), | ||
| 417 | + VMSTATE_UINT8(s.tis.next_locty, TPMState), | ||
| 418 | + | ||
| 419 | + VMSTATE_STRUCT_ARRAY(s.tis.loc, TPMState, TPM_TIS_NUM_LOCALITIES, 1, | ||
| 420 | + vmstate_locty, TPMLocality), | ||
| 421 | + | ||
| 422 | + VMSTATE_END_OF_LIST() | ||
| 423 | + } | ||
| 424 | }; | ||
| 425 | |||
| 426 | static Property tpm_tis_properties[] = { | ||
| 427 | diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h | ||
| 428 | index a1df41fa21..b7fc0ea1a9 100644 | ||
| 429 | --- a/hw/tpm/tpm_tis.h | ||
| 430 | +++ b/hw/tpm/tpm_tis.h | ||
| 431 | @@ -54,6 +54,8 @@ typedef struct TPMLocality { | ||
| 432 | |||
| 433 | typedef struct TPMTISEmuState { | ||
| 434 | QEMUBH *bh; | ||
| 435 | + bool bh_scheduled; /* bh scheduled but did not run yet */ | ||
| 436 | + | ||
| 437 | uint32_t offset; | ||
| 438 | uint8_t buf[TPM_TIS_BUFFER_MAX]; | ||
| 439 | |||
| 440 | diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c | ||
| 441 | index 7b35429725..b6ff74d946 100644 | ||
| 442 | --- a/hw/tpm/tpm_util.c | ||
| 443 | +++ b/hw/tpm/tpm_util.c | ||
| 444 | @@ -22,6 +22,17 @@ | ||
| 445 | #include "qemu/osdep.h" | ||
| 446 | #include "tpm_util.h" | ||
| 447 | #include "tpm_int.h" | ||
| 448 | +#include "tpm_ioctl.h" | ||
| 449 | +#include "qemu/error-report.h" | ||
| 450 | + | ||
| 451 | +#define DEBUG_TPM 0 | ||
| 452 | + | ||
| 453 | +#define DPRINTF(fmt, ...) do { \ | ||
| 454 | + if (DEBUG_TPM) { \ | ||
| 455 | + fprintf(stderr, fmt, ## __VA_ARGS__); \ | ||
| 456 | + } \ | ||
| 457 | +} while (0) | ||
| 458 | + | ||
| 459 | |||
| 460 | /* | ||
| 461 | * A basic test of a TPM device. We expect a well formatted response header | ||
| 462 | @@ -125,3 +136,215 @@ int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version) | ||
| 463 | |||
| 464 | return 1; | ||
| 465 | } | ||
| 466 | + | ||
| 467 | +static void tpm_sized_buffer_reset(TPMSizedBuffer *tsb) | ||
| 468 | +{ | ||
| 469 | + g_free(tsb->buffer); | ||
| 470 | + tsb->buffer = NULL; | ||
| 471 | + tsb->size = 0; | ||
| 472 | +} | ||
| 473 | + | ||
| 474 | +/* | ||
| 475 | + * Transfer a TPM state blob from the TPM into a provided buffer. | ||
| 476 | + * | ||
| 477 | + * @fd: file descriptor to talk to the CUSE TPM | ||
| 478 | + * @type: the type of blob to transfer | ||
| 479 | + * @decrypted_blob: whether we request to receive decrypted blobs | ||
| 480 | + * @tsb: the TPMSizeBuffer to fill with the blob | ||
| 481 | + * @flags: the flags to return to the caller | ||
| 482 | + */ | ||
| 483 | +static int tpm_util_cuse_get_state_blob(int fd, | ||
| 484 | + uint8_t type, | ||
| 485 | + bool decrypted_blob, | ||
| 486 | + TPMSizedBuffer *tsb, | ||
| 487 | + uint32_t *flags) | ||
| 488 | +{ | ||
| 489 | + ptm_getstate pgs; | ||
| 490 | + uint16_t offset = 0; | ||
| 491 | + ptm_res res; | ||
| 492 | + ssize_t n; | ||
| 493 | + size_t to_read; | ||
| 494 | + | ||
| 495 | + tpm_sized_buffer_reset(tsb); | ||
| 496 | + | ||
| 497 | + pgs.u.req.state_flags = (decrypted_blob) ? PTM_STATE_FLAG_DECRYPTED : 0; | ||
| 498 | + pgs.u.req.type = type; | ||
| 499 | + pgs.u.req.offset = offset; | ||
| 500 | + | ||
| 501 | + if (ioctl(fd, PTM_GET_STATEBLOB, &pgs) < 0) { | ||
| 502 | + error_report("CUSE TPM PTM_GET_STATEBLOB ioctl failed: %s", | ||
| 503 | + strerror(errno)); | ||
| 504 | + goto err_exit; | ||
| 505 | + } | ||
| 506 | + res = pgs.u.resp.tpm_result; | ||
| 507 | + if (res != 0 && (res & 0x800) == 0) { | ||
| 508 | + error_report("Getting the stateblob (type %d) failed with a TPM " | ||
| 509 | + "error 0x%x", type, res); | ||
| 510 | + goto err_exit; | ||
| 511 | + } | ||
| 512 | + | ||
| 513 | + *flags = pgs.u.resp.state_flags; | ||
| 514 | + | ||
| 515 | + tsb->buffer = g_malloc(pgs.u.resp.totlength); | ||
| 516 | + memcpy(tsb->buffer, pgs.u.resp.data, pgs.u.resp.length); | ||
| 517 | + tsb->size = pgs.u.resp.length; | ||
| 518 | + | ||
| 519 | + /* if there are bytes left to get use read() interface */ | ||
| 520 | + while (tsb->size < pgs.u.resp.totlength) { | ||
| 521 | + to_read = pgs.u.resp.totlength - tsb->size; | ||
| 522 | + if (unlikely(to_read > SSIZE_MAX)) { | ||
| 523 | + to_read = SSIZE_MAX; | ||
| 524 | + } | ||
| 525 | + | ||
| 526 | + n = read(fd, &tsb->buffer[tsb->size], to_read); | ||
| 527 | + if (n != to_read) { | ||
| 528 | + error_report("Could not read stateblob (type %d) : %s", | ||
| 529 | + type, strerror(errno)); | ||
| 530 | + goto err_exit; | ||
| 531 | + } | ||
| 532 | + tsb->size += to_read; | ||
| 533 | + } | ||
| 534 | + | ||
| 535 | + DPRINTF("tpm_util: got state blob type %d, %d bytes, flags 0x%08x, " | ||
| 536 | + "decrypted=%d\n", type, tsb->size, *flags, decrypted_blob); | ||
| 537 | + | ||
| 538 | + return 0; | ||
| 539 | + | ||
| 540 | +err_exit: | ||
| 541 | + return 1; | ||
| 542 | +} | ||
| 543 | + | ||
| 544 | +int tpm_util_cuse_get_state_blobs(int tpm_fd, | ||
| 545 | + bool decrypted_blobs, | ||
| 546 | + TPMBlobBuffers *tpm_blobs) | ||
| 547 | +{ | ||
| 548 | + if (tpm_util_cuse_get_state_blob(tpm_fd, PTM_BLOB_TYPE_PERMANENT, | ||
| 549 | + decrypted_blobs, | ||
| 550 | + &tpm_blobs->permanent, | ||
| 551 | + &tpm_blobs->permanent_flags) || | ||
| 552 | + tpm_util_cuse_get_state_blob(tpm_fd, PTM_BLOB_TYPE_VOLATILE, | ||
| 553 | + decrypted_blobs, | ||
| 554 | + &tpm_blobs->volatil, | ||
| 555 | + &tpm_blobs->volatil_flags) || | ||
| 556 | + tpm_util_cuse_get_state_blob(tpm_fd, PTM_BLOB_TYPE_SAVESTATE, | ||
| 557 | + decrypted_blobs, | ||
| 558 | + &tpm_blobs->savestate, | ||
| 559 | + &tpm_blobs->savestate_flags)) { | ||
| 560 | + goto err_exit; | ||
| 561 | + } | ||
| 562 | + | ||
| 563 | + return 0; | ||
| 564 | + | ||
| 565 | + err_exit: | ||
| 566 | + tpm_sized_buffer_reset(&tpm_blobs->volatil); | ||
| 567 | + tpm_sized_buffer_reset(&tpm_blobs->permanent); | ||
| 568 | + tpm_sized_buffer_reset(&tpm_blobs->savestate); | ||
| 569 | + | ||
| 570 | + return 1; | ||
| 571 | +} | ||
| 572 | + | ||
| 573 | +static int tpm_util_cuse_do_set_stateblob_ioctl(int fd, | ||
| 574 | + uint32_t flags, | ||
| 575 | + uint32_t type, | ||
| 576 | + uint32_t length) | ||
| 577 | +{ | ||
| 578 | + ptm_setstate pss; | ||
| 579 | + | ||
| 580 | + pss.u.req.state_flags = flags; | ||
| 581 | + pss.u.req.type = type; | ||
| 582 | + pss.u.req.length = length; | ||
| 583 | + | ||
| 584 | + if (ioctl(fd, PTM_SET_STATEBLOB, &pss) < 0) { | ||
| 585 | + error_report("CUSE TPM PTM_SET_STATEBLOB ioctl failed: %s", | ||
| 586 | + strerror(errno)); | ||
| 587 | + return 1; | ||
| 588 | + } | ||
| 589 | + | ||
| 590 | + if (pss.u.resp.tpm_result != 0) { | ||
| 591 | + error_report("Setting the stateblob (type %d) failed with a TPM " | ||
| 592 | + "error 0x%x", type, pss.u.resp.tpm_result); | ||
| 593 | + return 1; | ||
| 594 | + } | ||
| 595 | + | ||
| 596 | + return 0; | ||
| 597 | +} | ||
| 598 | + | ||
| 599 | + | ||
| 600 | +/* | ||
| 601 | + * Transfer a TPM state blob to the CUSE TPM. | ||
| 602 | + * | ||
| 603 | + * @fd: file descriptor to talk to the CUSE TPM | ||
| 604 | + * @type: the type of TPM state blob to transfer | ||
| 605 | + * @tsb: TPMSizeBuffer containing the TPM state blob | ||
| 606 | + * @flags: Flags describing the (encryption) state of the TPM state blob | ||
| 607 | + */ | ||
| 608 | +static int tpm_util_cuse_set_state_blob(int fd, | ||
| 609 | + uint32_t type, | ||
| 610 | + TPMSizedBuffer *tsb, | ||
| 611 | + uint32_t flags) | ||
| 612 | +{ | ||
| 613 | + uint32_t offset = 0; | ||
| 614 | + ssize_t n; | ||
| 615 | + size_t to_write; | ||
| 616 | + | ||
| 617 | + /* initiate the transfer to the CUSE TPM */ | ||
| 618 | + if (tpm_util_cuse_do_set_stateblob_ioctl(fd, flags, type, 0)) { | ||
| 619 | + return 1; | ||
| 620 | + } | ||
| 621 | + | ||
| 622 | + /* use the write() interface for transferring the state blob */ | ||
| 623 | + while (offset < tsb->size) { | ||
| 624 | + to_write = tsb->size - offset; | ||
| 625 | + if (unlikely(to_write > SSIZE_MAX)) { | ||
| 626 | + to_write = SSIZE_MAX; | ||
| 627 | + } | ||
| 628 | + | ||
| 629 | + n = write(fd, &tsb->buffer[offset], to_write); | ||
| 630 | + if (n != to_write) { | ||
| 631 | + error_report("Writing the stateblob (type %d) failed: %s", | ||
| 632 | + type, strerror(errno)); | ||
| 633 | + goto err_exit; | ||
| 634 | + } | ||
| 635 | + offset += to_write; | ||
| 636 | + } | ||
| 637 | + | ||
| 638 | + /* inidicate that the transfer is finished */ | ||
| 639 | + if (tpm_util_cuse_do_set_stateblob_ioctl(fd, flags, type, 0)) { | ||
| 640 | + goto err_exit; | ||
| 641 | + } | ||
| 642 | + | ||
| 643 | + DPRINTF("tpm_util: set the state blob type %d, %d bytes, flags 0x%08x\n", | ||
| 644 | + type, tsb->size, flags); | ||
| 645 | + | ||
| 646 | + return 0; | ||
| 647 | + | ||
| 648 | +err_exit: | ||
| 649 | + return 1; | ||
| 650 | +} | ||
| 651 | + | ||
| 652 | +int tpm_util_cuse_set_state_blobs(int tpm_fd, | ||
| 653 | + TPMBlobBuffers *tpm_blobs) | ||
| 654 | +{ | ||
| 655 | + ptm_res res; | ||
| 656 | + | ||
| 657 | + if (ioctl(tpm_fd, PTM_STOP, &res) < 0) { | ||
| 658 | + error_report("tpm_passthrough: Could not stop " | ||
| 659 | + "the CUSE TPM: %s (%i)", | ||
| 660 | + strerror(errno), errno); | ||
| 661 | + return 1; | ||
| 662 | + } | ||
| 663 | + | ||
| 664 | + if (tpm_util_cuse_set_state_blob(tpm_fd, PTM_BLOB_TYPE_PERMANENT, | ||
| 665 | + &tpm_blobs->permanent, | ||
| 666 | + tpm_blobs->permanent_flags) || | ||
| 667 | + tpm_util_cuse_set_state_blob(tpm_fd, PTM_BLOB_TYPE_VOLATILE, | ||
| 668 | + &tpm_blobs->volatil, | ||
| 669 | + tpm_blobs->volatil_flags) || | ||
| 670 | + tpm_util_cuse_set_state_blob(tpm_fd, PTM_BLOB_TYPE_SAVESTATE, | ||
| 671 | + &tpm_blobs->savestate, | ||
| 672 | + tpm_blobs->savestate_flags)) { | ||
| 673 | + return 1; | ||
| 674 | + } | ||
| 675 | + | ||
| 676 | + return 0; | ||
| 677 | +} | ||
| 678 | diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h | ||
| 679 | index df76245e6e..c24071d812 100644 | ||
| 680 | --- a/hw/tpm/tpm_util.h | ||
| 681 | +++ b/hw/tpm/tpm_util.h | ||
| 682 | @@ -26,4 +26,11 @@ | ||
| 683 | |||
| 684 | int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version); | ||
| 685 | |||
| 686 | +int tpm_util_cuse_get_state_blobs(int tpm_fd, | ||
| 687 | + bool decrypted_blobs, | ||
| 688 | + TPMBlobBuffers *tpm_blobs); | ||
| 689 | + | ||
| 690 | +int tpm_util_cuse_set_state_blobs(int tpm_fd, | ||
| 691 | + TPMBlobBuffers *tpm_blobs); | ||
| 692 | + | ||
| 693 | #endif /* TPM_TPM_UTIL_H */ | ||
| 694 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 695 | index b58f52d39f..3403821b9d 100644 | ||
| 696 | --- a/include/sysemu/tpm_backend.h | ||
| 697 | +++ b/include/sysemu/tpm_backend.h | ||
| 698 | @@ -62,6 +62,18 @@ typedef struct TPMSizedBuffer { | ||
| 699 | uint8_t *buffer; | ||
| 700 | } TPMSizedBuffer; | ||
| 701 | |||
| 702 | +/* blobs from the TPM; part of VM state when migrating */ | ||
| 703 | +typedef struct TPMBlobBuffers { | ||
| 704 | + uint32_t permanent_flags; | ||
| 705 | + TPMSizedBuffer permanent; | ||
| 706 | + | ||
| 707 | + uint32_t volatil_flags; | ||
| 708 | + TPMSizedBuffer volatil; | ||
| 709 | + | ||
| 710 | + uint32_t savestate_flags; | ||
| 711 | + TPMSizedBuffer savestate; | ||
| 712 | +} TPMBlobBuffers; | ||
| 713 | + | ||
| 714 | struct TPMDriverOps { | ||
| 715 | enum TpmType type; | ||
| 716 | const QemuOptDesc *opts; | ||
| 717 | -- | ||
| 718 | 2.11.0 | ||
| 719 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0004-tpm-backend-Move-thread-handling-inside-TPMBackend.patch b/meta/recipes-devtools/qemu/qemu/0004-tpm-backend-Move-thread-handling-inside-TPMBackend.patch new file mode 100644 index 0000000000..64e88b6de9 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0004-tpm-backend-Move-thread-handling-inside-TPMBackend.patch | |||
| @@ -0,0 +1,417 @@ | |||
| 1 | From 5767322022d54ceb5a2ed6c650f667a4d24aa150 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Thu, 30 Mar 2017 16:20:25 +0300 | ||
| 4 | Subject: [PATCH 04/12] tpm-backend: Move thread handling inside TPMBackend | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | Move thread handling inside TPMBackend, this way backend implementations need | ||
| 10 | not to maintain their own thread life cycle, instead they needs to implement | ||
| 11 | 'handle_request()' class method that always been called from a thread. | ||
| 12 | |||
| 13 | This change made tpm_backend_int.h kind of useless, hence removed it. | ||
| 14 | |||
| 15 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 16 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 17 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 18 | |||
| 19 | Upstream-Status: Backport [b19a5eea5a26e9bd83a48c742172d2a6aa8c4180] | ||
| 20 | --- | ||
| 21 | backends/tpm.c | 62 +++++++++++++++++++++++++--------------- | ||
| 22 | hw/tpm/tpm_passthrough.c | 58 ++++++------------------------------- | ||
| 23 | include/sysemu/tpm_backend.h | 32 +++++++++++++-------- | ||
| 24 | include/sysemu/tpm_backend_int.h | 41 -------------------------- | ||
| 25 | 4 files changed, 67 insertions(+), 126 deletions(-) | ||
| 26 | delete mode 100644 include/sysemu/tpm_backend_int.h | ||
| 27 | |||
| 28 | diff --git a/backends/tpm.c b/backends/tpm.c | ||
| 29 | index 536f262bb7..ce56c3b74d 100644 | ||
| 30 | --- a/backends/tpm.c | ||
| 31 | +++ b/backends/tpm.c | ||
| 32 | @@ -18,7 +18,24 @@ | ||
| 33 | #include "qapi/qmp/qerror.h" | ||
| 34 | #include "sysemu/tpm.h" | ||
| 35 | #include "qemu/thread.h" | ||
| 36 | -#include "sysemu/tpm_backend_int.h" | ||
| 37 | + | ||
| 38 | +static void tpm_backend_worker_thread(gpointer data, gpointer user_data) | ||
| 39 | +{ | ||
| 40 | + TPMBackend *s = TPM_BACKEND(user_data); | ||
| 41 | + TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 42 | + | ||
| 43 | + assert(k->handle_request != NULL); | ||
| 44 | + k->handle_request(s, (TPMBackendCmd)data); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +static void tpm_backend_thread_end(TPMBackend *s) | ||
| 48 | +{ | ||
| 49 | + if (s->thread_pool) { | ||
| 50 | + g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_END, NULL); | ||
| 51 | + g_thread_pool_free(s->thread_pool, FALSE, TRUE); | ||
| 52 | + s->thread_pool = NULL; | ||
| 53 | + } | ||
| 54 | +} | ||
| 55 | |||
| 56 | enum TpmType tpm_backend_get_type(TPMBackend *s) | ||
| 57 | { | ||
| 58 | @@ -39,6 +56,8 @@ void tpm_backend_destroy(TPMBackend *s) | ||
| 59 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 60 | |||
| 61 | k->ops->destroy(s); | ||
| 62 | + | ||
| 63 | + tpm_backend_thread_end(s); | ||
| 64 | } | ||
| 65 | |||
| 66 | int tpm_backend_init(TPMBackend *s, TPMState *state, | ||
| 67 | @@ -46,13 +65,23 @@ int tpm_backend_init(TPMBackend *s, TPMState *state, | ||
| 68 | { | ||
| 69 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 70 | |||
| 71 | - return k->ops->init(s, state, datacb); | ||
| 72 | + s->tpm_state = state; | ||
| 73 | + s->recv_data_callback = datacb; | ||
| 74 | + | ||
| 75 | + return k->ops->init(s); | ||
| 76 | } | ||
| 77 | |||
| 78 | int tpm_backend_startup_tpm(TPMBackend *s) | ||
| 79 | { | ||
| 80 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 81 | |||
| 82 | + /* terminate a running TPM */ | ||
| 83 | + tpm_backend_thread_end(s); | ||
| 84 | + | ||
| 85 | + s->thread_pool = g_thread_pool_new(tpm_backend_worker_thread, s, 1, TRUE, | ||
| 86 | + NULL); | ||
| 87 | + g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL); | ||
| 88 | + | ||
| 89 | return k->ops->startup_tpm(s); | ||
| 90 | } | ||
| 91 | |||
| 92 | @@ -72,9 +101,8 @@ size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb) | ||
| 93 | |||
| 94 | void tpm_backend_deliver_request(TPMBackend *s) | ||
| 95 | { | ||
| 96 | - TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 97 | - | ||
| 98 | - k->ops->deliver_request(s); | ||
| 99 | + g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, | ||
| 100 | + NULL); | ||
| 101 | } | ||
| 102 | |||
| 103 | void tpm_backend_reset(TPMBackend *s) | ||
| 104 | @@ -82,6 +110,8 @@ void tpm_backend_reset(TPMBackend *s) | ||
| 105 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 106 | |||
| 107 | k->ops->reset(s); | ||
| 108 | + | ||
| 109 | + tpm_backend_thread_end(s); | ||
| 110 | } | ||
| 111 | |||
| 112 | void tpm_backend_cancel_cmd(TPMBackend *s) | ||
| 113 | @@ -156,29 +186,14 @@ static void tpm_backend_instance_init(Object *obj) | ||
| 114 | tpm_backend_prop_get_opened, | ||
| 115 | tpm_backend_prop_set_opened, | ||
| 116 | NULL); | ||
| 117 | -} | ||
| 118 | |||
| 119 | -void tpm_backend_thread_deliver_request(TPMBackendThread *tbt) | ||
| 120 | -{ | ||
| 121 | - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL); | ||
| 122 | } | ||
| 123 | |||
| 124 | -void tpm_backend_thread_create(TPMBackendThread *tbt, | ||
| 125 | - GFunc func, gpointer user_data) | ||
| 126 | +static void tpm_backend_instance_finalize(Object *obj) | ||
| 127 | { | ||
| 128 | - if (!tbt->pool) { | ||
| 129 | - tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL); | ||
| 130 | - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL); | ||
| 131 | - } | ||
| 132 | -} | ||
| 133 | + TPMBackend *s = TPM_BACKEND(obj); | ||
| 134 | |||
| 135 | -void tpm_backend_thread_end(TPMBackendThread *tbt) | ||
| 136 | -{ | ||
| 137 | - if (tbt->pool) { | ||
| 138 | - g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL); | ||
| 139 | - g_thread_pool_free(tbt->pool, FALSE, TRUE); | ||
| 140 | - tbt->pool = NULL; | ||
| 141 | - } | ||
| 142 | + tpm_backend_thread_end(s); | ||
| 143 | } | ||
| 144 | |||
| 145 | static const TypeInfo tpm_backend_info = { | ||
| 146 | @@ -186,6 +201,7 @@ static const TypeInfo tpm_backend_info = { | ||
| 147 | .parent = TYPE_OBJECT, | ||
| 148 | .instance_size = sizeof(TPMBackend), | ||
| 149 | .instance_init = tpm_backend_instance_init, | ||
| 150 | + .instance_finalize = tpm_backend_instance_finalize, | ||
| 151 | .class_size = sizeof(TPMBackendClass), | ||
| 152 | .abstract = true, | ||
| 153 | }; | ||
| 154 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 155 | index a0baf5f080..f50d9cffd7 100644 | ||
| 156 | --- a/hw/tpm/tpm_passthrough.c | ||
| 157 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 158 | @@ -30,7 +30,6 @@ | ||
| 159 | #include "tpm_int.h" | ||
| 160 | #include "hw/hw.h" | ||
| 161 | #include "hw/i386/pc.h" | ||
| 162 | -#include "sysemu/tpm_backend_int.h" | ||
| 163 | #include "tpm_tis.h" | ||
| 164 | #include "tpm_util.h" | ||
| 165 | |||
| 166 | @@ -47,20 +46,9 @@ | ||
| 167 | OBJECT_CHECK(TPMPassthruState, (obj), TYPE_TPM_PASSTHROUGH) | ||
| 168 | |||
| 169 | /* data structures */ | ||
| 170 | -typedef struct TPMPassthruThreadParams { | ||
| 171 | - TPMState *tpm_state; | ||
| 172 | - | ||
| 173 | - TPMRecvDataCB *recv_data_callback; | ||
| 174 | - TPMBackend *tb; | ||
| 175 | -} TPMPassthruThreadParams; | ||
| 176 | - | ||
| 177 | struct TPMPassthruState { | ||
| 178 | TPMBackend parent; | ||
| 179 | |||
| 180 | - TPMBackendThread tbt; | ||
| 181 | - | ||
| 182 | - TPMPassthruThreadParams tpm_thread_params; | ||
| 183 | - | ||
| 184 | char *tpm_dev; | ||
| 185 | int tpm_fd; | ||
| 186 | bool tpm_executing; | ||
| 187 | @@ -214,12 +202,9 @@ static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, | ||
| 188 | selftest_done); | ||
| 189 | } | ||
| 190 | |||
| 191 | -static void tpm_passthrough_worker_thread(gpointer data, | ||
| 192 | - gpointer user_data) | ||
| 193 | +static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd cmd) | ||
| 194 | { | ||
| 195 | - TPMPassthruThreadParams *thr_parms = user_data; | ||
| 196 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(thr_parms->tb); | ||
| 197 | - TPMBackendCmd cmd = (TPMBackendCmd)data; | ||
| 198 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 199 | bool selftest_done = false; | ||
| 200 | |||
| 201 | DPRINTF("tpm_passthrough: processing command type %d\n", cmd); | ||
| 202 | @@ -227,12 +212,12 @@ static void tpm_passthrough_worker_thread(gpointer data, | ||
| 203 | switch (cmd) { | ||
| 204 | case TPM_BACKEND_CMD_PROCESS_CMD: | ||
| 205 | tpm_passthrough_unix_transfer(tpm_pt, | ||
| 206 | - thr_parms->tpm_state->locty_data, | ||
| 207 | + tb->tpm_state->locty_data, | ||
| 208 | &selftest_done); | ||
| 209 | |||
| 210 | - thr_parms->recv_data_callback(thr_parms->tpm_state, | ||
| 211 | - thr_parms->tpm_state->locty_number, | ||
| 212 | - selftest_done); | ||
| 213 | + tb->recv_data_callback(tb->tpm_state, | ||
| 214 | + tb->tpm_state->locty_number, | ||
| 215 | + selftest_done); | ||
| 216 | break; | ||
| 217 | case TPM_BACKEND_CMD_INIT: | ||
| 218 | case TPM_BACKEND_CMD_END: | ||
| 219 | @@ -248,15 +233,6 @@ static void tpm_passthrough_worker_thread(gpointer data, | ||
| 220 | */ | ||
| 221 | static int tpm_passthrough_startup_tpm(TPMBackend *tb) | ||
| 222 | { | ||
| 223 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 224 | - | ||
| 225 | - /* terminate a running TPM */ | ||
| 226 | - tpm_backend_thread_end(&tpm_pt->tbt); | ||
| 227 | - | ||
| 228 | - tpm_backend_thread_create(&tpm_pt->tbt, | ||
| 229 | - tpm_passthrough_worker_thread, | ||
| 230 | - &tpm_pt->tpm_thread_params); | ||
| 231 | - | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | @@ -268,20 +244,11 @@ static void tpm_passthrough_reset(TPMBackend *tb) | ||
| 236 | |||
| 237 | tpm_passthrough_cancel_cmd(tb); | ||
| 238 | |||
| 239 | - tpm_backend_thread_end(&tpm_pt->tbt); | ||
| 240 | - | ||
| 241 | tpm_pt->had_startup_error = false; | ||
| 242 | } | ||
| 243 | |||
| 244 | -static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, | ||
| 245 | - TPMRecvDataCB *recv_data_cb) | ||
| 246 | +static int tpm_passthrough_init(TPMBackend *tb) | ||
| 247 | { | ||
| 248 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 249 | - | ||
| 250 | - tpm_pt->tpm_thread_params.tpm_state = s; | ||
| 251 | - tpm_pt->tpm_thread_params.recv_data_callback = recv_data_cb; | ||
| 252 | - tpm_pt->tpm_thread_params.tb = tb; | ||
| 253 | - | ||
| 254 | return 0; | ||
| 255 | } | ||
| 256 | |||
| 257 | @@ -315,13 +282,6 @@ static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb) | ||
| 258 | return sb->size; | ||
| 259 | } | ||
| 260 | |||
| 261 | -static void tpm_passthrough_deliver_request(TPMBackend *tb) | ||
| 262 | -{ | ||
| 263 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 264 | - | ||
| 265 | - tpm_backend_thread_deliver_request(&tpm_pt->tbt); | ||
| 266 | -} | ||
| 267 | - | ||
| 268 | static void tpm_passthrough_cancel_cmd(TPMBackend *tb) | ||
| 269 | { | ||
| 270 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 271 | @@ -483,8 +443,6 @@ static void tpm_passthrough_destroy(TPMBackend *tb) | ||
| 272 | |||
| 273 | tpm_passthrough_cancel_cmd(tb); | ||
| 274 | |||
| 275 | - tpm_backend_thread_end(&tpm_pt->tbt); | ||
| 276 | - | ||
| 277 | qemu_close(tpm_pt->tpm_fd); | ||
| 278 | qemu_close(tpm_pt->cancel_fd); | ||
| 279 | |||
| 280 | @@ -520,7 +478,6 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 281 | .realloc_buffer = tpm_passthrough_realloc_buffer, | ||
| 282 | .reset = tpm_passthrough_reset, | ||
| 283 | .had_startup_error = tpm_passthrough_get_startup_error, | ||
| 284 | - .deliver_request = tpm_passthrough_deliver_request, | ||
| 285 | .cancel_cmd = tpm_passthrough_cancel_cmd, | ||
| 286 | .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, | ||
| 287 | .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag, | ||
| 288 | @@ -540,6 +497,7 @@ static void tpm_passthrough_class_init(ObjectClass *klass, void *data) | ||
| 289 | TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass); | ||
| 290 | |||
| 291 | tbc->ops = &tpm_passthrough_driver; | ||
| 292 | + tbc->handle_request = tpm_passthrough_handle_request; | ||
| 293 | } | ||
| 294 | |||
| 295 | static const TypeInfo tpm_passthrough_info = { | ||
| 296 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 297 | index 3708413035..58308b3687 100644 | ||
| 298 | --- a/include/sysemu/tpm_backend.h | ||
| 299 | +++ b/include/sysemu/tpm_backend.h | ||
| 300 | @@ -29,22 +29,24 @@ | ||
| 301 | |||
| 302 | typedef struct TPMBackendClass TPMBackendClass; | ||
| 303 | typedef struct TPMBackend TPMBackend; | ||
| 304 | - | ||
| 305 | typedef struct TPMDriverOps TPMDriverOps; | ||
| 306 | +typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done); | ||
| 307 | |||
| 308 | -struct TPMBackendClass { | ||
| 309 | - ObjectClass parent_class; | ||
| 310 | - | ||
| 311 | - const TPMDriverOps *ops; | ||
| 312 | - | ||
| 313 | - void (*opened)(TPMBackend *s, Error **errp); | ||
| 314 | -}; | ||
| 315 | +typedef enum TPMBackendCmd { | ||
| 316 | + TPM_BACKEND_CMD_INIT = 1, | ||
| 317 | + TPM_BACKEND_CMD_PROCESS_CMD, | ||
| 318 | + TPM_BACKEND_CMD_END, | ||
| 319 | + TPM_BACKEND_CMD_TPM_RESET, | ||
| 320 | +} TPMBackendCmd; | ||
| 321 | |||
| 322 | struct TPMBackend { | ||
| 323 | Object parent; | ||
| 324 | |||
| 325 | /*< protected >*/ | ||
| 326 | bool opened; | ||
| 327 | + TPMState *tpm_state; | ||
| 328 | + GThreadPool *thread_pool; | ||
| 329 | + TPMRecvDataCB *recv_data_callback; | ||
| 330 | |||
| 331 | char *id; | ||
| 332 | enum TpmModel fe_model; | ||
| 333 | @@ -54,7 +56,15 @@ struct TPMBackend { | ||
| 334 | QLIST_ENTRY(TPMBackend) list; | ||
| 335 | }; | ||
| 336 | |||
| 337 | -typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done); | ||
| 338 | +struct TPMBackendClass { | ||
| 339 | + ObjectClass parent_class; | ||
| 340 | + | ||
| 341 | + const TPMDriverOps *ops; | ||
| 342 | + | ||
| 343 | + void (*opened)(TPMBackend *s, Error **errp); | ||
| 344 | + | ||
| 345 | + void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd); | ||
| 346 | +}; | ||
| 347 | |||
| 348 | typedef struct TPMSizedBuffer { | ||
| 349 | uint32_t size; | ||
| 350 | @@ -71,7 +81,7 @@ struct TPMDriverOps { | ||
| 351 | void (*destroy)(TPMBackend *t); | ||
| 352 | |||
| 353 | /* initialize the backend */ | ||
| 354 | - int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb); | ||
| 355 | + int (*init)(TPMBackend *t); | ||
| 356 | /* start up the TPM on the backend */ | ||
| 357 | int (*startup_tpm)(TPMBackend *t); | ||
| 358 | /* returns true if nothing will ever answer TPM requests */ | ||
| 359 | @@ -79,8 +89,6 @@ struct TPMDriverOps { | ||
| 360 | |||
| 361 | size_t (*realloc_buffer)(TPMSizedBuffer *sb); | ||
| 362 | |||
| 363 | - void (*deliver_request)(TPMBackend *t); | ||
| 364 | - | ||
| 365 | void (*reset)(TPMBackend *t); | ||
| 366 | |||
| 367 | void (*cancel_cmd)(TPMBackend *t); | ||
| 368 | diff --git a/include/sysemu/tpm_backend_int.h b/include/sysemu/tpm_backend_int.h | ||
| 369 | deleted file mode 100644 | ||
| 370 | index 00639dd7de..0000000000 | ||
| 371 | --- a/include/sysemu/tpm_backend_int.h | ||
| 372 | +++ /dev/null | ||
| 373 | @@ -1,41 +0,0 @@ | ||
| 374 | -/* | ||
| 375 | - * common TPM backend driver functions | ||
| 376 | - * | ||
| 377 | - * Copyright (c) 2012-2013 IBM Corporation | ||
| 378 | - * Authors: | ||
| 379 | - * Stefan Berger <stefanb@us.ibm.com> | ||
| 380 | - * | ||
| 381 | - * This library is free software; you can redistribute it and/or | ||
| 382 | - * modify it under the terms of the GNU Lesser General Public | ||
| 383 | - * License as published by the Free Software Foundation; either | ||
| 384 | - * version 2 of the License, or (at your option) any later version. | ||
| 385 | - * | ||
| 386 | - * This library is distributed in the hope that it will be useful, | ||
| 387 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 388 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 389 | - * Lesser General Public License for more details. | ||
| 390 | - * | ||
| 391 | - * You should have received a copy of the GNU Lesser General Public | ||
| 392 | - * License along with this library; if not, see <http://www.gnu.org/licenses/> | ||
| 393 | - */ | ||
| 394 | - | ||
| 395 | -#ifndef TPM_BACKEND_INT_H | ||
| 396 | -#define TPM_BACKEND_INT_H | ||
| 397 | - | ||
| 398 | -typedef struct TPMBackendThread { | ||
| 399 | - GThreadPool *pool; | ||
| 400 | -} TPMBackendThread; | ||
| 401 | - | ||
| 402 | -void tpm_backend_thread_deliver_request(TPMBackendThread *tbt); | ||
| 403 | -void tpm_backend_thread_create(TPMBackendThread *tbt, | ||
| 404 | - GFunc func, gpointer user_data); | ||
| 405 | -void tpm_backend_thread_end(TPMBackendThread *tbt); | ||
| 406 | - | ||
| 407 | -typedef enum TPMBackendCmd { | ||
| 408 | - TPM_BACKEND_CMD_INIT = 1, | ||
| 409 | - TPM_BACKEND_CMD_PROCESS_CMD, | ||
| 410 | - TPM_BACKEND_CMD_END, | ||
| 411 | - TPM_BACKEND_CMD_TPM_RESET, | ||
| 412 | -} TPMBackendCmd; | ||
| 413 | - | ||
| 414 | -#endif /* TPM_BACKEND_INT_H */ | ||
| 415 | -- | ||
| 416 | 2.11.0 | ||
| 417 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0005-tpm-backend-Initialize-and-free-data-members-in-it-s.patch b/meta/recipes-devtools/qemu/qemu/0005-tpm-backend-Initialize-and-free-data-members-in-it-s.patch new file mode 100644 index 0000000000..91dd542f45 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0005-tpm-backend-Initialize-and-free-data-members-in-it-s.patch | |||
| @@ -0,0 +1,185 @@ | |||
| 1 | From 83ef052c60de271a97abb7eb9b5a8aeee52659e6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Fri, 31 Mar 2017 10:58:11 +0300 | ||
| 4 | Subject: [PATCH 05/12] tpm-backend: Initialize and free data members in it's | ||
| 5 | own methods | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=UTF-8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | Initialize and free TPMBackend data members in it's own instance_init() and | ||
| 11 | instance_finalize methods. | ||
| 12 | |||
| 13 | Took the opportunity to remove unneeded destroy() method from TpmDriverOps | ||
| 14 | interface as TPMBackend is a Qemu Object, we can use object_unref() inplace of | ||
| 15 | tpm_backend_destroy() to free the backend object, hence removed destroy() from | ||
| 16 | TPMDriverOps interface. | ||
| 17 | |||
| 18 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 19 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 20 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 21 | |||
| 22 | Upstream-Status: Backport [f35fe5cb97bbdaa6a6967f2fefc3fc1f79680601] | ||
| 23 | --- | ||
| 24 | backends/tpm.c | 16 ++++++---------- | ||
| 25 | hw/tpm/tpm_passthrough.c | 31 ++++++++++++------------------- | ||
| 26 | include/sysemu/tpm_backend.h | 7 ------- | ||
| 27 | tpm.c | 2 +- | ||
| 28 | 4 files changed, 19 insertions(+), 37 deletions(-) | ||
| 29 | |||
| 30 | diff --git a/backends/tpm.c b/backends/tpm.c | ||
| 31 | index ce56c3b74d..cf5abf1582 100644 | ||
| 32 | --- a/backends/tpm.c | ||
| 33 | +++ b/backends/tpm.c | ||
| 34 | @@ -51,15 +51,6 @@ const char *tpm_backend_get_desc(TPMBackend *s) | ||
| 35 | return k->ops->desc(); | ||
| 36 | } | ||
| 37 | |||
| 38 | -void tpm_backend_destroy(TPMBackend *s) | ||
| 39 | -{ | ||
| 40 | - TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 41 | - | ||
| 42 | - k->ops->destroy(s); | ||
| 43 | - | ||
| 44 | - tpm_backend_thread_end(s); | ||
| 45 | -} | ||
| 46 | - | ||
| 47 | int tpm_backend_init(TPMBackend *s, TPMState *state, | ||
| 48 | TPMRecvDataCB *datacb) | ||
| 49 | { | ||
| 50 | @@ -182,17 +173,22 @@ static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp) | ||
| 51 | |||
| 52 | static void tpm_backend_instance_init(Object *obj) | ||
| 53 | { | ||
| 54 | + TPMBackend *s = TPM_BACKEND(obj); | ||
| 55 | + | ||
| 56 | object_property_add_bool(obj, "opened", | ||
| 57 | tpm_backend_prop_get_opened, | ||
| 58 | tpm_backend_prop_set_opened, | ||
| 59 | NULL); | ||
| 60 | - | ||
| 61 | + s->fe_model = -1; | ||
| 62 | } | ||
| 63 | |||
| 64 | static void tpm_backend_instance_finalize(Object *obj) | ||
| 65 | { | ||
| 66 | TPMBackend *s = TPM_BACKEND(obj); | ||
| 67 | |||
| 68 | + g_free(s->id); | ||
| 69 | + g_free(s->path); | ||
| 70 | + g_free(s->cancel_path); | ||
| 71 | tpm_backend_thread_end(s); | ||
| 72 | } | ||
| 73 | |||
| 74 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 75 | index f50d9cffd7..815a72ef9a 100644 | ||
| 76 | --- a/hw/tpm/tpm_passthrough.c | ||
| 77 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 78 | @@ -417,8 +417,6 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) | ||
| 79 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 80 | |||
| 81 | tb->id = g_strdup(id); | ||
| 82 | - /* let frontend set the fe_model to proper value */ | ||
| 83 | - tb->fe_model = -1; | ||
| 84 | |||
| 85 | if (tpm_passthrough_handle_device_opts(opts, tb)) { | ||
| 86 | goto err_exit; | ||
| 87 | @@ -432,26 +430,11 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) | ||
| 88 | return tb; | ||
| 89 | |||
| 90 | err_exit: | ||
| 91 | - g_free(tb->id); | ||
| 92 | + object_unref(obj); | ||
| 93 | |||
| 94 | return NULL; | ||
| 95 | } | ||
| 96 | |||
| 97 | -static void tpm_passthrough_destroy(TPMBackend *tb) | ||
| 98 | -{ | ||
| 99 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 100 | - | ||
| 101 | - tpm_passthrough_cancel_cmd(tb); | ||
| 102 | - | ||
| 103 | - qemu_close(tpm_pt->tpm_fd); | ||
| 104 | - qemu_close(tpm_pt->cancel_fd); | ||
| 105 | - | ||
| 106 | - g_free(tb->id); | ||
| 107 | - g_free(tb->path); | ||
| 108 | - g_free(tb->cancel_path); | ||
| 109 | - g_free(tpm_pt->tpm_dev); | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | static const QemuOptDesc tpm_passthrough_cmdline_opts[] = { | ||
| 113 | TPM_STANDARD_CMDLINE_OPTS, | ||
| 114 | { | ||
| 115 | @@ -472,7 +455,6 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 116 | .opts = tpm_passthrough_cmdline_opts, | ||
| 117 | .desc = tpm_passthrough_create_desc, | ||
| 118 | .create = tpm_passthrough_create, | ||
| 119 | - .destroy = tpm_passthrough_destroy, | ||
| 120 | .init = tpm_passthrough_init, | ||
| 121 | .startup_tpm = tpm_passthrough_startup_tpm, | ||
| 122 | .realloc_buffer = tpm_passthrough_realloc_buffer, | ||
| 123 | @@ -486,10 +468,21 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 124 | |||
| 125 | static void tpm_passthrough_inst_init(Object *obj) | ||
| 126 | { | ||
| 127 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj); | ||
| 128 | + | ||
| 129 | + tpm_pt->tpm_fd = -1; | ||
| 130 | + tpm_pt->cancel_fd = -1; | ||
| 131 | } | ||
| 132 | |||
| 133 | static void tpm_passthrough_inst_finalize(Object *obj) | ||
| 134 | { | ||
| 135 | + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj); | ||
| 136 | + | ||
| 137 | + tpm_passthrough_cancel_cmd(TPM_BACKEND(obj)); | ||
| 138 | + | ||
| 139 | + qemu_close(tpm_pt->tpm_fd); | ||
| 140 | + qemu_close(tpm_pt->cancel_fd); | ||
| 141 | + g_free(tpm_pt->tpm_dev); | ||
| 142 | } | ||
| 143 | |||
| 144 | static void tpm_passthrough_class_init(ObjectClass *klass, void *data) | ||
| 145 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 146 | index 58308b3687..202ec8d5a2 100644 | ||
| 147 | --- a/include/sysemu/tpm_backend.h | ||
| 148 | +++ b/include/sysemu/tpm_backend.h | ||
| 149 | @@ -78,7 +78,6 @@ struct TPMDriverOps { | ||
| 150 | const char *(*desc)(void); | ||
| 151 | |||
| 152 | TPMBackend *(*create)(QemuOpts *opts, const char *id); | ||
| 153 | - void (*destroy)(TPMBackend *t); | ||
| 154 | |||
| 155 | /* initialize the backend */ | ||
| 156 | int (*init)(TPMBackend *t); | ||
| 157 | @@ -118,12 +117,6 @@ enum TpmType tpm_backend_get_type(TPMBackend *s); | ||
| 158 | const char *tpm_backend_get_desc(TPMBackend *s); | ||
| 159 | |||
| 160 | /** | ||
| 161 | - * tpm_backend_destroy: | ||
| 162 | - * @s: the backend to destroy | ||
| 163 | - */ | ||
| 164 | -void tpm_backend_destroy(TPMBackend *s); | ||
| 165 | - | ||
| 166 | -/** | ||
| 167 | * tpm_backend_init: | ||
| 168 | * @s: the backend to initialized | ||
| 169 | * @state: TPMState | ||
| 170 | diff --git a/tpm.c b/tpm.c | ||
| 171 | index b7166ca200..7feb3b43c9 100644 | ||
| 172 | --- a/tpm.c | ||
| 173 | +++ b/tpm.c | ||
| 174 | @@ -158,7 +158,7 @@ void tpm_cleanup(void) | ||
| 175 | |||
| 176 | QLIST_FOREACH_SAFE(drv, &tpm_backends, list, next) { | ||
| 177 | QLIST_REMOVE(drv, list); | ||
| 178 | - tpm_backend_destroy(drv); | ||
| 179 | + object_unref(OBJECT(drv)); | ||
| 180 | } | ||
| 181 | } | ||
| 182 | |||
| 183 | -- | ||
| 184 | 2.11.0 | ||
| 185 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0006-tpm-backend-Made-few-interface-methods-optional.patch b/meta/recipes-devtools/qemu/qemu/0006-tpm-backend-Made-few-interface-methods-optional.patch new file mode 100644 index 0000000000..eb456f01c7 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0006-tpm-backend-Made-few-interface-methods-optional.patch | |||
| @@ -0,0 +1,284 @@ | |||
| 1 | From 47e6ef6586401e82e652f3c013a349bba3a0479b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Thu, 30 Mar 2017 18:04:16 +0300 | ||
| 4 | Subject: [PATCH 06/12] tpm-backend: Made few interface methods optional | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | This allows backend implementations left optional interface methods. | ||
| 10 | For mandatory methods assertion checks added. | ||
| 11 | |||
| 12 | Took the opportunity to remove unused methods: | ||
| 13 | - tpm_backend_get_desc() | ||
| 14 | - TPMDriverOps->handle_startup_error | ||
| 15 | |||
| 16 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 17 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 18 | Reviewed-by: Stefan Berger<stefanb@linux.vnet.ibm.com> | ||
| 19 | |||
| 20 | Upstream-Status: Backport [93330cf542b920b6ea5fea8120a08b76bb353113] | ||
| 21 | --- | ||
| 22 | backends/tpm.c | 39 ++++++++++++++++++++++++--------------- | ||
| 23 | hw/tpm/tpm_passthrough.c | 36 +----------------------------------- | ||
| 24 | include/sysemu/tpm_backend.h | 13 ++----------- | ||
| 25 | tpm.c | 2 +- | ||
| 26 | 4 files changed, 28 insertions(+), 62 deletions(-) | ||
| 27 | |||
| 28 | diff --git a/backends/tpm.c b/backends/tpm.c | ||
| 29 | index cf5abf1582..8911597fab 100644 | ||
| 30 | --- a/backends/tpm.c | ||
| 31 | +++ b/backends/tpm.c | ||
| 32 | @@ -44,13 +44,6 @@ enum TpmType tpm_backend_get_type(TPMBackend *s) | ||
| 33 | return k->ops->type; | ||
| 34 | } | ||
| 35 | |||
| 36 | -const char *tpm_backend_get_desc(TPMBackend *s) | ||
| 37 | -{ | ||
| 38 | - TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 39 | - | ||
| 40 | - return k->ops->desc(); | ||
| 41 | -} | ||
| 42 | - | ||
| 43 | int tpm_backend_init(TPMBackend *s, TPMState *state, | ||
| 44 | TPMRecvDataCB *datacb) | ||
| 45 | { | ||
| 46 | @@ -58,12 +51,14 @@ int tpm_backend_init(TPMBackend *s, TPMState *state, | ||
| 47 | |||
| 48 | s->tpm_state = state; | ||
| 49 | s->recv_data_callback = datacb; | ||
| 50 | + s->had_startup_error = false; | ||
| 51 | |||
| 52 | - return k->ops->init(s); | ||
| 53 | + return k->ops->init ? k->ops->init(s) : 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | int tpm_backend_startup_tpm(TPMBackend *s) | ||
| 57 | { | ||
| 58 | + int res = 0; | ||
| 59 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 60 | |||
| 61 | /* terminate a running TPM */ | ||
| 62 | @@ -73,20 +68,24 @@ int tpm_backend_startup_tpm(TPMBackend *s) | ||
| 63 | NULL); | ||
| 64 | g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL); | ||
| 65 | |||
| 66 | - return k->ops->startup_tpm(s); | ||
| 67 | + res = k->ops->startup_tpm ? k->ops->startup_tpm(s) : 0; | ||
| 68 | + | ||
| 69 | + s->had_startup_error = (res != 0); | ||
| 70 | + | ||
| 71 | + return res; | ||
| 72 | } | ||
| 73 | |||
| 74 | bool tpm_backend_had_startup_error(TPMBackend *s) | ||
| 75 | { | ||
| 76 | - TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 77 | - | ||
| 78 | - return k->ops->had_startup_error(s); | ||
| 79 | + return s->had_startup_error; | ||
| 80 | } | ||
| 81 | |||
| 82 | size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb) | ||
| 83 | { | ||
| 84 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 85 | |||
| 86 | + assert(k->ops->realloc_buffer); | ||
| 87 | + | ||
| 88 | return k->ops->realloc_buffer(sb); | ||
| 89 | } | ||
| 90 | |||
| 91 | @@ -100,15 +99,21 @@ void tpm_backend_reset(TPMBackend *s) | ||
| 92 | { | ||
| 93 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 94 | |||
| 95 | - k->ops->reset(s); | ||
| 96 | + if (k->ops->reset) { | ||
| 97 | + k->ops->reset(s); | ||
| 98 | + } | ||
| 99 | |||
| 100 | tpm_backend_thread_end(s); | ||
| 101 | + | ||
| 102 | + s->had_startup_error = false; | ||
| 103 | } | ||
| 104 | |||
| 105 | void tpm_backend_cancel_cmd(TPMBackend *s) | ||
| 106 | { | ||
| 107 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 108 | |||
| 109 | + assert(k->ops->cancel_cmd); | ||
| 110 | + | ||
| 111 | k->ops->cancel_cmd(s); | ||
| 112 | } | ||
| 113 | |||
| 114 | @@ -116,20 +121,24 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s) | ||
| 115 | { | ||
| 116 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 117 | |||
| 118 | - return k->ops->get_tpm_established_flag(s); | ||
| 119 | + return k->ops->get_tpm_established_flag ? | ||
| 120 | + k->ops->get_tpm_established_flag(s) : false; | ||
| 121 | } | ||
| 122 | |||
| 123 | int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty) | ||
| 124 | { | ||
| 125 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 126 | |||
| 127 | - return k->ops->reset_tpm_established_flag(s, locty); | ||
| 128 | + return k->ops->reset_tpm_established_flag ? | ||
| 129 | + k->ops->reset_tpm_established_flag(s, locty) : 0; | ||
| 130 | } | ||
| 131 | |||
| 132 | TPMVersion tpm_backend_get_tpm_version(TPMBackend *s) | ||
| 133 | { | ||
| 134 | TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 135 | |||
| 136 | + assert(k->ops->get_tpm_version); | ||
| 137 | + | ||
| 138 | return k->ops->get_tpm_version(s); | ||
| 139 | } | ||
| 140 | |||
| 141 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 142 | index 815a72ef9a..4c21e52b7c 100644 | ||
| 143 | --- a/hw/tpm/tpm_passthrough.c | ||
| 144 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 145 | @@ -54,7 +54,6 @@ struct TPMPassthruState { | ||
| 146 | bool tpm_executing; | ||
| 147 | bool tpm_op_canceled; | ||
| 148 | int cancel_fd; | ||
| 149 | - bool had_startup_error; | ||
| 150 | |||
| 151 | TPMVersion tpm_version; | ||
| 152 | }; | ||
| 153 | @@ -227,29 +226,11 @@ static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd cmd) | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | -/* | ||
| 158 | - * Start the TPM (thread). If it had been started before, then terminate | ||
| 159 | - * and start it again. | ||
| 160 | - */ | ||
| 161 | -static int tpm_passthrough_startup_tpm(TPMBackend *tb) | ||
| 162 | -{ | ||
| 163 | - return 0; | ||
| 164 | -} | ||
| 165 | - | ||
| 166 | static void tpm_passthrough_reset(TPMBackend *tb) | ||
| 167 | { | ||
| 168 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 169 | - | ||
| 170 | DPRINTF("tpm_passthrough: CALL TO TPM_RESET!\n"); | ||
| 171 | |||
| 172 | tpm_passthrough_cancel_cmd(tb); | ||
| 173 | - | ||
| 174 | - tpm_pt->had_startup_error = false; | ||
| 175 | -} | ||
| 176 | - | ||
| 177 | -static int tpm_passthrough_init(TPMBackend *tb) | ||
| 178 | -{ | ||
| 179 | - return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb) | ||
| 183 | @@ -264,13 +245,6 @@ static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb, | ||
| 184 | return 0; | ||
| 185 | } | ||
| 186 | |||
| 187 | -static bool tpm_passthrough_get_startup_error(TPMBackend *tb) | ||
| 188 | -{ | ||
| 189 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 190 | - | ||
| 191 | - return tpm_pt->had_startup_error; | ||
| 192 | -} | ||
| 193 | - | ||
| 194 | static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb) | ||
| 195 | { | ||
| 196 | size_t wanted_size = 4096; /* Linux tpm.c buffer size */ | ||
| 197 | @@ -309,11 +283,6 @@ static void tpm_passthrough_cancel_cmd(TPMBackend *tb) | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | -static const char *tpm_passthrough_create_desc(void) | ||
| 202 | -{ | ||
| 203 | - return "Passthrough TPM backend driver"; | ||
| 204 | -} | ||
| 205 | - | ||
| 206 | static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb) | ||
| 207 | { | ||
| 208 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 209 | @@ -453,13 +422,10 @@ static const QemuOptDesc tpm_passthrough_cmdline_opts[] = { | ||
| 210 | static const TPMDriverOps tpm_passthrough_driver = { | ||
| 211 | .type = TPM_TYPE_PASSTHROUGH, | ||
| 212 | .opts = tpm_passthrough_cmdline_opts, | ||
| 213 | - .desc = tpm_passthrough_create_desc, | ||
| 214 | + .desc = "Passthrough TPM backend driver", | ||
| 215 | .create = tpm_passthrough_create, | ||
| 216 | - .init = tpm_passthrough_init, | ||
| 217 | - .startup_tpm = tpm_passthrough_startup_tpm, | ||
| 218 | .realloc_buffer = tpm_passthrough_realloc_buffer, | ||
| 219 | .reset = tpm_passthrough_reset, | ||
| 220 | - .had_startup_error = tpm_passthrough_get_startup_error, | ||
| 221 | .cancel_cmd = tpm_passthrough_cancel_cmd, | ||
| 222 | .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, | ||
| 223 | .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag, | ||
| 224 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 225 | index 202ec8d5a2..9ea707253a 100644 | ||
| 226 | --- a/include/sysemu/tpm_backend.h | ||
| 227 | +++ b/include/sysemu/tpm_backend.h | ||
| 228 | @@ -47,6 +47,7 @@ struct TPMBackend { | ||
| 229 | TPMState *tpm_state; | ||
| 230 | GThreadPool *thread_pool; | ||
| 231 | TPMRecvDataCB *recv_data_callback; | ||
| 232 | + bool had_startup_error; | ||
| 233 | |||
| 234 | char *id; | ||
| 235 | enum TpmModel fe_model; | ||
| 236 | @@ -75,7 +76,7 @@ struct TPMDriverOps { | ||
| 237 | enum TpmType type; | ||
| 238 | const QemuOptDesc *opts; | ||
| 239 | /* get a descriptive text of the backend to display to the user */ | ||
| 240 | - const char *(*desc)(void); | ||
| 241 | + const char *desc; | ||
| 242 | |||
| 243 | TPMBackend *(*create)(QemuOpts *opts, const char *id); | ||
| 244 | |||
| 245 | @@ -83,8 +84,6 @@ struct TPMDriverOps { | ||
| 246 | int (*init)(TPMBackend *t); | ||
| 247 | /* start up the TPM on the backend */ | ||
| 248 | int (*startup_tpm)(TPMBackend *t); | ||
| 249 | - /* returns true if nothing will ever answer TPM requests */ | ||
| 250 | - bool (*had_startup_error)(TPMBackend *t); | ||
| 251 | |||
| 252 | size_t (*realloc_buffer)(TPMSizedBuffer *sb); | ||
| 253 | |||
| 254 | @@ -109,14 +108,6 @@ struct TPMDriverOps { | ||
| 255 | enum TpmType tpm_backend_get_type(TPMBackend *s); | ||
| 256 | |||
| 257 | /** | ||
| 258 | - * tpm_backend_get_desc: | ||
| 259 | - * @s: the backend | ||
| 260 | - * | ||
| 261 | - * Returns a human readable description of the backend. | ||
| 262 | - */ | ||
| 263 | -const char *tpm_backend_get_desc(TPMBackend *s); | ||
| 264 | - | ||
| 265 | -/** | ||
| 266 | * tpm_backend_init: | ||
| 267 | * @s: the backend to initialized | ||
| 268 | * @state: TPMState | ||
| 269 | diff --git a/tpm.c b/tpm.c | ||
| 270 | index 7feb3b43c9..9f4f37da50 100644 | ||
| 271 | --- a/tpm.c | ||
| 272 | +++ b/tpm.c | ||
| 273 | @@ -63,7 +63,7 @@ static void tpm_display_backend_drivers(void) | ||
| 274 | continue; | ||
| 275 | } | ||
| 276 | fprintf(stderr, "%12s %s\n", | ||
| 277 | - TpmType_lookup[i], be_drivers[i]->desc()); | ||
| 278 | + TpmType_lookup[i], be_drivers[i]->desc); | ||
| 279 | } | ||
| 280 | fprintf(stderr, "\n"); | ||
| 281 | } | ||
| 282 | -- | ||
| 283 | 2.11.0 | ||
| 284 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch b/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch new file mode 100644 index 0000000000..6d79ac4d63 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch | |||
| @@ -0,0 +1,293 @@ | |||
| 1 | From 5f698395b5de1ab2826f5aad99d757ce31d7c95f Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Mon, 6 Mar 2017 00:10:10 +0200 | ||
| 4 | Subject: [PATCH 07/12] tpm backend: Add new api to read backend TpmInfo | ||
| 5 | |||
| 6 | TPM configuration options are backend implementation details and shall not be | ||
| 7 | part of base TPMBackend object, and these shall not be accessed directly outside | ||
| 8 | of the class, hence added a new interface method, get_tpm_options() to | ||
| 9 | TPMDriverOps., which shall be implemented by the derived classes to return | ||
| 10 | configured tpm options. | ||
| 11 | |||
| 12 | A new tpm backend api - tpm_backend_query_tpm() which uses _get_tpm_options() to | ||
| 13 | prepare TpmInfo. | ||
| 14 | |||
| 15 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 16 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 17 | |||
| 18 | Upstream-Status: Backport[f59864ba3aedd26aef7c84545cc1e565caccebf7] | ||
| 19 | --- | ||
| 20 | backends/tpm.c | 15 +++++++++++-- | ||
| 21 | hw/tpm/tpm_passthrough.c | 51 +++++++++++++++++++++++++++----------------- | ||
| 22 | include/sysemu/tpm_backend.h | 15 +++++++++++-- | ||
| 23 | tpm.c | 32 +-------------------------- | ||
| 24 | 4 files changed, 59 insertions(+), 54 deletions(-) | ||
| 25 | |||
| 26 | diff --git a/backends/tpm.c b/backends/tpm.c | ||
| 27 | index 8911597fab..de313c9d5a 100644 | ||
| 28 | --- a/backends/tpm.c | ||
| 29 | +++ b/backends/tpm.c | ||
| 30 | @@ -142,6 +142,19 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s) | ||
| 31 | return k->ops->get_tpm_version(s); | ||
| 32 | } | ||
| 33 | |||
| 34 | +TPMInfo *tpm_backend_query_tpm(TPMBackend *s) | ||
| 35 | +{ | ||
| 36 | + TPMInfo *info = g_new0(TPMInfo, 1); | ||
| 37 | + TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 38 | + | ||
| 39 | + info->id = g_strdup(s->id); | ||
| 40 | + info->model = s->fe_model; | ||
| 41 | + info->options = k->ops->get_tpm_options ? | ||
| 42 | + k->ops->get_tpm_options(s) : NULL; | ||
| 43 | + | ||
| 44 | + return info; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | static bool tpm_backend_prop_get_opened(Object *obj, Error **errp) | ||
| 48 | { | ||
| 49 | TPMBackend *s = TPM_BACKEND(obj); | ||
| 50 | @@ -196,8 +209,6 @@ static void tpm_backend_instance_finalize(Object *obj) | ||
| 51 | TPMBackend *s = TPM_BACKEND(obj); | ||
| 52 | |||
| 53 | g_free(s->id); | ||
| 54 | - g_free(s->path); | ||
| 55 | - g_free(s->cancel_path); | ||
| 56 | tpm_backend_thread_end(s); | ||
| 57 | } | ||
| 58 | |||
| 59 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 60 | index 4c21e52b7c..84fc49a4d3 100644 | ||
| 61 | --- a/hw/tpm/tpm_passthrough.c | ||
| 62 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 63 | @@ -30,6 +30,7 @@ | ||
| 64 | #include "tpm_int.h" | ||
| 65 | #include "hw/hw.h" | ||
| 66 | #include "hw/i386/pc.h" | ||
| 67 | +#include "qapi/clone-visitor.h" | ||
| 68 | #include "tpm_tis.h" | ||
| 69 | #include "tpm_util.h" | ||
| 70 | |||
| 71 | @@ -49,7 +50,8 @@ | ||
| 72 | struct TPMPassthruState { | ||
| 73 | TPMBackend parent; | ||
| 74 | |||
| 75 | - char *tpm_dev; | ||
| 76 | + TPMPassthroughOptions *options; | ||
| 77 | + const char *tpm_dev; | ||
| 78 | int tpm_fd; | ||
| 79 | bool tpm_executing; | ||
| 80 | bool tpm_op_canceled; | ||
| 81 | @@ -296,15 +298,14 @@ static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb) | ||
| 82 | * in Documentation/ABI/stable/sysfs-class-tpm. | ||
| 83 | * From /dev/tpm0 create /sys/class/misc/tpm0/device/cancel | ||
| 84 | */ | ||
| 85 | -static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) | ||
| 86 | +static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt) | ||
| 87 | { | ||
| 88 | - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 89 | int fd = -1; | ||
| 90 | char *dev; | ||
| 91 | char path[PATH_MAX]; | ||
| 92 | |||
| 93 | - if (tb->cancel_path) { | ||
| 94 | - fd = qemu_open(tb->cancel_path, O_WRONLY); | ||
| 95 | + if (tpm_pt->options->cancel_path) { | ||
| 96 | + fd = qemu_open(tpm_pt->options->cancel_path, O_WRONLY); | ||
| 97 | if (fd < 0) { | ||
| 98 | error_report("Could not open TPM cancel path : %s", | ||
| 99 | strerror(errno)); | ||
| 100 | @@ -319,7 +320,7 @@ static int tpm_passthrough_open_sysfs_cancel(TPMBackend *tb) | ||
| 101 | dev) < sizeof(path)) { | ||
| 102 | fd = qemu_open(path, O_WRONLY); | ||
| 103 | if (fd >= 0) { | ||
| 104 | - tb->cancel_path = g_strdup(path); | ||
| 105 | + tpm_pt->options->cancel_path = g_strdup(path); | ||
| 106 | } else { | ||
| 107 | error_report("tpm_passthrough: Could not open TPM cancel " | ||
| 108 | "path %s : %s", path, strerror(errno)); | ||
| 109 | @@ -339,17 +340,18 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 110 | const char *value; | ||
| 111 | |||
| 112 | value = qemu_opt_get(opts, "cancel-path"); | ||
| 113 | - tb->cancel_path = g_strdup(value); | ||
| 114 | + if (value) { | ||
| 115 | + tpm_pt->options->cancel_path = g_strdup(value); | ||
| 116 | + tpm_pt->options->has_cancel_path = true; | ||
| 117 | + } | ||
| 118 | |||
| 119 | value = qemu_opt_get(opts, "path"); | ||
| 120 | - if (!value) { | ||
| 121 | - value = TPM_PASSTHROUGH_DEFAULT_DEVICE; | ||
| 122 | + if (value) { | ||
| 123 | + tpm_pt->options->has_path = true; | ||
| 124 | + tpm_pt->options->path = g_strdup(value); | ||
| 125 | } | ||
| 126 | |||
| 127 | - tpm_pt->tpm_dev = g_strdup(value); | ||
| 128 | - | ||
| 129 | - tb->path = g_strdup(tpm_pt->tpm_dev); | ||
| 130 | - | ||
| 131 | + tpm_pt->tpm_dev = value ? value : TPM_PASSTHROUGH_DEFAULT_DEVICE; | ||
| 132 | tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR); | ||
| 133 | if (tpm_pt->tpm_fd < 0) { | ||
| 134 | error_report("Cannot access TPM device using '%s': %s", | ||
| 135 | @@ -370,10 +372,8 @@ static int tpm_passthrough_handle_device_opts(QemuOpts *opts, TPMBackend *tb) | ||
| 136 | tpm_pt->tpm_fd = -1; | ||
| 137 | |||
| 138 | err_free_parameters: | ||
| 139 | - g_free(tb->path); | ||
| 140 | - tb->path = NULL; | ||
| 141 | - | ||
| 142 | - g_free(tpm_pt->tpm_dev); | ||
| 143 | + qapi_free_TPMPassthroughOptions(tpm_pt->options); | ||
| 144 | + tpm_pt->options = NULL; | ||
| 145 | tpm_pt->tpm_dev = NULL; | ||
| 146 | |||
| 147 | return 1; | ||
| 148 | @@ -391,7 +391,7 @@ static TPMBackend *tpm_passthrough_create(QemuOpts *opts, const char *id) | ||
| 149 | goto err_exit; | ||
| 150 | } | ||
| 151 | |||
| 152 | - tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tb); | ||
| 153 | + tpm_pt->cancel_fd = tpm_passthrough_open_sysfs_cancel(tpm_pt); | ||
| 154 | if (tpm_pt->cancel_fd < 0) { | ||
| 155 | goto err_exit; | ||
| 156 | } | ||
| 157 | @@ -404,6 +404,17 @@ err_exit: | ||
| 158 | return NULL; | ||
| 159 | } | ||
| 160 | |||
| 161 | +static TpmTypeOptions *tpm_passthrough_get_tpm_options(TPMBackend *tb) | ||
| 162 | +{ | ||
| 163 | + TpmTypeOptions *options = g_new0(TpmTypeOptions, 1); | ||
| 164 | + | ||
| 165 | + options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; | ||
| 166 | + options->u.passthrough.data = QAPI_CLONE(TPMPassthroughOptions, | ||
| 167 | + TPM_PASSTHROUGH(tb)->options); | ||
| 168 | + | ||
| 169 | + return options; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | static const QemuOptDesc tpm_passthrough_cmdline_opts[] = { | ||
| 173 | TPM_STANDARD_CMDLINE_OPTS, | ||
| 174 | { | ||
| 175 | @@ -430,12 +441,14 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 176 | .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, | ||
| 177 | .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag, | ||
| 178 | .get_tpm_version = tpm_passthrough_get_tpm_version, | ||
| 179 | + .get_tpm_options = tpm_passthrough_get_tpm_options, | ||
| 180 | }; | ||
| 181 | |||
| 182 | static void tpm_passthrough_inst_init(Object *obj) | ||
| 183 | { | ||
| 184 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj); | ||
| 185 | |||
| 186 | + tpm_pt->options = g_new0(TPMPassthroughOptions, 1); | ||
| 187 | tpm_pt->tpm_fd = -1; | ||
| 188 | tpm_pt->cancel_fd = -1; | ||
| 189 | } | ||
| 190 | @@ -448,7 +461,7 @@ static void tpm_passthrough_inst_finalize(Object *obj) | ||
| 191 | |||
| 192 | qemu_close(tpm_pt->tpm_fd); | ||
| 193 | qemu_close(tpm_pt->cancel_fd); | ||
| 194 | - g_free(tpm_pt->tpm_dev); | ||
| 195 | + qapi_free_TPMPassthroughOptions(tpm_pt->options); | ||
| 196 | } | ||
| 197 | |||
| 198 | static void tpm_passthrough_class_init(ObjectClass *klass, void *data) | ||
| 199 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 200 | index 9ea707253a..e96c1918cc 100644 | ||
| 201 | --- a/include/sysemu/tpm_backend.h | ||
| 202 | +++ b/include/sysemu/tpm_backend.h | ||
| 203 | @@ -49,10 +49,9 @@ struct TPMBackend { | ||
| 204 | TPMRecvDataCB *recv_data_callback; | ||
| 205 | bool had_startup_error; | ||
| 206 | |||
| 207 | + /* <public> */ | ||
| 208 | char *id; | ||
| 209 | enum TpmModel fe_model; | ||
| 210 | - char *path; | ||
| 211 | - char *cancel_path; | ||
| 212 | |||
| 213 | QLIST_ENTRY(TPMBackend) list; | ||
| 214 | }; | ||
| 215 | @@ -96,6 +95,8 @@ struct TPMDriverOps { | ||
| 216 | int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty); | ||
| 217 | |||
| 218 | TPMVersion (*get_tpm_version)(TPMBackend *t); | ||
| 219 | + | ||
| 220 | + TpmTypeOptions *(*get_tpm_options)(TPMBackend *t); | ||
| 221 | }; | ||
| 222 | |||
| 223 | |||
| 224 | @@ -214,6 +215,16 @@ void tpm_backend_open(TPMBackend *s, Error **errp); | ||
| 225 | */ | ||
| 226 | TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); | ||
| 227 | |||
| 228 | +/** | ||
| 229 | + * tpm_backend_query_tpm: | ||
| 230 | + * @s: the backend | ||
| 231 | + * | ||
| 232 | + * Query backend tpm info | ||
| 233 | + * | ||
| 234 | + * Returns newly allocated TPMInfo | ||
| 235 | + */ | ||
| 236 | +TPMInfo *tpm_backend_query_tpm(TPMBackend *s); | ||
| 237 | + | ||
| 238 | TPMBackend *qemu_find_tpm(const char *id); | ||
| 239 | |||
| 240 | const TPMDriverOps *tpm_get_backend_driver(const char *type); | ||
| 241 | diff --git a/tpm.c b/tpm.c | ||
| 242 | index 9f4f37da50..cac400ef3e 100644 | ||
| 243 | --- a/tpm.c | ||
| 244 | +++ b/tpm.c | ||
| 245 | @@ -203,36 +203,6 @@ static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) | ||
| 246 | return be_drivers[type]; | ||
| 247 | } | ||
| 248 | |||
| 249 | -static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) | ||
| 250 | -{ | ||
| 251 | - TPMInfo *res = g_new0(TPMInfo, 1); | ||
| 252 | - TPMPassthroughOptions *tpo; | ||
| 253 | - | ||
| 254 | - res->id = g_strdup(drv->id); | ||
| 255 | - res->model = drv->fe_model; | ||
| 256 | - res->options = g_new0(TpmTypeOptions, 1); | ||
| 257 | - | ||
| 258 | - switch (tpm_backend_get_type(drv)) { | ||
| 259 | - case TPM_TYPE_PASSTHROUGH: | ||
| 260 | - res->options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; | ||
| 261 | - tpo = g_new0(TPMPassthroughOptions, 1); | ||
| 262 | - res->options->u.passthrough.data = tpo; | ||
| 263 | - if (drv->path) { | ||
| 264 | - tpo->path = g_strdup(drv->path); | ||
| 265 | - tpo->has_path = true; | ||
| 266 | - } | ||
| 267 | - if (drv->cancel_path) { | ||
| 268 | - tpo->cancel_path = g_strdup(drv->cancel_path); | ||
| 269 | - tpo->has_cancel_path = true; | ||
| 270 | - } | ||
| 271 | - break; | ||
| 272 | - case TPM_TYPE__MAX: | ||
| 273 | - break; | ||
| 274 | - } | ||
| 275 | - | ||
| 276 | - return res; | ||
| 277 | -} | ||
| 278 | - | ||
| 279 | /* | ||
| 280 | * Walk the list of active TPM backends and collect information about them | ||
| 281 | * following the schema description in qapi-schema.json. | ||
| 282 | @@ -247,7 +217,7 @@ TPMInfoList *qmp_query_tpm(Error **errp) | ||
| 283 | continue; | ||
| 284 | } | ||
| 285 | info = g_new0(TPMInfoList, 1); | ||
| 286 | - info->value = qmp_query_tpm_inst(drv); | ||
| 287 | + info->value = tpm_backend_query_tpm(drv); | ||
| 288 | |||
| 289 | if (!cur_item) { | ||
| 290 | head = cur_item = info; | ||
| 291 | -- | ||
| 292 | 2.11.0 | ||
| 293 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0008-tpm-backend-Move-realloc_buffer-implementation-to-tp.patch b/meta/recipes-devtools/qemu/qemu/0008-tpm-backend-Move-realloc_buffer-implementation-to-tp.patch new file mode 100644 index 0000000000..94cc6c542c --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0008-tpm-backend-Move-realloc_buffer-implementation-to-tp.patch | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | From 02189909fdc5e73b3ca54362084c16f0b67a3fdf Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Fri, 7 Apr 2017 10:57:28 +0300 | ||
| 4 | Subject: [PATCH 08/12] tpm-backend: Move realloc_buffer() implementation to | ||
| 5 | tpm-tis model | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=UTF-8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | buffer reallocation is very unlikely to be backend specific. Hence move inside | ||
| 11 | the tis. | ||
| 12 | |||
| 13 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 14 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 15 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 16 | |||
| 17 | Upstream-Status: Backport [d0c519bdffa303d141727369e55b157c45b03147] | ||
| 18 | --- | ||
| 19 | backends/tpm.c | 9 --------- | ||
| 20 | hw/tpm/tpm_passthrough.c | 12 ------------ | ||
| 21 | hw/tpm/tpm_tis.c | 14 ++++++++++++-- | ||
| 22 | include/sysemu/tpm_backend.h | 12 ------------ | ||
| 23 | 4 files changed, 12 insertions(+), 35 deletions(-) | ||
| 24 | |||
| 25 | diff --git a/backends/tpm.c b/backends/tpm.c | ||
| 26 | index de313c9d5a..37c84b7c66 100644 | ||
| 27 | --- a/backends/tpm.c | ||
| 28 | +++ b/backends/tpm.c | ||
| 29 | @@ -80,15 +80,6 @@ bool tpm_backend_had_startup_error(TPMBackend *s) | ||
| 30 | return s->had_startup_error; | ||
| 31 | } | ||
| 32 | |||
| 33 | -size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb) | ||
| 34 | -{ | ||
| 35 | - TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); | ||
| 36 | - | ||
| 37 | - assert(k->ops->realloc_buffer); | ||
| 38 | - | ||
| 39 | - return k->ops->realloc_buffer(sb); | ||
| 40 | -} | ||
| 41 | - | ||
| 42 | void tpm_backend_deliver_request(TPMBackend *s) | ||
| 43 | { | ||
| 44 | g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, | ||
| 45 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 46 | index 84fc49a4d3..22d3460550 100644 | ||
| 47 | --- a/hw/tpm/tpm_passthrough.c | ||
| 48 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 49 | @@ -247,17 +247,6 @@ static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb, | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | -static size_t tpm_passthrough_realloc_buffer(TPMSizedBuffer *sb) | ||
| 54 | -{ | ||
| 55 | - size_t wanted_size = 4096; /* Linux tpm.c buffer size */ | ||
| 56 | - | ||
| 57 | - if (sb->size != wanted_size) { | ||
| 58 | - sb->buffer = g_realloc(sb->buffer, wanted_size); | ||
| 59 | - sb->size = wanted_size; | ||
| 60 | - } | ||
| 61 | - return sb->size; | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | static void tpm_passthrough_cancel_cmd(TPMBackend *tb) | ||
| 65 | { | ||
| 66 | TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); | ||
| 67 | @@ -435,7 +424,6 @@ static const TPMDriverOps tpm_passthrough_driver = { | ||
| 68 | .opts = tpm_passthrough_cmdline_opts, | ||
| 69 | .desc = "Passthrough TPM backend driver", | ||
| 70 | .create = tpm_passthrough_create, | ||
| 71 | - .realloc_buffer = tpm_passthrough_realloc_buffer, | ||
| 72 | .reset = tpm_passthrough_reset, | ||
| 73 | .cancel_cmd = tpm_passthrough_cancel_cmd, | ||
| 74 | .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag, | ||
| 75 | diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c | ||
| 76 | index a6440fef91..d5118e7f60 100644 | ||
| 77 | --- a/hw/tpm/tpm_tis.c | ||
| 78 | +++ b/hw/tpm/tpm_tis.c | ||
| 79 | @@ -963,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s) | ||
| 80 | return tpm_backend_startup_tpm(s->be_driver); | ||
| 81 | } | ||
| 82 | |||
| 83 | +static void tpm_tis_realloc_buffer(TPMSizedBuffer *sb) | ||
| 84 | +{ | ||
| 85 | + size_t wanted_size = 4096; /* Linux tpm.c buffer size */ | ||
| 86 | + | ||
| 87 | + if (sb->size != wanted_size) { | ||
| 88 | + sb->buffer = g_realloc(sb->buffer, wanted_size); | ||
| 89 | + sb->size = wanted_size; | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | /* | ||
| 94 | * Get the TPMVersion of the backend device being used | ||
| 95 | */ | ||
| 96 | @@ -1010,9 +1020,9 @@ static void tpm_tis_reset(DeviceState *dev) | ||
| 97 | tis->loc[c].state = TPM_TIS_STATE_IDLE; | ||
| 98 | |||
| 99 | tis->loc[c].w_offset = 0; | ||
| 100 | - tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].w_buffer); | ||
| 101 | + tpm_tis_realloc_buffer(&tis->loc[c].w_buffer); | ||
| 102 | tis->loc[c].r_offset = 0; | ||
| 103 | - tpm_backend_realloc_buffer(s->be_driver, &tis->loc[c].r_buffer); | ||
| 104 | + tpm_tis_realloc_buffer(&tis->loc[c].r_buffer); | ||
| 105 | } | ||
| 106 | |||
| 107 | tpm_tis_do_startup_tpm(s); | ||
| 108 | diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h | ||
| 109 | index e96c1918cc..2c798a1eb4 100644 | ||
| 110 | --- a/include/sysemu/tpm_backend.h | ||
| 111 | +++ b/include/sysemu/tpm_backend.h | ||
| 112 | @@ -84,8 +84,6 @@ struct TPMDriverOps { | ||
| 113 | /* start up the TPM on the backend */ | ||
| 114 | int (*startup_tpm)(TPMBackend *t); | ||
| 115 | |||
| 116 | - size_t (*realloc_buffer)(TPMSizedBuffer *sb); | ||
| 117 | - | ||
| 118 | void (*reset)(TPMBackend *t); | ||
| 119 | |||
| 120 | void (*cancel_cmd)(TPMBackend *t); | ||
| 121 | @@ -140,16 +138,6 @@ int tpm_backend_startup_tpm(TPMBackend *s); | ||
| 122 | bool tpm_backend_had_startup_error(TPMBackend *s); | ||
| 123 | |||
| 124 | /** | ||
| 125 | - * tpm_backend_realloc_buffer: | ||
| 126 | - * @s: the backend | ||
| 127 | - * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the | ||
| 128 | - * backend. | ||
| 129 | - * | ||
| 130 | - * This function returns the size of the allocated buffer | ||
| 131 | - */ | ||
| 132 | -size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb); | ||
| 133 | - | ||
| 134 | -/** | ||
| 135 | * tpm_backend_deliver_request: | ||
| 136 | * @s: the backend to send the request to | ||
| 137 | * | ||
| 138 | -- | ||
| 139 | 2.11.0 | ||
| 140 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch b/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch new file mode 100644 index 0000000000..8670b8a0d3 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0009-tpm-passthrough-move-reusable-code-to-utils.patch | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | From b8322aaa2f31995e1b7b776e7efae68416573bc3 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Wed, 29 Mar 2017 15:36:47 +0300 | ||
| 4 | Subject: [PATCH 09/12] tpm-passthrough: move reusable code to utils | ||
| 5 | MIME-Version: 1.0 | ||
| 6 | Content-Type: text/plain; charset=UTF-8 | ||
| 7 | Content-Transfer-Encoding: 8bit | ||
| 8 | |||
| 9 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 10 | Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 11 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 12 | |||
| 13 | Upstream-Status: Backport [4a3d80980ebf71d8faf9d0ce2e2e23bdda5728df] | ||
| 14 | --- | ||
| 15 | hw/tpm/tpm_passthrough.c | 64 ++++-------------------------------------------- | ||
| 16 | hw/tpm/tpm_util.c | 25 +++++++++++++++++++ | ||
| 17 | hw/tpm/tpm_util.h | 4 +++ | ||
| 18 | 3 files changed, 34 insertions(+), 59 deletions(-) | ||
| 19 | |||
| 20 | diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c | ||
| 21 | index 22d3460550..e6ace28b04 100644 | ||
| 22 | --- a/hw/tpm/tpm_passthrough.c | ||
| 23 | +++ b/hw/tpm/tpm_passthrough.c | ||
| 24 | @@ -68,27 +68,6 @@ typedef struct TPMPassthruState TPMPassthruState; | ||
| 25 | |||
| 26 | static void tpm_passthrough_cancel_cmd(TPMBackend *tb); | ||
| 27 | |||
| 28 | -static int tpm_passthrough_unix_write(int fd, const uint8_t *buf, uint32_t len) | ||
| 29 | -{ | ||
| 30 | - int ret, remain; | ||
| 31 | - | ||
| 32 | - remain = len; | ||
| 33 | - while (remain > 0) { | ||
| 34 | - ret = write(fd, buf, remain); | ||
| 35 | - if (ret < 0) { | ||
| 36 | - if (errno != EINTR && errno != EAGAIN) { | ||
| 37 | - return -1; | ||
| 38 | - } | ||
| 39 | - } else if (ret == 0) { | ||
| 40 | - break; | ||
| 41 | - } else { | ||
| 42 | - buf += ret; | ||
| 43 | - remain -= ret; | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - return len - remain; | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len) | ||
| 50 | { | ||
| 51 | int ret; | ||
| 52 | @@ -102,45 +81,12 @@ static int tpm_passthrough_unix_read(int fd, uint8_t *buf, uint32_t len) | ||
| 53 | } | ||
| 54 | return ret; | ||
| 55 | } | ||
| 56 | - | ||
| 57 | -static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf) | ||
| 58 | -{ | ||
| 59 | - struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)buf; | ||
| 60 | - | ||
| 61 | - return be32_to_cpu(resp->len); | ||
| 62 | -} | ||
| 63 | - | ||
| 64 | -/* | ||
| 65 | - * Write an error message in the given output buffer. | ||
| 66 | - */ | ||
| 67 | -static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) | ||
| 68 | -{ | ||
| 69 | - if (out_len >= sizeof(struct tpm_resp_hdr)) { | ||
| 70 | - struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; | ||
| 71 | - | ||
| 72 | - resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); | ||
| 73 | - resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); | ||
| 74 | - resp->errcode = cpu_to_be32(TPM_FAIL); | ||
| 75 | - } | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len) | ||
| 79 | -{ | ||
| 80 | - struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; | ||
| 81 | - | ||
| 82 | - if (in_len >= sizeof(*hdr)) { | ||
| 83 | - return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - return false; | ||
| 87 | -} | ||
| 88 | - | ||
| 89 | static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 90 | const uint8_t *in, uint32_t in_len, | ||
| 91 | uint8_t *out, uint32_t out_len, | ||
| 92 | bool *selftest_done) | ||
| 93 | { | ||
| 94 | - int ret; | ||
| 95 | + ssize_t ret; | ||
| 96 | bool is_selftest; | ||
| 97 | const struct tpm_resp_hdr *hdr; | ||
| 98 | |||
| 99 | @@ -148,9 +94,9 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 100 | tpm_pt->tpm_executing = true; | ||
| 101 | *selftest_done = false; | ||
| 102 | |||
| 103 | - is_selftest = tpm_passthrough_is_selftest(in, in_len); | ||
| 104 | + is_selftest = tpm_util_is_selftest(in, in_len); | ||
| 105 | |||
| 106 | - ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len); | ||
| 107 | + ret = qemu_write_full(tpm_pt->tpm_fd, (const void *)in, (size_t)in_len); | ||
| 108 | if (ret != in_len) { | ||
| 109 | if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) { | ||
| 110 | error_report("tpm_passthrough: error while transmitting data " | ||
| 111 | @@ -170,7 +116,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 112 | strerror(errno), errno); | ||
| 113 | } | ||
| 114 | } else if (ret < sizeof(struct tpm_resp_hdr) || | ||
| 115 | - tpm_passthrough_get_size_from_buffer(out) != ret) { | ||
| 116 | + be32_to_cpu(((struct tpm_resp_hdr *)out)->len) != ret) { | ||
| 117 | ret = -1; | ||
| 118 | error_report("tpm_passthrough: received invalid response " | ||
| 119 | "packet from TPM"); | ||
| 120 | @@ -183,7 +129,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, | ||
| 121 | |||
| 122 | err_exit: | ||
| 123 | if (ret < 0) { | ||
| 124 | - tpm_write_fatal_error_response(out, out_len); | ||
| 125 | + tpm_util_write_fatal_error_response(out, out_len); | ||
| 126 | } | ||
| 127 | |||
| 128 | tpm_pt->tpm_executing = false; | ||
| 129 | diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c | ||
| 130 | index 7b35429725..fb929f6e92 100644 | ||
| 131 | --- a/hw/tpm/tpm_util.c | ||
| 132 | +++ b/hw/tpm/tpm_util.c | ||
| 133 | @@ -24,6 +24,31 @@ | ||
| 134 | #include "tpm_int.h" | ||
| 135 | |||
| 136 | /* | ||
| 137 | + * Write an error message in the given output buffer. | ||
| 138 | + */ | ||
| 139 | +void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len) | ||
| 140 | +{ | ||
| 141 | + if (out_len >= sizeof(struct tpm_resp_hdr)) { | ||
| 142 | + struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out; | ||
| 143 | + | ||
| 144 | + resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND); | ||
| 145 | + resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr)); | ||
| 146 | + resp->errcode = cpu_to_be32(TPM_FAIL); | ||
| 147 | + } | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len) | ||
| 151 | +{ | ||
| 152 | + struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; | ||
| 153 | + | ||
| 154 | + if (in_len >= sizeof(*hdr)) { | ||
| 155 | + return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + return false; | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +/* | ||
| 162 | * A basic test of a TPM device. We expect a well formatted response header | ||
| 163 | * (error response is fine) within one second. | ||
| 164 | */ | ||
| 165 | diff --git a/hw/tpm/tpm_util.h b/hw/tpm/tpm_util.h | ||
| 166 | index df76245e6e..2f7c96146d 100644 | ||
| 167 | --- a/hw/tpm/tpm_util.h | ||
| 168 | +++ b/hw/tpm/tpm_util.h | ||
| 169 | @@ -24,6 +24,10 @@ | ||
| 170 | |||
| 171 | #include "sysemu/tpm_backend.h" | ||
| 172 | |||
| 173 | +void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len); | ||
| 174 | + | ||
| 175 | +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len); | ||
| 176 | + | ||
| 177 | int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version); | ||
| 178 | |||
| 179 | #endif /* TPM_TPM_UTIL_H */ | ||
| 180 | -- | ||
| 181 | 2.11.0 | ||
| 182 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0010-tpm-Added-support-for-TPM-emulator.patch b/meta/recipes-devtools/qemu/qemu/0010-tpm-Added-support-for-TPM-emulator.patch new file mode 100644 index 0000000000..968e12e88a --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0010-tpm-Added-support-for-TPM-emulator.patch | |||
| @@ -0,0 +1,1059 @@ | |||
| 1 | From 70e73b7c6c7cf982d645db9c81c74588e6b10a2b Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Wed, 29 Mar 2017 15:39:41 +0300 | ||
| 4 | Subject: [PATCH 10/12] tpm: Added support for TPM emulator | ||
| 5 | |||
| 6 | This change introduces a new TPM backend driver that can communicate with | ||
| 7 | swtpm(software TPM emulator) using unix domain socket interface. QEMU talks to | ||
| 8 | TPM emulator using QEMU's socket-based chardev backend device. | ||
| 9 | |||
| 10 | Swtpm uses two Unix sockets for communications, one for plain TPM commands and | ||
| 11 | responses, and one for out-of-band control messages. QEMU passes data socket to | ||
| 12 | be used over the control channel. | ||
| 13 | |||
| 14 | The swtpm and associated tools can be found here: | ||
| 15 | https://github.com/stefanberger/swtpm | ||
| 16 | |||
| 17 | The swtpm's control channel protocol specification can be found here: | ||
| 18 | https://github.com/stefanberger/swtpm/wiki/Control-Channel-Specification | ||
| 19 | |||
| 20 | Usage: | ||
| 21 | # setup TPM state directory | ||
| 22 | mkdir /tmp/mytpm | ||
| 23 | chown -R tss:root /tmp/mytpm | ||
| 24 | /usr/bin/swtpm_setup --tpm-state /tmp/mytpm --createek | ||
| 25 | |||
| 26 | # Ask qemu to use TPM emulator with given tpm state directory | ||
| 27 | qemu-system-x86_64 \ | ||
| 28 | [...] \ | ||
| 29 | -chardev socket,id=chrtpm,path=/tmp/swtpm-sock \ | ||
| 30 | -tpmdev emulator,id=tpm0,chardev=chrtpm \ | ||
| 31 | -device tpm-tis,tpmdev=tpm0 \ | ||
| 32 | [...] | ||
| 33 | |||
| 34 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 35 | |||
| 36 | Upstream-Status: Backport [f4ede81eed29e6140374177d1f2808248c5b5650] | ||
| 37 | --- | ||
| 38 | configure | 13 +- | ||
| 39 | hmp.c | 5 + | ||
| 40 | hw/tpm/Makefile.objs | 1 + | ||
| 41 | hw/tpm/tpm_emulator.c | 583 ++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 42 | hw/tpm/tpm_ioctl.h | 246 +++++++++++++++++++++ | ||
| 43 | qapi-schema.json | 18 +- | ||
| 44 | qemu-options.hx | 22 +- | ||
| 45 | 7 files changed, 882 insertions(+), 6 deletions(-) | ||
| 46 | create mode 100644 hw/tpm/tpm_emulator.c | ||
| 47 | create mode 100644 hw/tpm/tpm_ioctl.h | ||
| 48 | |||
| 49 | diff --git a/configure b/configure | ||
| 50 | index dd73cce62f..9a25537096 100755 | ||
| 51 | --- a/configure | ||
| 52 | +++ b/configure | ||
| 53 | @@ -3503,6 +3503,12 @@ else | ||
| 54 | tpm_passthrough=no | ||
| 55 | fi | ||
| 56 | |||
| 57 | +# TPM emulator is for all posix systems | ||
| 58 | +if test "$mingw32" != "yes"; then | ||
| 59 | + tpm_emulator=$tpm | ||
| 60 | +else | ||
| 61 | + tpm_emulator=no | ||
| 62 | +fi | ||
| 63 | ########################################## | ||
| 64 | # attr probe | ||
| 65 | |||
| 66 | @@ -5396,6 +5402,7 @@ echo "gcov enabled $gcov" | ||
| 67 | echo "TPM support $tpm" | ||
| 68 | echo "libssh2 support $libssh2" | ||
| 69 | echo "TPM passthrough $tpm_passthrough" | ||
| 70 | +echo "TPM emulator $tpm_emulator" | ||
| 71 | echo "QOM debugging $qom_cast_debug" | ||
| 72 | echo "Live block migration $live_block_migration" | ||
| 73 | echo "lzo support $lzo" | ||
| 74 | @@ -5983,12 +5990,16 @@ else | ||
| 75 | echo "HOST_USB=stub" >> $config_host_mak | ||
| 76 | fi | ||
| 77 | |||
| 78 | -# TPM passthrough support? | ||
| 79 | if test "$tpm" = "yes"; then | ||
| 80 | echo 'CONFIG_TPM=$(CONFIG_SOFTMMU)' >> $config_host_mak | ||
| 81 | + # TPM passthrough support? | ||
| 82 | if test "$tpm_passthrough" = "yes"; then | ||
| 83 | echo "CONFIG_TPM_PASSTHROUGH=y" >> $config_host_mak | ||
| 84 | fi | ||
| 85 | + # TPM emulator support? | ||
| 86 | + if test "$tpm_emulator" = "yes"; then | ||
| 87 | + echo "CONFIG_TPM_EMULATOR=y" >> $config_host_mak | ||
| 88 | + fi | ||
| 89 | fi | ||
| 90 | |||
| 91 | echo "TRACE_BACKENDS=$trace_backends" >> $config_host_mak | ||
| 92 | diff --git a/hmp.c b/hmp.c | ||
| 93 | index fd80dce758..820aa8f002 100644 | ||
| 94 | --- a/hmp.c | ||
| 95 | +++ b/hmp.c | ||
| 96 | @@ -995,6 +995,7 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) | ||
| 97 | Error *err = NULL; | ||
| 98 | unsigned int c = 0; | ||
| 99 | TPMPassthroughOptions *tpo; | ||
| 100 | + TPMEmulatorOptions *teo; | ||
| 101 | |||
| 102 | info_list = qmp_query_tpm(&err); | ||
| 103 | if (err) { | ||
| 104 | @@ -1024,6 +1025,10 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) | ||
| 105 | tpo->has_cancel_path ? ",cancel-path=" : "", | ||
| 106 | tpo->has_cancel_path ? tpo->cancel_path : ""); | ||
| 107 | break; | ||
| 108 | + case TPM_TYPE_OPTIONS_KIND_EMULATOR: | ||
| 109 | + teo = ti->options->u.emulator.data; | ||
| 110 | + monitor_printf(mon, ",chardev=%s", teo->chardev); | ||
| 111 | + break; | ||
| 112 | case TPM_TYPE_OPTIONS_KIND__MAX: | ||
| 113 | break; | ||
| 114 | } | ||
| 115 | diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs | ||
| 116 | index 64cecc3b67..41f0b7a590 100644 | ||
| 117 | --- a/hw/tpm/Makefile.objs | ||
| 118 | +++ b/hw/tpm/Makefile.objs | ||
| 119 | @@ -1,2 +1,3 @@ | ||
| 120 | common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o | ||
| 121 | common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o | ||
| 122 | +common-obj-$(CONFIG_TPM_EMULATOR) += tpm_emulator.o tpm_util.o | ||
| 123 | diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c | ||
| 124 | new file mode 100644 | ||
| 125 | index 0000000000..433bc4fa8a | ||
| 126 | --- /dev/null | ||
| 127 | +++ b/hw/tpm/tpm_emulator.c | ||
| 128 | @@ -0,0 +1,583 @@ | ||
| 129 | +/* | ||
| 130 | + * Emulator TPM driver | ||
| 131 | + * | ||
| 132 | + * Copyright (c) 2017 Intel Corporation | ||
| 133 | + * Author: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 134 | + * | ||
| 135 | + * Copyright (c) 2010 - 2013 IBM Corporation | ||
| 136 | + * Authors: | ||
| 137 | + * Stefan Berger <stefanb@us.ibm.com> | ||
| 138 | + * | ||
| 139 | + * Copyright (C) 2011 IAIK, Graz University of Technology | ||
| 140 | + * Author: Andreas Niederl | ||
| 141 | + * | ||
| 142 | + * This library is free software; you can redistribute it and/or | ||
| 143 | + * modify it under the terms of the GNU Lesser General Public | ||
| 144 | + * License as published by the Free Software Foundation; either | ||
| 145 | + * version 2 of the License, or (at your option) any later version. | ||
| 146 | + * | ||
| 147 | + * This library is distributed in the hope that it will be useful, | ||
| 148 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 149 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 150 | + * Lesser General Public License for more details. | ||
| 151 | + * | ||
| 152 | + * You should have received a copy of the GNU Lesser General Public | ||
| 153 | + * License along with this library; if not, see <http://www.gnu.org/licenses/> | ||
| 154 | + * | ||
| 155 | + */ | ||
| 156 | + | ||
| 157 | +#include "qemu/osdep.h" | ||
| 158 | +#include "qemu/error-report.h" | ||
| 159 | +#include "qemu/sockets.h" | ||
| 160 | +#include "io/channel-socket.h" | ||
| 161 | +#include "sysemu/tpm_backend.h" | ||
| 162 | +#include "tpm_int.h" | ||
| 163 | +#include "hw/hw.h" | ||
| 164 | +#include "hw/i386/pc.h" | ||
| 165 | +#include "tpm_util.h" | ||
| 166 | +#include "tpm_ioctl.h" | ||
| 167 | +#include "migration/blocker.h" | ||
| 168 | +#include "qapi/error.h" | ||
| 169 | +#include "qapi/clone-visitor.h" | ||
| 170 | +#include "chardev/char-fe.h" | ||
| 171 | + | ||
| 172 | +#include <fcntl.h> | ||
| 173 | +#include <sys/types.h> | ||
| 174 | +#include <sys/stat.h> | ||
| 175 | +#include <stdio.h> | ||
| 176 | + | ||
| 177 | +#define DEBUG_TPM 0 | ||
| 178 | + | ||
| 179 | +#define DPRINTF(fmt, ...) do { \ | ||
| 180 | + if (DEBUG_TPM) { \ | ||
| 181 | + fprintf(stderr, "tpm-emulator:"fmt"\n", ## __VA_ARGS__); \ | ||
| 182 | + } \ | ||
| 183 | +} while (0) | ||
| 184 | + | ||
| 185 | +#define TYPE_TPM_EMULATOR "tpm-emulator" | ||
| 186 | +#define TPM_EMULATOR(obj) \ | ||
| 187 | + OBJECT_CHECK(TPMEmulator, (obj), TYPE_TPM_EMULATOR) | ||
| 188 | + | ||
| 189 | +#define TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(S, cap) (((S)->caps & (cap)) == (cap)) | ||
| 190 | + | ||
| 191 | +static const TPMDriverOps tpm_emulator_driver; | ||
| 192 | + | ||
| 193 | +/* data structures */ | ||
| 194 | +typedef struct TPMEmulator { | ||
| 195 | + TPMBackend parent; | ||
| 196 | + | ||
| 197 | + TPMEmulatorOptions *options; | ||
| 198 | + CharBackend ctrl_chr; | ||
| 199 | + QIOChannel *data_ioc; | ||
| 200 | + TPMVersion tpm_version; | ||
| 201 | + ptm_cap caps; /* capabilities of the TPM */ | ||
| 202 | + uint8_t cur_locty_number; /* last set locality */ | ||
| 203 | + Error *migration_blocker; | ||
| 204 | +} TPMEmulator; | ||
| 205 | + | ||
| 206 | + | ||
| 207 | +static int tpm_emulator_ctrlcmd(CharBackend *dev, unsigned long cmd, void *msg, | ||
| 208 | + size_t msg_len_in, size_t msg_len_out) | ||
| 209 | +{ | ||
| 210 | + uint32_t cmd_no = cpu_to_be32(cmd); | ||
| 211 | + ssize_t n = sizeof(uint32_t) + msg_len_in; | ||
| 212 | + uint8_t *buf = NULL; | ||
| 213 | + | ||
| 214 | + buf = g_alloca(n); | ||
| 215 | + memcpy(buf, &cmd_no, sizeof(cmd_no)); | ||
| 216 | + memcpy(buf + sizeof(cmd_no), msg, msg_len_in); | ||
| 217 | + | ||
| 218 | + n = qemu_chr_fe_write_all(dev, buf, n); | ||
| 219 | + if (n <= 0) { | ||
| 220 | + return -1; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + if (msg_len_out != 0) { | ||
| 224 | + n = qemu_chr_fe_read_all(dev, msg, msg_len_out); | ||
| 225 | + if (n <= 0) { | ||
| 226 | + return -1; | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + return 0; | ||
| 231 | +} | ||
| 232 | + | ||
| 233 | +static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu, | ||
| 234 | + const uint8_t *in, uint32_t in_len, | ||
| 235 | + uint8_t *out, uint32_t out_len, | ||
| 236 | + bool *selftest_done, | ||
| 237 | + Error **err) | ||
| 238 | +{ | ||
| 239 | + ssize_t ret; | ||
| 240 | + bool is_selftest = false; | ||
| 241 | + const struct tpm_resp_hdr *hdr = NULL; | ||
| 242 | + | ||
| 243 | + if (selftest_done) { | ||
| 244 | + *selftest_done = false; | ||
| 245 | + is_selftest = tpm_util_is_selftest(in, in_len); | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + ret = qio_channel_write(tpm_emu->data_ioc, (char *)in, in_len, err); | ||
| 249 | + if (ret != in_len) { | ||
| 250 | + return -1; | ||
| 251 | + } | ||
| 252 | + | ||
| 253 | + ret = qio_channel_read(tpm_emu->data_ioc, (char *)out, out_len, err); | ||
| 254 | + if (ret <= 0 || ret < sizeof(*hdr)) { | ||
| 255 | + return -1; | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + hdr = (struct tpm_resp_hdr *)out; | ||
| 259 | + if (be32_to_cpu(hdr->len) != ret) { | ||
| 260 | + return -1; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + if (is_selftest) { | ||
| 264 | + *selftest_done = (be32_to_cpu(hdr->errcode) == 0); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + return 0; | ||
| 268 | +} | ||
| 269 | + | ||
| 270 | +static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number) | ||
| 271 | +{ | ||
| 272 | + ptm_loc loc; | ||
| 273 | + | ||
| 274 | + DPRINTF("%s : locality: 0x%x", __func__, locty_number); | ||
| 275 | + | ||
| 276 | + if (tpm_emu->cur_locty_number == locty_number) { | ||
| 277 | + return 0; | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + DPRINTF("setting locality : 0x%x", locty_number); | ||
| 281 | + loc.u.req.loc = locty_number; | ||
| 282 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SET_LOCALITY, &loc, | ||
| 283 | + sizeof(loc), sizeof(loc)) < 0) { | ||
| 284 | + error_report("tpm-emulator: could not set locality : %s", | ||
| 285 | + strerror(errno)); | ||
| 286 | + return -1; | ||
| 287 | + } | ||
| 288 | + | ||
| 289 | + loc.u.resp.tpm_result = be32_to_cpu(loc.u.resp.tpm_result); | ||
| 290 | + if (loc.u.resp.tpm_result != 0) { | ||
| 291 | + error_report("tpm-emulator: TPM result for set locality : 0x%x", | ||
| 292 | + loc.u.resp.tpm_result); | ||
| 293 | + return -1; | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + tpm_emu->cur_locty_number = locty_number; | ||
| 297 | + | ||
| 298 | + return 0; | ||
| 299 | +} | ||
| 300 | + | ||
| 301 | +static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd cmd) | ||
| 302 | +{ | ||
| 303 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 304 | + TPMLocality *locty = NULL; | ||
| 305 | + bool selftest_done = false; | ||
| 306 | + Error *err = NULL; | ||
| 307 | + | ||
| 308 | + DPRINTF("processing command type %d", cmd); | ||
| 309 | + | ||
| 310 | + switch (cmd) { | ||
| 311 | + case TPM_BACKEND_CMD_PROCESS_CMD: | ||
| 312 | + locty = tb->tpm_state->locty_data; | ||
| 313 | + if (tpm_emulator_set_locality(tpm_emu, | ||
| 314 | + tb->tpm_state->locty_number) < 0 || | ||
| 315 | + tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, | ||
| 316 | + locty->w_offset, locty->r_buffer.buffer, | ||
| 317 | + locty->r_buffer.size, &selftest_done, | ||
| 318 | + &err) < 0) { | ||
| 319 | + tpm_util_write_fatal_error_response(locty->r_buffer.buffer, | ||
| 320 | + locty->r_buffer.size); | ||
| 321 | + error_report_err(err); | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number, | ||
| 325 | + selftest_done); | ||
| 326 | + | ||
| 327 | + break; | ||
| 328 | + case TPM_BACKEND_CMD_INIT: | ||
| 329 | + case TPM_BACKEND_CMD_END: | ||
| 330 | + case TPM_BACKEND_CMD_TPM_RESET: | ||
| 331 | + /* nothing to do */ | ||
| 332 | + break; | ||
| 333 | + } | ||
| 334 | +} | ||
| 335 | + | ||
| 336 | +static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) | ||
| 337 | +{ | ||
| 338 | + DPRINTF("%s", __func__); | ||
| 339 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_GET_CAPABILITY, | ||
| 340 | + &tpm_emu->caps, 0, sizeof(tpm_emu->caps)) < 0) { | ||
| 341 | + error_report("tpm-emulator: probing failed : %s", strerror(errno)); | ||
| 342 | + return -1; | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + tpm_emu->caps = be64_to_cpu(tpm_emu->caps); | ||
| 346 | + | ||
| 347 | + DPRINTF("capbilities : 0x%lx", tpm_emu->caps); | ||
| 348 | + | ||
| 349 | + return 0; | ||
| 350 | +} | ||
| 351 | + | ||
| 352 | +static int tpm_emulator_check_caps(TPMEmulator *tpm_emu) | ||
| 353 | +{ | ||
| 354 | + ptm_cap caps = 0; | ||
| 355 | + const char *tpm = NULL; | ||
| 356 | + | ||
| 357 | + /* check for min. required capabilities */ | ||
| 358 | + switch (tpm_emu->tpm_version) { | ||
| 359 | + case TPM_VERSION_1_2: | ||
| 360 | + caps = PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLISHED | | ||
| 361 | + PTM_CAP_SET_LOCALITY | PTM_CAP_SET_DATAFD; | ||
| 362 | + tpm = "1.2"; | ||
| 363 | + break; | ||
| 364 | + case TPM_VERSION_2_0: | ||
| 365 | + caps = PTM_CAP_INIT | PTM_CAP_SHUTDOWN | PTM_CAP_GET_TPMESTABLISHED | | ||
| 366 | + PTM_CAP_SET_LOCALITY | PTM_CAP_RESET_TPMESTABLISHED | | ||
| 367 | + PTM_CAP_SET_DATAFD; | ||
| 368 | + tpm = "2"; | ||
| 369 | + break; | ||
| 370 | + case TPM_VERSION_UNSPEC: | ||
| 371 | + error_report("tpm-emulator: TPM version has not been set"); | ||
| 372 | + return -1; | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + if (!TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(tpm_emu, caps)) { | ||
| 376 | + error_report("tpm-emulator: TPM does not implement minimum set of " | ||
| 377 | + "required capabilities for TPM %s (0x%x)", tpm, (int)caps); | ||
| 378 | + return -1; | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + return 0; | ||
| 382 | +} | ||
| 383 | + | ||
| 384 | +static int tpm_emulator_startup_tpm(TPMBackend *tb) | ||
| 385 | +{ | ||
| 386 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 387 | + ptm_init init; | ||
| 388 | + ptm_res res; | ||
| 389 | + | ||
| 390 | + DPRINTF("%s", __func__); | ||
| 391 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_INIT, &init, sizeof(init), | ||
| 392 | + sizeof(init)) < 0) { | ||
| 393 | + error_report("tpm-emulator: could not send INIT: %s", | ||
| 394 | + strerror(errno)); | ||
| 395 | + goto err_exit; | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + res = be32_to_cpu(init.u.resp.tpm_result); | ||
| 399 | + if (res) { | ||
| 400 | + error_report("tpm-emulator: TPM result for CMD_INIT: 0x%x", res); | ||
| 401 | + goto err_exit; | ||
| 402 | + } | ||
| 403 | + return 0; | ||
| 404 | + | ||
| 405 | +err_exit: | ||
| 406 | + return -1; | ||
| 407 | +} | ||
| 408 | + | ||
| 409 | +static bool tpm_emulator_get_tpm_established_flag(TPMBackend *tb) | ||
| 410 | +{ | ||
| 411 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 412 | + ptm_est est; | ||
| 413 | + | ||
| 414 | + DPRINTF("%s", __func__); | ||
| 415 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_GET_TPMESTABLISHED, &est, | ||
| 416 | + 0, sizeof(est)) < 0) { | ||
| 417 | + error_report("tpm-emulator: Could not get the TPM established flag: %s", | ||
| 418 | + strerror(errno)); | ||
| 419 | + return false; | ||
| 420 | + } | ||
| 421 | + DPRINTF("established flag: %0x", est.u.resp.bit); | ||
| 422 | + | ||
| 423 | + return (est.u.resp.bit != 0); | ||
| 424 | +} | ||
| 425 | + | ||
| 426 | +static int tpm_emulator_reset_tpm_established_flag(TPMBackend *tb, | ||
| 427 | + uint8_t locty) | ||
| 428 | +{ | ||
| 429 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 430 | + ptm_reset_est reset_est; | ||
| 431 | + ptm_res res; | ||
| 432 | + | ||
| 433 | + /* only a TPM 2.0 will support this */ | ||
| 434 | + if (tpm_emu->tpm_version != TPM_VERSION_2_0) { | ||
| 435 | + return 0; | ||
| 436 | + } | ||
| 437 | + | ||
| 438 | + reset_est.u.req.loc = tpm_emu->cur_locty_number; | ||
| 439 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_RESET_TPMESTABLISHED, | ||
| 440 | + &reset_est, sizeof(reset_est), | ||
| 441 | + sizeof(reset_est)) < 0) { | ||
| 442 | + error_report("tpm-emulator: Could not reset the establishment bit: %s", | ||
| 443 | + strerror(errno)); | ||
| 444 | + return -1; | ||
| 445 | + } | ||
| 446 | + | ||
| 447 | + res = be32_to_cpu(reset_est.u.resp.tpm_result); | ||
| 448 | + if (res) { | ||
| 449 | + error_report("tpm-emulator: TPM result for rest establixhed flag: 0x%x", | ||
| 450 | + res); | ||
| 451 | + return -1; | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + return 0; | ||
| 455 | +} | ||
| 456 | + | ||
| 457 | +static void tpm_emulator_cancel_cmd(TPMBackend *tb) | ||
| 458 | +{ | ||
| 459 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 460 | + ptm_res res; | ||
| 461 | + | ||
| 462 | + if (!TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(tpm_emu, PTM_CAP_CANCEL_TPM_CMD)) { | ||
| 463 | + DPRINTF("Backend does not support CANCEL_TPM_CMD"); | ||
| 464 | + return; | ||
| 465 | + } | ||
| 466 | + | ||
| 467 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_CANCEL_TPM_CMD, &res, 0, | ||
| 468 | + sizeof(res)) < 0) { | ||
| 469 | + error_report("tpm-emulator: Could not cancel command: %s", | ||
| 470 | + strerror(errno)); | ||
| 471 | + } else if (res != 0) { | ||
| 472 | + error_report("tpm-emulator: Failed to cancel TPM: 0x%x", | ||
| 473 | + be32_to_cpu(res)); | ||
| 474 | + } | ||
| 475 | +} | ||
| 476 | + | ||
| 477 | +static TPMVersion tpm_emulator_get_tpm_version(TPMBackend *tb) | ||
| 478 | +{ | ||
| 479 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 480 | + | ||
| 481 | + return tpm_emu->tpm_version; | ||
| 482 | +} | ||
| 483 | + | ||
| 484 | +static int tpm_emulator_block_migration(TPMEmulator *tpm_emu) | ||
| 485 | +{ | ||
| 486 | + Error *err = NULL; | ||
| 487 | + | ||
| 488 | + error_setg(&tpm_emu->migration_blocker, | ||
| 489 | + "Migration disabled: TPM emulator not yet migratable"); | ||
| 490 | + migrate_add_blocker(tpm_emu->migration_blocker, &err); | ||
| 491 | + if (err) { | ||
| 492 | + error_report_err(err); | ||
| 493 | + error_free(tpm_emu->migration_blocker); | ||
| 494 | + tpm_emu->migration_blocker = NULL; | ||
| 495 | + | ||
| 496 | + return -1; | ||
| 497 | + } | ||
| 498 | + | ||
| 499 | + return 0; | ||
| 500 | +} | ||
| 501 | + | ||
| 502 | +static int tpm_emulator_prepare_data_fd(TPMEmulator *tpm_emu) | ||
| 503 | +{ | ||
| 504 | + ptm_res res; | ||
| 505 | + Error *err = NULL; | ||
| 506 | + int fds[2] = { -1, -1 }; | ||
| 507 | + | ||
| 508 | + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { | ||
| 509 | + error_report("tpm-emulator: Failed to create socketpair"); | ||
| 510 | + return -1; | ||
| 511 | + } | ||
| 512 | + | ||
| 513 | + qemu_chr_fe_set_msgfds(&tpm_emu->ctrl_chr, fds + 1, 1); | ||
| 514 | + | ||
| 515 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SET_DATAFD, &res, 0, | ||
| 516 | + sizeof(res)) || res != 0) { | ||
| 517 | + error_report("tpm-emulator: Failed to send CMD_SET_DATAFD: %s", | ||
| 518 | + strerror(errno)); | ||
| 519 | + goto err_exit; | ||
| 520 | + } | ||
| 521 | + | ||
| 522 | + tpm_emu->data_ioc = QIO_CHANNEL(qio_channel_socket_new_fd(fds[0], &err)); | ||
| 523 | + if (err) { | ||
| 524 | + error_prepend(&err, "tpm-emulator: Failed to create io channel: "); | ||
| 525 | + error_report_err(err); | ||
| 526 | + goto err_exit; | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + closesocket(fds[1]); | ||
| 530 | + | ||
| 531 | + return 0; | ||
| 532 | + | ||
| 533 | +err_exit: | ||
| 534 | + closesocket(fds[0]); | ||
| 535 | + closesocket(fds[1]); | ||
| 536 | + return -1; | ||
| 537 | +} | ||
| 538 | + | ||
| 539 | +static int tpm_emulator_handle_device_opts(TPMEmulator *tpm_emu, QemuOpts *opts) | ||
| 540 | +{ | ||
| 541 | + const char *value; | ||
| 542 | + | ||
| 543 | + value = qemu_opt_get(opts, "chardev"); | ||
| 544 | + if (value) { | ||
| 545 | + Error *err = NULL; | ||
| 546 | + Chardev *dev = qemu_chr_find(value); | ||
| 547 | + | ||
| 548 | + if (!dev) { | ||
| 549 | + error_report("tpm-emulator: tpm chardev '%s' not found.", value); | ||
| 550 | + goto err; | ||
| 551 | + } | ||
| 552 | + | ||
| 553 | + if (!qemu_chr_fe_init(&tpm_emu->ctrl_chr, dev, &err)) { | ||
| 554 | + error_prepend(&err, "tpm-emulator: No valid chardev found at '%s':", | ||
| 555 | + value); | ||
| 556 | + error_report_err(err); | ||
| 557 | + goto err; | ||
| 558 | + } | ||
| 559 | + | ||
| 560 | + tpm_emu->options->chardev = g_strdup(value); | ||
| 561 | + } | ||
| 562 | + | ||
| 563 | + if (tpm_emulator_prepare_data_fd(tpm_emu) < 0) { | ||
| 564 | + goto err; | ||
| 565 | + } | ||
| 566 | + | ||
| 567 | + /* FIXME: tpm_util_test_tpmdev() accepts only on socket fd, as it also used | ||
| 568 | + * by passthrough driver, which not yet using GIOChannel. | ||
| 569 | + */ | ||
| 570 | + if (tpm_util_test_tpmdev(QIO_CHANNEL_SOCKET(tpm_emu->data_ioc)->fd, | ||
| 571 | + &tpm_emu->tpm_version)) { | ||
| 572 | + error_report("'%s' is not emulating TPM device. Error: %s", | ||
| 573 | + tpm_emu->options->chardev, strerror(errno)); | ||
| 574 | + goto err; | ||
| 575 | + } | ||
| 576 | + | ||
| 577 | + DPRINTF("TPM Version %s", tpm_emu->tpm_version == TPM_VERSION_1_2 ? "1.2" : | ||
| 578 | + (tpm_emu->tpm_version == TPM_VERSION_2_0 ? "2.0" : "Unspecified")); | ||
| 579 | + | ||
| 580 | + if (tpm_emulator_probe_caps(tpm_emu) || | ||
| 581 | + tpm_emulator_check_caps(tpm_emu)) { | ||
| 582 | + goto err; | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + return tpm_emulator_block_migration(tpm_emu); | ||
| 586 | + | ||
| 587 | +err: | ||
| 588 | + DPRINTF("Startup error"); | ||
| 589 | + return -1; | ||
| 590 | +} | ||
| 591 | + | ||
| 592 | +static TPMBackend *tpm_emulator_create(QemuOpts *opts, const char *id) | ||
| 593 | +{ | ||
| 594 | + TPMBackend *tb = TPM_BACKEND(object_new(TYPE_TPM_EMULATOR)); | ||
| 595 | + | ||
| 596 | + tb->id = g_strdup(id); | ||
| 597 | + | ||
| 598 | + if (tpm_emulator_handle_device_opts(TPM_EMULATOR(tb), opts)) { | ||
| 599 | + goto err_exit; | ||
| 600 | + } | ||
| 601 | + | ||
| 602 | + return tb; | ||
| 603 | + | ||
| 604 | +err_exit: | ||
| 605 | + object_unref(OBJECT(tb)); | ||
| 606 | + | ||
| 607 | + return NULL; | ||
| 608 | +} | ||
| 609 | + | ||
| 610 | +static TpmTypeOptions *tpm_emulator_get_tpm_options(TPMBackend *tb) | ||
| 611 | +{ | ||
| 612 | + TPMEmulator *tpm_emu = TPM_EMULATOR(tb); | ||
| 613 | + TpmTypeOptions *options = g_new0(TpmTypeOptions, 1); | ||
| 614 | + | ||
| 615 | + options->type = TPM_TYPE_OPTIONS_KIND_EMULATOR; | ||
| 616 | + options->u.emulator.data = QAPI_CLONE(TPMEmulatorOptions, tpm_emu->options); | ||
| 617 | + | ||
| 618 | + return options; | ||
| 619 | +} | ||
| 620 | + | ||
| 621 | +static const QemuOptDesc tpm_emulator_cmdline_opts[] = { | ||
| 622 | + TPM_STANDARD_CMDLINE_OPTS, | ||
| 623 | + { | ||
| 624 | + .name = "chardev", | ||
| 625 | + .type = QEMU_OPT_STRING, | ||
| 626 | + .help = "Character device to use for out-of-band control messages", | ||
| 627 | + }, | ||
| 628 | + { /* end of list */ }, | ||
| 629 | +}; | ||
| 630 | + | ||
| 631 | +static const TPMDriverOps tpm_emulator_driver = { | ||
| 632 | + .type = TPM_TYPE_EMULATOR, | ||
| 633 | + .opts = tpm_emulator_cmdline_opts, | ||
| 634 | + .desc = "TPM emulator backend driver", | ||
| 635 | + | ||
| 636 | + .create = tpm_emulator_create, | ||
| 637 | + .startup_tpm = tpm_emulator_startup_tpm, | ||
| 638 | + .cancel_cmd = tpm_emulator_cancel_cmd, | ||
| 639 | + .get_tpm_established_flag = tpm_emulator_get_tpm_established_flag, | ||
| 640 | + .reset_tpm_established_flag = tpm_emulator_reset_tpm_established_flag, | ||
| 641 | + .get_tpm_version = tpm_emulator_get_tpm_version, | ||
| 642 | + .get_tpm_options = tpm_emulator_get_tpm_options, | ||
| 643 | +}; | ||
| 644 | + | ||
| 645 | +static void tpm_emulator_inst_init(Object *obj) | ||
| 646 | +{ | ||
| 647 | + TPMEmulator *tpm_emu = TPM_EMULATOR(obj); | ||
| 648 | + | ||
| 649 | + DPRINTF("%s", __func__); | ||
| 650 | + tpm_emu->options = g_new0(TPMEmulatorOptions, 1); | ||
| 651 | + tpm_emu->cur_locty_number = ~0; | ||
| 652 | +} | ||
| 653 | + | ||
| 654 | +/* | ||
| 655 | + * Gracefully shut down the external TPM | ||
| 656 | + */ | ||
| 657 | +static void tpm_emulator_shutdown(TPMEmulator *tpm_emu) | ||
| 658 | +{ | ||
| 659 | + ptm_res res; | ||
| 660 | + | ||
| 661 | + if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SHUTDOWN, &res, 0, | ||
| 662 | + sizeof(res)) < 0) { | ||
| 663 | + error_report("tpm-emulator: Could not cleanly shutdown the TPM: %s", | ||
| 664 | + strerror(errno)); | ||
| 665 | + } else if (res != 0) { | ||
| 666 | + error_report("tpm-emulator: TPM result for sutdown: 0x%x", | ||
| 667 | + be32_to_cpu(res)); | ||
| 668 | + } | ||
| 669 | +} | ||
| 670 | + | ||
| 671 | +static void tpm_emulator_inst_finalize(Object *obj) | ||
| 672 | +{ | ||
| 673 | + TPMEmulator *tpm_emu = TPM_EMULATOR(obj); | ||
| 674 | + | ||
| 675 | + tpm_emulator_shutdown(tpm_emu); | ||
| 676 | + | ||
| 677 | + object_unref(OBJECT(tpm_emu->data_ioc)); | ||
| 678 | + | ||
| 679 | + qemu_chr_fe_deinit(&tpm_emu->ctrl_chr, false); | ||
| 680 | + | ||
| 681 | + qapi_free_TPMEmulatorOptions(tpm_emu->options); | ||
| 682 | + | ||
| 683 | + if (tpm_emu->migration_blocker) { | ||
| 684 | + migrate_del_blocker(tpm_emu->migration_blocker); | ||
| 685 | + error_free(tpm_emu->migration_blocker); | ||
| 686 | + } | ||
| 687 | +} | ||
| 688 | + | ||
| 689 | +static void tpm_emulator_class_init(ObjectClass *klass, void *data) | ||
| 690 | +{ | ||
| 691 | + TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass); | ||
| 692 | + tbc->ops = &tpm_emulator_driver; | ||
| 693 | + tbc->handle_request = tpm_emulator_handle_request; | ||
| 694 | +} | ||
| 695 | + | ||
| 696 | +static const TypeInfo tpm_emulator_info = { | ||
| 697 | + .name = TYPE_TPM_EMULATOR, | ||
| 698 | + .parent = TYPE_TPM_BACKEND, | ||
| 699 | + .instance_size = sizeof(TPMEmulator), | ||
| 700 | + .class_init = tpm_emulator_class_init, | ||
| 701 | + .instance_init = tpm_emulator_inst_init, | ||
| 702 | + .instance_finalize = tpm_emulator_inst_finalize, | ||
| 703 | +}; | ||
| 704 | + | ||
| 705 | +static void tpm_emulator_register(void) | ||
| 706 | +{ | ||
| 707 | + type_register_static(&tpm_emulator_info); | ||
| 708 | + tpm_register_driver(&tpm_emulator_driver); | ||
| 709 | +} | ||
| 710 | + | ||
| 711 | +type_init(tpm_emulator_register) | ||
| 712 | diff --git a/hw/tpm/tpm_ioctl.h b/hw/tpm/tpm_ioctl.h | ||
| 713 | new file mode 100644 | ||
| 714 | index 0000000000..33564b11de | ||
| 715 | --- /dev/null | ||
| 716 | +++ b/hw/tpm/tpm_ioctl.h | ||
| 717 | @@ -0,0 +1,246 @@ | ||
| 718 | +/* | ||
| 719 | + * tpm_ioctl.h | ||
| 720 | + * | ||
| 721 | + * (c) Copyright IBM Corporation 2014, 2015. | ||
| 722 | + * | ||
| 723 | + * This file is licensed under the terms of the 3-clause BSD license | ||
| 724 | + */ | ||
| 725 | +#ifndef _TPM_IOCTL_H_ | ||
| 726 | +#define _TPM_IOCTL_H_ | ||
| 727 | + | ||
| 728 | +#include <stdint.h> | ||
| 729 | +#include <sys/uio.h> | ||
| 730 | +#include <sys/types.h> | ||
| 731 | +#include <sys/ioctl.h> | ||
| 732 | + | ||
| 733 | +/* | ||
| 734 | + * Every response from a command involving a TPM command execution must hold | ||
| 735 | + * the ptm_res as the first element. | ||
| 736 | + * ptm_res corresponds to the error code of a command executed by the TPM. | ||
| 737 | + */ | ||
| 738 | + | ||
| 739 | +typedef uint32_t ptm_res; | ||
| 740 | + | ||
| 741 | +/* PTM_GET_TPMESTABLISHED: get the establishment bit */ | ||
| 742 | +struct ptm_est { | ||
| 743 | + union { | ||
| 744 | + struct { | ||
| 745 | + ptm_res tpm_result; | ||
| 746 | + unsigned char bit; /* TPM established bit */ | ||
| 747 | + } resp; /* response */ | ||
| 748 | + } u; | ||
| 749 | +}; | ||
| 750 | + | ||
| 751 | +/* PTM_RESET_TPMESTABLISHED: reset establishment bit */ | ||
| 752 | +struct ptm_reset_est { | ||
| 753 | + union { | ||
| 754 | + struct { | ||
| 755 | + uint8_t loc; /* locality to use */ | ||
| 756 | + } req; /* request */ | ||
| 757 | + struct { | ||
| 758 | + ptm_res tpm_result; | ||
| 759 | + } resp; /* response */ | ||
| 760 | + } u; | ||
| 761 | +}; | ||
| 762 | + | ||
| 763 | +/* PTM_INIT */ | ||
| 764 | +struct ptm_init { | ||
| 765 | + union { | ||
| 766 | + struct { | ||
| 767 | + uint32_t init_flags; /* see definitions below */ | ||
| 768 | + } req; /* request */ | ||
| 769 | + struct { | ||
| 770 | + ptm_res tpm_result; | ||
| 771 | + } resp; /* response */ | ||
| 772 | + } u; | ||
| 773 | +}; | ||
| 774 | + | ||
| 775 | +/* above init_flags */ | ||
| 776 | +#define PTM_INIT_FLAG_DELETE_VOLATILE (1 << 0) | ||
| 777 | + /* delete volatile state file after reading it */ | ||
| 778 | + | ||
| 779 | +/* PTM_SET_LOCALITY */ | ||
| 780 | +struct ptm_loc { | ||
| 781 | + union { | ||
| 782 | + struct { | ||
| 783 | + uint8_t loc; /* locality to set */ | ||
| 784 | + } req; /* request */ | ||
| 785 | + struct { | ||
| 786 | + ptm_res tpm_result; | ||
| 787 | + } resp; /* response */ | ||
| 788 | + } u; | ||
| 789 | +}; | ||
| 790 | + | ||
| 791 | +/* PTM_HASH_DATA: hash given data */ | ||
| 792 | +struct ptm_hdata { | ||
| 793 | + union { | ||
| 794 | + struct { | ||
| 795 | + uint32_t length; | ||
| 796 | + uint8_t data[4096]; | ||
| 797 | + } req; /* request */ | ||
| 798 | + struct { | ||
| 799 | + ptm_res tpm_result; | ||
| 800 | + } resp; /* response */ | ||
| 801 | + } u; | ||
| 802 | +}; | ||
| 803 | + | ||
| 804 | +/* | ||
| 805 | + * size of the TPM state blob to transfer; x86_64 can handle 8k, | ||
| 806 | + * ppc64le only ~7k; keep the response below a 4k page size | ||
| 807 | + */ | ||
| 808 | +#define PTM_STATE_BLOB_SIZE (3 * 1024) | ||
| 809 | + | ||
| 810 | +/* | ||
| 811 | + * The following is the data structure to get state blobs from the TPM. | ||
| 812 | + * If the size of the state blob exceeds the PTM_STATE_BLOB_SIZE, multiple reads | ||
| 813 | + * with this ioctl and with adjusted offset are necessary. All bytes | ||
| 814 | + * must be transferred and the transfer is done once the last byte has been | ||
| 815 | + * returned. | ||
| 816 | + * It is possible to use the read() interface for reading the data; however, the | ||
| 817 | + * first bytes of the state blob will be part of the response to the ioctl(); a | ||
| 818 | + * subsequent read() is only necessary if the total length (totlength) exceeds | ||
| 819 | + * the number of received bytes. seek() is not supported. | ||
| 820 | + */ | ||
| 821 | +struct ptm_getstate { | ||
| 822 | + union { | ||
| 823 | + struct { | ||
| 824 | + uint32_t state_flags; /* may be: PTM_STATE_FLAG_DECRYPTED */ | ||
| 825 | + uint32_t type; /* which blob to pull */ | ||
| 826 | + uint32_t offset; /* offset from where to read */ | ||
| 827 | + } req; /* request */ | ||
| 828 | + struct { | ||
| 829 | + ptm_res tpm_result; | ||
| 830 | + uint32_t state_flags; /* may be: PTM_STATE_FLAG_ENCRYPTED */ | ||
| 831 | + uint32_t totlength; /* total length that will be transferred */ | ||
| 832 | + uint32_t length; /* number of bytes in following buffer */ | ||
| 833 | + uint8_t data[PTM_STATE_BLOB_SIZE]; | ||
| 834 | + } resp; /* response */ | ||
| 835 | + } u; | ||
| 836 | +}; | ||
| 837 | + | ||
| 838 | +/* TPM state blob types */ | ||
| 839 | +#define PTM_BLOB_TYPE_PERMANENT 1 | ||
| 840 | +#define PTM_BLOB_TYPE_VOLATILE 2 | ||
| 841 | +#define PTM_BLOB_TYPE_SAVESTATE 3 | ||
| 842 | + | ||
| 843 | +/* state_flags above : */ | ||
| 844 | +#define PTM_STATE_FLAG_DECRYPTED 1 /* on input: get decrypted state */ | ||
| 845 | +#define PTM_STATE_FLAG_ENCRYPTED 2 /* on output: state is encrypted */ | ||
| 846 | + | ||
| 847 | +/* | ||
| 848 | + * The following is the data structure to set state blobs in the TPM. | ||
| 849 | + * If the size of the state blob exceeds the PTM_STATE_BLOB_SIZE, multiple | ||
| 850 | + * 'writes' using this ioctl are necessary. The last packet is indicated | ||
| 851 | + * by the length being smaller than the PTM_STATE_BLOB_SIZE. | ||
| 852 | + * The very first packet may have a length indicator of '0' enabling | ||
| 853 | + * a write() with all the bytes from a buffer. If the write() interface | ||
| 854 | + * is used, a final ioctl with a non-full buffer must be made to indicate | ||
| 855 | + * that all data were transferred (a write with 0 bytes would not work). | ||
| 856 | + */ | ||
| 857 | +struct ptm_setstate { | ||
| 858 | + union { | ||
| 859 | + struct { | ||
| 860 | + uint32_t state_flags; /* may be PTM_STATE_FLAG_ENCRYPTED */ | ||
| 861 | + uint32_t type; /* which blob to set */ | ||
| 862 | + uint32_t length; /* length of the data; | ||
| 863 | + use 0 on the first packet to | ||
| 864 | + transfer using write() */ | ||
| 865 | + uint8_t data[PTM_STATE_BLOB_SIZE]; | ||
| 866 | + } req; /* request */ | ||
| 867 | + struct { | ||
| 868 | + ptm_res tpm_result; | ||
| 869 | + } resp; /* response */ | ||
| 870 | + } u; | ||
| 871 | +}; | ||
| 872 | + | ||
| 873 | +/* | ||
| 874 | + * PTM_GET_CONFIG: Data structure to get runtime configuration information | ||
| 875 | + * such as which keys are applied. | ||
| 876 | + */ | ||
| 877 | +struct ptm_getconfig { | ||
| 878 | + union { | ||
| 879 | + struct { | ||
| 880 | + ptm_res tpm_result; | ||
| 881 | + uint32_t flags; | ||
| 882 | + } resp; /* response */ | ||
| 883 | + } u; | ||
| 884 | +}; | ||
| 885 | + | ||
| 886 | +#define PTM_CONFIG_FLAG_FILE_KEY 0x1 | ||
| 887 | +#define PTM_CONFIG_FLAG_MIGRATION_KEY 0x2 | ||
| 888 | + | ||
| 889 | + | ||
| 890 | +typedef uint64_t ptm_cap; | ||
| 891 | +typedef struct ptm_est ptm_est; | ||
| 892 | +typedef struct ptm_reset_est ptm_reset_est; | ||
| 893 | +typedef struct ptm_loc ptm_loc; | ||
| 894 | +typedef struct ptm_hdata ptm_hdata; | ||
| 895 | +typedef struct ptm_init ptm_init; | ||
| 896 | +typedef struct ptm_getstate ptm_getstate; | ||
| 897 | +typedef struct ptm_setstate ptm_setstate; | ||
| 898 | +typedef struct ptm_getconfig ptm_getconfig; | ||
| 899 | + | ||
| 900 | +/* capability flags returned by PTM_GET_CAPABILITY */ | ||
| 901 | +#define PTM_CAP_INIT (1) | ||
| 902 | +#define PTM_CAP_SHUTDOWN (1 << 1) | ||
| 903 | +#define PTM_CAP_GET_TPMESTABLISHED (1 << 2) | ||
| 904 | +#define PTM_CAP_SET_LOCALITY (1 << 3) | ||
| 905 | +#define PTM_CAP_HASHING (1 << 4) | ||
| 906 | +#define PTM_CAP_CANCEL_TPM_CMD (1 << 5) | ||
| 907 | +#define PTM_CAP_STORE_VOLATILE (1 << 6) | ||
| 908 | +#define PTM_CAP_RESET_TPMESTABLISHED (1 << 7) | ||
| 909 | +#define PTM_CAP_GET_STATEBLOB (1 << 8) | ||
| 910 | +#define PTM_CAP_SET_STATEBLOB (1 << 9) | ||
| 911 | +#define PTM_CAP_STOP (1 << 10) | ||
| 912 | +#define PTM_CAP_GET_CONFIG (1 << 11) | ||
| 913 | +#define PTM_CAP_SET_DATAFD (1 << 12) | ||
| 914 | + | ||
| 915 | +enum { | ||
| 916 | + PTM_GET_CAPABILITY = _IOR('P', 0, ptm_cap), | ||
| 917 | + PTM_INIT = _IOWR('P', 1, ptm_init), | ||
| 918 | + PTM_SHUTDOWN = _IOR('P', 2, ptm_res), | ||
| 919 | + PTM_GET_TPMESTABLISHED = _IOR('P', 3, ptm_est), | ||
| 920 | + PTM_SET_LOCALITY = _IOWR('P', 4, ptm_loc), | ||
| 921 | + PTM_HASH_START = _IOR('P', 5, ptm_res), | ||
| 922 | + PTM_HASH_DATA = _IOWR('P', 6, ptm_hdata), | ||
| 923 | + PTM_HASH_END = _IOR('P', 7, ptm_res), | ||
| 924 | + PTM_CANCEL_TPM_CMD = _IOR('P', 8, ptm_res), | ||
| 925 | + PTM_STORE_VOLATILE = _IOR('P', 9, ptm_res), | ||
| 926 | + PTM_RESET_TPMESTABLISHED = _IOWR('P', 10, ptm_reset_est), | ||
| 927 | + PTM_GET_STATEBLOB = _IOWR('P', 11, ptm_getstate), | ||
| 928 | + PTM_SET_STATEBLOB = _IOWR('P', 12, ptm_setstate), | ||
| 929 | + PTM_STOP = _IOR('P', 13, ptm_res), | ||
| 930 | + PTM_GET_CONFIG = _IOR('P', 14, ptm_getconfig), | ||
| 931 | + PTM_SET_DATAFD = _IOR('P', 15, ptm_res), | ||
| 932 | +}; | ||
| 933 | + | ||
| 934 | +/* | ||
| 935 | + * Commands used by the non-CUSE TPMs | ||
| 936 | + * | ||
| 937 | + * All messages container big-endian data. | ||
| 938 | + * | ||
| 939 | + * The return messages only contain the 'resp' part of the unions | ||
| 940 | + * in the data structures above. Besides that the limits in the | ||
| 941 | + * buffers above (ptm_hdata:u.req.data and ptm_get_state:u.resp.data | ||
| 942 | + * and ptm_set_state:u.req.data) are 0xffffffff. | ||
| 943 | + */ | ||
| 944 | +enum { | ||
| 945 | + CMD_GET_CAPABILITY = 1, | ||
| 946 | + CMD_INIT, | ||
| 947 | + CMD_SHUTDOWN, | ||
| 948 | + CMD_GET_TPMESTABLISHED, | ||
| 949 | + CMD_SET_LOCALITY, | ||
| 950 | + CMD_HASH_START, | ||
| 951 | + CMD_HASH_DATA, | ||
| 952 | + CMD_HASH_END, | ||
| 953 | + CMD_CANCEL_TPM_CMD, | ||
| 954 | + CMD_STORE_VOLATILE, | ||
| 955 | + CMD_RESET_TPMESTABLISHED, | ||
| 956 | + CMD_GET_STATEBLOB, | ||
| 957 | + CMD_SET_STATEBLOB, | ||
| 958 | + CMD_STOP, | ||
| 959 | + CMD_GET_CONFIG, | ||
| 960 | + CMD_SET_DATAFD | ||
| 961 | +}; | ||
| 962 | + | ||
| 963 | +#endif /* _TPM_IOCTL_H */ | ||
| 964 | diff --git a/qapi-schema.json b/qapi-schema.json | ||
| 965 | index 802ea53d00..78a00bc868 100644 | ||
| 966 | --- a/qapi-schema.json | ||
| 967 | +++ b/qapi-schema.json | ||
| 968 | @@ -5314,10 +5314,12 @@ | ||
| 969 | # An enumeration of TPM types | ||
| 970 | # | ||
| 971 | # @passthrough: TPM passthrough type | ||
| 972 | +# @emulator: Software Emulator TPM type | ||
| 973 | +# Since: 2.11 | ||
| 974 | # | ||
| 975 | # Since: 1.5 | ||
| 976 | ## | ||
| 977 | -{ 'enum': 'TpmType', 'data': [ 'passthrough' ] } | ||
| 978 | +{ 'enum': 'TpmType', 'data': [ 'passthrough', 'emulator' ] } | ||
| 979 | |||
| 980 | ## | ||
| 981 | # @query-tpm-types: | ||
| 982 | @@ -5352,6 +5354,17 @@ | ||
| 983 | '*cancel-path' : 'str'} } | ||
| 984 | |||
| 985 | ## | ||
| 986 | +# @TPMEmulatorOptions: | ||
| 987 | +# | ||
| 988 | +# Information about the TPM emulator type | ||
| 989 | +# | ||
| 990 | +# @chardev: Name of a unix socket chardev | ||
| 991 | +# | ||
| 992 | +# Since: 2.11 | ||
| 993 | +## | ||
| 994 | +{ 'struct': 'TPMEmulatorOptions', 'data': { 'chardev' : 'str' } } | ||
| 995 | + | ||
| 996 | +## | ||
| 997 | # @TpmTypeOptions: | ||
| 998 | # | ||
| 999 | # A union referencing different TPM backend types' configuration options | ||
| 1000 | @@ -5361,7 +5374,8 @@ | ||
| 1001 | # Since: 1.5 | ||
| 1002 | ## | ||
| 1003 | { 'union': 'TpmTypeOptions', | ||
| 1004 | - 'data': { 'passthrough' : 'TPMPassthroughOptions' } } | ||
| 1005 | + 'data': { 'passthrough' : 'TPMPassthroughOptions', | ||
| 1006 | + 'emulator': 'TPMEmulatorOptions'} } | ||
| 1007 | |||
| 1008 | ## | ||
| 1009 | # @TPMInfo: | ||
| 1010 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
| 1011 | index 9f6e2adfff..60eb193c23 100644 | ||
| 1012 | --- a/qemu-options.hx | ||
| 1013 | +++ b/qemu-options.hx | ||
| 1014 | @@ -3121,7 +3121,9 @@ DEF("tpmdev", HAS_ARG, QEMU_OPTION_tpmdev, \ | ||
| 1015 | "-tpmdev passthrough,id=id[,path=path][,cancel-path=path]\n" | ||
| 1016 | " use path to provide path to a character device; default is /dev/tpm0\n" | ||
| 1017 | " use cancel-path to provide path to TPM's cancel sysfs entry; if\n" | ||
| 1018 | - " not provided it will be searched for in /sys/class/misc/tpm?/device\n", | ||
| 1019 | + " not provided it will be searched for in /sys/class/misc/tpm?/device\n" | ||
| 1020 | + "-tpmdev emulator,id=id,chardev=dev\n" | ||
| 1021 | + " configure the TPM device using chardev backend\n", | ||
| 1022 | QEMU_ARCH_ALL) | ||
| 1023 | STEXI | ||
| 1024 | |||
| 1025 | @@ -3130,8 +3132,8 @@ The general form of a TPM device option is: | ||
| 1026 | |||
| 1027 | @item -tpmdev @var{backend} ,id=@var{id} [,@var{options}] | ||
| 1028 | @findex -tpmdev | ||
| 1029 | -Backend type must be: | ||
| 1030 | -@option{passthrough}. | ||
| 1031 | +Backend type must be either one of the following: | ||
| 1032 | +@option{passthrough}, @option{emulator}. | ||
| 1033 | |||
| 1034 | The specific backend type will determine the applicable options. | ||
| 1035 | The @code{-tpmdev} option creates the TPM backend and requires a | ||
| 1036 | @@ -3181,6 +3183,20 @@ To create a passthrough TPM use the following two options: | ||
| 1037 | Note that the @code{-tpmdev} id is @code{tpm0} and is referenced by | ||
| 1038 | @code{tpmdev=tpm0} in the device option. | ||
| 1039 | |||
| 1040 | +@item -tpmdev emulator, id=@var{id}, chardev=@var{dev} | ||
| 1041 | + | ||
| 1042 | +(Linux-host only) Enable access to a TPM emulator using Unix domain socket based | ||
| 1043 | +chardev backend. | ||
| 1044 | + | ||
| 1045 | +@option{chardev} specifies the unique ID of a character device backend that provides connection to the software TPM server. | ||
| 1046 | + | ||
| 1047 | +To create a TPM emulator backend device with chardev socket backend: | ||
| 1048 | +@example | ||
| 1049 | + | ||
| 1050 | +-chardev socket,id=chrtpm,path=/tmp/swtpm-sock -tpmdev emulator,id=tpm0,chardev=chrtpm -device tpm-tis,tpmdev=tpm0 | ||
| 1051 | + | ||
| 1052 | +@end example | ||
| 1053 | + | ||
| 1054 | @end table | ||
| 1055 | |||
| 1056 | ETEXI | ||
| 1057 | -- | ||
| 1058 | 2.11.0 | ||
| 1059 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0011-tpm-Move-tpm_cleanup-to-right-place.patch b/meta/recipes-devtools/qemu/qemu/0011-tpm-Move-tpm_cleanup-to-right-place.patch new file mode 100644 index 0000000000..f4998e1681 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0011-tpm-Move-tpm_cleanup-to-right-place.patch | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | From 22429d175911af2e57617a30e0ac097af74f2791 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 3 | Date: Fri, 29 Sep 2017 12:57:33 +0300 | ||
| 4 | Subject: [PATCH 11/12] tpm: Move tpm_cleanup() to right place | ||
| 5 | |||
| 6 | As Emulator TPM backend uses chardev, tpm cleanup should happen before chardev | ||
| 7 | similar to other vhost-users. | ||
| 8 | |||
| 9 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> | ||
| 10 | |||
| 11 | Upstream-Status: Backport [c37cacabf2285b0731b44c1f667781fdd4f2b658] | ||
| 12 | --- | ||
| 13 | tpm.c | 1 - | ||
| 14 | vl.c | 1 + | ||
| 15 | 2 files changed, 1 insertion(+), 1 deletion(-) | ||
| 16 | |||
| 17 | diff --git a/tpm.c b/tpm.c | ||
| 18 | index cac400ef3e..4a9d3d739e 100644 | ||
| 19 | --- a/tpm.c | ||
| 20 | +++ b/tpm.c | ||
| 21 | @@ -173,7 +173,6 @@ int tpm_init(void) | ||
| 22 | return -1; | ||
| 23 | } | ||
| 24 | |||
| 25 | - atexit(tpm_cleanup); | ||
| 26 | return 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | diff --git a/vl.c b/vl.c | ||
| 30 | index 8e247cc2a2..5df0b7f205 100644 | ||
| 31 | --- a/vl.c | ||
| 32 | +++ b/vl.c | ||
| 33 | @@ -4797,6 +4797,7 @@ int main(int argc, char **argv, char **envp) | ||
| 34 | res_free(); | ||
| 35 | |||
| 36 | /* vhost-user must be cleaned up before chardevs. */ | ||
| 37 | + tpm_cleanup(); | ||
| 38 | net_cleanup(); | ||
| 39 | audio_cleanup(); | ||
| 40 | monitor_cleanup(); | ||
| 41 | -- | ||
| 42 | 2.11.0 | ||
| 43 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/0012-tpm-Use-EMSGSIZE-instead-of-EBADMSG-to-compile-on-Op.patch b/meta/recipes-devtools/qemu/qemu/0012-tpm-Use-EMSGSIZE-instead-of-EBADMSG-to-compile-on-Op.patch new file mode 100644 index 0000000000..430fe1b1c4 --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/0012-tpm-Use-EMSGSIZE-instead-of-EBADMSG-to-compile-on-Op.patch | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | From c559d599c6880caf7aa0f0a60c6c023584e1b8ad Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 3 | Date: Wed, 11 Oct 2017 08:52:43 -0400 | ||
| 4 | Subject: [PATCH 12/12] tpm: Use EMSGSIZE instead of EBADMSG to compile on | ||
| 5 | OpenBSD | ||
| 6 | MIME-Version: 1.0 | ||
| 7 | Content-Type: text/plain; charset=UTF-8 | ||
| 8 | Content-Transfer-Encoding: 8bit | ||
| 9 | |||
| 10 | EBADMSG was only added to OpenBSD very recently. To make QEMU compilable | ||
| 11 | on older OpenBSD versions use EMSGSIZE instead when a mismatch between | ||
| 12 | number of received bytes and message size indicated in the header was | ||
| 13 | found. | ||
| 14 | |||
| 15 | Return -EMSGSIZE and convert all other errnos in the same functions to | ||
| 16 | return the negative errno. | ||
| 17 | |||
| 18 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | ||
| 19 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
| 20 | |||
| 21 | Upstream-Status: Backport [98979cdca44ba0e21055ee7736694aa5ebb54347] | ||
| 22 | --- | ||
| 23 | hw/tpm/tpm_util.c | 10 +++++----- | ||
| 24 | 1 file changed, 5 insertions(+), 5 deletions(-) | ||
| 25 | |||
| 26 | diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c | ||
| 27 | index fb929f6e92..73d77965fd 100644 | ||
| 28 | --- a/hw/tpm/tpm_util.c | ||
| 29 | +++ b/hw/tpm/tpm_util.c | ||
| 30 | @@ -68,10 +68,10 @@ static int tpm_util_test(int fd, | ||
| 31 | |||
| 32 | n = write(fd, request, requestlen); | ||
| 33 | if (n < 0) { | ||
| 34 | - return errno; | ||
| 35 | + return -errno; | ||
| 36 | } | ||
| 37 | if (n != requestlen) { | ||
| 38 | - return EFAULT; | ||
| 39 | + return -EFAULT; | ||
| 40 | } | ||
| 41 | |||
| 42 | FD_ZERO(&readfds); | ||
| 43 | @@ -80,18 +80,18 @@ static int tpm_util_test(int fd, | ||
| 44 | /* wait for a second */ | ||
| 45 | n = select(fd + 1, &readfds, NULL, NULL, &tv); | ||
| 46 | if (n != 1) { | ||
| 47 | - return errno; | ||
| 48 | + return -errno; | ||
| 49 | } | ||
| 50 | |||
| 51 | n = read(fd, &buf, sizeof(buf)); | ||
| 52 | if (n < sizeof(struct tpm_resp_hdr)) { | ||
| 53 | - return EFAULT; | ||
| 54 | + return -EFAULT; | ||
| 55 | } | ||
| 56 | |||
| 57 | resp = (struct tpm_resp_hdr *)buf; | ||
| 58 | /* check the header */ | ||
| 59 | if (be32_to_cpu(resp->len) != n) { | ||
| 60 | - return EBADMSG; | ||
| 61 | + return -EMSGSIZE; | ||
| 62 | } | ||
| 63 | |||
| 64 | *return_tag = be16_to_cpu(resp->tag); | ||
| 65 | -- | ||
| 66 | 2.11.0 | ||
| 67 | |||
diff --git a/meta/recipes-devtools/qemu/qemu/chardev-connect-socket-to-a-spawned-command.patch b/meta/recipes-devtools/qemu/qemu/chardev-connect-socket-to-a-spawned-command.patch new file mode 100644 index 0000000000..49d4af2e5e --- /dev/null +++ b/meta/recipes-devtools/qemu/qemu/chardev-connect-socket-to-a-spawned-command.patch | |||
| @@ -0,0 +1,227 @@ | |||
| 1 | From aa3aef4cf5f4dd98f9133df085e825ff5da7dcbd Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Patrick Ohly <patrick.ohly@intel.com> | ||
| 3 | Date: Fri, 27 Oct 2017 15:23:35 +0200 | ||
| 4 | Subject: [PATCH] chardev: connect socket to a spawned command | ||
| 5 | |||
| 6 | The command is started in a shell (sh -c) with stdin connect to QEMU | ||
| 7 | via a Unix domain stream socket. QEMU then exchanges data via its own | ||
| 8 | end of the socket, just like it normally does. | ||
| 9 | |||
| 10 | "-chardev socket" supports some ways of connecting via protocols like | ||
| 11 | telnet, but that is only a subset of the functionality supported by | ||
| 12 | tools socat. To use socat instead, for example to connect via a socks | ||
| 13 | proxy, use: | ||
| 14 | |||
| 15 | -chardev 'socket,id=socat,cmd=exec socat FD:0 SOCKS4A:socks-proxy.localdomain:example.com:9999,,socksuser=nobody' \ | ||
| 16 | -device usb-serial,chardev=socat | ||
| 17 | |||
| 18 | Beware that commas in the command must be escaped as double commas. | ||
| 19 | |||
| 20 | Or interactively in the console: | ||
| 21 | (qemu) chardev-add socket,id=cat,cmd=cat | ||
| 22 | (qemu) device_add usb-serial,chardev=cat | ||
| 23 | ^ac | ||
| 24 | # cat >/dev/ttyUSB0 | ||
| 25 | hello | ||
| 26 | hello | ||
| 27 | |||
| 28 | Another usage is starting swtpm from inside QEMU. swtpm will | ||
| 29 | automatically shut down once it looses the connection to the parent | ||
| 30 | QEMU, so there is no risk of lingering processes: | ||
| 31 | |||
| 32 | -chardev 'socket,id=chrtpm0,cmd=exec swtpm socket --terminate --ctrl type=unixio,,clientfd=0 --tpmstate dir=... --log file=swtpm.log' \ | ||
| 33 | -tpmdev emulator,id=tpm0,chardev=chrtpm0 \ | ||
| 34 | -device tpm-tis,tpmdev=tpm0 | ||
| 35 | |||
| 36 | The patch was discussed upstream, but QEMU developers believe that the | ||
| 37 | code calling QEMU should be responsible for managing additional | ||
| 38 | processes. In OE-core, that would imply enhancing runqemu and | ||
| 39 | oeqa. This patch is a simpler solution. | ||
| 40 | |||
| 41 | Because it is not going upstream, the patch was written so that it is | ||
| 42 | as simple as possible. | ||
| 43 | |||
| 44 | Upstream-Status: Inappropriate [embedded specific] | ||
| 45 | |||
| 46 | Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> | ||
| 47 | |||
| 48 | --- | ||
| 49 | chardev/char-socket.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++--- | ||
| 50 | chardev/char.c | 3 ++ | ||
| 51 | qapi-schema.json | 5 +++ | ||
| 52 | 3 files changed, 90 insertions(+), 4 deletions(-) | ||
| 53 | |||
| 54 | diff --git a/chardev/char-socket.c b/chardev/char-socket.c | ||
| 55 | index 1ae730a4..c366a02a 100644 | ||
| 56 | --- a/chardev/char-socket.c | ||
| 57 | +++ b/chardev/char-socket.c | ||
| 58 | @@ -854,6 +854,66 @@ static gboolean socket_reconnect_timeout(gpointer opaque) | ||
| 59 | return false; | ||
| 60 | } | ||
| 61 | |||
| 62 | +static void chardev_open_socket_cmd(Chardev *chr, | ||
| 63 | + const char *cmd, | ||
| 64 | + Error **errp) | ||
| 65 | +{ | ||
| 66 | + int fds[2] = { -1, -1 }; | ||
| 67 | + QIOChannelSocket *sioc = NULL; | ||
| 68 | + pid_t pid = -1; | ||
| 69 | + const char *argv[] = { "/bin/sh", "-c", cmd, NULL }; | ||
| 70 | + | ||
| 71 | + /* | ||
| 72 | + * We need a Unix domain socket for commands like swtpm and a single | ||
| 73 | + * connection, therefore we cannot use qio_channel_command_new_spawn() | ||
| 74 | + * without patching it first. Duplicating the functionality is easier. | ||
| 75 | + */ | ||
| 76 | + if (socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds)) { | ||
| 77 | + error_setg_errno(errp, errno, "Error creating socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC)"); | ||
| 78 | + goto error; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + pid = qemu_fork(errp); | ||
| 82 | + if (pid < 0) { | ||
| 83 | + goto error; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + if (!pid) { | ||
| 87 | + /* child */ | ||
| 88 | + dup2(fds[1], STDIN_FILENO); | ||
| 89 | + execv(argv[0], (char * const *)argv); | ||
| 90 | + _exit(1); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /* | ||
| 94 | + * Hand over our end of the socket pair to the qio channel. | ||
| 95 | + * | ||
| 96 | + * We don't reap the child because it is expected to keep | ||
| 97 | + * running. We also don't support the "reconnect" option for the | ||
| 98 | + * same reason. | ||
| 99 | + */ | ||
| 100 | + sioc = qio_channel_socket_new_fd(fds[0], errp); | ||
| 101 | + if (!sioc) { | ||
| 102 | + goto error; | ||
| 103 | + } | ||
| 104 | + fds[0] = -1; | ||
| 105 | + | ||
| 106 | + g_free(chr->filename); | ||
| 107 | + chr->filename = g_strdup_printf("cmd:%s", cmd); | ||
| 108 | + tcp_chr_new_client(chr, sioc); | ||
| 109 | + | ||
| 110 | + error: | ||
| 111 | + if (fds[0] >= 0) { | ||
| 112 | + close(fds[0]); | ||
| 113 | + } | ||
| 114 | + if (fds[1] >= 0) { | ||
| 115 | + close(fds[1]); | ||
| 116 | + } | ||
| 117 | + if (sioc) { | ||
| 118 | + object_unref(OBJECT(sioc)); | ||
| 119 | + } | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | static void qmp_chardev_open_socket(Chardev *chr, | ||
| 123 | ChardevBackend *backend, | ||
| 124 | bool *be_opened, | ||
| 125 | @@ -861,6 +921,7 @@ static void qmp_chardev_open_socket(Chardev *chr, | ||
| 126 | { | ||
| 127 | SocketChardev *s = SOCKET_CHARDEV(chr); | ||
| 128 | ChardevSocket *sock = backend->u.socket.data; | ||
| 129 | + const char *cmd = sock->cmd; | ||
| 130 | bool do_nodelay = sock->has_nodelay ? sock->nodelay : false; | ||
| 131 | bool is_listen = sock->has_server ? sock->server : true; | ||
| 132 | bool is_telnet = sock->has_telnet ? sock->telnet : false; | ||
| 133 | @@ -928,7 +989,12 @@ static void qmp_chardev_open_socket(Chardev *chr, | ||
| 134 | s->reconnect_time = reconnect; | ||
| 135 | } | ||
| 136 | |||
| 137 | - if (s->reconnect_time) { | ||
| 138 | + if (cmd) { | ||
| 139 | + chardev_open_socket_cmd(chr, cmd, errp); | ||
| 140 | + | ||
| 141 | + /* everything ready (or failed permanently) before we return */ | ||
| 142 | + *be_opened = true; | ||
| 143 | + } else if (s->reconnect_time) { | ||
| 144 | sioc = qio_channel_socket_new(); | ||
| 145 | tcp_chr_set_client_ioc_name(chr, sioc); | ||
| 146 | qio_channel_socket_connect_async(sioc, s->addr, | ||
| 147 | @@ -987,11 +1053,22 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, | ||
| 148 | const char *host = qemu_opt_get(opts, "host"); | ||
| 149 | const char *port = qemu_opt_get(opts, "port"); | ||
| 150 | const char *tls_creds = qemu_opt_get(opts, "tls-creds"); | ||
| 151 | + const char *cmd = qemu_opt_get(opts, "cmd"); | ||
| 152 | SocketAddressLegacy *addr; | ||
| 153 | ChardevSocket *sock; | ||
| 154 | |||
| 155 | backend->type = CHARDEV_BACKEND_KIND_SOCKET; | ||
| 156 | - if (!path) { | ||
| 157 | + if (cmd) { | ||
| 158 | + /* | ||
| 159 | + * Here we have to ensure that no options are set which are incompatible with | ||
| 160 | + * spawning a command, otherwise unmodified code that doesn't know about | ||
| 161 | + * command spawning (like socket_reconnect_timeout()) might get called. | ||
| 162 | + */ | ||
| 163 | + if (path || is_listen || is_telnet || is_tn3270 || reconnect || host || port || tls_creds) { | ||
| 164 | + error_setg(errp, "chardev: socket: cmd does not support any additional options"); | ||
| 165 | + return; | ||
| 166 | + } | ||
| 167 | + } else if (!path) { | ||
| 168 | if (!host) { | ||
| 169 | error_setg(errp, "chardev: socket: no host given"); | ||
| 170 | return; | ||
| 171 | @@ -1023,13 +1100,14 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, | ||
| 172 | sock->has_reconnect = true; | ||
| 173 | sock->reconnect = reconnect; | ||
| 174 | sock->tls_creds = g_strdup(tls_creds); | ||
| 175 | + sock->cmd = g_strdup(cmd); | ||
| 176 | |||
| 177 | addr = g_new0(SocketAddressLegacy, 1); | ||
| 178 | - if (path) { | ||
| 179 | + if (path || cmd) { | ||
| 180 | UnixSocketAddress *q_unix; | ||
| 181 | addr->type = SOCKET_ADDRESS_LEGACY_KIND_UNIX; | ||
| 182 | q_unix = addr->u.q_unix.data = g_new0(UnixSocketAddress, 1); | ||
| 183 | - q_unix->path = g_strdup(path); | ||
| 184 | + q_unix->path = cmd ? g_strdup_printf("cmd:%s", cmd) : g_strdup(path); | ||
| 185 | } else { | ||
| 186 | addr->type = SOCKET_ADDRESS_LEGACY_KIND_INET; | ||
| 187 | addr->u.inet.data = g_new(InetSocketAddress, 1); | ||
| 188 | diff --git a/chardev/char.c b/chardev/char.c | ||
| 189 | index 5d283b90..ccb329d4 100644 | ||
| 190 | --- a/chardev/char.c | ||
| 191 | +++ b/chardev/char.c | ||
| 192 | @@ -782,6 +782,9 @@ QemuOptsList qemu_chardev_opts = { | ||
| 193 | .name = "path", | ||
| 194 | .type = QEMU_OPT_STRING, | ||
| 195 | },{ | ||
| 196 | + .name = "cmd", | ||
| 197 | + .type = QEMU_OPT_STRING, | ||
| 198 | + },{ | ||
| 199 | .name = "host", | ||
| 200 | .type = QEMU_OPT_STRING, | ||
| 201 | },{ | ||
| 202 | diff --git a/qapi-schema.json b/qapi-schema.json | ||
| 203 | index 78a00bc8..790b026d 100644 | ||
| 204 | --- a/qapi-schema.json | ||
| 205 | +++ b/qapi-schema.json | ||
| 206 | @@ -5004,6 +5004,10 @@ | ||
| 207 | # | ||
| 208 | # @addr: socket address to listen on (server=true) | ||
| 209 | # or connect to (server=false) | ||
| 210 | +# @cmd: command to run via "sh -c" with stdin as one end of | ||
| 211 | +# a AF_UNIX SOCK_DSTREAM socket pair. The other end | ||
| 212 | +# is used by the chardev. Either an addr or a cmd can | ||
| 213 | +# be specified, but not both. | ||
| 214 | # @tls-creds: the ID of the TLS credentials object (since 2.6) | ||
| 215 | # @server: create server socket (default: true) | ||
| 216 | # @wait: wait for incoming connection on server | ||
| 217 | @@ -5021,6 +5025,7 @@ | ||
| 218 | # Since: 1.4 | ||
| 219 | ## | ||
| 220 | { 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddressLegacy', | ||
| 221 | + '*cmd' : 'str', | ||
| 222 | '*tls-creds' : 'str', | ||
| 223 | '*server' : 'bool', | ||
| 224 | '*wait' : 'bool', | ||
| 225 | -- | ||
| 226 | 2.11.0 | ||
| 227 | |||
diff --git a/meta/recipes-devtools/qemu/qemu_2.10.1.bb b/meta/recipes-devtools/qemu/qemu_2.10.1.bb index 5ac221c9ed..71cc74ebc7 100644 --- a/meta/recipes-devtools/qemu/qemu_2.10.1.bb +++ b/meta/recipes-devtools/qemu/qemu_2.10.1.bb | |||
| @@ -19,10 +19,19 @@ SRC_URI = "http://wiki.qemu-project.org/download/${BP}.tar.bz2 \ | |||
| 19 | file://pathlimit.patch \ | 19 | file://pathlimit.patch \ |
| 20 | file://qemu-2.5.0-cflags.patch \ | 20 | file://qemu-2.5.0-cflags.patch \ |
| 21 | file://glibc-2.25.patch \ | 21 | file://glibc-2.25.patch \ |
| 22 | file://0001-Provide-support-for-the-CUSE-TPM.patch \ | 22 | file://0001-tpm-Clean-up-driver-registration-lookup.patch \ |
| 23 | file://0002-Introduce-condition-to-notify-waiters-of-completed-c.patch \ | 23 | file://0002-tpm-Clean-up-model-registration-lookup.patch \ |
| 24 | file://0003-Introduce-condition-in-TPM-backend-for-notification.patch \ | 24 | file://0003-tpm-backend-Remove-unneeded-member-variable-from-bac.patch \ |
| 25 | file://0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch \ | 25 | file://0004-tpm-backend-Move-thread-handling-inside-TPMBackend.patch \ |
| 26 | file://0005-tpm-backend-Initialize-and-free-data-members-in-it-s.patch \ | ||
| 27 | file://0006-tpm-backend-Made-few-interface-methods-optional.patch \ | ||
| 28 | file://0007-tpm-backend-Add-new-api-to-read-backend-TpmInfo.patch \ | ||
| 29 | file://0008-tpm-backend-Move-realloc_buffer-implementation-to-tp.patch \ | ||
| 30 | file://0009-tpm-passthrough-move-reusable-code-to-utils.patch \ | ||
| 31 | file://0010-tpm-Added-support-for-TPM-emulator.patch \ | ||
| 32 | file://0011-tpm-Move-tpm_cleanup-to-right-place.patch \ | ||
| 33 | file://0012-tpm-Use-EMSGSIZE-instead-of-EBADMSG-to-compile-on-Op.patch \ | ||
| 34 | file://chardev-connect-socket-to-a-spawned-command.patch \ | ||
| 26 | file://apic-fixup-fallthrough-to-PIC.patch \ | 35 | file://apic-fixup-fallthrough-to-PIC.patch \ |
| 27 | file://ppc_locking.patch \ | 36 | file://ppc_locking.patch \ |
| 28 | " | 37 | " |
