qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: qemu_coroutine_yield switches thread?


From: Kevin Wolf
Subject: Re: qemu_coroutine_yield switches thread?
Date: Thu, 16 Apr 2020 13:04:08 +0200
User-agent: Mutt/1.12.1 (2019-06-15)

Am 16.04.2020 um 12:09 hat Dietmar Maurer geschrieben:
> > > quick question: Can a resume from a qemu_coroutine_yield happen in a
> > > different thread?
> > > 
> > > Well, it can, since I'm seeing it happen, but is that okay or a bug?
> > 
> > Yes, it can happen. At least for devices like IDE where a request is
> > started during a vmexit (MMIO or I/O port write), the coroutine will
> > usually begin its life in the vcpu thread and then move to the main loop
> > thread.
> > 
> > This is not a problem because the vcpu thread holds the BQL while
> > running the request coroutine.
> 
> Isn't that a problem when using QemuRecMutex, for example:
> 
> qemu_rec_mutex_lock(lock)
> ...
> qemu_coroutine_yield() // wait for something
> // we are now inside a different thread
> qemu_rec_mutex_unlock(lock) // Crash - wrong thread!!

Acquiring a lock (other than CoMutex etc.) in a coroutine would be wrong
even if the coroutine stays in the same thread because acquiring the
lock can block, and the coroutine must yield in that case instead of
blocking. Coroutines must use the the coroutine locking primitives from
qemu/coroutine.h.

Kevin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]