From 004171b9879af86d3c14654d0080b5559ee48267 Mon Sep 17 00:00:00 2001
Message-Id: <004171b9879af86d3c14654d0080b5559ee48267.1345545736.git.minovotn@redhat.com>
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 1 Aug 2012 07:34:23 +0200
Subject: [PATCH 1/8] kvmclock: guest stop notification
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

RH-Author: Amit Shah <amit.shah@redhat.com>
Message-id: <fa2c93031478ff374f7e3848cd7b2203b19b2046.1343806250.git.amit.shah@redhat.com>
Patchwork-id: 40488
O-Subject: [RHEL6 qemu PATCH 1/1] kvmclock: guest stop notification
Bugzilla: 831614
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Amos Kong <akong@redhat.com>

From: Eric B Munson <emunson@mgebm.net>

Often when a guest is stopped from the qemu console, it will report spurious
soft lockup warnings on resume.  There are kernel patches being discussed that
will give the host the ability to tell the guest that it is being stopped and
should ignore the soft lockup warning that generates.  This patch uses the qemu
Notifier system to tell the guest it is about to be stopped.

Signed-off-by: Eric B Munson <emunson@mgebm.net>
Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
(cherry picked from commit f349c12c0434e29c79ecde89029320c4002f7253)

Bugzilla: 831614

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/kvmclock.c           |   16 ++++++++++++++++
 kvm/include/linux/kvm.h |    2 ++
 2 files changed, 18 insertions(+), 0 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 hw/kvmclock.c           | 16 ++++++++++++++++
 kvm/include/linux/kvm.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/hw/kvmclock.c b/hw/kvmclock.c
index 39dffb2..e90d61f 100644
--- a/hw/kvmclock.c
+++ b/hw/kvmclock.c
@@ -66,9 +66,25 @@ static int kvmclock_post_load(void *opaque, int version_id)
 static void kvmclock_vm_state_change(void *opaque, int running, RunState state)
 {
     KVMClockState *s = opaque;
+    CPUState *penv = first_cpu;
+    int cap_clock_ctrl = kvm_check_extension(kvm_state, KVM_CAP_KVMCLOCK_CTRL);
+    int ret;
 
     if (running) {
         s->clock_valid = false;
+
+        if (!cap_clock_ctrl) {
+            return;
+        }
+        for (penv = first_cpu; penv != NULL; penv = penv->next_cpu) {
+            ret = kvm_vcpu_ioctl(penv, KVM_KVMCLOCK_CTRL, 0);
+            if (ret) {
+                if (ret != -EINVAL) {
+                    fprintf(stderr, "%s: %s\n", __func__, strerror(-ret));
+                }
+                return;
+            }
+        }
     }
 }
 
diff --git a/kvm/include/linux/kvm.h b/kvm/include/linux/kvm.h
index e61104e..f566e7b 100644
--- a/kvm/include/linux/kvm.h
+++ b/kvm/include/linux/kvm.h
@@ -530,6 +530,7 @@ struct kvm_enable_cap {
 #ifdef __KVM_HAVE_XCRS
 #define KVM_CAP_XCRS 56
 #endif
+#define KVM_CAP_KVMCLOCK_CTRL 76
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -726,6 +727,7 @@ struct kvm_clock_data {
 /* Available with KVM_CAP_XCRS */
 #define KVM_GET_XCRS		  _IOR(KVMIO,  0xa6, struct kvm_xcrs)
 #define KVM_SET_XCRS		  _IOW(KVMIO,  0xa7, struct kvm_xcrs)
+#define KVM_KVMCLOCK_CTRL	  _IO(KVMIO,   0xad)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
 
-- 
1.7.11.2

