qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: kvm@vger.kernel.org
Cc: mst@redhat.com, eddie.dong@intel.com, qemu-devel@nongnu.org,
	agraf@suse.de, alex.williamson@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [RFC PATCH v2] kvm: x86: ignore ioapic polarity
Date: Thu, 27 Feb 2014 23:06:17 -0500	[thread overview]
Message-ID: <20140228040617.GA22103@crash.ini.cmu.edu> (raw)
In-Reply-To: <530FCACF.40100@redhat.com>

Both QEMU and KVM have already accumulated a significant number of
optimizations based on the hard-coded assumption that ioapic polarity
will always use the ActiveHigh convention, where the logical and
physical states of level-triggered irq lines always match (i.e.,
active(asserted) == high == 1, inactive == low == 0). QEMU guests
are expected to follow directions given via ACPI and configure the
ioapic with polarity 0 (ActiveHigh). However, even when misbehaving
guests (e.g. OS X <= 10.9) set the ioapic polarity to 1 (ActiveLow),
QEMU will still use the ActiveHigh signaling convention when
interfacing with KVM.

This patch modifies KVM to completely ignore ioapic polarity as set by
the guest OS, enabling misbehaving guests to work alongside those which
comply with the ActiveHigh polarity specified by QEMU's ACPI tables.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Gabriel L. Somlo <somlo@cmu.edu>
---

On Fri, Feb 28, 2014 at 12:31:27AM +0100, Paolo Bonzini wrote:
>>>This is a much better description.  Can you turn it into a patch to
>>>Documentation/virtual/kvm/api.txt and a more complete commit
>>>message?

OK, let me know what you all think of this version.

> If you change ACPI tables to ActiveLow, and leave the polarity
> inversion in hw/intc/ioapic.c, then it will matter.

I only changed ACPI to ActiveLow to cause Linux to misbehave in the
same way OS X does, it was a temporary/test hack. ACPI should stay
ActiveHigh to reflect the rest of QEMU/KVM, and misbehaving guest OSs
should ignore it at their own peril :)

> >(Hmmm, maybe this one of the reasons I never got OS X to boot without
> >-enable-kvm... I should look at the QEMU hw/intc/ioapic*.c, and see
> >if *it* cares about guest-configured polarity, and maybe get it to
> >*stop* caring :)

> Exactly my point. :)

So this patch gets the accelerated path to work regardless of how
well-behaved a guest OS may or may not be w.r.t. ACPI and polarity.
I'll try to find out whether it's possible to be *extra* nice to these
types of guests by also allowing them to ignore ACPI polarity when not
using acceleration :)

Thanks again,
  Gabriel

 Documentation/virtual/kvm/api.txt | 18 ++++++++++++++++++
 include/uapi/linux/kvm.h          |  1 +
 virt/kvm/ioapic.c                 |  1 -
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 6cd63a9..0492a94 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1365,6 +1365,24 @@ struct kvm_irq_routing_msi {
 	__u32 pad;
 };
 
+NOTE: For each level-triggered interrupt managed by a virtual ioapic,
+the guest OS may set a polarity value (bit 13 of each corresponding I/O
+redirection table register). The polarity bit defines the relationship
+between an irq line's logical state (active/asserted = 1, inactive = 0)
+and its physical state (high = 1, low = 0). When the polarity bit is 0
+(ActiveHigh), logical and physical states are matched (active == high == 1,
+inactive == low == 0). When polarity is set to 1 (ActiveLow), logical and
+physical state are opposites (logical == !physical). Typically, guests are
+expected to use the same polarity across all level-triggered interrupts,
+as directed by ACPI. Historically, both KVM and QEMU have accumulated a
+significant number of optimizations based on the hard-coded assumption
+that polarity will always be set to ActiveHigh. When interfacing with KVM,
+QEMU will use the ActiveHigh convention for all level-triggered irqs,
+regardless of how the guest OS has configured the polarity bits in the
+ioapic registers. As such, KVM must also ignore these bits, and always act
+as if the logical and physical states of an irq line exactly match each
+other (i.e., follow the ActiveHigh convention regardless of polarity).
+
 
 4.53 KVM_ASSIGN_SET_MSIX_NR
 
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 932d7f2..5bfc0e6 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -675,6 +675,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_SPAPR_MULTITCE 94
 #define KVM_CAP_EXT_EMUL_CPUID 95
 #define KVM_CAP_HYPERV_TIME 96
+#define KVM_CAP_X86_IOAPIC_POLARITY_IGNORED 97
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
index ce9ed99..1539d37 100644
--- a/virt/kvm/ioapic.c
+++ b/virt/kvm/ioapic.c
@@ -328,7 +328,6 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id,
 	irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq],
 					 irq_source_id, level);
 	entry = ioapic->redirtbl[irq];
-	irq_level ^= entry.fields.polarity;
 	if (!irq_level) {
 		ioapic->irr &= ~mask;
 		ret = 1;
-- 
1.8.1.4

  reply	other threads:[~2014-02-28  4:06 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 20:02 [Qemu-devel] [PATCH] Add option to disable FDC from ISA bus and ACPI on i386 Gabriel L. Somlo
2014-01-08 20:38 ` Michael S. Tsirkin
2014-01-08 21:09   ` Gabriel L. Somlo
2014-01-15 11:13     ` Paolo Bonzini
2014-01-08 22:13 ` Paolo Bonzini
2014-01-08 23:39   ` Gabriel L. Somlo
2014-01-09  0:12     ` Alexander Graf
2014-01-09  1:51     ` Michael S. Tsirkin
2014-01-09 18:51       ` Gabriel L. Somlo
2014-01-09 20:12         ` Paolo Bonzini
2014-01-09 21:33           ` Michael S. Tsirkin
2014-01-09 21:58             ` Gabriel L. Somlo
2014-01-09 21:44           ` Gabriel L. Somlo
2014-01-10 12:37             ` Paolo Bonzini
2014-01-10 15:35               ` Gabriel L. Somlo
2014-01-10 16:13                 ` Igor Mammedov
2014-01-17 21:10                   ` [Qemu-devel] RFC: ACPI, HPET._CRS, MacOSX vs. WinXP Gabriel L. Somlo
2014-01-20 11:58                     ` Michael S. Tsirkin
2014-01-20 11:57                       ` Paolo Bonzini
2014-01-20 12:08                         ` Michael S. Tsirkin
2014-01-20 12:16                           ` Paolo Bonzini
2014-01-20 18:54                             ` Gabriel L. Somlo
2014-01-20 20:31                               ` Michael S. Tsirkin
2014-01-20 21:25                                 ` Gabriel L. Somlo
2014-01-21 10:33                                   ` Paolo Bonzini
2014-01-21 11:02                                     ` Michael S. Tsirkin
2014-01-21 11:05                                       ` Paolo Bonzini
2014-01-21 11:44                                         ` Michael S. Tsirkin
2014-01-21 18:11                                           ` [Qemu-devel] [PATCH] ACPI: Add IRQ resource to HPET._CRS on Mac OS X Gabriel L. Somlo
2014-01-21 18:38                                             ` Michael S. Tsirkin
2014-01-24 16:46                                               ` Gabriel L. Somlo
2014-01-24 21:18                                                 ` Alexander Graf
2014-01-25  0:09                                                   ` Gabriel L. Somlo
2014-01-25  9:08                                                     ` Alexander Graf
2014-01-27 22:51                                                       ` Gabriel L. Somlo
2014-01-27 23:51                                                         ` Alexander Graf
2014-01-28 16:45                                                           ` [Qemu-devel] OSX guest support review Gabriel L. Somlo
2014-01-28 16:57                                                             ` Michael S. Tsirkin
2014-01-29 14:17                                                             ` Alexander Graf
2014-01-29 21:36                                                               ` [Qemu-devel] OSX guest vs. kvm ioapic polarity Gabriel L. Somlo
2014-01-29 22:18                                                                 ` Michael S. Tsirkin
2014-01-30 14:18                                                                   ` Gabriel L. Somlo
2014-01-30 19:48                                                                     ` Michael S. Tsirkin
2014-01-30 20:21                                                                       ` Gabriel L. Somlo
2014-01-30 20:28                                                                         ` Michael S. Tsirkin
2014-01-30 20:33                                                                         ` Michael S. Tsirkin
2014-01-30 20:44                                                                           ` Gabriel L. Somlo
2014-02-11 18:23                                                                             ` [Qemu-devel] RFC: ioapic polarity vs. qemu os-x guest Gabriel L. Somlo
2014-02-11 19:54                                                                               ` Michael S. Tsirkin
2014-02-11 21:35                                                                                 ` Gabriel L. Somlo
2014-02-14 21:13                                                                                 ` Gabriel L. Somlo
2014-02-14 21:21                                                                                   ` Alexander Graf
2014-02-14 22:06                                                                                     ` Gabriel L. Somlo
2014-02-14 22:13                                                                                       ` Alexander Graf
2014-02-16 11:18                                                                                         ` Michael S. Tsirkin
2014-02-16 11:41                                                                                         ` Michael S. Tsirkin
2014-02-16 14:47                                                                                           ` Alex Williamson
2014-02-16 16:23                                                                                             ` Michael S. Tsirkin
2014-02-17 17:57                                                                                               ` Gabriel L. Somlo
2014-02-17 18:01                                                                                                 ` Gabriel L. Somlo
2014-02-17 18:06                                                                                                   ` Paolo Bonzini
2014-02-17 19:38                                                                                                     ` Gabriel L. Somlo
2014-02-18  0:58                                                                                                       ` Gabriel L. Somlo
2014-02-27 17:05                                                                                               ` [Qemu-devel] [PATCH RFC] kvm: ignore apic polarity Michael S. Tsirkin
2014-02-27 21:41                                                                                                 ` Gabriel L. Somlo
2014-02-27 22:30                                                                                                   ` Paolo Bonzini
2014-02-27 23:13                                                                                                     ` Gabriel L. Somlo
2014-02-27 23:31                                                                                                       ` Paolo Bonzini
2014-02-28  4:06                                                                                                         ` Gabriel L. Somlo [this message]
2014-02-28 17:23                                                                                                           ` [Qemu-devel] [RFC PATCH] qemu: x86: ignore ioapic polarity Gabriel L. Somlo
2014-02-28 18:57                                                                                                             ` [Qemu-devel] [RFC PATCH v2] " Gabriel L. Somlo
2014-02-28 19:14                                                                                                               ` [Qemu-devel] [PATCH] qemu: x86: report lapic version as 0x14 instead of 0x11 Gabriel L. Somlo
2014-03-01  3:44                                                                                                                 ` Alexander Graf
2014-03-01  4:25                                                                                                                   ` Gabriel L. Somlo
2014-03-01  5:45                                                                                                                     ` Alexander Graf
2014-03-01 14:46                                                                                                                 ` Paolo Bonzini
2014-03-02  0:17                                                                                                                   ` Gabriel L. Somlo
2014-03-02  8:56                                                                                                                     ` Paolo Bonzini
2014-03-02 14:31                                                                                                                       ` Michael S. Tsirkin
2014-03-02 16:02                                                                                                                         ` Michael S. Tsirkin
2014-03-06  7:50                                                                                                                     ` Michael S. Tsirkin
2014-03-02 14:52                                                                                                               ` [Qemu-devel] [RFC PATCH v2] qemu: x86: ignore ioapic polarity Michael S. Tsirkin
2014-03-02 16:15                                                                                                                 ` Gabriel L. Somlo
2014-03-02 17:09                                                                                                                   ` Michael S. Tsirkin
2014-03-06  7:45                                                                                                               ` Michael S. Tsirkin
2014-03-02 14:55                                                                                                           ` [Qemu-devel] [RFC PATCH v2] kvm: " Michael S. Tsirkin
2014-03-13 10:53                                                                                                           ` Paolo Bonzini
2014-03-13 13:43                                                                                                             ` Gabriel L. Somlo
2014-02-28  4:55                                                                                                     ` [Qemu-devel] [PATCH RFC] kvm: ignore apic polarity Michael S. Tsirkin
2014-02-28  8:10                                                                                                       ` Paolo Bonzini
2014-02-28  8:11                                                                                                       ` Paolo Bonzini
2014-03-01  5:03                                                                                                 ` Alex Williamson
2014-02-16 11:34                                                                                   ` [Qemu-devel] RFC: ioapic polarity vs. qemu os-x guest Michael S. Tsirkin
2014-02-16 15:12                                                                                     ` Peter Maydell
2014-02-16 11:37                                                                                   ` Michael S. Tsirkin
2014-01-29 23:13                                                                 ` [Qemu-devel] OSX guest vs. kvm ioapic polarity Alexander Graf
2014-01-30 15:56                                                                   ` Gabriel L. Somlo
2014-01-28 20:40                                                       ` [Qemu-devel] osx bootloader Gabriel L. Somlo
2014-01-28 22:51                                                         ` BALATON Zoltan
2014-01-29  3:07                                                           ` Gabriel L. Somlo
2014-01-29 11:29                                                             ` BALATON Zoltan
2014-01-29 14:53                                                               ` Gabriel L. Somlo
2014-01-29 15:00                                                                 ` Alexander Graf
2014-01-30  0:15                                                                   ` BALATON Zoltan
2014-02-01 17:43                                                                   ` BALATON Zoltan
2014-02-01  0:38                                                                 ` BALATON Zoltan
2014-02-01 10:07                                                                   ` Alexander Graf
2014-02-01 14:35                                                                     ` [Qemu-devel] OVMF with q35 (was: osx bootloader) BALATON Zoltan
2014-02-01 15:13                                                                       ` Alexander Graf
2014-02-01 17:38                                                                         ` BALATON Zoltan
2014-02-03  7:47                                                                       ` Gerd Hoffmann
2014-02-01 21:19                                                                   ` [Qemu-devel] osx bootloader Paolo Bonzini
2014-02-02  2:18                                                                     ` BALATON Zoltan
2014-01-29 12:10                                                             ` BALATON Zoltan
2014-01-29 14:20                                                             ` Alexander Graf
2014-01-21 11:38                                   ` [Qemu-devel] RFC: ACPI, HPET._CRS, MacOSX vs. WinXP Michael S. Tsirkin
2014-01-20 20:23                             ` Michael S. Tsirkin
2014-01-20 12:03                     ` Igor Mammedov
2014-01-09  8:46   ` [Qemu-devel] [PATCH] Add option to disable FDC from ISA bus and ACPI on i386 Markus Armbruster
2014-01-09 10:24     ` Paolo Bonzini
2014-01-31 19:03       ` [Qemu-devel] [RFC PATCH v2] Add option to switch off FDC Gabriel L. Somlo
2014-01-31 19:39         ` Eric Blake
2014-02-02 13:47           ` Michael S. Tsirkin
2014-02-10 14:10             ` Marcel Apfelbaum

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=20140228040617.GA22103@crash.ini.cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=agraf@suse.de \
    --cc=alex.williamson@redhat.com \
    --cc=eddie.dong@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 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).