From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: kwolf@redhat.com, aliguori@us.ibm.com,
stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org,
mdroth@linux.vnet.ibm.com, jschopp@linux.vnet.ibm.com,
stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/3] nvram: Add TPM NVRAM implementation
Date: Thu, 06 Jun 2013 09:32:15 -0400 [thread overview]
Message-ID: <51B08F5F.7030207@linux.vnet.ibm.com> (raw)
In-Reply-To: <20130606092214.GB13880@stefanha-thinkpad.redhat.com>
On 06/06/2013 05:22 AM, Stefan Hajnoczi wrote:
> On Wed, Jun 05, 2013 at 04:47:59PM -0400, Corey Bryant wrote:
>> +/*
>> + * Coroutine that reads a blob from the drive asynchronously
>> + */
>> +static void coroutine_fn tpm_nvram_co_read(void *opaque)
>> +{
>> + TPMNvramRWRequest *rwr = opaque;
>> +
>> + *rwr->blob_r = g_malloc(rwr->size);
>> +
>> + rwr->rc = bdrv_pread(rwr->bdrv,
>> + rwr->offset,
>> + *rwr->blob_r,
>> + rwr->size);
>> + if (rwr->rc != rwr->size) {
>> + g_free(*rwr->blob_r);
>> + *rwr->blob_r = NULL;
>> + }
>> +
>> + qemu_mutex_lock(&rwr->completion_mutex);
>
> Race condition: we must only store rwr->rc while holding
> ->completion_mutex. Otherwise the other thread may see ->rc and
> g_free(rwr) before we leave this function, causing us to operate on
> freed memory.
>
> I suggest storing rc into a local variable first and then assigning to
> rwr->rc here.
>
>> +/*
>> + * Enter a coroutine to write a blob to the drive
>> + */
>> +static void tpm_nvram_do_co_write(TPMNvramRWRequest *rwr)
>> +{
>> + int rc;
>> + Coroutine *co;
>> +
>> + rc = tpm_nvram_adjust_size(rwr->bdrv, rwr->offset, rwr->size);
>> + if (rc < 0) {
>> + rwr->rc = rc;
>> + return;
>> + }
>
> Do this inside the tpm_nvram_co_write() coroutine so error return still
> signals the condvar. Right now the other thread may miss completion and
> deadlock.
>
>
Thanks for the review. Sending a v3 out to the list now.
--
Regards,
Corey Bryant
next prev parent reply other threads:[~2013-06-06 13:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-05 20:47 [Qemu-devel] [PATCH v2 0/3] TPM NVRAM persistent storage Corey Bryant
2013-06-05 20:47 ` [Qemu-devel] [PATCH v2 1/3] nvram: Add TPM NVRAM implementation Corey Bryant
2013-06-06 9:22 ` Stefan Hajnoczi
2013-06-06 13:32 ` Corey Bryant [this message]
2013-06-05 20:48 ` [Qemu-devel] [PATCH v2 2/3] nvram: Add tpm-tis drive support Corey Bryant
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=51B08F5F.7030207@linux.vnet.ibm.com \
--to=coreyb@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=jschopp@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stefanha@gmail.com \
--cc=stefanha@redhat.com \
/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).