Re: [PATCH 4/6] coroutine-lock: reimplement CoRwlock to fix downgrade bug

2021-03-24 Thread Paolo Bonzini
On 24/03/21 17:15, Stefan Hajnoczi wrote: On Wed, Mar 17, 2021 at 07:00:11PM +0100, Paolo Bonzini wrote: +static void qemu_co_rwlock_maybe_wake_one(CoRwlock *lock) +{ +CoRwTicket *tkt = QSIMPLEQ_FIRST(&lock->tickets); +Coroutine *co = NULL; + +/* + * Setting lock->owners here pre

Re: [PATCH 4/6] coroutine-lock: reimplement CoRwlock to fix downgrade bug

2021-03-24 Thread Stefan Hajnoczi
On Wed, Mar 17, 2021 at 07:00:11PM +0100, Paolo Bonzini wrote: > +static void qemu_co_rwlock_maybe_wake_one(CoRwlock *lock) > +{ > +CoRwTicket *tkt = QSIMPLEQ_FIRST(&lock->tickets); > +Coroutine *co = NULL; > + > +/* > + * Setting lock->owners here prevents rdlock and wrlock from >

[PATCH 4/6] coroutine-lock: reimplement CoRwlock to fix downgrade bug

2021-03-17 Thread Paolo Bonzini
An invariant of the current rwlock is that if multiple coroutines hold a reader lock, all must be runnable. The unlock implementation relies on this, choosing to wake a single coroutine when the final read lock holder exits the critical section, assuming that it will wake a coroutine attempting to

Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug

2021-03-17 Thread David Edmondson
On Wednesday, 2021-03-17 at 18:19:58 +01, Paolo Bonzini wrote: > On 17/03/21 16:17, David Edmondson wrote: >>> +if (tkt) { >>> +if (tkt->read) { >>> +if (lock->owners >= 0) { >>> +lock->owners++; >>> +co = tkt->co; >>> +} >>> +

Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug

2021-03-17 Thread Paolo Bonzini
On 17/03/21 16:17, David Edmondson wrote: +if (tkt) { +if (tkt->read) { +if (lock->owners >= 0) { +lock->owners++; +co = tkt->co; +} +} else { +if (lock->owners == 0) { +lock->owners = -1; +

Re: [PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug

2021-03-17 Thread David Edmondson
On Wednesday, 2021-03-17 at 13:16:39 +01, Paolo Bonzini wrote: > An invariant of the current rwlock is that if multiple coroutines hold a > reader lock, all must be runnable. The unlock implementation relies on > this, choosing to wake a single coroutine when the final read lock > holder exits the

[PATCH 4/6] coroutine-lock: reimplement CoRwLock to fix downgrade bug

2021-03-17 Thread Paolo Bonzini
An invariant of the current rwlock is that if multiple coroutines hold a reader lock, all must be runnable. The unlock implementation relies on this, choosing to wake a single coroutine when the final read lock holder exits the critical section, assuming that it will wake a coroutine attempting to