From: Paolo Bonzini <pbonzini@redhat.com>
To: rhett <rhett.kernel@gmail.com>,
rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com,
hpa@zytor.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM:Hyper-V reduce one kvm_write_guest operation
Date: Wed, 20 Dec 2017 10:01:14 +0100 [thread overview]
Message-ID: <1c25be48-32a2-4ec3-d396-a52cbda568e2@redhat.com> (raw)
In-Reply-To: <d1e55d03-1a21-e42b-8d10-af55e67eb567@gmail.com>
On 20/12/2017 08:46, rhett wrote:
> in function kvm_hv_setup_tsc_page , the old code write the full tsc_ref
> struct firstly, and write a
> tsc_sequence field later, it can be wirten once.
No, it cannot and this comment says exactly why:
> - /* Ensure sequence is zero before writing the rest of the struct. */
> - smp_wmb();
> - if (kvm_write_guest(kvm, gfn_to_gpa(gfn), &hv->tsc_ref,
> sizeof(hv->tsc_ref)))
> - goto out_unlock;
> -
> /*
> * Now switch to the TSC page mechanism by writing the sequence.
> */
The sequence is: disable TSC page, write TSC parameters, enable TSC
page. If the guest can read a partially-written TSC page, it can return
a wrong time.
Paolo
> @@ -922,7 +917,7 @@ void kvm_hv_setup_tsc_page(struct kvm *kvm,
>
> hv->tsc_ref.tsc_sequence = tsc_seq;
> kvm_write_guest(kvm, gfn_to_gpa(gfn),
> - &hv->tsc_ref, sizeof(hv->tsc_ref.tsc_sequence));
> + &hv->tsc_ref, sizeof(hv->tsc_ref));
> out_unlock:
> mutex_unlock(&kvm->arch.hyperv.hv_lock);
> }
> --
> 1.8.3.1
>
next parent reply other threads:[~2017-12-20 9:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <d1e55d03-1a21-e42b-8d10-af55e67eb567@gmail.com>
2017-12-20 9:01 ` Paolo Bonzini [this message]
[not found] ` <CABvbLL00cQP4Xbgz7T-4WqRu6Ar8dWBLtuTqgvadeaahsUMowg@mail.gmail.com>
2017-12-20 9:45 ` Paolo Bonzini
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=1c25be48-32a2-4ec3-d396-a52cbda568e2@redhat.com \
--to=pbonzini@redhat.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rhett.kernel@gmail.com \
--cc=rkrcmar@redhat.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®