From: Andreas Niederl <andreas.niederl@iaik.tugraz.at>
To: qemu-devel@nongnu.org
Cc: Andreas Niederl <andreas.niederl@iaik.tugraz.at>
Subject: [Qemu-devel] [PATCH 5/5] Adapt TPM host backend to use threadlets
Date: Fri, 18 Feb 2011 16:33:35 +0100 [thread overview]
Message-ID: <1298043215-10083-6-git-send-email-andreas.niederl@iaik.tugraz.at> (raw)
In-Reply-To: <1298043215-10083-1-git-send-email-andreas.niederl@iaik.tugraz.at>
Signed-off-by: Andreas Niederl <andreas.niederl@iaik.tugraz.at>
---
Makefile.objs | 3 -
hw/tpm_host_backend.c | 111 ++++++++++++++-----------------------------------
2 files changed, 32 insertions(+), 82 deletions(-)
diff --git a/Makefile.objs b/Makefile.objs
index 55fd6b5..5209a9b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -285,9 +285,6 @@ hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
# TPM passthrough device
hw-obj-$(CONFIG_TPM) += tpm_tis.o tpm_backend.o tpm_host_backend.o
-ifndef CONFIG_THREAD
-common-obj-$(CONFIG_TPM) += qemu-thread.o
-endif
######################################################################
# libdis
diff --git a/hw/tpm_host_backend.c b/hw/tpm_host_backend.c
index 4ae9deb..9204ede 100644
--- a/hw/tpm_host_backend.c
+++ b/hw/tpm_host_backend.c
@@ -20,17 +20,11 @@
#include <signal.h>
#include "qemu-common.h"
-#include "qemu-thread.h"
+#include "qemu-threadlet.h"
#include "hw/tpm_int.h"
-typedef struct {
- QemuThread id;
- QemuMutex lock;
- QemuCond send_command;
-} TPMThread;
-
#define STATUS_DONE (1 << 1)
#define STATUS_IN_PROGRESS (1 << 0)
#define STATUS_IDLE 0
@@ -38,7 +32,7 @@ typedef struct {
typedef struct {
TPMDriver common;
- TPMThread thread;
+ ThreadletWork work;
uint8_t send_status;
uint8_t recv_status;
@@ -56,7 +50,6 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty, uint32_t len)
drv->locty = locty;
- qemu_mutex_lock(&hdrv->thread.lock);
switch (hdrv->send_status) {
case STATUS_IN_PROGRESS:
break;
@@ -65,7 +58,7 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty, uint32_t len)
hdrv->recv_len = TPM_MAX_PKT;
/* asynchronous send */
n = 1;
- qemu_cond_signal( &hdrv->thread.send_command);
+ submit_work(&hdrv->work);
break;
case STATUS_DONE:
n = hdrv->send_len;
@@ -78,7 +71,6 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty, uint32_t len)
hdrv->send_status);
break;
}
- qemu_mutex_unlock(&hdrv->thread.lock);
return n;
}
@@ -90,7 +82,6 @@ static int tpm_host_recv(TPMDriver *drv, uint8_t locty, uint32_t len)
drv->locty = locty;
- qemu_mutex_lock(&hdrv->thread.lock);
switch (hdrv->recv_status) {
case STATUS_IN_PROGRESS:
break;
@@ -107,7 +98,6 @@ static int tpm_host_recv(TPMDriver *drv, uint8_t locty, uint32_t len)
hdrv->recv_status);
break;
}
- qemu_mutex_unlock(&hdrv->thread.lock);
return n;
}
@@ -153,82 +143,50 @@ static int unix_read(int fd, uint8_t *buf, uint32_t len)
return len - len1;
}
-static void die2(int err, const char *what)
-{
- fprintf(stderr, "%s failed: %s\n", what, strerror(err));
- abort();
-}
-
-static void die(const char *what)
+static void tpm_host_send_receive(ThreadletWork *work)
{
- die2(errno, what);
-}
-
-static void *tpm_host_thread(void *opaque)
-{
- TPMHostDriver *drv = opaque;
+ TPMHostDriver *drv = container_of(work, TPMHostDriver, work);
TPMDriver *s = &drv->common;
- sigset_t set;
uint32_t tpm_ret;
int ret;
- /* block all signals */
- if (sigfillset(&set)) {
- die("sigfillset");
- }
- if (sigprocmask(SIG_BLOCK, &set, NULL)) {
- die("sigprocmask");
- }
-
- qemu_mutex_lock(&drv->thread.lock);
- while (1) {
- qemu_cond_wait(&drv->thread.send_command, &drv->thread.lock);
- drv->send_status = STATUS_IN_PROGRESS;
- qemu_mutex_unlock(&drv->thread.lock);
+ drv->send_status = STATUS_IN_PROGRESS;
- DSHOW_BUFF(s->buf, "To TPM");
+ DSHOW_BUFF(s->buf, "To TPM");
- ret = unix_write(drv->fd, s->buf, drv->send_len);
+ ret = unix_write(drv->fd, s->buf, drv->send_len);
- qemu_mutex_lock(&drv->thread.lock);
- drv->send_len = ret;
- drv->send_status = STATUS_DONE;
+ drv->send_len = ret;
+ drv->send_status = STATUS_DONE;
- if (ret < 0) {
- fprintf(stderr, "Error: while transmitting data to host tpm"
- ": %s (%i)\n",
- strerror(errno), errno);
- continue;
- }
+ if (ret < 0) {
+ fprintf(stderr, "Error: while transmitting data to host tpm"
+ ": %s (%i)\n",
+ strerror(errno), errno);
+ }
- drv->recv_status = STATUS_IN_PROGRESS;
- qemu_mutex_unlock(&drv->thread.lock);
+ drv->recv_status = STATUS_IN_PROGRESS;
- ret = unix_read(drv->fd, s->buf, drv->recv_len);
+ ret = unix_read(drv->fd, s->buf, drv->recv_len);
- qemu_mutex_lock(&drv->thread.lock);
- drv->recv_len = ret;
- drv->recv_status = STATUS_DONE;
- drv->send_status = STATUS_IDLE;
+ drv->recv_len = ret;
+ drv->recv_status = STATUS_DONE;
+ drv->send_status = STATUS_IDLE;
- if (ret < 0) {
- fprintf(stderr, "Error: while reading data from host tpm"
- ": %s (%i)\n",
- strerror(errno), errno);
- continue;
- }
+ if (ret < 0) {
+ fprintf(stderr, "Error: while reading data from host tpm"
+ ": %s (%i)\n",
+ strerror(errno), errno);
+ }
- DSHOW_BUFF(s->buf, "From TPM");
+ DSHOW_BUFF(s->buf, "From TPM");
- tpm_ret = (s->buf[8])*256 + s->buf[9];
- if (tpm_ret) {
- DPRINTF("tpm command failed with error %d\n", tpm_ret);
- } else {
- DPRINTF("tpm command succeeded\n");
- }
+ tpm_ret = (s->buf[8])*256 + s->buf[9];
+ if (tpm_ret) {
+ DPRINTF("tpm command failed with error %d\n", tpm_ret);
+ } else {
+ DPRINTF("tpm command succeeded\n");
}
-
- return NULL;
}
@@ -236,7 +194,6 @@ TPMDriver *qemu_tpm_host_open(QemuOpts *opts)
{
TPMDriver *drv = NULL;
TPMHostDriver *hdrv = NULL;
- TPMThread *thread = NULL;
char *path = NULL;
int fd = -1;
@@ -263,11 +220,7 @@ TPMDriver *qemu_tpm_host_open(QemuOpts *opts)
}
hdrv->fd = fd;
- thread = &hdrv->thread;
- qemu_mutex_init(&thread->lock);
- qemu_cond_init( &thread->send_command);
-
- qemu_thread_create(&thread->id, &tpm_host_thread, hdrv);
+ hdrv->work.func = tpm_host_send_receive;
return drv;
--
1.7.4.1
prev parent reply other threads:[~2011-02-18 16:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-18 15:33 [Qemu-devel] [PATCH 0/5] TPM device emulation Andreas Niederl
2011-02-18 15:33 ` [Qemu-devel] [PATCH 1/5] Add TPM 1.2 device interface Andreas Niederl
2011-02-18 16:37 ` Stefan Berger
2011-02-18 17:37 ` Andreas Niederl
2011-02-18 20:27 ` Stefan Berger
2011-02-21 17:03 ` Andreas Niederl
2011-02-22 16:47 ` Stefan Berger
2011-02-24 15:30 ` Andreas Niederl
2011-02-24 17:44 ` Stefan Berger
2011-02-18 21:03 ` Stefan Berger
2011-02-21 17:13 ` Andreas Niederl
2011-02-18 15:33 ` [Qemu-devel] [PATCH 2/5] Provide SSDT for enabled TPM device Andreas Niederl
2011-02-18 17:02 ` Stefan Berger
2011-02-21 16:55 ` Andreas Niederl
2011-02-18 15:33 ` [Qemu-devel] [PATCH 3/5] Add TPM host passthrough device backend Andreas Niederl
2011-02-18 15:33 ` [Qemu-devel] [PATCH 4/5] Add configure script and command line options for TPM interface Andreas Niederl
2011-02-18 15:33 ` Andreas Niederl [this message]
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=1298043215-10083-6-git-send-email-andreas.niederl@iaik.tugraz.at \
--to=andreas.niederl@iaik.tugraz.at \
--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).