All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, John Snow <jsnow@redhat.com>,
	Pavel Butsykin <pbutsykin@virtuozzo.com>
Subject: [Qemu-devel] [PATCH 1/3] ide: don't loose pending dma state
Date: Wed, 23 Mar 2016 13:26:30 +0300	[thread overview]
Message-ID: <1458728792-15779-2-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1458728792-15779-1-git-send-email-den@openvz.org>

From: Pavel Butsykin <pbutsykin@virtuozzo.com>

If the migration occurs after the IDE DMA has been set up but before it
has been initiated, the state gets lost upon save/restore. Specifically,
->dma_cb callback gets cleared, so, when the guest eventually starts bus
mastering, the DMA never completes, causing the guest to time out the
operation.

OTOH all the infrastructure is already in place to restart the DMA if
the migration happens while the DMA is in progress.

So reuse that infrastructure, by calling the DMA callback with an
artificial error code in pre_save if the callback is already set but
DMAING is clear. The callback then sets bus->error_status to indicate
the need for restart; however since DMAING is clear the state upon
restore will be exactly "ready forDMA" as before the save.

This patch only fixes the IDE DMA case; the ATAPI DMA is left with a stub
for now since its restart hadn't been implemented yet. It will be
addressed in the followup patch.

Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: John Snow <jsnow@redhat.com>
---
 hw/ide/atapi.c    | 9 ++++++++-
 hw/ide/core.c     | 9 ++++++++-
 hw/ide/internal.h | 7 +++++++
 hw/ide/pci.c      | 3 +++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 1fe58ab..268220d 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -381,7 +381,14 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
     IDEState *s = opaque;
     int data_offset, n;
 
-    if (ret < 0) {
+    if (ret < 0) { /* XXX: handle -ESTATESAVE for migration */
+        if (ret == -ESTATESAVE) {
+            /*
+             * This case is not really an error
+             * but a request to save the state.
+             */
+            return;
+        }
         ide_atapi_io_error(s, ret);
         goto eot;
     }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 241e840..872e11f 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -810,7 +810,14 @@ static void ide_dma_cb(void *opaque, int ret)
         else if (s->dma_cmd == IDE_DMA_TRIM)
             op |= IDE_RETRY_TRIM;
 
-        if (ide_handle_rw_error(s, -ret, op)) {
+        if (ret == -ESTATESAVE) {
+            /*
+             * This case is not really an error
+             * but a request to save the state.
+             */
+            s->bus->error_status = op;
+            return;
+        } else if (ide_handle_rw_error(s, -ret, op)) {
             return;
         }
     }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 86bde26..dcd8627 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -513,6 +513,13 @@ struct IDEDevice {
 #define IDE_RETRY_TRIM 0x80
 #define IDE_RETRY_HBA  0x100
 
+/*
+ * a code to trigger entering error path and save/restore the "ready to DMA"
+ * state just like DMA-ing state. (Ab)use EINPROGRESS as it's not supposed to
+ * come from the block layer
+ */
+#define ESTATESAVE EINPROGRESS
+
 static inline IDEState *idebus_active_if(IDEBus *bus)
 {
     return bus->ifs + bus->unit;
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 92ffee7..e1f89fa 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -308,6 +308,9 @@ static void ide_bmdma_pre_save(void *opaque)
     BMDMAState *bm = opaque;
     uint8_t abused_bits = BM_MIGRATION_COMPAT_STATUS_BITS;
 
+    if (!(bm->status & BM_STATUS_DMAING) && bm->dma_cb) {
+        bm->dma_cb(bmdma_active_if(bm), -ESTATESAVE);
+    }
     bm->migration_retry_unit = bm->bus->retry_unit;
     bm->migration_retry_sector_num = bm->bus->retry_sector_num;
     bm->migration_retry_nsector = bm->bus->retry_nsector;
-- 
2.1.4

  reply	other threads:[~2016-03-23 10:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 10:26 [Qemu-devel] [PATCH for 2.6 0/3] ide: fix loss of the dma/atapi state during migration Denis V. Lunev
2016-03-23 10:26 ` Denis V. Lunev [this message]
2016-03-23 20:34   ` [Qemu-devel] [PATCH 1/3] ide: don't loose pending dma state Paolo Bonzini
2016-03-24  9:24     ` Pavel Butsykin
2016-03-24 11:23       ` Paolo Bonzini
2016-03-24 13:38         ` Pavel Butsykin
2016-03-24 14:07           ` Paolo Bonzini
2016-03-24 15:11             ` Pavel Butsykin
2016-03-24 15:12               ` Paolo Bonzini
2016-03-24 15:20                 ` Pavel Butsykin
2016-03-24 14:47       ` Eric Blake
2016-03-24 15:40         ` Pavel Butsykin
2016-03-30 17:35   ` John Snow
2016-03-30 17:38     ` Denis V. Lunev
2016-03-30 17:44       ` John Snow
2016-03-23 10:26 ` [Qemu-devel] [PATCH 2/3] ide: restart atapi dma by re-evaluating command packet Denis V. Lunev
2016-03-23 10:26 ` [Qemu-devel] [PATCH 3/3] ide: really restart pending and in-flight atapi dma Denis V. Lunev
2016-03-23 19:36   ` John Snow
2016-03-24  8:34     ` Pavel Butsykin

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=1458728792-15779-2-git-send-email-den@openvz.org \
    --to=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=pbutsykin@virtuozzo.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 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.