diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2017-12-06 12:03:32 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-12-10 22:41:43 +0000 |
commit | 82f37aa4c5152f104897fff04f09ad55c20c2a3f (patch) | |
tree | 1f12cceb9390f7d3715d2d9cfbeaecfbcedf1e51 /meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch | |
parent | d9b59df1230a20c7a5c9f4fb0325bb9216025a16 (diff) | |
download | openembedded-core-contrib-82f37aa4c5152f104897fff04f09ad55c20c2a3f.tar.gz |
qemu: use upstream swtpm support
Upstream finally accepted and merged a different approach for
connecting QEMU to swtpm: instead of a custom cuse-tpm device, a
normal chardev connects to swtpm, and that chardev then is used by the
TPM device. For now we have to backport those patches, but the next
major QEMU update will have them.
However, the chardev-connect-socket-to-a-spawned-command.patch is
something that OE will have to carry permanently. It simplifies
starting and stopping swtpm when invoking QEMU through runqemu without
having to teach that script about the additional process. Upstream
rejected the patch because they want to keep the complexity of
starting additional processes out of QEMU.
A recent enough swtpm is needed. The one currently used by
meta-security fails to communicate properly with QEMU, leading to this
failure:
qemu-system-x86_64: -tpmdev emulator,id=tpm0,chardev=chrtpm0: tpm-emulator: Failed to send CMD_SET_DATAFD: Input/output error
qemu-system-x86_64: -tpmdev emulator,id=tpm0,chardev=chrtpm0: tpm-emulator: Could not cleanly shutdown the TPM: Invalid argument
With a recent enough swtpm, one can create a TPM device like this:
- bitbake swtpm-native
- create a TPM instance and initialize it with:
$ mkdir -p my-machine/myvtpm0
$ tmp*/work/*/swtpm-wrappers-native/*/swtpm_setup_oe.sh --tpm-state my-machine/myvtpm0 --createek
Starting vTPM manufacturing as root:root @ Wed 06 Dec 2017 10:03:14 AM CET
TPM is listening on TCP port 34613.
Successfully created EK.
Successfully authored TPM state.
Ending vTPM manufacturing @ Wed 06 Dec 2017 10:03:14 AM CET
- runqemu "qemuparams=-chardev 'socket,id=chrtpm0,cmd=exec
swtpm_oe.sh socket --terminate --ctrl type=unixio,,clientfd=0
--tpmstate dir=... --log level=10,,file=.../swtpm.log --tpm2'
-tpmdev emulator,id=tpm0,chardev=chrtpm0 -device
tpm-tis,tpmdev=tpm0" ...
Beware that the double commas are intentional. They are needed to
embed commas in the "cmd" value.
swtpm_oe.sh is from swtpm-wrappers-native. In the example it is
invoked without the full path for the sake of brevity. In practice,
one has to use the full
path (tmp*/work/*/swtpm-wrappers-native/*/swtpm_oe.sh).
With the TPM2-preview version of swtpm, the same works for TPM2 by
adding the --tpm2 parameter when invoking swtpm_setup_oe.sh and
swtpm_oe.sh.
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch')
-rw-r--r-- | meta/recipes-devtools/qemu/qemu/0003-Introduce-condition-in-TPM-backend-for-notification.patch | 79 |
1 files changed, 0 insertions, 79 deletions
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 @@ -From 732a8e046948fd62b32cd1dd76a6798eb1caf4d6 Mon Sep 17 00:00:00 2001 -From: Stefan Berger <stefanb@linux.vnet.ibm.com> -Date: Sat, 31 Dec 2016 11:23:32 -0500 -Subject: [PATCH 3/4] Introduce condition in TPM backend for notification - -TPM backends will suspend independently of the frontends. Also -here we need to be able to wait for the TPM command to have been -completely processed. - -Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> - -Upstream-Status: Pending [https://lists.nongnu.org/archive/html/qemu-devel/2016-06/msg00252.html] -Signed-off-by: Patrick Ohly <patrick.ohly@intel.com> ---- - hw/tpm/tpm_passthrough.c | 20 ++++++++++++++++++++ - 1 file changed, 20 insertions(+) - -diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c -index 050f2ba850..44739ebad2 100644 ---- a/hw/tpm/tpm_passthrough.c -+++ b/hw/tpm/tpm_passthrough.c -@@ -75,6 +75,10 @@ struct TPMPassthruState { - TPMVersion tpm_version; - ptm_cap cuse_cap; /* capabilities of the CUSE TPM */ - uint8_t cur_locty_number; /* last set locality */ -+ -+ QemuMutex state_lock; -+ QemuCond cmd_complete; /* singnaled once tpm_busy is false */ -+ bool tpm_busy; - }; - - typedef struct TPMPassthruState TPMPassthruState; -@@ -274,6 +278,11 @@ static void tpm_passthrough_worker_thread(gpointer data, - thr_parms->recv_data_callback(thr_parms->tpm_state, - thr_parms->tpm_state->locty_number, - selftest_done); -+ /* result delivered */ -+ qemu_mutex_lock(&tpm_pt->state_lock); -+ tpm_pt->tpm_busy = false; -+ qemu_cond_signal(&tpm_pt->cmd_complete); -+ qemu_mutex_unlock(&tpm_pt->state_lock); - break; - case TPM_BACKEND_CMD_INIT: - case TPM_BACKEND_CMD_END: -@@ -401,6 +410,7 @@ static void tpm_passthrough_reset(TPMBackend *tb) - tpm_backend_thread_end(&tpm_pt->tbt); - - tpm_pt->had_startup_error = false; -+ tpm_pt->tpm_busy = false; - } - - static int tpm_passthrough_init(TPMBackend *tb, TPMState *s, -@@ -478,6 +488,11 @@ static void tpm_passthrough_deliver_request(TPMBackend *tb) - { - TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - -+ /* TPM considered busy once TPM Request scheduled for processing */ -+ qemu_mutex_lock(&tpm_pt->state_lock); -+ tpm_pt->tpm_busy = true; -+ qemu_mutex_unlock(&tpm_pt->state_lock); -+ - tpm_backend_thread_deliver_request(&tpm_pt->tbt); - } - -@@ -746,6 +761,11 @@ static const TPMDriverOps tpm_passthrough_driver = { - - static void tpm_passthrough_inst_init(Object *obj) - { -+ TPMBackend *tb = TPM_BACKEND(obj); -+ TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); -+ -+ qemu_mutex_init(&tpm_pt->state_lock); -+ qemu_cond_init(&tpm_pt->cmd_complete); - } - - static void tpm_passthrough_inst_finalize(Object *obj) --- -2.11.0 - |