All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Alexey Zaytsev <alexey.zaytsev@gmail.com>,
	"Liu, Jinsong" <jinsong.liu@intel.com>,
	Avi Kivity <avi@redhat.com>
Cc: Kernel development list <linux-kernel@vger.kernel.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	"Garrett D'Amore" <garrett@nexenta.com>
Subject: [PATCH] KVM: x86: Prevent exposing TSC deadline timer feature in the absence of in-kernel APIC
Date: Wed, 21 Dec 2011 11:10:09 +0100	[thread overview]
Message-ID: <4EF1B081.3010109@siemens.com> (raw)
In-Reply-To: <4EF1146D.208@siemens.com>

On 2011-12-21 00:04, Jan Kiszka wrote:
> On 2011-12-20 19:58, Linus Torvalds wrote:
>> On Tue, Dec 20, 2011 at 1:51 AM, Alexey Zaytsev
>> <alexey.zaytsev@gmail.com> wrote:
>>>
>>> Let me clarify the situation.
>>>
>>> Before this commit, the tsc was advertised in cpuid, and it was
>>> handled, if I understand things correctly, by qemu.
>>> After this commit, the tsc is advertised in cpuid, and is handled in
>>> the kernel, but only after qemu issues KVM_CREATE_IRQCHIP. If it does
>>> not issue the ioctl, the kernel just discards any wrmsrs done to the
>>> tsc. This does not look like an Illumos problem to me. Linux guests
>>> kind of work here, because they are  prepared to work on utterly
>>> broken hardware. Good for you, but please don't break less-prepared
>>> guests.
>>
>> Yes. This is a regression, and needs to be fixed.
>>
>> Liu, if you don't have time to debug it, we'll just revert the commit.
>> It's that easy. Regressions are not allowed. There are no excuses.
>>
>> In particular, saying "just wait for qemu-kvm" is not an acceptable
>> answer, because the point is that things *used* to work, and they
>> broke. No "change it to work with the new kernel" allowed, except for
>> some *very* rare critical circumstances (usually "major security-bug
>> that we had to fix, and people who relied on it are thus out of
>> luck").
>>
>> Commit a3e06bbe8445 still seems to revert cleanly, so that is the easy option.
>>
>> That said, it sounds like maybe another solution is to start with the
>> TSC_DEADLINE timer bit in cpuid cleared, and only setting it after the
>> KVM_CREATE_IRQCHIP ioctl.
> 
> KVM cpuid discovery can (and is) unfortunately be done before user space
> decides about creating an in-kernel irqchip or not. But the patch in
> question suggests to user space that it's optimal and perfectly fine to
> expose TSC_DEADLINE_TIMER to the guest - obviously a wrong suggestion in
> case user space does not use the in-kernel irqchip and does not
> implement the deadline timer in its own APIC model.
> 
> So the only proper solution I see is to drop that feature flag exposure
> from kvm_update_cpuid. Instead, KVM should indicate to *well informed*
> (i.e. updated) user space differently that there is now deadline timer
> support in the in-kernel APIC model. That different channel should be a
> KVM_CAP flag that user space can easily check and then merge the
> necessary flag on its own.
> 
>>
>> In fact, the patch is clearly buggy, in that it apparently doesn't
>> emulate TSC_DEADLINE correctly and natively on its own.
>>
>> Jan, Marcelo, Avi - is there a quick fix, or should I just revert?
> 
> Maybe fixing can be done quickly. In any case, the current ABI should
> not be exposed to user space, even at the price of postponing it's
> introduction. Just my 2 cents, though.

Was obviously too late for me. Here is a more accurate code analysis and
fix proposal:

kvm_update_cpuid is not involved in KVM_GET_SUPPORTED_CPUID as I
thought, thus there is no ABI issue. It should just be trivial bug in
setting the feature flag. Does this help? Untested!

Jan

-------8<-------

We must not report the TSC deadline timer feature on our own when user
space provides the APIC as we have no clue about its features.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 arch/x86/kvm/cpuid.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 230f713..28615f2 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -40,7 +40,7 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu)
 			best->ecx |= bit(X86_FEATURE_OSXSAVE);
 	}
 
-	if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
+	if (apic && boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
 		best->function == 0x1) {
 		best->ecx |= bit(X86_FEATURE_TSC_DEADLINE_TIMER);
 		timer_mode_mask = 3 << 17;
-- 
1.7.3.4

  reply	other threads:[~2011-12-21 10:10 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  0:32 [Regression, bisected] a3e06bbe8445f57eb949e6474c5a9b30f24d2057: KVM: emulate lapic tsc deadline timer for guest" Alexey Zaytsev
2011-12-12  6:13 ` Liu, Jinsong
2011-12-14  9:37   ` Alexey Zaytsev
2011-12-20  8:43     ` Alexey Zaytsev
2011-12-20  8:53       ` Liu, Jinsong
2011-12-20  8:58         ` Alexey Zaytsev
2011-12-20  9:26           ` Liu, Jinsong
2011-12-20  9:48             ` Avi Kivity
2011-12-20  9:51             ` Alexey Zaytsev
2011-12-20 18:58               ` Linus Torvalds
2011-12-20 19:21                 ` Liu, Jinsong
2011-12-20 19:47                   ` Alexey Zaytsev
2011-12-20 20:19                     ` Liu, Jinsong
2011-12-20 20:22                       ` Alexey Zaytsev
2011-12-20 20:26                         ` Liu, Jinsong
2011-12-20 20:36                           ` Alexey Zaytsev
2011-12-20 20:44                             ` Liu, Jinsong
2011-12-21  9:18                   ` Avi Kivity
2011-12-20 23:04                 ` Jan Kiszka
2011-12-21 10:10                   ` Jan Kiszka [this message]
2011-12-21 10:25                     ` [PATCH v2] KVM: x86: Prevent exposing TSC deadline timer feature in the absence of in-kernel APIC Jan Kiszka
2011-12-21 10:35                       ` Avi Kivity
2011-12-21 10:41                         ` Jan Kiszka
2011-12-21 10:44                           ` Avi Kivity
2011-12-21 11:28                             ` Jan Kiszka
2011-12-21 11:28                               ` Jan Kiszka
2011-12-21 11:45                               ` Avi Kivity
2011-12-21 11:45                                 ` Avi Kivity
2011-12-21 11:58                                 ` Jan Kiszka
2011-12-21 11:58                                   ` Jan Kiszka
2011-12-21 12:02                                   ` Avi Kivity
2011-12-21 12:02                                     ` Avi Kivity
2011-12-22 15:41                         ` Liu, Jinsong
2011-12-25 12:37                           ` Avi Kivity
2011-12-25 12:37                             ` Avi Kivity
2011-12-26  8:11                             ` Liu, Jinsong
2011-12-26 11:35                               ` Avi Kivity
2011-12-26 11:35                                 ` Avi Kivity
2011-12-26 14:23                                 ` Liu, Jinsong
2011-12-21 10:41                       ` Alexey Zaytsev
2011-12-20 19:05               ` [Regression, bisected] a3e06bbe8445f57eb949e6474c5a9b30f24d2057: KVM: emulate lapic tsc deadline timer for guest" Liu, Jinsong
2011-12-21  9:20                 ` 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=4EF1B081.3010109@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=alexey.zaytsev@gmail.com \
    --cc=avi@redhat.com \
    --cc=garrett@nexenta.com \
    --cc=jinsong.liu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=torvalds@linux-foundation.org \
    /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.