From: Thomas Gleixner <tglx@linutronix.de>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>, X86 ML <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
devel@linuxdriverproject.org,
Linux Virtualization <virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH v2 0/3] x86/vdso: Add Hyper-V TSC page clocksource support
Date: Thu, 16 Feb 2017 18:50:58 +0100 (CET) [thread overview]
Message-ID: <alpine.DEB.2.20.1702161832020.3543@nanos> (raw)
In-Reply-To: <87y3x7zh6h.fsf@vitty.brq.redhat.com>
On Wed, 15 Feb 2017, Vitaly Kuznetsov wrote:
> Actually, we already have an implementation of TSC page update in KVM
> (see arch/x86/kvm/hyperv.c, kvm_hv_setup_tsc_page()) and the update does
> the following:
>
> 0) stash seq into seq_prev
> 1) seq = 0 making all reads from the page invalid
> 2) smp_wmb()
> 3) update tsc_scale, tsc_offset
> 4) smp_wmb()
> 5) set seq = seq_prev + 1
I hope they handle the case where seq_prev overflows and becomes 0 :)
> As far as I understand this helps with situations you described above as
> guest will notice either invalid value of 0 or seq change. In case the
> implementation in real Hyper-V is the same we're safe with compile
> barriers only.
On x86 that's correct. smp_rmb() resolves to barrier(), but you certainly
need the smp_wmb() on the writer side.
Now looking at the above your reader side code is bogus:
+ while (1) {
+ sequence = tsc_pg->tsc_sequence;
+ if (!sequence)
+ break;
Why would you break out of the loop when seq is 0? The 0 is just telling
you that there is an update in progress.
The Linux seqcount writer side is:
seq++;
smp_wmb();
update...
smp_wmb();
seq++;
and it's defined that an odd sequence count, i.e. bit 0 set means update in
progress. Which is nice, because you don't have to treat 0 special on the
writer side and you don't need extra storage to stash seq away :)
So the reader side does:
do {
while (1) {
s = READ_ONCE(seq);
if (!(s & 0x01))
break;
cpu_relax();
}
smp_rmb();
read data ...
smp_rmb();
} while (s != seq)
So for that hyperv thing you want:
do {
while (1) {
s = READ_ONCE(seq);
if (s)
break;
cpu_relax();
}
smp_rmb();
read data ...
smp_rmb();
} while (s != seq)
Thanks,
tglx
next prev parent reply other threads:[~2017-02-16 17:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-14 12:44 [PATCH v2 0/3] x86/vdso: Add Hyper-V TSC page clocksource support Vitaly Kuznetsov
2017-02-14 12:44 ` [PATCH v2 1/3] x86/hyperv: implement hv_get_tsc_page() Vitaly Kuznetsov
2017-02-14 12:44 ` [PATCH v2 2/3] x86/hyperv: move TSC reading method to asm/mshyperv.h Vitaly Kuznetsov
2017-02-14 12:44 ` [PATCH v2 3/3] x86/vdso: Add VCLOCK_HVCLOCK vDSO clock read method Vitaly Kuznetsov
2017-02-14 14:46 ` [PATCH v2 0/3] x86/vdso: Add Hyper-V TSC page clocksource support KY Srinivasan via Virtualization
2017-02-14 14:56 ` Thomas Gleixner
2017-02-14 15:50 ` Vitaly Kuznetsov
2017-02-14 17:34 ` Andy Lutomirski
2017-02-15 14:01 ` Vitaly Kuznetsov
2017-02-16 17:50 ` Thomas Gleixner [this message]
2017-02-17 10:14 ` Vitaly Kuznetsov
[not found] ` <87tw7txgx9.fsf@vitty.brq.redhat.com>
2017-02-17 10:35 ` Thomas Gleixner
2017-02-17 17:02 ` Andy Lutomirski
[not found] ` <CALCETrXB8CufQujLAg6bbq=DGAMUE293CF7L4Kp+mCSoNWyuBg@mail.gmail.com>
2017-02-17 17:55 ` Thomas Gleixner
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=alpine.DEB.2.20.1702161832020.3543@nanos \
--to=tglx@linutronix.de \
--cc=devel@linuxdriverproject.org \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=sthemmin@microsoft.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
/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