kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Roman Kagan" <rkagan@virtuozzo.com>,
	kvm@vger.kernel.org, "Radim Krčmář" <rkrcmar@redhat.com>,
	"Denis V. Lunev" <den@openvz.org>,
	"Luiz Capitulino" <lcapitulino@redhat.com>
Subject: Re: [PATCH] KVM:x86: avoid VMCS access from non-vCPU context
Date: Thu, 3 Nov 2016 18:10:00 +0100	[thread overview]
Message-ID: <b3f5a46c-9171-bfd8-ae5d-a8efbebaf978@redhat.com> (raw)
In-Reply-To: <20161103141737.GA31710@rkaganb.sw.ru>



On 03/11/2016 15:17, Roman Kagan wrote:
> On Mon, Oct 31, 2016 at 07:31:53PM -0400, Paolo Bonzini wrote:
>>
>>> In commit 108b249c453dd7132599ab6dc7e435a7036c193f, "KVM: x86: introduce
>>> get_kvmclock_ns", a function to obtain the time as would be done by the
>>> guest via kvmclock was introduced and used throughout the code.
>>>
>>> The problem is that it reads the guest TSC value via kvm_read_l1_tsc
>>> which can only be called in vCPU context as it reads VMCS(TSC_OFFSET)
>>> directly (on Intel CPUs).  Therefore, when called in kvm_arch_vm_ioctl
>>> for KVM_[GS]ET_CLOCK, it returns bogus values, breaking save/restore.
>>
>> The patch isn't good unfortunately, because only __get_kvmclock_ns
>> can return the pvclock value.
> 
> Agreed.
> 
>> However, after Luiz's commit a545ab6a0085
>> ("kvm: x86: add tsc_offset field to struct kvm_vcpu_arch", 2016-09-07)
>> the TSC offset is cached outside the VMCS/VMCB
> 
> I was tempted to use it but saw it not updated in
> adjust_tsc_offset_* and thought it had some different meaning.
> Apparently that was just a bug which you also fix in your patch by
> making adjust_tsc_offset_guest go through kvm_vcpu_write_tsc_offset.
> 
>> and all the complexity in
>> vmx.c and (to a lesser extent) svm.c can be dropped.  See the following
>> untested patch...
>>
> 
> Consider it
> 
> Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
> Tested-by: Roman Kagan <rkagan@virtuozzo.com>

Too bad, I've already sent out the pull request so I couldn't include
the tags.  But thanks very much for the careful review and for testing!

Paolo

      reply	other threads:[~2016-11-03 17:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-31 17:12 [PATCH] KVM:x86: avoid VMCS access from non-vCPU context Roman Kagan
2016-10-31 23:31 ` Paolo Bonzini
2016-11-03 14:17   ` Roman Kagan
2016-11-03 17:10     ` Paolo Bonzini [this message]

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=b3f5a46c-9171-bfd8-ae5d-a8efbebaf978@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=den@openvz.org \
    --cc=kvm@vger.kernel.org \
    --cc=lcapitulino@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;
as well as URLs for NNTP newsgroup(s).