qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: amarnath.valluri@intel.com, marcandre.lureau@gmail.com,
	Stefan Berger <stefanb@linux.vnet.ibm.com>
Subject: [Qemu-devel] [RFC PATCH 3/4] tpm: Introduce condition in TPM backend for notification
Date: Wed, 11 Oct 2017 17:37:30 -0400	[thread overview]
Message-ID: <1507757851-12580-4-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1507757851-12580-1-git-send-email-stefanb@linux.vnet.ibm.com>

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>
---
 backends/tpm.c               | 16 ++++++++++++++++
 hw/tpm/tpm_emulator.c        |  3 +++
 include/sysemu/tpm_backend.h | 14 ++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/backends/tpm.c b/backends/tpm.c
index 37c84b7..334836b 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -52,10 +52,22 @@ int tpm_backend_init(TPMBackend *s, TPMState *state,
     s->tpm_state = state;
     s->recv_data_callback = datacb;
     s->had_startup_error = false;
+    s->tpm_busy = false;
+
+    qemu_mutex_init(&s->state_lock);
+    qemu_cond_init(&s->cmd_complete);
 
     return k->ops->init ? k->ops->init(s) : 0;
 }
 
+void tpm_backend_cmd_completed(TPMBackend *s)
+{
+    qemu_mutex_lock(&s->state_lock);
+    s->tpm_busy = false;
+    qemu_cond_signal(&s->cmd_complete);
+    qemu_mutex_unlock(&s->state_lock);
+}
+
 int tpm_backend_startup_tpm(TPMBackend *s)
 {
     int res = 0;
@@ -82,6 +94,10 @@ bool tpm_backend_had_startup_error(TPMBackend *s)
 
 void tpm_backend_deliver_request(TPMBackend *s)
 {
+    qemu_mutex_lock(&s->state_lock);
+    s->tpm_busy = true;
+    qemu_mutex_unlock(&s->state_lock);
+
     g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD,
                        NULL);
 }
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 95e1e04..556b8c8 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -200,6 +200,9 @@ static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd cmd)
         tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number,
                                selftest_done);
 
+        /* result delivered */
+        tpm_backend_cmd_completed(tb);
+
         break;
     case TPM_BACKEND_CMD_INIT:
     case TPM_BACKEND_CMD_END:
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 2c798a1..cdc4742 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -18,6 +18,7 @@
 #include "qapi-types.h"
 #include "qemu/option.h"
 #include "sysemu/tpm.h"
+#include "qemu/thread.h"
 
 #define TYPE_TPM_BACKEND "tpm-backend"
 #define TPM_BACKEND(obj) \
@@ -54,6 +55,10 @@ struct TPMBackend {
     enum TpmModel fe_model;
 
     QLIST_ENTRY(TPMBackend) list;
+
+    QemuMutex state_lock;
+    QemuCond cmd_complete; /* signaled once tpm_busy is false */
+    bool tpm_busy;
 };
 
 struct TPMBackendClass {
@@ -213,6 +218,15 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
  */
 TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
 
+/**
+ * tpm_backend_cmd_completed:
+ * @s: the backend
+ *
+ * Mark the backend as not busy and notify anyone interested
+ * in the state changed
+ */
+void tpm_backend_cmd_completed(TPMBackend *s);
+
 TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
-- 
2.5.5

  parent reply	other threads:[~2017-10-11 21:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-11 21:37 [Qemu-devel] [RFC PATCH 0/4] tpm: Extend TPM with state migration support Stefan Berger
2017-10-11 21:37 ` [Qemu-devel] [RFC PATCH 1/4] tpm: print buffers received from TPM when debugging Stefan Berger
2017-10-12 14:54   ` Marc-André Lureau
2017-10-11 21:37 ` [Qemu-devel] [RFC PATCH 2/4] tpm: Introduce condition to notify waiters of completed command Stefan Berger
2017-10-11 21:37 ` Stefan Berger [this message]
2017-10-11 21:37 ` [Qemu-devel] [RFC PATCH 4/4] tpm: extend TPM emulator and TIS with state migration support Stefan Berger
2017-10-11 21:45 ` [Qemu-devel] [RFC PATCH 0/4] tpm: Extend TPM " Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507757851-12580-4-git-send-email-stefanb@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=amarnath.valluri@intel.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).