9ae3a8
From 2462c7df4513e298596559627c61108e13809470 Mon Sep 17 00:00:00 2001
9ae3a8
From: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Date: Fri, 5 Sep 2014 12:30:38 +0200
9ae3a8
Subject: [PATCH 04/12] qemu: Adjust qemu wakeup
9ae3a8
9ae3a8
Message-id: <1409920238-9070-5-git-send-email-kraxel@redhat.com>
9ae3a8
Patchwork-id: 60872
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH 4/4] qemu: Adjust qemu wakeup
9ae3a8
Bugzilla: 1064156
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
9ae3a8
From: "Liu, Jinsong" <jinsong.liu@intel.com>
9ae3a8
9ae3a8
Currently Xen hvm s3 has a bug coming from the difference between
9ae3a8
qemu-traditioanl and qemu-xen. For qemu-traditional, the way to
9ae3a8
resume from hvm s3 is via 'xl trigger' command. However, for
9ae3a8
qemu-xen, the way to resume from hvm s3 inherited from standard
9ae3a8
qemu, i.e. via QMP, and it doesn't work under Xen.
9ae3a8
9ae3a8
The root cause is, for qemu-xen, 'xl trigger' command didn't reset
9ae3a8
devices, while QMP didn't unpause hvm domain though they did qemu
9ae3a8
system reset.
9ae3a8
9ae3a8
We have two qemu patches and one xl patch to fix Xen hvm s3 bug.
9ae3a8
This patch is the qemu patch 1. It adjusts qemu wakeup so that
9ae3a8
Xen s3 resume logic (which will be implemented at qemu patch 2)
9ae3a8
will be notified after qemu system reset.
9ae3a8
9ae3a8
Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
9ae3a8
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
9ae3a8
(cherry picked from commit 4bc78a877252d772b983810a7d2c0be00e9be70e)
9ae3a8
---
9ae3a8
 hw/acpi/core.c          |  3 ++-
9ae3a8
 include/sysemu/sysemu.h |  4 +++-
9ae3a8
 vl.c                    | 15 +++++++--------
9ae3a8
 3 files changed, 12 insertions(+), 10 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/acpi/core.c          |    3 ++-
9ae3a8
 include/sysemu/sysemu.h |    4 +++-
9ae3a8
 vl.c                    |   15 +++++++--------
9ae3a8
 3 files changed, 12 insertions(+), 10 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
9ae3a8
index 3352d17..88efba7 100644
9ae3a8
--- a/hw/acpi/core.c
9ae3a8
+++ b/hw/acpi/core.c
9ae3a8
@@ -364,12 +364,13 @@ static void acpi_notify_wakeup(Notifier *notifier, void *data)
9ae3a8
             (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_TIMER_STATUS);
9ae3a8
         break;
9ae3a8
     case QEMU_WAKEUP_REASON_OTHER:
9ae3a8
-    default:
9ae3a8
         /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
9ae3a8
            Pretend that resume was caused by power button */
9ae3a8
         ar->pm1.evt.sts |=
9ae3a8
             (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS);
9ae3a8
         break;
9ae3a8
+    default:
9ae3a8
+        break;
9ae3a8
     }
9ae3a8
 }
9ae3a8
 
9ae3a8
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
9ae3a8
index 07181ac..3e457b8 100644
9ae3a8
--- a/include/sysemu/sysemu.h
9ae3a8
+++ b/include/sysemu/sysemu.h
9ae3a8
@@ -42,9 +42,11 @@ int vm_stop(RunState state);
9ae3a8
 int vm_stop_force_state(RunState state);
9ae3a8
 
9ae3a8
 typedef enum WakeupReason {
9ae3a8
-    QEMU_WAKEUP_REASON_OTHER = 0,
9ae3a8
+    /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
9ae3a8
+    QEMU_WAKEUP_REASON_NONE = 0,
9ae3a8
     QEMU_WAKEUP_REASON_RTC,
9ae3a8
     QEMU_WAKEUP_REASON_PMTIMER,
9ae3a8
+    QEMU_WAKEUP_REASON_OTHER,
9ae3a8
 } WakeupReason;
9ae3a8
 
9ae3a8
 void qemu_system_reset_request(void);
9ae3a8
diff --git a/vl.c b/vl.c
9ae3a8
index fcc8fd1..7c1b9d2 100644
9ae3a8
--- a/vl.c
9ae3a8
+++ b/vl.c
9ae3a8
@@ -1690,14 +1690,14 @@ static pid_t shutdown_pid;
9ae3a8
 static int powerdown_requested;
9ae3a8
 static int debug_requested;
9ae3a8
 static int suspend_requested;
9ae3a8
-static int wakeup_requested;
9ae3a8
+static WakeupReason wakeup_reason;
9ae3a8
 static NotifierList powerdown_notifiers =
9ae3a8
     NOTIFIER_LIST_INITIALIZER(powerdown_notifiers);
9ae3a8
 static NotifierList suspend_notifiers =
9ae3a8
     NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
9ae3a8
 static NotifierList wakeup_notifiers =
9ae3a8
     NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
9ae3a8
-static uint32_t wakeup_reason_mask = ~0;
9ae3a8
+static uint32_t wakeup_reason_mask = ~(1 << QEMU_WAKEUP_REASON_NONE);
9ae3a8
 static RunState vmstop_requested = RUN_STATE_MAX;
9ae3a8
 
9ae3a8
 int qemu_shutdown_requested_get(void)
9ae3a8
@@ -1747,11 +1747,9 @@ static int qemu_suspend_requested(void)
9ae3a8
     return r;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int qemu_wakeup_requested(void)
9ae3a8
+static WakeupReason qemu_wakeup_requested(void)
9ae3a8
 {
9ae3a8
-    int r = wakeup_requested;
9ae3a8
-    wakeup_requested = 0;
9ae3a8
-    return r;
9ae3a8
+    return wakeup_reason;
9ae3a8
 }
9ae3a8
 
9ae3a8
 static int qemu_powerdown_requested(void)
9ae3a8
@@ -1868,8 +1866,7 @@ void qemu_system_wakeup_request(WakeupReason reason)
9ae3a8
         return;
9ae3a8
     }
9ae3a8
     runstate_set(RUN_STATE_RUNNING);
9ae3a8
-    notifier_list_notify(&wakeup_notifiers, &reason);
9ae3a8
-    wakeup_requested = 1;
9ae3a8
+    wakeup_reason = reason;
9ae3a8
     qemu_notify_event();
9ae3a8
 }
9ae3a8
 
9ae3a8
@@ -1961,6 +1958,8 @@ static bool main_loop_should_exit(void)
9ae3a8
         pause_all_vcpus();
9ae3a8
         cpu_synchronize_all_states();
9ae3a8
         qemu_system_reset(VMRESET_SILENT);
9ae3a8
+        notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
9ae3a8
+        wakeup_reason = QEMU_WAKEUP_REASON_NONE;
9ae3a8
         resume_all_vcpus();
9ae3a8
         monitor_protocol_event(QEVENT_WAKEUP, NULL);
9ae3a8
     }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8