|
| From: | Paolo Bonzini |
| Subject: | Re: [Qemu-devel] [PATCH v2 2/2] QEMUBH: make AioContext's bh re-entrant |
| Date: | Mon, 17 Jun 2013 18:41:42 +0200 |
| User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6 |
Il 17/06/2013 17:28, Stefan Hajnoczi ha scritto:
>> > + qemu_mutex_lock(&ctx->bh_lock);
>> > bh->next = ctx->first_bh;
>> > + /* Make sure the memebers ready before putting bh into list */
> s/memebers/members/
>
>> > + smp_wmb();
> Why lock bh_lock before assigning bh->next? Could you lock the mutex
> here and then drop the smp_wmb() since the pthread function already does
> that?
>
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_11
Not sure I understand, ctx->first_bh is read here and that's what the
lock protects.
thread 1 thread 2
------------------------------------------------------------------
bh->next = ctx->first_bh;
bh->next = ctx->first_bh;
lock
ctx->first_bh = bh;
unlock
lock
ctx->first_bh = bh;
unlock
and thread 2's bottom half is gone. There is also a similar race that
leaves a dangling pointer if aio_bh_new races against aio_bh_poll.
Paolo
| [Prev in Thread] | Current Thread | [Next in Thread] |