public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Stamatis, Ilias" <ilstam@amazon.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Cc: "jmattson@google.com" <jmattson@google.com>,
	"Woodhouse, David" <dwmw@amazon.co.uk>,
	"vkuznets@redhat.com" <vkuznets@redhat.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"mtosatti@redhat.com" <mtosatti@redhat.com>,
	"zamsden@gmail.com" <zamsden@gmail.com>,
	"seanjc@google.com" <seanjc@google.com>,
	"mlevitsk@redhat.com" <mlevitsk@redhat.com>,
	"wanpengli@tencent.com" <wanpengli@tencent.com>
Subject: Re: [PATCH v4 09/11] KVM: X86: Add vendor callbacks for writing the TSC multiplier
Date: Fri, 28 May 2021 10:44:51 +0000	[thread overview]
Message-ID: <6af2f61ff6a1a0dc83690bb39f4e3270174264f4.camel@amazon.com> (raw)
In-Reply-To: <9e971115-5634-e64e-72b6-5e41c024c796@redhat.com>

On Thu, 2021-05-27 at 15:08 +0200, Paolo Bonzini wrote:
> On 27/05/21 10:33, Stamatis, Ilias wrote:
> > >   #ifdef CONFIG_X86_64
> > > @@ -10444,6 +10461,7 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
> > >              return;
> > >      vcpu_load(vcpu);
> > >      kvm_synchronize_tsc(vcpu, 0);
> > > +    kvm_vcpu_write_tsc_multiplier(vcpu, kvm_default_tsc_scaling_ratio);
> > 
> > Hmm, I'm actually thinking now that this might not be correct. For example in
> > case we hotplug a new vCPU but the other vCPUs don't use the default ratio.
> 
> It is correct, the TSC frequency can be set per CPU (which is useless
> except possibly for debugging OS timekeeping, but still).  So, the
> default kHz after hotplug is the host frequency.
> 
> It doesn't really matter because it only affects the fixed delta between
> the hotplugged CPU and the others as soon as userspace sets the
> frequency to the correct value.
> 
> Paolo
> 

So this patch is wrong anyway. 

kvm_arch_vcpu_create() does a kvm_set_tsc_khz(vcpu, max_tsc_khz) when
initializing the vcpu. This wouldn't normally result in a VMWRITE, but now
(after applying patch 9) it does. The problem is that this write now happens too
early and it raises an exception. To fix this, that line needs to be moved to
kvm_arch_vcpu_postcreate() (like above) but before calling
kvm_synchronize_tsc(vcpu, 0).

I will re-submit this patch with the fix.

Best,
Ilias



  reply	other threads:[~2021-05-28 10:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26 18:44 [PATCH v4 00/11] KVM: Implement nested TSC scaling Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 01/11] math64.h: Add mul_s64_u64_shr() Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 02/11] KVM: X86: Store L1's TSC scaling ratio in 'struct kvm_vcpu_arch' Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 03/11] KVM: X86: Rename kvm_compute_tsc_offset() to kvm_compute_l1_tsc_offset() Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 04/11] KVM: X86: Add a ratio parameter to kvm_scale_tsc() Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 05/11] KVM: nVMX: Add a TSC multiplier field in VMCS12 Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 06/11] KVM: X86: Add functions for retrieving L2 TSC fields from common code Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 07/11] KVM: X86: Add functions that calculate the nested TSC fields Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 08/11] KVM: X86: Move write_l1_tsc_offset() logic to common code and rename it Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 09/11] KVM: X86: Add vendor callbacks for writing the TSC multiplier Ilias Stamatis
2021-05-27  8:33   ` Stamatis, Ilias
2021-05-27 13:08     ` Paolo Bonzini
2021-05-28 10:44       ` Stamatis, Ilias [this message]
2021-05-26 18:44 ` [PATCH v4 10/11] KVM: nVMX: Enable nested TSC scaling Ilias Stamatis
2021-05-26 18:44 ` [PATCH v4 11/11] KVM: selftests: x86: Add vmx_nested_tsc_scaling_test Ilias Stamatis
2021-06-15  8:44 ` [PATCH v4 00/11] KVM: Implement nested TSC scaling Stamatis, Ilias
2021-06-15  9:33   ` Stamatis, Ilias

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=6af2f61ff6a1a0dc83690bb39f4e3270174264f4.camel@amazon.com \
    --to=ilstam@amazon.com \
    --cc=dwmw@amazon.co.uk \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=zamsden@gmail.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