All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	marcandre.lureau@gmail.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL v1 14/21] tpm: add TPMBackendCmd to hold the request state
Date: Thu, 19 Oct 2017 14:02:48 -0400	[thread overview]
Message-ID: <1508436175-1596-15-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1508436175-1596-1-git-send-email-stefanb@linux.vnet.ibm.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

This simplifies a bit locality handling, and argument passing, and
could pave the way to queuing requests (if that makes sense).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
 backends/tpm.c               |  6 +++---
 hw/tpm/tpm_emulator.c        | 29 +++++++++++++++--------------
 hw/tpm/tpm_int.h             |  1 +
 hw/tpm/tpm_passthrough.c     | 24 +++++-------------------
 hw/tpm/tpm_tis.c             | 18 +++++++++++++-----
 include/sysemu/tpm_backend.h | 16 +++++++++++++---
 6 files changed, 50 insertions(+), 44 deletions(-)

diff --git a/backends/tpm.c b/backends/tpm.c
index 34e8208..dc7c831 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -25,7 +25,7 @@ static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
     TPMBackendClass *k  = TPM_BACKEND_GET_CLASS(s);
 
     assert(k->handle_request != NULL);
-    k->handle_request(s);
+    k->handle_request(s, (TPMBackendCmd *)data);
 }
 
 static void tpm_backend_thread_end(TPMBackend *s)
@@ -76,9 +76,9 @@ bool tpm_backend_had_startup_error(TPMBackend *s)
     return s->had_startup_error;
 }
 
-void tpm_backend_deliver_request(TPMBackend *s)
+void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd)
 {
-    g_thread_pool_push(s->thread_pool, NULL, NULL);
+    g_thread_pool_push(s->thread_pool, cmd, NULL);
 }
 
 void tpm_backend_reset(TPMBackend *s)
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 8fbe9ad..0b1a99f 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -172,28 +172,29 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
     return 0;
 }
 
-static void tpm_emulator_handle_request(TPMBackend *tb)
+static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
 {
     TPMEmulator *tpm_emu = TPM_EMULATOR(tb);
-    TPMLocality *locty = NULL;
-    bool selftest_done = false;
     Error *err = NULL;
 
     DPRINTF("processing TPM command");
 
-    locty = tb->tpm_state->locty_data;
-    if (tpm_emulator_set_locality(tpm_emu,
-                                  tb->tpm_state->locty_number) < 0 ||
-        tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer,
-                                  locty->w_offset, locty->r_buffer.buffer,
-                                  locty->r_buffer.size, &selftest_done,
-                                  &err) < 0) {
-        tpm_util_write_fatal_error_response(locty->r_buffer.buffer,
-                                            locty->r_buffer.size);
-        error_report_err(err);
+    if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < 0) {
+        goto error;
+    }
+
+    if (tpm_emulator_unix_tx_bufs(tpm_emu, cmd->in, cmd->in_len,
+                                  cmd->out, cmd->out_len,
+                                  &cmd->selftest_done, &err) < 0) {
+        goto error;
     }
 
-    tb->recv_data_callback(tb->tpm_state, selftest_done);
+    tb->recv_data_callback(tb->tpm_state);
+    return;
+
+error:
+    tpm_util_write_fatal_error_response(cmd->out, cmd->out_len);
+    error_report_err(err);
 }
 
 static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu)
diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h
index f2f285b..6d7b3dc 100644
--- a/hw/tpm/tpm_int.h
+++ b/hw/tpm/tpm_int.h
@@ -26,6 +26,7 @@ struct TPMState {
 
     uint8_t     locty_number;
     TPMLocality *locty_data;
+    TPMBackendCmd cmd;
 
     char *backend;
     TPMBackend *be_driver;
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index 0ae4596..93d72b8 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -137,30 +137,16 @@ err_exit:
     return ret;
 }
 
-static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt,
-                                         const TPMLocality *locty_data,
-                                         bool *selftest_done)
-{
-    return tpm_passthrough_unix_tx_bufs(tpm_pt,
-                                        locty_data->w_buffer.buffer,
-                                        locty_data->w_offset,
-                                        locty_data->r_buffer.buffer,
-                                        locty_data->r_buffer.size,
-                                        selftest_done);
-}
-
-static void tpm_passthrough_handle_request(TPMBackend *tb)
+static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
 {
     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
-    bool selftest_done = false;
 
-    DPRINTF("tpm_passthrough: processing command\n");
+    DPRINTF("tpm_passthrough: processing command %p\n", cmd);
 
-    tpm_passthrough_unix_transfer(tpm_pt,
-                                  tb->tpm_state->locty_data,
-                                  &selftest_done);
+    tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len,
+                                 cmd->out, cmd->out_len, &cmd->selftest_done);
 
-    tb->recv_data_callback(tb->tpm_state, selftest_done);
+    tb->recv_data_callback(tb->tpm_state);
 }
 
 static void tpm_passthrough_reset(TPMBackend *tb)
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 345a4fb..ffed7bf 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -215,7 +215,15 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty)
      */
     tis->loc[locty].state = TPM_TIS_STATE_EXECUTION;
 
-    tpm_backend_deliver_request(s->be_driver);
+    s->cmd = (TPMBackendCmd) {
+        .locty = locty,
+        .in = s->locty_data->w_buffer.buffer,
+        .in_len = s->locty_data->w_offset,
+        .out = s->locty_data->r_buffer.buffer,
+        .out_len = s->locty_data->r_buffer.size
+    };
+
+    tpm_backend_deliver_request(s->be_driver, &s->cmd);
 }
 
 /* raise an interrupt if allowed */
@@ -352,7 +360,7 @@ static void tpm_tis_receive_bh(void *opaque)
 {
     TPMState *s = opaque;
     TPMTISEmuState *tis = &s->s.tis;
-    uint8_t locty = s->locty_number;
+    uint8_t locty = s->cmd.locty;
 
     tpm_tis_sts_set(&tis->loc[locty],
                     TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
@@ -371,11 +379,11 @@ static void tpm_tis_receive_bh(void *opaque)
 /*
  * Callback from the TPM to indicate that the response was received.
  */
-static void tpm_tis_receive_cb(TPMState *s,
-                               bool is_selftest_done)
+static void tpm_tis_receive_cb(TPMState *s)
 {
     TPMTISEmuState *tis = &s->s.tis;
-    uint8_t locty = s->locty_number;
+    bool is_selftest_done = s->cmd.selftest_done;
+    uint8_t locty = s->cmd.locty;
     uint8_t l;
 
     if (is_selftest_done) {
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 9c83a51..3bb90be 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -30,7 +30,16 @@
 typedef struct TPMBackendClass TPMBackendClass;
 typedef struct TPMBackend TPMBackend;
 
-typedef void (TPMRecvDataCB)(TPMState *, bool selftest_done);
+typedef void (TPMRecvDataCB)(TPMState *);
+
+typedef struct TPMBackendCmd {
+    uint8_t locty;
+    const uint8_t *in;
+    uint32_t in_len;
+    uint8_t *out;
+    uint32_t out_len;
+    bool selftest_done;
+} TPMBackendCmd;
 
 struct TPMBackend {
     Object parent;
@@ -76,7 +85,7 @@ struct TPMBackendClass {
 
     void (*opened)(TPMBackend *s, Error **errp);
 
-    void (*handle_request)(TPMBackend *s);
+    void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd);
 };
 
 /**
@@ -121,11 +130,12 @@ bool tpm_backend_had_startup_error(TPMBackend *s);
 /**
  * tpm_backend_deliver_request:
  * @s: the backend to send the request to
+ * @cmd: the command to deliver
  *
  * Send a request to the backend. The backend will then send the request
  * to the TPM implementation.
  */
-void tpm_backend_deliver_request(TPMBackend *s);
+void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
 
 /**
  * tpm_backend_reset:
-- 
2.5.5

  parent reply	other threads:[~2017-10-19 18:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 18:02 [Qemu-devel] [PULL v1 00/21] Merge tpm 2017/10/19 Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 01/21] tpm-tis: remove unused hw_access argument Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 02/21] tpm-tis: remove RAISE_STS_IRQ Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 03/21] tpm: make tpm_get_backend_driver() static Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 04/21] tpm: lookup tpm backend class in tpm_driver_find_by_type() Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 05/21] tpm: replace tpm_get_backend_driver() to drop be_drivers Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 06/21] tpm: remove tpm_register_driver() Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 07/21] tpm: move TPMSizedBuffer to tpm_tis.h Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 08/21] tpm: remove TPMDriverOps Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 09/21] tpm: remove init() class method Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 10/21] tpm: remove configure_tpm() hop Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 11/21] tpm: remove unused TPMBackendCmd Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 12/21] tpm: remove needless cast Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 13/21] tpm: remove locty argument from receive_cb Stefan Berger
2017-10-19 18:02 ` Stefan Berger [this message]
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 15/21] tpm-emulator: fix error handling Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 16/21] tpm: remove locty_data from TPMState Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 17/21] tpm-tis: move TPMState to TIS header Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 18/21] tpm-tis: remove tpm_tis.h header Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 19/21] tpm-tis: fold TPMTISEmuState in TPMState Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 20/21] tpm: add a QOM TPM interface Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 21/21] tpm: move recv_data_callback to " Stefan Berger
2017-10-20 11:33 ` [Qemu-devel] [PULL v1 00/21] Merge tpm 2017/10/19 Peter Maydell

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=1508436175-1596-15-git-send-email-stefanb@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.