All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Avi Kivity <avi@redhat.com>
Cc: Alexey Zaytsev <alexey.zaytsev@gmail.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	jinsong.liu@intel.com, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: Don't automatically expose the TSC deadline timer in cpuid
Date: Sun, 25 Dec 2011 19:39:04 +0100	[thread overview]
Message-ID: <4EF76DC8.1020509@web.de> (raw)
In-Reply-To: <1324818200-15660-1-git-send-email-avi@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4810 bytes --]

On 2011-12-25 14:03, Avi Kivity wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> Unlike all of the other cpuid bits, the TSC deadline timer bit is set
> unconditionally, regardless of what userspace wants.
> 
> 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 deadline
>    timer will cause the feature to be pulled from under the guest's feet;
>    breaking it
>  - guests that are broken wrt the feature will fail.
> 
> Fix by not enabling the feature automatically; instead report it to userspace.
> Because the feature depends on KVM_CREATE_IRQCHIP, which we cannot guarantee
> will be called, we expose it via a KVM_CAP_TSC_DEADLINE_TIMER and not
> KVM_GET_SUPPORTED_CPUID.
> 
> Fixes the Illumos guest kernel, which uses the TSC deadline timer feature.
> 
> [avi: add the KVM_CAP + documentation]
> 
> Reported-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
> 
> As we're running out of time and everyone's checking their socks instead 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 <jan.kiszka@siemens.com>

> 
>  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(-)
> 
> 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 entry are defined as follows:
>     eax, ebx, ecx, edx: the values returned by the cpuid instruction for
>           this function/index combination
>  
> +The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
> +as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
> +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_CPUID2.
> +
>  4.47 KVM_PPC_GET_PVINFO
>  
>  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 = vcpu->arch.apic;
> -	u32 timer_mode_mask;
>  
>  	best = kvm_find_cpuid_entry(vcpu, 1, 0);
>  	if (!best)
> @@ -40,15 +39,12 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu)
>  			best->ecx |= bit(X86_FEATURE_OSXSAVE);
>  	}
>  
> -	if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
> -		best->function == 0x1) {
> -		best->ecx |= bit(X86_FEATURE_TSC_DEADLINE_TIMER);
> -		timer_mode_mask = 3 << 17;
> -	} else
> -		timer_mode_mask = 1 << 17;
> -
> -	if (apic)
> -		apic->lapic_timer.timer_mode_mask = timer_mode_mask;
> +	if (apic) {
> +		if (best->ecx & bit(X86_FEATURE_TSC_DEADLINE_TIMER))
> +			apic->lapic_timer.timer_mode_mask = 3 << 17;
> +		else
> +			apic->lapic_timer.timer_mode_mask = 1 << 17;
> +	}
>  
>  	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 = kvm_has_tsc_control;
>  		break;
> +	case KVM_CAP_TSC_DEADLINE_TIMER:
> +		r = boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER);
> +		break;
>  	default:
>  		r = 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
>  
>  #ifdef KVM_CAP_IRQ_ROUTING
>  

Thanks,
Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

  reply	other threads:[~2011-12-25 18:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-25 13:03 [PATCH] KVM: Don't automatically expose the TSC deadline timer in cpuid Avi Kivity
2011-12-25 18:39 ` Jan Kiszka [this message]
2011-12-26 11:14   ` Avi Kivity
2011-12-25 19:00 ` Sasha Levin
2011-12-25 19:47   ` Sasha Levin
2011-12-26  8:51     ` Liu, Jinsong
2011-12-26  0:44   ` Jan Kiszka
2011-12-26  8:42 ` Liu, Jinsong
2011-12-26 10:35   ` Avi Kivity
2011-12-26 10:43     ` Alexey Zaytsev
2011-12-26 10:45       ` Avi Kivity
2011-12-26 11:25         ` Alexey Zaytsev
2011-12-26 11:28           ` Avi Kivity

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=4EF76DC8.1020509@web.de \
    --to=jan.kiszka@web.de \
    --cc=alexey.zaytsev@gmail.com \
    --cc=avi@redhat.com \
    --cc=jinsong.liu@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.