qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Roman Pen <roman.penyaev@profitbricks.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/1] Revert "linux-aio: Cancel BH if not needed"
Date: Tue, 28 Jun 2016 09:41:49 +0100	[thread overview]
Message-ID: <CAJSP0QUUZktKSquB8a2k6Ncj4fTd=+8ahpFZROTiXO_t4x7Yow@mail.gmail.com> (raw)
In-Reply-To: <20160624144605.GF5422@noname.redhat.com>

On Fri, Jun 24, 2016 at 3:46 PM, Kevin Wolf <kwolf@redhat.com> wrote:
>> diff --git a/block/linux-aio.c b/block/linux-aio.c
>> index e468960..fe7cece 100644
>> --- a/block/linux-aio.c
>> +++ b/block/linux-aio.c
>> @@ -149,8 +149,6 @@ static void qemu_laio_completion_bh(void *opaque)
>>      if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) {
>>          ioq_submit(s);
>>      }
>> -
>> -    qemu_bh_cancel(s->completion_bh);
>>  }
>
> Maybe if a nested event loops cancels the BH, it's missing on the next
> loop iteration. Before my patch, the nested callback happened to leave
> an additional BH around which the outer one actually needs.

The scenario you described is:

qemu_laio_completion_bh()
 -> cb1()
     -> aio_poll()
         -> qemu_laio_completion_bh()
         <- qemu_laio_completion_bh() (cancel BH)
     <- aio_poll()
 <- cb1()
 -> cb2()
     -> aio_poll()
        (hang!)

This hang seems impossible because the qemu_laio_completion_bh() loop
processes all pending events.  Therefore cb1() consumes all pending
events and cb2() will not poll.

If new I/O was submitted during cb1() and cb2() waits for it, then the
eventfd will become readable upon completion and cb2() does not hang
in that case either.

If, instead of the original scenario, cb1() nests deeper then the BH
is still scheduled and events will be processed without a hang.

In summary, the job of scheduling the BH is not to force all nested
callbacks to call qemu_laio_completion_bh().  Only the first nested
callback needs the BH so that all pending events will be processed.

Stefan

  parent reply	other threads:[~2016-06-28  8:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-24 13:40 [Qemu-devel] [PATCH 1/1] Revert "linux-aio: Cancel BH if not needed" Roman Pen
2016-06-24 14:46 ` Kevin Wolf
2016-06-27 15:09   ` Stefan Hajnoczi
2016-06-28  8:41   ` Stefan Hajnoczi [this message]
2016-06-27 16:01 ` Stefan Hajnoczi

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='CAJSP0QUUZktKSquB8a2k6Ncj4fTd=+8ahpFZROTiXO_t4x7Yow@mail.gmail.com' \
    --to=stefanha@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=roman.penyaev@profitbricks.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).