public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: kvm@vger.kernel.org, rkrcmar@redhat.com
Cc: pbonzini@redhat.com, den@virtuozzo.com, rkagan@virtuozzo.com
Subject: [PATCH v2 10/11] pvclock: add clocksource change notification on changing of tsc stable bit
Date: Fri, 21 Jul 2017 18:45:17 +0300	[thread overview]
Message-ID: <1500651918-14156-11-git-send-email-dplotnikov@virtuozzo.com> (raw)
In-Reply-To: <1500651918-14156-1-git-send-email-dplotnikov@virtuozzo.com>

We going to allow L2 guest to use L1's kvm-clock clocksource, which is
a pvclock clocksource, as a stable one if it's stable in L1.

Therefore, we need to know when L1's kvm-clock becomes stable/unstable
to make it stable/unstable in L2 as well.

Do it, by adding tracking stability flag in pvclock

Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
 arch/x86/kernel/pvclock.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
index ab54c92..c73e5a5 100644
--- a/arch/x86/kernel/pvclock.c
+++ b/arch/x86/kernel/pvclock.c
@@ -22,6 +22,7 @@
 #include <linux/gfp.h>
 #include <linux/bootmem.h>
 #include <linux/nmi.h>
+#include <linux/cs_notifier.h>
 
 #include <asm/fixmap.h>
 #include <asm/pvclock.h>
@@ -73,6 +74,8 @@ u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
 	return flags & valid_flags;
 }
 
+static atomic64_t clocksource_stable = ATOMIC64_INIT(0);
+
 u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src,
 				u64 *cycles_stamp)
 {
@@ -96,10 +99,20 @@ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src,
 		pvclock_touch_watchdogs();
 	}
 
-	if ((valid_flags & PVCLOCK_TSC_STABLE_BIT) &&
-		(flags & PVCLOCK_TSC_STABLE_BIT))
-		return ret;
+	if (likely(valid_flags & PVCLOCK_TSC_STABLE_BIT)) {
+		bool stable_now = !!(flags & PVCLOCK_TSC_STABLE_BIT);
+		bool stable_last = (bool) atomic64_read(&clocksource_stable);
+
+		if (unlikely(stable_now != stable_last)) {
+			/* send notification once */
+			if (stable_last == atomic64_cmpxchg(
+				&clocksource_stable, stable_last, stable_now))
+				clocksource_changes_notify();
+		}
 
+		if (stable_now)
+			return ret;
+	}
 	/*
 	 * Assumption here is that last_value, a global accumulator, always goes
 	 * forward. If we are less than that, we should not be much smaller.
-- 
2.7.4

  parent reply	other threads:[~2017-07-21 15:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 15:45 [PATCH v2 00/11] make L2's kvm-clock stable, get rid of pvclock_gtod Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 01/11] timekeeper: change interface of clocksource reding functions Denis Plotnikov
2017-07-23  4:24   ` kbuild test robot
2017-07-21 15:45 ` [PATCH v2 02/11] pvclock: write cycle stamp value if a pointer given Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 03/11] kvmclock: pass cycles pointer to the changed pvclock interface Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 04/11] TSC: write cycles stamp value to input pointer Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 05/11] timekeeping: change ktime_get_with_offset interface to accept cycles pointer Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 06/11] timekeeping: add functions returning cycle stamp counter along with time Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 07/11] timekeeper: add clocksource change notifier Denis Plotnikov
2017-07-21 15:45 ` [PATCH v2 08/11] timekeeper: add a couple of the core timekeeper reading helpers Denis Plotnikov
2017-07-23  4:02   ` kbuild test robot
2017-07-23  4:02   ` kbuild test robot
2017-07-21 15:45 ` [PATCH v2 09/11] KVM: get rid of pv_clock_gtod Denis Plotnikov
2017-07-25 10:37   ` Paolo Bonzini
2017-07-21 15:45 ` Denis Plotnikov [this message]
2017-07-21 15:45 ` [PATCH v2 11/11] KVM: add pvclock to a list of stable clocks Denis Plotnikov

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=1500651918-14156-11-git-send-email-dplotnikov@virtuozzo.com \
    --to=dplotnikov@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkagan@virtuozzo.com \
    --cc=rkrcmar@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox