All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amol Surati <suratiamol@gmail.com>
To: qemu-devel@nongnu.org
Cc: Amol Surati <suratiamol@gmail.com>, John Snow <jsnow@redhat.com>,
	"open list:IDE" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [RFC 1/1] ide: bug #1777315: io_buffer_size and sg.size can represent partial sector sizes
Date: Mon, 18 Jun 2018 00:05:15 +0530	[thread overview]
Message-ID: <20180617183515.3982-2-suratiamol@gmail.com> (raw)
In-Reply-To: <20180617183515.3982-1-suratiamol@gmail.com>

This patch fixes the assumption that io_buffer_size is always a perfect
multiple of the sector size. The assumption is the cause of the firing
of 'assert(n * 512 == s->sg.size);'.

Signed-off-by: Amol Surati <suratiamol@gmail.com>
---
 hw/ide/core.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 2c62efc536..53a7c68196 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -835,7 +835,7 @@ int ide_handle_rw_error(IDEState *s, int error, int op)
 static void ide_dma_cb(void *opaque, int ret)
 {
     IDEState *s = opaque;
-    int n;
+    int m, n;
     int64_t sector_num;
     uint64_t offset;
     bool stay_active = false;
@@ -858,6 +858,10 @@ static void ide_dma_cb(void *opaque, int ret)
     }
 
     n = s->io_buffer_size >> 9;
+    if (s->io_buffer_size & (~BDRV_SECTOR_MASK)) {
+        n++;
+    }
+
     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
@@ -868,7 +872,11 @@ static void ide_dma_cb(void *opaque, int ret)
 
     sector_num = ide_get_sector(s);
     if (n > 0) {
-        assert(n * 512 == s->sg.size);
+        m = s->sg.size >> 9;
+        if (s->sg.size & (~BDRV_SECTOR_MASK)) {
+            m++;
+        }
+        assert(n == m);
         dma_buf_commit(s, s->sg.size);
         sector_num += n;
         ide_set_sector(s, sector_num);
-- 
2.17.1

  reply	other threads:[~2018-06-17 18:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-17 18:35 [Qemu-devel] [RFC 0/1] ide: attempt at fixing the bug #1777315 Amol Surati
2018-06-17 18:35 ` Amol Surati [this message]
2018-06-18 18:02   ` [Qemu-devel] [RFC 1/1] ide: bug #1777315: io_buffer_size and sg.size can represent partial sector sizes Amol Surati
2018-06-18 18:13     ` John Snow
2018-06-18 18:24       ` Amol Surati
2018-06-19  0:14     ` John Snow
2018-06-19  4:01       ` Amol Surati
2018-06-19  8:53         ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2018-06-19 13:45           ` John Snow
2018-06-19 14:34             ` Amol Surati
2018-06-19 21:26               ` Amol Surati
2018-06-19 21:43                 ` John Snow
2018-06-20  0:53                   ` Amol Surati
2018-06-20  1:27                     ` Amol Surati

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=20180617183515.3982-2-suratiamol@gmail.com \
    --to=suratiamol@gmail.com \
    --cc=jsnow@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.