9ae3a8
From cc224bcb3c12238466f8a6a366d3f813fb866a16 Mon Sep 17 00:00:00 2001
9ae3a8
From: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Date: Thu, 13 Dec 2018 21:54:28 +0100
9ae3a8
Subject: [PATCH 1/5] Inhibit ballooning during postcopy
9ae3a8
9ae3a8
RH-Author: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Message-id: <154473806860.22725.2305869657628116679.stgit@gimli.home>
9ae3a8
Patchwork-id: 83493
9ae3a8
O-Subject: [RHEL-7.7 qemu-kvm PATCH 1/5] Inhibit ballooning during postcopy
9ae3a8
Bugzilla: 1659229
9ae3a8
RH-Acked-by: Peter Xu <peterx@redhat.com>
9ae3a8
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
9ae3a8
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
9ae3a8
9ae3a8
From: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
9ae3a8
Bugzilla: 1659229
9ae3a8
Notes: Dropped all but balloon inhibitor infrastructure
9ae3a8
9ae3a8
Postcopy detects accesses to pages that haven't been transferred yet
9ae3a8
using userfaultfd, and it causes exceptions on pages that are 'not
9ae3a8
present'.
9ae3a8
Ballooning also causes pages to be marked as 'not present' when the
9ae3a8
guest inflates the balloon.
9ae3a8
Potentially a balloon could be inflated to discard pages that are
9ae3a8
currently inflight during postcopy and that may be arriving at about
9ae3a8
the same time.
9ae3a8
9ae3a8
To avoid this confusion, disable ballooning during postcopy.
9ae3a8
9ae3a8
When disabled we drop balloon requests from the guest.  Since ballooning
9ae3a8
is generally initiated by the host, the management system should avoid
9ae3a8
initiating any balloon instructions to the guest during migration,
9ae3a8
although it's not possible to know how long it would take a guest to
9ae3a8
process a request made prior to the start of migration.
9ae3a8
Guest initiated ballooning will not know if it's really freed a page
9ae3a8
of host memory or not.
9ae3a8
9ae3a8
Queueing the requests until after migration would be nice, but is
9ae3a8
non-trivial, since the set of inflate/deflate requests have to
9ae3a8
be compared with the state of the page to know what the final
9ae3a8
outcome is allowed to be.
9ae3a8
9ae3a8
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
9ae3a8
Reviewed-by: Juan Quintela <quintela@redhat.com>
9ae3a8
Reviewed-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
(cherry picked from commit 371ff5a3f04cd7d05bab49ac6e80da319026d95b)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 balloon.c                  | 11 +++++++++++
9ae3a8
 hw/virtio/virtio-balloon.c |  4 +++-
9ae3a8
 include/sysemu/balloon.h   |  2 ++
9ae3a8
 3 files changed, 16 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/balloon.c b/balloon.c
9ae3a8
index e321f2c..c7a0cf1 100644
9ae3a8
--- a/balloon.c
9ae3a8
+++ b/balloon.c
9ae3a8
@@ -35,6 +35,17 @@
9ae3a8
 static QEMUBalloonEvent *balloon_event_fn;
9ae3a8
 static QEMUBalloonStatus *balloon_stat_fn;
9ae3a8
 static void *balloon_opaque;
9ae3a8
+static bool balloon_inhibited;
9ae3a8
+
9ae3a8
+bool qemu_balloon_is_inhibited(void)
9ae3a8
+{
9ae3a8
+    return balloon_inhibited;
9ae3a8
+}
9ae3a8
+
9ae3a8
+void qemu_balloon_inhibit(bool state)
9ae3a8
+{
9ae3a8
+    balloon_inhibited = state;
9ae3a8
+}
9ae3a8
 
9ae3a8
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
9ae3a8
                              QEMUBalloonStatus *stat_func, void *opaque)
9ae3a8
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
9ae3a8
index 1a60d3c..c9562ef 100644
9ae3a8
--- a/hw/virtio/virtio-balloon.c
9ae3a8
+++ b/hw/virtio/virtio-balloon.c
9ae3a8
@@ -34,9 +34,11 @@
9ae3a8
 static void balloon_page(void *addr, int deflate)
9ae3a8
 {
9ae3a8
 #if defined(__linux__)
9ae3a8
-    if (!kvm_enabled() || kvm_has_sync_mmu())
9ae3a8
+    if (!qemu_balloon_is_inhibited() && (!kvm_enabled() ||
9ae3a8
+                                         kvm_has_sync_mmu())) {
9ae3a8
         qemu_madvise(addr, TARGET_PAGE_SIZE,
9ae3a8
                 deflate ? QEMU_MADV_WILLNEED : QEMU_MADV_DONTNEED);
9ae3a8
+    }
9ae3a8
 #endif
9ae3a8
 }
9ae3a8
 
9ae3a8
diff --git a/include/sysemu/balloon.h b/include/sysemu/balloon.h
9ae3a8
index bd9d395..eb5af19 100644
9ae3a8
--- a/include/sysemu/balloon.h
9ae3a8
+++ b/include/sysemu/balloon.h
9ae3a8
@@ -23,6 +23,8 @@ typedef void (QEMUBalloonStatus)(void *opaque, BalloonInfo *info);
9ae3a8
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
9ae3a8
 			     QEMUBalloonStatus *stat_func, void *opaque);
9ae3a8
 void qemu_remove_balloon_handler(void *opaque);
9ae3a8
+bool qemu_balloon_is_inhibited(void);
9ae3a8
+void qemu_balloon_inhibit(bool state);
9ae3a8
 
9ae3a8
 void qemu_balloon_changed(int64_t actual);
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8