qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Dietmar Maurer <dietmar@proxmox.com>
Cc: vsementsov@virtuozzo.com, slp@redhat.com,
	Stefan Reiter <s.reiter@proxmox.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com
Subject: Re: qemu_coroutine_yield switches thread?
Date: Thu, 16 Apr 2020 13:04:08 +0200	[thread overview]
Message-ID: <20200416110408.GB6014@linux.fritz.box> (raw)
In-Reply-To: <1548825935.27.1587031774908@webmail.proxmox.com>

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	other threads:[~2020-04-16 11:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16  8:06 qemu_coroutine_yield switches thread? Stefan Reiter
2020-04-16  8:28 ` Kevin Wolf
2020-04-16 10:09   ` Dietmar Maurer
2020-04-16 11:04     ` Kevin Wolf [this message]

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=20200416110408.GB6014@linux.fritz.box \
    --to=kwolf@redhat.com \
    --cc=dietmar@proxmox.com \
    --cc=jsnow@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=s.reiter@proxmox.com \
    --cc=slp@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.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).