From 4c1361e2dfac092c94077a20610087871c7878f4 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Mon, 3 Dec 2018 21:54:25 +0100 Subject: [PATCH 24/34] postcopy: Synchronize usage of the balloon inhibitor RH-Author: Alex Williamson Message-id: <154387406568.26945.10032109321234466443.stgit@gimli.home> Patchwork-id: 83233 O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 7/7] postcopy: Synchronize usage of the balloon inhibitor Bugzilla: 1619778 RH-Acked-by: Peter Xu RH-Acked-by: Cornelia Huck RH-Acked-by: Auger Eric RH-Acked-by: David Hildenbrand Bugzilla: 1619778 While the qemu_balloon_inhibit() interface appears rather general purpose, postcopy uses it in a last-caller-wins approach with no guarantee of balanced inhibits and de-inhibits. Wrap postcopy's usage of the inhibitor to give it one vote overall, using the same last-caller-wins approach as previously implemented at the balloon level. Fixes: 01ccbec7bdf6 ("balloon: Allow multiple inhibit users") Reported-by: Christian Borntraeger Tested-by: Christian Borntraeger Reviewed-by: Cornelia Huck Reviewed-by: Juan Quintela Signed-off-by: Alex Williamson (cherry picked from commit 154304cd6e99e4222ed762976f9d9aca33c094d3) Signed-off-by: Miroslav Rezanina --- migration/postcopy-ram.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 001b041..4b65ff9 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -400,6 +400,20 @@ int postcopy_ram_incoming_init(MigrationIncomingState *mis, size_t ram_pages) } /* + * Manage a single vote to the QEMU balloon inhibitor for all postcopy usage, + * last caller wins. + */ +static void postcopy_balloon_inhibit(bool state) +{ + static bool cur_state = false; + + if (state != cur_state) { + qemu_balloon_inhibit(state); + cur_state = state; + } +} + +/* * At the end of a migration where postcopy_ram_incoming_init was called. */ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) @@ -429,7 +443,7 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) mis->have_fault_thread = false; } - qemu_balloon_inhibit(false); + postcopy_balloon_inhibit(false); if (enable_mlock) { if (os_mlock() < 0) { @@ -801,7 +815,7 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis) * Ballooning can mark pages as absent while we're postcopying * that would cause false userfaults. */ - qemu_balloon_inhibit(true); + postcopy_balloon_inhibit(true); trace_postcopy_ram_enable_notify(); -- 1.8.3.1