qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com
Cc: amarnath.valluri@intel.com
Subject: Re: [Qemu-devel] [PATCH v3 10/13] tpm: Introduce condition in TPM backend for notification
Date: Wed, 27 Dec 2017 09:19:37 -0500	[thread overview]
Message-ID: <ee78a70b-4b66-6495-df59-15155451b5af@linux.vnet.ibm.com> (raw)
In-Reply-To: <1510323112-2207-11-git-send-email-stefanb@linux.vnet.ibm.com>

On 11/10/2017 09:11 AM, Stefan Berger wrote:
> 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               | 19 +++++++++++++++++++
>   include/sysemu/tpm_backend.h | 14 ++++++++++++++
>   2 files changed, 33 insertions(+)
>
> diff --git a/backends/tpm.c b/backends/tpm.c
> index 91222c5..bf0e120 100644
> --- a/backends/tpm.c
> +++ b/backends/tpm.c
> @@ -20,6 +20,14 @@
>   #include "qemu/thread.h"
>   #include "qemu/main-loop.h"
>
> +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);
> +}
> +
>   static void tpm_backend_request_completed_bh(void *opaque)
>   {
>       TPMBackend *s = TPM_BACKEND(opaque);
> @@ -36,6 +44,9 @@ static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
>       k->handle_request(s, (TPMBackendCmd *)data);
>
>       qemu_bh_schedule(s->bh);
> +
> +    /* result delivered */
> +    tpm_backend_cmd_completed(s);
>   }
>
>   static void tpm_backend_thread_end(TPMBackend *s)
> @@ -64,6 +75,10 @@ int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp)
>       object_ref(OBJECT(tpmif));
>
>       s->had_startup_error = false;
> +    s->tpm_busy = false;
> +
> +    qemu_mutex_init(&s->state_lock);
> +    qemu_cond_init(&s->cmd_complete);
>
>       return 0;
>   }
> @@ -93,6 +108,10 @@ bool tpm_backend_had_startup_error(TPMBackend *s)
>
>   void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd)
>   {
> +    qemu_mutex_lock(&s->state_lock);
> +    s->tpm_busy = true;
> +    qemu_mutex_unlock(&s->state_lock);
> +
>       g_thread_pool_push(s->thread_pool, cmd, NULL);
>   }
>
> diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
> index 0d6c994..39598e3 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) \
> @@ -53,6 +54,10 @@ struct TPMBackend {
>       char *id;
>
>       QLIST_ENTRY(TPMBackend) list;
> +
> +    QemuMutex state_lock;

This lock only locks the tpm_busy flag. So maybe I should rename it to 
tpm_busy_lock. It's not meant to be a general state lock.

    Stefan

> +    QemuCond cmd_complete; /* signaled once tpm_busy is false */
> +    bool tpm_busy;
>   };
>
>   struct TPMBackendClass {
> @@ -206,6 +211,15 @@ size_t tpm_backend_get_buffer_size(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_be(const char *id);
>
>   #endif

  reply	other threads:[~2017-12-27 14:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 14:11 [Qemu-devel] [PATCH v3 00/13] tpm: Extend TPM with state migration support (not 2.11) Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 01/13] tpm_tis: convert uint32_t to size_t Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 02/13] tpm_tis: limit size of buffer from backend Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 03/13] tpm_tis: remove TPMSizeBuffer usage Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 04/13] tpm_tis: move buffers from localities into common location Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 05/13] tpm_tis: merge read and write buffer into single buffer Stefan Berger
2017-12-21 14:41   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 06/13] tpm_tis: move r/w_offsets to TPMState Stefan Berger
2017-12-21 14:41   ` Marc-André Lureau
2017-12-21 14:44     ` Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 07/13] tpm_tis: merge r/w_offset into rw_offset Stefan Berger
2017-12-21 14:41   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 08/13] tpm: Implement tpm_sized_buffer_reset Stefan Berger
2017-12-21 14:44   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 09/13] tpm: Introduce condition to notify waiters of completed command Stefan Berger
2017-12-22 13:24   ` Marc-André Lureau
2017-12-27 14:17     ` Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 10/13] tpm: Introduce condition in TPM backend for notification Stefan Berger
2017-12-27 14:19   ` Stefan Berger [this message]
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 11/13] tpm: implement tpm_backend_wait_cmd_completed Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 12/13] tpm: extend TPM emulator with state migration support Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 13/13] tpm_tis: extend TPM TIS " Stefan Berger
2017-12-22 12:49 ` [Qemu-devel] [PATCH v3 00/13] tpm: Extend TPM with state migration support (not 2.11) Marc-André Lureau
2017-12-22 15:59   ` Stefan Berger
2017-12-22 16:13     ` Marc-André Lureau
2017-12-22 17:47       ` Stefan Berger
2017-12-22 17:52         ` Marc-André Lureau
2017-12-22 19:18           ` Stefan Berger
2017-12-27 15:00       ` Stefan Berger

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=ee78a70b-4b66-6495-df59-15155451b5af@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=amarnath.valluri@intel.com \
    --cc=marcandre.lureau@redhat.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).