qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, John Snow <jsnow@redhat.com>,
	Peter Lieven <pl@kamp.de>
Subject: Re: [Qemu-devel] [PATCH] ide: avoid unbounded recursion
Date: Thu, 12 Jan 2017 14:11:45 +0000	[thread overview]
Message-ID: <20170112141145.GA14042@stefanha-x1.localdomain> (raw)
In-Reply-To: <20170112105132.10394-1-pbonzini@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]

On Thu, Jan 12, 2017 at 11:51:32AM +0100, Paolo Bonzini wrote:
> The end_transfer_func can call ide_transfer_start immediately, before
> returning, and unbounded recursion can happen at least for
> ide_atapi_cmd_reply_end.  Use a bottom half to defer the call and
> limit stack usage.
> 
> Cc: Peter Lieven <pl@kamp.de>
> Cc: John Snow <jsnow@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/ide/core.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 43709e5..7b9831f 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -482,6 +482,13 @@ static void ide_clear_retry(IDEState *s)
>      s->bus->retry_nsector = 0;
>  }
>  
> +static void ide_start_transfer_bh_cb(void *opaque)
> +{
> +    IDEDMA *dma = opaque;
> +
> +    dma->ops->start_transfer(dma);
> +}
> +
>  /* prepare data transfer and tell what to do after */
>  void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
>                          EndTransferFunc *end_transfer_func)
> @@ -494,7 +501,12 @@ void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
>          s->status |= DRQ_STAT;
>      }
>      if (s->bus->dma->ops->start_transfer) {
> -        s->bus->dma->ops->start_transfer(s->bus->dma);
> +        /* There can be unbounded recursion between ops->start_transfer
> +         * and end_transfer_func, so defer to a bottom half.
> +         */
> +        aio_bh_schedule_oneshot(qemu_get_aio_context(),
> +                                ide_start_transfer_bh_cb,
> +                                s->bus->dma);

Are you sure this is safe?

I wonder if there are races with device reset, vmsave, or vcpu hw
register accesses.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  reply	other threads:[~2017-01-12 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-12 10:51 [Qemu-devel] [PATCH] ide: avoid unbounded recursion Paolo Bonzini
2017-01-12 14:11 ` Stefan Hajnoczi [this message]
2017-01-12 16:05   ` John Snow
2017-01-12 17:07     ` Paolo Bonzini
2017-01-12 16:18   ` Paolo Bonzini
2017-01-12 15:54 ` John Snow

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=20170112141145.GA14042@stefanha-x1.localdomain \
    --to=stefanha@gmail.com \
    --cc=jsnow@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    /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).