From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH] KVM: Don't automatically expose the TSC deadline timer in cpuid Date: Sun, 25 Dec 2011 19:39:04 +0100 Message-ID: <4EF76DC8.1020509@web.de> References: <1324818200-15660-1-git-send-email-avi@redhat.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFB7ADA003531F4F80369A9A1" Cc: Alexey Zaytsev , Marcelo Tosatti , jinsong.liu@intel.com, kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from fmmailgate04.web.de ([217.72.192.242]:36774 "EHLO fmmailgate04.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752824Ab1LYSjS (ORCPT ); Sun, 25 Dec 2011 13:39:18 -0500 Received: from moweb002.kundenserver.de (moweb002.kundenserver.de [172.19.20.108]) by fmmailgate04.web.de (Postfix) with ESMTP id 08762700998B for ; Sun, 25 Dec 2011 19:39:10 +0100 (CET) In-Reply-To: <1324818200-15660-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFB7ADA003531F4F80369A9A1 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable On 2011-12-25 14:03, Avi Kivity wrote: > From: Jan Kiszka >=20 > Unlike all of the other cpuid bits, the TSC deadline timer bit is set > unconditionally, regardless of what userspace wants. >=20 > This is broken in several ways: > - if userspace doesn't use KVM_CREATE_IRQCHIP, and doesn't emulate the= TSC > deadline timer feature, a guest that uses the feature will break > - live migration to older host kernels that don't support the TSC dead= line > timer will cause the feature to be pulled from under the guest's fee= t; > breaking it > - guests that are broken wrt the feature will fail. >=20 > Fix by not enabling the feature automatically; instead report it to use= rspace. > Because the feature depends on KVM_CREATE_IRQCHIP, which we cannot guar= antee > will be called, we expose it via a KVM_CAP_TSC_DEADLINE_TIMER and not > KVM_GET_SUPPORTED_CPUID. >=20 > Fixes the Illumos guest kernel, which uses the TSC deadline timer featu= re. >=20 > [avi: add the KVM_CAP + documentation] >=20 > Reported-by: Alexey Zaytsev > Signed-off-by: Avi Kivity > --- >=20 > As we're running out of time and everyone's checking their socks instea= d of > inboxes I've added the missing parts myself. Jan, if you accidentally = see > this, please review and add your signoff. I'm sorry for not holding my promise, was distracted the past days. Patch looks good to me, just some minor phrasing corrections below. Signed-off-by; Jan Kiszka >=20 > Documentation/virtual/kvm/api.txt | 9 +++++++++ > arch/x86/kvm/cpuid.c | 16 ++++++---------- > arch/x86/kvm/x86.c | 3 +++ > include/linux/kvm.h | 1 + > 4 files changed, 19 insertions(+), 10 deletions(-) >=20 > diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/= kvm/api.txt > index 5b03eee..da1f8fd 100644 > --- a/Documentation/virtual/kvm/api.txt > +++ b/Documentation/virtual/kvm/api.txt > @@ -1100,6 +1100,15 @@ emulate them efficiently. The fields in each ent= ry are defined as follows: > eax, ebx, ecx, edx: the values returned by the cpuid instruction fo= r > this function/index combination > =20 > +The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always retur= ned > +as false, since the feature depends on KVM_CREATE_IRQCHIP for local AP= IC > +support. Instead it is reported via > + > + ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER) > + > +if that returns true you use KVM_CREATE_IRQCHIP, or if emulate the ^^^ ^^^ and you > +feature in userspace, then you can enable the feature for KVM_SET_CPUI= D2. > + > 4.47 KVM_PPC_GET_PVINFO > =20 > Capability: KVM_CAP_PPC_GET_PVINFO > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 230f713..89b02bf 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -27,7 +27,6 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu) > { > struct kvm_cpuid_entry2 *best; > struct kvm_lapic *apic =3D vcpu->arch.apic; > - u32 timer_mode_mask; > =20 > best =3D kvm_find_cpuid_entry(vcpu, 1, 0); > if (!best) > @@ -40,15 +39,12 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu) > best->ecx |=3D bit(X86_FEATURE_OSXSAVE); > } > =20 > - if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL && > - best->function =3D=3D 0x1) { > - best->ecx |=3D bit(X86_FEATURE_TSC_DEADLINE_TIMER); > - timer_mode_mask =3D 3 << 17; > - } else > - timer_mode_mask =3D 1 << 17; > - > - if (apic) > - apic->lapic_timer.timer_mode_mask =3D timer_mode_mask; > + if (apic) { > + if (best->ecx & bit(X86_FEATURE_TSC_DEADLINE_TIMER)) > + apic->lapic_timer.timer_mode_mask =3D 3 << 17; > + else > + apic->lapic_timer.timer_mode_mask =3D 1 << 17; > + } > =20 > kvm_pmu_cpuid_update(vcpu); > } > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index df23dff..1171def 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2089,6 +2089,9 @@ int kvm_dev_ioctl_check_extension(long ext) > case KVM_CAP_TSC_CONTROL: > r =3D kvm_has_tsc_control; > break; > + case KVM_CAP_TSC_DEADLINE_TIMER: > + r =3D boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER); > + break; > default: > r =3D 0; > break; > diff --git a/include/linux/kvm.h b/include/linux/kvm.h > index c3892fc..68e67e5 100644 > --- a/include/linux/kvm.h > +++ b/include/linux/kvm.h > @@ -557,6 +557,7 @@ struct kvm_ppc_pvinfo { > #define KVM_CAP_MAX_VCPUS 66 /* returns max vcpus per vm */ > #define KVM_CAP_PPC_PAPR 68 > #define KVM_CAP_S390_GMAP 71 > +#define KVM_CAP_TSC_DEADLINE_TIMER 72 > =20 > #ifdef KVM_CAP_IRQ_ROUTING > =20 Thanks, Jan --------------enigFB7ADA003531F4F80369A9A1 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk73bcsACgkQitSsb3rl5xQobACdFYa+318bufnmc2916pPIJeB8 l9QAoMKeXrvxwG7doEPX2pDDIn3pGuX7 =pVgz -----END PGP SIGNATURE----- --------------enigFB7ADA003531F4F80369A9A1--