From: Stefan Hajnoczi <stefanha@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 4/5] ide: Fix crash with too long PRD
Date: Wed, 21 Nov 2012 11:12:31 +0100 [thread overview]
Message-ID: <1353492752-16084-5-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1353492752-16084-1-git-send-email-stefanha@redhat.com>
From: Kevin Wolf <kwolf@redhat.com>
Without this, s->nsector can become negative and badness happens (trying
to malloc huge amount of memory and glib calls abort())
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/ide/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 7d6b0fa..c2ab787 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -579,6 +579,7 @@ void ide_dma_cb(void *opaque, int ret)
IDEState *s = opaque;
int n;
int64_t sector_num;
+ bool stay_active = false;
if (ret < 0) {
int op = BM_STATUS_DMA_RETRY;
@@ -594,6 +595,14 @@ void ide_dma_cb(void *opaque, int ret)
}
n = s->io_buffer_size >> 9;
+ if (n > s->nsector) {
+ /* The PRDs were longer than needed for this request. Shorten them so
+ * we don't get a negative remainder. The Active bit must remain set
+ * after the request completes. */
+ n = s->nsector;
+ stay_active = true;
+ }
+
sector_num = ide_get_sector(s);
if (n > 0) {
dma_buf_commit(s);
@@ -646,6 +655,9 @@ eot:
bdrv_acct_done(s->bs, &s->acct);
}
ide_set_inactive(s);
+ if (stay_active) {
+ s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_DMAING);
+ }
}
static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
--
1.8.0
next prev parent reply other threads:[~2012-11-21 10:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-21 10:12 [Qemu-devel] [PULL 1.3-rc1 0/5] Block patches for QEMU 1.3-rc1 Stefan Hajnoczi
2012-11-21 10:12 ` [Qemu-devel] [PATCH 1/5] block: add bdrv_reopen() support for raw hdev, floppy, and cdrom Stefan Hajnoczi
2012-11-21 10:12 ` [Qemu-devel] [PATCH 2/5] vdi: don't override libuuid symbols Stefan Hajnoczi
2012-11-21 19:25 ` Stefan Weil
2012-11-22 7:33 ` Stefan Hajnoczi
2012-11-21 10:12 ` [Qemu-devel] [PATCH 3/5] use int64_t for return values from rbd instead of int Stefan Hajnoczi
2012-11-21 10:12 ` Stefan Hajnoczi [this message]
2012-11-21 10:12 ` [Qemu-devel] [PATCH 5/5] ide: Fix status register after short PRDs Stefan Hajnoczi
2012-11-26 15:34 ` [Qemu-devel] [PULL 1.3-rc1 0/5] Block patches for QEMU 1.3-rc1 Anthony Liguori
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=1353492752-16084-5-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kwolf@redhat.com \
--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).